diff options
Diffstat (limited to 'phpBB/phpbb/extension')
| -rw-r--r-- | phpBB/phpbb/extension/base.php | 12 | ||||
| -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 | 95 | ||||
| -rw-r--r-- | phpBB/phpbb/extension/metadata_manager.php | 115 | 
5 files changed, 229 insertions, 137 deletions
diff --git a/phpBB/phpbb/extension/base.php b/phpBB/phpbb/extension/base.php index 5bb530bad4..c7778cfed1 100644 --- a/phpBB/phpbb/extension/base.php +++ b/phpBB/phpbb/extension/base.php @@ -24,7 +24,7 @@ class base implements \phpbb\extension\extension_interface  	protected $container;  	/** @var \phpbb\finder */ -	protected $finder; +	protected $extension_finder;  	/** @var \phpbb\db\migrator */  	protected $migrator; @@ -73,9 +73,7 @@ class base implements \phpbb\extension\extension_interface  	*/  	public function enable_step($old_state)  	{ -		$migrations = $this->get_migration_file_list(); - -		$this->migrator->set_migrations($migrations); +		$this->get_migration_file_list();  		$this->migrator->update(); @@ -103,8 +101,6 @@ class base implements \phpbb\extension\extension_interface  	{  		$migrations = $this->get_migration_file_list(); -		$this->migrator->set_migrations($migrations); -  		foreach ($migrations as $migration)  		{  			while ($this->migrator->migration_state($migration) !== false) @@ -137,6 +133,10 @@ class base implements \phpbb\extension\extension_interface  		$migrations = $this->extension_finder->get_classes_from_files($migrations); +		$this->migrator->set_migrations($migrations); + +		$migrations = $this->migrator->get_migrations(); +  		return $migrations;  	}  } 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 e7e5f83c23..4b4109bd85 100644 --- a/phpBB/phpbb/extension/manager.php +++ b/phpBB/phpbb/extension/manager.php @@ -13,6 +13,8 @@  namespace phpbb\extension; +use phpbb\exception\runtime_exception; +use phpbb\file_downloader;  use Symfony\Component\DependencyInjection\ContainerInterface;  /** @@ -26,7 +28,6 @@ class manager  	protected $db;  	protected $config;  	protected $cache; -	protected $user;  	protected $php_ext;  	protected $extensions;  	protected $extension_table; @@ -39,15 +40,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 \phpbb\cache\service $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\service $cache = null, $cache_name = '_ext')  	{  		$this->cache = $cache;  		$this->cache_name = $cache_name; @@ -58,7 +58,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; @@ -149,12 +148,16 @@ class manager  	* Instantiates the metadata manager for the extension with the given name  	*  	* @param string $name The extension name -	* @param \phpbb\template\template $template The template manager or null  	* @return \phpbb\extension\metadata_manager Instance of the metadata manager  	*/ -	public function create_extension_metadata_manager($name, \phpbb\template\template $template = null) +	public function create_extension_metadata_manager($name)  	{ -		return new \phpbb\extension\metadata_manager($name, $this->config, $this, $template, $this->user, $this->phpbb_root_path); +		if (!isset($this->extensions[$name]['metadata'])) +		{ +			$metadata = new \phpbb\extension\metadata_manager($name, $this->get_extension_path($name, true)); +			$this->extensions[$name]['metadata'] = $metadata; +		} +		return $this->extensions[$name]['metadata'];  	}  	/** @@ -170,7 +173,7 @@ class manager  	public function enable_step($name)  	{  		// ignore extensions that are already enabled -		if (isset($this->extensions[$name]) && $this->extensions[$name]['ext_active']) +		if ($this->is_enabled($name))  		{  			return false;  		} @@ -259,8 +262,8 @@ class manager  	*/  	public function disable_step($name)  	{ -		// ignore extensions that are already disabled -		if (!isset($this->extensions[$name]) || !$this->extensions[$name]['ext_active']) +		// ignore extensions that are not enabled +		if (!$this->is_enabled($name))  		{  			return false;  		} @@ -338,8 +341,8 @@ class manager  	*/  	public function purge_step($name)  	{ -		// ignore extensions that do not exist -		if (!isset($this->extensions[$name])) +		// ignore extensions that are not configured +		if (!$this->is_configured($name))  		{  			return false;  		} @@ -436,7 +439,7 @@ class manager  				$ext_name = str_replace(DIRECTORY_SEPARATOR, '/', $ext_name);  				if ($this->is_available($ext_name))  				{ -					$available[$ext_name] = $this->phpbb_root_path . 'ext/' . $ext_name . '/'; +					$available[$ext_name] = $this->get_extension_path($ext_name, true);  				}  			}  		} @@ -450,34 +453,41 @@ 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']; -			$configured[$name] = $data; +			if ($this->is_configured($name)) +			{ +				unset($data['metadata']); +				$data['ext_path'] = ($phpbb_relative ? $this->phpbb_root_path : '') . $data['ext_path']; +				$configured[$name] = $data; +			}  		}  		return $configured;  	}  	/**  	* 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']) +			if ($this->is_enabled($name))  			{ -				$enabled[$name] = $this->phpbb_root_path . $data['ext_path']; +				$enabled[$name] = ($phpbb_relative ? $this->phpbb_root_path : '') . $data['ext_path'];  			}  		}  		return $enabled; @@ -486,17 +496,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']) +			if ($this->is_disabled($name))  			{ -				$disabled[$name] = $this->phpbb_root_path . $data['ext_path']; +				$disabled[$name] = ($phpbb_relative ? $this->phpbb_root_path : '') . $data['ext_path'];  			}  		}  		return $disabled; @@ -529,7 +541,7 @@ class manager  	*/  	public function is_enabled($name)  	{ -		return isset($this->extensions[$name]) && $this->extensions[$name]['ext_active']; +		return isset($this->extensions[$name]['ext_active']) && $this->extensions[$name]['ext_active'];  	}  	/** @@ -540,7 +552,7 @@ class manager  	*/  	public function is_disabled($name)  	{ -		return isset($this->extensions[$name]) && !$this->extensions[$name]['ext_active']; +		return isset($this->extensions[$name]['ext_active']) && !$this->extensions[$name]['ext_active'];  	}  	/** @@ -554,7 +566,36 @@ class manager  	*/  	public function is_configured($name)  	{ -		return isset($this->extensions[$name]); +		return isset($this->extensions[$name]['ext_active']); +	} + +	/** +	* Check the version and return the available updates (for an extension). +	* +	* @param \phpbb\extension\metadata_manager $md_manager The metadata manager for the version to check. +	* @param bool $force_update Ignores cached data. Defaults to false. +	* @param bool $force_cache Force the use of the cache. Override $force_update. +	* @param string $stability Force the stability (null by default). +	* @return array +	* @throws runtime_exception +	*/ +	public function version_check(\phpbb\extension\metadata_manager $md_manager, $force_update = false, $force_cache = false, $stability = null) +	{ +		$meta = $md_manager->get_metadata('all'); + +		if (!isset($meta['extra']['version-check'])) +		{ +			throw new runtime_exception('NO_VERSIONCHECK'); +		} + +		$version_check = $meta['extra']['version-check']; + +		$version_helper = new \phpbb\version_helper($this->cache, $this->config, new file_downloader()); +		$version_helper->set_current_version($meta['version']); +		$version_helper->set_file_location($version_check['host'], $version_check['directory'], $version_check['filename'], isset($version_check['ssl']) ? $version_check['ssl'] : false); +		$version_helper->force_stability($stability); + +		return $version_helper->get_ext_update_on_branch($force_update, $force_cache);  	}  	/** diff --git a/phpBB/phpbb/extension/metadata_manager.php b/phpBB/phpbb/extension/metadata_manager.php index a09f07bed2..60b8db8310 100644 --- a/phpBB/phpbb/extension/metadata_manager.php +++ b/phpBB/phpbb/extension/metadata_manager.php @@ -19,36 +19,6 @@ namespace phpbb\extension;  class metadata_manager  {  	/** -	* phpBB Config instance -	* @var \phpbb\config\config -	*/ -	protected $config; - -	/** -	* phpBB Extension Manager -	* @var \phpbb\extension\manager -	*/ -	protected $extension_manager; - -	/** -	* phpBB Template instance -	* @var \phpbb\template\template -	*/ -	protected $template; - -	/** -	* phpBB User instance -	* @var \phpbb\user -	*/ -	protected $user; - -	/** -	* phpBB root path -	* @var string -	*/ -	protected $phpbb_root_path; - -	/**  	* Name (including vendor) of the extension  	* @var string  	*/ @@ -66,30 +36,18 @@ class metadata_manager  	*/  	protected $metadata_file; -	// @codingStandardsIgnoreStart  	/**  	* Creates the metadata manager  	*  	* @param string				$ext_name			Name (including vendor) of the extension -	* @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 or null -	* @param \phpbb\user 		$user 				User instance -	* @param string				$phpbb_root_path	Path to the phpbb includes directory. +	* @param string				$ext_path			Path to the extension directory including root path  	*/ -	public function __construct($ext_name, \phpbb\config\config $config, \phpbb\extension\manager $extension_manager, \phpbb\template\template $template = null, \phpbb\user $user, $phpbb_root_path) +	public function __construct($ext_name, $ext_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;  		$this->metadata = array(); -		$this->metadata_file = ''; +		$this->metadata_file = $ext_path . 'composer.json';  	} -	// @codingStandardsIgnoreEnd  	/**  	* Processes and gets the metadata requested @@ -100,7 +58,7 @@ class metadata_manager  	public function get_metadata($element = 'all')  	{  		// Fetch and clean the metadata if not done yet -		if ($this->metadata_file === '') +		if ($this->metadata === array())  		{  			$this->fetch_metadata_from_file();  		} @@ -126,30 +84,25 @@ class metadata_manager  	}  	/** -	* Sets the path of the metadata file, gets its contents and cleans loaded file +	* Gets the metadata file contents and cleans loaded file  	*  	* @throws \phpbb\extension\exception  	*/  	private function fetch_metadata_from_file()  	{ -		$ext_filepath = $this->extension_manager->get_extension_path($this->ext_name); -		$metadata_filepath = $this->phpbb_root_path . $ext_filepath . 'composer.json'; - -		$this->metadata_file = $metadata_filepath; -  		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));  		}  		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')); @@ -190,7 +143,7 @@ class metadata_manager  		{  			case 'all':  				$this->validate_enable(); -				// no break +			// no break  			case 'display':  				foreach ($fields as $field => $data) @@ -206,12 +159,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; @@ -230,14 +183,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'));  			}  		} @@ -266,7 +219,7 @@ class metadata_manager  	{  		if (substr_count($this->ext_name, '/') !== 1 || $this->ext_name != $this->get_metadata('name'))  		{ -			throw new \phpbb\extension\exception($this->user->lang('EXTENSION_DIR_INVALID')); +			throw new \phpbb\extension\exception('EXTENSION_DIR_INVALID');  		}  		return true; @@ -283,7 +236,7 @@ class metadata_manager  	{  		if (!isset($this->metadata['extra']['soft-require']['phpbb/phpbb']))  		{ -			throw new \phpbb\extension\exception($this->user->lang('META_FIELD_NOT_SET', 'soft-require')); +			throw new \phpbb\extension\exception('META_FIELD_NOT_SET', array('soft-require'));  		}  		return true; @@ -299,45 +252,9 @@ class metadata_manager  	{  		if (!isset($this->metadata['require']['php']))  		{ -			throw new \phpbb\extension\exception($this->user->lang('META_FIELD_NOT_SET', 'require php')); +			throw new \phpbb\extension\exception('META_FIELD_NOT_SET', array('require php'));  		}  		return true;  	} - -	/** -	* Outputs the metadata into the template -	* -	* @return null -	*/ -	public function output_template_data() -	{ -		$this->template->assign_vars(array( -			'META_NAME'			=> $this->metadata['name'], -			'META_TYPE'			=> $this->metadata['type'], -			'META_DESCRIPTION'	=> (isset($this->metadata['description'])) ? $this->metadata['description'] : '', -			'META_HOMEPAGE'		=> (isset($this->metadata['homepage'])) ? $this->metadata['homepage'] : '', -			'META_VERSION'		=> (isset($this->metadata['version'])) ? $this->metadata['version'] : '', -			'META_TIME'			=> (isset($this->metadata['time'])) ? $this->metadata['time'] : '', -			'META_LICENSE'		=> $this->metadata['license'], - -			'META_REQUIRE_PHP'		=> (isset($this->metadata['require']['php'])) ? $this->metadata['require']['php'] : '', -			'META_REQUIRE_PHP_FAIL'	=> (isset($this->metadata['require']['php'])) ? false : true, - -			'META_REQUIRE_PHPBB'		=> (isset($this->metadata['extra']['soft-require']['phpbb/phpbb'])) ? $this->metadata['extra']['soft-require']['phpbb/phpbb'] : '', -			'META_REQUIRE_PHPBB_FAIL'	=> (isset($this->metadata['extra']['soft-require']['phpbb/phpbb'])) ? false : true, - -			'META_DISPLAY_NAME'	=> (isset($this->metadata['extra']['display-name'])) ? $this->metadata['extra']['display-name'] : '', -		)); - -		foreach ($this->metadata['authors'] as $author) -		{ -			$this->template->assign_block_vars('meta_authors', array( -				'AUTHOR_NAME'		=> $author['name'], -				'AUTHOR_EMAIL'		=> (isset($author['email'])) ? $author['email'] : '', -				'AUTHOR_HOMEPAGE'	=> (isset($author['homepage'])) ? $author['homepage'] : '', -				'AUTHOR_ROLE'		=> (isset($author['role'])) ? $author['role'] : '', -			)); -		} -	}  }  | 
