Example #1
0
 /**
  * Exports the PHP code
  *
  * @return string
  */
 public function exportCode()
 {
     $code_lines = array();
     $code_lines[] = '<?php';
     // Export the namespace
     if ($this->_reflection_class->getNamespaceName()) {
         $code_lines[] = '';
         $code_lines[] = 'namespace ' . $this->_reflection_class->getNamespaceName() . ';';
         $code_lines[] = '';
     }
     // Export the class' signature
     $code_lines[] = sprintf('%s%s%s %s%s%s', $this->_reflection_class->isAbstract() ? 'abstract ' : '', $this->_reflection_class->isFinal() ? 'final ' : '', $this->_reflection_class->isInterface() ? 'interface' : ($this->_reflection_class->isTrait() ? 'trait' : 'class'), $this->getClassName(), $this->_getParentClassName() ? " extends {$this->_getParentClassName()}" : '', $this->_getInterfaceNames() ? " implements " . join(', ', $this->_getInterfaceNames()) : '');
     $code_lines[] = '{';
     $code_lines[] = '';
     // Export constants
     foreach ($this->_reflection_class->getConstants() as $name => $value) {
         $reflection_constant = new ReflectionConstant($name, $value);
         $code_lines[] = "\t" . $reflection_constant->exportCode();
         $code_lines[] = '';
     }
     // Export properties
     foreach ($this->_reflection_class->getProperties() as $property) {
         $reflection_property = new ReflectionProperty($property);
         $code_lines[] = "\t" . $reflection_property->exportCode();
         $code_lines[] = '';
     }
     // Export methods
     foreach ($this->_reflection_class->getMethods() as $method) {
         $reflection_method = new ReflectionMethod($method);
         $code_lines[] = "\t" . $reflection_method->exportCode();
         $code_lines[] = '';
     }
     $code_lines[] = '}';
     return join("\n", $code_lines);
 }
Example #2
0
 /**
  * Get current object type
  * @return string  - class/trait/interface
  */
 public function getType()
 {
     if ($this->reflectionClass->isInterface()) {
         return 'interface';
     }
     if (method_exists($this->reflectionClass, 'isTrait') && $this->reflectionClass->isTrait()) {
         return 'trait';
     }
     return 'class';
 }
 /**
  * @param \Donquixote\HastyReflectionCommon\Canvas\ClassIndex\ClassIndexInterface $classIndex
  * @param string $class
  *
  * @dataProvider provideClassIndexArgs()
  */
 function testClassIndex(ClassIndexInterface $classIndex, $class)
 {
     $classReflection = $classIndex->classGetReflection($class);
     $reflectionClass = new \ReflectionClass($class);
     // Test identity.
     $this->assertTrue($classReflection === $classIndex->classGetReflection($class));
     // Test class type/info.
     $expectedIsClass = !$reflectionClass->isInterface() && !$reflectionClass->isTrait();
     $this->assertEquals($reflectionClass->getName(), $classReflection->getName());
     $this->assertEquals($reflectionClass->getShortName(), $classReflection->getShortName());
     $this->assertEquals($reflectionClass->getDocComment(), $classReflection->getDocComment());
     $this->assertEquals($reflectionClass->isInterface(), $classReflection->isInterface());
     $this->assertEquals($reflectionClass->isTrait(), $classReflection->isTrait());
     $this->assertEquals($expectedIsClass, $classReflection->isClass());
     $this->assertEquals($reflectionClass->isAbstract() && $expectedIsClass, $classReflection->isAbstractClass());
     // Test context.
     $this->assertEquals($reflectionClass->getNamespaceName(), $classReflection->getNamespaceUseContext()->getNamespaceName());
     // Test interfaces
     foreach ($classReflection->getOwnInterfaces() as $interfaceName => $interfaceReflection) {
         $this->assertTrue($reflectionClass->implementsInterface($interfaceName));
     }
     foreach ($reflectionClass->getInterfaceNames() as $interfaceName) {
         $this->assertTrue($classReflection->extendsOrImplementsInterface($interfaceName, FALSE));
     }
     $expectedAllInterfaceNames = $expectedAllAndSelfInterfaceNames = $reflectionClass->getInterfaceNames();
     if ($reflectionClass->isInterface()) {
         array_unshift($expectedAllAndSelfInterfaceNames, $class);
     }
     $this->assertEqualSorted($expectedAllAndSelfInterfaceNames, array_keys($classReflection->getAllInterfaces(TRUE)));
     $this->assertEqualSorted($expectedAllInterfaceNames, array_keys($classReflection->getAllInterfaces(FALSE)));
     $expectedMethodNames = array();
     $expectedOwnMethodNames = array();
     foreach ($reflectionClass->getMethods() as $method) {
         $expectedMethodNames[] = $method->getName();
         if ($method->getDeclaringClass()->getName() === $reflectionClass->getName()) {
             $expectedOwnMethodNames[] = $method->getName();
         }
     }
     $this->assertEquals($expectedOwnMethodNames, array_keys($classReflection->getOwnMethods()));
     $this->assertEqualSorted($expectedMethodNames, array_keys($classReflection->getMethods()));
     $methodReflections = $classReflection->getMethods();
     foreach ($reflectionClass->getMethods() as $reflectionMethod) {
         $methodReflection = $methodReflections[$reflectionMethod->getShortName()];
         $this->assertEqualMethods($reflectionMethod, $methodReflection);
     }
     // isAbstract() is a beast, so we test it least.
     $this->assertEquals($reflectionClass->isAbstract(), $classReflection->isAbstract());
 }
