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'); }
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); }
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) { } } } }
/** * @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()); }
/** * 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; }
public function testMethodReturns() { $reflectionClass = new Zend_Reflection_Class('Zend_Reflection_TestSampleClass2'); $methodByName = $reflectionClass->getMethod('getProp1'); $this->assertEquals('Zend_Reflection_Method', get_class($methodByName)); $methodsAll = $reflectionClass->getMethods(); $this->assertEquals(3, count($methodsAll)); $firstMethod = array_shift($methodsAll); $this->assertEquals('getProp1', $firstMethod->getName()); }
/** * 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)); } }
/** * @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); }
/** * @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()); }
/** * * @return ThemeHouse_Reflection_Method */ public function getMethod($name, $reflectionClass = 'ThemeHouse_Reflection_Method') { return parent::getMethod($name, $reflectionClass); }
public function testType() { $classReflection = new Zend_Reflection_Class('Zend_Reflection_TestSampleClass5'); $paramTag = $classReflection->getMethod('doSomething')->getDocblock()->getTag('return'); $this->assertEquals($paramTag->getType(), 'mixed'); }
/** * Document a web service along with its response * * @param string $classname The service class name * @param string $methodname The service method name * @param string $response The server response * @return string * @author Mark Nielsen */ public function document($classname, $methodname, $response) { $markup = ''; if (!empty($methodname)) { mr_bootstrap::zend(); require_once 'Zend/Reflection/Class.php'; $class = new Zend_Reflection_Class($classname); $method = $class->getMethod($methodname); $phpdoc = $method->getDocblock(); $params = $method->getParameters(); $description = $phpdoc->getShortDescription(); $longdesc = $phpdoc->getLongDescription(); if (!empty($longdesc)) { $description .= "\n{$longdesc}"; } $markup .= "h2. {$methodname}\n"; $markup .= "*Description:*\n{$description}\n\n"; $markup .= "*Parameters:*\n"; $markup .= "* _string_ *method*: (Required) Must be set to '{$methodname}'\n"; /** @var $params Zend_Reflection_Parameter[] */ foreach ($params as $param) { $name = $param->getName(); $tags = $phpdoc->getTags('param'); if (isset($tags[$param->getPosition()])) { $tag = $tags[$param->getPosition()]; $typestr = '_' . $tag->getType() . '_ '; $descstr = $tag->getDescription(); } else { $typestr = $descstr = ''; } if ($param->isOptional() and $param->isDefaultValueAvailable()) { $default = $param->getDefaultValue(); if (is_null($default)) { $default = 'NULL'; } else { if (!is_numeric($default) and is_string($default)) { $default = "'{$default}'"; } } $descstr = "(Optional, default = {$default}) {$descstr}"; } else { if ($param->isOptional()) { $descstr = "(Optional) {$descstr}"; } else { $descstr = "(Required) {$descstr}"; } } $markup .= "* {$typestr}*{$name}*: {$descstr}\n"; } $markup .= "\n*Example Response:*\n"; if ($simplexml = @simplexml_load_string($response)) { $dom = dom_import_simplexml($simplexml)->ownerDocument; $dom->formatOutput = true; $markup .= "{code:xml}\n"; $markup .= trim($dom->saveXML()); $markup .= "\n{code}\n"; } else { if (($json = json_decode($response)) !== NULL) { $markup .= "{noformat}\n"; $markup .= $response; $markup .= "\n{noformat}\n\n"; $markup .= "*Example Response (decoded JSON):*\n"; $markup .= "{noformat}\n"; $markup .= trim(print_r($json, true)); $markup .= "\n{noformat}\n"; } else { $markup .= "{noformat}\n"; $markup .= trim($response); $markup .= "\n{noformat}\n"; } } $markup = $this->generalize_text($markup); // Add to overall markup string $this->markup .= "{$markup}\n\n"; } return $markup; }
public function testVariableName() { $classReflection = new Zend_Reflection_Class('Zend_Reflection_TestSampleClass5'); $paramTag = $classReflection->getMethod('doSomething')->getDocblock()->getTag('param'); $this->assertEquals($paramTag->getVariableName(), '$one'); }