ServiceManager component from Zend Framework

Overview

zend-servicemanager

Repository abandoned 2019-12-31

This repository has moved to laminas/laminas-servicemanager.

Master: Build Status Coverage Status Develop: Build Status Coverage Status

The Service Locator design pattern is implemented by the Zend\ServiceManager component. The Service Locator is a service/object locator, tasked with retrieving other objects.

Benchmarks

We provide scripts for benchmarking zend-servicemanager using the PHPBench framework; these can be found in the benchmarks/ directory.

To execute the benchmarks you can run the following command:

$ vendor/bin/phpbench run --report=aggregate
Comments
  • [ZF3] Refactoring Service Manager

    [ZF3] Refactoring Service Manager

    This is a rebase of #8 against develop, intended for v3.0. Please see that PR for relevant discussion; we can now start testing and refining against this PR, however.

    To test, fetch my branch:

    $ git remote add weierophinney git://github.com/weierophinney/zend-servicemanager
    $ git fetch weierophinney
    $ git checkout -b refactor-sm weierophinney/refactor-sm
    

    Remaining TODO

    • [x] Migration guide
      • [x] How does configuration differ? (mostly: invokables, lazy services)
      • [x] How does the consumable API differ? (no ability to set or add factories)
      • [x] What interfaces have changed?
        • [x] FactoryInterface
        • [x] AbstractFactoryInterface
        • [x] InitializerInterface
        • [x] DelegatorFactoryInterface
        • [x] ServiceLocatorInterface (extends ContainerInterface, adds build())
      • [x] How are plugin managers different?
        • [x] New interface
        • [x] Abstract class has reasonable validation by default, based on a property you define
        • [x] get() proxies to build() (discrete instances by default)
    enhancement BC Break 
    opened by weierophinney 97
  • SM Refactor

    SM Refactor

    Hi everyone,

    This is my first PR for ZF3. It is a direct backport of my PR on ZF2 repo.

    Component is not yet fully tested but coverage should be already quite good.

    Let me quickly recap the major changes of this refactor.

    Motivation

    The initial motivation was to dramatically increase the performance of this core component, while making it easier to use.

    Performance wise, this refactor is dramatically faster, consume less memory (benchmark can be found on ZF2 repo).

    Breaking changes

    Removal of invokables

    The concept of invokables no longer exist. Now, everything is a factory. This simplifies the creation code by having a single main way to create object.

    A built-in factory to create invokables has been added.

    ZF2 code:

    return [
        'invokables' => [
            MyClass::class => MyClass::class
        ]
    ];
    

    ZF3 code:

    return [
        'factories' => [
            MyClass::class => InvokableFactory::class
        ]
    ]
    

    Factories are invokables

    To increase the performance and reduce branching, most interfaces (FactoryInterface, DelegatorFactory, AbstractFactory and Initializer) must be callable by implementing __invoke.

    This offer a unified way to create objects and dramatically increase performance be removing a lot of instanceof checks.

    Removal of aliases

    Now that this component is 5.5+, we can take advantage of ::class, and we should encourage this usage.

    The usage of aliases has been removed from the main service locator where ::class must be encouraged.

    For plugin managers, a specialized plugin manager that supports alias has been introduced (AbstractAliasedPluginManager) while a more efficient, alias-free AbstractPluginManager is still here.

    Ability to map multiple class to same factory

    This was previously possible in ZF2 but in a hacky way. Now you can map multiple class names to the same factory, and it will be supported by default in the interface signature.

    Plugin manager change

    Previously, a plugin manager had a method getServiceLocator to retrieve the main service locator.

    This was confusing for new-comers, and could lead to hard to debug error because the constructor didn't neforce the need to pass a service locator as a dependency.

    Now, what you receive in the factory is ALWAYS the main service manager, not the plugin manager one.

    If you create an object through a plugin manager in ZF2 and want to retrieve a dependency in the main service locator you had to do:

    class MyFactory implements FactoryInterface
    {
        public function createService(ServiceLocatorInterface $sl)
        {
            $mainSl = $sl->getServiceLocator();
    
            // ...
        }
    }
    

    In ZF3:

    class MyFactory implements FactoryInterface
    {
      public function __invoke(ServiceLocatorInterface $sl, $className, array $options = [])
      {
        // $sl is already the main service locator.
        // If you want a dependency coming from the same plugin manager, you'll need to fetch it first
    
        $pluginManager = $sl->get(MyPluginManager::class)
      }
    }
    

    Unified way of having options

    In ZF2 it was very hard to have options on factories. This is made easy now, because each interface have a last parameter called options.

    Usage:

    $object = $sl->get(MyObject::class, ['key' => 'value']);
    
    // Options are passed as part of the options
    

    Thanks

    opened by bakura10 64
  • Performance enhancements for has(), setService(), setFactory(), setShared(), setAlias(), setInvokableClass() and configure()

    Performance enhancements for has(), setService(), setFactory(), setShared(), setAlias(), setInvokableClass() and configure()

    This PR is about performance of the setter APIs (or injector APIs if you like) as well as has(). Here's the current comparison report. Thanks @dantleech for faster than light fix.

    benchmark: SetNewServicesBench
    +------------------------+--------------------+------------------+--------+
    | subject                | suite:develop:mean | suite:PR221:mean | gain   |
    +------------------------+--------------------+------------------+--------+
    | benchSetService        | 1.924µs            | 0.655µs          |  2,94x |
    | benchSetFactory        | 4.183µs            | 1.226µs          |  3,41x |
    | benchSetAlias          | 11.222µs           | 1.872µs          |  5,99x |
    | benchSetAliasOverrided | 34.617µs           | 1.876µs          | 18,45x |
    +------------------------+--------------------+------------------+--------+
    

    This is the develop branch:

    Dumped result to SetNewServices.develop.xml
    suite: 133ec8900bdebd2cfb961e09ca103052bd993f16, date: 2018-01-05, stime: 22:12:29
    +---------------------+------------------------+--------+--------+--------+-----+------------+-------------+-------------+-------------+-------------+------------+--------+--------+
    | benchmark           | subject                | groups | params | revs   | its | mem_peak   | best        | mean        | mode        | worst       | stdev      | rstdev | diff   |
    +---------------------+------------------------+--------+--------+--------+-----+------------+-------------+-------------+-------------+-------------+------------+--------+--------+
    | SetNewServicesBench | benchSetService        |        | []     | 100000 | 100 | 1,375,992b | 1.910110µs  | 1.957413µs  | 1.946003µs  | 2.050120µs  | 0.028245µs | 1.44%  | 1.00x  |
    | SetNewServicesBench | benchSetFactory        |        | []     | 100000 | 100 | 1,375,992b | 4.180240µs  | 4.240743µs  | 4.229557µs  | 4.420250µs  | 0.030047µs | 0.71%  | 2.17x  |
    | SetNewServicesBench | benchSetAlias          |        | []     | 100000 | 100 | 1,375,992b | 11.440650µs | 11.625965µs | 11.601287µs | 12.160700µs | 0.099540µs | 0.86%  | 5.94x  |
    | SetNewServicesBench | benchSetAliasOverrided |        | []     | 100000 | 100 | 1,376,000b | 35.572030µs | 35.950056µs | 35.759907µs | 37.172120µs | 0.312706µs | 0.87%  | 18.37x |
    +---------------------+------------------------+--------+--------+--------+-----+------------+-------------+-------------+-------------+-------------+------------+--------+--------+
    

    Here comes this PR:

    Dumped result to SetNewServices.setAlias.xml
    suite: 133ec89fee8638dd6d892c639ca0556b8090f9b8, date: 2018-01-05, stime: 21:42:44
    +---------------------+------------------------+--------+--------+--------+-----+------------+------------+------------+------------+------------+------------+--------+-------+
    | benchmark           | subject                | groups | params | revs   | its | mem_peak   | best       | mean       | mode       | worst      | stdev      | rstdev | diff  |
    +---------------------+------------------------+--------+--------+--------+-----+------------+------------+------------+------------+------------+------------+--------+-------+
    | SetNewServicesBench | benchSetService        |        | []     | 100000 | 100 | 1,347,528b | 0.640030µs | 0.654438µs | 0.650130µs | 0.680040µs | 0.010230µs | 1.56%  | 1.00x |
    | SetNewServicesBench | benchSetFactory        |        | []     | 100000 | 100 | 1,347,528b | 1.200070µs | 1.222270µs | 1.217291µs | 1.280070µs | 0.013681µs | 1.12%  | 1.87x |
    | SetNewServicesBench | benchSetAlias          |        | []     | 100000 | 100 | 1,347,528b | 1.810100µs | 1.845307µs | 1.848852µs | 1.900110µs | 0.015841µs | 0.86%  | 2.82x |
    | SetNewServicesBench | benchSetAliasOverrided |        | []     | 100000 | 100 | 1,347,536b | 1.780100µs | 1.803603µs | 1.794896µs | 1.870110µs | 0.019256µs | 1.07%  | 2.76x |
    +---------------------+------------------------+--------+--------+--------+-----+------------+------------+------------+------------+------------+------------+--------+-------+
    
    opened by fhein 56
  • Refactor v2

    Refactor v2

    Hi,

    This replace the other PR as I suck at rebasing.

    What do we need next for the PR @weierophinney ? you didn't give us your opinion regarding the options stuff. This is the only important thing that I'm unsure yet.

    awaiting author updates Needs Revert 
    opened by bakura10 27
  • A word about the immutability-for-performance paradigm

    A word about the immutability-for-performance paradigm

    Immutability may be a last ressort in order to increase performance. But I am not sure if this property can significantly contribute to performance at all.

    Current master, let's assume it was mutable (i.e providing public API's deleteService, deleteFactory et al), this mutability would cause almost no negative performance impact and would cost nothing at all (more or less). That's a statement, I'd be happy to proof that, if there were any demands for a mutable servicemanager.

    Current ServiceManager implementation is slow enough, that immutability is not a topic to discuss at all if performance is the issue. Performance gains (by several 100%) can easily get achieved omitting that discussion.

    From my user's point of view I'd say: I did never care about ServiceManager being mutable or not. It was set up from some accumulated configs. I always used that only, and never wanted to change it. So immutablity never became an issue,

    If there are use cases, where people want to change service manager configurations at runtime, I'd say, this capability could be provided at almost no cost. But I'd recommend to rather review the application design. There might be some flaws. There are flaws, definitely.

    Immutability does not improve performance at all. And it does not open areas of 'research' regarding performance. Mutability almost comes for free. Mutability is a requirement which can be satisfied almost trivially.

    opened by fhein 20
  • Bugfixes as of #242 applied to develop + more

    Bugfixes as of #242 applied to develop + more

    This PR initially delivered the rest of #221. As several bugs were unrevealed in the process I created according tests and fixes for master with #242.

    This PR applies the same fixes to develop recognizing that #221 and #230 were already merged. The issuese fixed are in particular

    1. Preconfigured abstract factories are not resolved.
    2. Preconfigured initializers are not resolved.
    3. Preconfigured invokables are not resolved.
    4. Invokables defined as name => InvokableClass can override delegators and factories.

    A performance gain of more than 100% in FetchNewServiceManagerBench.php is a welcome side effect.

    Btw, I should have named this branch initially 'Rest-Of-#221'. 211 was wrong right from the beginning. :(

    opened by fhein 16
  • Performance optimization

    Performance optimization

    I have deeply reviewed code of v3 and I have found some interesting performance improvements.

    • we don't need to resolve name from aliases before search in existing services.
    • we don't need to resolve aliases any time - only when they are change
    • and my favourite: improve construction of ServiceManager. We don't need to validate overrides if we configure manager first time, so we can omit it. It improve creation time about 20-25%!
    enhancement 
    opened by snapshotpl 16
  • Сonfigurable factories

    Сonfigurable factories

    Hi, all,

    I have tourbles with tons of factories (controllers/actions/simple services/etc) and I think to do simple dependencies configuration like:

    'dep-name' => [
        'class' => MyService::class,
        'deps' => [
            Dep1::class,
            Dep2::class,
        ],
    ],
    

    It's will be alternative for factories, invokables etc and works like a factory sample:

    'dep-name' => function($container) {
        return new MyService($container->get(Dep1::class), $container->get(Dep2::class));
    },
    

    In the future it can be used for annotations/reflection support maybe.

    I want to implement it.

    But I need help from you! First, I need discussions and ideas for implementation (config examples, naming etc). Second, I need support (moral).

    enhancement 
    opened by skar 15
  • [Feature Request] Add context binding or something like that

    [Feature Request] Add context binding or something like that

    I'm using zend service manager to manage my dependencies. In this case, I want to inject params to constructor base on context. Specifically, I have an SearchManager class, if in Application\User\Index, it will be injected with 2 params, but in Application\Post\Index, it will be injected 3 params.

    opened by khuyennguyen7007 14
  • Request for discussion: Lazy Services Configuration and Separation of Concerns

    Request for discussion: Lazy Services Configuration and Separation of Concerns

    Currently lazy_services configuration holds the class_map, proxies_namespace, proxies_target_dir and write_proxy_files. The class_map is a service manager concern but the other settings are configuration for @Ocramius ProxyManager library, which is external.

    Wouldn't it be cleaner to have a lazy_services configuration for ServiceManager which only holds the classmap like

    'lazy_services' => [
        'service1'  => Service1::class, 
        ...
    ]
    

    and provide the other configuration settings from elsewhere? ServiceManager is ServiceManager, I think, it is out of scope to have to know about configuration details of external libraries.

    private function createLazyServiceDelegatorFactory()
    {
        ...
    }
    

    is a factory embedded in the ServiceManger core. It deals with the class map and the other settings. By means of separation of concerns or modularization wouldn't it be worth to consider to put this factory in a separate class?

    question wontfix 
    opened by fhein 14
  • Replace container-interop with PSR-11 container interface

    Replace container-interop with PSR-11 container interface

    This PR replaces use of the container-interop package with the PSR-11 container interface. This is obviously a BC break and would need to be released in ServiceManager 4.0 along with a migration guide.

    Since zend-eventmanager comes into play when ProxyManager is used for lazy instantiation of services (via its own dependency on zend-code, which in turn depends on zend-eventmanager), I'll be submitting an equivalent PR on that repository shortly and will link it here when it's up.

    enhancement BC Break 
    opened by michaelmoussa 14
  • Bug with array_merge_recursive

    Bug with array_merge_recursive

    I'm trying to do something like this:

    $config1 = [
        'factories`=> [
            // factories
        ],
        'lazy_services' => [
            'class_map' => [
                'Foo' => 'Foo',
            ],
        ],
    ];
    
    $config2 = [
        'factories`=> [
            // factories
        ],
        'lazy_services' => [
            'class_map' => [
                'Foo' => 'Foo',
            ],
        ],
    ];
    
    $container = new ServiceManager($config1);
    $container->configure($config2);
    

    This will result on internal lazy_services property the following:

    $this->lazy_services = [
        'class_map' => [
            'Foo' => [
                'Foo',
                'Foo',
            ],
        ].
    ];
    

    The problem is the use of array_merge_recursive() function in this line.

    Same problem with delegators property.

    I found this issue using zend-mvc and an already configured container, then Zend\ModuleManager\Listener\ServiceListener reconfigure it adding configuration from ModuleManager features.

    opened by thomasvargiu 1
  • Warmup lazy services

    Warmup lazy services

    Hi there!

    I would like to generate all proxies before app deployment (like doctrine has orm:generate-proxies). Some host services (like Heroku) require to do this during "compile" process. Sure, generate on-demain works, but there is many cases when cache is purge.

    opened by snapshotpl 7
  • remove redundant isset(s)

    remove redundant isset(s)

    when we are also testing with ! empty() I believe we can skip isset() checks, as the execution speed is nearly the same (but it will double for positive isset)

    enhancement awaiting maintainer response 
    opened by pine3ree 9