Example #4
0
 private static function _createClassCode($decoratee_class, $decorator_class, $events_handler)
 {
     $reflection = new ReflectionClass($decoratee_class);
     if ($reflection->isInterface()) {
         $relation = "implements";
     } else {
         $relation = "extends";
     }
     $code = "class {$decorator_class} {$relation} {$decoratee_class} {" . PHP_EOL;
     $code .= $events_handler->onDeclareProperties() . PHP_EOL;
     $code .= "    function __construct() {" . PHP_EOL;
     //dealing with proxied class' public properties
     foreach ($reflection->getProperties() as $property) {
         if ($property->isPublic()) {
             $code .= 'unset($this->' . $property->getName() . ");" . PHP_EOL;
         }
     }
     $code .= "        \$args = func_get_args();" . PHP_EOL;
     $code .= $events_handler->onConstructor() . PHP_EOL;
     $code .= "    }" . PHP_EOL;
     $code .= self::_createHandlerCode($decoratee_class, $decorator_class, $events_handler) . PHP_EOL;
     $code .= "}" . PHP_EOL;
     //var_dump($code);
     return $code;
 }
Example #5
0
 /**
  * Filter classes.
  *
  * @param \ReflectionClass $class Class to filter.
  *
  * @throws FilterException
  */
 public function filter(\ReflectionClass $class)
 {
     $name = $class->getShortName();
     if ($class->isAbstract() || $class->isInterface() || !(strlen($name) > 4 && substr($name, -4) === 'Test')) {
         throw new FilterException(sprintf('TestCase was filtered by "%s" filter.', $this->getName()));
     }
 }
 protected function getFile($file, $classToCheck = null)
 {
     if (!file_exists($file)) {
         throw new ShopException("File {$file} not found");
     }
     if (!is_readable($file)) {
         throw new ShopException("File {$file} exists, but it's not readable");
     }
     require_once $file;
     if ($classToCheck === 'Product') {
         $classToCheck = array('ConfigurableProduct', 'SimpleProduct');
     }
     if ($classToCheck) {
         if (!is_array($classToCheck)) {
             $classToCheck = array($classToCheck);
         }
         foreach ($classToCheck as $class) {
             $reflection = new ReflectionClass($class);
             if (!$reflection->isInstantiable()) {
                 if (!$reflection->isAbstract() && !$reflection->isInterface()) {
                     throw new ShopException("{$class} class is not instantiable");
                 }
             }
         }
     }
 }
Example #7
0
 /**
  * @param \ReflectionClass $class
  * @return string
  * @throws IoException
  */
 public function loadTemplateForClass(\ReflectionClass $class)
 {
     if ($class->isInterface()) {
         return $this->loadFile($this->templateDir . 'Interface.php.template');
     }
     return $this->loadFile($this->templateDir . 'Class.php.template');
 }
