Beispiel #1
0
 public function testReflectionAnnotatedClass()
 {
     $reflection = new ReflectionAnnotatedClass('Example');
     $this->assertTrue($reflection->hasAnnotation('FirstAnnotation'));
     $this->assertTrue($reflection->hasAnnotation('SecondAnnotation'));
     $this->assertFalse($reflection->hasAnnotation('NonExistentAnnotation'));
     $this->assertIsA($reflection->getAnnotation('FirstAnnotation'), 'FirstAnnotation');
     $this->assertIsA($reflection->getAnnotation('SecondAnnotation'), 'SecondAnnotation');
     $annotations = $reflection->getAnnotations();
     $this->assertEqual(count($annotations), 2);
     $this->assertIsA($annotations[0], 'FirstAnnotation');
     $this->assertIsA($annotations[1], 'SecondAnnotation');
     $this->assertFalse($reflection->getAnnotation('NonExistentAnnotation'));
     $this->assertIsA($reflection->getConstructor(), 'ReflectionAnnotatedMethod');
     $this->assertIsA($reflection->getMethod('exampleMethod'), 'ReflectionAnnotatedMethod');
     foreach ($reflection->getMethods() as $method) {
         $this->assertIsA($method, 'ReflectionAnnotatedMethod');
     }
     $this->assertIsA($reflection->getProperty('exampleProperty'), 'ReflectionAnnotatedProperty');
     foreach ($reflection->getProperties() as $property) {
         $this->assertIsA($property, 'ReflectionAnnotatedProperty');
     }
     foreach ($reflection->getInterfaces() as $interface) {
         $this->assertIsA($interface, 'ReflectionAnnotatedClass');
     }
     $this->assertIsA($reflection->getParentClass(), 'ReflectionAnnotatedClass');
 }
Beispiel #2
0
 public function __construct(RootEventDispatcher $EventDispatcher)
 {
     $reflection = new \ReflectionAnnotatedClass(get_class($this));
     foreach ($reflection->getMethods() as $method) {
         if ($method->hasAnnotation('CEP_EventHandler')) {
             $annotation = $method->getAnnotation('CEP_EventHandler');
             $EventDispatcher->addListener($annotation->event, array($method->class, $method->name), $annotation->priority);
         }
     }
 }
 public function testReflectionClassShouldReturnAllMethodsWithNoFilter()
 {
     $reflection = new ReflectionAnnotatedClass('Example');
     $methods = $reflection->getMethods();
     $this->assertEqual(count($methods), 3);
 }
Beispiel #4
0
 /**
  * Parse the routes of the given controller
  * 
  * @param object $controller Controller object.
  * 
  * @return Encaminar
  */
 public function parseRoutes($controller)
 {
     $reflection = new ReflectionAnnotatedClass($controller);
     foreach ($reflection->getMethods() as $method) {
         if ($method->hasAnnotation(self::ANNOTATION)) {
             $annotation = $method->getAnnotation(self::ANNOTATION)->value;
             list($httpMethod, $path) = explode(' ', $annotation);
             $this->addRoute($method, $path, $httpMethod);
         }
     }
     return $this;
 }
