本文整理汇总了PHP中Doctrine\Common\Annotations\AnnotationRegistry::reset方法的典型用法代码示例。如果您正苦于以下问题:PHP AnnotationRegistry::reset方法的具体用法?PHP AnnotationRegistry::reset怎么用?PHP AnnotationRegistry::reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Annotations\AnnotationRegistry
的用法示例。
在下文中一共展示了AnnotationRegistry::reset方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerAnnotationLoader
protected static function registerAnnotationLoader(array $namespaces)
{
AnnotationRegistry::reset();
AnnotationRegistry::registerLoader(function ($class) use($namespaces) {
foreach ($namespaces as $namespace) {
if (strpos($class, $namespace) === 0) {
spl_autoload_call($class);
return class_exists($class, false);
}
}
});
}
示例2: testBootRegistersAnnotationInLoader
/**
* Test that calling boot() registers our annotation in the AnnotationRegistry.
*
* @return void
*/
public function testBootRegistersAnnotationInLoader()
{
$bundle = new TensideCoreBundle();
AnnotationRegistry::reset();
$this->assertFalse(AnnotationRegistry::loadAnnotationClass('Tenside\\CoreBundle\\Annotation\\ApiDescription'));
$this->assertFalse(class_exists('Tenside\\CoreBundle\\Annotation\\ApiDescription', false));
$bundle->boot();
$this->assertFalse(AnnotationRegistry::loadAnnotationClass('NonExistant\\Annotation'));
// Ensure the class does not get loaded by requiring another annotation.
$this->assertFalse(class_exists('Tenside\\CoreBundle\\Annotation\\ApiDescription', false));
$this->assertTrue(AnnotationRegistry::loadAnnotationClass('Tenside\\CoreBundle\\Annotation\\ApiDescription'));
$this->assertTrue(class_exists('Tenside\\CoreBundle\\Annotation\\ApiDescription', false));
}
示例3: getDefinitions
/**
* {@inheritdoc}
*/
public function getDefinitions()
{
$definitions = array();
$reader = $this->getAnnotationReader();
// Clear the annotation loaders of any previous annotation classes.
AnnotationRegistry::reset();
// Register the namespaces of classes that can be used for annotations.
AnnotationRegistry::registerLoader('class_exists');
// Search for classes within all PSR-0 namespace locations.
foreach ($this->getPluginNamespaces() as $namespace => $dirs) {
foreach ($dirs as $dir) {
if (file_exists($dir)) {
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS));
foreach ($iterator as $fileinfo) {
if ($fileinfo->getExtension() == 'php') {
$sub_path = $iterator->getSubIterator()->getSubPath();
$sub_path = $sub_path ? str_replace('/', '\\', $sub_path) . '\\' : '';
$class = $namespace . '\\' . str_replace('/', '\\', $this->pluginManagerDefinition['directory']) . '\\' . $sub_path . $fileinfo->getBasename('.php');
// The filename is already known, so there is no need to find the
// file. However, StaticReflectionParser needs a finder, so use a
// mock version.
$finder = MockFileFinder::create($fileinfo->getPathName());
$parser = new StaticReflectionParser($class, $finder, TRUE);
if ($annotation = $reader->getClassAnnotation($parser->getReflectionClass(), $this->pluginDefinitionAnnotationName)) {
$this->prepareAnnotationDefinition($annotation, $class);
$definitions[$annotation->getId()] = $annotation->get();
}
}
}
}
}
}
// Don't let annotation loaders pile up.
AnnotationRegistry::reset();
return $definitions;
}
示例4: getDefinitions
/**
* {@inheritdoc}
*/
public function getDefinitions()
{
$definitions = array();
$reader = $this->getAnnotationReader();
// Clear the annotation loaders of any previous annotation classes.
AnnotationRegistry::reset();
// Register the namespaces of classes that can be used for annotations.
AnnotationRegistry::registerLoader('class_exists');
// Search for classes within all PSR-0 namespace locations.
foreach ($this->getPluginNamespaces() as $namespace => $dirs) {
foreach ($dirs as $dir) {
if (file_exists($dir)) {
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS));
foreach ($iterator as $fileinfo) {
if ($fileinfo->getExtension() == 'php') {
if ($cached = $this->fileCache->get($fileinfo->getPathName())) {
if (isset($cached['id'])) {
// Explicitly unserialize this to create a new object instance.
$definitions[$cached['id']] = unserialize($cached['content']);
}
continue;
}
$sub_path = $iterator->getSubIterator()->getSubPath();
$sub_path = $sub_path ? str_replace(DIRECTORY_SEPARATOR, '\\', $sub_path) . '\\' : '';
$class = $namespace . '\\' . $sub_path . $fileinfo->getBasename('.php');
// The filename is already known, so there is no need to find the
// file. However, StaticReflectionParser needs a finder, so use a
// mock version.
$finder = MockFileFinder::create($fileinfo->getPathName());
$parser = new BaseStaticReflectionParser($class, $finder, FALSE);
/** @var $annotation \Drupal\Component\Annotation\AnnotationInterface */
if ($annotation = $reader->getClassAnnotation($parser->getReflectionClass(), $this->pluginDefinitionAnnotationName)) {
$this->prepareAnnotationDefinition($annotation, $class, $parser);
$id = $annotation->getId();
$content = $annotation->get();
$definitions[$id] = $content;
// Explicitly serialize this to create a new object instance.
$this->fileCache->set($fileinfo->getPathName(), ['id' => $id, 'content' => serialize($content)]);
} else {
// Store a NULL object, so the file is not reparsed again.
$this->fileCache->set($fileinfo->getPathName(), [NULL]);
}
}
}
}
}
}
// Don't let annotation loaders pile up.
AnnotationRegistry::reset();
return $definitions;
}
示例5: registerCommands
private function registerCommands()
{
if ($this->container->hasParameter('drupal.commands')) {
$consoleCommands = $this->container->getParameter('drupal.commands');
} else {
$consoleCommands = array_keys($this->container->findTaggedServiceIds('drupal.command'));
$this->container->setParameter('console.warning', 'application.site.errors.settings');
}
// // @TODO add auto-discovery of chain files
// $chainCommands['create:bulk:data'] = [
// 'file' => '/Users/jmolivas/.console/chain/create-data.yml'
// ];
//
// foreach ($chainCommands as $name => $chainCommand) {
// $file = $chainCommand['file'];
// $command = new ChainRegister($name, $file);
// $this->add($command);
// }
$serviceDefinitions = [];
$annotationValidator = null;
if ($this->container->hasParameter('console.service_definitions')) {
$serviceDefinitions = $this->container->getParameter('console.service_definitions');
/**
* @var AnnotationValidator $annotationValidator
*/
$annotationValidator = $this->container->get('console.annotation_validator');
}
$aliases = $this->container->get('console.configuration_manager')->getConfiguration()->get('application.commands.aliases') ?: [];
foreach ($consoleCommands as $name) {
// Some commands call AnnotationRegistry::reset,
// we need to ensure the AnnotationRegistry is correctly defined.
AnnotationRegistry::reset();
AnnotationRegistry::registerLoader([\Drupal::service('class_loader'), "loadClass"]);
if (!$this->container->has($name)) {
continue;
}
if ($annotationValidator) {
if (!($serviceDefinition = $serviceDefinitions[$name])) {
continue;
}
if (!$annotationValidator->isValidCommand($serviceDefinition->getClass())) {
continue;
}
}
try {
$command = $this->container->get($name);
} catch (\Exception $e) {
continue;
}
if (!$command) {
continue;
}
if (method_exists($command, 'setTranslator')) {
$command->setTranslator($this->container->get('console.translator_manager'));
}
if (method_exists($command, 'setContainer')) {
$command->setContainer($this->container->get('service_container'));
}
if (array_key_exists($command->getName(), $aliases)) {
$commandAliases = $aliases[$command->getName()];
if (!is_array($commandAliases)) {
$commandAliases = [$commandAliases];
}
$command->setAliases($commandAliases);
}
$this->add($command);
}
}