[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 namespace phpbb\controller; 15 16 use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; 17 use Symfony\Component\DependencyInjection\ContainerInterface; 18 use Symfony\Component\HttpFoundation\Request; 19 20 /** 21 * Controller manager class 22 */ 23 class resolver implements ControllerResolverInterface 24 { 25 /** 26 * User object 27 * @var \phpbb\user 28 */ 29 protected $user; 30 31 /** 32 * ContainerInterface object 33 * @var ContainerInterface 34 */ 35 protected $container; 36 37 /** 38 * phpbb\template\template object 39 * @var \phpbb\template\template 40 */ 41 protected $template; 42 43 /** 44 * Request type cast helper object 45 * @var \phpbb\request\type_cast_helper 46 */ 47 protected $type_cast_helper; 48 49 /** 50 * phpBB root path 51 * @var string 52 */ 53 protected $phpbb_root_path; 54 55 /** 56 * Construct method 57 * 58 * @param \phpbb\user $user User Object 59 * @param ContainerInterface $container ContainerInterface object 60 * @param string $phpbb_root_path Relative path to phpBB root 61 * @param \phpbb\template\template $template 62 */ 63 public function __construct(\phpbb\user $user, ContainerInterface $container, $phpbb_root_path, \phpbb\template\template $template = null) 64 { 65 $this->user = $user; 66 $this->container = $container; 67 $this->template = $template; 68 $this->type_cast_helper = new \phpbb\request\type_cast_helper(); 69 $this->phpbb_root_path = $phpbb_root_path; 70 } 71 72 /** 73 * Load a controller callable 74 * 75 * @param \Symfony\Component\HttpFoundation\Request $request Symfony Request object 76 * @return bool|Callable Callable or false 77 * @throws \phpbb\controller\exception 78 */ 79 public function getController(Request $request) 80 { 81 $controller = $request->attributes->get('_controller'); 82 83 if (!$controller) 84 { 85 throw new \phpbb\controller\exception($this->user->lang['CONTROLLER_NOT_SPECIFIED']); 86 } 87 88 // Require a method name along with the service name 89 if (stripos($controller, ':') === false) 90 { 91 throw new \phpbb\controller\exception($this->user->lang['CONTROLLER_METHOD_NOT_SPECIFIED']); 92 } 93 94 list($service, $method) = explode(':', $controller); 95 96 if (!$this->container->has($service)) 97 { 98 throw new \phpbb\controller\exception($this->user->lang('CONTROLLER_SERVICE_UNDEFINED', $service)); 99 } 100 101 $controller_object = $this->container->get($service); 102 103 /* 104 * If this is an extension controller, we'll try to automatically set 105 * the style paths for the extension (the ext author can change them 106 * if necessary). 107 */ 108 $controller_dir = explode('\\', get_class($controller_object)); 109 110 // 0 vendor, 1 extension name, ... 111 if (!is_null($this->template) && isset($controller_dir[1])) 112 { 113 $controller_style_dir = 'ext/' . $controller_dir[0] . '/' . $controller_dir[1] . '/styles'; 114 115 if (is_dir($this->phpbb_root_path . $controller_style_dir)) 116 { 117 $this->template->set_style(array($controller_style_dir, 'styles')); 118 } 119 } 120 121 return array($controller_object, $method); 122 } 123 124 /** 125 * Dependencies should be specified in the service definition and can be 126 * then accessed in __construct(). Arguments are sent through the URL path 127 * and should match the parameters of the method you are using as your 128 * controller. 129 * 130 * @param \Symfony\Component\HttpFoundation\Request $request Symfony Request object 131 * @param mixed $controller A callable (controller class, method) 132 * @return array An array of arguments to pass to the controller 133 * @throws \phpbb\controller\exception 134 */ 135 public function getArguments(Request $request, $controller) 136 { 137 // At this point, $controller contains the object and method name 138 list($object, $method) = $controller; 139 $mirror = new \ReflectionMethod($object, $method); 140 141 $arguments = array(); 142 $parameters = $mirror->getParameters(); 143 $attributes = $request->attributes->all(); 144 foreach ($parameters as $param) 145 { 146 if (array_key_exists($param->name, $attributes)) 147 { 148 if (is_string($attributes[$param->name])) 149 { 150 $value = $attributes[$param->name]; 151 $this->type_cast_helper->set_var($value, $attributes[$param->name], 'string', true, false); 152 $arguments[] = $value; 153 } 154 else 155 { 156 $arguments[] = $attributes[$param->name]; 157 } 158 } 159 else if ($param->getClass() && $param->getClass()->isInstance($request)) 160 { 161 $arguments[] = $request; 162 } 163 else if ($param->isDefaultValueAvailable()) 164 { 165 $arguments[] = $param->getDefaultValue(); 166 } 167 else 168 { 169 throw new \phpbb\controller\exception($this->user->lang('CONTROLLER_ARGUMENT_VALUE_MISSING', $param->getPosition() + 1, get_class($object) . ':' . $method, $param->name)); 170 } 171 } 172 173 return $arguments; 174 } 175 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |