<?php
namespace Liaison\Test\Integration\LifeCycle;
class LifeCycleTestComponent extends \Lia\Compo {
public $actualStack = [];
public $targetStack = [
['event'=> 'onCreate','args'=>[]],
['event'=> 'onReady','args'=>[]],
['event'=> 'onComponentsLoaded', 'args'=>[]],
['event'=> 'onPackageReady','args'=>[]],
['event'=> 'onAllPackagesReady','args'=>[]],
['event'=> 'onRequestStarted','args'=>[]],
['event'=> 'onRoutesFound','args'=>[]],
['event'=> 'onRoutesFiltered','args'=>[]],
['event'=> 'onRouteResolved','args'=>[]],
['event'=> 'onThemeLoaded','args'=>[]],
['event'=> 'onResponseReady','args'=>[]],
// ['event'=> 'onResponseSend','args'=>[]],
// ['event'=> 'onRequestFinished','args'=>[]],
];
protected function stack($eventName, ...$args){
$args = [];
$this->actualStack[] = ['event'=>$eventName, 'args'=>$args];
}
// NOT an event. this is called explicitly by the owning package
public function onCreate(){
$this->stack('onCreate');
}
// NOT an event. this is called explicitly by the owning package
public function onReady(){
$this->stack('onReady');
}
public function onComponentsLoaded(){
$this->stack("onComponentsLoaded");
}
// COULD be an event, if I allow event namespacing, but how would I specify the namespace here?
// Namespace would be automatically set by the package that loads the component
// But it also COULD just be called directly by the package, which would allow basic lifecycle methods, even if liaison is a bare instance
// So probably, probably this is NOT an event. But it COULD be.
public function onPackageReady(){
parent::onPackageReady();
$this->stack('onPackageReady');
}
// the rest of these are events
public function onEmitAllPackagesReady(){
// echo "LifeCycleTestComponent:: onEmitAllPackagesReady";
// exit;
$this->stack('onAllPackagesReady');
}
public function onEmitRequestStarted($requestObj, $responseObject){
$this->stack('onRequestStarted', $requestObj, $responseObject);
}
public function onEmitRoutesFound($routeList){
$this->stack('onRoutesFound', $routeList);
}
public function onEmitRoutesFiltered($finalRoute){
$this->stack('onRoutesFiltered', $finalRoute);
}
public function onEmitRouteResolved($finalRoute, $responseObj){
$this->stack('onRouteResolved', $finalRoute, $responseObj);
}
public function onEmitThemeLoaded($theme){
$this->stack('onThemeLoaded', $theme);
}
public function onEmitResponseReady($response){
$this->stack('onResponseReady', $response);
}
public function onEmitResponseSend($response){
$this->stack('onResponseSend', $response);
}
public function onEmitRequestFinished($requestObj, $responseObj){
$this->stack('onRequestFinished', $requestObj, $responseObj);
}
}
// $lia = new Liaison')
// $lia = new Liaison();
// // no events
// $package = new Lia\Package($lia,$dir,$configs)
// foreach ($component...) new $Component($package)
// $Component->__construct
// $Component->onCreate
// do __construct stuff
// $Component->onReady
// foreach ($Component...) $Component->onPackagReady() (& thus components are ready)
// $package2 = new \Lia\Package($lia,$dir2, $configs2)...
// ... repeat (but for this package)
// $lia->deliver() //Calls Server component
// $evevntBus->onAllPackagesReady()
// foreach ($ScheduledComponent...)$ScheduledComponent->onAllPackagesReady()
// $eventBus->onRequestStarted($requestObj, $responseObject)
// foreach ($ScheduledComponent...)$ScheduledComponent->onRequestStarted(...)
// $eventBus->onRoutesFound($routeList)
// $eventBus->onRoutesFiltered($finalRoute)
// $eventBus->onRouteResolved($finalRoute, $responseObj)
// $eventBus->onThemeLoaded($theme) <- not ALWAYS called, because themes are not always used
// $eventBus->onResponseReady($response) <- before headers are sent or content is echo'd
// $eventBus->onResponseSend($response)
// $eventBus->onRequestFinished($requestObj, $responseObj)