本文整理匯總了PHP中Nette\Reflection\ClassType::from方法的典型用法代碼示例。如果您正苦於以下問題:PHP ClassType::from方法的具體用法?PHP ClassType::from怎麽用?PHP ClassType::from使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Nette\Reflection\ClassType
的用法示例。
在下文中一共展示了ClassType::from方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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]);
}
示例2: setupServices
private function setupServices()
{
$builder = $this->getContainerBuilder();
$config = $this->validateConfig($this->defaults);
$gopay = $builder->getDefinition($this->prefix('gopay'));
$services = ['payment' => PaymentService::class, 'recurrentPayment' => RecurrentPaymentService::class, 'preAuthorizedPayment' => PreAuthorizedPaymentService::class];
foreach ($services as $serviceName => $serviceClass) {
$def = $builder->addDefinition($this->prefix("service.{$serviceName}"))->setClass($serviceClass, [$gopay]);
if (is_bool($config['payments']['changeChannel'])) {
$def->addSetup('allowChangeChannel', [$config['payments']['changeChannel']]);
}
if (isset($config['payments']['channels'])) {
$constants = ClassType::from(Gopay::class);
foreach ($config['payments']['channels'] as $code => $channel) {
$constChannel = 'METHOD_' . strtoupper($code);
if ($constants->hasConstant($constChannel)) {
$code = $constants->getConstant($constChannel);
}
if (is_array($channel)) {
$channel['code'] = $code;
$def->addSetup('addChannel', $channel);
} else {
if (is_scalar($channel)) {
$def->addSetup('addChannel', [$code, $channel]);
}
}
}
}
}
}
示例3: getSchema
/**
* @param $class
*/
public function getSchema($class)
{
if (!isset($this->_annotationSchema[$class])) {
$schema = array();
$ref = ClassType::from($class);
if ($ref->hasAnnotation('secured')) {
foreach ($ref->getMethods() as $method) {
$name = $method->getName();
if (substr($name, 0, 6) !== 'action' && substr($name, 0, 6) !== 'handle') {
continue;
}
if ($method->hasAnnotation('secured')) {
$secured = $method->getAnnotation('secured');
$name = $method->getName();
$schema[$name] = array();
$schema[$name]['resource'] = $this->getSchemaOfResource($method, $secured);
$schema[$name]['privilege'] = $this->getSchemaOfPrivilege($method, $secured);
$schema[$name]['roles'] = $this->getSchemaOfRoles($method, $secured);
$schema[$name]['users'] = $this->getSchemaOfUsers($method, $secured);
}
}
}
$this->_annotationSchema[$class] = $schema;
}
return $this->_annotationSchema[$class];
}
示例4: build
public static function build($className)
{
$reflection = \Nette\Reflection\ClassType::from($className);
$annotations = $reflection->getAnnotations();
$ret = array('entityClass' => $className);
foreach ($annotations as $key => $value) {
if ($key == "Entity") {
$entity = $value[0];
if (isset($entity->repositoryClass)) {
$ret['repositoryClass'] = (string) $entity->repositoryClass;
} elseif (isset($entity->validatorClass)) {
$ret['validatorClass'] = (string) $entity->validatorClass;
}
} elseif ($key == "Table") {
$table = $value[0];
$ret['table'] = (string) $table->name;
$ret['mainIndex'] = isset($table->mainIndex) ? (string) $table->mainIndex : NULL;
$ret['topicIndex'] = isset($table->topicIndex) ? (string) $table->topicIndex : NULL;
} elseif ($key == "Column") {
foreach ($value as $column) {
$name = $column->name;
unset($column->name);
$ret['columns'][$name] = (array) $column;
}
} elseif (in_array($key, array("AssociationHasOne", "AssociationHasMany"))) {
foreach ($value as $association) {
$name = $association->name;
unset($association->name);
$ret['associations'][$name] = (array) $association;
}
}
}
return $ret;
}
示例5: testSignalAllow
public function testSignalAllow()
{
$this->presenter->setSignalMock("test2");
$this->presenter->checkRequirements(ClassType::from(__NAMESPACE__ . '\BackendPresenter\PresenterMock'));
$this->assertFalse($this->presenter->isAllowedMock('handleTest1'));
$this->assertTrue($this->presenter->isAllowedMock('handleTest2'));
}
示例6: __construct
public function __construct($type)
{
if (strpos($type, '*') !== FALSE) {
$this->pattern = str_replace('\\*', '.*', preg_quote($type));
} else {
$this->type = Nette\Reflection\ClassType::from($type)->getName();
}
}
示例7: __set
/**
* Sets a variable in this session section.
* @param string name
* @param mixed value
* @return void
*/
public function __set($name, $value)
{
$this->start();
$this->data[$name] = $value;
if (is_object($value)) {
$this->meta[$name]['V'] = Nette\Reflection\ClassType::from($value)->getAnnotation('serializationVersion');
}
}
示例8: loadConfiguration
public function loadConfiguration()
{
$builder = $this->getContainerBuilder();
$latte = $builder->hasDefinition('nette.latteFactory') ? $builder->getDefinition('nette.latteFactory') : $builder->getDefinition('nette.latte');
$latte->addSetup('Lohini\\Latte\\Macros\\CoreMacros::install(?->getCompiler())', ['@self']);
foreach (\Nette\Reflection\ClassType::from('Lohini\\Latte\\Filters')->getMethods() as $method) {
$latte->addSetup('addFilter', [$method->name, ['Lohini\\Latte\\Filters', $method->name]]);
}
}
示例9: __construct
public function __construct(Nette\DI\ServiceDefinition $def, $serviceId)
{
$this->serviceDefinition = $def;
if (empty($def->class)) {
throw new Kdyby\Aop\InvalidArgumentException("Given service definition has unresolved class, please specify service type explicitly.");
}
$this->originalType = Nette\Reflection\ClassType::from($def->class);
$this->serviceId = $serviceId;
}
示例10: registerExtension
/**
* Registers adapter for given file extension.
* @param string file extension
* @param string class name (IConfigAdapter)
* @return void
*/
public static function registerExtension($extension, $class)
{
if (!class_exists($class)) {
throw new Nette\InvalidArgumentException("Class '{$class}' was not found.");
}
if (!Nette\Reflection\ClassType::from($class)->implementsInterface('Nette\\Config\\IAdapter')) {
throw new Nette\InvalidArgumentException("Configuration adapter '{$class}' is not Nette\\Config\\IAdapter implementor.");
}
self::$extensions[strtolower($extension)] = $class;
}
示例11: beforeCompile
public function beforeCompile()
{
$builder = $this->getContainerBuilder();
$mapping = $builder->getDefinition('movi.entityMapping');
foreach (array_keys($builder->findByTag(self::REPOSITORY_TAG)) as $repository) {
$reflection = ClassType::from($builder->getDefinition($repository)->class);
$class = $reflection->newInstanceWithoutConstructor();
$mapping->addSetup('registerEntities', array($class->getEntities()));
}
}
示例12: getTests
public function getTests()
{
$tests = [];
foreach (ClassType::from($this)->getMethods(Method::IS_PUBLIC) as $method) {
$name = $method->getShortName();
if (preg_match(static::METHOD_PATTERN, $name)) {
$tests[] = $name;
}
}
return $tests;
}
示例13: getValues
/**
* Získá všechny hodnoty z entity, které mají anotaci @column a nemají anotaci @id.
* @return array
*/
public function getValues()
{
$reflector = \Nette\Reflection\ClassType::from($this);
$values = array();
foreach ($reflector->getProperties() as $property) {
if ($property->hasAnnotation("column") && !$property->hasAnnotation("id")) {
$name = $property->getName();
$values[$this->normalizeColumnName($name)] = $this->{$name};
}
}
return $values;
}
示例14: preFlush
public function preFlush(PreFlushEventArgs $args)
{
$em = $args->getEntityManager();
$uow = $em->getUnitOfWork();
foreach ($uow->getScheduledEntityInsertions() as $entity) {
$reflection = Nette\Reflection\ClassType::from($entity);
if ($reflection->hasProperty("priority")) {
$repository = $em->getRepository($reflection->getName());
$result = $repository->createQueryBuilder("p")->select("MAX(p.priority)")->getQuery()->execute();
$entity->priority = ($result ? (int) $result[0][1] : 0) + 1;
}
}
}
示例15: createBaseQuery
/**
* @param $entity
* @param callable $modifier
* @return \Kdyby\Doctrine\QueryBuilder
*/
private function createBaseQuery($entity, $modifier)
{
$reflection = ClassType::from($entity);
if (!$reflection->hasProperty('priority')) {
throw new InvalidArgumentException('Entity has not property $priority');
}
$qb = $this->entityManager->getRepository($reflection->getName())->createQueryBuilder("e")->select();
if ($modifier !== NULL) {
$modifier($qb);
}
$qb->setMaxResults(1);
return $qb;
}