本文整理汇总了PHP中Doctrine\Common\Annotations\AnnotationReader::getClassAnnotations方法的典型用法代码示例。如果您正苦于以下问题:PHP AnnotationReader::getClassAnnotations方法的具体用法?PHP AnnotationReader::getClassAnnotations怎么用?PHP AnnotationReader::getClassAnnotations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Annotations\AnnotationReader
的用法示例。
在下文中一共展示了AnnotationReader::getClassAnnotations方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseController
/**
* Parse a controller class.
*
* @param string $class
* @return array
*/
public function parseController($class)
{
$reflectionClass = new ReflectionClass($class);
$classAnnotations = $this->reader->getClassAnnotations($reflectionClass);
$controllerMetadata = [];
$middleware = [];
// find entity parameters and plugins
foreach ($classAnnotations as $annotation) {
// controller attributes
if ($annotation instanceof \ProAI\Annotations\Annotations\Controller) {
$prefix = $annotation->prefix;
$middleware = $this->addMiddleware($middleware, $annotation->middleware);
}
if ($annotation instanceof \ProAI\Annotations\Annotations\Middleware) {
$middleware = $this->addMiddleware($middleware, $annotation->value);
}
// resource controller
if ($annotation instanceof \ProAI\Annotations\Annotations\Resource) {
$resourceMethods = ['index', 'create', 'store', 'show', 'edit', 'update', 'destroy'];
if (!empty($annotation->only)) {
$resourceMethods = array_intersect($resourceMethods, $annotation->only);
} elseif (!empty($annotation->except)) {
$resourceMethods = array_diff($resourceMethods, $annotation->except);
}
$resource = ['name' => $annotation->value, 'methods' => $resourceMethods];
}
}
// find routes
foreach ($reflectionClass->getMethods() as $reflectionMethod) {
$name = $reflectionMethod->getName();
$methodAnnotations = $this->reader->getMethodAnnotations($reflectionMethod);
$routeMetadata = [];
// controller method is resource route
if (!empty($resource) && in_array($name, $resource['methods'])) {
$routeMetadata = ['uri' => $resource['name'] . $this->getResourcePath($name), 'controller' => $class, 'controllerMethod' => $name, 'httpMethod' => $this->getResourceHttpMethod($name), 'as' => $resource['name'] . '.' . $name, 'middleware' => ''];
}
// controller method is route
if ($route = $this->hasHttpMethodAnnotation($name, $methodAnnotations)) {
$routeMetadata = ['uri' => $route['uri'], 'controller' => $class, 'controllerMethod' => $name, 'httpMethod' => $route['httpMethod'], 'as' => $route['as'], 'middleware' => $route['middleware']];
}
// add more route options to route metadata
if (!empty($routeMetadata)) {
if (!empty($middleware)) {
$routeMetadata['middleware'] = $middleware;
}
// add other method annotations
foreach ($methodAnnotations as $annotation) {
if ($annotation instanceof \ProAI\Annotations\Annotations\Middleware) {
$middleware = $this->addMiddleware($middleware, $routeMetadata['middleware']);
}
}
// add global prefix and middleware
if (!empty($prefix)) {
$routeMetadata['uri'] = $prefix . '/' . $routeMetadata['uri'];
}
$controllerMetadata[$name] = $routeMetadata;
}
}
return $controllerMetadata;
}
示例2: getClassAnnotations
/**
* @param string|object $class
* @return array
*/
public function getClassAnnotations($class)
{
$reflectionClass = new \ReflectionClass($class);
$classAnotation = array();
foreach ($this->annotationReader->getClassAnnotations($reflectionClass) as $contraint) {
if ($contraint instanceof Annotations\Synchronizer) {
$classAnotation[] = $contraint;
}
}
return $classAnotation;
}
示例3: loadClassMetadata
/**
* Parse all of the annotations for a given ClassMetadata object
*
* @param ClassMetadata $metadata
*/
public function loadClassMetadata(ClassMetadata $metadata)
{
$reflClass = $metadata->getReflectionClass();
$className = $reflClass->getName();
foreach ($this->reader->getClassAnnotations($reflClass) as $annotation) {
if ($annotation instanceof XmlObject) {
$this->loadClassAttributes($metadata);
$this->loadClassElements($metadata);
$this->loadClassLists($metadata);
$this->loadClassValue($metadata);
}
}
}
示例4: getDefinitions
/**
* @param ReflectionClass $reflection
* @return Definition[]|Generator
*/
private function getDefinitions(ReflectionClass $reflection)
{
$annotations = $this->reader->getClassAnnotations($reflection);
/** @var ServiceDefinition $builder */
foreach ($annotations as $class => $annotation) {
if (isset($this->builders[$class])) {
$builder = $this->builders[$class];
} else {
/** @var string|Service $class */
$this->builders[$class] = $builder = $class::getBuilder($this->reader);
}
list($id, $definition) = $builder->build($reflection, $annotation);
(yield $id => $definition);
}
}
示例5: loadMetadataForClass
/**
* @param ReflectionClass $class
*
* @return ClassMetadata
*/
public function loadMetadataForClass(ReflectionClass $class)
{
$classMetadata = new ClassMetadata($class->getName());
$classAnnotations = $this->reader->getClassAnnotations($class);
foreach ($classAnnotations as $annotation) {
if ($annotation instanceof Document) {
$classMetadata->collection = $annotation->collection ?: strtolower($class->getShortName());
$classMetadata->repository = $annotation->repository ?: DocumentRepository::class;
}
}
$classMetadata->identifier = $this->findIdentifer($class);
foreach ($class->getProperties() as $property) {
$classMetadata->addPropertyMetadata($this->loadPropertyMetadata($property));
}
return $classMetadata;
}
示例6: create
/**
* @param string $className
* @return Datagrid
*/
public function create($className)
{
/** @var \Doctrine\ORM\EntityManager $entityManager */
$entityManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
$metadata = $entityManager->getClassMetadata($className);
$reflection = $metadata->getReflectionClass();
$datagridSpec = new ArrayObject(array('className' => $className, 'primaryKey' => $metadata->getSingleIdentifierFieldName(), 'name' => array('singular' => '', 'plural' => ''), 'defaultSort' => null, 'headerColumns' => array(), 'searchColumns' => array(), 'suggestColumns' => array()));
$reader = new AnnotationReader();
foreach ($reader->getClassAnnotations($reflection) as $annotation) {
$params = compact('datagridSpec', 'annotation');
$this->getEventManager()->trigger('discoverTitle', $this, $params);
}
foreach ($reflection->getProperties() as $property) {
foreach ($reader->getPropertyAnnotations($property) as $annotation) {
$params = compact('datagridSpec', 'annotation', 'property');
$this->getEventManager()->trigger('configureColumn', $this, $params);
}
}
foreach ($reflection->getMethods() as $method) {
foreach ($reader->getMethodAnnotations($method) as $annotation) {
$params = compact('datagridSpec', 'annotation', 'method');
$this->getEventManager()->trigger('configureColumn', $this, $params);
}
}
$this->datagrids[$className] = new Datagrid($entityManager, $datagridSpec->getArrayCopy());
return $this->datagrids[$className];
}
示例7: __construct
/**
* Entity Indexer
* @param string|EntityClass $entityClassName
*
* @throws InvalidAnnotationException Invalid annotations used
*/
public function __construct($entityClassName)
{
$this->entityClass = new \ReflectionClass($entityClassName);
if (!$this->entityClass->isSubclassOf("\\SweetORM\\Entity")) {
throw new \UnexpectedValueException("The className for getTable should be a class that is extending the SweetORM Entity class");
// @codeCoverageIgnore
}
$this->entity = new EntityStructure();
$this->entity->name = $this->entityClass->getName();
// Reader
$reader = new AnnotationReader();
$this->classAnnotations = $reader->getClassAnnotations($this->entityClass);
$this->entityAnnotation = $reader->getClassAnnotation($this->entityClass, EntityClass::class);
// Validate Entity annotation
if ($this->entityAnnotation === null || !$this->entityAnnotation instanceof EntityClass) {
throw new InvalidAnnotationException("Entity '" . $this->entityClass->getName() . "' should use Annotations to use it! Please look at the documentation for help.");
// @codeCoverageIgnore
}
// Run all the indexers
foreach (self::$indexers as $indexerClass) {
$indexerFullClass = "\\SweetORM\\Structure\\Indexer\\" . $indexerClass;
/** @var Indexer $instance */
$instance = new $indexerFullClass($this->entityClass, $reader);
$instance->indexEntity($this->entity);
}
}
示例8: isTransient
/**
* Whether the class with the specified name is transient. Only non-transient
* classes, that is entities and mapped superclasses, should have their metadata loaded.
* A class is non-transient if it is annotated with either @Entity or
* @MappedSuperclass in the class doc block.
*
* @param string $className
* @return boolean
*/
public function isTransient($className)
{
$classAnnotations = $this->_reader->getClassAnnotations(new \ReflectionClass($className));
return ! isset($classAnnotations['Doctrine\ORM\Mapping\Entity']) &&
! isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass']);
}
示例9: testParseAnnotationDocblocks
public function testParseAnnotationDocblocks()
{
$class = new \ReflectionClass(__NAMESPACE__ . '\\DCOM55Annotation');
$reader = new AnnotationReader();
$annots = $reader->getClassAnnotations($class);
$this->assertEquals(0, count($annots));
}
示例10: getContentFiles
public function getContentFiles($object)
{
$reflectedClass = new \ReflectionClass($object);
$reader = new AnnotationReader();
$annotations = $reader->getClassAnnotations($reflectedClass);
$isContentFiledClass = false;
foreach ($annotations as $annotation) {
if ($annotation instanceof ContentFiled) {
$isContentFiledClass = true;
}
}
if (!$isContentFiledClass) {
throw new \InvalidArgumentException('Only @ContentFiled annotated classes are supported!');
}
$contentFiles = [];
foreach ($reflectedClass->getProperties() as $property) {
foreach ($reader->getPropertyAnnotations($property) as $annotation) {
if ($annotation instanceof ContentFileAnnotation) {
$mappingType = $object->{$annotation->mappingTypeMethod}();
$contentFiles = array_merge($contentFiles, $this->contentFileManager->findFilesByMappingType($mappingType));
}
}
}
return $contentFiles;
}
示例11: getClassMetadata
/**
* @param string $classname
* @return array
*/
public function getClassMetadata($classname)
{
$classMetadata = [];
$reflexionClass = $this->getReflectionClass($classname);
$classAnnotations = $this->reader->getClassAnnotations($reflexionClass);
foreach ($classAnnotations as $classAnnotation) {
if (!isset($classMetadata[get_class($classAnnotation)])) {
$classMetadata[get_class($classAnnotation)] = [];
}
$classMetadata[get_class($classAnnotation)][] = $classAnnotation;
}
if ($this->reader->getClassAnnotation($reflexionClass, ParentClass::class)) {
$classMetadata = array_merge_recursive($this->getClassMetadata(get_parent_class($classname)), $classMetadata);
}
return $classMetadata;
}
示例12: processClassAnnotations
/**
* @param ReflectionClass $reflectionClass
* @param ControllerCollection $controllerCollection
*/
public function processClassAnnotations(ReflectionClass $reflectionClass, ControllerCollection $controllerCollection)
{
foreach ($this->reader->getClassAnnotations($reflectionClass) as $annotation) {
if ($annotation instanceof RouteAnnotation) {
$annotation->process($controllerCollection);
}
}
}
示例13: loadClassAnnotations
/**
* @param AnnotationReader $reader
* @param ReflectionClass $reflClass
*/
protected function loadClassAnnotations(AnnotationReader $reader, ReflectionClass $reflClass)
{
foreach ($reader->getClassAnnotations($reflClass) as $annotation) {
if ($annotation instanceof Prefix) {
$this->metadata->setPrefix($annotation->value);
}
}
}
示例14: isTransient
/**
* Whether the class with the specified name is transient. Only non-transient
* classes, that is entities and mapped superclasses, should have their metadata loaded.
* A class is non-transient if it is annotated with either @Entity or
* @MappedSuperclass in the class doc block.
*
* @param string $className
* @return boolean
*/
public function isTransient($className)
{
$classAnnotations = $this->reader->getClassAnnotations(new \ReflectionClass($className));
return ! isset($classAnnotations['Doctrine\ODM\MongoDB\Mapping\Document']) &&
! isset($classAnnotations['Doctrine\ODM\MongoDB\Mapping\MappedSuperclass']) &&
! isset($classAnnotations['Doctrine\ODM\MongoDB\Mapping\EmbeddedDocument']);
}
示例15: testGivenAnObjectShouldProcessIt
public function testGivenAnObjectShouldProcessIt()
{
a\AnnotationRegistry::registerFile(__DIR__ . "/resource/AnnotationSample.php");
$someObj = new AnnotatedClass();
$reader = new a\AnnotationReader("/tmp/", $debug = true);
$classAnnots = $reader->getClassAnnotations(new ReflectionObject($someObj));
$this->assertNotEmpty($classAnnots);
$this->assertEquals($classAnnots[0]->property, "some");
}