diff options
Diffstat (limited to 'phpBB/phpbb/extension/metadata_manager.php')
| -rw-r--r-- | phpBB/phpbb/extension/metadata_manager.php | 72 | 
1 files changed, 32 insertions, 40 deletions
| diff --git a/phpBB/phpbb/extension/metadata_manager.php b/phpBB/phpbb/extension/metadata_manager.php index 19c6288e96..d0323120d8 100644 --- a/phpBB/phpbb/extension/metadata_manager.php +++ b/phpBB/phpbb/extension/metadata_manager.php @@ -10,14 +10,6 @@  namespace phpbb\extension;  /** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ -	exit; -} - -/**  * The extension metadata manager validates and gets meta-data for extensions  *  * @package extension @@ -147,7 +139,7 @@ class metadata_manager  		if (!file_exists($this->metadata_file))  		{ -    		throw new \phpbb\extension\exception('The required file does not exist: ' . $this->metadata_file); +			throw new \phpbb\extension\exception('The required file does not exist: ' . $this->metadata_file);  		}  	} @@ -166,12 +158,12 @@ class metadata_manager  		{  			if (!($file_contents = file_get_contents($this->metadata_file)))  			{ -    			throw new \phpbb\extension\exception('file_get_contents failed on ' . $this->metadata_file); +				throw new \phpbb\extension\exception('file_get_contents failed on ' . $this->metadata_file);  			} -			if (($metadata = json_decode($file_contents, true)) === NULL) +			if (($metadata = json_decode($file_contents, true)) === null)  			{ -    			throw new \phpbb\extension\exception('json_decode failed on ' . $this->metadata_file); +				throw new \phpbb\extension\exception('json_decode failed on ' . $this->metadata_file);  			}  			$this->metadata = $metadata; @@ -199,50 +191,50 @@ class metadata_manager  	* @return Bool True if valid, throws an exception if invalid  	*/  	public function validate($name = 'display') -    { -    	// Basic fields -    	$fields = array( -    		'name'		=> '#^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$#', -    		'type'		=> '#^phpbb-extension$#', -    		'licence'	=> '#.+#', -    		'version'	=> '#.+#', -    	); - -    	switch ($name) -    	{ -    		case 'all': -    			$this->validate('display'); +	{ +		// Basic fields +		$fields = array( +			'name'		=> '#^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$#', +			'type'		=> '#^phpbb-extension$#', +			'licence'	=> '#.+#', +			'version'	=> '#.+#', +		); + +		switch ($name) +		{ +			case 'all': +				$this->validate('display');  				$this->validate_enable(); -    		break; +			break; -    		case 'display': -    			foreach ($fields as $field => $data) +			case 'display': +				foreach ($fields as $field => $data)  				{  					$this->validate($field);  				}  				$this->validate_authors(); -    		break; - -    		default: -    			if (isset($fields[$name])) -    			{ -    				if (!isset($this->metadata[$name])) -    				{ -    					throw new \phpbb\extension\exception("Required meta field '$name' has not been set."); +			break; + +			default: +				if (isset($fields[$name])) +				{ +					if (!isset($this->metadata[$name])) +					{ +						throw new \phpbb\extension\exception("Required meta field '$name' has not been set.");  					}  					if (!preg_match($fields[$name], $this->metadata[$name]))  					{ -    					throw new \phpbb\extension\exception("Meta field '$name' is invalid."); +						throw new \phpbb\extension\exception("Meta field '$name' is invalid.");  					}  				}  			break;  		}  		return true; -    } +	}  	/**  	 * Validates the contents of the authors field @@ -253,14 +245,14 @@ class metadata_manager  	{  		if (empty($this->metadata['authors']))  		{ -    		throw new \phpbb\extension\exception("Required meta field 'authors' has not been set."); +			throw new \phpbb\extension\exception("Required meta field 'authors' has not been set.");  		}  		foreach ($this->metadata['authors'] as $author)  		{  			if (!isset($author['name']))  			{ -    			throw new \phpbb\extension\exception("Required meta field 'author name' has not been set."); +				throw new \phpbb\extension\exception("Required meta field 'author name' has not been set.");  			}  		} | 
