Documentation

ComponentController extends SystemComponentController
in package
implements EventListener

Main controller for Sync

Tags
copyright

Cloudrexx AG

author

Michael Ritter michael.ritter@cloudrexx.com

subpackage

core_modules_sync

todo

In order to respect permission layer, this should not make direct use of doctrine (except for handling \Cx\Core_Modules\Sync\Model\Entity... entities)

Table of Contents

Interfaces

EventListener
Event listener

Constants

SYNC_COMMAND_NAME  = 'sync'

Properties

$addIds  : mixed
$alreadySyncedEntities  : mixed
$config  : array<string|int, mixed>
Config loaded from YAML
$currentInsertId  : array<string|int, mixed>
$cx  : Cx
Main class instance
$developerDocumentationUrl  : string
URL pointing to the developer documentation for this component
$doPush  : bool
$enduserDocumentationUrl  : string
URL pointing to the end-user documentation for this component
$foreignHost  : mixed
On remote side, this is set to the changeset's foreign host
$spooledPushes  : mixed
$spooler  : Spooler
$supportedApiVersions  : array<string|int, mixed>
$syncs  : array<string|int, mixed>
$systemComponent  : SystemComponent
Decorated SystemComponent
$templateDocumentationUrl  : string
URL pointing to the template definitions for this component
$unspooling  : mixed

Methods

__call()  : mixed
Decoration: all methods that are not specified in this or child classes call the corresponding method of the decorated SystemComponent
__construct()  : mixed
Initializes a controller
adjustResponse()  : mixed
Do something with a Response object You may do page alterations here (like changing the metatitle) You may do response alterations here (like set headers) PLEASE MAKE SURE THIS METHOD IS MOCKABLE. IT MAY ONLY INTERACT WITH resolve() HOOK.
executeCommand()  : void
Execute one of the commands listed in getCommandsForCommandMode()
getCascadingFields()  : mixed
Returns the fields another entity depends on (relations that should be satisfied)
getCommandDescription()  : string
Returns the description for a command provided by this component
getCommandsForCommandMode()  : array<string|int, mixed>
Returns a list of command mode commands provided by this component
getComponent()  : SystemComponentController
Get component controller object
getConfigValue()  : string
Returns a value from the config tree
getConfigValues()  : array<string|int, mixed>
Returns part of the config tree
getController()  : Controller
Returns a controller instance if one already exists
getControllerClasses()  : array<string|int, mixed>
Returns all Controller class names for this component (except this)
getControllers()  : array<string|int, mixed>
Returns a list of controllers
getControllersAccessableByJson()  : array<string|int, mixed>
Returns a list of JsonAdapter class names
getDependendingFields()  : mixed
Returns the fields this entity depends on (relations that must be satisfied)
getDeveloperDocumentationUrl()  : string
Returns the URL pointing to the developer documentation of this component.
getEnduserDocumentationUrl()  : string
Returns the URL pointing to the end-user documentation for this component.
getEntityIndexData()  : mixed
getIdMapping()  : mixed
Remote side
getSystemComponent()  : SystemComponent
Returns the SystemComponent this Controller decorates
getSystemComponentController()  : SystemComponentController
Returns the main controller
getTemplateDocumentationUrl()  : string
Returns the URL pointing to the template documentation for this component.
handleChange()  : mixed
Spools changes to be pushed to remote on local side
hasAccessToExecuteCommand()  : bool
Check whether the command has access to execute or not.
load()  : mixed
Load your component. It is needed for this request.
onEvent()  : mixed
Pushes changes to remote (local side) and updates mapping table (remote side)
postComponentLoad()  : mixed
Do something after all active components are loaded USE CAREFULLY, DO NOT DO ANYTHING COSTLY HERE! CALCULATE YOUR STUFF AS LATE AS POSSIBLE.
postContentLoad()  : mixed
Do something after content is loaded from DB
postContentParse()  : mixed
Do something after a module is loaded
postFinalize()  : mixed
Do something after main template got parsed
postInit()  : mixed
Do something after system initialization
postResolve()  : mixed
Do something after resolving is done
preComponentLoad()  : mixed
Do something before component load * USE CAREFULLY, DO NOT DO ANYTHING COSTLY HERE! CALCULATE YOUR STUFF AS LATE AS POSSIBLE.
preContentLoad()  : mixed
Do something before content is loaded from DB
preContentParse()  : mixed
Do something before a module is loaded
preFinalize()  : mixed
Do something before main template gets parsed
preInit()  : mixed
Do something before system initialization
preResolve()  : mixed
Do something before resolving is done
registerController()  : null
Registers a controller instance
registerEventListeners()  : mixed
Register your event listeners here
registerEvents()  : mixed
Registers all needed events for all syncronized entities
replacePrimaryKey()  : bool
Checks if there is an identifier ($identifier) of a remote entity (of class $dataSourceIdentifier from host $foreignHost) registered of which a local mapping exists. If so, then the associated primary key entries in $fieldData will be translated into the locally mapped identifier.
resolve()  : mixed
Called for additional, component specific resolving
setSystemComponent()  : SystemComponent
Sets the SystemComponent this Controller decorates
sync()  : mixed
This is the handler for remote side: handles incoming changes
unspool()  : mixed
Call to process the changesets hold in the spooler.
useHackForCalendar()  : bool
adjustFullyQualifiedClassName()  : string
This makes sure a FQCN does not contain double backslashes
getControllerClassName()  : string
This finds the correct FQCN for a controller name
loadConfigFile()  : array<string|int, mixed>
Loads a config YAML file
loadData()  : void
Load data from Component.yml
pushChanges()  : mixed
Push any pending changes to the set replicas.

