/**
  * @return IAnnotationReflection
  */
 public function getAnnotationReflection()
 {
     if ($this->annotationReflection === null) {
         $this->annotationReflection = AnnotationReflection::build($this->reflectionClass->getDocComment());
     }
     return $this->annotationReflection;
 }
Example #2
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;
 }
 /**
  *
  */
 public function getXmlNamespace()
 {
     $namespace = $this->_parseAnnotation($this->reflection->getDocComment(), 'xmlNamespace');
     if (!$namespace && $this->configuration) {
         $namespace = $this->configuration->getXmlNamespace($this->reflection->getNamespaceName());
     }
     return $namespace;
 }
Example #4
0
 /**
  * @return string|null
  */
 public function description()
 {
     $docComment = $this->class->getDocComment();
     if (!$docComment) {
         return null;
     }
     return $this->parser->parse(implode("\n", array_map(function ($line) {
         return ltrim($line, " *\r\n\t");
     }, array_slice(explode("\n", $docComment), 1, -1))));
 }
 protected function _initClass($class)
 {
     $class = trim($class);
     if (!empty($class)) {
         $this->_class = new \ReflectionClass($class);
         $docComment = $this->_class->getDocComment();
         $docComment = new DocBloc($docComment);
         $this->_annotations = $docComment->getAnnotations();
         $this->_parseProperties();
         $this->_parseMethods();
     }
 }
Example #6
0
 protected function _init()
 {
     $docComment = $this->_reflectionClass->getDocComment();
     $rows = explode("\n", $docComment);
     foreach ($rows as $row) {
         if (preg_match('/\\@property/ui', $row)) {
             $property = new Mongostar_Model_Reflection_Property($row);
             if ($property->name) {
                 $this->_properties[$property->name] = $property;
             }
         }
     }
 }
Example #7
0
 /**
  * @return array[]
  */
 public function getClassAnnotations()
 {
     if (isset($this->classAnnotations)) {
         return $this->classAnnotations;
     }
     $docblock = $this->class->getDocComment();
     if ($docblock === false) {
         $this->classAnnotations = array();
     } else {
         $this->classAnnotations = $this->parser->parse($docblock, "class", $this->_getNamespaces());
     }
     return $this->classAnnotations;
 }
 /**
  * PHPUnit_Retriable_TestCase constructor. Receives the same arguments as
  * {@link PHPUnit_Framework_TestCase::__construct() the standard PHPUnit constructor}.
  *
  * @author Art <a.molcanovas@gmail.com>
  *
  * @param string $name
  * @param array  $data
  * @param string $dataName
  */
 function __construct($name = null, array $data = [], $dataName = '')
 {
     $this->thisReflect = new ReflectionClass($this);
     if ($doc = $this->thisReflect->getDocComment()) {
         $parsed = DocBlockFactoryManager::getFactory()->create($doc);
         if ($parsed->hasTag(SleepTime::NAME)) {
             $this->sleepTime = (int) $parsed->getTagsByName(SleepTime::NAME)[0]->__toString();
         }
         if ($parsed->hasTag(RetryCount::NAME)) {
             $this->retryCount = (int) $parsed->getTagsByName(RetryCount::NAME)[0]->__toString();
         }
     }
     parent::__construct($name, $data, $dataName);
 }
Example #9
0
 /**
  * @param string $class Entity class name
  *
  * @throws Exception\InvalidArgumentException
  * @throws Exception\EntityException
  */
 public function __construct($class)
 {
     $this->className = (string) $class;
     if (!is_subclass_of($this->className, "UniMapper\\Entity")) {
         throw new Exception\InvalidArgumentException("Class must be subclass of UniMapper\\Entity but " . $this->className . " given!", $this->className);
     }
     $reflection = new \ReflectionClass($this->className);
     $this->fileName = $reflection->getFileName();
     foreach ($reflection->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
         if ($property->isStatic()) {
             continue;
         }
         $this->publicProperties[] = $property->getName();
     }
     // Register reflection
     self::load($this);
     $docComment = $reflection->getDocComment();
     // Parse adapter
     try {
         $adapter = Reflection\Annotation::parseAdapter($docComment);
         if ($adapter) {
             list($this->adapterName, $this->adapterResource) = $adapter;
         }
     } catch (Exception\AnnotationException $e) {
         throw new Exception\EntityException($e->getMessage(), $this->className, $e->getDefinition());
     }
     // Parse properties
     $this->_parseProperties($docComment);
 }