Example #8
0
 /**
  * @param $rpcRequest \RpcGateway\Request
  * @throws \Exception
  */
 protected function throwErrorIfRpcRequestIsInvalid($rpcRequest)
 {
     $serviceMethodName = $rpcRequest->getMethodName();
     // create a PHP compatible version of the requested service class
     $serviceClassName = $this->getServiceClassNamespace() . str_replace(Request::METHOD_DELIMITER, '_', $rpcRequest->getClassName());
     try {
         class_exists($serviceClassName);
     } catch (\Exception $exception) {
         throw new \Exception("Invalid rpc.method [" . $rpcRequest->getMethod() . "] (not found) at " . __METHOD__);
     }
     $serviceClassReflection = new \ReflectionClass($serviceClassName);
     if ($serviceClassReflection->isAbstract() || $serviceClassReflection->isInterface() || $serviceClassReflection->isInternal()) {
         throw new \Exception("Invalid rpc.class [" . $rpcRequest->getMethod() . "] at " . __METHOD__);
     }
     if ($serviceClassReflection->hasMethod($serviceMethodName) !== true) {
         throw new \Exception("Invalid rpc.method [" . $rpcRequest->getMethod() . "] (not found) at " . __METHOD__);
     }
     $serviceMethodReflection = $serviceClassReflection->getMethod($serviceMethodName);
     if ($serviceMethodReflection->isAbstract() || $serviceMethodReflection->isConstructor() || $serviceMethodReflection->isStatic() || !$serviceMethodReflection->isPublic()) {
         throw new \Exception("Invalid rpc.method [" . $rpcRequest->getMethod() . "] (not invokable) at " . __METHOD__);
     }
     $argsExpectedMin = $serviceMethodReflection->getNumberOfRequiredParameters();
     $argsExpectedMax = $serviceMethodReflection->getNumberOfParameters();
     $argsOptional = $argsExpectedMax - $argsExpectedMin;
     $argsGiven = count($rpcRequest->getParams());
     if ($argsGiven < $argsExpectedMin || $argsGiven > $argsExpectedMax) {
         $msg = 'Invalid rpc.method [' . $rpcRequest->getMethod() . ']' . " Wrong number of parameters:" . " " . $argsGiven . " given" . " (required: " . $argsExpectedMin . " optional: " . $argsOptional . ")" . " expectedMin: " . $argsExpectedMin . " expectedMax: " . $argsExpectedMax;
         throw new Exception($msg);
     }
 }
 /**
  * Identify concrete extensible interface name based on the class name.
  *
  * @param string $extensibleClassName
  * @return string
  */
 public function getExtensibleInterfaceName($extensibleClassName)
 {
     $exceptionMessage = "Class '{$extensibleClassName}' must implement an interface, " . "which extends from '" . self::EXTENSIBLE_INTERFACE_NAME . "'";
     $notExtensibleClassFlag = '';
     if (isset($this->classInterfaceMap[$extensibleClassName])) {
         if ($notExtensibleClassFlag === $this->classInterfaceMap[$extensibleClassName]) {
             throw new \LogicException($exceptionMessage);
         } else {
             return $this->classInterfaceMap[$extensibleClassName];
         }
     }
     $modelReflection = new \ReflectionClass($extensibleClassName);
     if ($modelReflection->isInterface() && $modelReflection->isSubClassOf(self::EXTENSIBLE_INTERFACE_NAME) && $modelReflection->hasMethod('getExtensionAttributes')) {
         $this->classInterfaceMap[$extensibleClassName] = $extensibleClassName;
         return $this->classInterfaceMap[$extensibleClassName];
     }
     foreach ($modelReflection->getInterfaces() as $interfaceReflection) {
         if ($interfaceReflection->isSubclassOf(self::EXTENSIBLE_INTERFACE_NAME) && $interfaceReflection->hasMethod('getExtensionAttributes')) {
             $this->classInterfaceMap[$extensibleClassName] = $interfaceReflection->getName();
             return $this->classInterfaceMap[$extensibleClassName];
         }
     }
     $this->classInterfaceMap[$extensibleClassName] = $notExtensibleClassFlag;
     throw new \LogicException($exceptionMessage);
 }