Constants

Properties

$currentInsertId

protected array<string|int, mixed> $currentInsertId = array()

Holds the primary key of the entity being persisted (on the remote side)

$developerDocumentationUrl

URL pointing to the developer documentation for this component

protected string $developerDocumentationUrl = ''

Developer documentation URL

$enduserDocumentationUrl

URL pointing to the end-user documentation for this component

protected string $enduserDocumentationUrl = ''

End-user documentation URL

$supportedApiVersions

protected array<string|int, mixed> $supportedApiVersions = array('v1')

List of supported API versions

$syncs

protected array<string|int, mixed> $syncs = array()

Two dimensional array array(<entityClassName> => <listOfSyncEntities)

$templateDocumentationUrl

URL pointing to the template definitions for this component

protected string $templateDocumentationUrl = ''

Template documentation URL

Methods

__call()

Decoration: all methods that are not specified in this or child classes call the corresponding method of the decorated SystemComponent

public __call(string $methodName, array<string|int, mixed> $arguments) : mixed
Parameters
$methodName : string

Name of method to call

$arguments : array<string|int, mixed>

List of arguments for the method to call

Attributes
#[ReturnTypeWillChange]
Return values
mixed

Return value of the method to call

adjustResponse()

Do something with a Response object You may do page alterations here (like changing the metatitle) You may do response alterations here (like set headers) PLEASE MAKE SURE THIS METHOD IS MOCKABLE. IT MAY ONLY INTERACT WITH resolve() HOOK.

public adjustResponse(Response $response) : mixed
Parameters
$response : Response

Response object to adjust

Tags
todo

This is currently only available in "frontend" mode.

executeCommand()

Execute one of the commands listed in getCommandsForCommandMode()

public executeCommand(string $command, array<string|int, mixed> $arguments[, mixed $dataArguments = array() ]) : void

(/)/api/sync/<apiVersion>/<outputModule>/<dataSource>/[(?apikey=(&))|?]

Parameters
$command : string

Name of command to execute

$arguments : array<string|int, mixed>

List of arguments for the command

$dataArguments : mixed = array()

(optional) List of data arguments for the command

Tags
see
getCommandsForCommandMode()

getCascadingFields()

Returns the fields another entity depends on (relations that should be satisfied)

public getCascadingFields(mixed $entity, mixed $eventType[, mixed $manyToManyOnly = false ]) : mixed
Parameters
$entity : mixed
$eventType : mixed
$manyToManyOnly : mixed = false
Tags
todo:

This method should be in DataSource model

getCommandDescription()

Returns the description for a command provided by this component

public getCommandDescription(string $command[, bool $short = false ]) : string
Parameters
$command : string