Example #10
0
 private static function getActionResult($controller, $action)
 {
     $controller = $controller . '_controller';
     if (!class_exists($controller)) {
         throw new WebException($controller, $action, "Can't find controller - [{$controller}]");
     }
     if (!method_exists($controller, $action)) {
         throw new WebException($controller, $action, "Can't find action [{$action}] in [{$controller}]");
     }
     /**
      * @var Controller $controller
      */
     $controller = DI::get($controller);
     $ref = new \ReflectionClass($controller);
     $controller->attributes = AttributeCollection::create($ref->getDocComment());
     $controller->req = DI::get(Request::class);
     $pageLoadResult = $controller->onPageLoad();
     if (isset($pageLoadResult)) {
         return $pageLoadResult;
     }
     if (!$controller->isEnded) {
         $actionInfo = new ActionInfo($controller, $action);
         try {
             $actionResult = $actionInfo->invoke($controller->req->params(), $controller->req->posts());
             return $actionResult;
         } catch (\Exception $ex) {
             if ($controller instanceof OutputStatusException || $actionInfo->getIfOutputStatusException() || $controller->attributes->exists(OutputStatusExceptionAttribute::class)) {
                 $status = $controller->status($ex->getMessage(), $ex->getCode());
                 return $status;
             }
             throw new WebException($controller, $action, $ex->getMessage(), $ex);
         }
     }
     return null;
 }
Example #11
0
 /**
  * create the path for the cache file
  */
 private function _createPath()
 {
     $config = jApp::config();
     //Check module availability
     if (!isset($config->_modulesPathList[$this->module])) {
         throw new jExceptionSelector('jelix~errors.module.unknown', $this->module);
     }
     //Build controller path
     $this->_ctrlpath = $config->_modulesPathList[$this->module] . 'controllers/' . $this->controller . '.soap.php';
     //Check controller availability
     if (!file_exists($this->_ctrlpath)) {
         throw new jException('jelix~errors.action.unknown', $this->controller);
     }
     //Check controller declaration
     require_once $this->_ctrlpath;
     $this->controllerClassName = $this->controller . 'Ctrl';
     if (!class_exists($this->controllerClassName, false)) {
         throw new jException('jelix~errors.ad.controller.class.unknown', array('jWSDL', $this->controllerClassName, $this->_ctrlpath));
     }
     //Check eAccelerator configuration in order to Reflexion API work
     if (extension_loaded('eAccelerator')) {
         $reflect = new ReflectionClass('jWSDL');
         if ($reflect->getDocComment() == NULL) {
             throw new jException('jsoap~errors.eaccelerator.configuration');
         }
         unset($reflect);
     }
 }
 public function handle()
 {
     $this->checkArgs(array('table'));
     $namespace = array_key_exists('namespace', $this->args) ? $this->args['namespace'] : null;
     if (!isset($namespace)) {
         $namespace = array_key_exists('ns', $this->args) ? $this->args['ns'] : null;
     }
     $table = $this->args['table'];
     $class = array_key_exists('class', $this->args) ? $this->args['class'] : Strings::snakeToCamel($table);
     $path = $this->path($class, $namespace);
     $schema = new TableSchema($table);
     if (file_exists($path)) {
         $content = File::readText($path);
         $className = isset($namespace) ? "{$namespace}\\{$class}" : $class;
         $reflection = new \ReflectionClass($className);
         $header = $reflection->getDocComment();
         if (isset($header)) {
             $content = str_replace($header, Template::generateHeader($schema->columns()), $content);
             unlink($path);
             File::writeText($path, $content);
         }
         Console::line("Model [{$class}] updated in path [{$path}].");
     } else {
         File::writeText($path, Template::generateModel($table, $class, $schema->columns(), $namespace));
         Console::line("Model [{$class}] created in path [{$path}].");
     }
 }
