Skip to content
This repository has been archived by the owner on Feb 6, 2020. It is now read-only.

BUGFIXES: Processing of preconfigured settings and invokable resolution #242

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5413057
Adds test that preconfiguration through members gets applied.
fhein Jan 28, 2018
3b5ddd6
Adds PreconfiguredServiceManager test asset.
fhein Jan 28, 2018
d51cf4b
Adds TaggingInitializer, AbstractFactoryFoo and PassthroughDelegator
fhein Jan 28, 2018
860d629
Adds test asset PreconfiguredServiceManager.
fhein Jan 28, 2018
ab26a61
Adds class Foo test asset. To be generated by AbstractFactoryFoo on
fhein Jan 28, 2018
1c1f0d6
Fake.
fhein Jan 28, 2018
f977a4b
Fix: Process preconfigured abstract factories and initializers
fhein Jan 29, 2018
bcaf2d5
Adds test asset TaggingDelegatorFactory.
fhein Jan 29, 2018
539cfb4
Completes the fix for abstract factories and initializers. Invokables
fhein Jan 29, 2018
3b8155e
Fixes completed for abstract factories and initializers.
fhein Jan 29, 2018
d2650ee
Removed tests which explicitly tested if invokables are converted to
fhein Jan 29, 2018
c94e1cf
Parens added.
fhein Jan 29, 2018
5298ab0
Change for PHP 5.6 compatibility.
fhein Jan 29, 2018
5aa73cc
Removed $constructing parameter.
fhein Jan 29, 2018
cb3b0b1
Set $this->configured after call to configure() at construction time.
fhein Jan 29, 2018
8b787f2
Extended benchmarks as of #231
fhein Jan 31, 2018
13e0feb
Deleted an assert which was assuming that invokables are handled as
fhein Feb 1, 2018
0365c4b
As requested.
fhein Feb 1, 2018
63b2302
Split PreconfigurationGetsAppliedTest. Changed tag checking
fhein Feb 1, 2018
0d36f50
Replaced unsets with [] assignments. Moved $configured assignment back
fhein Feb 1, 2018
e568c94
As requested.
fhein Feb 1, 2018
a8ba1a3
Made $invokables private to avoid bc issues.
fhein Feb 1, 2018
8e91bc6
Had to revert access to $invokables[] to protected in order to allow
fhein Feb 1, 2018
de467bd
Moved object creation through factory one level down to avoid using a
fhein Feb 1, 2018
b27f5d0
Changed docblock.
fhein Feb 1, 2018
44a7b5b
Removed commented old line of previous implementation.
fhein Feb 2, 2018
73eadf1
Removed @covers getFactory, because that does not exist any longer.
fhein Feb 2, 2018
1c58b3a
Renamed createObjectTroughFactory to createServiceThroughFactory
fhein Feb 6, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmarks/BenchAsset/AbstractFactoryFoo.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace ZendBench\ServiceManager\BenchAsset;

use Zend\ServiceManager\Factory\AbstractFactoryInterface;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Factory\AbstractFactoryInterface;

class AbstractFactoryFoo implements AbstractFactoryInterface
{
Expand Down
23 changes: 23 additions & 0 deletions benchmarks/BenchAsset/DelegatorFactoryFoo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* @link https://github.com/zendframework/zend-servicemanager for the canonical source repository
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendBench\ServiceManager\BenchAsset;

use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Factory\DelegatorFactoryInterface;

class DelegatorFactoryFoo implements DelegatorFactoryInterface
{
/**
* {@inheritDoc}
* @see \Zend\ServiceManager\Factory\DelegatorFactoryInterface::__invoke()
*/
public function __invoke(ContainerInterface $container, $name, callable $callback, array $options = null)
{
return ($options !== null) ? $callback($options) : $callback();
}
}
2 changes: 1 addition & 1 deletion benchmarks/BenchAsset/FactoryFoo.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace ZendBench\ServiceManager\BenchAsset;

use Zend\ServiceManager\Factory\FactoryInterface;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Factory\FactoryInterface;

class FactoryFoo implements FactoryInterface
{
Expand Down
28 changes: 28 additions & 0 deletions benchmarks/BenchAsset/InitializerFoo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* @link https://github.com/zendframework/zend-servicemanager for the canonical source repository
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendBench\ServiceManager\BenchAsset;

use Zend\ServiceManager\Initializer\InitializerInterface;

class InitializerFoo implements InitializerInterface
{
protected $options;

/**
* {@inheritDoc}
* @see \Zend\ServiceManager\Initializer\InitializerInterface::__invoke()
*/
public function __invoke(\Interop\Container\ContainerInterface $container, $instance)
{
}

public function __construct($options = null)
{
$this->options = $options;
}
}
113 changes: 113 additions & 0 deletions benchmarks/HasBench.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<?php
/**
* @link http://github.com/zendframework/zend-servicemanager for the canonical source repository
* @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendBench\ServiceManager;

use PhpBench\Benchmark\Metadata\Annotations\Iterations;
use PhpBench\Benchmark\Metadata\Annotations\Revs;
use PhpBench\Benchmark\Metadata\Annotations\Warmup;
use Zend\ServiceManager\ServiceManager;

/**
* @Revs(1000)
* @Iterations(20)
* @Warmup(2)
*/
class HasBench
{
/**
* @var ServiceManager
*/
private $sm;

public function __construct()
{
$this->sm = new ServiceManager([
'factories' => [
'factory1' => BenchAsset\FactoryFoo::class,
],
'invokables' => [
'invokable1' => BenchAsset\Foo::class,
],
'services' => [
'service1' => new \stdClass(),
],
'aliases' => [
'alias1' => 'service1',
'recursiveAlias1' => 'alias1',
'recursiveAlias2' => 'recursiveAlias1',
],
'abstract_factories' => [
BenchAsset\AbstractFactoryFoo::class
]
]);
}

public function benchHasFactory1()
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;

$sm->has('factory1');
}

public function benchHasInvokable1()
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;

$sm->has('invokable1');
}

public function benchHasService1()
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;

$sm->has('service1');
}

