parseLocationPath( $path, $this->getSuffix() ); } } /** * Initializes the reader with a location and a name. These values determine * where the configuration will be serialized. * * @param string $location The main placement for the configuration. It is * up to the specific reader to interpret this value. This * can for instance be used to determine the directory * location for an INI file. * @param string $name The name for the configuration. It is up to the * specific reader to interpret this value. This can for * instance be the basename for the INI file, so a value of * 'site' would create a file with name 'site.ini'. * @param array $options An associative array of options for the reader. * Which options to use is determined by the specific reader * class. * @return void */ public function init( $location, $name, array $options = array() ) { $this->path = $location . DIRECTORY_SEPARATOR . $name . '.' . $this->getSuffix(); $this->location = $location; $this->name = $name; $this->setOptions( $options ); } /** * Sets the options $configurationData. * * The options are specified in a associative array in the form 'optionName' => value. * * @throws ezcBaseSettingNotFoundException if you try to set a non existent setting. * @throws ezcBaseSettingValueException if you specify a value out of range for a setting. * @param array(string=>mixed) $configurationData * @return void */ public function setOptions( $configurationData ) { foreach ( $configurationData as $name => $value ) { switch ( $name ) { case 'useComments': if ( gettype( $value ) != 'boolean' ) { throw new ezcBaseSettingValueException( $name, $value, 'bool' ); } $this->useComments = $value; break; default: throw new ezcBaseSettingNotFoundException( $name ); } } } /** * Returns the current options for the reader. * * @return array */ public function getOptions() { return array( 'useComments' => $this->useComments ); } /** * Returns the current configuration object. * * Returns false if there no current configuration. * * @return ezcConfiguration */ public function getConfig() { return $this->config; } /** * Returns the current location string. * * @return string */ public function getLocation() { return $this->location; } /** * Returns the current name for the configuration to be read. * * @return string */ public function getName() { return $this->name; } /** * Parses a the path $path and sets the location and name * properties on this object. * * ezcConfigurationFileWriter::parseLocationPath() has the same * code. It is duplicated to prevent complex OO hacks. * * @throws ezcConfigurationException if the configuration file has the wrong suffix. * @param string $path * @param string $suffix * @return void */ protected function parseLocationPath( $path, $suffix ) { $this->path = $path; $this->location = dirname( $path ); $base = basename( $path ); if ( $suffix[0] != '.' ) { $suffix = ".$suffix"; } if ( !preg_match( '@' . preg_quote( $suffix ) . '$@', $path ) ) { throw new ezcConfigurationInvalidSuffixException( $path, $suffix ); } $this->name = basename( $base, $suffix ); } /** * Returns the last modified timestamp. * * Returns false if there is not last current timestamp. * * @return int */ public function getTimestamp() { if ( file_exists( $this->path ) ) { return filemtime( $this->path ); } return false; } /** * Returns true if the configuration exists. * * @return bool */ public function configExists() { return file_exists( $this->path ); } } ?>