コード例 #1
0
ファイル: Repository.php プロジェクト: comelyio/comely
 /**
  * Save an instance in repository
  *
  * @param $instance
  * @param string|null $key
  * @throws RepositoryException
  */
 public function push($instance, string $key = null)
 {
     // Repository holds only instances
     if (!is_object($instance)) {
         throw RepositoryException::badInstance();
     }
     // Use short/base name of class if $key param is not specified
     $key = $key ?? \Comely::baseClassName(get_class($instance));
     // Save instance
     $this->instances[$key] = $instance;
 }
コード例 #2
0
ファイル: Kernel.php プロジェクト: comelyio/framework-kernel
 /**
  * Framework Kernel constructor.
  *
  * @param array $components
  * @param string $env
  */
 public function __construct(array $components, string $env)
 {
     // Create a private dependency injection container
     $this->container = new Container();
     // Run through all passed components
     foreach ($components as $component) {
         /// Add to container
         $this->container->add(\Comely::baseClassName(is_object($component) ? get_class($component) : $component), $component);
     }
     // Set variables
     $this->dateTime = new DateTime();
     $this->env = $env;
     $this->setRootPath(dirname(dirname(dirname(dirname(__DIR__)))));
     $this->errorHandler = new ErrorHandler($this);
     // Setup disks instances
     $this->disks = new Repository();
     $this->container->add("disks", $this->disks);
     $this->disks->push(new Disk($this->rootPath . self::DS . self::CACHE_PATH), "cache");
 }