/**
  * @param string                 $interface
  * @param null|object            $bind
  * @param null|ResolverInterface $resolver
  */
 public function __construct($interface, $bind = null, ResolverInterface $resolver = null)
 {
     try {
         ClassInfo::assertInterface($interface);
         parent::__construct(new \ReflectionClass($interface), $bind, $resolver);
     } catch (\Exception $exception) {
         throw $this->getConstructorException(['interface name string', $interface]);
     }
 }
示例#2
0
 /**
  * @param string $namespace
  *
  * @return string[]|array[]
  */
 private static final function parseNamespaceContext($namespace)
 {
     $sections = self::getNamespaceSections(self::normalizeSequentialUpperChars($namespace));
     if (ClassInfo::isClass($namespace)) {
         array_pop($sections);
     }
     $transformer = new StringTransform(array_shift($sections));
     $root = (string) $transformer->pascalToSnakeCase();
     return [$root, $sections];
 }
 public function testThrowableEquitable()
 {
     $class = 'SR\\Util\\Test\\Fixture\\IsInstanceOfThrowableFixture';
     $instance = new $class();
     $this->assertTrue(ClassInfo::isThrowableEquitable($class));
     $this->assertTrue(ClassInfo::isThrowableEquitable($instance));
     $class = 'SR\\Util\\Test\\Fixture\\NotInstanceOfThrowableFixture';
     $instance = new $class();
     $this->assertFalse(ClassInfo::isThrowableEquitable($class));
     $this->assertFalse(ClassInfo::isThrowableEquitable($instance));
     $this->assertFalse(ClassInfo::isThrowableEquitable(__NAMESPACE__ . '\\This\\Class\\Does\\Not\\Exist'));
 }
 /**
  * @param string                 $class
  * @param string                 $constant
  * @param null|object            $bindTo
  * @param null|ResolverInterface $resolver
  */
 public function __construct($class, $constant, $bindTo = null, ResolverInterface $resolver = null)
 {
     try {
         parent::__construct(new ReflectionConstant($class, $constant), $bindTo, $resolver);
         if (ClassInfo::isInterface($class)) {
             $this->declaringClass = new InterfaceInspector($class);
         } elseif (ClassInfo::isClass($class)) {
             $this->declaringClass = new ClassInspector($class);
         }
     } catch (\Exception $exception) {
         throw $this->getConstructorException(['class name string', $class], ['constant name string', $constant]);
     }
 }
 /**
  * @param string                 $class
  * @param string                 $method
  * @param null|object            $bindTo
  * @param null|ResolverInterface $resolver
  */
 public function __construct($class, $method, $bindTo = null, ResolverInterface $resolver = null)
 {
     try {
         parent::__construct(new \ReflectionMethod($class, $method), $bindTo, $resolver);
         if (ClassInfo::isTrait($class)) {
             $this->declaringClass = new TraitInspector($class);
         }
         if (!ClassInfo::isTrait($class) && ClassInfo::isClass($class)) {
             $this->declaringClass = new ClassInspector($class);
         }
     } catch (\Exception $exception) {
         throw $this->getConstructorException(['class name string', $class], ['method name string', $method]);
     }
 }
 /**
  * Try to determine the type of passed item and proxies the call to the respective specific this[*] methods.
  *
  * @param object|string $what A class name, object instance, interface name, or trait name
  * @param object|null   $bind Alternate $this binding for internal resolver instance
  *
  * @throws RuntimeException If passed value is not an instance, class, interface or trait
  *
  * @return ClassInspector|ObjectInspector|InterfaceInspector|TraitInspector
  */
 public static function using($what, $bind = null)
 {
     if (ClassInfo::isInstance($what)) {
         return self::useInstance($what, $bind);
     }
     if (ClassInfo::isClass($what)) {
         return self::useClass($what, $bind);
     }
     if (ClassInfo::isInterface($what)) {
         return self::useInterface($what, $bind);
     }
     if (ClassInfo::isTrait($what)) {
         return self::useTrait($what);
     }
     throw RuntimeException::create('Invalid inspector argument provided (got %s)', var_export($what, true));
 }
 /**
  * Filters an array of parameters (the values passed to any of this object's variadic methods) of non-throwables
  * and returns the first found or null if none are found.
  *
  * @param mixed[] $from
  *
  * @return \Throwable[]
  */
 private final function filterThrowable(array $from)
 {
     return array_filter($from, function ($p) {
         return is_object($p) && ClassInfo::isThrowableEquitable($p);
     });
 }
示例#8
0
 /**
  * Returns the name of the Twig extension based on the classname.
  *
  * @return string
  */
 public final function getName()
 {
     return strtolower('twig_extension_' . preg_replace('{twigextension$}i', '', ClassInfo::getNameShort(static::class)));
 }