Esempio n. 1
0
 /**
  * Test if a class implements an interface
  * @param $class_name
  * @param $interface_name
  * @return bool
  */
 public static function classImplements($class_name, $interface_name)
 {
     if (empty($interface_name) || !interface_exists($interface_name)) {
         return false;
     }
     return CodeHelper::implementsInterface($class_name, $interface_name);
 }
 /**
  * Construct a service based on its `constructor` item and references it
  *
  * @param   string  $name
  * @param   array   $arguments
  * @return  void
  * @throws  ErrorException
  */
 protected function _constructService($name, array $arguments = array())
 {
     if ($this->hasProvider($name)) {
         $data = $this->getProvider($name);
         if (is_object($data) && CodeHelper::implementsInterface($data, 'ServiceContainer\\ServiceProviderInterface')) {
             $data->boot($this);
             $this->setService($name, $data);
         } elseif (is_callable($data) || $data instanceof \Closure) {
             try {
                 $item = call_user_func_array($data, array($this, $name, $arguments));
                 $this->setService($name, $item);
             } catch (\Exception $e) {
                 throw new ErrorException(sprintf('An error occurred while trying to create a "%s" service!', $name), 0, 1, __FILE__, __LINE__, $e);
             }
         } elseif (is_array($data)) {
             $this->setService($name, $data[1], isset($data[2]) ? $data[2] : false);
         } else {
             throw new ErrorException(sprintf('A "%s" service constructor must be a valid callback!', $name));
         }
     }
 }