Example #13
0
 /**
  * @inheritdoc
  */
 public function parse($file, $annotationName = null)
 {
     $data = array();
     $class = $this->findClass($file);
     $ref = new \ReflectionClass($class);
     $annotations = $this->resolveAnnotations($ref->getDocComment());
     foreach ($annotations as $annotation) {
         if (!$annotationName || preg_match($annotationName, $annotation['key'])) {
             $data[] = array('class' => $class, 'key' => $annotation['key'], 'value' => (array) Yaml::parse($annotation['value']), 'metadata' => array('class' => $class));
         }
     }
     foreach ($ref->getProperties() as $property) {
         $annotations = $this->resolveAnnotations($property->getDocComment());
         foreach ($annotations as $annotation) {
             if (!$annotationName || preg_match($annotationName, $annotation['key'])) {
                 $data[] = array('property' => $property->getName(), 'key' => $annotation['key'], 'value' => (array) Yaml::parse($annotation['value']), 'metadata' => array('class' => $class));
             }
         }
     }
     foreach ($ref->getMethods() as $method) {
         $annotations = $this->resolveAnnotations($method->getDocComment());
         foreach ($annotations as $annotation) {
             if (!$annotationName || preg_match($annotationName, $annotation['key'])) {
                 $data[] = array('method' => $method->getName(), 'key' => $annotation['key'], 'value' => (array) Yaml::parse($annotation['value']), 'metadata' => array('class' => $class));
             }
         }
     }
     return $data;
 }
Example #14
0
 /**
  *
  * @param string $view
  * @param array  $options
  * @param string $class
  * @return string
  */
 public function document($ns, $view, $options, $class)
 {
     $inspector = new \ReflectionClass($this);
     list($description, $tags) = $this->parseDoccomment($inspector->getDocComment());
     $doc = $this->view($view, ['description' => $description, 'tags' => (array) $tags, 'options' => $options, 'class' => $class], $ns);
     return $doc;
 }
Example #15
0
 /**
  * Run TestCase.
  *
  * @param TestCase $testCase
  *
  * @return int Status code
  */
 public function run(TestCase $testCase)
 {
     $this->precondition($testCase);
     if ($this->tests->count() == 0) {
         $this->logger->notice('Tests not found in TestCase', ['pid' => getmypid()]);
         /** @var EventDispatcherInterface $dispatcher */
         $dispatcher = $this->container->get('dispatcher');
         $dispatcher->dispatch(EventStorage::EV_CASE_FILTERED);
         return 1;
     }
     $statusCode = 0;
     $testCaseEvent = new TestCaseEvent($this->reflectionClass->getName());
     $testCaseEvent->setAnnotations(self::getAnnotations($this->reflectionClass->getDocComment()));
     $this->controller->beforeCase($testCaseEvent);
     foreach ($this->tests as $test) {
         if ($test->getStatus() !== TestMeta::TEST_NEW && $test->getStatus() !== TestMeta::TEST_MARKED) {
             continue;
         }
         if ($this->testMethod($test)) {
             $statusCode = 1;
         }
     }
     $this->controller->afterCase($testCaseEvent);
     return $statusCode;
 }
Example #16
0
 public function preToolbarRendering()
 {
     $rawAdvices = (array) \Debug\Toolbar\Service\DataStorage::get('AOP:Advices');
     $advices = array();
     foreach ($rawAdvices as $key => $value) {
         if (stristr($value['adviceClass'], 'Debug\\Toolbar') && TRUE) {
         } else {
             $key = implode('.', $value);
             if (isset($advices[$key])) {
                 $advices[$key]['counter']++;
             } else {
                 $advices[$key] = $value;
                 $advices[$key]['counter'] = 1;
                 $reflectionClass = new \ReflectionClass($value['adviceClass']);
                 $advices[$key]['classComment'] = $this->cleanupComment($reflectionClass->getDocComment());
                 $advices[$key]['methodComment'] = $this->cleanupComment($reflectionClass->getMethod($value['adviceMethodName'])->getDocComment());
             }
         }
     }
     $table = '';
     foreach ($advices as $advice) {
         $title = '<b>' . $advice['adviceClass'] . '->' . $advice['adviceClass'] . '</b> <br /> <small>Called ' . $advice['counter'] . ' times</small>';
         $content = $advice['joinPointClass'] . '->' . $advice['joinPointMethodName'];
         $table .= '<table class="table table-striped table-bordered small-break signals">';
         $table .= '<tr><th>' . $title . '</th></tr>';
         $table .= '<tr><td class="indent-left">' . $content . '</td></tr>';
         $table .= '</table>';
     }
     \Debug\Toolbar\Service\Collector::getModule('AOP')->getToolbar()->addText('AOP')->addBadge(count($advices))->getPopup()->addHtml($table)->getPanel()->addHtml($table);
 }
 /**
  * @param \Donquixote\HastyPhpAst\PhpToAst\PhpToAstInterface $phpToAst
  * @param string $class
  *
  * @dataProvider providerPhpToAst
  */
 function testPhpToAst(PhpToAstInterface $phpToAst, $class)
 {
     $reflectionClass = new \ReflectionClass($class);
     $file = $reflectionClass->getFileName();
     $php = file_get_contents($file);
     $fileAst = $phpToAst->phpGetAst($php);
     $classNodes = $this->fileAstGetClassNodes($fileAst);
     $this->assertEquals(array(0), array_keys($classNodes));
     $classNode = $classNodes[0];
     $this->assertEquals($reflectionClass->getShortName(), $classNode->getShortName());
     $this->assertEquals($reflectionClass->getDocComment(), $classNode->getDocComment());
     $expectedOwnMethodNames = array();
     foreach ($reflectionClass->getMethods() as $method) {
         if ($method->getDeclaringClass()->getName() === $reflectionClass->getName()) {
             $expectedOwnMethodNames[] = $method->getName();
         }
     }
     $actualOwnMethodNames = array();
     foreach ($classNode->getBody()->getMemberNodes() as $memberNode) {
         if ($memberNode instanceof AstFunctionLikeInterface) {
             $actualOwnMethodNames[] = $memberNode->getShortName();
         }
     }
     $this->assertEquals($expectedOwnMethodNames, $actualOwnMethodNames);
 }