The name of the command to fetch the description from

$short : bool = false

Wheter to return short or long description

Return values
string

Command description

getCommandsForCommandMode()

Returns a list of command mode commands provided by this component

public getCommandsForCommandMode() : array<string|int, mixed>
Return values
array<string|int, mixed>

List of command names

getConfigValue()

Returns a value from the config tree

public getConfigValue(string $key) : string
Parameters
$key : string

Slash-separated path to requested branch

Tags
throws
Exception

If the requested branch was not found in config

throws
Exception

If the value is not a leaf but a branch

Return values
string

Requested value as string

getConfigValues()

Returns part of the config tree

public getConfigValues(string $key) : array<string|int, mixed>
Parameters
$key : string

Slash-separated path to requested branch

Tags
throws
Exception

If the requested branch was not found in config

throws
Exception

If the value found is not an array

Return values
array<string|int, mixed>

Requested values

getController()

Returns a controller instance if one already exists

public getController(mixed $controllerClass) : Controller
Parameters
$controllerClass : mixed

Short or FQCN controller name

Tags
throws
Exception

if controller exists but cannot be loaded

Return values
Controller

Controller instance

getControllerClasses()

Returns all Controller class names for this component (except this)

public getControllerClasses() : array<string|int, mixed>

Be sure to return all your controller classes if you add your own

Return values
array<string|int, mixed>

List of Controller class names (without namespace)

getControllers()

Returns a list of controllers

public getControllers([bool $loadedOnly = true ]) : array<string|int, mixed>
Parameters
$loadedOnly : bool = true

(optional) If false, controller that did not register are instanciated, default true

Return values
array<string|int, mixed>

List of Controller instances

getControllersAccessableByJson()

Returns a list of JsonAdapter class names

public getControllersAccessableByJson() : array<string|int, mixed>

The array values might be a class name without namespace. In that case the namespace \Cx{component_type}{component_name}\Controller is used. If the array value starts with a backslash, no namespace is added.

Avoid calculation of anything, just return an array!

Return values
array<string|int, mixed>

List of ComponentController classes

getDependendingFields()

Returns the fields this entity depends on (relations that must be satisfied)

public getDependendingFields(mixed $entity) : mixed
Parameters
$entity : mixed
Tags
todo:

This method should be in DataSource model

getDeveloperDocumentationUrl()

Returns the URL pointing to the developer documentation of this component.

public getDeveloperDocumentationUrl() : string
Return values
string

URL pointing to the developer documentation

getEnduserDocumentationUrl()

Returns the URL pointing to the end-user documentation for this component.

public getEnduserDocumentationUrl() : string
Return values
string

URL pointing to the end-user documentation or empty string

getEntityIndexData()

public getEntityIndexData(mixed $entity) : mixed
Parameters
$entity : mixed
Tags
todo:

This method should be in DataSource model

getIdMapping()

Remote side

public getIdMapping(mixed $entityType[, mixed $foreignHost = '' ][, mixed $foreignId = '' ][, mixed $localId = '' ][, mixed $allowMultiple = false ]) : mixed
Parameters
$entityType : mixed
$foreignHost : mixed = ''
$foreignId : mixed = ''
$localId : mixed = ''
$allowMultiple : mixed = false

getTemplateDocumentationUrl()

Returns the URL pointing to the template documentation for this component.

public getTemplateDocumentationUrl() : string
Return values
string

URL pointing to the template documentation or empty string

handleChange()

Spools changes to be pushed to remote on local side

public handleChange(string $eventType, string $entityClassName, array<string|int, mixed> $entityIndexData, EntityBase $entity) : mixed
Parameters
$eventType : string

One of "post", "put", "delete"

$entityClassName : string

Classname of the entity to update

$entityIndexData : array<string|int, mixed>

Field=>value-type array with primary key data

$entity : EntityBase

Changed entity

Tags
todo:

Push relations first

todo:

This does not spool yet, instead it writes changes instantly

hasAccessToExecuteCommand()

Check whether the command has access to execute or not.

public hasAccessToExecuteCommand(string $command, array<string|int, mixed> $arguments) : bool
Parameters
$command : string

name of the command to execute

$arguments : array<string|int, mixed>

