cvs: pear /HTML_CSS CSS.php

From: Date: Mon, 25 Jul 2005 10:00:42 +0000
Subject: cvs: pear /HTML_CSS CSS.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-33287@lists.php.net to get a copy of this message
thesaur Mon Jul 25 06:00:42 2005 EDT Modified files: /pear/HTML_CSS CSS.php Log: Committing Laurent's changes to the implementation of duplication

http://cvs.php.net/diff.php/pear/HTML_CSS/CSS.php?r1=1.40&r2=1.41&ty=u Index: pear/HTML_CSS/CSS.php diff -u pear/HTML_CSS/CSS.php:1.40 pear/HTML_CSS/CSS.php:1.41 --- pear/HTML_CSS/CSS.php:1.40 Tue Jun 14 17:13:38 2005 +++ pear/HTML_CSS/CSS.php Mon Jul 25 06:00:37 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.40 2005/06/14 21:13:38 thesaur Exp $ + * @version CVS: $Id: CSS.php,v 1.41 2005/07/25 10:00:37 thesaur Exp $ * @link http://pear.php.net/package/HTML_CSS */ @@ -137,7 +137,7 @@ * Determines whether groups are output prior to elements * * @var array - * @since 0.3.0 + * @since 1.0.0 * @access private */ var $_groupsFirst = true; @@ -173,6 +173,16 @@ var $_xhtmlCompliant = true; /** + * Allows to have duplicate rules in selector + * Useful for IE hack. + * + * @var bool + * @since 1.0.0 + * @access private + */ + var $_allowsDuplicates = false; + + /** * Error message callback. * This will be used to generate the error message * from the error code. @@ -273,6 +283,10 @@ $this->setOutputGroupsFirst($attributes['groupsfirst']); } } + if ((isset($attributes['allowDuplicates']) ) + && is_bool($attributes['allowDuplicates'])) { + $this->_allowDuplicates = $attributes['allowDuplicates']; + } } /** @@ -570,7 +584,7 @@ * @param mixed $group CSS definition group identifier * @param string $property Property defined * @param string $value Value assigned - * @param string $duplicates Value assigned + * @param bool $duplicates Allow or disallow duplicates. * * @return void|int|PEAR_Error Returns an integer if duplicates * are allowed. @@ -579,7 +593,7 @@ * @throws HTML_CSS_ERROR_INVALID_INPUT, HTML_CSS_ERROR_NO_GROUP * @see getGroupStyle() */ - function setGroupStyle($group, $property, $value, $duplicates = HTML_CSS_ALLOW_DUPLICATES) + function setGroupStyle($group, $property, $value, $duplicates = null) { if (!is_int($group) && !is_string($group)) { return $this->raiseError(HTML_CSS_ERROR_INVALID_INPUT, 'exception', @@ -602,7 +616,7 @@ 'expected' => 'string', 'paramnum' => 3)); - } elseif (!is_bool($duplicates)) { + } elseif (isset($duplicates) && !is_bool($duplicates)) { return $this->raiseError(HTML_CSS_ERROR_INVALID_INPUT, 'exception', array('var' => '$duplicates', 'was' => gettype($duplicates), @@ -610,6 +624,10 @@ 'paramnum' => 4)); } + if (!isset($duplicates)) { + $duplicates = $this->_allowsDuplicates; + } + $groupIdent = '@-'.$group; if ($group < 0 || $group > $this->_groupCount || !isset($this->_groups[$groupIdent])) { @@ -617,7 +635,7 @@ array('identifier' => $group)); } - if($duplicates === true) { + if ($duplicates === true) { $this->_duplicateCounter++; $this->_css[$groupIdent][$this->_duplicateCounter][$property]= $value; return $this->_duplicateCounter; @@ -775,7 +793,7 @@ * @throws HTML_CSS_ERROR_INVALID_INPUT * @see getStyle() */ - function setStyle ($element, $property, $value, $duplicates = HTML_CSS_ALLOW_DUPLICATES) + function setStyle ($element, $property, $value, $duplicates = null) { if (!is_string($element)) { return $this->raiseError(HTML_CSS_ERROR_INVALID_INPUT, 'exception', @@ -806,7 +824,7 @@ 'expected' => 'string without comma', 'paramnum' => 1)); - } elseif (!is_bool($duplicates)) { + } elseif (isset($duplicates) && !is_bool($duplicates)) { return $this->raiseError(HTML_CSS_ERROR_INVALID_INPUT, 'exception', array('var' => '$duplicates', 'was' => gettype($duplicates), @@ -814,8 +832,13 @@ 'paramnum' => 4)); } + if (!isset($duplicates)) { + $duplicates = $this->_allowsDuplicates; + } + $element = $this->parseSelectors($element); - if($duplicates === true) { + + if ($duplicates === true) { $this->_duplicateCounter++; $this->_css[$element][$this->_duplicateCounter][$property]= $value; return $this->_duplicateCounter; @@ -1017,7 +1040,7 @@ * @throws HTML_CSS_ERROR_INVALID_INPUT * @see createGroup(), setGroupStyle(), setStyle() */ - function parseString($str, $duplicates = HTML_CSS_ALLOW_DUPLICATES) + function parseString($str, $duplicates = null) { if (!is_string($str)) { return $this->raiseError(HTML_CSS_ERROR_INVALID_INPUT, 'exception', @@ -1025,6 +1048,17 @@ 'was' => gettype($str), 'expected' => 'string', '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->_allowsDuplicates; } // Remove comments @@ -1089,6 +1123,7 @@ * Parse a file that contains CSS information * * @param string $filename file to parse + * @param bool $duplicates Allow or disallow duplicates. * * @return void|PEAR_Error * @since 0.3.0 @@ -1096,7 +1131,7 @@ * @throws HTML_CSS_ERROR_INVALID_INPUT, HTML_CSS_ERROR_NO_FILE * @see parseString() */ - function parseFile($filename) + function parseFile($filename, $duplicates = null) { if (!is_string($filename)) { return $this->raiseError(HTML_CSS_ERROR_INVALID_INPUT, 'exception', @@ -1108,13 +1143,24 @@ } elseif (!file_exists($filename)) { return $this->raiseError(HTML_CSS_ERROR_NO_FILE, 'error', array('identifier' => $filename)); + + } 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->_allowsDuplicates; } if (function_exists('file_get_contents')){ - $this->parseString(file_get_contents($filename)); + $this->parseString(file_get_contents($filename), $duplicates); } else { $file = fopen("$filename", "rb"); - $this->parseString(fread($file, filesize($filename))); + $this->parseString(fread($file, filesize($filename)), $duplicates); fclose($file); } } @@ -1158,7 +1204,7 @@ if (isset($this->_alibis[$element])) { $alibis = $this->_alibis[$element]; - // All the groups must be run through to be able to + // All the groups must be run through to be able to // properly assign the value to the inline. foreach ($alibis as $alibi) { foreach ($this->_css[$alibi] as $rank => $property) {
« previous php.pear.cvs (#33287) next »