Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ServiceFactory
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __invoke
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/**
6 * This file is part of php-fast-forward/container.
7 *
8 * This source file is subject to the license bundled
9 * with this source code in the file LICENSE.
10 *
11 * @copyright Copyright (c) 2025-2026 Felipe SayĆ£o Lobato Abreu <github@mentordosnerds.com>
12 * @license   https://opensource.org/licenses/MIT MIT License
13 *
14 * @see       https://github.com/php-fast-forward/container
15 * @see       https://github.com/php-fast-forward
16 * @see       https://datatracker.ietf.org/doc/html/rfc2119
17 */
18
19namespace FastForward\Container\Factory;
20
21use Psr\Container\ContainerInterface;
22
23/**
24 * This factory wraps a predefined service instance and returns it directly upon invocation.
25 *
26 * It SHALL be used when a fixed service object must be registered in a container using
27 * a factory interface.
28 *
29 * The returned value MUST be the exact same instance provided at construction.
30 *
31 * This ensures immutability and predictable resolution.
32 */
33  class ServiceFactory implements FactoryInterface
34{
35    /**
36     * Constructs the factory with a fixed service instance.
37     *
38     * @param mixed $service the service instance to be returned by the factory
39     */
40    public function __construct(
41        private mixed $service
42    ) {}
43
44    /**
45     * Returns the fixed service instance.
46     *
47     * @param ContainerInterface $container the container instance (ignored in this context)
48     *
49     * @return mixed the predefined service instance
50     */
51    public function __invoke(ContainerInterface $container): mixed
52    {
53        return $this->service;
54    }
55}