当前位置: 首页>>代码示例>>PHP>>正文


PHP ReflectionClass::inNamespace方法代码示例

本文整理汇总了PHP中ReflectionClass::inNamespace方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionClass::inNamespace方法的具体用法?PHP ReflectionClass::inNamespace怎么用?PHP ReflectionClass::inNamespace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ReflectionClass的用法示例。


在下文中一共展示了ReflectionClass::inNamespace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: load_class

/**
 * Load classes
 * 
 * @param String Class name of class for loading
 * @param string Directory of class
 * @param boolean If class need instantiation
 * @return object
 */

function load_class($class, $directory = 'core', $instantiate = FALSE )
{
	static $_classes = array();

        $class_path = ROOT . '/' . $directory . '/' . $class;

        // return classe instance if exists (singleton pattern)
	if (isset($_classes[$class]))
	{
		return $_classes[$class];
	}

        if (file_exists($class_path . '.php'))
        {
                require $class_path . '.php';

                $reflection = new ReflectionClass("\\$directory\\$class");

                if($reflection->inNamespace())
                {
                        $class = $reflection->getNamespaceName() . '\\' . $class;
                }

                if($instantiate === TRUE)
                {
                        $_classes[$class] = new $class();
                        return $_classes[$class];
                }
        }
}
开发者ID:rosianesrocha,项目名称:nanico,代码行数:39,代码来源:common.php

示例2: getInheritanceInspection

 /**
  * Returns inheritance inspection.
  *
  * The inspection result:
  *
  * must:
  *
  * * shortName
  * * name
  * * userDefined
  *
  * optional:
  *
  * * namespace
  *
  * @param \ReflectionClass $declaringClass ReflectionClass object.
  * @return array Inheritance inspection.
  */
 protected function getInheritanceInspection(\ReflectionClass $declaringClass)
 {
     $inheritanceInspection = array('shortname' => $declaringClass->getShortName(), 'name' => $declaringClass->getName(), 'filename' => $declaringClass->getFileName(), 'userDefined' => $declaringClass->isUserDefined());
     if ($declaringClass->inNamespace()) {
         $inheritanceInspection['namespace'] = $declaringClass->getNamespaceName();
     }
     return $inheritanceInspection;
 }
开发者ID:satooshi,项目名称:object-inspector,代码行数:26,代码来源:ObjectInspector.php

示例3: get

 public function get($entity)
 {
     $function = new \ReflectionClass($entity);
     $className = $function->getShortName();
     $transformerClassName = sprintf("AppBundle\\Response\\Transformer\\%sTransformer", $className);
     if (class_exists($transformerClassName) === false) {
         throw new \Exception(sprintf("Transformer class for entity %s does not exist.", $function->inNamespace()));
     }
     $transformerClass = new $transformerClassName();
     return $transformerClass;
 }
开发者ID:cvele,项目名称:fondacija,代码行数:11,代码来源:TransformerFactory.php