Releases(release-3.4.0)
  • release-3.4.0(Dec 22, 2018)

    Added

    • #275 Enables plugin managers to accept as a creation context PSR Containers not implementing Interop interface

    Changed

    • Nothing.

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • #268 Fixes ReflectionBasedAbstractFactory trying to instantiate classes with private constructors
    Source code(tar.gz)
    Source code(zip)
  • release-2.7.11(Jun 22, 2018)

    2.7.11 - 2018-06-22

    Added

    • Nothing.

    Changed

    • Nothing.

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • #269 fixes a regression whereby using static Callable strings caused an undefined variable notice.
    Source code(tar.gz)
    Source code(zip)
  • release-3.3.2(Jan 29, 2018)

    Added

    • Nothing.

    Changed

    • Nothing.

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • #243 provides a fix to the ReflectionBasedAbstractFactory to resolve type-hinted arguments with default values to their default values if no matching type is found in the container.

    • #233 fixes a number of parameter annotations to reflect the actual types used.

    Source code(tar.gz)
    Source code(zip)
  • release-2.7.10(Dec 5, 2017)

    Added

    • Nothing.

    Changed

    • Nothing.

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • #210 fixes a regression whereby factories accepting creation options were receiving an empty array versus a null value when no options were present for a particular invocation; they now correctly receive a null value.
    Source code(tar.gz)
    Source code(zip)
  • release-3.3.1(Nov 27, 2017)

    Added

    • #201 and #202 add support for PHP versions 7.1 and 7.2.

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • #206 fixes an issue where by callables in Class::method notation were not being honored under PHP 5.6.
    Source code(tar.gz)
    Source code(zip)
  • release-2.7.9(Nov 27, 2017)

    Added

    • Nothing.

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • #205 fixes how the AbstractPluginManager handles repeated retrievals of the same service when instance options are provided and the service is marked as "shared". Previously, it incorrectly would return the first instance retrieved; with this release, no instance created with instance options is ever shared.
    Source code(tar.gz)
    Source code(zip)
  • release-3.3.0(Mar 1, 2017)

    Added

    • #180 adds explicit support for PSR-11 (ContainerInterface) by requiring container-interop at a minimum version of 1.2.0, and adding a requirement on psr/container 1.0. Zend\ServiceManager\ServiceLocatorInterface now explicitly extends the ContainerInterface from both projects.

      Factory interfaces still typehint against the container-interop variant, as changing the typehint would break backwards compatibility. Users can duck-type most of these interfaces, however, by creating callables or invokables that typehint against psr/container instead.

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • Nothing.
    Source code(tar.gz)
    Source code(zip)
  • release-3.2.1(Feb 15, 2017)

    Added

    • #176 adds the options -i or --ignore-unresolved to the shipped generate-deps-for-config-factory command. This flag allows it to build configuration for classes resolved by the ConfigAbstractFactory that typehint on interfaces, which was previously unsupported.

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • #174 updates the ConfigAbstractFactory to allow the config service to be either an array or an ArrayObject; previously, only array was supported.
    Source code(tar.gz)
    Source code(zip)
  • release-3.2.0(Dec 19, 2016)

    Added

    • #146 adds Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory, which enables a configuration-based approach to providing class dependencies when all dependencies are services known to the ServiceManager. Please see the documentation for details.
    • #154 adds Zend\ServiceManager\Tool\ConfigDumper, which will introspect a given class to determine dependencies, and then create configuration for Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory, merging it with the provided configuration file. It also adds a vendor binary, generate-deps-for-config-factory, for generating these from the command line.
    • #154 adds Zend\ServiceManager\Tool\FactoryCreator, which will introspect a given class and generate a factory for it. It also adds a vendor binary, generate-factory-for-class, for generating these from the command line.
    • #153 adds Zend\ServiceManager\AbstractFactory\ReflectionBasedAbstractFactory. This class may be used as either a mapped factory or an abstract factory, and will use reflection in order to determine which dependencies to use from the container when instantiating the requested service, with the following rules:
      • Scalar values are not allowed, unless they have default values associated.
      • Values named $config type-hinted against array will be injected with the config service, if present.
      • All other array values will be provided an empty array.
      • Class/interface typehints will be pulled from the container.
    • #150 adds a "cookbook" section to the documentation, with an initial document detailing the pros and cons of abstract factory usage.

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • #106 adds detection of multiple attempts to register the same instance or named abstract factory, using a previous instance when detected. You may still use multiple discrete instances, however.
    Source code(tar.gz)
    Source code(zip)
  • release-3.1.2(Dec 19, 2016)

    Added

    • Nothing.

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • #167 fixes how exception codes are provided to ServiceNotCreatedException. Previously, the code was provided as-is. However, some PHP internal exception classes, notably PDOException, can sometimes return other values (such as strings), which can lead to fatal errors when instantiating the new exception. The patch provided casts exception codes to integers to prevent these errors.
    Source code(tar.gz)
    Source code(zip)
  • release-2.7.8(Dec 19, 2016)

    Added

    • Nothing.

    Changes

    • #158 provides a performance optimization within the InvokableFactory, ensuring it checks for a class matching the $requestedName prior to the $canonicalName; this also is more in line with version 3, which only has access to the requested name.

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • #164 fixes how the InvokableFactory deals with creation options. Prior to this release, absence of options led to setting the creation options to an empty array, which, because it was non-null, led to breakage in plugins that treated an empty array differently than null. This patch ensures that the original behavior is restored.
    • #168 fixes how exception codes are provided to ServiceNotCreatedException. Previously, the code was provided as-is. However, some PHP internal exception classes, notably PDOException, can sometimes return other values (such as strings), which can lead to fatal errors when instantiating the new exception. The patch provided casts exception codes to integers to prevent these errors.
    Source code(tar.gz)
    Source code(zip)
  • release-2.7.7(Sep 1, 2016)

    Added

    • Nothing.

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • #127 fixes how the AbstractPluingManager handles $options arrays passed when retrieving a plugin when that plugin resolves to the InvokableFactory, ensuring subsequent calls with different options are created correctly.
    Source code(tar.gz)
    Source code(zip)
  • release-3.1.1(Jul 15, 2016)

    Added

    • Nothing.

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • #136 removes several imports to classes in subnamespaces within the ServiceManager classfile, removing potential name resolution conflicts that occurred in edge cases when testing.
    Source code(tar.gz)
    Source code(zip)
  • release-3.1.0(Jun 1, 2016)

    Added

    • #103 Allowing installation of ocramius/proxy-manager ^2.0 together with zendframework/zend-servicemanager.
    • #103 Disallowing test failures when running tests against PHP 7.0.*.
    • #113 Improved performance when dealing with registering aliases and factories via ServiceManager#setFactory() and ServiceManager#setAlias()
    • #120 The zendframework/zend-servicemanager component now provides a container-interop/container-interop-implementation implementation

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • #97 Typo corrections in the delegator factories documentation.
    • #98 Using coveralls ^1.0 for tracking test code coverage changes.
    Source code(tar.gz)
    Source code(zip)
  • release-2.7.6(Apr 27, 2016)

    Added

    • Nothing.

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • #116 updates ServiceLocatorInterface to extend container-interop's ContainerInterface, as the definitions are compatible. This change will mean that implementing ServiceLocatorInterface will provide a ContainerInterface implementation.
    Source code(tar.gz)
    Source code(zip)
  • release-3.0.3(Feb 2, 2016)

    Added

    • #89 adds cyclic alias detection to the ServiceManager; it now raises a Zend\ServiceManager\Exception\CyclicAliasException when one is detected, detailing the cycle detected.
    • #95 adds GitHub Pages publication automation, and moves the documentation to https://zendframework.github.io/zend-servicemanager/
    • #93 adds Zend\ServiceManager\Test\CommonPluginManagerTrait, which can be used to validate that a plugin manager instance is ready for version 3.

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • #90 fixes several examples in the configuration chapter of the documentation, ensuring that the signatures are correct.
    • #92 ensures that alias resolution is skipped during configuration if no aliases are present, and forward-ports the test from #81 to validate v2/v3 compatibility for plugin managers.
    Source code(tar.gz)
    Source code(zip)
  • release-2.7.5(Feb 2, 2016)

    Added

    • #81 adds a test covering forwards-compatibility features for plugin manager implementations.
    • #96 adds Zend\ServiceManager\Test\CommonPluginManagerTrait, which allows you to test that your plugin manager is forwards compatible with v3.

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • #91 updates the InvokableFactory to add the setCreationOptions() method, allowing the InvokableFactory to accept $options when triggered.
    Source code(tar.gz)
    Source code(zip)
  • release-3.0.2(Jan 24, 2016)

    Added

    • #64 performance optimizations when dealing with alias resolution during service manager instantiation

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • #62 #64 corrected benchmark assets signature
    • #72 corrected link to the Proxy Pattern Wikipedia page in the documentation
    • #78 #79 creation context was not being correctly passed to abstract factories when using plugin managers
    • #82 corrected migration guide in the DocBlock of the InitializerInterface
    Source code(tar.gz)
    Source code(zip)
  • release-3.0.1(Jan 19, 2016)

    Added

    • Nothing.

    Deprecated

    • Nothing.

    Removed

    • #68 removes the dependency on zend-stdlib by inlining the ArrayUtils::merge() routine as a private method of Zend\ServiceManager\Config.

    Fixed

    • Nothing.
    Source code(tar.gz)
    Source code(zip)
  • release-2.7.4(Jan 19, 2016)

    Added

    • Nothing.

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • #71 fixes an edge case with alias usage, whereby an alias of an alias was not being resolved to the final service name.
    Source code(tar.gz)
    Source code(zip)
  • release-3.0.0(Jan 11, 2016)

    First stable release of version 3 of zend-servicemanager.

    Documentation is now available at:

    • http://zend-servicemanager.rtfd.org

    with migration documentation at:

    • http://zend-servicemanager.rtfd.org/en/latest/book/migration/

    Added

    • You can now map multiple key names to the same factory. It was previously possible in ZF2 but it was not enforced by the FactoryInterface interface. Now the interface receives the $requestedName as the second parameter (previously, it was the third).

      Example:

      $sm = new \Zend\ServiceManager\ServiceManager([
          'factories'  => [
              MyClassA::class => MyFactory::class,
              MyClassB::class => MyFactory::class,
              'MyClassC'      => 'MyFactory' // This is equivalent as using ::class
          ],
      ]);
      
      $sm->get(MyClassA::class); // MyFactory will receive MyClassA::class as second parameter
      
    • Writing a plugin manager has been simplified. If you have simple needs, you no longer need to implement the complete validate method.

      In versions 2.x, if your plugin manager only allows creating instances that implement Zend\Validator\ValidatorInterface, you needed to write the following code:

      class MyPluginManager extends AbstractPluginManager
      {
        public function validate($instance)
        {
            if ($instance instanceof \Zend\Validator\ValidatorInterface) {
                return;
            }
      
            throw new InvalidServiceException(sprintf(
                'Plugin manager "%s" expected an instance of type "%s", but "%s" was received',
                 __CLASS__,
                 \Zend\Validator\ValidatorInterface::class,
                 is_object($instance) ? get_class($instance) : gettype($instance)
            ));
        }
      }
      

      In version 3, this becomes:

      use Zend\ServiceManager\AbstractPluginManager;
      use Zend\Validator\ValidatorInterface;
      
      class MyPluginManager extends AbstractPluginManager
      {
          protected $instanceOf = ValidatorInterface::class;
      }
      

      Of course, you can still override the validate method if your logic is more complex.

      To aid migration, validate() will check for a validatePlugin() method (which was required in v2), and proxy to it if found, after emitting an E_USER_DEPRECATED notice prompting you to rename the method.

    • A new method, configure(), was added, allowing full configuration of the ServiceManager instance at once. Each of the various configuration methods — setAlias(), setInvokableClass(), etc. — now proxy to this method.

    • A new method, mapLazyService($name, $class = null), was added, to allow mapping a lazy service, and as an analog to the other various service definition methods.

    Deprecated

    • Nothing

    Removed

    • Peering has been removed. It was a complex and rarely used feature that was misunderstood most of the time.
    • Integration with Zend\Di has been removed. It may be re-integrated later.
    • MutableCreationOptionsInterface has been removed, as options can now be passed directly through factories.
    • ServiceLocatorAwareInterface and its associated trait has been removed. It was an anti-pattern, and you are encouraged to inject your dependencies in factories instead of injecting the whole service locator.

    Changed/Fixed

    v3 of the ServiceManager component is a completely rewritten, more efficient implementation of the service locator pattern. It includes a number of breaking changes, outlined in this section.

    • You no longer need a Zend\ServiceManager\Config object to configure the service manager; you can pass the configuration array directly instead.

      In version 2.x:

      $config = new \Zend\ServiceManager\Config([
          'factories'  => [...]
      ]);
      
      $sm = new \Zend\ServiceManager\ServiceManager($config);
      

      In ZF 3.x:

      $sm = new \Zend\ServiceManager\ServiceManager([
          'factories'  => [...]
      ]);
      

      Config and ConfigInterface still exist, however, but primarily for the purposes of codifying and aggregating configuration to use.

    • ConfigInterface has two important changes:

      • configureServiceManager() now must return the updated service manager instance.
      • A new method, toArray(), was added, to allow pulling the configuration in order to pass to a ServiceManager or plugin manager's constructor or configure() method.
    • Interfaces for FactoryInterface, DelegatorFactoryInterface and AbstractFactoryInterface have changed. All are now directly invokable. This allows a number of performance optimization internally.

      Additionally, all signatures that accepted a "canonical name" argument now remove it.

      Most of the time, rewriting a factory to match the new interface implies replacing the method name by __invoke, and removing the canonical name argument if present.

      For instance, here is a simple version 2.x factory:

      class MyFactory implements FactoryInterface
      {
          function createService(ServiceLocatorInterface $sl)
          {
              // ...
          }
      }
      

      The equivalent version 3 factory:

      class MyFactory implements FactoryInterface
      {
          function __invoke(ServiceLocatorInterface $sl, $requestedName)
          {
              // ...
          }
      }
      

      Note another change in the above: factories also receive a second parameter, enforced through the interface, that allows you to easily map multiple service names to the same factory.

      To provide forwards compatibility, the original interfaces have been retained, but extend the new interfaces (which are under new namespaces). You can implement the new methods in your existing v2 factories in order to make them forwards compatible with v3.

    • The for AbstractFactoryInterface interface renames the method canCreateServiceWithName() to canCreate(), and merges the $name and $requestedName arguments.

    • Plugin managers will now receive the parent service locator instead of itself in factories. In version 2.x, you needed to call the method getServiceLocator() to retrieve the parent (application) service locator. This was confusing, and not IDE friendly as this method was not enforced through the interface.

      In version 2.x, if a factory was set to a service name defined in a plugin manager:

      class MyFactory implements FactoryInterface
      {
          function createService(ServiceLocatorInterface $sl)
          {
              // $sl is actually a plugin manager
      
              $parentLocator = $sl->getServiceLocator();
      
              // ...
          }
      }
      

      In version 3:

      class MyFactory implements FactoryInterface
      {
          function __invoke(ServiceLocatorInterface $sl, $requestedName)
          {
              // $sl is already the main, parent service locator. If you need to
              // retrieve the plugin manager again, you can retrieve it through the
              // servicelocator:
              $pluginManager = $sl->get(MyPluginManager::class);
              // ...
          }
      }
      

      In practice, this should reduce code, as dependencies often come from the main service locator, and not the plugin manager itself.

      To assist in migration, the method getServiceLocator() was added to ServiceManager to ensure that existing factories continue to work; the method emits an E_USER_DEPRECATED message to signal developers to update their factories.

    • PluginManager now enforces the need for the main service locator in its constructor. In v2.x, people often forgot to set the parent locator, which led to bugs in factories trying to fetch dependencies from the parent locator. Additionally, plugin managers now pull dependencies from the parent locator by default; if you need to pull a peer plugin, your factories will now need to pull the corresponding plugin manager first.

      If you omit passing a service locator to the constructor, your plugin manager will continue to work, but will emit a deprecation notice indicatin you should update your initialization code.

    • It's so fast now that your app will fly!

    Source code(tar.gz)
    Source code(zip)
  • release-2.7.0(Jan 11, 2016)

    Added

    • #60 adds forward compatibility features for AbstractPluingManager and introduces InvokableFactory to help forward migration to version 3.

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • #46 updates the exception hierarchy to inherit from the container-interop exceptions. This ensures that all exceptions thrown by the component follow the recommendations of that project.
    • #52 fixes the exception message thrown by ServiceManager::setFactory() to remove references to abstract factories.
    Source code(tar.gz)
    Source code(zip)
  • release-2.6.0(Jul 23, 2015)

    Added

    Deprecated

    • Nothing.

    Removed

    • Nothing.

    Fixed

    • #3 properly updates the codebase to PHP 5.5, by taking advantage of the default closure binding ($this in a closure is the invoking object when created within a method). It also removes several @requires PHP 5.4.0 annotations.
    Source code(tar.gz)
    Source code(zip)
