Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

clean up custom role xml definition, add validationmethod and impleme…

…nt it for customrole/customtask/customcommand

git-svn-id: http://svn.php.net/repository/pear2/Pyrus/trunk@286124 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
commit 7af6e7ed6b4526899f59e869cb319f1324b94955 1 parent 4782962
@cellog cellog authored
View
10 data/customrole-2.0.xsd
@@ -13,6 +13,14 @@
</xs:documentation>
</xs:annotation>
</xs:element>
+ <xs:element name="validationmethod" type="xs:string" minOccurs="0" maxOccurs="1">
+ <xs:annotation>
+ <xs:documentation xml:lang="EN">
+ A method in the class that implements package-time
+ validation
+ </xs:documentation>
+ </xs:annotation>
+ </xs:element>
<xs:element name="autoloadpath" type="xs:string" minOccurs="0" maxOccurs="1">
<xs:annotation>
<xs:documentation xml:lang="EN">
@@ -26,9 +34,7 @@
<xs:element name="locationconfig" type="xs:string"/>
<xs:element name="honorsbaseinstall" type="xs:int" default="0"/>
<xs:element name="unusualbaseinstall" type="xs:int" default="0"/>
- <xs:element name="phpfile" type="xs:int" default="0"/>
<xs:element name="executable" type="xs:int" default="0"/>
- <xs:element name="phpextension" type="xs:int" default="0"/>
<xs:element ref="configvar" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="version" type="xs:string" fixed="2.0"/>
View
32 src/Pyrus/Installer/Role.php
@@ -171,36 +171,6 @@ static function getBaseinstallRoles($clear = false)
}
/**
- * Return an array of file roles that should be analyzed for PHP content at package time,
- * like the "php" role.
- * @param bool clear cache
- * @return array
- * @static
- */
- static function getPhpRoles($clear = false)
- {
- if (!isset(self::$_roles)) {
- self::registerRoles();
- }
-
- static $ret;
- if ($clear) {
- unset($ret);
- }
-
- if (!isset($ret)) {
- $ret = array();
- foreach (self::$_roles as $role => $okreleases) {
- if ($okreleases['phpfile']) {
- $ret[] = $role;
- }
- }
- }
-
- return $ret;
- }
-
- /**
* Scan through the Command directory looking for classes
* and see what commands they implement.
* @param string which directory to look for classes, defaults to
@@ -257,7 +227,6 @@ static function registerRoles($dir = null)
self::$_roles = $roles;
self::getBaseinstallRoles(true);
self::getInstallableRoles(true);
- self::getPhpRoles(true);
self::getValidRoles('****', true);
return true;
}
@@ -270,7 +239,6 @@ static function registerCustomRole($info)
self::$_roles = $roles;
self::getBaseinstallRoles(true);
self::getInstallableRoles(true);
- self::getPhpRoles(true);
self::getValidRoles('****', true);
if (isset($info['configvar'])) {
if (!isset($info['configvar'][0])) {
View
2  src/Pyrus/Installer/Role/Cfg.xml
@@ -10,7 +10,5 @@
<locationconfig>cfg_dir</locationconfig>
<honorsbaseinstall />
<unusualbaseinstall>1</unusualbaseinstall>
- <phpfile />
<executable />
- <phpextension />
</role>
View
19 src/Pyrus/Installer/Role/Common.php
@@ -242,6 +242,20 @@ function setup($installer, $pkg, $atts, $file)
{
}
+ final function packageTimeValidate(PEAR2_Pyrus_Package $package, array $fileXml)
+ {
+ if (!isset($this->info['validationmethod'])) {
+ return true;
+ }
+ if (!method_exists($this, $this->info['validationmethod'])) {
+ PEAR2_Pyrus_Log::log(0, 'WARNING: custom role ' . $this->info['name'] .
+ ' specifies non-existing validation method ' .
+ $this->info['validationmethod']);
+ return true;
+ }
+ return $this->{$this->info['validationmethod']}($package, $fileXml);
+ }
+
function isExecutable()
{
return $this->info['executable'];
@@ -251,9 +265,4 @@ function isInstallable()
{
return $this->info['installable'];
}
-
- function isExtension()
- {
- return $this->info['phpextension'];
- }
}
View
19 src/Pyrus/Installer/Role/Customcommand.php
@@ -23,5 +23,22 @@
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @link http://svn.pear.php.net/wsvn/PEARSVN/Pyrus/
*/
-class PEAR2_Pyrus_Installer_Role_Customcommand extends PEAR2_Pyrus_Installer_Role_Data {}
+class PEAR2_Pyrus_Installer_Role_Customcommand extends PEAR2_Pyrus_Installer_Role_Data
+{
+ function validate(PEAR2_Pyrus_IPackage $package, array $file)
+ {
+ $parser = new PEAR2_Pyrus_XMLParser;
+ $schemapath = PEAR2_Pyrus::getDataPath();
+ if (!file_exists(PEAR2_Pyrus::getDataPath() . '/customcommand-2.0.xsd')) {
+ $schemapath = realpath(__DIR__ . '/../../../../data');
+ }
+ $taskschema = $schemapath . '/customcommand-2.0.xsd';
+ try {
+ $taskinfo = $parser->parse($package->getFilePath($file['attribs']['name']), $taskschema);
+ } catch (\Exception $e) {
+ throw new PEAR2_Pyrus_Installer_Role_Exception('Invalid custom command definition file,' .
+ ' file does not conform to the schema', $e);
+ }
+ }
+}
?>
View
3  src/Pyrus/Installer/Role/Customcommand.xml
@@ -1,6 +1,7 @@
<role version="2.0" xmlns="http://pear2.php.net/dtd/customrole-2.0">
<name>customcommand</name>
<class>PEAR2_Pyrus_Installer_Role_Customcommand</class>
+ <validationmethod>validate</validationmethod>
<releasetypes>php</releasetypes>
<releasetypes>extsrc</releasetypes>
<releasetypes>extbin</releasetypes>
@@ -10,7 +11,5 @@
<locationconfig>data_dir</locationconfig>
<honorsbaseinstall />
<unusualbaseinstall>1</unusualbaseinstall>
- <phpfile />
<executable />
- <phpextension />
</role>
View
19 src/Pyrus/Installer/Role/Customrole.php
@@ -23,5 +23,22 @@
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @link http://svn.pear.php.net/wsvn/PEARSVN/Pyrus/
*/
-class PEAR2_Pyrus_Installer_Role_Customrole extends PEAR2_Pyrus_Installer_Role_Data {}
+class PEAR2_Pyrus_Installer_Role_Customrole extends PEAR2_Pyrus_Installer_Role_Data
+{
+ function validate(PEAR2_Pyrus_IPackage $package, array $file)
+ {
+ $parser = new PEAR2_Pyrus_XMLParser;
+ $schemapath = PEAR2_Pyrus::getDataPath();
+ if (!file_exists(PEAR2_Pyrus::getDataPath() . '/customrole-2.0.xsd')) {
+ $schemapath = realpath(__DIR__ . '/../../../../data');
+ }
+ $taskschema = $schemapath . '/customrole-2.0.xsd';
+ try {
+ $taskinfo = $parser->parse($package->getFilePath($file['attribs']['name']), $taskschema);
+ } catch (\Exception $e) {
+ throw new PEAR2_Pyrus_Installer_Role_Exception('Invalid custom role definition file,' .
+ ' file does not conform to the schema', $e);
+ }
+ }
+}
?>
View
3  src/Pyrus/Installer/Role/Customrole.xml
@@ -1,6 +1,7 @@
<role version="2.0" xmlns="http://pear2.php.net/dtd/customrole-2.0">
<name>customrole</name>
<class>PEAR2_Pyrus_Installer_Role_Customrole</class>
+ <validationmethod>validate</validationmethod>
<releasetypes>php</releasetypes>
<releasetypes>extsrc</releasetypes>
<releasetypes>extbin</releasetypes>
@@ -10,7 +11,5 @@
<locationconfig>data_dir</locationconfig>
<honorsbaseinstall />
<unusualbaseinstall>1</unusualbaseinstall>
- <phpfile />
<executable />
- <phpextension />
</role>
View
19 src/Pyrus/Installer/Role/Customtask.php
@@ -23,5 +23,22 @@
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @link http://svn.pear.php.net/wsvn/PEARSVN/Pyrus/
*/
-class PEAR2_Pyrus_Installer_Role_Customtask extends PEAR2_Pyrus_Installer_Role_Data {}
+class PEAR2_Pyrus_Installer_Role_Customtask extends PEAR2_Pyrus_Installer_Role_Data
+{
+ function validate(PEAR2_Pyrus_IPackage $package, array $file)
+ {
+ $parser = new PEAR2_Pyrus_XMLParser;
+ $schemapath = PEAR2_Pyrus::getDataPath();
+ if (!file_exists(PEAR2_Pyrus::getDataPath() . '/customtask-2.0.xsd')) {
+ $schemapath = realpath(__DIR__ . '/../../../../data');
+ }
+ $taskschema = $schemapath . '/customtask-2.0.xsd';
+ try {
+ $taskinfo = $parser->parse($package->getFilePath($file['attribs']['name']), $taskschema);
+ } catch (\Exception $e) {
+ throw new PEAR2_Pyrus_Installer_Role_Exception('Invalid custom task definition file,' .
+ ' file does not conform to the schema', $e);
+ }
+ }
+}
?>
View
3  src/Pyrus/Installer/Role/Customtask.xml
@@ -1,6 +1,7 @@
<role version="2.0" xmlns="http://pear2.php.net/dtd/customrole-2.0">
<name>customtask</name>
<class>PEAR2_Pyrus_Installer_Role_Customtask</class>
+ <validationmethod>validate</validationmethod>
<releasetypes>php</releasetypes>
<releasetypes>extsrc</releasetypes>
<releasetypes>extbin</releasetypes>
@@ -10,7 +11,5 @@
<locationconfig>data_dir</locationconfig>
<honorsbaseinstall />
<unusualbaseinstall>1</unusualbaseinstall>
- <phpfile />
<executable />
- <phpextension />
</role>
View
2  src/Pyrus/Installer/Role/Data.xml
@@ -10,7 +10,5 @@
<locationconfig>data_dir</locationconfig>
<honorsbaseinstall />
<unusualbaseinstall>1</unusualbaseinstall>
- <phpfile />
<executable />
- <phpextension />
</role>
View
2  src/Pyrus/Installer/Role/Doc.xml
@@ -10,7 +10,5 @@
<locationconfig>doc_dir</locationconfig>
<honorsbaseinstall />
<unusualbaseinstall>1</unusualbaseinstall>
- <phpfile />
<executable />
- <phpextension />
</role>
View
2  src/Pyrus/Installer/Role/Ext.xml
@@ -7,7 +7,5 @@
<locationconfig>ext_dir</locationconfig>
<honorsbaseinstall>1</honorsbaseinstall>
<unusualbaseinstall />
- <phpfile />
<executable />
- <phpextension>1</phpextension>
</role>
View
2  src/Pyrus/Installer/Role/Php.xml
@@ -10,7 +10,5 @@
<locationconfig>php_dir</locationconfig>
<honorsbaseinstall>1</honorsbaseinstall>
<unusualbaseinstall />
- <phpfile>1</phpfile>
<executable />
- <phpextension />
</role>
View
2  src/Pyrus/Installer/Role/Script.xml
@@ -10,7 +10,5 @@
<locationconfig>bin_dir</locationconfig>
<honorsbaseinstall>1</honorsbaseinstall>
<unusualbaseinstall />
- <phpfile />
<executable>1</executable>
- <phpextension />
</role>
View
2  src/Pyrus/Installer/Role/Src.xml
@@ -7,7 +7,5 @@
<locationconfig>src_dir</locationconfig>
<honorsbaseinstall />
<unusualbaseinstall>1</unusualbaseinstall>
- <phpfile />
<executable />
- <phpextension />
</role>
View
2  src/Pyrus/Installer/Role/Test.xml
@@ -10,7 +10,5 @@
<locationconfig>test_dir</locationconfig>
<honorsbaseinstall />
<unusualbaseinstall>1</unusualbaseinstall>
- <phpfile />
<executable />
- <phpextension />
</role>
View
2  src/Pyrus/Installer/Role/Www.xml
@@ -10,7 +10,5 @@
<locationconfig>www_dir</locationconfig>
<honorsbaseinstall />
<unusualbaseinstall>1</unusualbaseinstall>
- <phpfile />
<executable />
- <phpextension />
</role>
View
4 src/Pyrus/Package/Creator.php
@@ -208,6 +208,10 @@ function render(PEAR2_Pyrus_Package $package, array $extrafiles = array())
'to' => 'version',
'type' => 'package-info'));
foreach ($package->packagingcontents as $packageat => $info) {
+ $role =
+ PEAR2_Pyrus_Installer_Role::factory($package->getPackageType(), $info['attribs']['role']);
+ $role->packageTimeValidate($package);
+
$packageat = str_replace('\\', '/', $packageat);
$packageat = str_replace('//', '/', $packageat);
if ($packageat[0] === '/' ||
View
2  src/Pyrus/PluginRegistry.php
@@ -141,7 +141,7 @@ static function makeAutoloader($info, $type)
$info['autoloadpath']);
if (!$fullpath) {
throw new PEAR2_Pyrus_PluginRegistry_Exception(
- 'Unable to create autoloader for custom ' . $type . $info['name'] .
+ 'Unable to create autoloader for custom ' . $type . ' ' . $info['name'] .
', autoload path ' . $info['autoloadpath'] . ' does not exist');
}
$autoloader = function($class) use ($fullpath) {
View
2  tests/Custom/Role/basic.phpt
@@ -21,9 +21,7 @@ file_put_contents(__DIR__ . '/testit/foobar', '<?xml version="1.0" encoding="UTF
<locationconfig>www_dir</locationconfig>
<honorsbaseinstall />
<unusualbaseinstall>1</unusualbaseinstall>
- <phpfile />
<executable />
- <phpextension />
<configvar>
<name>burm_dir</name>
<type>string</type>
Please sign in to comment.
Something went wrong with that request. Please try again.