示例4: getExistingClasses

 /**
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function getExistingClasses(array $paths) : array
 {
     $namespaceList = [];
     $classList = [];
     $list = [];
     foreach ($paths as $path) {
         if (false === $path->isSourceCode()) {
             continue;
         }
         $iter = new ClassIterator($this->getPhpFiles($path->getPathBase()));
         foreach (array_keys($iter->getClassMap()) as $classname) {
             if (in_array(substr($classname, -4), ['Test', 'Spec'])) {
                 continue;
             }
             $reflection = new \ReflectionClass($classname);
             if ($reflection->isAbstract() || $reflection->isTrait() || $reflection->isInterface()) {
                 continue;
             }
             if ($reflection->inNamespace()) {
                 $namespaces = explode('\\', $reflection->getNamespaceName());
                 $namespace = '';
                 foreach ($namespaces as $key => $namespacePart) {
                     if ($namespace !== '') {
                         $namespace .= '/';
                     }
                     $namespace .= $namespacePart;
                     if (!array_key_exists($key, $namespaceList)) {
                         $namespaceList[$key] = [];
                     }
                     $namespaceList[$key][$namespace] = $namespace;
                 }
             }
             $escapedName = str_replace('\\', '/', $classname);
             $classList[$escapedName] = $escapedName;
         }
     }
     foreach ($namespaceList as $namespaceDepthList) {
         $list = array_merge($list, $namespaceDepthList);
     }
     $list = array_merge($list, $classList);
     return $list;
 }
开发者ID:nulldevelopmenthr,项目名称:generator,代码行数:45,代码来源:SourceCodePathReader.php

示例5: expandClassName

	/**
	 * Expands class name into FQN.
	 * @param  string
	 * @return string  fully qualified class name
	 * @throws Nette\InvalidArgumentException
	 */
	public static function expandClassName($name, \ReflectionClass $reflector)
	{
		if (empty($name)) {
			throw new Nette\InvalidArgumentException('Class name must not be empty.');

		} elseif ($name === 'self') {
			return $reflector->getName();

		} elseif ($name[0] === '\\') { // already fully qualified
			return ltrim($name, '\\');
		}

		$filename = $reflector->getFileName();
		$parsed = static::getCache()->load($filename, function (& $dp) use ($filename) {
			if (AnnotationsParser::$autoRefresh) {
				$dp[Nette\Caching\Cache::FILES] = $filename;
			}
			return AnnotationsParser::parsePhp(file_get_contents($filename));
		});
		$uses = array_change_key_case((array) $tmp = & $parsed[$reflector->getName()]['use']);
		$parts = explode('\\', $name, 2);
		$parts[0] = strtolower($parts[0]);
		if (isset($uses[$parts[0]])) {
			$parts[0] = $uses[$parts[0]];
			return implode('\\', $parts);

		} elseif ($reflector->inNamespace()) {
			return $reflector->getNamespaceName() . '\\' . $name;

		} else {
			return $name;
		}
	}
开发者ID:nakoukal,项目名称:fakturace,代码行数:39,代码来源:AnnotationsParser.php

示例6: load

    /**
     * Loads a list of classes and caches them in one big file.
     *
     * @param array   $classes    An array of classes to load
     * @param string  $cacheDir   A cache directory
     * @param string  $name       The cache name prefix
     * @param Boolean $autoReload Whether to flush the cache when the cache is stale or not
     * @param Boolean $adaptive   Whether to remove already declared classes or not
     * @param string  $extension  File extension of the resulting file
     *
     * @throws \InvalidArgumentException When class can't be loaded
     */
    static public function load($classes, $cacheDir, $name, $autoReload, $adaptive = false, $extension = '.php')
    {
        // each $name can only be loaded once per PHP process
        if (isset(self::$loaded[$name])) {
            return;
        }

        self::$loaded[$name] = true;

        if ($adaptive) {
            // don't include already declared classes
            $classes = array_diff($classes, get_declared_classes(), get_declared_interfaces());

            // the cache is different depending on which classes are already declared
            $name = $name.'-'.substr(md5(implode('|', $classes)), 0, 5);
        }

        $cache = $cacheDir.'/'.$name.$extension;

        // auto-reload
        $reload = false;
        if ($autoReload) {
            $metadata = $cacheDir.'/'.$name.$extension.'.meta';
            if (!is_file($metadata) || !is_file($cache)) {
                $reload = true;
            } else {
                $time = filemtime($cache);
                $meta = unserialize(file_get_contents($metadata));

                if ($meta[1] != $classes) {
                    $reload = true;
                } else {
                    foreach ($meta[0] as $resource) {
                        if (!is_file($resource) || filemtime($resource) > $time) {
                            $reload = true;

                            break;
                        }
                    }
                }
            }
        }

        if (!$reload && is_file($cache)) {
            require_once $cache;

            return;
        }

        $files = array();
        $content = '';
        foreach ($classes as $class) {
            if (!class_exists($class) && !interface_exists($class) && (!function_exists('trait_exists') || !trait_exists($class))) {
                throw new \InvalidArgumentException(sprintf('Unable to load class "%s"', $class));
            }

            $r = new \ReflectionClass($class);
            $files[] = $r->getFileName();

            $c = preg_replace(array('/^\s*<\?php/', '/\?>\s*$/'), '', file_get_contents($r->getFileName()));

            // add namespace declaration for global code
            if (!$r->inNamespace()) {
                $c = "\nnamespace\n{\n".self::stripComments($c)."\n}\n";
            } else {
                $c = self::fixNamespaceDeclarations('<?php '.$c);
                $c = preg_replace('/^\s*<\?php/', '', $c);
            }

            $content .= $c;
        }

        // cache the core classes
        if (!is_dir(dirname($cache))) {
            mkdir(dirname($cache), 0777, true);
        }
        self::writeCacheFile($cache, '<?php '.$content);

        if ($autoReload) {
            // save the resources
            self::writeCacheFile($metadata, serialize(array($files, $classes)));
        }
    }
