generate($config); if (static::$_instance->exists($class)) { return static::$_instance->get($class); } else { return static::$_instance->generate($config); } } /** * @param \common\Config $config * @return $this */ public function generate(Config $config) { $this->config = $config; return $this; } /** * @param $class * @return object|ReflectionClass * @throws ReflectionException * @throws Exception */ private function createObject($class) { $newInstance = new \ReflectionClass($class); if (!$newInstance->isInstantiable()) { throw new Exception('Class Con\'t instance.'); } $newInstance = $newInstance->newInstance(); if (method_exists($newInstance, 'initConfig')) { $newInstance->initConfig($this->config); } $this->container[$class] = $newInstance; return $newInstance; } /** * @param $name * @return mixed */ public function get($name) { return $this->container[$name]; } /** * @param $name * @return bool */ public function exists($name) { return array_key_exists($name, $this->container) && $this->container[$name] instanceof Progaram; } }