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


PHP Reflection\ClassType类代码示例

本文整理汇总了PHP中Nette\Reflection\ClassType的典型用法代码示例。如果您正苦于以下问题:PHP ClassType类的具体用法?PHP ClassType怎么用?PHP ClassType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getPresenterClass

 /**
  * Generates and checks presenter class name.
  *
  * @param  string presenter name
  * @return string  class name
  * @throws Application\InvalidPresenterException
  */
 public function getPresenterClass(&$name)
 {
     if (isset($this->cache[$name])) {
         return $this->cache[$name];
     }
     if (!is_string($name) || !Nette\Utils\Strings::match($name, '#^[a-zA-Z\\x7f-\\xff][a-zA-Z0-9\\x7f-\\xff:]*\\z#')) {
         throw new Application\InvalidPresenterException("Presenter name must be alphanumeric string, '{$name}' is invalid.");
     }
     $classes = $this->formatPresenterClasses($name);
     if (!$classes) {
         throw new Application\InvalidPresenterException("Cannot load presenter '{$name}', no applicable mapping found.");
     }
     $class = $this->findValidClass($classes);
     if (!$class) {
         throw new Application\InvalidPresenterException("Cannot load presenter '{$name}', none of following classes were found: " . implode(', ', $classes));
     }
     $reflection = new Nette\Reflection\ClassType($class);
     $class = $reflection->getName();
     if (!$reflection->implementsInterface('Nette\\Application\\IPresenter')) {
         throw new Application\InvalidPresenterException("Cannot load presenter '{$name}', class '{$class}' is not Nette\\Application\\IPresenter implementor.");
     }
     if ($reflection->isAbstract()) {
         throw new Application\InvalidPresenterException("Cannot load presenter '{$name}', class '{$class}' is abstract.");
     }
     return $this->cache[$name] = $class;
 }
开发者ID:librette,项目名称:presenter-factory,代码行数:33,代码来源:PresenterFactory.php

示例2: call

	/**
	 * Call to undefined method.
	 * @param  object
	 * @param  string  method name
	 * @param  array   arguments
	 * @return mixed
	 * @throws MemberAccessException
	 */
	public static function call($_this, $name, $args)
	{
		$class = new Reflection\ClassType($_this);

		if ($name === '') {
			throw new MemberAccessException("Call to class '$class->name' method without name.");
		}

		// event functionality
		if ($class->hasEventProperty($name)) {
			if (is_array($list = $_this->$name) || $list instanceof \Traversable) {
				foreach ($list as $handler) {
					callback($handler)->invokeArgs($args);
				}
			}
			return NULL;
		}

		// extension methods
		if ($cb = $class->getExtensionMethod($name)) {
			array_unshift($args, $_this);
			return $cb->invokeArgs($args);
		}

		throw new MemberAccessException("Call to undefined method $class->name::$name().");
	}
开发者ID:norbe,项目名称:nette,代码行数:34,代码来源:ObjectMixin.php

示例3: convertToTyped

 /**
  * if the object contains an explicit type marker, this method attempts to convert it to its typed counterpart
  * if the typed class is already available, then simply creates a new instance of it. If not,
  * attempts to load the file from the available service folders.
  * If then the class is still not available, the object is not converted
  * note: This is not a recursive function. Rather the recusrion is handled by Amfphp_Core_Amf_Util::applyFunctionToContainedObjects.
  * must be public so that Amfphp_Core_Amf_Util::applyFunctionToContainedObjects can call it
  *
  * Part of AMFPHP
  * @author Silex Labs
  *
  * @param mixed $obj
  * @throws \Goodshape\InvalidStateException
  * @return mixed
  */
 private function convertToTyped($obj)
 {
     if (!is_object($obj)) {
         return $obj;
     }
     $explicitTypeField = Deserializer::FIELD_EXPLICIT_TYPE;
     if (isset($obj->{$explicitTypeField})) {
         $customClassName = $obj->{$explicitTypeField};
         foreach ($this->customClassesNamespaces as $namespace) {
             $fqcn = $namespace . '\\' . $customClassName;
             if (class_exists($fqcn)) {
                 //class is available. Use it!
                 $classReflection = new ClassType($fqcn);
                 $typedObj = $classReflection->newInstanceWithoutConstructor();
                 foreach ($obj as $key => $data) {
                     // loop over each element to copy it into typed object
                     if ($key != $explicitTypeField) {
                         $typedObj->{$key} = $data;
                     }
                 }
                 return $typedObj;
             }
         }
         throw new InvalidStateException("Class {$customClassName} was not found in any of provided namespaces.");
     }
     return $obj;
 }