开发者ID:reddragon010,项目名称:RG-ServerPanel,代码行数:95,代码来源:ClassCollectionLoader.php

示例7: getMagicMethods

    /**
     * Returns array of magic methods defined by annotation @method.
     * @return array
     */
    public static function getMagicMethods($class)
    {
        $rc = new \ReflectionClass($class);
        preg_match_all('~^
			[ \\t*]*  @method  [ \\t]+
			(?: [^\\s(]+  [ \\t]+ )?
			(set|get|is|add)  ([A-Z]\\w*)  [ \\t]*
			(?: \\(  [ \\t]* ([^)$\\s]+)  )?
		()~mx', $rc->getDocComment(), $matches, PREG_SET_ORDER);
        $methods = array();
        foreach ($matches as $m) {
            list(, $op, $prop, $type) = $m;
            $name = $op . $prop;
            $prop = strtolower($prop[0]) . substr($prop, 1) . ($op === 'add' ? 's' : '');
            if ($rc->hasProperty($prop) && ($rp = $rc->getProperty($prop)) && !$rp->isStatic()) {
                $rp->setAccessible(TRUE);
                if ($op === 'get' || $op === 'is') {
                    $type = NULL;
                    $op = 'get';
                } elseif (!$type && preg_match('#@var[ \\t]+(\\S+)' . ($op === 'add' ? '\\[\\]#' : '#'), $rp->getDocComment(), $m)) {
                    $type = $m[1];
                }
                if ($rc->inNamespace() && preg_match('#^[A-Z]\\w+(\\[|\\||\\z)#', $type)) {
                    $type = $rc->getNamespaceName() . '\\' . $type;
                }
                $methods[$name] = array($op, $rp, $type);
            }
        }
        return $methods;
    }
开发者ID:eduardobenito10,项目名称:jenkins-php-quickstart,代码行数:34,代码来源:ObjectMixin.php

示例8: getMagicMethods

    /**
     * Returns array of magic methods defined by annotation @method.
     * @return array
     */
    public static function getMagicMethods(string $class) : array
    {
        $rc = new \ReflectionClass($class);
        preg_match_all('~^
			[ \\t*]*  @method  [ \\t]+
			(?: [^\\s(]+  [ \\t]+ )?
			(set|get|is|add)  ([A-Z]\\w*)
			(?: ([ \\t]* \\()  [ \\t]* ([^)$\\s]*)  )?
		()~mx', (string) $rc->getDocComment(), $matches, PREG_SET_ORDER);
        $methods = [];
        foreach ($matches as list(, $op, $prop, $bracket, $type)) {
            if ($bracket !== '(') {
                trigger_error("Bracket must be immediately after @method {$op}{$prop}() in class {$class}.", E_USER_WARNING);
            }
            $name = $op . $prop;
            $prop = strtolower($prop[0]) . substr($prop, 1) . ($op === 'add' ? 's' : '');
            if ($rc->hasProperty($prop) && ($rp = $rc->getProperty($prop)) && !$rp->isStatic()) {
                $rp->setAccessible(TRUE);
                if ($op === 'get' || $op === 'is') {
                    $type = NULL;
                    $op = 'get';
                } elseif (!$type && preg_match('#@var[ \\t]+(\\S+)' . ($op === 'add' ? '\\[\\]#' : '#'), (string) $rp->getDocComment(), $m)) {
                    $type = $m[1];
                }
                if ($rc->inNamespace() && preg_match('#^[A-Z]\\w+(\\[|\\||\\z)#', (string) $type)) {
                    $type = $rc->getNamespaceName() . '\\' . $type;
                }
                $methods[$name] = [$op, $rp, $type];
            }
        }
        return $methods;
    }
开发者ID:kukulich,项目名称:utils,代码行数:36,代码来源:ObjectMixin.php

示例9: expandClassName

 /**
  * Expands class name into FQN.
  * @param  string
  * @return string  fully qualified class name
  * @throws Nette\InvalidArgumentException
  */
 public static function expandClassName($name, \ReflectionClass $reflector)
 {
     if (empty($name)) {
         throw new Nette\InvalidArgumentException('Class name must not be empty.');
     }
     if ($name[0] === '\\') {
         // already fully qualified
         return ltrim($name, '\\');
     }
     $parsed = static::parsePhp(file_get_contents($reflector->getFileName()));
     $uses = array_change_key_case((array) ($tmp =& $parsed[$reflector->getName()]['use']));
     $parts = explode('\\', $name, 2);
     $parts[0] = strtolower($parts[0]);
     if (isset($uses[$parts[0]])) {
         $parts[0] = $uses[$parts[0]];
         return implode('\\', $parts);
     } elseif ($reflector->inNamespace()) {
         return $reflector->getNamespaceName() . '\\' . $name;
     } else {
         return $name;
     }
 }
开发者ID:eduardobenito10,项目名称:jenkins-php-quickstart,代码行数:28,代码来源:AnnotationsParser.php

示例10: testGeneratedEntityRepositoryClassCustomDefaultRepository

 /**
  * @group DDC-3231
  */
 public function testGeneratedEntityRepositoryClassCustomDefaultRepository()
 {
     $em = $this->_getTestEntityManager();
     $ns = $this->_namespace;
     require_once __DIR__ . '/../../Models/DDC3231/DDC3231User2.php';
     $className = $ns . '\\DDC3231User2Tmp';
     $this->writeEntityClass('Doctrine\\Tests\\Models\\DDC3231\\DDC3231User2', $className);
     $rpath = $this->writeRepositoryClass($className, 'Doctrine\\Tests\\Models\\DDC3231\\DDC3231EntityRepository');
     $this->assertNotNull($rpath);
     $this->assertFileExists($rpath);
     require $rpath;
     $repo = new \ReflectionClass($em->getRepository($className));
     $this->assertTrue($repo->inNamespace());
     $this->assertSame($className . 'Repository', $repo->getName());
     $this->assertSame('Doctrine\\Tests\\Models\\DDC3231\\DDC3231EntityRepository', $repo->getParentClass()->getName());
     require_once __DIR__ . '/../../Models/DDC3231/DDC3231User2NoNamespace.php';
     $className2 = 'DDC3231User2NoNamespaceTmp';
     $this->writeEntityClass('DDC3231User2NoNamespace', $className2);
     $rpath2 = $this->writeRepositoryClass($className2, 'Doctrine\\Tests\\Models\\DDC3231\\DDC3231EntityRepository');
     $this->assertNotNull($rpath2);
     $this->assertFileExists($rpath2);
     require $rpath2;
     $repo2 = new \ReflectionClass($em->getRepository($className2));
     $this->assertFalse($repo2->inNamespace());
     $this->assertSame($className2 . 'Repository', $repo2->getName());
     $this->assertSame('Doctrine\\Tests\\Models\\DDC3231\\DDC3231EntityRepository', $repo2->getParentClass()->getName());
 }
开发者ID:selimcr,项目名称:servigases,代码行数:30,代码来源:EntityRepositoryGeneratorTest.php

示例11: load

 public static function load($classes, $cacheDir, $name, $autoReload, $adaptive = false)
 {
     if (isset(self::$loaded[$name])) {
         return;
     }
     self::$loaded[$name] = true;
     $classes = array_unique($classes);
     if ($adaptive) {
         $classes = array_diff($classes, get_declared_classes(), get_declared_interfaces());
         $name = $name . '-' . substr(md5(implode('|', $classes)), 0, 5);
     }
     $cache = $cacheDir . '/' . $name . '.php';
     $reload = false;
     if ($autoReload) {
         $metadata = $cacheDir . '/' . $name . '.meta';
         if (!file_exists($metadata) || !file_exists($cache)) {
             $reload = true;
         } else {
             $time = filemtime($cache);
             $meta = unserialize(file_get_contents($metadata));
             if ($meta[1] != $classes) {
                 $reload = true;
             } else {
                 foreach ($meta[0] as $resource) {
                     if (!file_exists($resource) || filemtime($resource) > $time) {
                         $reload = true;
                         break;
                     }
                 }
             }
         }
     }
     if (!$reload && file_exists($cache)) {
         require_once $cache;
         return;
     }
     $files = array();
     $content = '';
     foreach ($classes as $class) {
         if (!class_exists($class) && !interface_exists($class)) {
             throw new \InvalidArgumentException(sprintf('Unable to load class "%s"', $class));
         }
         $r = new \ReflectionClass($class);
         $files[] = $r->getFileName();
         $c = preg_replace(array('/^\\s*<\\?php/', '/\\?>\\s*$/'), '', file_get_contents($r->getFileName()));
         if (!$r->inNamespace()) {
             $c = "\nnamespace\n{\n{$c}\n}\n";
         } else {
             $c = self::fixNamespaceDeclarations('<?php ' . $c);
             $c = preg_replace('/^\\s*<\\?php/', '', $c);
         }
         $content .= $c;
     }
     if (!is_dir(dirname($cache))) {
         mkdir(dirname($cache), 0777, true);
     }
     self::writeCacheFile($cache, Kernel::stripComments('<?php ' . $content));
     if ($autoReload) {
         self::writeCacheFile($metadata, serialize(array($files, $classes)));
     }
 }
开发者ID:notbrain,项目名称:symfony,代码行数:61,代码来源:bootstrap.php

示例12: catch

 /**
  * Return the local class for an object or a class that can be loaded.
  *
  * @param object|string $object
  *
  * @return string
  */
 static function get_local_class($object)
 {
     $class_name = is_object($object) ? get_class($object) : $object;
     try {
         $reflector = new \ReflectionClass($class_name);
         if ($reflector->inNamespace()) {
             $base_class = $reflector->getShortName();
         } else {
             $base_class = $class_name;
         }
     } catch (\Exception $e) {
         $base_class = $class_name;
     }
     return $base_class;
 }
开发者ID:wplib,项目名称:json-loader,代码行数:22,代码来源:util.php

示例13: inNamespace

 /**
  * {@inheritdoc}
  */
 public function inNamespace()
 {
     return $this->reflectionClass->inNamespace();
 }
开发者ID:roave,项目名称:better-reflection,代码行数:7,代码来源:ReflectionObject.php

示例14: inspectNamespace

 /**
  * Inspect namespace.
  *
  * @return void
  */
 protected function inspectNamespace()
 {
     if ($this->class->inNamespace()) {
         $this->inspection['namespace'] = $this->class->getNamespaceName();
     }
 }
开发者ID:satooshi,项目名称:object-inspector,代码行数:11,代码来源:ObjectTypeInspector.php

示例15: expandClassName

 /**
  * Expands class name into full name.
  * @param  string
  * @return string  full name
  * @throws Nette\InvalidArgumentException
  */
 public static function expandClassName(string $name, \ReflectionClass $rc) : string
 {
     $lower = strtolower($name);
     if (empty($name)) {
         throw new Nette\InvalidArgumentException('Class name must not be empty.');
     } elseif (in_array($lower, ['string', 'int', 'float', 'bool', 'array', 'callable'], TRUE)) {
         return $lower;
     } elseif ($lower === 'self') {
         return $rc->getName();
     } elseif ($name[0] === '\\') {
         // fully qualified name
         return ltrim($name, '\\');
     }
     $uses =& self::$cache[$rc->getName()];
     if ($uses === NULL) {
         self::$cache = self::parseUseStatemenets(file_get_contents($rc->getFileName()), $rc->getName()) + self::$cache;
         $uses =& self::$cache[$rc->getName()];
     }
     $parts = explode('\\', $name, 2);
     if (isset($uses[$parts[0]])) {
         $parts[0] = $uses[$parts[0]];
         return implode('\\', $parts);
     } elseif ($rc->inNamespace()) {
         return $rc->getNamespaceName() . '\\' . $name;
     } else {
         return $name;
     }
 }
开发者ID:kukulich,项目名称:di,代码行数:34,代码来源:PhpReflection.php


注:本文中的ReflectionClass::inNamespace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。