Owner
Zend Framework
Zend Framework
Adapters for PHP framework containers to an interoperable interface

Acclimate - Container Adapters Get Acclimated! Use any third-party dependency injection containers and service locators in your code by adapting them

Acclimate Container 215 Dec 16, 2022
Zend\Text is a component to work on text strings from Zend Framework

zend-text Repository abandoned 2019-12-31 This repository has moved to laminas/laminas-text. Zend\Text is a component to work on text strings. It cont

Zend Framework 31 Jan 24, 2021
laminas-di integration for laminas-servicemanager

laminas-servicemanager-di This package is considered feature-complete, and is now in security-only maintenance mode, following a decision by the Techn

Laminas Project 4 Jul 10, 2022
Authentication component from Zend Framework

zend-authentication Repository abandoned 2019-12-31 This repository has moved to laminas/laminas-authentication. The Zend\Authentication component pro

Zend Framework 43 Jun 13, 2021
Serializer component from Zend Framework

zend-serializer Repository abandoned 2019-12-31 This repository has moved to laminas/laminas-serializer. zend-serializer provides an adapter-based int

Zend Framework 45 Jan 13, 2022
Console component from Zend Framework

zend-console Repository abandoned 2019-12-31 This repository has moved to laminas/laminas-console. Zend\Console is a component to design and implement