开发者ID:goodshape,项目名称:nette-amf,代码行数:42,代码来源:CustomClassConvertor.php

示例4: isAllowed

 /**
  * {@inheritdoc}
  */
 public function isAllowed($role, $resource, $privilege)
 {
     if ($role instanceof IRole) {
         $role = $role->getRoleId();
     }
     if (!$resource instanceof PresenterResource) {
         throw new \Ark8\Security\Exceptions\SkipException(sprintf('Resource must be instance of %s, %s given.', PresenterResource::class, gettype($resource)));
     }
     $request = $resource->getRequest();
     $presenterName = $request->getPresenterName();
     list($signal, $signalReceiver) = $this->getSignal($request);
     if (!$signal) {
         throw new \Ark8\Security\Exceptions\SkipException(sprintf('No signal sent.'));
     }
     $refClass = new PresenterComponentReflection($class = $this->presenterFactory->getPresenterClass($presenterName));
     while ($name = array_shift($signalReceiver)) {
         $name = 'createComponent' . ucfirst($name);
         if (!$refClass->hasMethod($name)) {
             throw new \Nette\InvalidStateException(sprintf('Method %s::%s is not implemented.', $refClass->getName(), $name));
         }
         $refMethod = $refClass->getMethod($name);
         if (!$refMethod->hasAnnotation('return')) {
             throw new \Nette\InvalidStateException(sprintf('Method %s::%s must have fully qualified return annotation.', $refClass->getName(), $name));
         }
         $refClass = new ClassType($refMethod->getAnnotation('return'));
     }
     if (!$refClass->hasMethod($name = Presenter::formatSignalMethod($signal))) {
         throw new \Ark8\Security\Exceptions\SkipException(sprintf('Method %s::%s is not implemented.', $refClass->getName(), $name));
     }
     $refMethod = $refClass->getMethod($name);
     if (!$refMethod->hasAnnotation($privilege)) {
         throw new \Ark8\Security\Exceptions\SkipException(sprintf('Method %s::%s does not have annotation %s.', $refClass->getName(), $name, $privilege));
     }
     return in_array($role, preg_split('#\\s+#', trim((string) $refMethod->getAnnotation($privilege))));
 }
开发者ID:ark8,项目名称:security,代码行数:38,代码来源:SignalAuthorizator.php

示例5: getDataToArray

 /**
  * @param Config $config
  * @throws LogicException
  * @return array
  */
 public function getDataToArray(Config $config)
 {
     $this->setPosId($config->getPosId());
     if ($this instanceof NewPaymentRequest) {
         $this->setPosAuthKey($config->getPosAuthKey());
     }
     $reflection = new ClassType($this);
     $parameters = array();
     $errors = array();
     foreach ($reflection->getProperties() as $property) {
         if ($property->hasAnnotation('var') && $property->getAnnotation('var') == 'bool') {
             $getterPrefix = 'is';
         } else {
             $getterPrefix = 'get';
         }
         $propertyGetter = $getterPrefix . ucfirst($property->getName());
         $value = $this->{$propertyGetter}();
         if ($value !== NULL) {
             $parameters[Strings::camelToUnderdash($property->getName())] = $value;
         }
         if ($property->hasAnnotation('required') && $value === NULL) {
             $errors[] = $property->getName();
         }
     }
     if (count($errors) > 0) {
         throw new LogicException('Empty required properties: ' . implode(', ', $errors));
     }
     $parameters['sig'] = $this->getSig($config->getKey1());
     return $parameters;
 }
开发者ID:hostbox,项目名称:api-payu,代码行数:35,代码来源:Request.php

