本文整理汇总了PHP中Properties::keys方法的典型用法代码示例。如果您正苦于以下问题:PHP Properties::keys方法的具体用法?PHP Properties::keys怎么用?PHP Properties::keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Properties
的用法示例。
在下文中一共展示了Properties::keys方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: resolveAllProperties
/**
* Given a Properties object, this method goes through and resolves
* any references to properties within the object.
*
* @param Properties $props The collection of Properties that need to be resolved.
* @throws BuildException
* @return void
*/
protected function resolveAllProperties(Properties $props)
{
foreach ($props->keys() as $name) {
// There may be a nice regex/callback way to handle this
// replacement, but at the moment it is pretty complex, and
// would probably be a lot uglier to work into a preg_replace_callback()
// system. The biggest problem is the fact that a resolution may require
// multiple passes.
$value = $props->getProperty($name);
$resolved = false;
$resolveStack = array();
while (!$resolved) {
$fragments = array();
$propertyRefs = array();
// [HL] this was ::parsePropertyString($this->value ...) ... this seems wrong
self::parsePropertyString($value, $fragments, $propertyRefs);
$resolved = true;
if (count($propertyRefs) == 0) {
continue;
}
$sb = "";
$j = $propertyRefs;
foreach ($fragments as $fragment) {
if ($fragment !== null) {
$sb .= $fragment;
continue;
}
$propertyName = array_shift($j);
if (in_array($propertyName, $resolveStack)) {
// Should we maybe just log this as an error & move on?
// $this->log("Property ".$name." was circularly defined.", Project::MSG_ERR);
throw new BuildException("Property " . $propertyName . " was circularly defined.");
}
$fragment = $this->getProject()->getProperty($propertyName);
if ($fragment !== null) {
$sb .= $fragment;
continue;
}
if ($props->containsKey($propertyName)) {
$fragment = $props->getProperty($propertyName);
if (strpos($fragment, '${') !== false) {
$resolveStack[] = $propertyName;
$resolved = false;
// parse again (could have been replaced w/ another var)
}
} else {
$fragment = "\${" . $propertyName . "}";
}
$sb .= $fragment;
}
$this->log("Resolved Property \"{$value}\" to \"{$sb}\"", Project::MSG_DEBUG);
$value = $sb;
$props->setProperty($name, $value);
}
// while (!$resolved)
}
// while (count($keys)
}
示例2: runBuild
/**
* Executes the build.
* @return void
*/
function runBuild()
{
if (!$this->readyToRun) {
return;
}
$project = new Project();
self::setCurrentProject($project);
set_error_handler(array('Phing', 'handlePhpError'));
$error = null;
$this->addBuildListeners($project);
$this->addInputHandler($project);
// set this right away, so that it can be used in logging.
$project->setUserProperty("phing.file", $this->buildFile->getAbsolutePath());
try {
$project->fireBuildStarted();
$project->init();
} catch (Exception $exc) {
$project->fireBuildFinished($exc);
throw $exc;
}
$project->setUserProperty("phing.version", $this->getPhingVersion());
$e = self::$definedProps->keys();
while (count($e)) {
$arg = (string) array_shift($e);
$value = (string) self::$definedProps->getProperty($arg);
$project->setUserProperty($arg, $value);
}
unset($e);
$project->setUserProperty("phing.file", $this->buildFile->getAbsolutePath());
// first use the Configurator to create the project object
// from the given build file.
try {
ProjectConfigurator::configureProject($project, $this->buildFile);
} catch (Exception $exc) {
$project->fireBuildFinished($exc);
restore_error_handler();
self::unsetCurrentProject();
throw $exc;
}
// make sure that we have a target to execute
if (count($this->targets) === 0) {
$this->targets[] = $project->getDefaultTarget();
}
// make sure that minimum required phing version is satisfied
try {
$this->comparePhingVersion($project->getPhingVersion());
} catch (Exception $exc) {
$project->fireBuildFinished($exc);
restore_error_handler();
self::unsetCurrentProject();
throw $exc;
}
// execute targets if help param was not given
if (!$this->projectHelp) {
try {
$project->executeTargets($this->targets);
} catch (Exception $exc) {
$project->fireBuildFinished($exc);
restore_error_handler();
self::unsetCurrentProject();
throw $exc;
}
}
// if help is requested print it
if ($this->projectHelp) {
try {
$this->printDescription($project);
$this->printTargets($project);
} catch (Exception $exc) {
$project->fireBuildFinished($exc);
restore_error_handler();
self::unsetCurrentProject();
throw $exc;
}
}
// finally {
if (!$this->projectHelp) {
$project->fireBuildFinished(null);
}
restore_error_handler();
self::unsetCurrentProject();
}
示例3: main
public function main()
{
if ($this->_database === null) {
$coverageDatabase = $this->project->getProperty('coverage.database');
if (!$coverageDatabase) {
throw new BuildException('Either include coverage-setup in your build file or set ' . 'the "database" attribute');
}
$database = new PhingFile($coverageDatabase);
} else {
$database = $this->_database;
}
$this->log('Calculating coverage threshold: min. ' . $this->_perProject . '% per project, ' . $this->_perClass . '% per class and ' . $this->_perMethod . '% per method is required');
$props = new Properties();
$props->load($database);
foreach ($props->keys() as $filename) {
$file = unserialize($props->getProperty($filename));
// Skip file if excluded from coverage threshold validation
if ($this->_excludes !== null) {
if (in_array($file['fullname'], $this->_excludes->getExcludedFiles())) {
continue;
}
}
$this->calculateCoverageThreshold($file['fullname'], $file['coverage']);
}
if ($this->_projectStatementCount > 0) {
$coverage = $this->_projectStatementsCovered / $this->_projectStatementCount * 100;
} else {
$coverage = 0;
}
if ($coverage < $this->_perProject) {
throw new BuildException('The coverage (' . round($coverage, 2) . '%) for the entire project ' . 'is lower than the specified threshold (' . $this->_perProject . '%)');
}
$this->log('Passed coverage threshold. Minimum found coverage values are: ' . round($coverage, 2) . '% per project, ' . round($this->_minClassCoverageFound, 2) . '% per class and ' . round($this->_minMethodCoverageFound, 2) . '% per method');
}
示例4: main
function main()
{
$this->log("Transforming coverage report");
$database = new PhingFile($this->project->getProperty('coverage.database'));
$props = new Properties();
$props->load($database);
foreach ($props->keys() as $filename) {
$file = unserialize($props->getProperty($filename));
$this->transformCoverageInformation($file['fullname'], $file['coverage']);
}
$this->calculateStatistics();
$this->doc->save($this->outfile);
foreach ($this->transformers as $transformer) {
$transformer->setXmlDocument($this->doc);
$transformer->transform();
}
}
示例5: main
/**
* Load the sql file and then execute it
*
* @throws BuildException
*/
public function main()
{
$this->sqlCommand = trim($this->sqlCommand);
if ($this->sqldbmap === null || $this->getSqlDbMap()->exists() === false) {
throw new BuildException("You haven't provided an sqldbmap, or " . "the one you specified doesn't exist: " . $this->sqldbmap->getPath());
}
if ($this->url === null) {
throw new BuildException("DSN url attribute must be set!");
}
$map = new Properties();
try {
$map->load($this->getSqlDbMap());
} catch (IOException $ioe) {
throw new BuildException("Cannot open and process the sqldbmap!");
}
$databases = array();
foreach ($map->keys() as $sqlfile) {
$database = $map->getProperty($sqlfile);
// Q: already there?
if (!isset($databases[$database])) {
// A: No.
$databases[$database] = array();
}
// We want to make sure that the base schemas
// are inserted first.
if (strpos($sqlfile, "schema.sql") !== false) {
// add to the beginning of the array
array_unshift($databases[$database], $sqlfile);
} else {
array_push($databases[$database], $sqlfile);
}
}
foreach ($databases as $db => $files) {
$transactions = array();
foreach ($files as $fileName) {
$file = new PhingFile($this->srcDir, $fileName);
if ($file->exists()) {
$this->log("Executing statements in file: " . $file->__toString());
$transaction = new PropelSQLExecTransaction($this);
$transaction->setSrc($file);
$transactions[] = $transaction;
} else {
$this->log("File '" . $file->__toString() . "' in sqldbmap does not exist, so skipping it.");
}
}
$this->insertDatabaseSqlFiles($this->url, $db, $transactions);
}
}
示例6: setContextProperties
/**
* Set the context properties that will be
* fed into the initial context be the
* generating process starts.
* @param string $file
* @throws BuildException
* @return void
*/
public function setContextProperties($file)
{
$sources = explode(",", $file);
$this->contextProperties = new Properties();
// Always try to get the context properties resource
// from a file first. Templates may be taken from a JAR
// file but the context properties resource may be a
// resource in the filesystem. If this fails than attempt
// to get the context properties resource from the
// classpath.
for ($i = 0, $sourcesLength = count($sources); $i < $sourcesLength; $i++) {
$source = new Properties();
try {
// resolve relative path from basedir and leave
// absolute path untouched.
$fullPath = $this->project->resolveFile($sources[$i]);
$this->log("Using contextProperties file: " . $fullPath->__toString());
$source->load($fullPath);
} catch (Exception $e) {
throw new BuildException("Context properties file " . $sources[$i] . " could not be found in the file system!");
}
$keys = $source->keys();
foreach ($keys as $key) {
$name = $key;
$value = $this->project->replaceProperties($source->getProperty($name));
$this->contextProperties->setProperty($name, $value);
}
}
}
示例7: main
function main()
{
$coverageDatabase = $this->project->getProperty('coverage.database');
if (!$coverageDatabase) {
throw new BuildException("Property coverage.database is not set - please include coverage-setup in your build file");
}
$database = new PhingFile($coverageDatabase);
$this->log("Transforming coverage report");
$props = new Properties();
$props->load($database);
foreach ($props->keys() as $filename) {
$file = unserialize($props->getProperty($filename));
$this->transformCoverageInformation($file['fullname'], $file['coverage']);
}
$this->calculateStatistics();
$this->doc->save($this->outfile);
foreach ($this->transformers as $transformer) {
$transformer->setXmlDocument($this->doc);
$transformer->transform();
}
}
示例8: main
/**
* Main method parses the XML files and creates SQL files.
*
* @return void
* @throws Exception If there is an error parsing the data xml.
*/
public function main()
{
$this->validate();
$targetDatabase = $this->getTargetDatabase();
$platform = $this->getPlatformForTargetDatabase();
// Load the Data XML -> DB Name properties
$map = new Properties();
try {
$map->load($this->getDataDbMap());
} catch (IOException $ioe) {
throw new BuildException("Cannot open and process the datadbmap!", $ioe);
}
DataModelBuilder::setBuildProperties($this->getPropelProperties());
// Parse each file in teh data -> db map
foreach ($map->keys() as $dataXMLFilename) {
$dataXMLFile = new PhingFile($this->srcDir, $dataXMLFilename);
// if file exists then proceed
if ($dataXMLFile->exists()) {
$dbname = $map->get($dataXMLFilename);
$db = $this->getDatabase($dbname);
if (!$db) {
throw new BuildException("Cannot find instantiated Database for name '{$dbname}' from datadbmap file.");
}
$db->setPlatform($platform);
$outFile = $this->getMappedFile($dataXMLFilename);
$this->log("Creating SQL from XML data dump file: " . $dataXMLFile->getAbsolutePath());
try {
$dataXmlParser = new XmlToData($db, $this->dbEncoding);
$data = $dataXmlParser->parseFile($dataXMLFile->getAbsolutePath());
} catch (Exception $e) {
throw new Exception("Exception parsing data XML: " . $e->getMessage());
}
$fp = fopen($outFile->getAbsolutePath(), 'w');
$currTable = null;
foreach ($data as $dataRow) {
if ($currTable !== $dataRow->getTable()) {
$currTable = $dataRow->getTable();
$builder = DataModelBuilder::builderFactory($currTable, 'datasql');
}
$sql = $builder->buildRowSql($dataRow);
fwrite($fp, $sql);
}
fclose($fp);
// Place the generated SQL file(s)
$p = new Properties();
if ($this->getSqlDbMap()->exists()) {
$p->load($this->getSqlDbMap());
}
$p->setProperty($outFile->getName(), $db->getName());
$p->store($this->getSqlDbMap(), "Sqlfile -> Database map");
} else {
$this->log("File '" . $dataXMLFile->getAbsolutePath() . "' in datadbmap does not exist, so skipping it.", PROJECT_MSG_WARN);
}
}
// foreach data xml file
}
示例9: main
/**
* Main method parses the XML files and creates SQL files.
*
* @return void
* @throws Exception If there is an error parsing the data xml.
* @throws BuildException
*/
public function main()
{
$this->validate();
$targetDatabase = $this->getTargetDatabase();
$platform = $this->getGeneratorConfig()->getConfiguredPlatform();
// Load the Data XML -> DB Name properties
$map = new Properties();
try {
$map->load($this->getDataDbMap());
} catch (IOException $ioe) {
throw new BuildException("Cannot open and process the datadbmap!", $ioe);
}
// Parse each file in the data -> db map
foreach ($map->keys() as $dataXMLFilename) {
$dataXMLFile = new PhingFile($this->srcDir, $dataXMLFilename);
// if file exists then proceed
if ($dataXMLFile->exists()) {
$dbname = $map->get($dataXMLFilename);
$db = $this->getDatabase($dbname);
if (!$db) {
throw new BuildException("Cannot find instantiated Database for name '{$dbname}' from datadbmap file.");
}
$db->setPlatform($platform);
$outFile = $this->getMappedFile($dataXMLFilename);
$sqlWriter = new FileWriter($outFile);
$this->log("Creating SQL from XML data dump file: " . $dataXMLFile->getAbsolutePath());
try {
$dataXmlParser = new XmlToDataSQL($db, $this->getGeneratorConfig(), $this->dbEncoding);
$dataXmlParser->transform($dataXMLFile, $sqlWriter);
} catch (Exception $e) {
throw new BuildException("Exception parsing data XML: " . $e->getMessage(), $x);
}
// Place the generated SQL file(s)
$p = new Properties();
if ($this->getSqlDbMap()->exists()) {
$p->load($this->getSqlDbMap());
}
$p->setProperty($outFile->getName(), $db->getName());
$p->store($this->getSqlDbMap(), "Sqlfile -> Database map");
} else {
$this->log("File '" . $dataXMLFile->getAbsolutePath() . "' in datadbmap does not exist, so skipping it.", Project::MSG_WARN);
}
}
// foreach data xml file
}