list of arguments for the command

Return values
bool

load()

Load your component. It is needed for this request.

public load(Page $page) : mixed

This loads your FrontendController or BackendController depending on the mode Cx runs in. For modes other than frontend and backend, nothing is done. If you you'd like to name your Controllers differently, or have another use case, overwrite this.

Parameters
$page : Page

The resolved page

onEvent()

Pushes changes to remote (local side) and updates mapping table (remote side)

public onEvent(string $eventName, object $eventArgs) : mixed
Parameters
$eventName : string

Name of the triggered event

$eventArgs : object

Doctrine event args

Tags
todo

update ID fields does not work as expected

postComponentLoad()

Do something after all active components are loaded USE CAREFULLY, DO NOT DO ANYTHING COSTLY HERE! CALCULATE YOUR STUFF AS LATE AS POSSIBLE.

public postComponentLoad() : mixed

postContentLoad()

Do something after content is loaded from DB

public postContentLoad(Page $page) : mixed

USE CAREFULLY, DO NOT DO ANYTHING COSTLY HERE! CALCULATE YOUR STUFF AS LATE AS POSSIBLE

Parameters
$page : Page

The resolved page

postContentParse()

Do something after a module is loaded

public postContentParse(Page $page) : mixed

This method is called only if any module gets loaded for content parsing USE CAREFULLY, DO NOT DO ANYTHING COSTLY HERE! CALCULATE YOUR STUFF AS LATE AS POSSIBLE

Parameters
$page : Page

The resolved page

postFinalize()

Do something after main template got parsed

public postFinalize(string &$endcode) : mixed

USE CAREFULLY, DO NOT DO ANYTHING COSTLY HERE!

Parameters
$endcode : string

The processed data to be sent to the client as response

postInit()

Do something after system initialization

public postInit(Cx $cx) : mixed

USE CAREFULLY, DO NOT DO ANYTHING COSTLY HERE! CALCULATE YOUR STUFF AS LATE AS POSSIBLE. This event must be registered in the postInit-Hook definition file config/postInitHooks.yml.

Parameters
$cx : Cx

The instance of \Cx\Core\Core\Controller\Cx

postResolve()

Do something after resolving is done

public postResolve(Page $page) : mixed

USE CAREFULLY, DO NOT DO ANYTHING COSTLY HERE! CALCULATE YOUR STUFF AS LATE AS POSSIBLE

Parameters
$page : Page

The resolved page

preComponentLoad()

Do something before component load * USE CAREFULLY, DO NOT DO ANYTHING COSTLY HERE! CALCULATE YOUR STUFF AS LATE AS POSSIBLE.

public preComponentLoad() : mixed

This event must be registered in the preComponentLoad-Hook definition file config/preComponentLoadHooks.yml.

preContentLoad()

Do something before content is loaded from DB

public preContentLoad(Page $page) : mixed

USE CAREFULLY, DO NOT DO ANYTHING COSTLY HERE! CALCULATE YOUR STUFF AS LATE AS POSSIBLE

Parameters
$page : Page

The resolved page

preContentParse()

Do something before a module is loaded

public preContentParse(Page $page) : mixed

This method is called only if any module gets loaded for content parsing USE CAREFULLY, DO NOT DO ANYTHING COSTLY HERE! CALCULATE YOUR STUFF AS LATE AS POSSIBLE

Parameters
$page : Page

The resolved page

preFinalize()

Do something before main template gets parsed

public preFinalize(Sigma $template) : mixed

USE CAREFULLY, DO NOT DO ANYTHING COSTLY HERE! CALCULATE YOUR STUFF AS LATE AS POSSIBLE

Parameters
$template : Sigma

The main template

preInit()

Do something before system initialization

public preInit(Cx $cx) : mixed

USE CAREFULLY, DO NOT DO ANYTHING COSTLY HERE! CALCULATE YOUR STUFF AS LATE AS POSSIBLE. This event must be registered in the preInit-Hook definition file config/preInitHooks.yml.

Parameters
$cx : Cx

The instance of \Cx\Core\Core\Controller\Cx

preResolve()

Do something before resolving is done

public preResolve(Url $request) : mixed

