本文整理汇总了PHP中Doctrine\Common\Annotations\Reader::getMethodAnnotation方法的典型用法代码示例。如果您正苦于以下问题:PHP Reader::getMethodAnnotation方法的具体用法?PHP Reader::getMethodAnnotation怎么用?PHP Reader::getMethodAnnotation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Annotations\Reader
的用法示例。
在下文中一共展示了Reader::getMethodAnnotation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processMethod
/**
* @param Method $method
* @param string $endpoint
*
* @return RpcApiDoc
*/
protected function processMethod(Method $method, $endpoint)
{
/** @var string[] $views */
$views = $method->getContext();
if ($method->includeDefaultContext()) {
$views[] = 'Default';
}
$views[] = 'default';
$request = new Request($method, [], new ParameterBag(['_controller' => $method->getController()]));
/** @var array $controller */
$controller = $this->resolver->getController($request);
$refl = new \ReflectionMethod($controller[0], $controller[1]);
/** @var RpcApiDoc $methodDoc */
$methodDoc = $this->reader->getMethodAnnotation($refl, RpcApiDoc::class);
if (null === $methodDoc) {
$methodDoc = new RpcApiDoc(['resource' => $endpoint]);
}
$methodDoc = clone $methodDoc;
$methodDoc->setEndpoint($endpoint);
$methodDoc->setRpcMethod($method);
if (null === $methodDoc->getSection()) {
$methodDoc->setSection($endpoint);
}
foreach ($views as $view) {
$methodDoc->addView($view);
}
$route = new Route($endpoint);
$route->setMethods([$endpoint]);
$route->setDefault('_controller', get_class($controller[0]) . '::' . $controller[1]);
$methodDoc->setRoute($route);
return $methodDoc;
}
示例2: loadClass
public static function loadClass(ReflectionClass $refl, Reader $reader)
{
$router = Application::instance()->getRouter();
$annotation = $reader->getClassAnnotation($refl, 'Destiny\\Common\\Annotation\\Controller');
if (empty($annotation)) {
return;
}
$methods = $refl->getMethods(ReflectionMethod::IS_PUBLIC);
foreach ($methods as $method) {
// Get all the route annotations
$routes = array();
$annotations = $reader->getMethodAnnotations($method);
for ($i = 0; $i < count($annotations); ++$i) {
if ($annotations[$i] instanceof \Destiny\Common\Annotation\Route) {
$routes[] = $annotations[$i];
}
}
// No routes, continue
if (count($routes) <= 0) {
continue;
}
// We have 1 or many routes, add to the router
$httpMethod = $reader->getMethodAnnotation($method, 'Destiny\\Common\\Annotation\\HttpMethod');
$secure = $reader->getMethodAnnotation($method, 'Destiny\\Common\\Annotation\\Secure');
$feature = $reader->getMethodAnnotation($method, 'Destiny\\Common\\Annotation\\Feature');
for ($i = 0; $i < count($routes); ++$i) {
$router->addRoute(new Route(array('path' => $routes[$i]->path, 'classMethod' => $method->name, 'class' => $refl->name, 'httpMethod' => $httpMethod ? $httpMethod->allow : null, 'secure' => $secure ? $secure->roles : null, 'feature' => $feature ? $feature->features : null)));
}
}
}
示例3: extractAnnotation
private function extractAnnotation(\ReflectionMethod $m, $typeName)
{
if (($a = $this->reader->getMethodAnnotation($m, $typeName)) === null) {
throw new NotFound("Annotation: {$typeName} is not found.");
}
return $a;
}
示例4: onKernelRequest
/**
* @param GetResponseEvent $event
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
* @return bool
*/
public function onKernelRequest(GetResponseEvent $event)
{
if (strpos($event->getRequest()->attributes->get('_controller'), 'Api\\Resource') !== false) {
header('Access-Control-Allow-Origin: *');
$controller = explode('::', $event->getRequest()->attributes->get('_controller'));
$reflection = new \ReflectionMethod($controller[0], $controller[1]);
$scopeAnnotation = $this->reader->getMethodAnnotation($reflection, 'Etu\\Core\\ApiBundle\\Framework\\Annotation\\Scope');
if ($scopeAnnotation) {
$requiredScope = $scopeAnnotation->value;
} else {
$requiredScope = null;
}
if (!$requiredScope) {
$requiredScope = 'public';
}
$request = $event->getRequest();
$token = $request->query->get('access_token');
$access = $this->server->checkAccess($token, $requiredScope);
if (!$access->isGranted()) {
$event->setResponse($this->formatter->format($event->getRequest(), ['error' => $access->getError(), 'error_message' => $access->getErrorMessage()], 403));
} else {
$event->getRequest()->attributes->set('_oauth_token', $access->getToken());
}
}
}
示例5: loadMetadataForMethod
/**
* @param \ReflectionClass $class
* @param \ReflectionMethod $method
* @return null|MethodMetadata
*/
private function loadMetadataForMethod(\ReflectionClass $class, \ReflectionMethod $method)
{
$methodAnnotation = $this->reader->getMethodAnnotation($method, Method::class);
if ($methodAnnotation === null) {
return null;
}
/** @var Method $methodAnnotation */
$methodMetadata = new MethodMetadata($class->name, $method->name);
$methodMetadata->isMethod = true;
$methodMetadata->isFormHandler = $methodAnnotation->formHandler;
$methodMetadata->hasNamedParams = $methodAnnotation->namedParams;
$methodMetadata->isStrict = $methodAnnotation->strict;
$methodMetadata->hasSession = $methodAnnotation->session;
$methodMetadata->addParameters($method->getParameters());
foreach ($this->reader->getMethodAnnotations($method) as $annotation) {
if ($annotation instanceof Parameter) {
if (!empty($annotation->constraints)) {
$methodMetadata->addParameterMetadata($annotation->name, $annotation->constraints, $annotation->validationGroups, $annotation->strict, $annotation->serializationGroups, $annotation->serializationAttributes, $annotation->serializationVersion);
}
}
}
/** @var Result $resultAnnotation */
$resultAnnotation = $this->reader->getMethodAnnotation($method, Result::class);
if ($resultAnnotation) {
$methodMetadata->setResult($resultAnnotation->groups, $resultAnnotation->attributes, $resultAnnotation->version);
}
/** @var Security $securityAnnotation */
$securityAnnotation = $this->reader->getMethodAnnotation($method, Security::class);
if ($securityAnnotation) {
$methodMetadata->authorizationExpression = $securityAnnotation->expression;
}
return $methodMetadata;
}
示例6: onKernelController
/**
* Modifies the Request object to apply configuration information found in
* controllers annotations like the template to render or HTTP caching
* configuration.
*
* @param FilterControllerEvent $event A FilterControllerEvent instance
*
* @return void
*/
public function onKernelController(FilterControllerEvent $event)
{
if (!is_array($controller = $event->getController())) {
return;
}
$className = class_exists('Doctrine\\Common\\Util\\ClassUtils') ? ClassUtils::getClass($controller[0]) : get_class($controller[0]);
$object = new \ReflectionClass($className);
$transactional = $this->reader->getClassAnnotation($object, Transactional::NAME);
if (!$transactional instanceof Transactional) {
return;
}
$avoidTransaction = $this->reader->getMethodAnnotation($object->getMethod($controller[1]), AvoidTransaction::NAME);
if (!is_null($avoidTransaction)) {
return;
}
$request = $event->getRequest();
$modelName = $transactional->model;
$model = new $modelName();
$this->transactionBuilder->setRequestMethod($request->getRealMethod());
$this->transactionBuilder->setRequestSource(Transaction::SOURCE_REST);
$this->transactionBuilder->setRelatedRoute($transactional->relatedRoute);
$ids = [];
foreach ($model->getIds() as $field => $value) {
$ids[$field] = $request->attributes->get($field);
}
$this->transactionBuilder->setRelatedIds($ids);
$this->transactionBuilder->setModel($transactional->model);
$transaction = $this->transactionBuilder->build();
$request->attributes->set('transaction', $transaction);
}
示例7: matchesMethod
/**
* The interceptor is activated for public methods in Transactional annotated components.
*
* {@inheritDoc}
*/
public function matchesMethod(ReflectionMethod $method)
{
$transactionalEnabled = false;
if ($method->isPublic()) {
// Gets method-level annotation.
/** @var Transactional $annotation */
$annotation = $this->reader->getMethodAnnotation($method, Transactional::class);
$transactionalEnabled = $annotation !== null;
if (!$transactionalEnabled) {
// If there is no method-level annotation, gets class-level annotation.
$annotation = $this->reader->getClassAnnotation($method->getDeclaringClass(), Transactional::class);
$transactionalEnabled = $annotation !== null;
}
if ($transactionalEnabled) {
switch ($annotation->getPolicy()) {
case Transactional::NOT_REQUIRED:
$policyName = 'not required';
break;
case Transactional::REQUIRED:
$policyName = 'required';
break;
case Transactional::NESTED:
$policyName = 'nested';
break;
default:
$policyName = 'default';
}
$methodString = $method->getDeclaringClass()->name . '::' . $method->name;
$this->logger->debug('TX policy for \'' . $methodString . '\': ' . $policyName);
$noRollbackExceptionsStr = implode(', ', $annotation->getNoRollbackExceptions() === null ? ['default'] : $annotation->getNoRollbackExceptions());
$this->logger->debug('TX no-rollback exceptions for \'' . $methodString . '\': ' . $noRollbackExceptionsStr);
}
}
return $transactionalEnabled;
}
示例8: loadClass
public static function loadClass(ReflectionClass $refl, Reader $reader, Router $router)
{
$annotation = $reader->getClassAnnotation($refl, 'Destiny\\Common\\Annotation\\Controller');
if (empty($annotation)) {
return;
}
$methods = $refl->getMethods(ReflectionMethod::IS_PUBLIC);
foreach ($methods as $method) {
/** @var Route[] $routes */
$routes = array();
$annotations = $reader->getMethodAnnotations($method);
for ($i = 0; $i < count($annotations); ++$i) {
/** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */
if ($annotations[$i] instanceof \Destiny\Common\Annotation\Route) {
$routes[] = $annotations[$i];
}
}
if (count($routes) <= 0) {
continue;
}
/** @var \Destiny\Common\Annotation\HttpMethod $feature */
$httpMethod = $reader->getMethodAnnotation($method, 'Destiny\\Common\\Annotation\\HttpMethod');
/** @var \Destiny\Common\Annotation\Secure $feature */
$secure = $reader->getMethodAnnotation($method, 'Destiny\\Common\\Annotation\\Secure');
for ($i = 0; $i < count($routes); ++$i) {
$router->addRoute(new Route(array('path' => $routes[$i]->path, 'classMethod' => $method->name, 'class' => $refl->name, 'httpMethod' => $httpMethod ? $httpMethod->allow : null, 'secure' => $secure ? $secure->roles : null)));
}
}
}
示例9: load
/**
* Loads ACL annotations from PHP files
*
* @param AclAnnotationStorage $storage
*/
public function load(AclAnnotationStorage $storage)
{
$configLoader = OroSecurityExtension::getAclAnnotationLoader();
$resources = $configLoader->load();
foreach ($resources as $resource) {
foreach ($resource->data as $file) {
$className = $this->getClassName($file);
if ($className !== null) {
$reflection = $this->getReflectionClass($className);
// read annotations from class
$annotation = $this->reader->getClassAnnotation($reflection, self::ANNOTATION_CLASS);
if ($annotation) {
$storage->add($annotation, $reflection->getName());
} else {
$ancestor = $this->reader->getClassAnnotation($reflection, self::ANCESTOR_CLASS);
if ($ancestor) {
$storage->addAncestor($ancestor, $reflection->getName());
}
}
// read annotations from methods
foreach ($reflection->getMethods() as $reflectionMethod) {
$annotation = $this->reader->getMethodAnnotation($reflectionMethod, self::ANNOTATION_CLASS);
if ($annotation) {
$storage->add($annotation, $reflection->getName(), $reflectionMethod->getName());
} else {
$ancestor = $this->reader->getMethodAnnotation($reflectionMethod, self::ANCESTOR_CLASS);
if ($ancestor) {
$storage->addAncestor($ancestor, $reflection->getName(), $reflectionMethod->getName());
}
}
}
}
}
}
}
示例10: map
/**
* @param $serviceId
* @param $class
* @param $method
*/
public function map($serviceId, $class, $method)
{
$class = new \ReflectionClass($class);
$method = $class->getMethod($method);
$annotations = [];
$annotations[] = $this->reader->getMethodAnnotation($method, self::REGISTER_ANNOTATION_CLASS);
$annotations[] = $this->reader->getMethodAnnotation($method, self::SUBSCRIBE_ANNOTATION_CLASS);
$securityAnnotation = $this->reader->getMethodAnnotation($method, self::SECURITY_ANNOTATION_CLASS);
/* @var $annotation Register */
foreach ($annotations as $annotation) {
if ($annotation) {
/* @var $workerAnnotation Register */
$workerAnnotation = isset($this->workerAnnotationsClasses[$class->getName()]) ? $this->workerAnnotationsClasses[$class->getName()] : null;
if ($workerAnnotation) {
$worker = $workerAnnotation->getName();
} else {
$worker = $annotation->getWorker() ?: "default";
}
$mapping = new URIClassMapping($serviceId, $method, $annotation);
if (isset($this->mappings[$worker][$annotation->getName()])) {
$uri = $annotation->getName();
$className = $this->mappings[$worker][$annotation->getName()]->getMethod()->class;
throw new Exception("The URI '{$uri}' has already been registered in '{$className}' for the worker '{$worker}'");
}
//Set security Annotation
$mapping->setSecurityAnnotation($securityAnnotation);
$this->mappings[$worker][$annotation->getName()] = $mapping;
}
}
}
示例11: invoke
public function invoke(MethodInvocation $invocation)
{
$resource = $invocation->getThis();
$result = $invocation->proceed();
$annotation = $this->reader->getMethodAnnotation($invocation->getMethod(), Annotation\ResourceDelegate::class);
if (isset($annotation)) {
$class = $this->getDelegateClassName($annotation, $resource);
if (!class_exists($class)) {
throw new InvalidAnnotationException('Resource Delegate class is not found.');
}
$method = isset($resource->uri->query['_override']) ? $resource->uri->query['_override'] : $resource->uri->method;
if (stripos($method, $resource->uri->method) !== 0) {
throw new InvalidMatcherException('Overriden method must match to original method');
}
$call = $this->resolveDelegateMethod($method);
if (!method_exists($class, $call)) {
throw new InvalidMatcherException('Resource Delegate method is not found');
}
$delegate = new $class($resource);
$params = $this->paramHandler->getParameters([$delegate, $call], $resource->uri->query);
return call_user_func_array([$delegate, $call], $params);
} else {
$result;
}
}
示例12: onKernelController
/**
* Load JSON API configuration from controller annotations
*
* @param FilterControllerEvent $event
*/
public function onKernelController(FilterControllerEvent $event)
{
$controller = $event->getController();
if (!is_array($controller)) {
return;
}
$config = null;
$refClass = new \ReflectionClass($controller[0]);
if (null !== ($annotation = $this->reader->getClassAnnotation($refClass, ApiRequest::class))) {
/* @var $annotation ApiRequest */
$config = $annotation->toArray();
}
$refMethod = $refClass->getMethod($controller[1]);
if (null !== ($annotation = $this->reader->getMethodAnnotation($refMethod, ApiRequest::class))) {
if (null !== $config) {
$config = array_replace($config, $annotation->toArray());
} else {
$config = $annotation->toArray();
}
}
if (null !== $config) {
if (!array_key_exists('matcher', $config)) {
$config['matcher'] = $this->defMatcher;
}
$event->getRequest()->attributes->set('_jsonapi', $this->factory->createEnvironment($config));
}
}
示例13: supports
/**
* @param \ReflectionMethod $action
* @return bool|Annotation
*/
public function supports(\ReflectionMethod $action)
{
$annotation = $this->reader->getMethodAnnotation($action, $this->annotationClass);
if ($annotation !== null) {
return $annotation;
}
return false;
}
示例14: getMethodAnnotation
/**
* {@inheritdoc}
*/
public function getMethodAnnotation(\ReflectionMethod $method, $annotationName)
{
$annotation = $this->innerReader->getMethodAnnotation($method, $annotationName);
if (null === $annotation) {
return null;
}
return $this->processMethodAnnotation($annotation);
}
示例15: isProtectedByCsrfDoubleSubmit
/**
* @return boolean
*/
private function isProtectedByCsrfDoubleSubmit(\ReflectionClass $class, \ReflectionMethod $method)
{
$annotation = $this->annotationReader->getClassAnnotation($class, 'Bazinga\\Bundle\\RestExtraBundle\\Annotation\\CsrfDoubleSubmit');
if (null !== $annotation) {
return true;
}
$annotation = $this->annotationReader->getMethodAnnotation($method, 'Bazinga\\Bundle\\RestExtraBundle\\Annotation\\CsrfDoubleSubmit');
return null !== $annotation;
}