Example #18
0
 /**
  * Testing annotations.
  *
  * @test
  */
 public function testAnnotations()
 {
     $sut = new AsDateTime();
     $reflection = new \ReflectionClass($sut);
     $comments = $reflection->getDocComment();
     $expected = preg_quote('@Annotation');
     $results = preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches);
     $this->assertEquals(1, $results);
     $expected = preg_quote('@Target({"PROPERTY"})');
     $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches));
     $property = $reflection->getProperty('allowNull');
     $comments = $property->getDocComment();
     $expected = preg_quote('@var ') . '(bool|boolean)';
     $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches));
     //
     $property = $reflection->getProperty('min');
     $comments = $property->getDocComment();
     $expected = preg_quote('@var \\DateTime');
     $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches));
     $property = $reflection->getProperty('max');
     //
     $comments = $property->getDocComment();
     $expected = preg_quote('@var \\DateTime');
     $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches));
 }
Example #19
0
 /**
  * Testing annotations.
  *
  * @test
  */
 public function testAnnotations()
 {
     $sut = new AsFloat();
     $reflection = new \ReflectionClass($sut);
     $comments = $reflection->getDocComment();
     $expected = preg_quote('@Annotation');
     $results = preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches);
     $this->assertEquals(1, $results);
     $expected = preg_quote('@Target({"PROPERTY"})');
     $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches));
     $property = $reflection->getProperty('allowNull');
     $comments = $property->getDocComment();
     $expected = preg_quote('@var ') . '(bool|boolean)';
     $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches));
     //
     $property = $reflection->getProperty('precision');
     $comments = $property->getDocComment();
     $expected = preg_quote('@var ') . '(int|integer)';
     $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches));
     //
     $property = $reflection->getProperty('decimalSeparator');
     $comments = $property->getDocComment();
     $expected = preg_quote('@var ') . '(str|string)';
     $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches));
     //
     $property = $reflection->getProperty('digitsSeparator');
     $comments = $property->getDocComment();
     $expected = preg_quote('@var ') . '(str|string)';
     $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches));
 }
 /**
  * @depends testMainClassExists
  */
 public function testThereIsNoNewLineAfterDescriptionByDefault(\ReflectionClass $mainClass)
 {
     $this->markTestIncomplete('Enable after generated classes will have docs');
     $this->assertContains('
  * And by opposing end them?
  */', $mainClass->getDocComment());
 }
Example #21
0
 /**
  * Fetches the class level doc-block and extracts all @property and @property-write tags.
  * If they are in the format <type> <$property> then they are considered a magicProperty
  *
  * @return string['property' => 'type']
  */
 public static function magicProperties()
 {
     $class = get_called_class();
     if (!isset(static::$_properties[$class])) {
         $reflection = new \ReflectionClass($class);
         $properties = [];
         $docBlock = $reflection->getDocComment();
         if ($docBlock) {
             $pattern = '#^\\s*\\*\\s+@property(?:-(\\w*)){0,1}\\s+(\\S+)\\s+(\\$\\S+).*$#im';
             if (preg_match_all($pattern, $docBlock, $matches, PREG_SET_ORDER)) {
                 foreach ($matches as $match) {
                     if (empty($match[1]) || strtolower($match[1] == 'write')) {
                         // Only support writable properties
                         $properties[trim($match[3], '$')] = $match[2];
                     }
                 }
             }
         }
         if (!array_key_exists('_id', $properties)) {
             $properties['_id'] = 'MongoId';
         }
         static::$_properties[$class] = $properties;
     }
     return static::$_properties[$class];
 }
 /**
  * @param Route[] $routes
  */
 protected function displayRoutes(array $routes)
 {
     $routeFilters = [];
     foreach ($routes as $route) {
         $before = array_keys($route->beforeFilters());
         $before = array_unique(array_merge($before, $this->getPatternFilters($route)));
         $after = array_keys($route->afterFilters());
         $routeFilters = array_unique(array_merge($routeFilters, $before, $after));
     }
     natsort($routeFilters);
     foreach ($routeFilters as &$routeFilter) {
         $listenerClosure = Event::getListeners('router.filter: ' . $routeFilter)[0];
         $reflectionFunction = new \ReflectionFunction($listenerClosure);
         $closureParser = new ClosureParser($reflectionFunction);
         $listenerName = $closureParser->getUsedVariables()['listener'];
         if (str_contains($listenerName, '@')) {
             $className = explode('@', $listenerName)[0];
             $reflectionClass = new \ReflectionClass($className);
             $description = substr(explode("\n", $reflectionClass->getDocComment())[1], 3);
         } else {
             $description = 'UNKNOWN';
         }
         $routeFilter = [$routeFilter, $listenerName, $description];
     }
     $this->table(['Filter Name', 'Callback', 'Description'], $routeFilters);
 }
 public function getDocComment()
 {
     // if it's already been retrieved, just return it
     if ($this->docString) {
         return $this->docString;
     }
     // check to see if it's here first
     if ($docString = parent::getDocComment()) {
         $this->docString = $docString;
         return $docString;
     }
     // go through each parent class
     $class = $this->getParentClass();
     while ($class) {
         if ($docString = $class->getDocComment()) {
             $this->docString = $docString;
             break;
         }
         $class = $class->getParentClass();
     }
     // then go through each interface
     foreach ($this->getInterfaces() as $iFace) {
         if ($docString = $iFace->getDocComment()) {
             $this->docString = $docString;
             break;
         }
     }
     return $this->docString;
 }
Example #24
0
 /**
  * Contructs new type reflector instance
  *
  * @param string $type
  * @return KalturaTypeReflector
  */
 public function __construct($type)
 {
     if (!class_exists($type)) {
         throw new KalturaReflectionException("Type \"" . $type . "\" not found");
     }
     $this->_type = $type;
     $reflectClass = new ReflectionClass($this->_type);
     $this->_abstract = $reflectClass->isAbstract();
     $comments = $reflectClass->getDocComment();
     if ($comments) {
         $this->_comments = $comments;
         $commentsParser = new KalturaDocCommentParser($comments);
         $this->_description = $commentsParser->description;
         $this->_deprecated = $commentsParser->deprecated;
         $this->_serverOnly = $commentsParser->serverOnly;
         $this->_package = $commentsParser->package;
         $this->_subpackage = $commentsParser->subpackage;
         $permissions = array();
         $parentType = get_parent_class($this->_type);
         if ($parentType !== false) {
             $parentReflector = KalturaTypeReflectorCacher::get($parentType);
             $permissions = array_merge($permissions, $parentReflector->_permissions);
         }
         if (!is_null($commentsParser->permissions)) {
             $permissions = array_merge($permissions, explode(',', trim($commentsParser->permissions)));
         }
         $this->_permissions = $permissions;
     }
 }
 private function addRouteForController($controllerClass)
 {
     $ref = new ReflectionClass($controllerClass);
     $annotations = $this->reflectionHelper->getAnnotations($ref->getDocComment());
     // these are used by the generated code
     /** @noinspection PhpUnusedLocalVariableInspection */
     $container = $this->container;
     /** @noinspection PhpUnusedLocalVariableInspection */
     $app = $this->app;
     $middlewareAnnotations = $annotations->getWithName('middleware');
     foreach ($annotations->getWithName('route') as $ano) {
         $builder = new RouteBuilder();
         $values = $ano->getValues();
         $builder->setMethod(strtolower($values[0]));
         $builder->setControllerName($controllerClass);
         $builder->setRoute($values[1]);
         preg_match_all('/\\/:([a-z0-9]+)/i', $values[1], $matches);
         foreach ($matches[1] as $match) {
             $builder->addParam($match);
         }
         foreach ($middlewareAnnotations as $midAno) {
             $midValues = $midAno->getValues();
             $builder->addMiddleware($midValues[0]);
         }
         eval($builder->render());
     }
 }
Example #26
0
 /**
  * Testing annotations.
  *
  * @test
  * @covers \Bairwell\Hydrator\Annotations\From
  */
 public function testAnnotations()
 {
     $sut = new From();
     $reflection = new \ReflectionClass($sut);
     $this->assertTrue($reflection->isFinal());
     $properties = $reflection->getDefaultProperties();
     $expectedProperties = ['sources' => [], 'field' => null, 'conditions' => []];
     foreach ($expectedProperties as $k => $v) {
         $this->assertArrayHasKey($k, $properties);
         $this->assertEquals($v, $properties[$k]);
     }
     $comments = $reflection->getDocComment();
     $expected = preg_quote('@Annotation');
     $results = preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches);
     $this->assertEquals(1, $results);
     $expected = preg_quote('@Target({"PROPERTY"})');
     $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches));
     //
     $property = $reflection->getProperty('sources');
     $comments = $property->getDocComment();
     $expected = '@var\\s+array';
     $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches));
     $expected = '@Required';
     $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches));
     // field
     $property = $reflection->getProperty('field');
     $comments = $property->getDocComment();
     $expected = '@var\\s+string';
     $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches));
     // conditions
     $property = $reflection->getProperty('conditions');
     $comments = $property->getDocComment();
     $expected = '@var\\s+array';
     $this->assertEquals(1, preg_match_all('/(\\n|\\r)\\s*\\*\\s+' . $expected . '\\s*(\\n|\\r)/', $comments, $matches));
 }
