From a4c15bbf4f108604d1839648662f6ef26b77930e Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 21 May 2014 22:24:48 +0200 Subject: [PATCH 01/10] [ticket/12575] Speed up load_class() Load the services referenced in a service_collection only when they are used to avoid to load some unsuded services. PHPBB3-12575 --- phpBB/phpbb/di/service_collection.php | 81 ++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/di/service_collection.php b/phpBB/phpbb/di/service_collection.php index 3a18644891..f0b387a5b1 100644 --- a/phpBB/phpbb/di/service_collection.php +++ b/phpBB/phpbb/di/service_collection.php @@ -30,6 +30,28 @@ class service_collection extends \ArrayObject $this->container = $container; } + /** + * {@inheritdoc} + */ + public function getIterator() + { + return new service_collection_iterator($this->container, $this); + } + + /** + * {@inheritdoc} + */ + public function offsetGet($index) + { + if (($task = parent::offsetGet($index)) == null) + { + $task = $this->container->get($index); + $this->offsetSet($index, $task); + } + + return $task; + } + /** * Add a service to the collection * @@ -38,8 +60,61 @@ class service_collection extends \ArrayObject */ public function add($name) { - $task = $this->container->get($name); - - $this->offsetSet($name, $task); + $this->offsetSet($name, null); + } +} + + +/** +* Iterator which load the services when they are requested +* +* @package phpBB3 +*/ +class service_collection_iterator extends \ArrayIterator +{ + protected $container; + + /** + * Construct an ArrayIterator for service_collection + * + * @param ContainerInterface $container Container object + * @param array $array The array or object to be iterated on. + * @param int $flags Flags to control the behaviour of the ArrayObject object. + * @see ArrayObject::setFlags() + */ + public function __construct(ContainerInterface $container, $array = array() , $flags = 0) + { + parent::__construct($array, $flags); + $this->container = $container; + } + + /** + * {@inheritdoc} + */ + public function offsetGet($index) + { + if (($task = parent::offsetGet($index)) == null) + { + $task = $this->container->get($index); + $this->offsetSet($index, $task); + } + + return $task; + } + + + /** + * {@inheritdoc} + */ + public function current() + { + if (($task = parent::current()) == null) + { + $name = $this->key(); + $task = $this->container->get($name); + $this->offsetSet($name, $task); + } + + return $task; } } From a0985c7a22014ac1b354f95195d26fd002bf1374 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 21 May 2014 23:09:25 +0200 Subject: [PATCH 02/10] [ticket/12575] Move service_collection_iterator to its own file PHPBB3-12575 --- phpBB/phpbb/di/service_collection.php | 55 ---------------- .../phpbb/di/service_collection_iterator.php | 65 +++++++++++++++++++ 2 files changed, 65 insertions(+), 55 deletions(-) create mode 100644 phpBB/phpbb/di/service_collection_iterator.php diff --git a/phpBB/phpbb/di/service_collection.php b/phpBB/phpbb/di/service_collection.php index f0b387a5b1..032d299553 100644 --- a/phpBB/phpbb/di/service_collection.php +++ b/phpBB/phpbb/di/service_collection.php @@ -63,58 +63,3 @@ class service_collection extends \ArrayObject $this->offsetSet($name, null); } } - - -/** -* Iterator which load the services when they are requested -* -* @package phpBB3 -*/ -class service_collection_iterator extends \ArrayIterator -{ - protected $container; - - /** - * Construct an ArrayIterator for service_collection - * - * @param ContainerInterface $container Container object - * @param array $array The array or object to be iterated on. - * @param int $flags Flags to control the behaviour of the ArrayObject object. - * @see ArrayObject::setFlags() - */ - public function __construct(ContainerInterface $container, $array = array() , $flags = 0) - { - parent::__construct($array, $flags); - $this->container = $container; - } - - /** - * {@inheritdoc} - */ - public function offsetGet($index) - { - if (($task = parent::offsetGet($index)) == null) - { - $task = $this->container->get($index); - $this->offsetSet($index, $task); - } - - return $task; - } - - - /** - * {@inheritdoc} - */ - public function current() - { - if (($task = parent::current()) == null) - { - $name = $this->key(); - $task = $this->container->get($name); - $this->offsetSet($name, $task); - } - - return $task; - } -} diff --git a/phpBB/phpbb/di/service_collection_iterator.php b/phpBB/phpbb/di/service_collection_iterator.php new file mode 100644 index 0000000000..ace66d1906 --- /dev/null +++ b/phpBB/phpbb/di/service_collection_iterator.php @@ -0,0 +1,65 @@ +container = $container; + } + + /** + * {@inheritdoc} + */ + public function offsetGet($index) + { + if (($task = parent::offsetGet($index)) == null) + { + $task = $this->container->get($index); + $this->offsetSet($index, $task); + } + + return $task; + } + + /** + * {@inheritdoc} + */ + public function current() + { + if (($task = parent::current()) == null) + { + $name = $this->key(); + $task = $this->container->get($name); + $this->offsetSet($name, $task); + } + + return $task; + } +} From bea9372efa650bd97f5b63c23f392bacd56de219 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 22 May 2014 01:09:41 +0200 Subject: [PATCH 03/10] [ticket/12575] Fix the tests PHPBB3-12575 --- phpBB/phpbb/di/service_collection.php | 8 ++++++++ phpBB/phpbb/di/service_collection_iterator.php | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/phpBB/phpbb/di/service_collection.php b/phpBB/phpbb/di/service_collection.php index 032d299553..3ae3f793c0 100644 --- a/phpBB/phpbb/di/service_collection.php +++ b/phpBB/phpbb/di/service_collection.php @@ -38,6 +38,14 @@ class service_collection extends \ArrayObject return new service_collection_iterator($this->container, $this); } + /** + * {@inheritdoc} + */ + public function offsetExists($index) + { + return parent::offsetExists($index); + } + /** * {@inheritdoc} */ diff --git a/phpBB/phpbb/di/service_collection_iterator.php b/phpBB/phpbb/di/service_collection_iterator.php index ace66d1906..93f74adca9 100644 --- a/phpBB/phpbb/di/service_collection_iterator.php +++ b/phpBB/phpbb/di/service_collection_iterator.php @@ -48,6 +48,14 @@ class service_collection_iterator extends \ArrayIterator return $task; } + /** + * {@inheritdoc} + */ + public function offsetExists($index) + { + parent::offsetExists($index); + } + /** * {@inheritdoc} */ From 6e478862273946a2088ff3b672ef64034473bcf3 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 22 May 2014 01:24:11 +0200 Subject: [PATCH 04/10] [ticket/12575] Remove inline assignments PHPBB3-12575 --- phpBB/phpbb/di/service_collection.php | 3 ++- phpBB/phpbb/di/service_collection_iterator.php | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/phpBB/phpbb/di/service_collection.php b/phpBB/phpbb/di/service_collection.php index 3ae3f793c0..6a2e62a553 100644 --- a/phpBB/phpbb/di/service_collection.php +++ b/phpBB/phpbb/di/service_collection.php @@ -51,7 +51,8 @@ class service_collection extends \ArrayObject */ public function offsetGet($index) { - if (($task = parent::offsetGet($index)) == null) + $task = parent::offsetGet($index); + if ($task == null) { $task = $this->container->get($index); $this->offsetSet($index, $task); diff --git a/phpBB/phpbb/di/service_collection_iterator.php b/phpBB/phpbb/di/service_collection_iterator.php index 93f74adca9..a6cb0e6c3e 100644 --- a/phpBB/phpbb/di/service_collection_iterator.php +++ b/phpBB/phpbb/di/service_collection_iterator.php @@ -39,7 +39,8 @@ class service_collection_iterator extends \ArrayIterator */ public function offsetGet($index) { - if (($task = parent::offsetGet($index)) == null) + $task = parent::offsetGet($index); + if ($task == null) { $task = $this->container->get($index); $this->offsetSet($index, $task); @@ -61,7 +62,8 @@ class service_collection_iterator extends \ArrayIterator */ public function current() { - if (($task = parent::current()) == null) + $task = parent::current(); + if ($task == null) { $name = $this->key(); $task = $this->container->get($name); From d4cc6990e48ca4f98e16c717dcdbdf37473312fd Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 22 May 2014 03:02:25 +0200 Subject: [PATCH 05/10] [ticket/12575] Skip sniffer issue triggered by the solution of a php bug https://bugs.php.net/bug.php?id=66834 https://bugs.php.net/bug.php?id=67067 PHPBB3-12575 --- phpBB/phpbb/di/service_collection.php | 7 +++++++ phpBB/phpbb/di/service_collection_iterator.php | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/phpBB/phpbb/di/service_collection.php b/phpBB/phpbb/di/service_collection.php index 6a2e62a553..ebf933d338 100644 --- a/phpBB/phpbb/di/service_collection.php +++ b/phpBB/phpbb/di/service_collection.php @@ -38,6 +38,12 @@ class service_collection extends \ArrayObject return new service_collection_iterator($this->container, $this); } + // Because of a PHP issue we have to redefine offsetExists + // (even Date: Thu, 22 May 2014 11:34:19 +0200 Subject: [PATCH 06/10] [ticket/12575] Fix typos in comments PHPBB3-12575 --- phpBB/phpbb/di/service_collection.php | 2 +- phpBB/phpbb/di/service_collection_iterator.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/phpbb/di/service_collection.php b/phpBB/phpbb/di/service_collection.php index ebf933d338..f598a1db1a 100644 --- a/phpBB/phpbb/di/service_collection.php +++ b/phpBB/phpbb/di/service_collection.php @@ -39,7 +39,7 @@ class service_collection extends \ArrayObject } // Because of a PHP issue we have to redefine offsetExists - // (even Date: Thu, 22 May 2014 13:27:12 +0200 Subject: [PATCH 07/10] [ticket/12575] Fix 2 typos in comments PHPBB3-12575 --- phpBB/phpbb/di/service_collection.php | 2 +- phpBB/phpbb/di/service_collection_iterator.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/di/service_collection.php b/phpBB/phpbb/di/service_collection.php index f598a1db1a..b64d8c9dcd 100644 --- a/phpBB/phpbb/di/service_collection.php +++ b/phpBB/phpbb/di/service_collection.php @@ -39,7 +39,7 @@ class service_collection extends \ArrayObject } // Because of a PHP issue we have to redefine offsetExists - // (even Date: Sat, 14 Jun 2014 01:52:12 +0200 Subject: [PATCH 08/10] [ticket/12575] Usethe new header PHPBB3-12575 --- phpBB/phpbb/di/service_collection_iterator.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/phpBB/phpbb/di/service_collection_iterator.php b/phpBB/phpbb/di/service_collection_iterator.php index 8f4abbc6e8..6e8e1de7a4 100644 --- a/phpBB/phpbb/di/service_collection_iterator.php +++ b/phpBB/phpbb/di/service_collection_iterator.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ @@ -13,11 +17,12 @@ use Symfony\Component\DependencyInjection\ContainerInterface; /** * Iterator which loads the services when they are requested -* -* @package phpBB3 */ class service_collection_iterator extends \ArrayIterator { + /** + * @var \Symfony\Component\DependencyInjection\ContainerInterface + */ protected $container; /** From d33ed1edf6d51534048265880099eac740116516 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 14 Jun 2014 09:42:32 +0200 Subject: [PATCH 09/10] [ticket/12575] Add missing property PHPBB3-12575 --- phpBB/phpbb/di/service_collection.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/phpBB/phpbb/di/service_collection.php b/phpBB/phpbb/di/service_collection.php index b64d8c9dcd..a8eeeab8bb 100644 --- a/phpBB/phpbb/di/service_collection.php +++ b/phpBB/phpbb/di/service_collection.php @@ -20,6 +20,11 @@ use Symfony\Component\DependencyInjection\ContainerInterface; */ class service_collection extends \ArrayObject { + /** + * @var \Symfony\Component\DependencyInjection\ContainerInterface + */ + protected $container; + /** * Constructor * @@ -59,7 +64,7 @@ class service_collection extends \ArrayObject public function offsetGet($index) { $task = parent::offsetGet($index); - if ($task == null) + if ($task === null) { $task = $this->container->get($index); $this->offsetSet($index, $task); From 482f60f1bd45580fe7010a5687a66dd9b0695d29 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Sat, 14 Jun 2014 12:04:25 +0200 Subject: [PATCH 10/10] [ticket/12575] Use strict comparison PHPBB3-12575 --- phpBB/phpbb/di/service_collection_iterator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpBB/phpbb/di/service_collection_iterator.php b/phpBB/phpbb/di/service_collection_iterator.php index 6e8e1de7a4..54aefca1f7 100644 --- a/phpBB/phpbb/di/service_collection_iterator.php +++ b/phpBB/phpbb/di/service_collection_iterator.php @@ -45,7 +45,7 @@ class service_collection_iterator extends \ArrayIterator public function offsetGet($index) { $task = parent::offsetGet($index); - if ($task == null) + if ($task === null) { $task = $this->container->get($index); $this->offsetSet($index, $task); @@ -75,7 +75,7 @@ class service_collection_iterator extends \ArrayIterator public function current() { $task = parent::current(); - if ($task == null) + if ($task === null) { $name = $this->key(); $task = $this->container->get($name);