Example #1
0
 public function routeShutdown(Zend_Controller_Request_Abstract $request)
 {
     if (!in_array(Zend_Controller_Front::getInstance()->getRouter()->getCurrentRouteName(), array('admin', 'admin_language'))) {
         return;
     }
     $resource = new User_Model_Acl_Resource();
     $resource->getAdminPrivileges();
     if ($resource->admin_privileges) {
         //$actionStack = Zend_Controller_Action_HelperBroker::getStaticHelper('ActionStack');
         $actionStack = new Zend_Controller_Plugin_ActionStack();
         foreach ($resource->admin_privileges as $module => $actions) {
             $class = ucfirst($module) . '_AdminController';
             if (!class_exists($class)) {
                 Zend_Loader::loadFile(APPLICATION_PATH . '/modules/' . $module . '/controllers/AdminController.php');
             }
             $reflection = new Zend_Reflection_Class($class);
             $method = null;
             try {
                 if ($method = $reflection->getMethod('menuAction')) {
                     $actionStack->pushStack(new Zend_Controller_Request_Simple('menu', 'admin', $module, array('admin_actions' => array_flip($actions))));
                 }
             } catch (Exception $e) {
             }
         }
     }
 }
Example #2
0
 public function testToString()
 {
     $classReflection = new Zend_Reflection_Class('Zend_Reflection_TestSampleClass6');
     $tag = $classReflection->getMethod('doSomething')->getDocblock()->getTag('descriptionTag');
     $expectedString = "Docblock Tag [ * @descriptionTag ]" . PHP_EOL;
     $this->assertEquals($expectedString, (string) $tag);
 }
Example #3
0
 /**
  * fromReflection() - build a Code Generation PHP Object from a Class Reflection
  *
  * @param Zend_Reflection_Class $reflectionClass
  * @return dmZendCodeGeneratorPhpClass
  */
 public static function fromReflection(Zend_Reflection_Class $reflectionClass)
 {
     $class = new self();
     $class->setSourceContent($class->getSourceContent());
     $class->setSourceDirty(false);
     if ($reflectionClass->getDocComment() != '') {
         $class->setDocblock(Zend_CodeGenerator_Php_Docblock::fromReflection($reflectionClass->getDocblock()));
     }
     $class->setAbstract($reflectionClass->isAbstract());
     $class->setName($reflectionClass->getName());
     if ($parentClass = $reflectionClass->getParentClass()) {
         $class->setExtendedClass($parentClass->getName());
         $interfaces = array_diff($parentClass->getInterfaces(), $reflectionClass->getInterfaces());
     } else {
         $interfaces = $reflectionClass->getInterfaces();
     }
     $class->setImplementedInterfaces($interfaces);
     $properties = array();
     foreach ($reflectionClass->getProperties() as $reflectionProperty) {
         if ($reflectionProperty->getDeclaringClass()->getName() == $class->getName()) {
             $properties[] = Zend_CodeGenerator_Php_Property::fromReflection($reflectionProperty);
         }
     }
     $class->setProperties($properties);
     $methods = array();
     foreach ($reflectionClass->getMethods(-1, 'dmZendReflectionMethod') as $reflectionMethod) {
         if ($reflectionMethod->getDeclaringClass()->getName() == $class->getName()) {
             $methods[] = dmZendCodeGeneratorPhpMethod::fromReflection($reflectionMethod);
         }
     }
     $class->setMethods($methods);
     return $class;
 }
 public static function getCodeKeys()
 {
     if (null === self::$_codeKeys) {
         $r = new Zend_Reflection_Class(__CLASS__);
         self::$_codeKeys = array_flip($r->getConstants());
     }
     return self::$_codeKeys;
 }
Example #5
0
 public function testInterfaceReturn()
 {
     $reflectionClass = new Zend_Reflection_Class('Zend_Reflection_TestSampleClass4');
     $interfaces = $reflectionClass->getInterfaces();
     $this->assertEquals(count($interfaces), 1);
     $interface = array_shift($interfaces);
     $this->assertEquals($interface->getName(), 'Zend_Reflection_TestSampleClassInterface');
 }
Example #6
0
 /**
  * @group ZF-8307
  */
 public function testNamespaceInParam()
 {
     $classReflection = new Zend_Reflection_Class('Zend_Reflection_Docblock_Param_WithNamespace');
     $paramTag = $classReflection->getMethod('doSomething')->getDocblock()->getTag('param');
     $this->assertEquals('Zend\\Foo\\Bar', $paramTag->getType());
     $this->assertEquals('$var', $paramTag->getVariableName());
     $this->assertEquals('desc', $paramTag->getDescription());
 }
 public function testDocblockTags()
 {
     $classReflection = new Zend_Reflection_Class('Zend_Reflection_TestSampleClass5');
     $this->assertEquals($classReflection->getMethod('doSomething')->getDocblock()->hasTag('return'), true);
     $returnTag = $classReflection->getMethod('doSomething')->getDocblock()->getTag('return');
     $this->assertEquals(get_class($returnTag), 'Zend_Reflection_Docblock_Tag_Return');
     $this->assertEquals($returnTag->getType(), 'mixed');
 }
Example #8
0
 public function __construct($object)
 {
     if ($object != null) {
         $refl = new Zend_Reflection_Class(get_class($object));
         $this->getReader()->setFile($refl->getFileName());
         $this->_object = $object;
     }
 }
 /**
  * Prüft ob der Service einen Account benötigt
  * @param string $classname
  * @param string $methodname
  * @return boolean
  */
 private function _authenticateRequired($classname, $methodname)
 {
     try {
         $reflectionClass = new Zend_Reflection_Class($classname);
         return $reflectionClass->getMethod($methodname)->getDocblock()->hasTag('dragonx_account_authenticate');
     } catch (Exception $exception) {
     }
     return false;
 }
Example #10
0
 /**
  * Construção de Objetos para Elementos Internas
  * @param string $name Nome Completo da Classe
  * @return mixed Instância da Classe Solicitada
  * @throws Zend_Controller_Action_Exception Classe Inválida
  */
 private function _build($name, array $params = array())
 {
     if (!(is_string($name) && class_exists($name))) {
         throw new Zend_Controller_Action_Exception('Invalid Class Name');
     }
     // Construção
     $reflect = new Zend_Reflection_Class($name);
     // Retorno da Instância
     return $reflect->newInstance($params);
 }
Example #11
0
 protected function _getProperties()
 {
     $propertyArray = array();
     $class = new Zend_Reflection_Class($this);
     $properties = $class->getProperties();
     foreach ($properties as $property) {
         if ($property->isPublic()) {
             $propertyArray[] = $property->getName();
         }
     }
     return $propertyArray;
 }
Example #12
0
 /**
  * Returns the URL for the given class' API page 
  * 
  * @param mixed $class 
  * @access protected
  * @return string
  */
 protected function _getClassUrl($class)
 {
     $reflection = new Zend_Reflection_Class($class);
     $docblock = $reflection->getDocblock();
     $url = $this->_zendApiUrl;
     if ($docblock->hasTag('package')) {
         $url .= $docblock->getTag('package')->getDescription();
     }
     if ($docblock->hasTag('subpackage')) {
         $url .= '/' . $docblock->getTag('subpackage')->getDescription();
     }
     $url .= '/' . $class . '.html';
     return $url;
 }
 /**
  * Captura um Formulário de Determinado Tipo
  * @param string Nome do Formulário
  * @return Local_Form_FormAbstract Elemento Solicitado
  */
 protected function _getFormReferencia($tipo)
 {
     // Filtro de Dados
     $filter = new Zend_Filter();
     $filter->addFilter(new Zend_Filter_StringToLower())->addFilter(new Zend_Filter_Callback('ucfirst'));
     $tipo = $filter->filter($tipo);
     // Verificação
     if (!in_array($tipo, $this->_references)) {
         throw new Zend_Controller_Action_Exception('Invalid Referencia');
     }
     $classname = 'Application_Form_Referencia_' . $tipo;
     $reflect = new Zend_Reflection_Class($classname);
     return $reflect->newInstance(array());
 }
