1: <?php
2:
3: namespace Charcoal\App\Route;
4:
5:
6: use InvalidArgumentException;
7:
8:
9: use Psr\Http\Message\RequestInterface;
10: use Psr\Http\Message\ResponseInterface;
11:
12:
13: use Pimple\Container;
14:
15:
16: use Charcoal\Config\ConfigurableInterface;
17: use Charcoal\Config\ConfigurableTrait;
18:
19:
20: use Charcoal\App\Route\RouteInterface;
21: use Charcoal\App\Route\ScriptRouteConfig;
22: use Charcoal\App\Script\ScriptInterface;
23:
24: 25: 26:
27: class ScriptRoute implements
28: ConfigurableInterface,
29: RouteInterface
30: {
31: use ConfigurableTrait;
32:
33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47:
48: public function __construct(array $data)
49: {
50: $this->setConfig($data['config']);
51: }
52:
53: 54: 55: 56: 57: 58:
59: public function createConfig($data = null)
60: {
61: return new ScriptRouteConfig($data);
62: }
63:
64: 65: 66: 67: 68: 69:
70: public function __invoke(Container $container, RequestInterface $request, ResponseInterface $response)
71: {
72: $config = $this->config();
73:
74: $scriptController = $config['controller'];
75:
76: $scriptFactory = $container['script/factory'];
77:
78: $script = $scriptFactory->create($scriptController);
79:
80: $script->setData($config['script_data']);
81:
82:
83: return $script($request, $response);
84: }
85: }
86: