cvs: pear /HTML_CSS CSS.php
| From: | Laurent Laville | Date: | Thu, 15 Dec 2005 17:16:07 +0000 |
| Subject: | cvs: pear /HTML_CSS CSS.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-36884@lists.php.net to get a copy of this message | ||
farell Thu Dec 15 17:16:07 2005 EDT
Modified files:
/pear/HTML_CSS CSS.php
Log:
- add new feature : ability to parse a list of data sources (filenames or strings)
see parseData() function; a new example will follow to explain.
- add a PEAR::isError like asked by Luka Smith on July 29, 2005 (pear-dev mailing list)
i've promised to include it in RC2
Works fine with PEAR_Error, but also PEAR_ErrorStack (and as usual, any other custom error
handler)
http://cvs.php.net/viewcvs.cgi/pear/HTML_CSS/CSS.php?r1=1.43&r2=1.44&diff_format=u
Index: pear/HTML_CSS/CSS.php
diff -u pear/HTML_CSS/CSS.php:1.43 pear/HTML_CSS/CSS.php:1.44
--- pear/HTML_CSS/CSS.php:1.43 Mon Jul 25 20:48:38 2005
+++ pear/HTML_CSS/CSS.php Thu Dec 15 17:16:07 2005
@@ -19,7 +19,7 @@
* @author Laurent Laville <pear@laurent-laville.org>
* @copyright 1997-2005 The PHP Group
* @license http://www.php.net/license/3_0.txt
PHP License 3.0
- * @version CVS: $Id: CSS.php,v 1.43 2005/07/25 20:48:38 thesaur Exp $
+ * @version CVS: $Id: CSS.php,v 1.44 2005/12/15 17:16:07 farell Exp $
* @link http://pear.php.net/package/HTML_CSS
*/
@@ -229,6 +229,16 @@
*/
var $_errorhandler_options = array();
+ /**
+ * Last error that might occured
+ *
+ * @var false|mixed
+ * @since 1.0.0RC2
+ * @access private
+ * @see isError(), raiseError()
+ */
+ var $_lastError = false;
+
/**
* Class constructor
@@ -1156,6 +1166,51 @@
}
/**
+ * Parse data sources, file(s) or string(s), that contains CSS information
+ *
+ * @param array $styles data sources to parse
+ * @param bool $duplicates Allow or disallow duplicates.
+ *
+ * @return void|PEAR_Error
+ * @since 1.0.0RC2
+ * @access public
+ * @throws HTML_CSS_ERROR_INVALID_INPUT
+ * @see parseString(), parseFile()
+ */
+ function parseData($styles, $duplicates = null)
+ {
+ if (!is_array($styles)) {
+ return $this->raiseError(HTML_CSS_ERROR_INVALID_INPUT, 'exception',
+ array('var' => '$styles',
+ 'was' => gettype($styles),
+ 'expected' => 'array',
+ 'paramnum' => 1));
+
+ } elseif (isset($duplicates) && !is_bool($duplicates)) {
+ return $this->raiseError(HTML_CSS_ERROR_INVALID_INPUT, 'exception',
+ array('var' => '$duplicates',
+ 'was' => gettype($duplicates),
+ 'expected' => 'bool',
+ 'paramnum' => 2));
+ }
+
+ if (!isset($duplicates)) {
+ $duplicates = $this->_allowDuplicates;
+ }
+
+ foreach($styles as $style) {
+ if (strcasecmp(substr($style, -4,4), '.css') == 0) {
+ $res = $this->parseFile($style, $duplicates);
+ } else {
+ $res = $this->parseString($style, $duplicates);
+ }
+ if ($this->isError($res)) {
+ return $res;
+ }
+ }
+ }
+
+ /**
* Returns the array of CSS properties
*
* @return array
@@ -1468,7 +1523,20 @@
function raiseError()
{
$args = func_get_args();
- return call_user_func_array($this->_callback_errorhandler, $args);
+ $this->_lastError = call_user_func_array($this->_callback_errorhandler, $args);
+ return $this->_lastError;
+ }
+
+ /**
+ * Determine whether there is an error
+ *
+ * @return boolean TRUE if error raised, FALSE otherwise
+ * @since 1.0.0RC2
+ * @access public
+ */
+ function isError()
+ {
+ return (!is_bool($this->_lastError));
}
}
?>
\ No newline at end of file