Issues (480)

src/Plugin/Scope.php (1 issue)

1
<?php
2
/**
3
 *
4
 */
5
6
namespace Mvc5\Plugin;
7
8
use Mvc5\App;
9
use Mvc5\Service\Manager;
10
use Mvc5\Service\Service;
11
12
use const Mvc5\SERVICES;
13
14
/**
15
 * Creates a model with a scopable plugins container and sets the model as the scope of the anonymous functions.
16
 */
17
class Scope
18
    extends Call
19
{
20
    /**
21
     * @param array $plugins
22
     * @param string $name
23
     */
24 5
    function __construct(array $plugins, string $name)
25
    {
26 5
        parent::__construct([$this, 'scope'], [
27 5
            new Plugin(App::class, [[SERVICES => $plugins], null, true, true]), new Link, $name]);
28 5
    }
29
30
    /**
31
     * @param Manager $context
32
     * @param Service $service
33
     * @param string $name
34
     * @return callable|object|null
35
     */
36 4
    function scope(Manager $context, Service $service, string $name)
37
    {
38 4
        return $context->plugin(new ScopedCall(fn() => fn() => $this->scope = $service->plugin($name, [$this, $service])));
0 ignored issues
show
Bug Best Practice introduced by
The property scope does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
39
    }
40
}
41