USE CAREFULLY, DO NOT DO ANYTHING COSTLY HERE! CALCULATE YOUR STUFF AS LATE AS POSSIBLE

Parameters
$request : Url

The URL object for this request

registerEventListeners()

Register your event listeners here

public registerEventListeners() : mixed

USE CAREFULLY, DO NOT DO ANYTHING COSTLY HERE! CALCULATE YOUR STUFF AS LATE AS POSSIBLE. Keep in mind, that you can also register your events later. Do not do anything else here than initializing your event listeners and list statements like $this->cx->getEvents()->addEventListener($eventName, $listener);

registerEvents()

Registers all needed events for all syncronized entities

public registerEvents() : mixed

This includes listeners for local side (all entities that are to be synced) and listeners for remote side (all changes of ID that are in mapping table)

replacePrimaryKey()

Checks if there is an identifier ($identifier) of a remote entity (of class $dataSourceIdentifier from host $foreignHost) registered of which a local mapping exists. If so, then the associated primary key entries in $fieldData will be translated into the locally mapped identifier.

public replacePrimaryKey(string $foreignHost, string $dataSourceIdentifier, array<string|int, mixed> $primaryKeyNames, array<string|int, mixed> &$fieldData[, array<string|int, mixed> $identifier = array() ][, bool $foreign = true ]) : bool

If $foreign is set to FALSE, then the check and replacement is done in reverse, meaning that $identifier is threatened as the local identifier and is translated into the remote identifier from $foreignHost.

Parameters
$foreignHost : string
$dataSourceIdentifier : string
$primaryKeyNames : array<string|int, mixed>
$fieldData : array<string|int, mixed>
$identifier : array<string|int, mixed> = array()
$foreign : bool = true
Return values
bool

Whether a mapping exists and has been replaced.

resolve()

Called for additional, component specific resolving

public resolve(array<string|int, mixed> $parts, Page $page) : mixed

If /en/Path/to/Page is the path to a page for this component a request like /en/Path/to/Page/with/some/parameters will give an array like array('with', 'some', 'parameters') for $parts PLEASE MAKE SURE THIS METHOD IS MOCKABLE. IT MAY ONLY INTERACT WITH adjustResponse() HOOK.

This may be used to redirect to another page

Parameters
$parts : array<string|int, mixed>

List of additional path parts

$page : Page

Resolved virtual page

sync()

This is the handler for remote side: handles incoming changes

public sync(string $command, array<string|int, mixed> $arguments, array<string|int, mixed> $dataArguments) : mixed
Parameters
$command : string

Always "sync"

$arguments : array<string|int, mixed>

Arguments for API, first entry is API version

$dataArguments : array<string|int, mixed>

(optional) List of data arguments for the command

Tags
todo

pretending delete was successful does not work for other output methods than json

todo

update ID fields does not work as expected

unspool()

Call to process the changesets hold in the spooler.

public unspool() : mixed

This will initiate the sync command to push the model changes to the remotes.

useHackForCalendar()

public useHackForCalendar(mixed $entityClassName) : bool

Will be dropped by CLX-3974

Parameters
$entityClassName : mixed
Return values
bool

Whether we should use dodgy logic to make the sync for component Calendar work.

adjustFullyQualifiedClassName()

This makes sure a FQCN does not contain double backslashes

protected adjustFullyQualifiedClassName(string $className) : string
Parameters
$className : string

FQCN of a controller

Return values
string

Clean FQCN of a controller

getControllerClassName()

This finds the correct FQCN for a controller name

protected getControllerClassName(string $controllerClassShort) : string
Parameters
$controllerClassShort : string

Short name for controller

Return values
string

Fully qualified controller class name

loadConfigFile()

Loads a config YAML file

protected loadConfigFile(string $filename) : array<string|int, mixed>
Parameters
$filename : string

Name of the file to load

Tags
throws
Exception

If the file could not be loaded correctly

Return values
array<string|int, mixed>

Loaded data

pushChanges()

Push any pending changes to the set replicas.

protected pushChanges([bool $verbose = false ]) : mixed
Parameters
$verbose : bool = false

Set to TRUE for continuous log output. If not set, the log output will be buffered till the end.


        
On this page

Search results