Ejemplo n.º 1
0
 /**
  * 
  */
 public function __construct()
 {
     parent::__construct();
     // set package name and namespace
     $parts = explode('\\', get_class($this));
     $pkgName = strtolower($parts[0] . '/' . $parts[1]);
     $this->setComposerName($pkgName);
     $this->setNamespace($parts[0] . '\\' . $parts[1]);
     // unique key. being used when dumping package's assets
     $this->key = sha1(get_class($this));
     // every package has its own factory. extensions created by facade will
     // inherit application's factory.
     $this->setFactory(new Factory\Factory($this));
     // not all packages are being created by the facade so we have to assign
     // application instance explicitly
     //$this->setApplication(AbstractFacade::getApplication());
     $this->init();
     // assign event listeners
     $this->addEventListener(Event\Type\System\Build::toType(), function ($event) {
         //var_dump($this->getNamespace());exit;
         $this->onBuildEvent($event);
     });
     $this->addEventListener(Event\Type\System\PkgNotification::toType(), function ($event) {
         switch ($event->getNotifWord()) {
             case 'load-config-file':
                 $this->loadConfigFile();
                 break;
             case 'init-routing':
                 $this->initRouting();
                 break;
         }
     });
 }
Ejemplo n.º 2
0
 /**
  * @return $this
  */
 public function bootstrap($externalEvent)
 {
     if ($this->bootstrapFlag) {
         return;
     }
     // assign application directory path
     if (!$this->getDirectory()) {
         $this->setDirectory(realpath($this->getClassPath(get_class($this)) . '/..'));
     }
     // set event being dispatched
     $this->setCurrentEvent($externalEvent);
     // create event context
     $this->context = $externalEvent->createContext();
     $this->addPathAliases();
     $this->autoloadExtensions();
     $this->flattenManifestFile($externalEvent);
     $this->buildApp();
     $this->addServices();
     $this->assignActions();
     $this->assignEventListeners();
     $this->addRouter('\\PHPCrystal\\PHPCrystal\\Service\\Router\\_Default');
     parent::dispatch(Event\Type\System\PkgNotification::create('load-config-file'));
     parent::dispatch(Event\Type\System\PkgNotification::create('init-routing'));
     $this->bootstrapFlag = true;
     return $this;
 }