Example #10
0
 public function compile()
 {
     foreach (PluginRepository::findAll() as $plugin) {
         $containerBuilder = new UnfreezableContainerBuilder();
         $containerBuilder->registerExtension(new GeneralExtension());
         $extensionClass = new \ReflectionClass('Stagehand\\TestRunner\\DependencyInjection\\Extension\\' . $plugin->getPluginID() . 'Extension');
         if (!$extensionClass->isInterface() && !$extensionClass->isAbstract() && $extensionClass->isSubclassOf('Symfony\\Component\\DependencyInjection\\Extension\\ExtensionInterface')) {
             $containerBuilder->registerExtension($extensionClass->newInstance());
         }
         foreach ($containerBuilder->getExtensions() as $extension) {
             /* @var $extension \Symfony\Component\DependencyInjection\Extension\ExtensionInterface */
             $containerBuilder->loadFromExtension($extension->getAlias(), array());
         }
         $containerBuilder->addCompilerPass(new ReplaceDefinitionByPluginDefinitionPass($plugin));
         $containerBuilder->getCompilerPassConfig()->setOptimizationPasses(array_filter($containerBuilder->getCompilerPassConfig()->getOptimizationPasses(), function (CompilerPassInterface $compilerPass) {
             return !$compilerPass instanceof ResolveParameterPlaceHoldersPass;
         }));
         ErrorReporting::invokeWith(error_reporting() & ~E_USER_DEPRECATED, function () use($containerBuilder) {
             $containerBuilder->compile();
         });
         $phpDumper = new PhpDumper($containerBuilder);
         $containerClass = $plugin->getPluginID() . 'Container';
         $containerClassSource = $phpDumper->dump(array('class' => $containerClass));
         $containerClassSource = preg_replace('/^<\\?php/', '<?php' . PHP_EOL . 'namespace ' . self::COMPILED_CONTAINER_NAMESPACE . ';' . PHP_EOL, $containerClassSource);
         file_put_contents(__DIR__ . '/../' . $containerClass . '.php', $containerClassSource);
     }
 }
 /**
  * Finds installable records from the models folder.
  *
  * @return array
  */
 public function findInstallableRecords()
 {
     $records = array();
     $recordsFolder = craft()->path->getAppPath() . 'records/';
     $recordFiles = IOHelper::getFolderContents($recordsFolder, false, ".*Record\\.php\$");
     foreach ($recordFiles as $file) {
         if (IOHelper::fileExists($file)) {
             $fileName = IOHelper::getFileName($file, false);
             $class = __NAMESPACE__ . '\\' . $fileName;
             // Ignore abstract classes and interfaces
             $ref = new \ReflectionClass($class);
             if ($ref->isAbstract() || $ref->isInterface()) {
                 Craft::log("Skipping record {$file} because it’s abstract or an interface.", LogLevel::Warning);
                 continue;
             }
             $obj = new $class('install');
             if (method_exists($obj, 'createTable')) {
                 $records[] = $obj;
             } else {
                 Craft::log("Skipping record {$file} because it doesn’t have a createTable() method.", LogLevel::Warning);
             }
         } else {
             Craft::log("Skipping record {$file} because it doesn’t exist.", LogLevel::Warning);
         }
     }
     return $records;
 }
Example #12
0
 /**
  * @param  \ReflectionClass|string
  * @return self
  */
 public static function from($from)
 {
     $from = new \ReflectionClass($from instanceof \ReflectionClass ? $from->getName() : $from);
     if (PHP_VERSION_ID >= 70000 && $from->isAnonymous()) {
         $class = new static('anonymous');
     } else {
         $class = new static($from->getShortName(), new PhpNamespace($from->getNamespaceName()));
     }
     $class->type = $from->isInterface() ? 'interface' : (PHP_VERSION_ID >= 50400 && $from->isTrait() ? 'trait' : 'class');
     $class->final = $from->isFinal() && $class->type === 'class';
     $class->abstract = $from->isAbstract() && $class->type === 'class';
     $class->implements = $from->getInterfaceNames();
     $class->documents = $from->getDocComment() ? array(preg_replace('#^\\s*\\* ?#m', '', trim($from->getDocComment(), "/* \r\n\t"))) : array();
     if ($from->getParentClass()) {
         $class->extends = $from->getParentClass()->getName();
         $class->implements = array_diff($class->implements, $from->getParentClass()->getInterfaceNames());
     }
     foreach ($from->getProperties() as $prop) {
         if ($prop->getDeclaringClass()->getName() === $from->getName()) {
             $class->properties[$prop->getName()] = Property::from($prop);
         }
     }
     foreach ($from->getMethods() as $method) {
         if ($method->getDeclaringClass()->getName() === $from->getName()) {
             $class->methods[$method->getName()] = Method::from($method)->setNamespace($class->namespace);
         }
     }
     return $class;
 }
