本文整理汇总了PHP中Symfony\Component\DependencyInjection\Definition::getClass方法的典型用法代码示例。如果您正苦于以下问题:PHP Definition::getClass方法的具体用法?PHP Definition::getClass怎么用?PHP Definition::getClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DependencyInjection\Definition
的用法示例。
在下文中一共展示了Definition::getClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processDefinition
/**
* @param Definition $definition
*/
protected function processDefinition(Definition $definition)
{
if ($definition->isSynthetic()) {
return;
}
if ($definition->getFactoryService() || $definition->getFactoryClass()) {
return;
}
if ($file = $definition->getFile()) {
require_once $file;
}
if (!class_exists($definition->getClass())) {
return;
}
$class = new \ReflectionClass($definition->getClass());
if (!$class->implementsInterface(static::INTERFACE_CLASS)) {
return;
}
$metadata = $this->getMetadataFactory()->getMetadataForClass($definition->getClass());
if (!$metadata instanceof ClassMetadata) {
return;
}
$namespace = $metadata->getNamespace() ?: static::ROOT_NAMESPACE;
$serviceName = static::PROVIDER_PREFIX . substr(sha1($namespace), 0, 10);
if (!$this->container->hasDefinition($serviceName)) {
$cacher = new Definition('Werkint\\Bundle\\CacheBundle\\Service\\CacheProvider', [$this->container->getParameter('kernel.cache_dir') . '/werkint_cache']);
$cacher->setPublic(true);
$cacher->addMethodCall('setNamespace', [$namespace]);
$this->container->setDefinition($serviceName, $cacher);
}
$definition->addMethodCall('setCacheProvider', [new Reference($serviceName)]);
}
示例2: addService
/**
* Adds a service
*
* @param string $id
* @param Definition $definition
*
* @return string
*/
private function addService($id, $definition)
{
$code = " {$id}:\n";
if ($definition->getClass()) {
$code .= sprintf(" class: %s\n", $definition->getClass());
}
$tagsCode = '';
foreach ($definition->getTags() as $name => $tags) {
foreach ($tags as $attributes) {
$att = array();
foreach ($attributes as $key => $value) {
$att[] = sprintf('%s: %s', $this->dumper->dump($key), $this->dumper->dump($value));
}
$att = $att ? ', ' . implode(' ', $att) : '';
$tagsCode .= sprintf(" - { name: %s%s }\n", $this->dumper->dump($name), $att);
}
}
if ($tagsCode) {
$code .= " tags:\n" . $tagsCode;
}
if ($definition->getFile()) {
$code .= sprintf(" file: %s\n", $definition->getFile());
}
if ($definition->isSynthetic()) {
$code .= sprintf(" synthetic: true\n");
}
if ($definition->isSynchronized()) {
$code .= sprintf(" synchronized: true\n");
}
if ($definition->getFactoryMethod()) {
$code .= sprintf(" factory_method: %s\n", $definition->getFactoryMethod());
}
if ($definition->getFactoryService()) {
$code .= sprintf(" factory_service: %s\n", $definition->getFactoryService());
}
if ($definition->getArguments()) {
$code .= sprintf(" arguments: %s\n", $this->dumper->dump($this->dumpValue($definition->getArguments()), 0));
}
if ($definition->getProperties()) {
$code .= sprintf(" properties: %s\n", $this->dumper->dump($this->dumpValue($definition->getProperties()), 0));
}
if ($definition->getMethodCalls()) {
$code .= sprintf(" calls:\n%s\n", $this->dumper->dump($this->dumpValue($definition->getMethodCalls()), 1, 12));
}
if (ContainerInterface::SCOPE_CONTAINER !== ($scope = $definition->getScope())) {
$code .= sprintf(" scope: %s\n", $scope);
}
if ($callable = $definition->getConfigurator()) {
if (is_array($callable)) {
if ($callable[0] instanceof Reference) {
$callable = array($this->getServiceCall((string) $callable[0], $callable[0]), $callable[1]);
} else {
$callable = array($callable[0], $callable[1]);
}
}
$code .= sprintf(" configurator: %s\n", $this->dumper->dump($callable, 0));
}
return $code;
}
示例3: addService
/**
* Adds a service.
*
* @param string $id
* @param Definition $definition
*
* @return string
*/
private function addService($id, $definition)
{
$code = " {$id}:\n";
if ($definition->getClass()) {
$code .= sprintf(" class: %s\n", $definition->getClass());
}
if (!$definition->isPublic()) {
$code .= " public: false\n";
}
$tagsCode = '';
foreach ($definition->getTags() as $name => $tags) {
foreach ($tags as $attributes) {
$att = array();
foreach ($attributes as $key => $value) {
$att[] = sprintf('%s: %s', $this->dumper->dump($key), $this->dumper->dump($value));
}
$att = $att ? ', ' . implode(', ', $att) : '';
$tagsCode .= sprintf(" - { name: %s%s }\n", $this->dumper->dump($name), $att);
}
}
if ($tagsCode) {
$code .= " tags:\n" . $tagsCode;
}
if ($definition->getFile()) {
$code .= sprintf(" file: %s\n", $definition->getFile());
}
if ($definition->isSynthetic()) {
$code .= sprintf(" synthetic: true\n");
}
if ($definition->isLazy()) {
$code .= sprintf(" lazy: true\n");
}
if ($definition->getArguments()) {
$code .= sprintf(" arguments: %s\n", $this->dumper->dump($this->dumpValue($definition->getArguments()), 0));
}
if ($definition->getProperties()) {
$code .= sprintf(" properties: %s\n", $this->dumper->dump($this->dumpValue($definition->getProperties()), 0));
}
if ($definition->getMethodCalls()) {
$code .= sprintf(" calls:\n%s\n", $this->dumper->dump($this->dumpValue($definition->getMethodCalls()), 1, 12));
}
if (ContainerInterface::SCOPE_CONTAINER !== ($scope = $definition->getScope())) {
$code .= sprintf(" scope: %s\n", $scope);
}
if (null !== ($decorated = $definition->getDecoratedService())) {
list($decorated, $renamedId) = $decorated;
$code .= sprintf(" decorates: %s\n", $decorated);
if (null !== $renamedId) {
$code .= sprintf(" decoration_inner_name: %s\n", $renamedId);
}
}
if ($callable = $definition->getFactory()) {
$code .= sprintf(" factory: %s\n", $this->dumper->dump($this->dumpCallable($callable), 0));
}
if ($callable = $definition->getConfigurator()) {
$code .= sprintf(" configurator: %s\n", $this->dumper->dump($this->dumpCallable($callable), 0));
}
return $code;
}
示例4: assertProvider
private function assertProvider(ContainerBuilder $container, Definition $definition)
{
$class = $container->getParameterBag()->resolveValue($definition->getClass());
$refClass = new \ReflectionClass($class);
if (!$refClass->implementsInterface('Hateoas\\Configuration\\Provider\\Resolver\\RelationProviderResolverInterface')) {
throw new InvalidArgumentException(sprintf('Relation provider "%s" does not implement the ReleationProviderResolver interface', $definition->getClass()));
}
}
示例5: validate
public function validate(Definition $definition) : bool
{
if (!$definition->isPublic() || $definition->isAbstract()) {
return false;
}
if (null === $definition->getClass() || !class_exists($definition->getClass())) {
return false;
}
return true;
}
示例6: getProxyCode
/**
* {@inheritdoc}
*/
public function getProxyCode(Definition $definition)
{
// Maybe the same class is used in different services, which are both marked
// as lazy (just think about 2 database connections).
// In those cases we should not generate proxy code the second time.
if (!isset($this->buildClasses[$definition->getClass()])) {
$this->buildClasses[$definition->getClass()] = TRUE;
return $this->builder->build($definition->getClass());
} else {
return '';
}
}
示例7: testConstructor
/**
* @covers Symfony\Component\DependencyInjection\Definition::__construct
*/
public function testConstructor()
{
$def = new Definition('stdClass');
$this->assertEquals('stdClass', $def->getClass(), '__construct() takes the class name as its first argument');
$def = new Definition('stdClass', array('foo'));
$this->assertEquals(array('foo'), $def->getArguments(), '__construct() takes an optional array of arguments as its second argument');
}
示例8: watchServiceClassForChanges
private function watchServiceClassForChanges(Definition $definition, ContainerBuilder $containerBuilder)
{
$classReflection = new ReflectionClass($definition->getClass());
do {
$containerBuilder->addResource(new FileResource($classReflection->getFileName()));
} while ($classReflection = $classReflection->getParentClass());
}
示例9: assertDefinition
/**
* @param Definition $definition
* @param string $class
* @param string $repository
*/
private function assertDefinition(Definition $definition, $class, $repository)
{
$this->assertSame($definition->getClass(), $repository);
$factory = $definition->getFactory();
$this->assertSame($factory[1], "getRepository");
$this->assertSame($definition->getArgument(0), $class);
}
开发者ID:itkg-canne,项目名称:open-orchestra-media-bundle,代码行数:12,代码来源:OpenOrchestraMediaModelExtensionTest.php
示例10: guardAgainstInvalidClass
/**
* @param Definition $emitterService
* @param string $expectedInterface
*
* @throws LogicException
*/
private function guardAgainstInvalidClass(Definition $emitterService, $expectedInterface)
{
$definedClass = $emitterService->getClass();
$reflection = new ReflectionClass($definedClass);
if ($reflection->implementsInterface($expectedInterface) === false) {
throw new LogicException(sprintf('Invalid class type registered, expected %s, got %s.', $expectedInterface, $definedClass));
}
}
示例11: addDefinitionArguments
/**
* @param Definition $definition
* @param stdClass $dependables
*/
private function addDefinitionArguments(Definition $definition, stdClass $dependables)
{
$class = $definition->getClass();
$dependables->references[$class] = array();
for ($arg = 0; $arg < count($definition->getArguments()); $arg++) {
$dependables->references[$class][$arg] = $definition->getArgument($arg);
}
}
示例12: assertClassImplementInterface
/**
* @param ContainerBuilder $container
* @param Definition $definition
* @param string $id
*/
private function assertClassImplementInterface(ContainerBuilder $container, Definition $definition, $id)
{
$class = $this->resolveClassName($container, $definition->getClass());
$refClass = new ReflectionClass($class);
if (!$refClass->implementsInterface($this->interfaceToImplement)) {
throw new InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $this->interfaceToImplement));
}
}
示例13: instantiateProxy
/**
* {@inheritdoc}
*/
public function instantiateProxy(ContainerInterface $container, Definition $definition, $id, $realInstantiator)
{
return $this->factory->createProxy($definition->getClass(), function (&$wrappedInstance, LazyLoadingInterface $proxy) use($realInstantiator) {
$wrappedInstance = call_user_func($realInstantiator);
$proxy->setProxyInitializer(null);
return true;
});
}
示例14: injectContainer
/**
* @param Definition $definition
* @param Reference $container
*/
private function injectContainer(Definition $definition, Reference $container)
{
$class = $definition->getClass();
if (empty($class) || !is_subclass_of($class, ContainerAwareInterface::class)) {
return;
}
$definition->addMethodCall('setContainer', [$container]);
}
示例15: isDefinitionATemplate
/**
* Is the definition an interface template?
*
* @access private
* @return boolean
*/
private function isDefinitionATemplate(Definition $definition)
{
try {
$reflect = new \ReflectionClass($definition->getClass());
} catch (\ReflectionException $e) {
return false;
}
return $reflect->isInterface();
}