Example #14
0
 public function InjectDependencies($object)
 {
     $reflectionClass = new \Zend_Reflection_Class($object);
     //$reflectionProperty = new \Zend_Reflection_Property(null, null);
     foreach ($reflectionClass->getProperties() as $reflectionProperty) {
         /** @var \Zend_Reflection_Property $reflectionProperty */
         $reflectionDocComment = $reflectionProperty->getDocComment();
         if ($reflectionDocComment) {
             if ($reflectionDocComment->hasTag("Inject")) {
                 $reflectionDocCommentTag = $reflectionDocComment->getTag("Inject");
                 $dependencyName = $reflectionDocCommentTag->getDescription();
                 $dependency = $this->kernel->Get($dependencyName);
                 $reflectionProperty->setAccessible(true);
                 $reflectionProperty->setValue($object, $dependency);
             }
         }
     }
     //print_r($reflectionClass);
 }
Example #15
0
 /**
  * Trigger Seotoaster plugins hooks
  *
  * @param $method string Method to trigger
  */
 private function _callPlugins($method)
 {
     $enabledPlugins = Tools_Plugins_Tools::getEnabledPlugins();
     if (is_array($enabledPlugins) && !empty($enabledPlugins)) {
         array_walk($enabledPlugins, function ($plugin, $key, $data) {
             try {
                 $name = ucfirst($plugin->getName());
                 Tools_Factory_PluginFactory::validate($name);
                 $reflection = new Zend_Reflection_Class($name);
                 if ($reflection->hasMethod($data['method'])) {
                     $pluginInstance = Tools_Factory_PluginFactory::createPlugin($plugin->getName(), array(), array('websiteUrl' => $data['websiteUrl']));
                     $pluginInstance->{$data}['method']();
                 }
             } catch (Exceptions_SeotoasterException $se) {
                 error_log($se->getMessage());
                 error_log($se->getTraceAsString());
             }
         }, array('method' => $method, 'websiteUrl' => Zend_Controller_Action_HelperBroker::getStaticHelper('Website')->getUrl()));
     }
 }
 /**
  * Check for dependencies and inject them if needed.
  */
 protected function setUp()
 {
     parent::setUp();
     if (Zend_Registry::isRegistered(LoSo_Zend_Application_Bootstrap_SymfonyContainerBootstrap::getRegistryIndex()) && ($container = Zend_Registry::get(LoSo_Zend_Application_Bootstrap_SymfonyContainerBootstrap::getRegistryIndex())) instanceof \Symfony\Component\DependencyInjection\ContainerInterface) {
         $r = new Zend_Reflection_Class($this);
         $properties = $r->getProperties();
         foreach ($properties as $property) {
             if ($property->getDocComment() && $property->getDocComment()->hasTag('Inject')) {
                 $injectTag = $property->getDocComment()->getTag('Inject');
                 $serviceName = $injectTag->getDescription();
                 if (empty($serviceName)) {
                     $serviceName = $this->_formatServiceName($property->getName());
                 }
                 if ($container->has($serviceName)) {
                     $property->setAccessible(true);
                     $property->setValue($this, $container->get($serviceName));
                 }
             }
         }
     }
 }
 /**
  * Takes care of injecting controller dependencies
  * into the controller at runtime.
  */
 public function preDispatch()
 {
     $actionController = $this->getActionController();
     $r = new Zend_Reflection_Class($actionController);
     $properties = $r->getProperties();
     foreach ($properties as $property) {
         if ($property->getDeclaringClass()->getName() == get_class($actionController)) {
             if ($property->getDocComment() && $property->getDocComment()->hasTag('InjectService')) {
                 $tag = $property->getDocComment()->getTag('InjectService');
                 if ($tag->getDescription()) {
                     $sc = Zend_Registry::get('sc');
                     $service = $sc->getService(trim(lcfirst($tag->getDescription())));
                     $property->setAccessible(true);
                     $property->setValue($actionController, $service);
                 } else {
                     throw new Exception("No service key given");
                 }
             }
         }
     }
 }