Example #13
0
 public function testCheckInterfaceExtending()
 {
     $refl = new \ReflectionClass('Test\\ExtendedInterface');
     $this->assertTrue($refl->isInterface());
     $this->assertContains('IteratorAggregate', $refl->getInterfaceNames());
     $this->assertContains('Countable', $refl->getInterfaceNames());
 }
Example #14
0
function classData(ReflectionClass $class)
{
    $details = "";
    $name = $class->getName();
    if ($class->isUserDefined()) {
        $details .= "{$name} is user defined\n";
    }
    if ($class->isInternal()) {
        $details .= "{$name} is built-in\n";
    }
    if ($class->isInterface()) {
        $details .= "{$name} is interface\n";
    }
    if ($class->isAbstract()) {
        $details .= "{$name} is an abstract class\n";
    }
    if ($class->isFinal()) {
        $details .= "{$name} is a final class\n";
    }
    if ($class->isInstantiable()) {
        $details .= "{$name} can be instantiated\n";
    } else {
        $details .= "{$name} can not be instantiated\n";
    }
    return $details;
}
 /**
  * Check if all classes given by the cli are instantiable.
  */
 public function run()
 {
     $classNames = array_keys($this->_args);
     //No classes given
     if (!$classNames) {
         exit(1);
     }
     //Perform single checks for the classes
     foreach ($classNames as $className) {
         $reflectionClass = new ReflectionClass($className);
         //Is an interface?
         if ($reflectionClass->isInterface()) {
             echo "Interface";
             exit(1);
         }
         //Is an abstract class?
         if ($reflectionClass->isAbstract()) {
             echo "Abstract";
             exit(1);
         }
         //Is a trait?
         if ($reflectionClass->isTrait()) {
             echo "Trait";
             exit(1);
         }
         //Can create the class with new?
         if (!$reflectionClass->isInstantiable()) {
             echo "Not instantiable";
             exit(1);
         }
     }
     echo 'Done';
 }