示例6: prepareRepositories

 /**
  * @return array
  */
 protected function prepareRepositories()
 {
     $builder = $this->getContainerBuilder();
     $repositories = [];
     foreach ($builder->findByType(Repository::class) as $repositoryName => $definition) {
         $repositoryClass = $definition->getClass();
         $reflection = new ClassType($repositoryClass);
         $name = $reflection->getAnnotation('entity2');
         if ($name === NULL) {
             $name = $this->createEntityName($repositoryClass);
         }
         $repositories[$name] = $repositoryClass;
         $mapperClass = Strings::replace($repositoryClass, '~Repository$~', 'Mapper');
         $mapperName = $builder->getByType($mapperClass);
         if ($mapperName === NULL) {
             $mapperName = Strings::replace($repositoryName, '~Repository$~', 'Mapper');
             $builder->addDefinition($mapperName)->setClass($mapperClass)->setArguments(['cache' => '@' . $this->prefix('cache')]);
         } else {
             $builder->getDefinition($mapperName)->setArguments(['cache' => '@' . $this->prefix('cache')]);
         }
         $definition->setArguments(['mapper' => '@' . $mapperName, 'dependencyProvider' => '@' . $this->prefix('dependencyProvider')]);
         $definition->addSetup('setModel', ['@' . $this->prefix('model')]);
     }
     return $repositories;
 }
开发者ID:sw2eu,项目名称:dynamic-model,代码行数:28,代码来源:DynamicOrmExtension.php

示例7: injectComponentFactories

 /**
  * @param \Nette\DI\Container $dic
  * @throws MemberAccessException
  * @internal
  */
 public function injectComponentFactories(Nette\DI\Container $dic)
 {
     if (!$this instanceof Nette\Application\UI\PresenterComponent && !$this instanceof Nette\Application\UI\Component) {
         throw new MemberAccessException('Trait ' . __TRAIT__ . ' can be used only in descendants of PresenterComponent.');
     }
     $this->autowireComponentFactoriesLocator = $dic;
     $storage = $dic->hasService('autowired.cacheStorage') ? $dic->getService('autowired.cacheStorage') : $dic->getByType('Nette\\Caching\\IStorage');
     $cache = new Nette\Caching\Cache($storage, 'Kdyby.Autowired.AutowireComponentFactories');
     if ($cache->load($presenterClass = get_class($this)) !== NULL) {
         return;
     }
     $ignore = class_parents('Nette\\Application\\UI\\Presenter') + ['ui' => 'Nette\\Application\\UI\\Presenter'];
     $rc = new ClassType($this);
     foreach ($rc->getMethods() as $method) {
         if (in_array($method->getDeclaringClass()->getName(), $ignore, TRUE) || !Strings::startsWith($method->getName(), 'createComponent')) {
             continue;
         }
         foreach ($method->getParameters() as $parameter) {
             if (!($class = $parameter->getClassName())) {
                 // has object type hint
                 continue;
             }
             if (!$this->findByTypeForFactory($class) && !$parameter->allowsNull()) {
                 throw new MissingServiceException("No service of type {$class} found. Make sure the type hint in {$method} is written correctly and service of this type is registered.");
             }
         }
     }
     $files = array_map(function ($class) {
         return ClassType::from($class)->getFileName();
     }, array_diff(array_values(class_parents($presenterClass) + ['me' => $presenterClass]), $ignore));
     $files[] = ClassType::from($this->autowireComponentFactoriesLocator)->getFileName();
     $cache->save($presenterClass, TRUE, [$cache::FILES => $files]);
 }
开发者ID:kdyby,项目名称:autowired,代码行数:38,代码来源:AutowireComponentFactories.php

示例8: parseAnnotations

	/**
	 * @param string
	 * @param string
	 * @return array
	 */
	public static function parseAnnotations($class, $method = NULL)
	{
		if (strpos($class, '::') !== FALSE && !$method) {
			list($class, $method) = explode('::', $class);
		}

		$ref = new Reflection\Method($class, $method);
		$cRef = new Reflection\ClassType($class);
		$anntations = (array)$ref->getAnnotation('allowed');

		$role = isset($anntations['role']) ? $anntations['role']
			: ($ref->hasAnnotation('role') ? $ref->getAnnotation('role') : NULL);

		$resource = isset($anntations['resource']) ? $anntations['resource']
			: ($ref->hasAnnotation('resource')
			? $ref->getAnnotation('resource')
				: ($cRef->hasAnnotation('resource') ? $cRef->getAnnotation('resource') : NULL));

		$privilege = isset($anntations['privilege']) ? $anntations['privilege']
			: ($ref->hasAnnotation('privilege') ? $ref->getAnnotation('privilege') : NULL);

		return array(
			static::ROLE => $role,
			static::RESOURCE => $resource,
			static::PRIVILEGE => $privilege,
		);
	}
