Skip to content

Commit

Permalink
Merge pull request #3 from fhein/TEST-Prefconfiguration-gets-applied
Browse files Browse the repository at this point in the history
Merge zend-servicemanager PR zendframework#242
  • Loading branch information
mxc-commons authored Feb 6, 2018
2 parents 15f862f + 73eadf1 commit 9e8bcb6
Show file tree
Hide file tree
Showing 16 changed files with 648 additions and 130 deletions.
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

0 comments on commit 9e8bcb6

Please sign in to comment.