public function testClassTester() { $instance = new ClassInfo(); static::assertTrue(ClassInfo::assertClass(__CLASS__)); static::assertTrue(ClassInfo::isClass(__CLASS__)); static::assertFalse(ClassInfo::isClass($instance)); $this->expectException('\\InvalidArgumentException'); ClassInfo::assertClass($instance); }
/** * @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]; }
/** * @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)); }