aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/controller/provider.php
diff options
context:
space:
mode:
authorDavid King <imkingdavid@gmail.com>2012-10-19 19:54:19 -0400
committerDavid King <imkingdavid@gmail.com>2012-11-16 16:25:09 -0500
commit06158693c7b846518abfe9d72491fc7376e457f3 (patch)
tree46ce44bfeab4bb9f5275fee8ad8e01df3babaddf /phpBB/includes/controller/provider.php
parent65dde648cab316fd0f0715f13d57ef45452398a3 (diff)
downloadforums-06158693c7b846518abfe9d72491fc7376e457f3.tar
forums-06158693c7b846518abfe9d72491fc7376e457f3.tar.gz
forums-06158693c7b846518abfe9d72491fc7376e457f3.tar.bz2
forums-06158693c7b846518abfe9d72491fc7376e457f3.tar.xz
forums-06158693c7b846518abfe9d72491fc7376e457f3.zip
[feature/controller] Implement a front controller
PHPBB3-10864
Diffstat (limited to 'phpBB/includes/controller/provider.php')
-rw-r--r--phpBB/includes/controller/provider.php94
1 files changed, 94 insertions, 0 deletions
diff --git a/phpBB/includes/controller/provider.php b/phpBB/includes/controller/provider.php
new file mode 100644
index 0000000000..25deedb5d1
--- /dev/null
+++ b/phpBB/includes/controller/provider.php
@@ -0,0 +1,94 @@
+<?php
+/**
+*
+* @package controller
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+use Symfony\Component\Routing\RouteCollection;
+use Symfony\Component\Routing\Loader\YamlFileLoader;
+use Symfony\Component\Config\FileLocator;
+
+/**
+* Controller interface
+* @package phpBB3
+*/
+class phpbb_controller_provider
+{
+ /**
+ * YAML file(s) containing route information
+ * @var array
+ */
+ protected $routing_paths;
+
+ /**
+ * Construct method
+ *
+ * @param array() $routing_paths Array of strings containing paths
+ * to YAML files holding route information
+ */
+ public function __construct($routing_paths = array())
+ {
+ $this->set_paths($routing_paths);
+ }
+
+ /**
+ * Locate paths containing routing files
+ * This sets an internal property but does not return the paths.
+ *
+ * @return The current instance of this object for method chaining
+ */
+ public function get_paths(phpbb_extension_finder $finder)
+ {
+ // We hardcode the path to the core config directory
+ // because the finder cannot find it
+ $this->set_paths(array_merge(array('config'), array_map('dirname', array_keys($finder
+ ->directory('config')
+ ->prefix('routing')
+ ->suffix('yml')
+ ->find()
+ ))));
+
+ return $this;
+ }
+
+ /**
+ * Set the $routing_paths property with a given list of paths
+ *
+ * @return The current instance of this object for method chaining
+ */
+ public function set_paths(array $paths)
+ {
+ $this->routing_paths = $paths;
+
+ return $this;
+ }
+
+ /**
+ * Get a list of controllers and return it
+ *
+ * @param string $base_path Base path to prepend to file paths
+ * @return array Array of controllers and their route information
+ */
+ public function find($base_path = '')
+ {
+ $routes = new RouteCollection;
+ foreach ($this->routing_paths as $path)
+ {
+ $loader = new YamlFileLoader(new FileLocator($base_path . $path));
+ $routes->addCollection($loader->load('routing.yml'));
+ }
+
+ return $routes;
+ }
+}