Example #16
0
 public function __construct(\ReflectionClass $interface)
 {
     if (!$interface->isInterface() || $interface->isTrait()) {
         throw new \InvalidArgumentException('Only interfaces supported');
     }
     parent::__construct($interface);
 }
    public final function getMockClassHeader(ReflectionClass $class, $test_double_class_name, array $interfaces, array $traits)
    {
        $extends = '';
        if ($class->isInterface()) {
            $interfaces[] = $class->getName();
        } else {
            $extends = 'extends ' . $class->getName();
        }
        $interfaces_str = $interfaces ? 'implements ' . implode(', ', $interfaces) : '';
        $traits[] = 'FBMock_TestDoubleObject';
        $traits_str = 'use ' . implode(', ', $traits) . ';';
        $doc_block = '';
        if (FBMock_Utils::isHHVM()) {
            // Allows mocking final classes and methods.
            // CAUTION: this implementation is subject to change, avoid using outside
            // of FBMock
            $doc_block = '<< __MockClass >>';
        }
        return sprintf(<<<'EOT'
%s
class %s %s %s {
  %s
EOT
, $doc_block, $test_double_class_name, $extends, $interfaces_str, $traits_str);
    }
Example #18
0
 /**
  * Generates a new class with the given class name
  *
  * @param string $newClassName - The name of the new class
  * @param string $mockedClassName - The name of the class being mocked
  * @param Phake_Mock_InfoRegistry $infoRegistry
  * @return NULL
  */
 public function generate($newClassName, $mockedClassName, Phake_Mock_InfoRegistry $infoRegistry)
 {
     $extends = '';
     $implements = '';
     $interfaces = array();
     $constructor = '';
     $mockedClass = new ReflectionClass($mockedClassName);
     if (!$mockedClass->isInterface()) {
         $extends = "extends {$mockedClassName}";
     } elseif ($mockedClassName != 'Phake_IMock') {
         $implements = ", {$mockedClassName}";
         if ($mockedClass->implementsInterface('Traversable') && !$mockedClass->implementsInterface('Iterator') && !$mockedClass->implementsInterface('IteratorAggregate')) {
             if ($mockedClass->getName() == 'Traversable') {
                 $implements = ', Iterator';
             } else {
                 $implements = ', Iterator' . $implements;
             }
             $interfaces = array('Iterator');
         }
     }
     $classDef = "\nclass {$newClassName} {$extends}\n\timplements Phake_IMock {$implements}\n{\n    public \$__PHAKE_info;\n\n    public static \$__PHAKE_staticInfo;\n\n\tconst __PHAKE_name = '{$mockedClassName}';\n\n\tpublic \$__PHAKE_constructorArgs;\n\n\t{$constructor}\n\n\t/**\n\t * @return void\n\t */\n\tpublic function __destruct() {}\n\n \t{$this->generateSafeConstructorOverride($mockedClass)}\n\n\t{$this->generateMockedMethods($mockedClass, $interfaces)}\n}\n";
     $this->loader->loadClassByString($newClassName, $classDef);
     $newClassName::$__PHAKE_staticInfo = $this->createMockInfo($mockedClassName, new Phake_CallRecorder_Recorder(), new Phake_Stubber_StubMapper(), new Phake_Stubber_Answers_NoAnswer());
     $infoRegistry->addInfo($newClassName::$__PHAKE_staticInfo);
 }
Example #19
0
 protected function _checkProtection($protectionType)
 {
     // Check type
     if (!is_string($protectionType) || $protectionType != self::PROTECTION_CSRF && $protectionType != self::PROTECTION_CAPTCHA && $protectionType != self::PROTECTION_BRUTEFORCE && $protectionType != self::PROTECTION_XSS) {
         throw new \Exception('Invalid protection type : "' . $protectionType . '"');
     }
     // Check class
     if (class_exists('framework\\security\\form\\' . ucfirst($protectionType))) {
         $className = 'framework\\security\\form\\' . ucfirst($protectionType);
     } else {
         $className = $protectionType;
     }
     $class = new \ReflectionClass($className);
     if (!in_array('framework\\security\\IForm', $class->getInterfaceNames())) {
         throw new \Exception('Form protection drivers must be implement framework\\security\\IForm');
     }
     if ($class->isAbstract()) {
         throw new \Exception('Form protection drivers must be not abstract class');
     }
     if ($class->isInterface()) {
         throw new \Exception('Form protection drivers must be not interface');
     }
     $classInstance = $class->newInstanceWithoutConstructor();
     $constuctor = new \ReflectionMethod($classInstance, '__construct');
     if ($constuctor->isPrivate() || $constuctor->isProtected()) {
         throw new \Exception('Protection constructor must be public');
     }
     return $className;
 }
Example #20
0
 /**
  * @static
  * @throws phpMorphy_Exception
  * @param string $decorateeClass
  * @param string|null $decoratorClass
  * @param null|phpMorphy_Generator_Decorator_HandlerInterface $handler
  * @return string
  */
 static function generate($decorateeClass, $decoratorClass = null, phpMorphy_Generator_Decorator_HandlerInterface $handler = null)
 {
     if (!class_exists($decorateeClass) && !interface_exists($decorateeClass)) {
         throw new phpMorphy_Exception("Class '{$decorateeClass}' not found");
     }
     if (null === $decoratorClass) {
         $decoratorClass = self::getDecoratorClassName($decorateeClass);
     }
     $helper = new phpMorphy_Generator_ReflectionHelper();
     if (null === $handler) {
         $handler = new phpMorphy_Generator_Decorator_HandlerDefault();
     }
     $classref = new ReflectionClass($decorateeClass);
     // generateHeaderPhpDoc header
     $buffer = $handler->generateHeaderDocComment($decorateeClass, $decoratorClass) . PHP_EOL . PHP_EOL;
     $parents = null;
     $interfaces = null;
     if ($classref->isInterface()) {
         $interfaces = array($decorateeClass);
     } else {
         $parents = array($decorateeClass);
     }
     // generateHeaderPhpDoc class declaration
     $buffer .= $handler->generateClassDeclaration($classref->getDocComment(), $decoratorClass, $parents, $interfaces);
     // generateHeaderPhpDoc common methods
     $buffer .= ' {' . PHP_EOL . $handler->generateCommonMethods($decoratorClass, $decorateeClass) . PHP_EOL . PHP_EOL;
     // generateHeaderPhpDoc wrapped methods
     foreach ($helper->getOverridableMethods($classref) as $method) {
         $buffer .= $handler->generateMethod($method->getDocComment(), $helper->generateMethodModifiers($method, ReflectionMethod::IS_ABSTRACT), $method->returnsReference(), $method->getName(), $helper->generateMethodArguments($method), $helper->generateArgsPass($method)) . PHP_EOL . PHP_EOL;
     }
     $buffer .= '}' . PHP_EOL;
     return $buffer;
 }
 /**
  * Get controller to use, either plugin controller or application controller
  *
  * @param \Cake\Network\Request $request Request object
  * @param \Cake\Network\Response $response Response for the controller.
  * @return mixed name of controller if not loaded, or object if loaded
  */
 protected function _getController($request, $response)
 {
     $pluginPath = $controller = null;
     $namespace = 'Controller';
     if (!empty($request->params['plugin'])) {
         $pluginPath = $request->params['plugin'] . '.';
     }
     if (!empty($request->params['controller'])) {
         $controller = $request->params['controller'];
     }
     if (!empty($request->params['prefix'])) {
         $prefixes = array_map('Cake\\Utility\\Inflector::camelize', explode('/', $request->params['prefix']));
         $namespace .= '/' . implode('/', $prefixes);
     }
     $className = false;
     if ($pluginPath . $controller) {
         $className = App::classname($pluginPath . $controller, $namespace, 'Controller');
     }
     if (!$className) {
         return false;
     }
     $reflection = new \ReflectionClass($className);
     if ($reflection->isAbstract() || $reflection->isInterface()) {
         return false;
     }
     return $reflection->newInstance($request, $response, $controller);
 }
Example #22
0
function __autoload($className)
{
    if (function_exists('smartyAutoload') and smartyAutoload($className)) {
        return true;
    }
    $className = str_replace(chr(0), '', $className);
    $classDir = dirname(__FILE__) . '/../classes/';
    $overrideDir = dirname(__FILE__) . '/../override/classes/';
    $file_in_override = file_exists($overrideDir . $className . '.php');
    $file_in_classes = file_exists($classDir . $className . '.php');
    // This is a Core class and its name is the same as its declared name
    if (substr($className, -4) == 'Core') {
        require_once $classDir . substr($className, 0, -4) . '.php';
    } else {
        if ($file_in_override && $file_in_classes) {
            require_once $classDir . str_replace(chr(0), '', $className) . '.php';
            require_once $overrideDir . $className . '.php';
        } elseif (!$file_in_override && $file_in_classes) {
            require_once $classDir . str_replace(chr(0), '', $className) . '.php';
            $classInfos = new ReflectionClass($className . ((interface_exists($className, false) or class_exists($className, false)) ? '' : 'Core'));
            if (!$classInfos->isInterface() && substr($classInfos->name, -4) == 'Core') {
                eval(($classInfos->isAbstract() ? 'abstract ' : '') . 'class ' . $className . ' extends ' . $className . 'Core {}');
            }
        } elseif ($file_in_override && !$file_in_classes) {
            require_once $overrideDir . $className . '.php';
        }
    }
}
Example #23
0
 /**
  * @return string
  */
 public function getTitle()
 {
     if ($this->_classReflector->isInterface()) {
         $prefix = 'Interface';
     } elseif ($this->_classReflector->isFinal()) {
         $prefix = 'Final class';
     } elseif ($this->_classReflector->isAbstract()) {
         $prefix = 'Abstract class';
     } else {
         $prefix = 'Class';
     }
     $rstClassName = str_replace("\\", "\\\\", $this->_className);
     $rstTitle = "{$prefix} **{$rstClassName}**" . PHP_EOL;
     $rstTitle .= str_repeat('=', strlen($rstTitle) - strlen(PHP_EOL)) . PHP_EOL . PHP_EOL;
     return $rstTitle;
 }
Example #24
0
 protected function addInterface($fqcn)
 {
     $added = new \ReflectionClass($fqcn);
     if (!$added->isInterface()) {
         throw new \LogicException("{$fqcn} is not an interface");
     }
     $this->interfaceList[] = $added;
 }
Example #25
0
 /**
  * @test
  */
 public function testCommon()
 {
     $reflection = new \ReflectionClass('Upwork\\API\\Interfaces\\Client');
     $this->assertTrue($reflection->isInterface());
     $this->assertTrue($reflection->hasMethod('auth'));
     $this->assertTrue($reflection->hasMethod('request'));
     $this->assertTrue($reflection->hasMethod('setupRequestToken'));
 }
 static function getInterfaces($name)
 {
     $reflection = new ReflectionClass($name);
     if ($reflection->isInterface()) {
         return array($name);
     }
     return self::_onlyParents($reflection->getInterfaces());
 }
Example #27
0
 /**
  * Whether instance is concrete implementation
  *
  * @param string $type
  * @return bool
  */
 public function isConcrete($type)
 {
     try {
         $instance = new \ReflectionClass($type);
     } catch (\ReflectionException $e) {
         return false;
     }
     return !$instance->isAbstract() && !$instance->isInterface();
 }
 public function __construct(\ReflectionClass $reflectionClass, \ReflectionProperty $reflectionProperty)
 {
     $reflectionProperty->setAccessible(true);
     if (strpos($reflectionProperty->getDocComment(), "@skipSerialization") !== false) {
         $this->isSkipped = true;
     }
     if (strpos($reflectionProperty->getDocComment(), "@var") === false) {
         throw new PropertyTypeWasNotDefined($reflectionClass->getName(), $reflectionProperty->getName());
     }
     if (preg_match('/@var\\s+([^\\s]+)/', $reflectionProperty->getDocComment(), $matches)) {
         list(, $type) = $matches;
         $types = explode("|", $type);
         if (!empty($types)) {
             foreach ($types as $type) {
                 if ($pos = strpos($type, '[]')) {
                     $this->isArray = true;
                     $type = substr($type, 0, $pos);
                 }
                 if (class_exists($type)) {
                     // Object
                     $this->types[] = $type;
                     $typeReflectionClass = new \ReflectionClass($type);
                     if (!$typeReflectionClass->isInterface() && !$typeReflectionClass->isAbstract()) {
                         $this->isObject = $type;
                     }
                 } else {
                     $typeCheck = $reflectionClass->getNamespaceName() . '\\' . $type;
                     if (class_exists($typeCheck)) {
                         // Object
                         $this->types[] = $typeCheck;
                         $typeReflectionClass = new \ReflectionClass($typeCheck);
                         if (!$typeReflectionClass->isInterface() && !$typeReflectionClass->isAbstract()) {
                             $this->isObject = $typeCheck;
                         }
                     } else {
                         $aliases = $this->getAliases($reflectionClass->getFileName());
                         if (array_key_exists($type, $aliases) && class_exists($aliases[$type])) {
                             $type = $aliases[$type];
                             // Object
                             $this->types[] = $type;
                             $typeReflectionClass = new \ReflectionClass($type);
                             if (!$typeReflectionClass->isInterface() && !$typeReflectionClass->isAbstract()) {
                                 $this->isObject = $type;
                             }
                         } else {
                             $this->types[] = $type = null;
                         }
                     }
                 }
             }
             array_unique($this->types);
         }
     }
     $this->reflectionClass = $reflectionClass;
     $this->reflectionProperty = $reflectionProperty;
 }
 private static function loadAllPlugins()
 {
     foreach (Finder::create()->name('/^.+Plugin\\.php$/')->files()->in(__DIR__) as $file) {
         /* @var $file \SplFileInfo */
         $pluginClass = new \ReflectionClass(__NAMESPACE__ . '\\' . $file->getBasename('.php'));
         if (!$pluginClass->isInterface() && !$pluginClass->isAbstract() && $pluginClass->isSubclassOf('Stagehand\\TestRunner\\Core\\Plugin\\IPlugin')) {
             self::$plugins[] = $pluginClass->newInstance();
         }
     }
 }
Example #30
0
 public function auto_fill()
 {
     $test_case = new \ReflectionClass('ztest\\TestCase');
     foreach (get_declared_classes() as $class_name) {
         $r = new \ReflectionClass($class_name);
         if ($r->isSubclassOf($test_case) && !$r->isInterface() && !$r->isAbstract()) {
             $this->add_test(new $class_name());
         }
     }
 }