/** * Returns the code for a given formating option of a given type. * * $type is the type of formating ('color', 'bgcolor' or 'style'), $key the * name of the format to lookup. Returns the numeric code for the requested * format or 0 if format or type do not exist. * * @see ezcConsoleOutput::isValidFormatCode() * * @param string $type Formatting type. * @param string $key Format option name. * @return int The code representation. */ protected function getFormatCode($type, $key) { if (!ezcConsoleOutput::isValidFormatCode($type, $key)) { return 0; } return ezcConsoleOutput::${$type}[$key]; }
<?php class ezcConsoleOutput { protected static $color = array('gray' => 30); public static function isValidFormatCode($type, $key) { return isset(self::${$type}[$key]); } } var_dump(ezcConsoleOutput::isValidFormatCode('color', 'gray'));
/** * Overloaded __set() method to gain read-only access to properties. * It also performs checks on setting others. * * @throws ezcBasePropertyNotFoundException * If the setting you try to access does not exists * @throws ezcBaseValueException * If trying to set an invalid value for a setting. * * @param string $propertyName Name of the attrinbute to access. * @param string $val The value to set. * @ignore */ public function __set($propertyName, $val) { if (!isset($this->properties[$propertyName])) { throw new ezcBasePropertyNotFoundException($propertyName); } // Extry handling of multi styles if ($propertyName === 'style') { if (!is_array($val)) { $val = array($val); } foreach ($val as $style) { if (!ezcConsoleOutput::isValidFormatCode($propertyName, $style)) { throw new ezcBaseValueException($propertyName, $style, 'valid ezcConsoleOutput format code'); } } $this->properties['style'] = $val; return; } // Continue normal handling if (($propertyName === "color" || $propertyName === "bgcolor") && !ezcConsoleOutput::isValidFormatCode($propertyName, $val)) { throw new ezcBaseValueException($propertyName, $val, 'valid ezcConsoleOutput format code'); } $this->properties[$propertyName] = $val; }