Zend Framework 47 Mar 16, 2021
Cryptographic component from Zend Framework

zend-crypt Repository abandoned 2019-12-31 This repository has moved to laminas/laminas-crypt. Zend\Crypt provides support of some cryptographic tools

Zend Framework 89 Dec 4, 2021
Db component from Zend Framework

zend-db Repository abandoned 2019-12-31 This repository has moved to laminas/laminas-db. Zend\Db is a component that abstract the access to a Database

Zend Framework 98 Sep 5, 2022
Debug component from Zend Framework

zend-debug Zend\Debug is a component that help the debugging of PHP applications. In particular it offers a static method Zend\Debug\Debug::dump() tha

Zend Framework 12 Jan 29, 2020
Navigation component from Zend Framework

zend-navigation Repository abandoned 2019-12-31 This repository has moved to laminas/laminas-navigation. Zend\Navigation is a component for managing t

Zend Framework 19 Jun 30, 2021
Json component from Zend Framework

zend-json Repository abandoned 2019-12-31 This repository has moved to laminas/laminas-json. Zend\Json provides convenience methods for serializing na

Zend Framework 102 Nov 17, 2022
A panel created based on the Zend Framework MVC framework

?? Painel MyZap2.0 Com ZendFramework 3 Descrição Esse é um painel criado como estudo pessoal do framework (Zend Framework MVC) não foi criado para fin

