本文整理汇总了PHP中Doctrine\Common\Annotations\AnnotationReader::getMethodAnnotation方法的典型用法代码示例。如果您正苦于以下问题:PHP AnnotationReader::getMethodAnnotation方法的具体用法?PHP AnnotationReader::getMethodAnnotation怎么用?PHP AnnotationReader::getMethodAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Annotations\AnnotationReader
的用法示例。
在下文中一共展示了AnnotationReader::getMethodAnnotation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateRemotingApi
/**
* Generate Remote API from a list of controllers
*/
public function generateRemotingApi()
{
$list = array();
foreach ($this->remotingBundles as $bundle) {
$bundleRef = new \ReflectionClass($bundle);
$controllerDir = new Finder();
$controllerDir->files()->in(dirname($bundleRef->getFileName()) . '/Controller/')->name('/.*Controller\\.php$/');
foreach ($controllerDir as $controllerFile) {
/** @var SplFileInfo $controllerFile */
$controller = $bundleRef->getNamespaceName() . "\\Controller\\" . substr($controllerFile->getFilename(), 0, -4);
$controllerRef = new \ReflectionClass($controller);
foreach ($controllerRef->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
/** @var $methodDirectAnnotation Direct */
$methodDirectAnnotation = $this->annoReader->getMethodAnnotation($method, 'Tpg\\ExtjsBundle\\Annotation\\Direct');
if ($methodDirectAnnotation !== null) {
$nameSpace = str_replace("\\", ".", $bundleRef->getNamespaceName());
$className = str_replace("Controller", "", $controllerRef->getShortName());
$methodName = str_replace("Action", "", $method->getName());
$list[$nameSpace][$className][] = array('name' => $methodName, 'len' => count($method->getParameters()));
}
}
}
}
return $list;
}
示例2: onKernelRequest
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
$method = $request->attributes->get('_controller');
$class_full = explode("::", $method);
if (sizeof($class_full) != 2) {
return;
}
if ($class_full[1] != "indexAction") {
return;
}
$class = trim($class_full[0]);
$reflectionClass = new \ReflectionClass($class);
$reader = new AnnotationReader();
$hdata = $reader->getClassAnnotation($reflectionClass, 'BOS\\ApiBundle\\Annotations\\BOSApiController');
if ($hdata) {
$i = -1;
$methods = array();
$methodsArray = $reflectionClass->getMethods();
foreach ($methodsArray as $m) {
$currentFullMethod = $class . "::" . $m->getName();
$collection = $this->router->getRouteCollection()->all();
$url = null;
foreach ($collection as $route => $params) {
$defaults = $params->getDefaults();
if (isset($defaults['_controller'])) {
if ($currentFullMethod == $defaults['_controller']) {
$url = $this->router->generate($route);
}
}
}
//die("ffFF");
$rm = new \ReflectionMethod($class . "::" . $m->getName());
$data = $reader->getMethodAnnotation($rm, 'BOS\\ApiBundle\\Annotations\\BOSApiMethod');
if ($data) {
/* Method data, POST OR GET OR ANY */
$mData = $reader->getMethodAnnotation($rm, "Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Method");
$nMethods = array();
if ($mData) {
$nMethods = $mData->getMethods();
}
if (!$url) {
die("BOSApiBundle fatal error: couldn't generate route for: " . $rm->getName());
}
$i++;
$data->url = $url;
$data->methods = $nMethods;
$methods[$i] = $data;
}
}
$message = $this->render->render("BOSApiBundle:Default:index.html.twig", array("api_header" => $hdata, "api_methods" => $methods));
$response = new Response($message);
$event->setResponse($response);
}
}
示例3: addMethods
/**
*
* @param \ReflectionClass $class
* @param Object $c_ann
*/
public function addMethods(\ReflectionClass $class, $c_ann)
{
if ($this->isEvent($c_ann)) {
foreach ($class->getMethods() as $ref_met) {
$annotation = $this->reader->getMethodAnnotation($ref_met, 'DIPcom\\AnnEvents\\Mapping\\Target');
if ($annotation) {
$this->guideline->addEvent($ref_met, $annotation);
}
}
}
}
示例4: testPdfAnnotationIsCorrectlyCreatedByReader
/**
* @Pdf()
*/
public function testPdfAnnotationIsCorrectlyCreatedByReader()
{
$reader = new AnnotationReader();
$method = new \ReflectionMethod($this, 'testPdfAnnotationIsCorrectlyCreatedByReader');
$pdf = $reader->getMethodAnnotation($method, 'Ps\\PdfBundle\\Annotation\\Pdf');
$this->assertNotNull($pdf);
}
示例5: invoke
/**
* {@inheritdoc}
*/
public function invoke(MethodInvocation $invocation)
{
$object = $invocation->getThis();
$method = $invocation->getMethod();
$write = ['onPut', 'onDelete', 'onPost'];
$connectionParams = in_array($method->name, $write) ? $this->masterDb : $this->slaveDb;
$pagerAnnotation = $this->reader->getMethodAnnotation($method, 'BEAR\\Sunday\\Annotation\\DbPager');
$db = $this->getDb($pagerAnnotation, $connectionParams);
/* @var $db \BEAR\Package\Module\Database\Dbal\PagerConnection */
if ($this->sqlLogger instanceof SQLLogger) {
$db->getConfiguration()->setSQLLogger($this->sqlLogger);
}
$object->setDb($db);
$result = $invocation->proceed();
if ($this->sqlLogger instanceof DebugStack) {
$this->sqlLogger->stopQuery();
$object->headers['x-sql'] = [$this->sqlLogger->queries];
} elseif ($this->sqlLogger instanceof SQLLogger) {
$this->sqlLogger->stopQuery();
}
if (!$pagerAnnotation) {
return $result;
}
$pagerData = $db->getPager();
if ($pagerData) {
$object->headers['pager'] = $pagerData;
}
return $result;
}
示例6: invoke
/**
* (non-PHPdoc)
* @see Ray\Aop.MethodInterceptor::invoke()
*/
public function invoke(MethodInvocation $invocation)
{
$object = $invocation->getThis();
$method = $invocation->getMethod();
$connectionParams = $method->name !== 'onGet' ? $this->slaveDb : $this->masterDb;
$pagerAnnotation = $this->reader->getMethodAnnotation($method, 'BEAR\\Sunday\\Annotation\\DbPager');
if ($pagerAnnotation) {
$connectionParams['wrapperClass'] = 'BEAR\\Package\\Module\\Database\\DoctrineDbalModule\\Connection';
$db = DriverManager::getConnection($connectionParams);
$db->setMaxPerPage($pagerAnnotation->limit);
} else {
$db = DriverManager::getConnection($connectionParams);
}
/* @var $db \BEAR\Package\Module\Database\DoctrineDbalModule\Connection */
if ($this->sqlLogger instanceof SQLLogger) {
$db->getConfiguration()->setSQLLogger($this->sqlLogger);
}
$object->setDb($db);
$result = $invocation->proceed();
if ($this->sqlLogger instanceof SQLLogger) {
$this->sqlLogger->stopQuery();
$object->headers['x-sql'] = [$this->sqlLogger->queries];
}
if ($pagerAnnotation) {
$pagerData = $db->getPager();
if ($pagerData) {
$object->headers['pager'] = $pagerData;
}
}
return $result;
}
示例7: getMethodAnnotation
public function getMethodAnnotation(\ReflectionMethod $method, $type)
{
$annotation = parent::getMethodAnnotation($method, $type);
if ($annotation !== null && count($annotation) > 1) {
throw new \LogicException(sprintf("There is more than one annotation of type '%s'!", $type));
}
return $annotation !== null ? $annotation[0] : null;
}
示例8: getArrangeDescription
/**
* @param PHPUnit_Framework_Test $test
* @param AnnotationReader $annotationReader
* @param string $arrangeMethod
* @return string
*/
private function getArrangeDescription(PHPUnit_Framework_Test $test, AnnotationReader $annotationReader, $arrangeMethod)
{
$arrangeMethodAnnotation = $annotationReader->getMethodAnnotation(new \ReflectionMethod($test, $arrangeMethod), Arrange::class);
if ($arrangeMethodAnnotation === null) {
throw new \DomainException('The arrange method does not have an annotation itself');
}
return $arrangeMethodAnnotation->getMethods()['describe'];
}
示例9: isServiceCall
/**
* Returns if the given method is a ServiceCall
* @static
* @param \ReflectionMethod $reflectionMethod The method to reflect on
* @param \Doctrine\Common\Annotations\AnnotationReader $reader The annotation reader
* @return bool true if the method is a service call, false otherwise
*/
public static function isServiceCall(\ReflectionMethod $reflectionMethod, \Doctrine\Common\Annotations\AnnotationReader $reader)
{
if ($reader->getMethodAnnotation($reflectionMethod, "PartKeepr\\Service\\Annotations\\ServiceCall") === null) {
return false;
} else {
return true;
}
}
示例10: convert
/**
* @param $object
* @return array
*/
public function convert($object) : array
{
$reflectionObject = new \ReflectionObject($object);
$owners = [];
foreach ($reflectionObject->getProperties() as $property) {
/** @var Owner $annotation */
$annotation = $this->reader->getPropertyAnnotation($property, $this->annotationClass);
if (null !== $annotation) {
$owners[] = $annotation->value;
}
}
foreach ($reflectionObject->getMethods() as $method) {
$annotation = $this->reader->getMethodAnnotation($method, $this->annotationClass);
if (null !== $annotation) {
$owners[] = $method->invoke($object);
}
}
return $owners;
}
示例11: processProperty
/**
* Try to extract the RelationAnnotation from the method.
* If it is found then we set the informations in the static property <code>static::$relationsMapping</code>
*
* @param \ReflectionMethod $method
*
* @throws \Exception
*/
protected function processProperty(\ReflectionMethod $method)
{
$reader = new AnnotationReader();
$relation = $reader->getMethodAnnotation($method, RelationAnnotation::class);
/* @var RelationAnnotation $relation */
if ($relation) {
$class = $this->extractAndCorrectClassIdNeeded($relation, $method);
static::$relationsMapping[$class] = array('class' => $method->class, 'method' => $method->name);
}
}
示例12: connect
/**
* @param Application $app
* @return \Silex\ControllerCollection
*/
public function connect(Application $app)
{
/** @var \Silex\ControllerCollection $controllers */
$controllers = $app['controllers_factory'];
// Routes are already cached using Flint
if (file_exists($app['sys_temp_path'] . 'ProjectUrlMatcher.php')) {
return $controllers;
}
$reflection = new \ReflectionClass($app[$this->controllerName]);
$className = $reflection->getName();
// Needed in order to get annotations
$annotationReader = new AnnotationReader();
//$classAnnotations = $annotationReader->getClassAnnotations($reflection);
$routeAnnotation = new Route(array());
$methodAnnotation = new Method(array());
$methods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
foreach ($methods as $method) {
$methodName = $method->getName();
$controllerName = $this->controllerName . ':' . $methodName;
// Parse only function with the "Action" suffix
if (strpos($methodName, 'Action') === false) {
continue;
}
// Getting all annotations
$routeObjects = $annotationReader->getMethodAnnotations($method);
/** @var Method $routeObject */
$methodObject = $annotationReader->getMethodAnnotation($method, $methodAnnotation);
$methodsToString = 'GET';
if ($methodObject) {
$methodsToString = implode('|', $methodObject->getMethods());
}
/** @var Route $routeObject */
foreach ($routeObjects as $routeObject) {
if ($routeObject && is_a($routeObject, 'Symfony\\Component\\Routing\\Annotation\\Route')) {
$match = $controllers->match($routeObject->getPath(), $controllerName, $methodsToString);
// Setting requirements
$req = $routeObject->getRequirements();
if (!empty($req)) {
foreach ($req as $key => $value) {
$match->assert($key, $value);
}
}
// Setting defaults
$defaults = $routeObject->getDefaults();
if (!empty($defaults)) {
foreach ($defaults as $key => $value) {
$match->value($key, $value);
}
}
$match->bind($controllerName);
}
}
}
return $controllers;
}
示例13: registerRoutes
/**
* @return void
*/
protected function registerRoutes()
{
$reader = new AnnotationReader();
$class = new \ReflectionClass($this);
/** @var RouteCollection $router */
$router = $this->getContainer()->get(Application::CONTAINER_ID_ROUTER);
/** @var \ReflectionMethod $method */
foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
$this->registerRoute($router, $class, $method, $reader->getMethodAnnotation($method, '\\Phprest\\Annotation\\Route'));
}
}
示例14: validate
/**
* Uses the underlying evaluator to extract the endpoint class method
* and its Validator\Validate annotation. If an annotation exists, the
* validateArguments() method is called for the actual validation.
*
* @param string $method Method name
* @param array $arguments Positional or associative argument array
* @throws JsonRpc\Exception\Argument If the validation fails on any of the arguments
*/
private function validate($method, $arguments)
{
/** @var Validate $validateAnnotation */
$reader = new AnnotationReader();
$callable = $this->mapper->getCallable($method);
$filledArguments = $this->mapper->getArguments($callable, $arguments);
$reflectMethod = new ReflectionMethod($callable[0], $callable[1]);
$validateAnnotation = $reader->getMethodAnnotation($reflectMethod, self::VALIDATE_CLASS_NAME);
if ($validateAnnotation) {
$this->validateArguments($filledArguments, $validateAnnotation, $reflectMethod);
}
}
示例15: processProperty
/**
* Try to extract the MethodAnnotation from the method.
* If it is found then we set the informations in the static property <code>static::$pathsMapping</code>
*
* @param \ReflectionMethod $method
*
* @throws \Exception
*/
protected function processProperty(\ReflectionMethod $method)
{
$reader = new AnnotationReader();
$methodAnnotation = $reader->getMethodAnnotation($method, MethodAnnotation::class);
if ($methodAnnotation instanceof MethodAnnotation) {
$this->testParametersValid($method);
$paths = explode('/', $methodAnnotation->path);
$path = '[' . implode('][', $paths) . ']';
$propertyAccessor = PropertyAccess::createPropertyAccessor();
$propertyAccessor->setValue(static::$pathsMapping, $path, array('class' => $method->class, 'method' => $method->name, 'use_key' => $methodAnnotation->key));
}
}