Class \Prado\Util\TBehaviorsModule
TBehaviorsModule loads and attaches TBehavior. This attaches Behaviors to classes and to application components like the TApplication, individual modules, and TPage of the TPageService.
Contents enclosed within the module tag are treated as behaviors, e.g.,
<module class="Prado\Util\TBehaviorsModule" Parameter="AdditionalBehaviors">
<behavior Name="pagethemeparameter" Class="Prado\Util\Behaviors\TParameterizeBehavior" AttachToClass="Prade\Web\UI\TPage" Priority="10" Parameter="ThemeName" Property="Theme"/>
<behavior Name="sharedModuleBehavior" Class="FooModuleBehavior" AttachToClass="Prado\TModule" Attribute1="abc"/>
<behavior name="TimeZoneBehavior" Class="Prado\Util\Behaviors\TTimeZoneParameterBehavior" AttachTo="Application" Priority="10" TimeZone="America/New York" TimeZoneParameter="prop:TimeZone" />
<behavior name="MyModuleBehavior" Class="MyModuleBehavior" AttachTo="Module:page" Property1="Value1" Property2="Value2" ... />
<behavior name="MyPageTitleBehavior" Class="Prado\Util\Behaviors\TParameterizeBehavior" AttachTo="Page" Priority="10" Parameter="PageTitle" Property="Title" Localize="true"/>
</module>
When the Service is not TPageService, page behaviors are not installed and have no effect other than be ignored.
When \Prado\Util\setAdditionalBehaviors is set, this module loads the behaviors from that property. It can be an array of php behavior definition arrays. or a string that is then passed through unserialize or json_decode; otherwise is treated as an xml document of behavior like above.
The format is in the PHP style module configuration:
[['name' => 'behaviorname', 'class' => 'TMyBehaviorClass', 'attachto' => 'page', 'priority' => '10', 'behaviorProperty'=>"value1'], ...]
This allows TBehaviorsModule to load behaviors, dynamically, from parameters with the TParameterizeBehavior.
Multiple TBehaviorsModules can be instanced, for instance, a second set of behaviors could be configured in TPageService. The second TBehaviorsModule can reference behaviors from the first to attach its behaviors.
Class hierarchy
- \Prado\Util\TBehaviorsModule
- \Prado\TModule implements IModule
- \Prado\TApplicationComponent
- \Prado\TComponent
Since: 4.2.0
public
|
|
public
|
attachTPageBehaviors(object $sender, TPage $page) : mixed
This method attaches page behaviors to the TPage handling the TPageService::OnPreInitPage event.
|
public
|
attachTPageServiceHandler(object $sender, mixed $param) : mixed
TApplication::onBeginRequest Handler that adds {@see attachTPageBehaviors} to
TPageService::onPreRunPage. In turn, this attaches {@see attachTPageBehaviors}
to TPageService to then adds the page behaviors.
|
public
|
|
public
|
init(TXmlElement $config) : mixed
Initializes the module by loading behaviors. If there are page behaviors, this
attaches behaviors to TPage through TApplication::onBeginRequest and then
TPageService::onPreRunPage.
|
public
|
setAdditionalBehaviors(array<string|int, array<string|int, mixed>>|string $behaviors) : mixed
this will take a string that is an array of behaviors that has been
through serialize(), or json array of behaviors. If one behavior is
set as an array, then it is automatically placed into an array.
|
protected
|
loadBehaviors(mixed $config) : mixed
Loads behaviors and attach to the proper object. behaviors for pages are
attached separately if and when the TPage is loaded on TPageSerivce::onPreRunPage
|
\Prado\TApplicationComponent::FX_CACHE_FILE, \Prado\TComponent::GLOBAL_RAISE_EVENT_LISTENER |