Jonathan Henrique 9 Jun 10, 2022
Official Zend Framework repository

Welcome to the Zend Framework 3.0 Release! RELEASE INFORMATION Zend Framework 3.0.1dev This is the first maintenance release for the Zend Framework 3

Zend Framework 5.6k Dec 29, 2022
Converts a string to a slug. Includes integrations for Symfony, Silex, Laravel, Zend Framework 2, Twig, Nette and Latte.

cocur/slugify Converts a string into a slug. Developed by Florian Eckerstorfer in Vienna, Europe with the help of many great contributors. Features Re

Cocur 2.8k Dec 22, 2022
Zend Framework cache backend for MongoDB

Zend_Cache_Backend_Mongo Author: Anton Stöckl About Zend_Cache_Backend_Mongo is a Zend Framework Cache Backend for MongoDB. It supports tags and autoc

Anton Stöckl 12 Feb 19, 2020
A skeleton application using the Zend Framework MVC

This is a skeleton application using the Zend Framework MVC layer and module systems. This application is meant to be used as a starting place for those looking to get their feet wet with Zend Framework.

Zend Framework 1.5k Dec 15, 2022
💗 C++ wrapper for Zend API

PHP-X C++ wrapper for Zend API Requirements PHP 7.2 or later Linux/MacOS/Windows GCC 4.8 or later Composer Build phpx (bin) ./build.sh sudo cp bin/php

韩天峰-Rango 815 Dec 6, 2022
zend-config is designed to simplify access to configuration data within applications

zend-config is designed to simplify access to configuration data within applications

Zend Framework 89 Jan 13, 2022
zend-memory manages data in an environment with limited memory

Memory objects (memory containers) are generated by the memory manager, and transparently swapped/loaded when required.

Zend Framework 16 Aug 29, 2020
A clean and responsive interface for Zend OPcache information,

A clean and responsive interface for Zend OPcache information, showing statistics, settings and cached files, and providing a real-time update for the information.

Andrew Collington 1.1k Dec 27, 2022