/** * Configures the validation set. * * First this method tries to load a configuration from a configuration * file in the given configration directory using * Piece_Right_Config_Factory::factory method. The method creates a new * object if the load failed. * Second this method merges the given configuretion into the loaded * configuration. * * @param string $validationSetName * @param Piece_Right_Config $dynamicConfig * @return Piece_Right_Config */ function &_configure($validationSetName = null, $dynamicConfig = null) { $config =& Piece_Right_Config_Factory::factory($validationSetName, $this->_configDirectory, $this->_cacheDirectory, $this->_template); if (Piece_Right_Error::hasErrors()) { $return = null; return $return; } if (is_a($dynamicConfig, 'Piece_Right_Config')) { $config->merge($dynamicConfig); } return $config; }
/** * Sets whether or not Piece_Right uses underscores in validation set * names as directory separators. * * @param boolean $treatUnderscoreAsDirectorySeparator * @since Method available since Release 1.3.0 */ function setUseUnderscoreAsDirectorySeparator($useUnderscoreAsDirectorySeparator) { Piece_Right_Config_Factory::setUseUnderscoreAsDirectorySeparator($useUnderscoreAsDirectorySeparator); }
/** * Gets a Piece_Right_Config object from a configuration file or a cache. * * @param string $masterFile * @param string $cacheDirectory * @return Piece_Right_Config */ function &_getConfiguration($masterFile, $cacheDirectory) { $masterFile = realpath($masterFile); $cache =& new Cache_Lite_File(array('cacheDir' => "{$cacheDirectory}/", 'masterFile' => $masterFile, 'automaticSerialization' => true, 'errorHandlingAPIBreak' => true)); if (!Piece_Right_Env::isProduction()) { $cache->remove($masterFile); } /* * The Cache_Lite class always specifies PEAR_ERROR_RETURN when * calling PEAR::raiseError in default. */ $config = $cache->get($masterFile); if (PEAR::isError($config)) { trigger_error("Cannot read the cache file in the directory [ {$cacheDirectory} ].", E_USER_WARNING); return Piece_Right_Config_Factory::_getConfigurationFromFile($masterFile); } if (!$config) { $config =& Piece_Right_Config_Factory::_getConfigurationFromFile($masterFile); if (Piece_Right_Error::hasErrors()) { $return = null; return $return; } $result = $cache->save($config); if (PEAR::isError($result)) { trigger_error("Cannot write the Piece_Right_Config object to the cache file in the directory [ {$cacheDirectory} ].", E_USER_WARNING); } } return $config; }
/** * @since Method available since Release 1.8.0 */ function testUnderScoresInValidationSetNamesShouldBeUsedAsDirectorySeparators() { Piece_Right_Config_Factory::setUseUnderscoreAsDirectorySeparator(true); $_SERVER['REQUEST_METHOD'] = 'POST'; $_POST['firstName'] = ' Foo '; $_POST['lastName'] = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'; $right =& new Piece_Right($this->_cacheDirectory, $this->_cacheDirectory); $right->setTemplate('Common'); $this->assertFalse($right->validate('UnderScoresInValidationSetNamesShouldBeUsedAsDirectorySeparators_Foo')); $results =& $right->getResults(); $this->assertTrue(in_array('firstName', $results->getValidFields())); $this->assertTrue(in_array('lastName', $results->getErrorFields())); $this->assertEquals('Foo', $results->getFieldValue('firstName')); $this->assertEquals('The length of Last Name must be less than 255 characters', $results->getErrorMessage('lastName')); $fieldNames = $right->getFieldNames('UnderScoresInValidationSetNamesShouldBeUsedAsDirectorySeparators_Foo'); $this->assertEquals(2, count($fieldNames)); $this->assertContains('firstName', $fieldNames); $this->assertContains('lastName', $fieldNames); Piece_Right_Config_Factory::setUseUnderscoreAsDirectorySeparator(false); }