public function benchHasAlias1()
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;

$sm->has('alias1');
}

public function benchHasRecursiveAlias1()
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;

$sm->has('recursiveAlias1');
}

public function benchHasRecursiveAlias2()
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;

$sm->has('recursiveAlias2');
}

public function benchHasAbstractFactory()
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;

$sm->has('foo');
}

public function benchHasNot()
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;

$sm->has('42');
}
}
87 changes: 77 additions & 10 deletions benchmarks/SetNewServicesBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PhpBench\Benchmark\Metadata\Annotations\Revs;
use PhpBench\Benchmark\Metadata\Annotations\Warmup;
use Zend\ServiceManager\ServiceManager;
use ZendBench\ServiceManager\BenchAsset\DelegatorFactoryFoo;

/**
* @Revs(1000)
Expand Down Expand Up @@ -43,40 +44,106 @@ public function __construct()
'recursiveFactoryAlias1' => 'factoryAlias1',
'recursiveFactoryAlias2' => 'recursiveFactoryAlias1',
],
'abstract_factories' => [
BenchAsset\AbstractFactoryFoo::class
],
];

for ($i = 0; $i <= self::NUM_SERVICES; $i++) {
$config['factories']["factory_$i"] = BenchAsset\FactoryFoo::class;
$config['aliases']["alias_$i"] = "service_$i";
$config['abstract_factories'][] = BenchAsset\AbstractFactoryFoo::class;
$config['invokables']["invokable_$i"] = BenchAsset\Foo::class;
$config['delegators']["delegator_$i"] = [ DelegatorFactoryFoo::class ];
}

$this->initializer = new BenchAsset\InitializerFoo();
$this->abstractFactory = new BenchAsset\AbstractFactoryFoo();
$this->sm = new ServiceManager($config);
}

public function benchSetFactory()

public function benchSetService()
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
$sm->setService('service2', new \stdClass());
}

/**
* @todo @link https://github.com/phpbench/phpbench/issues/304
*/
public function benchSetFactory()
{
$sm = clone $this->sm;
$sm->setFactory('factory2', BenchAsset\FactoryFoo::class);
}

/**
* @todo @link https://github.com/phpbench/phpbench/issues/304
*/
public function benchSetAlias()
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;

$sm->setAlias('factoryAlias2', 'factory1');
}

public function benchSetAliasOverrided()
/**
* @todo @link https://github.com/phpbench/phpbench/issues/304
*/
public function benchOverrideAlias()
{
$sm = clone $this->sm;
$sm->setAlias('recursiveFactoryAlias1', 'factory1');
}

/**
* @todo @link https://github.com/phpbench/phpbench/issues/304
*/
public function benchSetInvokableClass()
{
// @todo @link https://github.com/phpbench/phpbench/issues/304
$sm = clone $this->sm;
$sm->setInvokableClass(BenchAsset\Foo::class, BenchAsset\Foo::class);
}

$sm->setAlias('recursiveFactoryAlias1', 'factory1');
/**
* @todo @link https://github.com/phpbench/phpbench/issues/304
*/
public function benchAddDelegator()
{
$sm = clone $this->sm;
$sm->addDelegator(BenchAsset\Foo::class, DelegatorFactoryFoo::class);
}

/**
* @todo @link https://github.com/phpbench/phpbench/issues/304
*/
public function benchAddInitializerByClassName()
{
$sm = clone $this->sm;
$sm->addInitializer(BenchAsset\InitializerFoo::class);
}

/**
* @todo @link https://github.com/phpbench/phpbench/issues/304
*/
public function benchAddInitializerByInstance()
{
$sm = clone $this->sm;
$sm->addInitializer($this->initializer);
}

/**
* @todo @link https://github.com/phpbench/phpbench/issues/304
*/
public function benchAddAbstractFactoryByClassName()
{
$sm = clone $this->sm;
$sm->addAbstractFactory(BenchAsset\AbstractFactoryFoo::class);
}

/**
* @todo @link https://github.com/phpbench/phpbench/issues/304
*/
public function benchAddAbstractFactoryByInstance()
{
$sm = clone $this->sm;
$sm->addAbstractFactory($this->abstractFactory);
}
}
Loading