Example #1
0
 /**
  * Build console entry point
  * @param array|null $services
  * @throws \Ffcms\Core\Exception\NativeException
  */
 public static function init(array $services = null)
 {
     self::$Properties = new Properties();
     self::$Input = new Input();
     self::$Output = new Output();
     // establish database link
     if (Obj::isArray(self::$Properties->get('database')) && (isset($services['Database']) && $services['Database'] === true || $services === null)) {
         self::$Database = new Capsule();
         self::$Database->addConnection(self::$Properties->get('database'));
         // Make this Capsule instance available globally via static methods... (optional)
         self::$Database->setAsGlobal();
         // Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
         self::$Database->bootEloquent();
     }
 }
Example #2
0
 /**
  * Prepare dynamic static links from object configurations as anonymous functions
  * @throws NativeException
  */
 private function dynamicStaticLinks()
 {
     /** @var array $objects */
     $objects = App::$Properties->getAll('object');
     if (!Obj::isArray($objects)) {
         throw new NativeException('Object configurations is not loaded: /Private/Config/Object.php');
     }
     // each all objects as service_name => service_instance()
     foreach ($objects as $name => $instance) {
         // check if definition of object is exist and services list contains it or is null to auto build
         if (property_exists(get_called_class(), $name) && $instance instanceof \Closure && (isset($this->_services[$name]) || $this->_services === null)) {
             if ($this->_services[$name] === true || $this->_services === null) {
                 // initialize from configs
                 self::${$name} = $instance();
             } elseif (is_callable($this->_services[$name])) {
                 // raw initialization from App::run()
                 self::${$name} = $this->_services[$name]();
             }
         } elseif (Str::startsWith('_', $name)) {
             // just anonymous callback without entry-point
             @call_user_func($instance);
         }
     }
 }