Beispiel #5
0
 public function registerInstance($MODULE_NAME, $name, &$obj)
 {
     $name = strtolower($name);
     $this->logger->log('DEBUG', "Registering instance name '{$name}' for module '{$MODULE_NAME}'");
     if (Registry::instanceExists($name)) {
         $this->logger->log('WARN', "Instance with name '{$name}' already registered--replaced with new instance");
     }
     $obj->moduleName = $MODULE_NAME;
     Registry::setInstance($name, $obj);
     // register settings annotated on the class
     $reflection = new ReflectionAnnotatedClass($obj);
     foreach ($reflection->getProperties() as $property) {
         if ($property->hasAnnotation('Setting')) {
             $this->settingManager->add($MODULE_NAME, $property->getAnnotation('Setting')->value, $property->getAnnotation('Description')->value, $property->getAnnotation('Visibility')->value, $property->getAnnotation('Type')->value, $obj->{$property->name}, @$property->getAnnotation('Options')->value, @$property->getAnnotation('Intoptions')->value, @$property->getAnnotation('AccessLevel')->value, @$property->getAnnotation('Help')->value);
         }
     }
     // register commands, subcommands, and events annotated on the class
     $commands = array();
     $subcommands = array();
     foreach ($reflection->getAllAnnotations() as $annotation) {
         if ($annotation instanceof DefineCommand) {
             if (!$annotation->command) {
                 $this->logger->log('WARN', "Cannot parse @DefineCommand annotation in '{$name}'.");
             }
             $command = $annotation->command;
             $definition = array('channels' => $annotation->channels, 'defaultStatus' => $annotation->defaultStatus, 'accessLevel' => $annotation->accessLevel, 'description' => $annotation->description, 'help' => $annotation->help, 'handlers' => array());
             list($parentCommand, $subCommand) = explode(" ", $command, 2);
             if ($subCommand) {
                 $definition['parentCommand'] = $parentCommand;
                 $subcommands[$command] = $definition;
             } else {
                 $commands[$command] = $definition;
             }
             // register command alias if defined
             if ($annotation->alias) {
                 $this->commandAlias->register($MODULE_NAME, $command, $annotation->alias);
             }
         }
     }
     foreach ($reflection->getMethods() as $method) {
         if ($method->hasAnnotation('Setup')) {
             $this->setupHandlers[] = array($name, $method->name);
         } else {
             if ($method->hasAnnotation('HandlesCommand')) {
                 $commandName = $method->getAnnotation('HandlesCommand')->value;
                 $methodName = $method->name;
                 $handlerName = "{$name}.{$method->name}";
                 if (isset($commands[$commandName])) {
                     $commands[$commandName]['handlers'][] = $handlerName;
                 } else {
                     if (isset($subcommands[$commandName])) {
                         $subcommands[$commandName]['handlers'][] = $handlerName;
                     } else {
                         $this->logger->log('WARN', "Cannot handle command '{$commandName}' as it is not defined with @DefineCommand in '{$name}'.");
                     }
                 }
             } else {
                 if ($method->hasAnnotation('Event')) {
                     $this->eventManager->register($MODULE_NAME, $method->getAnnotation('Event')->value, $name . '.' . $method->name, @$method->getAnnotation('Description')->value, @$method->getAnnotation('Help')->value, @$method->getAnnotation('DefaultStatus')->value);
                 }
             }
         }
     }
     foreach ($commands as $command => $definition) {
         $this->commandManager->register($MODULE_NAME, $definition['channels'], implode(',', $definition['handlers']), $command, $definition['accessLevel'], $definition['description'], $definition['help'], $definition['defaultStatus']);
     }
     foreach ($subcommands as $subCommand => $definition) {
         $this->subcommandManager->register($MODULE_NAME, $definition['channels'], implode(',', $definition['handlers']), $subCommand, $definition['accessLevel'], $definition['parentCommand'], $definition['description'], $definition['help'], $definition['defaultStatus']);
     }
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     if ($this->isPropelPluginActive()) {
         $this->loadPropelPeerClasses();
     }
     $app = $arguments['application'];
     $env = $options['environment'];
     $dbg = $options['enabledebug'];
     $file = $arguments['name'];
     $url = $arguments['url'];
     $this->buildControllerFile($file, $app, $env, $dbg);
     $gen = new ckWsdlGenerator(new ckWsdlGeneratorContext($file, $url, null, $env == self::DEFAULT_ENVIRONMENT));
     WSMethod::setCreateMethodNameCallback(array($this, 'generateWSMethodName'));
     $handler_methods = array();
     foreach ($this->getModules() as $module) {
         if ($this->loadModuleClassFile($module)) {
             $yml = $this->loadModuleConfigFile($module);
             if (!isset($yml[$env]) || !is_array($yml[$env])) {
                 $yml[$env] = array();
             }
             $class = new ReflectionAnnotatedClass($module . 'Actions');
             foreach ($class->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
                 try {
                     extract($this->getModuleAndAction($method));
                 } catch (InvalidArgumentException $e) {
                     continue;
                 }
                 if (!$gen->addMethod($method)) {
                     continue;
                 }
                 $name = $method->getAnnotation('WSMethod')->getName();
                 $result = isset($yml[$env][$action]['result']) ? $yml[$env][$action]['result'] : array('class' => 'ckPropertyResultAdapter', 'param' => array('property' => 'result'));
                 $yml[$env][$action] = array('parameter' => array(), 'result' => $result);
                 $handler_methods[$name] = array('module' => $module, 'action' => $action, 'parameter' => array());
                 foreach (ckDocBlockParser::parseParameters($method->getDocComment()) as $param) {
                     $yml[$env][$action]['parameter'][] = $handler_methods[$name]['parameter'][] = $param['name'];
                 }
             }
             if (!empty($yml[$env])) {
                 $this->saveModuleConfigFile($module, $yml);
             }
         }
     }
     $this->buildHandlerFile($file);
     $this->buildBaseHandlerFile($file, $handler_methods);
     $file = sprintf('%s/%s.wsdl', sfConfig::get('sf_web_dir'), $file);
     $gen->save($file);
     $this->logSection('file+', $file);
 }
 /**
  * 
  * @param String $filename réal path of the php file to scan ex: /home/project/src/org/foo/bar.php
  * @param String $namespace the name space of this file ex: org\foo
  * @return void
  * @throws IocException
  */
 protected function scanFile($filename, $namespace)
 {
     if (!is_file($filename)) {
         \org\equinox\utils\Logger::error("({$filename}) is not a file!");
         throw new IocException("({$filename}) is not a file!");
     }
     include_once $filename;
     $name = basename($filename);
     $className = $namespace . '\\' . substr($name, 0, strpos($name, '.'));
     if (class_exists($className)) {
         $ref = new \ReflectionAnnotatedClass($className);
         $listAnnotation = $ref->getAllAnnotations();
         if (empty($listAnnotation)) {
             return;
             // this class is not a Component !
         }
         $bean = new BeanDefinition();
         $bean->setClassName($className);
         foreach ($listAnnotation as $annotation) {
             if ($annotation instanceof annotations\ClassAnnotation) {
                 $annotation->doBean($bean, $className);
             }
         }
         if ($bean->getId() == null) {
             throw new IocException("Equinox annotation found but no @Component annotation found (mandatory) in {$className}");
         }
         $listProperties = $ref->getProperties();
         foreach ($listProperties as $property) {
             $this->doProperty($bean, $property);
         }
         $listMethod = $ref->getMethods();
         foreach ($listMethod as $method) {
             $this->doMethod($bean, $method);
         }
         $this->context->addBeanDefinition($bean);
     }
 }