Update to Drupal 8.0.0 beta 14. For more information, see https://drupal.org/node/2544542
This commit is contained in:
parent
3b2511d96d
commit
81ccda77eb
2155 changed files with 54307 additions and 46870 deletions
|
@ -22,7 +22,30 @@ class ProxyBuilder {
|
|||
* The class name of the proxy.
|
||||
*/
|
||||
public static function buildProxyClassName($class_name) {
|
||||
return str_replace('\\', '_', $class_name) . '_Proxy';
|
||||
$match = [];
|
||||
preg_match('/([a-zA-Z0-9_]+\\\\[a-zA-Z0-9_]+)\\\\(.+)/', $class_name, $match);
|
||||
$root_namespace = $match[1];
|
||||
$rest_fqcn = $match[2];
|
||||
$proxy_class_name = $root_namespace . '\\ProxyClass\\' . $rest_fqcn;
|
||||
|
||||
return $proxy_class_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the used proxy namespace from a given class name.
|
||||
*
|
||||
* @param string $class_name
|
||||
* The class name of the actual service.
|
||||
*
|
||||
* @return string
|
||||
* The namespace name of the proxy.
|
||||
*/
|
||||
public static function buildProxyNamespace($class_name) {
|
||||
$proxy_classname = static::buildProxyClassName($class_name);
|
||||
|
||||
preg_match('/(.+)\\\\[a-zA-Z0-9]+/', $proxy_classname, $match);
|
||||
$proxy_namespace = $match[1];
|
||||
return $proxy_namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -30,23 +53,38 @@ class ProxyBuilder {
|
|||
*
|
||||
* @param string $class_name
|
||||
* The class name of the actual service.
|
||||
* @param string $proxy_class_name
|
||||
* (optional) The class name of the proxy service.
|
||||
*
|
||||
* @return string
|
||||
* The full string with namespace class and methods.
|
||||
*/
|
||||
public function build($class_name) {
|
||||
public function build($class_name, $proxy_class_name = '') {
|
||||
$reflection = new \ReflectionClass($class_name);
|
||||
|
||||
if ($proxy_class_name) {
|
||||
$proxy_class_reflection = new \ReflectionClass($proxy_class_name);
|
||||
$proxy_namespace = $proxy_class_reflection->getNamespaceName();
|
||||
}
|
||||
else {
|
||||
$proxy_class_name = $this->buildProxyClassName($class_name);
|
||||
$proxy_namespace = $this->buildProxyNamespace($class_name);
|
||||
$proxy_class_shortname = str_replace($proxy_namespace . '\\', '', $proxy_class_name);
|
||||
}
|
||||
|
||||
$output = '';
|
||||
$class_documentation = <<<'EOS'
|
||||
/**
|
||||
* Provides a proxy class for \{{ class_name }}.
|
||||
*
|
||||
* @see \Drupal\Component\ProxyBuilder
|
||||
*/
|
||||
|
||||
namespace {{ namespace }}{
|
||||
|
||||
/**
|
||||
* Provides a proxy class for \{{ class_name }}.
|
||||
*
|
||||
* @see \Drupal\Component\ProxyBuilder
|
||||
*/
|
||||
|
||||
EOS;
|
||||
$class_start = 'class {{ proxy_class_name }}';
|
||||
$class_start = ' class {{ proxy_class_shortname }}';
|
||||
|
||||
// For cases in which the implemented interface is a child of another
|
||||
// interface, getInterfaceNames() also returns the parent. This causes a
|
||||
|
@ -77,11 +115,15 @@ EOS;
|
|||
// The actual class;
|
||||
$properties = <<<'EOS'
|
||||
/**
|
||||
* The id of the original proxied service.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $serviceId;
|
||||
protected $drupalProxyOriginalServiceId;
|
||||
|
||||
/**
|
||||
* The real proxied service, after it was lazy loaded.
|
||||
*
|
||||
* @var \{{ class_name }}
|
||||
*/
|
||||
protected $service;
|
||||
|
@ -123,13 +165,14 @@ EOS;
|
|||
if ($value === '') {
|
||||
return $value;
|
||||
}
|
||||
return " $value";
|
||||
return " $value";
|
||||
}, explode("\n", $output)));
|
||||
|
||||
$final_output = $class_documentation . $class_start . "\n{\n\n" . $output . "\n}\n";
|
||||
$final_output = $class_documentation . $class_start . "\n {\n\n" . $output . "\n }\n\n}\n";
|
||||
|
||||
$final_output = str_replace('{{ class_name }}', $class_name, $final_output);
|
||||
$final_output = str_replace('{{ proxy_class_name }}', $this->buildProxyClassName($class_name), $final_output);
|
||||
$final_output = str_replace('{{ namespace }}', $proxy_namespace ? $proxy_namespace . ' ' : '', $final_output);
|
||||
$final_output = str_replace('{{ proxy_class_shortname }}', $proxy_class_shortname, $final_output);
|
||||
|
||||
return $final_output;
|
||||
}
|
||||
|
@ -141,11 +184,16 @@ EOS;
|
|||
*/
|
||||
protected function buildLazyLoadItselfMethod() {
|
||||
$output = <<<'EOS'
|
||||
/**
|
||||
* Lazy loads the real service from the container.
|
||||
*
|
||||
* @return object
|
||||
* Returns the constructed real service.
|
||||
*/
|
||||
protected function lazyLoadItself()
|
||||
{
|
||||
if (!isset($this->service)) {
|
||||
$method_name = 'get' . Container::camelize($this->serviceId) . 'Service';
|
||||
$this->service = $this->container->$method_name(false);
|
||||
$this->service = $this->container->get($this->drupalProxyOriginalServiceId);
|
||||
}
|
||||
|
||||
return $this->service;
|
||||
|
@ -177,11 +225,19 @@ EOS;
|
|||
if ($reflection_method->returnsReference()) {
|
||||
$reference = '&';
|
||||
}
|
||||
|
||||
$signature_line = <<<'EOS'
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
||||
EOS;
|
||||
|
||||
if ($reflection_method->isStatic()) {
|
||||
$signature_line = 'public static function ' . $reference . $function_name . '(';
|
||||
$signature_line .= 'public static function ' . $reference . $function_name . '(';
|
||||
}
|
||||
else {
|
||||
$signature_line = 'public function ' . $reference . $function_name . '(';
|
||||
$signature_line .= 'public function ' . $reference . $function_name . '(';
|
||||
}
|
||||
|
||||
$signature_line .= implode(', ', $parameters);
|
||||
|
@ -269,10 +325,18 @@ EOS;
|
|||
*/
|
||||
protected function buildConstructorMethod() {
|
||||
$output = <<<'EOS'
|
||||
public function __construct(\Symfony\Component\DependencyInjection\ContainerInterface $container, $serviceId)
|
||||
/**
|
||||
* Constructs a ProxyClass Drupal proxy object.
|
||||
*
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
|
||||
* The container.
|
||||
* @param string $drupal_proxy_original_service_id
|
||||
* The service ID of the original service.
|
||||
*/
|
||||
public function __construct(\Symfony\Component\DependencyInjection\ContainerInterface $container, $drupal_proxy_original_service_id)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->serviceId = $serviceId;
|
||||
$this->drupalProxyOriginalServiceId = $drupal_proxy_original_service_id;
|
||||
}
|
||||
|
||||
EOS;
|
||||
|
|
|
@ -1,78 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Component\ProxyBuilder\ProxyDumper.
|
||||
*/
|
||||
|
||||
namespace Drupal\Component\ProxyBuilder;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface;
|
||||
|
||||
/**
|
||||
* Dumps the proxy service into the dumped PHP container file.
|
||||
*/
|
||||
class ProxyDumper implements DumperInterface {
|
||||
|
||||
/**
|
||||
* Keeps track of already existing proxy classes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $buildClasses = [];
|
||||
|
||||
/**
|
||||
* The proxy builder.
|
||||
*
|
||||
* @var \Drupal\Component\ProxyBuilder\ProxyBuilder
|
||||
*/
|
||||
protected $builder;
|
||||
|
||||
public function __construct(ProxyBuilder $builder) {
|
||||
$this->builder = $builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isProxyCandidate(Definition $definition) {
|
||||
return $definition->isLazy() && ($class = $definition->getClass()) && class_exists($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getProxyFactoryCode(Definition $definition, $id) {
|
||||
// Note: the specific get method is called initially with $lazyLoad=TRUE;
|
||||
// When you want to retrieve the actual service, the code generated in
|
||||
// ProxyBuilder calls the method with lazy loading disabled.
|
||||
$output = <<<'EOS'
|
||||
if ($lazyLoad) {
|
||||
return $this->services['{{ id }}'] = new {{ class_name }}($this, '{{ id }}');
|
||||
}
|
||||
|
||||
EOS;
|
||||
$output = str_replace('{{ id }}', $id, $output);
|
||||
$output = str_replace('{{ class_name }}', $this->builder->buildProxyClassName($definition->getClass()), $output);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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 '';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
"homepage": "https://www.drupal.org/project/drupal",
|
||||
"license": "GPL-2.0+",
|
||||
"require": {
|
||||
"php": ">=5.4.2",
|
||||
"php": ">=5.5.9",
|
||||
"symfony/dependency-injection": "~2.6"
|
||||
},
|
||||
"autoload": {
|
||||
|
|
Reference in a new issue