开发者ID:norbe,项目名称:framework,代码行数:32,代码来源:Authorizator.php

示例9: setupTemplate

 protected function setupTemplate($view = "default", $filename = null)
 {
     $controlReflection = new Nette\Reflection\ClassType(get_class($this));
     $controlDir = dirname($controlReflection->getFileName());
     $filename = $filename ? $controlDir . DIRECTORY_SEPARATOR . $filename : $controlDir . DIRECTORY_SEPARATOR . "{$view}.latte";
     $this->template->setFile($filename);
     return $this->template;
 }
开发者ID:RiKap,项目名称:ErrorMonitoring,代码行数:8,代码来源:FactoryBaseControl.php

示例10: getAllClassesImplementing

 /**
  * Returns all classes implementing specified interface
  *
  * @param string interface name
  * @return array of fully qualified class names (with namespace)
  */
 public function getAllClassesImplementing($interfaceName)
 {
     $cacheKey = array();
     $cacheKey[] = 'implementing';
     $cacheKey[] = $interfaceName;
     return $this->getAllClassesHelper($cacheKey, function ($className) use($interfaceName) {
         $class = new Nette\Reflection\ClassType($className);
         return $class->implementsInterface($interfaceName) && $interfaceName != $className;
     });
 }
开发者ID:vbuilder,项目名称:framework,代码行数:16,代码来源:ClassInfoProvider.php

示例11: createNew

 /**
  * @param array $values
  */
 public function createNew($arguments = array())
 {
     $class = $this->getEntityName();
     if (!$arguments) {
         $entity = new $class();
     } else {
         $reflection = new Nette\Reflection\ClassType($class);
         $entity = $reflection->newInstanceArgs($arguments);
     }
     return $entity;
 }
开发者ID:svobodni,项目名称:web,代码行数:14,代码来源:BaseRepository.php

示例12: startup

 public function startup()
 {
     parent::startup();
     $classReflection = new Nette\Reflection\ClassType('Helpers');
     $methods = $classReflection->getMethods();
     foreach ($methods as $method) {
         $this->template->registerHelper($method->getName(), 'Helpers::' . $method->getName());
     }
     $this->template->kategorie = $this->kategorie->getMenu();
     $this->template->aktuality = $this->clanky->getClanky(5, 0, "aktuality", null, true);
 }
开发者ID:stanley89,项目名称:piratskelisty,代码行数:11,代码来源:BasePresenter.php

示例13: getSubscribedEvents

 /**
  * @return array
  */
 public final function getSubscribedEvents()
 {
     $list = [];
     $ref = new ClassType($this);
     foreach ($ref->getMethods() as $method) {
         if ($method->getAnnotation('subscribe')) {
             $list[] = $method->name;
         }
     }
     return $list;
 }
开发者ID:VasekPurchart,项目名称:khanovaskola-v3,代码行数:14,代码来源:Badge.php

示例14: getPersistentParams

 /**
  * Returns array of classes persistent parameters. They have public visibility and are non-static.
  * This default implementation detects persistent parameters by annotation @persistent.
  *
  * @return array
  */
 public static function getPersistentParams()
 {
     /*5.2*$arg = func_get_arg(0);*/
     $rc = new Nette\Reflection\ClassType(get_called_class());
     $params = array();
     foreach ($rc->getProperties(\ReflectionProperty::IS_PUBLIC) as $rp) {
         if (!$rp->isStatic() && $rp->hasAnnotation('persistent')) {
             $params[] = $rp->getName();
         }
     }
     return $params;
 }
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:18,代码来源:PresenterComponent.php

示例15: __callStatic

 /**
  * Allowing to emit static events through public variable
  *
  * @param string name
  * @param array of args
  * @return mixed
  */
 public static function __callStatic($name, $args)
 {
     $class = new Nette\Reflection\ClassType(get_called_class());
     $properties = $class->getStaticProperties();
     if (isset($properties[$name])) {
         if (is_array($list = $properties[$name]) || $list instanceof \Traversable) {
             foreach ($list as $handler) {
                 callback($handler)->invokeArgs($args);
             }
         }
         return NULL;
     }
     return parent::__callStatic($name, $args);
 }
开发者ID:vbuilder,项目名称:framework,代码行数:21,代码来源:Object.php


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