com web/rmtools: the better way to read the chained props from SimpleXml objects: client/include/PeclExt.php
| From: | Stephen A. Zarkos | Date: | Wed, 11 Sep 2013 16:09:00 +0000 |
| Subject: | com web/rmtools: the better way to read the chained props from SimpleXml objects: client/include/PeclExt.php | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-16702@lists.php.net to get a copy of this message | ||
Commit: ce81e97346ed24b794fc066e5dc726e089137a99
Author: Anatol Belski <ab@php.net> Wed, 11 Sep 2013 18:09:00 +0200
Parents: 8706985d0a2b387d645613391e879201f0398cbd
Branches: master
Link: http://git.php.net/?p=web/rmtools.git;a=commitdiff;h=ce81e97346ed24b794fc066e5dc726e089137a99
Log:
the better way to read the chained props from SimpleXml objects
Changed paths:
M client/include/PeclExt.php
Diff:
diff --git a/client/include/PeclExt.php b/client/include/PeclExt.php
index 36e7deb..dc86f73 100644
--- a/client/include/PeclExt..php
+++ b/client/include/PeclExt.php
@@ -36,8 +36,8 @@ class PeclExt
/* Setup some stuff */
if ($this->package_xml) {
- $this->name = (string)$this->package_xml->name;
- $this->version = (string)$this->package_xml->version->release;
+ $this->name = $this->getPackageXmlProperty("name");
+ $this->version = $this->getPackageXmlProperty("version", "release");
}
if (!$this->name || !$this->version) {
@@ -67,7 +67,7 @@ class PeclExt
}
}
- $this->name = strtolower($this->name);
+ $this->name = str_replace('_', '-', strtolower($this->name));
$this->version = strtolower($this->version);
}
@@ -398,8 +398,8 @@ class PeclExt
}
if ($this->package_xml) {
- $min_php_ver = (string)$this->package_xml->dependencies->required->php->min;
- $max_php_ver = (string)$this->package_xml->dependencies->required->php->max;
+ $min_php_ver = $this->getPackageXmlProperty("dependencies", "required",
"php", "min");
+ $max_php_ver = $this->getPackageXmlProperty("dependencies", "required",
"php", "max");
$php_ver = '';
$ver_hdr = $this->build->getSourceDir() . '/main/php_version.h';
@@ -465,5 +465,33 @@ class PeclExt
}
+ protected function getPackageXmlProperty()
+ {
+ if (!$this->package_xml) {
+ return NULL;
+ }
+
+ $list = func_get_args();
+ $last = func_get_arg(func_num_args()-1);
+
+ $current = $this->package_xml;
+ foreach ($list as $prop) {
+ if (!isset($current->$prop)) {
+ return NULL;
+ }
+
+ if ($prop == $last) {
+ return $current->$prop;
+ }
+
+ /* if the $prop isn't an object and isn't last,
+ no way to iterate the remaining chain*/
+ if (is_object($current->$prop)) {
+ $current = $current->$prop;
+ } else {
+ return NULL;
+ }
+ }
+ }
}