本文整理汇总了PHP中Doctrine\Common\Annotations\Reader类的典型用法代码示例。如果您正苦于以下问题:PHP Reader类的具体用法?PHP Reader怎么用?PHP Reader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Reader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: readFormType
private static function readFormType(\Doctrine\Common\Annotations\Reader $reader, \ReflectionClass $rc, array &$out, array &$non_deep_fields)
{
$as = $reader->getClassAnnotations($rc);
$annot = null;
if ($as) {
foreach ($as as $_annot) {
if ($_annot instanceof \Symforce\AdminBundle\Compiler\Annotation\FormType) {
if (null !== $annot) {
throw new \Exception(sprintf("sf_admin.form.type ( class: %s ) has multi form annotation", $rc->getName()));
}
$annot = $_annot;
}
}
}
if ($annot) {
foreach ($annot as $key => $value) {
if (!isset($out[$key]) || null === $out[$key]) {
if (!$out['deep'] || !in_array($key, $non_deep_fields)) {
$out[$key] = $value;
}
}
}
}
$parent = $rc->getParentClass();
if ($parent && !$parent->isAbstract()) {
$out['deep']++;
self::readFormType($reader, $parent, $out, $non_deep_fields);
}
}
示例2: setUp
protected function setUp()
{
AnnotationRegistry::registerLoader('class_exists');
$this->reader = new SimpleAnnotationReader();
$this->reader->addNamespace('Bazinga\\Bundle\\GeocoderBundle\\Mapping\\Annotations');
$this->driver = new AnnotationDriver($this->reader);
}
示例3: getForm
public function getForm(ResourceInterface $resource)
{
$resourceClassName = \Doctrine\Common\Util\ClassUtils::getClass($resource);
$resourceParts = explode("\\", $resourceClassName);
$resourceParts[count($resourceParts) - 2] = 'Form';
$resourceParts[count($resourceParts) - 1] .= 'Type';
$formType = implode("\\", $resourceParts);
if (class_exists($formType)) {
return $this->formFactory->create(new $formType(), $resource);
}
$options = array('data_class' => $resourceClassName);
$builder = $this->formFactory->createBuilder('form', $resource, $options);
$reflectionClass = new \ReflectionClass($resourceClassName);
$annotationClass = 'uebb\\HateoasBundle\\Annotation\\FormField';
foreach ($reflectionClass->getProperties() as $propertyReflection) {
/**
* @var \uebb\HateoasBundle\Annotation\FormField $annotation
*/
$annotation = $this->annotationReader->getPropertyAnnotation($propertyReflection, $annotationClass);
if ($annotation) {
$builder->add($propertyReflection->getName(), $annotation->type, is_array($annotation->options) ? $annotation->options : array());
}
}
$form = $builder->getForm();
return $form;
}
示例4: fillFromArray
/**
* @param $object
* @param $classRefl
* @param $segmentData
* @throws MandatorySegmentPieceMissing
*/
protected function fillFromArray($object, $classRefl, $segmentData)
{
foreach ($classRefl->getProperties() as $propRefl) {
$isSegmentPiece = $this->annotationReader->getPropertyAnnotation($propRefl, SegmentPiece::class);
if ($isSegmentPiece) {
$piece = isset($segmentData[$isSegmentPiece->position]) ? $segmentData[$isSegmentPiece->position] : null;
$propRefl->setAccessible(true);
if ($isSegmentPiece->parts) {
$value = array();
$i = 0;
foreach ($isSegmentPiece->parts as $k => $part) {
if (!is_numeric($k) && is_array($part)) {
$partName = $k;
if (!empty($piece) && in_array("@mandatory", $part) && $this->isEmpty($piece[$i])) {
throw new MandatorySegmentPieceMissing(sprintf("Segment %s part %s missing value at offset %d", $segmentData[0], $partName, $i));
}
} else {
$partName = $part;
}
$value[$partName] = isset($piece[$i]) ? $piece[$i] : null;
++$i;
}
$propRefl->setValue($object, $value);
} else {
$propRefl->setValue($object, $piece);
}
}
}
}
示例5: getEntityClassName
/**
* @internal
* @param Reader $annotationReader
* @return string
* @throws InvalidAnnotationException
*/
static function getEntityClassName(Reader $annotationReader)
{
$reflect = new ReflectionClass(get_called_class());
$annotation = $annotationReader->getClassAnnotation($reflect, Entity::class);
InvalidAnnotationException::assert($annotation, Entity::class);
return $annotation->className;
}
示例6: loadClassMetadata
/**
* {@inheritdoc}
*/
public function loadClassMetadata(ClassMetadata $metadata)
{
$reflClass = $metadata->getReflectionClass();
$className = $reflClass->name;
$loaded = false;
foreach ($reflClass->getProperties() as $property) {
if ($property->getDeclaringClass()->name == $className) {
foreach ($this->reader->getPropertyAnnotations($property) as $groups) {
if ($groups instanceof Groups) {
foreach ($groups->getGroups() as $group) {
$metadata->addAttributeGroup($property->name, $group);
}
}
$loaded = true;
}
}
}
foreach ($reflClass->getMethods() as $method) {
if ($method->getDeclaringClass()->name == $className) {
foreach ($this->reader->getMethodAnnotations($method) as $groups) {
if ($groups instanceof Groups) {
if (preg_match('/^(get|is)(.+)$/i', $method->name, $matches)) {
foreach ($groups->getGroups() as $group) {
$metadata->addAttributeGroup(lcfirst($matches[2]), $group);
}
} else {
throw new \BadMethodCallException(sprintf('Groups on "%s::%s" cannot be added. Groups can only be added on methods beginning with "get" or "is".', $className, $method->name));
}
}
$loaded = true;
}
}
}
return $loaded;
}
示例7: loadMetadata
/**
* {@inheritDoc}
*/
public function loadMetadata($class)
{
// Try get object annotation from class
$objectAnnotation = null;
$classAnnotations = Reflection::loadClassAnnotations($this->reader, $class, true);
foreach ($classAnnotations as $classAnnotation) {
if ($classAnnotation instanceof ObjectAnnotation) {
if ($objectAnnotation) {
throw new \RuntimeException(sprintf('Many @Transformer\\Object annotation in class "%s".', $class));
}
$objectAnnotation = $classAnnotation;
}
}
if (!$objectAnnotation) {
throw new TransformAnnotationNotFoundException(sprintf('Not found @Object annotations in class "%s".', $class));
}
// Try get properties annotations
$properties = [];
$classProperties = Reflection::getClassProperties($class, true);
foreach ($classProperties as $classProperty) {
$propertyAnnotations = $this->reader->getPropertyAnnotations($classProperty);
foreach ($propertyAnnotations as $propertyAnnotation) {
if ($propertyAnnotation instanceof PropertyAnnotation) {
$property = new PropertyMetadata($propertyAnnotation->propertyName ?: $classProperty->getName(), $propertyAnnotation->groups, $propertyAnnotation->shouldTransform, $propertyAnnotation->expressionValue);
$properties[$classProperty->getName()] = $property;
}
}
}
return new ObjectMetadata($objectAnnotation->transformedClass, $properties);
}
示例8: 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;
}
示例9: processClass
/**
* @param string $className
*
* @return array
*/
public function processClass($className, $path)
{
$reflection = new \ReflectionClass($className);
if (null === $this->reader->getClassAnnotation($reflection, $this->annotationClass)) {
return array();
}
$mappings = array();
$this->output->writeln("Found class: {$className}");
foreach ($reflection->getMethods() as $method) {
/** @var Method[] $annotations */
$annotations = $this->reader->getMethodAnnotations($method);
if (0 == count($annotations)) {
continue;
}
$this->output->writeln(sprintf("Found annotations for method %s::%s.", $method->class, $method->getName()));
foreach ($annotations as $annotation) {
if (!$annotation instanceof Method) {
continue;
}
$this->output->writeln(sprintf("Found mapping: %s::%s --> %s::%s", $method->class, $method->getName(), $annotation->getClass(), $annotation->getMethod()));
$mapping = new Mapping();
$moduleFile = $reflection->getFileName();
$moduleFile = substr($moduleFile, strpos($moduleFile, $path));
$mapping->setOxidClass($annotation->getClass())->setOxidMethod($annotation->getMethod())->setModuleClass($className)->setModuleMethod($method->getName())->setReturn($annotation->hasReturnValue())->setParentExecution($annotation->getParentExecution())->setModuleFile($moduleFile);
$mappings[] = $mapping;
}
}
return $mappings;
}
示例10: loadMetadataForClass
/**
* @param \ReflectionClass $class
*
* @return \Metadata\ClassMetadata
*/
public function loadMetadataForClass(\ReflectionClass $class)
{
$metadata = $this->driver->loadMetadataForClass($class);
foreach ($metadata->propertyMetadata as $key => $propertyMetadata) {
$type = $propertyMetadata->type['name'];
if (!$propertyMetadata->reflection) {
continue;
}
/** @var PropertyMetadata $propertyMetadata */
/** @var HandledType $annot */
$annot = $this->reader->getPropertyAnnotation($propertyMetadata->reflection, HandledType::class);
if (!$annot) {
continue;
}
$isCollection = false;
$collectionType = null;
if (in_array($type, ['array', 'ArrayCollection'], true)) {
$isCollection = true;
$collectionType = $type;
$type = $propertyMetadata->type['params'][0]['name'];
}
$handler = $annot->handler ?: 'Relation';
$newType = sprintf('%s<%s>', $handler, $type);
if ($isCollection) {
$newType = sprintf('%s<%s<%s>>', $collectionType, $handler, $type);
}
$propertyMetadata->setType($newType);
}
return $metadata;
}
示例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
/**
* This event will fire during any controller call.
*
* @param FilterControllerEvent $event
*
* @return type
*
* @throws AccessDeniedHttpException
*/
public function onKernelController(FilterControllerEvent $event)
{
if (!is_array($controller = $event->getController())) {
//return if no controller
return;
}
$object = new \ReflectionObject($controller[0]);
// get controller
$method = $object->getMethod($controller[1]);
// get method
$configurations = $this->reader->getMethodAnnotations($method);
foreach ($configurations as $configuration) {
//Start of annotations reading
if (isset($configuration->grantType) && $controller[0] instanceof BaseProjectController) {
//Found our annotation
$controller[0]->setProjectGrantType($configuration->grantType);
$request = $controller[0]->get('request_stack')->getCurrentRequest();
$id = $request->get('id', false);
if ($id !== false) {
$redirectUrl = $controller[0]->initAction($id, $configuration->grantType);
if ($redirectUrl) {
$event->setController(function () use($redirectUrl) {
return new RedirectResponse($redirectUrl);
});
}
}
}
}
}
示例13: 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));
}
}
示例14: testLoadMetadataForClassAddValuesToMetadata
/**
* @expectedException \Doctrine\Search\Exception\Driver\PropertyDoesNotExistsInMetadataException
*/
public function testLoadMetadataForClassAddValuesToMetadata()
{
$this->reflectionClass->expects($this->once())->method('getProperties')->will($this->returnValue(array()));
$this->reader->expects($this->once())->method('getClassAnnotations')->will($this->returnValue(array(0, new TestSearchable(array()))));
$this->classMetadata->expects($this->once())->method('getReflectionClass')->will($this->returnValue($this->reflectionClass));
$this->annotationDriver->loadMetadataForClass('Doctrine\\Tests\\Models\\Blog\\BlogPost', $this->classMetadata);
}
示例15: 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());
}
}
}