本文整理汇总了PHP中OMBuilder::build方法的典型用法代码示例。如果您正苦于以下问题:PHP OMBuilder::build方法的具体用法?PHP OMBuilder::build怎么用?PHP OMBuilder::build使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OMBuilder
的用法示例。
在下文中一共展示了OMBuilder::build方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: build
/**
* Uses a builder class to create the output class.
* This method assumes that the DataModelBuilder class has been initialized with the build properties.
*
* @param OMBuilder $builder
* @param boolean $overwrite Whether to overwrite existing files with te new ones (default is YES).
*
* @todo -cPropelOMTask Consider refactoring build() method into AbstractPropelDataModelTask (would need to be more generic).
* @return int
*/
protected function build(OMBuilder $builder, $overwrite = true)
{
$path = $builder->getClassFilePath();
$this->ensureDirExists(dirname($path));
$_f = new PhingFile($this->getOutputDirectory(), $path);
// skip files already created once
if ($_f->exists() && !$overwrite) {
$this->log("\t-> (exists) " . $builder->getClassFilePath(), Project::MSG_VERBOSE);
return 0;
}
$script = $builder->build();
foreach ($builder->getWarnings() as $warning) {
$this->log($warning, Project::MSG_WARN);
}
// skip unchanged files
if ($_f->exists() && $script == $_f->contents()) {
$this->log("\t-> (unchanged) " . $builder->getClassFilePath(), Project::MSG_VERBOSE);
return 0;
}
// write / overwrite new / changed files
$action = $_f->exists() ? 'Updating' : 'Creating';
$this->log(sprintf("\t-> %s %s (table: %s, builder: %s)", $action, $builder->getClassFilePath(), $builder->getTable()->getName(), get_class($builder)));
file_put_contents($_f->getAbsolutePath(), $script);
return 1;
}
示例2: build
public function build()
{
$phpDir = $this->getBuildProperty('phpDir');
$fassadePath = $phpDir . DIRECTORY_SEPARATOR . $this->getClassFilePath();
if (in_array($this->getBuildProperty('behaviorProviderCachefile'), array('true', 'on', 'yes', '1'))) {
$outputDir = $this->getBuildProperty('outputDir');
$cacheFile = $outputDir . DIRECTORY_SEPARATOR . 'providerCache.json';
$className = $this->getClassname();
$package = $this->getPackage();
$nameSpace = $this->getNamespace();
// Check if a special constant has been defined - if not, this is the first run of
// and Provider build, so we need to clear the cache.
if (!defined('BEHAVIOR_PROVIDER_FASSADE_CACHE_CLEARED') || true != BEHAVIOR_PROVIDER_FASSADE_CACHE_CLEARED) {
if (!file_exists($outputDir)) {
mkdir($outputDir);
}
if (file_exists($cacheFile)) {
unlink($cacheFile);
}
touch($cacheFile);
define('BEHAVIOR_PROVIDER_FASSADE_CACHE_CLEARED', true);
}
$cache = (array) json_decode(file_get_contents($cacheFile), true);
if (JSON_ERROR_NONE == json_last_error()) {
$cache[] = array('package' => $package, 'namespace' => $nameSpace, 'modelName' => str_replace('Provider', '', $className), 'providerName' => $className);
file_put_contents($cacheFile, json_encode($cache));
}
}
if (file_exists($fassadePath)) {
// Fassade already exists.
// It is not possible to just stop the process here and continue with the next file,
// so we return the source string just as it is in the current file, so it does not get overwritten
$sourceString = file_get_contents($fassadePath);
} else {
// Fassade does not exist yet, so we build it
$sourceString = parent::build();
}
return $sourceString;
}