本文整理汇总了PHP中ReflectionClass::getNamespaceName方法的典型用法代码示例。如果您正苦于以下问题:PHP ReflectionClass::getNamespaceName方法的具体用法?PHP ReflectionClass::getNamespaceName怎么用?PHP ReflectionClass::getNamespaceName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReflectionClass
的用法示例。
在下文中一共展示了ReflectionClass::getNamespaceName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerPlugins
/**
* @param string|mixed $class
*/
public function registerPlugins($class)
{
switch (true) {
case is_string($class):
$class = is_string($class) ? new $class() : $class;
case $class instanceof AbstractHelper:
$reflector = new \ReflectionClass($class);
$path = realpath(dirname($reflector->getFileName()));
$class = array();
foreach (scandir($path) as $file) {
if (strpos($file, '.php') !== FALSE && strpos($file, 'Abstract') === FALSE) {
$className = str_replace('.php', '', $file);
$class[lcfirst($className)] = $reflector->getNamespaceName() . '\\' . $className;
$p = strtolower(preg_replace("/([a-z])([A-Z])/", "\$1_\$2", $className));
$class[$p] = $reflector->getNamespaceName() . '\\' . $className;
}
}
break;
case is_array($class):
break;
default:
throw new \Exception('Invalid input for $class variable. Type must be string, Zend\\Form\\View\\Helper\\AbstractHelper or array.');
}
foreach ($class as $name => $invokableClass) {
$this->registerPlugin($name, $invokableClass);
}
return $this;
}
示例2: qualifiedClass
protected static function qualifiedClass(\ReflectionClass $class, $type)
{
if (substr($type, 0, 1) == '\\') {
return substr($type, 1);
}
$classNamespace = $class->getNamespaceName();
if (!($uses = self::$namespaceUses[$classNamespace])) {
$scriptContent = file_get_contents($class->getFileName());
$scriptContent = substr($scriptContent, strpos($scriptContent, 'namespace ' . $class->getNamespaceName()));
preg_match_all("/use\\s+([a-z]+(\\\\[a-z]+)*);/i", $scriptContent, $uses);
if (isset($uses[1])) {
$uses = $uses[1];
} else {
$uses = [];
}
$_temp = [];
foreach ($uses as $use) {
$parts = explode('\\', $use);
$className = end($parts);
$_temp[$className] = implode('\\', array_slice($parts, 0, -1));
}
$uses = $_temp;
self::$namespaceUses[$classNamespace] = $uses;
}
if (isset($uses[$type])) {
$classNamespace = $uses[$type];
}
return $classNamespace . '\\' . $type;
}
示例3: toObjectValue
/**
* {@inheritdoc}
*/
public function toObjectValue($value, $type, \ReflectionProperty $property, $object)
{
$className = null;
$context = new \ReflectionClass($property->class);
//try to get the class from use statements in the class file
if ($className === null) {
$classContent = file_get_contents($context->getFileName());
$regExps = ["/use\\s+([\\w\\\\]+{$type});/", "/use\\s+([\\w\\\\]+)\\s+as\\s+{$type}/"];
foreach ($regExps as $regExp) {
if ($matchClass = $this->extractClass($regExp, $classContent)) {
$className = $matchClass;
break;
}
}
}
//use the same namespace as class container
if ($className === null && class_exists($context->getNamespaceName() . '\\' . $type)) {
$className = $context->getNamespaceName() . '\\' . $type;
}
//use the type as class
if (class_exists($type)) {
$className = $type;
}
if (is_array($value) && $className !== null && class_exists($className) && $this->array2Object) {
$property->setAccessible(true);
$currentValue = $property->getValue($object);
if (is_object($currentValue)) {
$this->array2Object->populate($currentValue, $value);
return $currentValue;
} else {
return $this->array2Object->createObject($className, $value);
}
}
return $value;
}
示例4: generateRemotingApi
/**
* Generate Remote API from a list of controllers
*/
public function generateRemotingApi()
{
$list = array();
foreach ($this->remotingBundles as $bundle) {
$bundleRef = new \ReflectionClass($bundle);
$controllerDir = new Finder();
$controllerDir->files()->in(dirname($bundleRef->getFileName()) . '/Controller/')->name('/.*Controller\\.php$/');
foreach ($controllerDir as $controllerFile) {
/** @var SplFileInfo $controllerFile */
$controller = $bundleRef->getNamespaceName() . "\\Controller\\" . substr($controllerFile->getFilename(), 0, -4);
$controllerRef = new \ReflectionClass($controller);
foreach ($controllerRef->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
/** @var $methodDirectAnnotation Direct */
$methodDirectAnnotation = $this->annoReader->getMethodAnnotation($method, 'Tpg\\ExtjsBundle\\Annotation\\Direct');
if ($methodDirectAnnotation !== null) {
$nameSpace = str_replace("\\", ".", $bundleRef->getNamespaceName());
$className = str_replace("Controller", "", $controllerRef->getShortName());
$methodName = str_replace("Action", "", $method->getName());
$list[$nameSpace][$className][] = array('name' => $methodName, 'len' => count($method->getParameters()));
}
}
}
}
return $list;
}
示例5: getNamespace
/**
* @return string $classNamespace
*/
protected function getNamespace() : string
{
if (is_null($this->namespace)) {
$this->namespace = $this->reflection->getNamespaceName();
}
return $this->namespace;
}
示例6: initialize
/**
* @param Controller $controller
* @param null $entityClassName
* @return $this
*/
public function initialize(Controller $controller, $entityClassName = null)
{
$entityClassName = explode('\\', $entityClassName);
$this->entityClassName = $entityClassName[count($entityClassName) - 1];
$this->reflector = new \ReflectionClass($controller);
$this->namespace = explode('\\', $this->reflector->getNamespaceName());
$key = array_search('__CG__', $this->namespace);
//if the controller come from jms aop bundle
if ($key) {
for ($i = $key; $i >= 0; $i--) {
unset($this->namespace[$i]);
}
}
$this->namespace = array_values($this->namespace);
$key = array_search('Controller', $this->namespace);
$lastValue = $this->namespace[count($this->namespace) - 1];
//May be you have nested controller
if ('Controller' !== $lastValue) {
$this->exclude = $lastValue;
}
for ($i = $key; $i <= count($this->namespace); $i++) {
array_pop($this->namespace);
}
return $this;
}
示例7: bringValueToType
/**
* Recursively brings value to type
* @param $parent
* @param $type
* @param $value
* @param bool $isNullable
* @param array $restrictions
* @throws Exception
* @return mixed
*/
public static function bringValueToType($parent, $type, $value, $isNullable = false, $restrictions = [])
{
if ($isNullable && null === $value || empty($type)) {
return $value;
}
$typeParts = explode("[]", $type);
$singleType = current($typeParts);
if (count($typeParts) > 2) {
throw new Exception(sprintf("In %s type '{$type}' is invalid", get_class($parent)), Exception::INTERNAL_ERROR);
}
//for array type
if (count($typeParts) === 2) {
if (!is_array($value)) {
if ($parent instanceof \JsonRpc2\Dto) {
throw new Exception(sprintf("In %s value has type %s, but array expected", get_class($parent), gettype($value)), Exception::INTERNAL_ERROR);
} else {
throw new Exception("Value has type %s, but array expected", gettype($value), Exception::INTERNAL_ERROR);
}
}
foreach ($value as $key => $childValue) {
$value[$key] = self::bringValueToType($parent, $singleType, $childValue, $isNullable);
}
return $value;
}
$class = new \ReflectionClass($parent);
if (0 !== strpos($type, "\\") && class_exists($class->getNamespaceName() . "\\" . $type)) {
$type = $class->getNamespaceName() . "\\" . $type;
}
if (class_exists($type)) {
if (!is_subclass_of($type, '\\JsonRpc2\\Dto')) {
throw new Exception(sprintf("In %s class '%s' MUST be instance of '\\JsonRpc2\\Dto'", get_class($parent), $type), Exception::INTERNAL_ERROR);
}
return new $type($value);
} else {
switch ($type) {
case "string":
$value = (string) $value;
self::restrictValue($parent, $type, $value, $restrictions);
return $value;
break;
case "int":
$value = (int) $value;
self::restrictValue($parent, $type, $value, $restrictions);
return $value;
break;
case "float":
$value = (double) $value;
self::restrictValue($parent, $type, $value, $restrictions);
return $value;
break;
case "array":
throw new Exception("Parameter type 'array' is deprecated. Use square brackets with simply types or DTO based classes instead.", Exception::INTERNAL_ERROR);
case "bool":
return (bool) $value;
break;
}
}
return $value;
}
示例8: getXmlNamespace
/**
*
*/
public function getXmlNamespace()
{
$namespace = $this->_parseAnnotation($this->reflection->getDocComment(), 'xmlNamespace');
if (!$namespace && $this->configuration) {
$namespace = $this->configuration->getXmlNamespace($this->reflection->getNamespaceName());
}
return $namespace;
}
示例9: __construct
/**
* Initializes a new ClassMetadata instance that will hold the object-relational mapping
* metadata of the class with the given name.
*
* @param string $entityName The name of the entity class the new instance is used for.
*/
public function __construct($entityName)
{
$this->name = $entityName;
$this->reflClass = new \ReflectionClass($entityName);
$this->namespace = $this->reflClass->getNamespaceName();
$this->primaryTable['name'] = $this->reflClass->getShortName();
$this->rootEntityName = $entityName;
}
示例10: __construct
public function __construct(\ReflectionClass $intf)
{
$this->intf = $intf;
$classParser = new PhpParser();
$uses = array_merge($classParser->parseClass($this->intf), [$this->intf->getNamespaceName()]);
$this->reader = new AnnotationReader($this->intf);
$this->converter = new AnnotationConverter($uses);
}
示例11: initialize
public function initialize()
{
$ref = new \ReflectionClass($this);
$namespace = str_replace(basename($ref->getNamespaceName()), '', $ref->getNamespaceName());
$this->moduleInstance = $this->getDI()->get($namespace . 'Module');
$this->modelName = strtolower(basename($ref->name));
$this->setSource(TH_DB_PREFIX . $this->modelName);
$this->onInitialize();
}
示例12:
static function widget_name()
{
$function_name = 'widget_';
$r = new \ReflectionClass(get_called_class());
$function_name .= Str::snake(str_replace('Widget', '', $r->getShortName()));
if ('Larakit\\Widget' != $r->getNamespaceName()) {
$function_name .= '__' . Str::snake(str_replace(['\\', 'Widget'], '', $r->getNamespaceName()));
}
return $function_name;
}
示例13: generateClassName
private function generateClassName()
{
$shortName = $this->reflection->getShortName();
$fullName = $this->reflection->getNamespaceName() . "\\{$shortName}Mock";
$counter = 1;
while (class_exists($fullName . $counter)) {
$counter++;
}
return ["{$shortName}Mock{$counter}", $fullName . $counter];
}
示例14: getFactory
/**
* Creates the factory for this concrete product.
* If the class does not exists yet, it is generated on the fly.
*
* The factory implements an interface named after the short name of the
* product class name with the suffix "Factory". The namespace is the
* same namespace as the product classname.
*
* The concrete factory is not of your concern, that's the trick of
* factory method. That's why I put a random number after the classname
* of the concrete factory : do not use that name !
*
* @param string $fqcnProduct
*
* @return object the the new factory
*/
public function getFactory($fqcnProduct)
{
$refl = new \ReflectionClass($fqcnProduct);
$fmName = 'Concrete' . $refl->getShortName() . 'Factory' . crc32($fqcnProduct);
$fqcnFM = $refl->getNamespaceName() . '\\' . $fmName;
if (!class_exists($fqcnFM)) {
eval($this->generate($refl->getNamespaceName(), $refl->getShortName() . 'Factory', $fmName, $refl->getName()));
}
return new $fqcnFM();
}
示例15: initialize
public function initialize()
{
$ref = new \ReflectionClass($this);
$namespace = str_replace(basename($ref->getNamespaceName()), '', $ref->getNamespaceName());
$this->moduleInstance = $this->getDI()->get($namespace . 'Module');
$this->tag->setTitleSeparator(' - ');
$this->tag->setTitle('thunderhawk');
$this->onInitialize();
$this->onPrepareAssets();
$this->onPrepareThemeAssets();
}