PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.6
Booking for Appointments and Events Calendar – Amelia v2.4.6
2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / vendor / league / tactician / src / Handler / Locator / CallableLocator.php
ameliabooking / vendor / league / tactician / src / Handler / Locator Last commit date
CallableLocator.php 7 years ago HandlerLocator.php 7 years ago InMemoryLocator.php 7 years ago
CallableLocator.php
55 lines
1 <?php
2 namespace League\Tactician\Handler\Locator;
3
4 use League\Tactician\Exception\MissingHandlerException;
5
6 /**
7 * This locator loads Handlers from a provided callable.
8 *
9 * At first glance, this might seem fairly useless but it's actually very
10 * useful to encapsulate DI containers without having to write a custom adapter
11 * for each one.
12 *
13 * Let's say you have a Symfony container or similar that works via a 'get'
14 * method. You can pass in an array style callable such as:
15 *
16 * $locator = new CallableLocator([$container, 'get'])
17 *
18 * This is easy to set up and will now automatically pipe the command name
19 * straight through to the $container->get() method without having to write
20 * the custom locator.
21 *
22 * Naturally, you can also pass in closures for further behavior tweaks.
23 */
24 class CallableLocator implements HandlerLocator
25 {
26 /**
27 * @var callable
28 */
29 private $callable;
30
31 /**
32 * @param callable $callable
33 */
34 public function __construct(callable $callable)
35 {
36 $this->callable = $callable;
37 }
38
39 /**
40 * {@inheritdoc}
41 */
42 public function getHandlerForCommand($commandName)
43 {
44 $callable = $this->callable;
45 $handler = $callable($commandName);
46
47 // Odds are the callable threw an exception but it always pays to check
48 if ($handler === null) {
49 throw MissingHandlerException::forCommand($commandName);
50 }
51
52 return $handler;
53 }
54 }
55