Example #27
0
 protected function getPropertiesFromAnnotations(\ReflectionClass $reflection, $scalar_only = false, $return_data_types = false)
 {
     $properties = array();
     $docblock_entries = explode("\n", $reflection->getDocComment());
     foreach ($docblock_entries as $entry) {
         $property_start = strpos($entry, '@property');
         if ($property_start !== false) {
             $property_elements = explode(' ', substr($entry, $property_start + 10));
             if (count($property_elements) == 2) {
                 if (!$scalar_only) {
                     $properties[str_replace('$', '', trim($property_elements[1]))] = $property_elements[0];
                 } else {
                     switch ($property_elements[0]) {
                         case 'int':
                         case 'integer':
                         case 'bool':
                         case 'boolean':
                         case 'string':
                         case 'double':
                         case 'float':
                         case 'decimal':
                         case 'array':
                             $properties[str_replace('$', '', trim($property_elements[1]))] = $property_elements[0];
                             break;
                     }
                 }
             }
         }
     }
     $parent = $reflection->getParentClass();
     if ($parent) {
         $properties = array_merge($properties, $this->getPropertiesFromAnnotations($parent, $scalar_only, true));
     }
     return $return_data_types ? $properties : array_keys($properties);
 }
 public function getControllerAuthorization($class)
 {
     $refMethod = new \ReflectionClass($class);
     $doc = $refMethod->getDocComment();
     preg_match_all("/@Authorize/", $doc, $authorizations);
     return $authorizations[0];
 }
