diff options
Diffstat (limited to 'phpBB/phpbb/extension')
| -rw-r--r-- | phpBB/phpbb/extension/di/extension_base.php | 138 | ||||
| -rw-r--r-- | phpBB/phpbb/extension/exception.php | 6 | ||||
| -rw-r--r-- | phpBB/phpbb/extension/manager.php | 26 | ||||
| -rw-r--r-- | phpBB/phpbb/extension/metadata_manager.php | 26 | 
4 files changed, 162 insertions, 34 deletions
| diff --git a/phpBB/phpbb/extension/di/extension_base.php b/phpBB/phpbb/extension/di/extension_base.php new file mode 100644 index 0000000000..ba74615e70 --- /dev/null +++ b/phpBB/phpbb/extension/di/extension_base.php @@ -0,0 +1,138 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\extension\di; + +use Symfony\Component\Config\FileLocator; +use Symfony\Component\Config\Resource\FileResource; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; +use Symfony\Component\HttpKernel\DependencyInjection\Extension; + +/** + * Container core extension + */ +class extension_base extends Extension +{ +	/** +	 * Name of the extension (vendor/name) +	 * +	 * @var string +	 */ +	protected $extension_name; + +	/** +	 * Path to the extension. +	 * +	 * @var string +	 */ +	protected $ext_path; + +	/** +	 * Constructor +	 * +	 * @param string $extension_name Name of the extension (vendor/name) +	 * @param string $ext_path       Path to the extension +	 */ +	public function __construct($extension_name, $ext_path) +	{ +		$this->extension_name = $extension_name; +		$this->ext_path = $ext_path; +	} + +	/** +	 * Loads a specific configuration. +	 * +	 * @param array            $configs   An array of configuration values +	 * @param ContainerBuilder $container A ContainerBuilder instance +	 * +	 * @throws \InvalidArgumentException When provided tag is not defined in this extension +	 */ +	public function load(array $configs, ContainerBuilder $container) +	{ +		$this->load_services($container); +	} + +	/** +	 * Loads the services.yml file. +	 * +	 * @param ContainerBuilder $container A ContainerBuilder instance +	 */ +	protected function load_services(ContainerBuilder $container) +	{ +		$services_directory = false; +		$services_file = false; + +		if (file_exists($this->ext_path . 'config/' . $container->getParameter('core.environment') . '/container/environment.yml')) +		{ +			$services_directory = $this->ext_path . 'config/' . $container->getParameter('core.environment') . '/container/'; +			$services_file = 'environment.yml'; +		} +		else if (!is_dir($this->ext_path . 'config/' . $container->getParameter('core.environment'))) +		{ +			if (file_exists($this->ext_path . 'config/default/container/environment.yml')) +			{ +				$services_directory = $this->ext_path . 'config/default/container/'; +				$services_file = 'environment.yml'; +			} +			else if (!is_dir($this->ext_path . 'config/default') && file_exists($this->ext_path . '/config/services.yml')) +			{ +				$services_directory = $this->ext_path . 'config'; +				$services_file = 'services.yml'; +			} +		} + +		if ($services_directory && $services_file) +		{ +			$filesystem = new \phpbb\filesystem\filesystem(); +			$loader = new YamlFileLoader($container, new FileLocator($filesystem->realpath($services_directory))); +			$loader->load($services_file); +		} +	} + +	/** +	 * {@inheritdoc} +	 */ +	public function getConfiguration(array $config, ContainerBuilder $container) +	{ +		$reflected = new \ReflectionClass($this); +		$namespace = $reflected->getNamespaceName(); + +		$class = $namespace . '\\di\configuration'; +		if (class_exists($class)) +		{ +			$r = new \ReflectionClass($class); +			$container->addResource(new FileResource($r->getFileName())); + +			if (!method_exists($class, '__construct')) +			{ +				$configuration = new $class(); + +				return $configuration; +			} +		} + +	} + +	/** +	 * Returns the recommended alias to use in XML. +	 * +	 * This alias is also the mandatory prefix to use when using YAML. +	 * +	 * @return string The alias +	 */ +	public function getAlias() +	{ +		return str_replace('/', '_', $this->extension_name); +	} +} diff --git a/phpBB/phpbb/extension/exception.php b/phpBB/phpbb/extension/exception.php index 3f7d251a4e..9050449bf1 100644 --- a/phpBB/phpbb/extension/exception.php +++ b/phpBB/phpbb/extension/exception.php @@ -16,10 +16,6 @@ namespace phpbb\extension;  /**   * Exception class for metadata   */ -class exception extends \UnexpectedValueException +class exception extends \phpbb\exception\runtime_exception  { -	public function __toString() -	{ -		return $this->getMessage(); -	}  } diff --git a/phpBB/phpbb/extension/manager.php b/phpBB/phpbb/extension/manager.php index 76f0e3558e..98d2d27278 100644 --- a/phpBB/phpbb/extension/manager.php +++ b/phpBB/phpbb/extension/manager.php @@ -26,7 +26,6 @@ class manager  	protected $db;  	protected $config;  	protected $cache; -	protected $user;  	protected $php_ext;  	protected $extensions;  	protected $extension_table; @@ -39,15 +38,14 @@ class manager  	* @param ContainerInterface $container A container  	* @param \phpbb\db\driver\driver_interface $db A database connection  	* @param \phpbb\config\config $config Config object -	* @param \phpbb\filesystem $filesystem -	* @param \phpbb\user $user User object +	* @param \phpbb\filesystem\filesystem_interface $filesystem  	* @param string $extension_table The name of the table holding extensions  	* @param string $phpbb_root_path Path to the phpbb includes directory.  	* @param string $php_ext php file extension, defaults to php  	* @param \phpbb\cache\driver\driver_interface $cache A cache instance or null  	* @param string $cache_name The name of the cache variable, defaults to _ext  	*/ -	public function __construct(ContainerInterface $container, \phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\filesystem $filesystem, \phpbb\user $user, $extension_table, $phpbb_root_path, $php_ext = 'php', \phpbb\cache\driver\driver_interface $cache = null, $cache_name = '_ext') +	public function __construct(ContainerInterface $container, \phpbb\db\driver\driver_interface $db, \phpbb\config\config $config, \phpbb\filesystem\filesystem_interface $filesystem, $extension_table, $phpbb_root_path, $php_ext = 'php', \phpbb\cache\driver\driver_interface $cache = null, $cache_name = '_ext')  	{  		$this->cache = $cache;  		$this->cache_name = $cache_name; @@ -58,7 +56,6 @@ class manager  		$this->filesystem = $filesystem;  		$this->phpbb_root_path = $phpbb_root_path;  		$this->php_ext = $php_ext; -		$this->user = $user;  		$this->extensions = ($this->cache) ? $this->cache->get($this->cache_name) : false; @@ -154,7 +151,7 @@ class manager  	*/  	public function create_extension_metadata_manager($name, \phpbb\template\template $template)  	{ -		return new \phpbb\extension\metadata_manager($name, $this->config, $this, $template, $this->user, $this->phpbb_root_path); +		return new \phpbb\extension\metadata_manager($name, $this->config, $this, $template, $this->phpbb_root_path);  	}  	/** @@ -464,15 +461,17 @@ class manager  	* All enabled and disabled extensions are considered configured. A purged  	* extension that is no longer in the database is not configured.  	* +	* @param bool $phpbb_relative Whether the path should be relative to phpbb root +	*  	* @return array An array with extension names as keys and and the  	*               database stored extension information as values  	*/ -	public function all_configured() +	public function all_configured($phpbb_relative = true)  	{  		$configured = array();  		foreach ($this->extensions as $name => $data)  		{ -			$data['ext_path'] = $this->phpbb_root_path . $data['ext_path']; +			$data['ext_path'] = ($phpbb_relative ? $this->phpbb_root_path : '') . $data['ext_path'];  			$configured[$name] = $data;  		}  		return $configured; @@ -480,18 +479,19 @@ class manager  	/**  	* Retrieves all enabled extensions. +	* @param bool $phpbb_relative Whether the path should be relative to phpbb root  	*  	* @return array An array with extension names as keys and and the  	*               database stored extension information as values  	*/ -	public function all_enabled() +	public function all_enabled($phpbb_relative = true)  	{  		$enabled = array();  		foreach ($this->extensions as $name => $data)  		{  			if ($data['ext_active'])  			{ -				$enabled[$name] = $this->phpbb_root_path . $data['ext_path']; +				$enabled[$name] = ($phpbb_relative ? $this->phpbb_root_path : '') . $data['ext_path'];  			}  		}  		return $enabled; @@ -500,17 +500,19 @@ class manager  	/**  	* Retrieves all disabled extensions.  	* +	* @param bool $phpbb_relative Whether the path should be relative to phpbb root +	*  	* @return array An array with extension names as keys and and the  	*               database stored extension information as values  	*/ -	public function all_disabled() +	public function all_disabled($phpbb_relative = true)  	{  		$disabled = array();  		foreach ($this->extensions as $name => $data)  		{  			if (!$data['ext_active'])  			{ -				$disabled[$name] = $this->phpbb_root_path . $data['ext_path']; +				$disabled[$name] = ($phpbb_relative ? $this->phpbb_root_path : '') . $data['ext_path'];  			}  		}  		return $disabled; diff --git a/phpBB/phpbb/extension/metadata_manager.php b/phpBB/phpbb/extension/metadata_manager.php index a64d88fe39..4f080647c8 100644 --- a/phpBB/phpbb/extension/metadata_manager.php +++ b/phpBB/phpbb/extension/metadata_manager.php @@ -37,12 +37,6 @@ class metadata_manager  	protected $template;  	/** -	* phpBB User instance -	* @var \phpbb\user -	*/ -	protected $user; - -	/**  	* phpBB root path  	* @var string  	*/ @@ -73,15 +67,13 @@ class metadata_manager  	* @param \phpbb\config\config		$config				phpBB Config instance  	* @param \phpbb\extension\manager	$extension_manager	An instance of the phpBB extension manager  	* @param \phpbb\template\template	$template			phpBB Template instance -	* @param \phpbb\user 		$user 				User instance  	* @param string				$phpbb_root_path	Path to the phpbb includes directory.  	*/ -	public function __construct($ext_name, \phpbb\config\config $config, \phpbb\extension\manager $extension_manager, \phpbb\template\template $template, \phpbb\user $user, $phpbb_root_path) +	public function __construct($ext_name, \phpbb\config\config $config, \phpbb\extension\manager $extension_manager, \phpbb\template\template $template, $phpbb_root_path)  	{  		$this->config = $config;  		$this->extension_manager = $extension_manager;  		$this->template = $template; -		$this->user = $user;  		$this->phpbb_root_path = $phpbb_root_path;  		$this->ext_name = $ext_name; @@ -149,7 +141,7 @@ class metadata_manager  		if (!file_exists($this->metadata_file))  		{ -			throw new \phpbb\extension\exception($this->user->lang('FILE_NOT_FOUND', $this->metadata_file)); +			throw new \phpbb\extension\exception('FILE_NOT_FOUND', array($this->metadata_file));  		}  	} @@ -163,18 +155,18 @@ class metadata_manager  	{  		if (!file_exists($this->metadata_file))  		{ -			throw new \phpbb\extension\exception($this->user->lang('FILE_NOT_FOUND', $this->metadata_file)); +			throw new \phpbb\extension\exception('FILE_NOT_FOUND', array($this->metadata_file));  		}  		else  		{  			if (!($file_contents = file_get_contents($this->metadata_file)))  			{ -				throw new \phpbb\extension\exception($this->user->lang('FILE_CONTENT_ERR', $this->metadata_file)); +				throw new \phpbb\extension\exception('FILE_CONTENT_ERR', array($this->metadata_file));  			}  			if (($metadata = json_decode($file_contents, true)) === null)  			{ -				throw new \phpbb\extension\exception($this->user->lang('FILE_JSON_DECODE_ERR', $this->metadata_file)); +				throw new \phpbb\extension\exception('FILE_JSON_DECODE_ERR', array($this->metadata_file));  			}  			array_walk_recursive($metadata, array($this, 'sanitize_json')); @@ -246,12 +238,12 @@ class metadata_manager  				{  					if (!isset($this->metadata[$name]))  					{ -						throw new \phpbb\extension\exception($this->user->lang('META_FIELD_NOT_SET', $name)); +						throw new \phpbb\extension\exception('META_FIELD_NOT_SET', array($name));  					}  					if (!preg_match($fields[$name], $this->metadata[$name]))  					{ -						throw new \phpbb\extension\exception($this->user->lang('META_FIELD_INVALID', $name)); +						throw new \phpbb\extension\exception('META_FIELD_INVALID', array($name));  					}  				}  			break; @@ -270,14 +262,14 @@ class metadata_manager  	{  		if (empty($this->metadata['authors']))  		{ -			throw new \phpbb\extension\exception($this->user->lang('META_FIELD_NOT_SET', 'authors')); +			throw new \phpbb\extension\exception('META_FIELD_NOT_SET', array('authors'));  		}  		foreach ($this->metadata['authors'] as $author)  		{  			if (!isset($author['name']))  			{ -				throw new \phpbb\extension\exception($this->user->lang('META_FIELD_NOT_SET', 'author name')); +				throw new \phpbb\extension\exception('META_FIELD_NOT_SET', array('author name'));  			}  		} | 