Example #18
0
 /**
  * Method scan given object for properties which has public getters
  * and generate array of entities-replacements pairs from this method
  * @param $object Object
  * @param $namespace Custom namespace for replacements
  * @return Tools_Content_EntityParser Return self for chaining
  * @throws Exceptions_SeotoasterException
  */
 public function objectToDictionary($object, $namespace = null)
 {
     if (!is_object($object)) {
         throw new Exceptions_SeotoasterException('Given variable must be an object');
     }
     $reflection = new Zend_Reflection_Class($object);
     $dictionary = array();
     foreach ($reflection->getProperties() as $prop) {
         $normalizedPropName = join('', array_map('ucfirst', explode('_', $prop->getName())));
         $getter = 'get' . join('', array_map('ucfirst', explode('_', $prop->getName())));
         if ($reflection->hasMethod($getter)) {
             $replacement = $object->{$getter}();
             $className = empty($namespace) ? preg_replace('/.*_([\\w\\d]*)$/', '$1', $reflection->getName()) : $namespace;
             $entityName = strtolower($className . ':' . $normalizedPropName);
             if (!is_array($replacement) && !is_object($replacement)) {
                 $dictionary[$entityName] = $replacement;
             }
         }
     }
     $this->addToDictionary($dictionary);
     return $this;
 }
Example #19
0
 /**
  * Prüft bei jedem Request ist die Authentifizierung
  * @param Dragon_Json_Server_Request_Http $request
  */
 public function preDispatch(Dragon_Json_Server_Request_Http $request)
 {
     try {
         list($classname, $methodname) = $request->parseMethod();
         $reflectionClass = new Zend_Reflection_Class($classname);
         $tagResource = $reflectionClass->getMethod($methodname)->getDocblock()->getTag('dragonx_acl_resource');
         if (!$tagResource) {
             return;
         }
         $resource = $tagResource->getDescription();
     } catch (Exception $exception) {
         return;
     }
     $resources = array();
     if (Zend_Registry::isRegistered('recordAccount')) {
         $logicAcl = new DragonX_Acl_Logic_Acl();
         $resources = $logicAcl->getResources(Zend_Registry::get('recordAccount'));
     }
     if (!in_array($resource, $resources)) {
         throw new Dragon_Application_Exception_System('missing resource', array('resource' => $resource));
     }
 }
 /**
  * @group ZF-6444
  */
 public function testPropertyWillLoadFromReflection()
 {
     $reflectionClass = new Zend_Reflection_Class('Zend_CodeGenerator_Php_TestClassWithManyProperties');
     // test property 1
     $reflProp = $reflectionClass->getProperty('_bazProperty');
     $cgProp = Zend_CodeGenerator_Php_Property::fromReflection($reflProp);
     $this->assertEquals('_bazProperty', $cgProp->getName());
     $this->assertEquals(array(true, false, true), $cgProp->getDefaultValue()->getValue());
     $this->assertEquals('private', $cgProp->getVisibility());
     $reflProp = $reflectionClass->getProperty('_bazStaticProperty');
     // test property 2
     $cgProp = Zend_CodeGenerator_Php_Property::fromReflection($reflProp);
     $this->assertEquals('_bazStaticProperty', $cgProp->getName());
     $this->assertEquals(Zend_CodeGenerator_Php_TestClassWithManyProperties::FOO, $cgProp->getDefaultValue()->getValue());
     $this->assertTrue($cgProp->isStatic());
     $this->assertEquals('private', $cgProp->getVisibility());
 }
 /**
  * _processActionableMethods() - process all methods that can be called on this provider.
  *
  */
 protected function _processActionableMethods()
 {
     $specialtyRegex = '#(.*)(' . implode('|', $this->_specialties) . ')$#i';
     $methods = $this->_providerReflection->getMethods();
     $actionableMethods = array();
     foreach ($methods as $method) {
         $methodName = $method->getName();
         /**
          * the following will determine what methods are actually actionable
          * public, non-static, non-underscore prefixed, classes that dont
          * contain the name "
          */
         if (!$method->getDeclaringClass()->isInstantiable() || !$method->isPublic() || $methodName[0] == '_' || $method->isStatic() || in_array($methodName, array('getContextClasses', 'getName'))) {
             continue;
         }
         /**
          * check to see if the method was a required method by a Zend_Tool_* interface
          */
         foreach ($method->getDeclaringClass()->getInterfaces() as $methodDeclaringClassInterface) {
             if (strpos($methodDeclaringClassInterface->getName(), 'Zend_Tool_') === 0 && $methodDeclaringClassInterface->hasMethod($methodName)) {
                 continue 2;
             }
         }
         $actionableName = ucfirst($methodName);
         if (substr($actionableName, -6) == 'Action') {
             $actionableName = substr($actionableName, 0, -6);
         }
         $actionableMethods[$methodName]['methodName'] = $methodName;
         $matches = null;
         if (preg_match($specialtyRegex, $actionableName, $matches)) {
             $actionableMethods[$methodName]['actionName'] = $matches[1];
             $actionableMethods[$methodName]['specialty'] = $matches[2];
         } else {
             $actionableMethods[$methodName]['actionName'] = $actionableName;
             $actionableMethods[$methodName]['specialty'] = '_Global';
         }
         // get the action, and create non-existent actions when they dont exist (the true part below)
         $action = $this->_registry->getActionRepository()->getAction($actionableMethods[$methodName]['actionName']);
         if ($action == null) {
             $action = new Zend_Tool_Framework_Action_Base($actionableMethods[$methodName]['actionName']);
             $this->_registry->getActionRepository()->addAction($action);
         }
         $actionableMethods[$methodName]['action'] = $action;
         if (!in_array($actionableMethods[$methodName]['action'], $this->_actions)) {
             $this->_actions[] = $actionableMethods[$methodName]['action'];
         }
         $parameterInfo = array();
         $position = 1;
         foreach ($method->getParameters() as $parameter) {
             $currentParam = $parameter->getName();
             $parameterInfo[$currentParam]['position'] = $position++;
             $parameterInfo[$currentParam]['optional'] = $parameter->isOptional();
             $parameterInfo[$currentParam]['default'] = $parameter->isOptional() ? $parameter->getDefaultValue() : null;
             $parameterInfo[$currentParam]['name'] = $currentParam;
             $parameterInfo[$currentParam]['type'] = 'string';
             $parameterInfo[$currentParam]['description'] = null;
         }
         $matches = null;
         if (($docComment = $method->getDocComment()) != '' && preg_match_all('/@param\\s+(\\w+)+\\s+(\\$\\S+)\\s+(.*?)(?=(?:\\*\\s*@)|(?:\\*\\/))/s', $docComment, $matches)) {
             for ($i = 0; $i <= count($matches[0]) - 1; $i++) {
                 $currentParam = ltrim($matches[2][$i], '$');
                 if ($currentParam != '' && isset($parameterInfo[$currentParam])) {
                     $parameterInfo[$currentParam]['type'] = $matches[1][$i];
                     $descriptionSource = $matches[3][$i];
                     if ($descriptionSource != '') {
                         $parameterInfo[$currentParam]['description'] = trim($descriptionSource);
                     }
                 }
             }
         }
         $actionableMethods[$methodName]['parameterInfo'] = $parameterInfo;
     }
     $this->_actionableMethods = $actionableMethods;
 }
Example #22
0
 /**
  * Generate map of public class attributes
  * 
  * @param  string $typename type name
  * @param  DOMElement $typexml target XML element 
  * @return void
  */
 protected function _addClassAttributes($typename, DOMElement $typexml)
 {
     // Do not try to autoload here because _phpTypeToAS should
     // have already attempted to load this class
     if (!class_exists($typename, false)) {
         return;
     }
     $rc = new Zend_Reflection_Class($typename);
     foreach ($rc->getProperties() as $prop) {
         if (!$prop->isPublic()) {
             continue;
         }
         $propxml = $this->_xml->createElement('property');
         $propxml->setAttribute('name', $prop->getName());
         $type = $this->_registerType($this->_getPropertyType($prop));
         $propxml->setAttribute('type', $type);
         $typexml->appendChild($propxml);
     }
 }
 public function testToString()
 {
     $classReflection = new Zend_Reflection_Class('Zend_Reflection_TestSampleClass5');
     $classDocblock = $classReflection->getDocblock();
     $expectedString = 'Docblock [ /* Docblock */ ] {' . PHP_EOL . PHP_EOL . '  - Tags [1] {' . PHP_EOL . '    Docblock Tag [ * @author ]' . PHP_EOL . '  }' . PHP_EOL . '}' . PHP_EOL;
     $this->assertEquals($expectedString, (string) $classDocblock);
 }
Example #24
0
 public function testGetDeclaringFileReturnsFilename()
 {
     $reflectionClass = new Zend_Reflection_Class('Zend_Reflection_TestSampleClass2');
     $this->assertContains('TestSampleClass.php', $reflectionClass->getDeclaringFile()->getFileName());
     //ns(, $reflectionClass->getDeclaringFile());
 }
Example #25
0
 /**
  *
  * @return ThemeHouse_Reflection_Method
  */
 public function getMethod($name, $reflectionClass = 'ThemeHouse_Reflection_Method')
 {
     return parent::getMethod($name, $reflectionClass);
 }
Example #26
0
 /**
  * Add a confirmation code to the form using the {@link Zend_Form_Element_Hash}
  * useful to avoid CSRF attack and prevent resubmission of forms
  *
  * @return void
  */
 protected function addConfirmationCode()
 {
     $class = new Zend_Reflection_Class($this);
     $name = $class->getName() . '_confirmcode';
     $this->addElement('hash', $name, array('decorators' => array('viewHelper'), 'ignore' => true));
 }
Example #27
0
 /**
  * @param  string $method
  * @return Zend_Reflection_Parameter
  */
 private function getFirstReflectionParameter($method)
 {
     $reflClass = new Zend_Reflection_Class('Zend_CodeGenerator_Php_ParameterExample');
     $method = $reflClass->getMethod($method);
     $params = $method->getParameters();
     return array_shift($params);
 }
Example #28
0
 /**
  * @group ZF-8307
  */
 public function testReturnClassWithNamespace()
 {
     $classReflection = new Zend_Reflection_Class('Zend_Reflection_Docblock_Param_WithNamespace');
     $paramTag = $classReflection->getMethod('doSomething')->getDocblock()->getTag('return');
     $this->assertEquals('Zend\\Reflection\\Docblock', $paramTag->getType());
 }
Example #29
0
 public function testType()
 {
     $classReflection = new Zend_Reflection_Class('Zend_Reflection_TestSampleClass5');
     $paramTag = $classReflection->getMethod('doSomething')->getDocblock()->getTag('return');
     $this->assertEquals($paramTag->getType(), 'mixed');
 }
Example #30
0
 protected function _getClassAnnotations($class)
 {
     $annotations = array();
     // TODO: Go up to parent classes (let subclasses override tags from parent classes)
     $reflectionClass = new Zend_Reflection_Class($class);
     foreach ($reflectionClass->getProperties() as $property) {
         $docblock = $property->getDocComment();
         if ($docblock) {
             $tags = $docblock->getTags('firephp');
             if ($tags) {
                 foreach ($tags as $tag) {
                     list($name, $value) = $this->_parseAnnotationTag($tag);
                     $annotations['$' . $property->getName()][$name] = $value;
                 }
             }
         }
     }
     return $annotations;
 }