Example #29
0
 /**
  * Documentation comment
  *
  * @return ABReflectionDocComment
  */
 public function getDocComment()
 {
     if ($this->docComment === null) {
         $this->docComment = new ABReflectionDocComment(parent::getDocComment());
     }
     return $this->docComment;
 }
Example #30
0
 /**
  * Contructs new type reflector instance
  *
  * @param string $type
  * @return KalturaTypeReflector
  */
 public function KalturaTypeReflector($type)
 {
     //		KalturaLog::debug("Reflecting type [$type]");
     if (!class_exists($type)) {
         throw new KalturaReflectionException("Type \"" . $type . "\" not found");
     }
     $this->_type = $type;
     $reflectClass = new ReflectionClass($this->_type);
     $comments = $reflectClass->getDocComment();
     if ($comments) {
         $this->_comments = $comments;
         $commentsParser = new KalturaDocCommentParser($comments);
         $this->_deprecated = $commentsParser->deprecated;
         $this->_package = $commentsParser->package;
         $this->_subpackage = $commentsParser->subpackage;
         $this->_abstract = $commentsParser->abstract;
         if (!is_null($commentsParser->permissions)) {
             $this->_permissions = explode(',', $commentsParser->permissions);
         }
     }
     if (!$reflectClass->isAbstract()) {
         $constructor = $reflectClass->getConstructor();
         if (!$constructor || $constructor->isPublic()) {
             //				KalturaLog::debug("Instanciating type [$type]");
             $this->_instance = new $type();
         }
     }
 }