本文整理汇总了PHP中ClassTools类的典型用法代码示例。如果您正苦于以下问题:PHP ClassTools类的具体用法?PHP ClassTools怎么用?PHP ClassTools使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ClassTools类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPages
protected function getPages()
{
if (!$this->using_pages || $this->count_items <= $this->items_on_page) {
return;
}
// aktualna strona kategorii
$page = ClassTools::getValue('page') ? ClassTools::getValue('page') . '/' : '';
echo '<div class="sew-pages clearfix"><ul class="clearfix">';
for ($i = 1; $i <= ceil($this->count_items / $this->items_on_page); $i++) {
echo '<li><a href="/' . $this->controller_name . '/' . $page . 'strona/' . $i . '" class="btn btn-' . ($this->current_page == $i ? 'default" disabled="disabled"' : 'default"') . '>' . $i . '</a></li>';
}
echo '</ul></div>';
return;
}
示例2: getParentClassName
/**
* Returns classpath to parent class.
* @return string
*/
protected function getParentClassName()
{
$ancestorClassName = ClassTools::classname($this->getChild()->getAncestor());
if ($this->getDatabase()->hasTableByPhpName($ancestorClassName)) {
return $this->getNewStubQueryBuilder($this->getDatabase()->getTableByPhpName($ancestorClassName))->getClassname();
} else {
// find the inheritance for the parent class
foreach ($this->getTable()->getChildrenColumn()->getChildren() as $child) {
if ($child->getClassName() == $ancestorClassName) {
return $this->getNewStubQueryInheritanceBuilder($child)->getClassname();
}
}
}
}
示例3: validateModel
/**
* Validates the current table to make sure that it won't
* result in generated code that will not parse.
*
* This method may emit warnings for code which may cause problems
* and will throw exceptions for errors that will definitely cause
* problems.
*/
protected function validateModel()
{
parent::validateModel();
$table = $this->getTable();
// Check to see if any of the column constants are PHP reserved words.
$colConstants = array();
foreach ($table->getColumns() as $col) {
$colConstants[] = $this->getColumnName($col);
}
$reservedConstants = array_map('strtoupper', ClassTools::getPhpReservedWords());
$intersect = array_intersect($reservedConstants, $colConstants);
if (!empty($intersect)) {
throw new EngineException("One or more of your column names for [" . $table->getName() . "] table conflict with a PHP reserved word (" . implode(", ", $intersect) . ")");
}
}
示例4: generateWhereList
protected static function generateWhereList($controller, $prefix = false)
{
if (!($session_search = self::getSearchSession($controller))) {
return false;
}
$prefix = $prefix ? $prefix . '.' : '';
$first = true;
foreach ($session_search as $key => $val) {
$val = ClassTools::pSQL($val);
if ($first) {
$first = false;
$search = "{$prefix}`{$key}` LIKE '%{$val}%'";
} else {
$search .= " AND {$prefix}`{$key}` LIKE '%{$val}%'";
}
}
return $search;
}
示例5: addClassClose
protected function addClassClose(&$script)
{
parent::addClassClose($script);
$behavior_file_name = 'Base' . $this->getTable()->getPhpName() . 'Behaviors';
$behavior_file_path = ClassTools::getFilePath($this->getStubObjectBuilder()->getPackage() . '.om', $behavior_file_name);
$absolute_behavior_file_path = sfConfig::get('sf_root_dir') . '/' . $behavior_file_path;
if (file_exists($absolute_behavior_file_path)) {
unlink($absolute_behavior_file_path);
}
$behaviors = $this->getTable()->getAttribute('behaviors');
if ($behaviors) {
file_put_contents($absolute_behavior_file_path, sprintf("<?php\nsfPropelBehavior::add('%s', %s);\n", $this->getTable()->getPhpName(), var_export(unserialize($behaviors), true)));
$behavior_include_script = <<<EOF
if (sfProjectConfiguration::getActive() instanceof sfApplicationConfiguration)
{
include_once '%s';
}
EOF;
$script .= sprintf($behavior_include_script, $behavior_file_path);
}
}
示例6: search
protected function search()
{
if (!$this->checkSearchDefinition()) {
return;
}
$ClassModel = new ClassModel();
$session_old = false;
$session = array();
$class = $this->search_definition['class'];
$definition = $class::$definition['fields'];
if (isset($_SESSION['search'][$this->search_definition['controller']])) {
$session_old = $_SESSION['search'][$this->search_definition['controller']];
}
foreach ($_POST as $key => $val) {
if ($key == 'form_action_search') {
continue;
}
$value = ClassTools::getValue($key) !== false && ClassTools::getValue($key) != '' ? ClassTools::getValue($key) : false;
if ($value === false) {
continue;
}
if (isset($this->search_definition['form'][$key])) {
if (isset($definition[$key]) && isset($definition[$key]['validate'])) {
foreach ($definition[$key]['validate'] as $validate_method) {
$value = $ClassModel->validByMethod($validate_method, $value, $definition[$key]['name'], $key);
if ($ClassModel->errors && count($ClassModel->errors) > 0) {
$this->alerts['danger search'][] = $ClassModel->errors['0'];
$ClassModel->errors = array();
} else {
$session[$key] = $value;
}
}
} else {
$session[$key] = $value;
}
}
}
$_SESSION['search'][$this->search_definition['controller']] = $session;
return;
}
示例7: edit
protected function edit()
{
// ladowanie klasy
$item = new ClassSoldierSchool(ClassTools::getValue('id_school'));
// sprawdza czy klasa zostala poprawnie zaladowana
if (!$item->load_class) {
$this->alerts['danger'] = "Szkoła żołnierza nie istnieje.";
return;
}
$item->name = ClassTools::getValue('form_name');
$item->address = ClassTools::getValue('form_address');
$item->specialization = ClassTools::getValue('form_specialization');
$item->id_academic_degree = ClassTools::getValue('form_academic_degree');
$item->date_start = ClassTools::getValue('form_date_start');
$item->date_end = ClassTools::getValue('form_date_end');
$item->id_soldier = ClassTools::getValue('id_soldier');
$item->id_user = ClassAuth::getCurrentUserId();
// komunikaty bledu
if (!$item->update()) {
$this->alerts['danger'] = $item->errors;
return;
}
// komunikat
$this->alerts['success'] = "Poprawnie zaktualizowano szkolę żołnierza: <b>{$item->name}</b>";
// czyszczeie zmiennych wyswietlania
$this->tpl_values = '';
$_POST = array();
return;
}
示例8: getClassFilePath
public function getClassFilePath()
{
return ClassTools::getFilePath('lib.model.om', $this->getClassname());
}
示例9: generateRandomPasswordLinkKey
public static function generateRandomPasswordLinkKey()
{
return ClassTools::generateRandomPasswd(60, array('1', '2', '3'));
}
示例10: detach
protected function detach()
{
// ladowanie klasy
$item = new ClassSoldier2Mission(ClassTools::getValue('id_soldier2missions'));
// sprawdza czy klasa zostala poprawnie zaladowana
if (!$item->load_class) {
$this->alerts['danger'] = "Misja żołnierza nie istnieje.";
return;
}
$item->id_soldier = ClassTools::getValue('id_soldier');
$item->id_mission = ClassTools::getValue('id_mission');
$item->description_detach = ClassTools::getValue('form_description_detach');
$item->date_mission_detach = ClassTools::getValue('form_date');
$item->id_user = ClassAuth::getCurrentUserId();
// komunikaty bledu
if (!$item->detach()) {
$this->alerts['danger'] = $item->errors;
return;
}
// komunikat
$this->alerts['success'] = "Poprawnie oddelegowano żołnierza z misji.";
// czyszczeie zmiennych wyswietlania
$this->tpl_values = '';
$_POST = array();
return;
}
示例11: getClassMap
/**
* Lists data model classes and builds an associative array className => classPath
* To be used for autoloading
* @return array
*/
protected function getClassMap()
{
$phpconfClassmap = array();
$generatorConfig = $this->getGeneratorConfig();
foreach ($this->getDataModels() as $dataModel) {
foreach ($dataModel->getDatabases() as $database) {
$classMap = array();
foreach ($database->getTables() as $table) {
if (!$table->isForReferenceOnly()) {
// -----------------------------------------------------
// Add TableMap class,
// Peer, Object & Query stub classes,
// and Peer, Object & Query base classes
// -----------------------------------------------------
// (this code is based on PropelOMTask)
foreach (array('tablemap', 'peerstub', 'objectstub', 'querystub', 'peer', 'object', 'query') as $target) {
$builder = $generatorConfig->getConfiguredBuilder($table, $target);
$this->log("Adding class mapping: " . $builder->getClassname() . ' => ' . $builder->getClassFilePath());
$classMap[$builder->getClassname()] = $builder->getClassFilePath();
}
// -----------------------------------------------------
// Add children classes for object and query,
// as well as base child query,
// for single tabel inheritance tables.
// -----------------------------------------------------
if ($col = $table->getChildrenColumn()) {
if ($col->isEnumeratedClasses()) {
foreach ($col->getChildren() as $child) {
foreach (array('objectmultiextend', 'queryinheritance', 'queryinheritancestub') as $target) {
$builder = $generatorConfig->getConfiguredBuilder($table, $target);
$builder->setChild($child);
$this->log("Adding class mapping: " . $builder->getClassname() . ' => ' . $builder->getClassFilePath());
$classMap[$builder->getClassname()] = $builder->getClassFilePath();
}
}
}
}
// -----------------------------------------------------
// Add base classes for alias tables (undocumented)
// -----------------------------------------------------
$baseClass = $table->getBaseClass();
if ($baseClass !== null) {
$className = ClassTools::classname($baseClass);
if (!isset($classMap[$className])) {
$classPath = ClassTools::getFilePath($baseClass);
$this->log('Adding class mapping: ' . $className . ' => ' . $classPath);
$classMap[$className] = $classPath;
}
}
$basePeer = $table->getBasePeer();
if ($basePeer !== null) {
$className = ClassTools::classname($basePeer);
if (!isset($classMap[$className])) {
$classPath = ClassTools::getFilePath($basePeer);
$this->log('Adding class mapping: ' . $className . ' => ' . $classPath);
$classMap[$className] = $classPath;
}
}
// ----------------------------------------------
// Add classes for interface
// ----------------------------------------------
if ($table->getInterface()) {
$builder = $generatorConfig->getConfiguredBuilder($table, 'interface');
$this->log("Adding class mapping: " . $builder->getClassname() . ' => ' . $builder->getClassFilePath());
$classMap[$builder->getClassname()] = $builder->getClassFilePath();
}
// ----------------------------------------------
// Add classes from old treeMode implementations
// ----------------------------------------------
if ($table->treeMode() == 'MaterializedPath') {
foreach (array('nodepeerstub', 'nodestub', 'nodepeer', 'node') as $target) {
$builder = $generatorConfig->getConfiguredBuilder($table, $target);
$this->log("Adding class mapping: " . $builder->getClassname() . ' => ' . $builder->getClassFilePath());
$classMap[$builder->getClassname()] = $builder->getClassFilePath();
}
}
if ($table->treeMode() == 'NestedSet') {
foreach (array('nestedset', 'nestedsetpeer') as $target) {
$builder = $generatorConfig->getConfiguredBuilder($table, $target);
$this->log("Adding class mapping: " . $builder->getClassname() . ' => ' . $builder->getClassFilePath());
$classMap[$builder->getClassname()] = $builder->getClassFilePath();
}
}
}
// if (!$table->isReferenceOnly())
}
$phpconfClassmap = array_merge($phpconfClassmap, $classMap);
}
}
return $phpconfClassmap;
}
示例12: main
public function main()
{
// check to make sure task received all correct params
$this->validate();
$basepath = $this->getOutputDirectory();
// Get new Capsule context
$generator = $this->createContext();
$generator->put("basepath", $basepath);
// make available to other templates
$targetPlatform = $this->getTargetPlatform();
// convenience for embedding in strings below
// we need some values that were loaded into the template context
$basePrefix = $generator->get('basePrefix');
$project = $generator->get('project');
foreach ($this->getDataModels() as $dataModel) {
$this->log("Processing Datamodel : " . $dataModel->getName());
foreach ($dataModel->getDatabases() as $database) {
$this->log(" - processing database : " . $database->getName());
$generator->put("platform", $database->getPlatform());
foreach ($database->getTables() as $table) {
if (!$table->isForReferenceOnly()) {
if ($table->getPackage()) {
$package = $table->getPackage();
} else {
$package = $this->targetPackage;
}
$pkbase = "{$package}.om";
$pkpeer = "{$package}";
$pkmap = "{$package}.map";
// make these available
$generator->put("package", $package);
$generator->put("pkbase", $pkbase);
//$generator->put("pkpeer", $pkpeer); -- we're not using this yet
$generator->put("pkmap", $pkmap);
foreach (array($pkpeer, $pkmap, $pkbase) as $pk) {
$path = strtr($pk, '.', '/');
$f = new PhingFile($this->getOutputDirectory(), $path);
if (!$f->exists()) {
if (!$f->mkdirs()) {
throw new Exception("Error creating directories: " . $f->getPath());
}
}
}
// for each package
$this->log("\t+ " . $table->getName());
$generator->put("table", $table);
// Create the Base Peer class
$this->log("\t\t-> " . $basePrefix . $table->getPhpName() . "Peer");
$path = ClassTools::getFilePath($pkbase, $basePrefix . $table->getPhpName() . "Peer");
$generator->parse("om/{$targetPlatform}/Peer.tpl", $path);
// Create the Base object class
$this->log("\t\t-> " . $basePrefix . $table->getPhpName());
$path = ClassTools::getFilePath($pkbase, $basePrefix . $table->getPhpName());
$generator->parse("om/{$targetPlatform}/Object.tpl", $path);
if ($table->isTree()) {
// Create the Base NodePeer class
$this->log("\t\t-> " . $basePrefix . $table->getPhpName() . "NodePeer");
$path = ClassTools::getFilePath($pkbase, $basePrefix . $table->getPhpName() . "NodePeer");
$generator->parse("om/{$targetPlatform}/NodePeer.tpl", $path);
// Create the Base Node class if the table is a tree
$this->log("\t\t-> " . $basePrefix . $table->getPhpName() . "Node");
$path = ClassTools::getFilePath($pkbase, $basePrefix . $table->getPhpName() . "Node");
$generator->parse("om/{$targetPlatform}/Node.tpl", $path);
}
// Create MapBuilder class if this table is not an alias
if (!$table->isAlias()) {
$this->log("\t\t-> " . $table->getPhpName() . "MapBuilder");
$path = ClassTools::getFilePath($pkmap, $table->getPhpName() . "MapBuilder");
$generator->parse("om/{$targetPlatform}/MapBuilder.tpl", $path);
}
// if !$table->isAlias()
// Create [empty] stub Peer class if it does not already exist
$path = ClassTools::getFilePath($package, $table->getPhpName() . "Peer");
$_f = new PhingFile($basepath, $path);
if (!$_f->exists()) {
$this->log("\t\t-> " . $table->getPhpName() . "Peer");
$generator->parse("om/{$targetPlatform}/ExtensionPeer.tpl", $path);
} else {
$this->log("\t\t-> (exists) " . $table->getPhpName() . "Peer");
}
// Create [empty] stub object class if it does not already exist
$path = ClassTools::getFilePath($package, $table->getPhpName());
$_f = new PhingFile($basepath, $path);
if (!$_f->exists()) {
$this->log("\t\t-> " . $table->getPhpName());
$generator->parse("om/{$targetPlatform}/ExtensionObject.tpl", $path);
} else {
$this->log("\t\t-> (exists) " . $table->getPhpName());
}
if ($table->isTree()) {
// Create [empty] stub Node Peer class if it does not already exist
$path = ClassTools::getFilePath($package, $table->getPhpName() . "NodePeer");
$_f = new PhingFile($basepath, $path);
if (!$_f->exists()) {
$this->log("\t\t-> " . $table->getPhpName() . "NodePeer");
$generator->parse("om/{$targetPlatform}/ExtensionNodePeer.tpl", $path);
} else {
$this->log("\t\t-> (exists) " . $table->getPhpName() . "NodePeer");
}
// Create [empty] stub Node class if it does not already exist
//.........这里部分代码省略.........
示例13: addClassOpen
/**
* Adds class phpdoc comment and openning of class.
* @param string &$script The script will be modified in this method.
*/
protected function addClassOpen(&$script)
{
$table = $this->getTable();
$tableName = $table->getName();
$tableDesc = $table->getDescription();
$interface = $this->getInterface();
$script .= "\r\n/**\r\n * Base class that represents a row from the '{$tableName}' table.\r\n *\r\n * {$tableDesc}\r\n *";
if ($this->getBuildProperty('addTimeStamp')) {
$now = strftime('%c');
$script .= "\r\n * This class was autogenerated by Propel " . $this->getBuildProperty('version') . " on:\r\n *\r\n * {$now}\r\n *";
}
$script .= "\r\n * @package " . $this->getPackage() . "\r\n */\r\nabstract class " . $this->getClassname() . " extends " . ClassTools::classname($this->getBaseClass()) . " ";
$interface = ClassTools::getInterface($table);
if ($interface) {
$script .= " implements " . ClassTools::classname($interface);
}
$script .= " {\r\n\r\n";
}
示例14: addClassClose
protected function addClassClose(&$script)
{
parent::addClassClose($script);
$behaviors = $this->getTable()->getAttribute('behaviors');
if ($behaviors) {
$behavior_file_name = 'Base' . $this->getTable()->getPhpName() . 'Behaviors';
$behavior_file_path = ClassTools::getFilePath($this->getStubObjectBuilder()->getPackage() . '.om', $behavior_file_name);
$script .= sprintf("\ninclude_once '%s';\n", $behavior_file_path);
}
}
示例15: main
/**
* The main method does the work of the task.
*/
public function main()
{
// Check to make sure the input and output files were specified and that the input file exists.
if (!$this->xmlConfFile || !$this->xmlConfFile->exists()) {
throw new BuildException("No valid xmlConfFile specified.", $this->getLocation());
}
if (!$this->outputFile) {
throw new BuildException("No outputFile specified.", $this->getLocation());
}
if (!$this->outputClassmapFile) {
// We'll create a default one for BC
$this->outputClassmapFile = 'classmap-' . $this->outputFile;
}
// Create a PHP array from the XML file
$xmlDom = new DOMDocument();
$xmlDom->load($this->xmlConfFile->getAbsolutePath());
$xml = simplexml_load_string($xmlDom->saveXML());
$phpconf = self::simpleXmlToArray($xml);
$phpconfClassmap = array();
// $this->log(var_export($phpconf,true));
// Create a map of all PHP classes and their filepaths for this data model
$generatorConfig = $this->getGeneratorConfig();
foreach ($this->getDataModels() as $dataModel) {
foreach ($dataModel->getDatabases() as $database) {
$classMap = array();
// $this->log("Processing class mappings in database: " . $database->getName());
//print the tables
foreach ($database->getTables() as $table) {
if (!$table->isForReferenceOnly()) {
// $this->log("\t+ " . $table->getName());
// Classes that I'm assuming do not need to be mapped (because they will be required by subclasses):
// - base peer and object classes
// - interfaces
// - base node peer and object classes
// -----------------------------------------------------------------------------------------
// Add Peer & Object stub classes and MapBuilder classes
// -----------------------------------------------------------------------------------------
// (this code is based on PropelOMTask)
foreach (array('mapbuilder', 'peerstub', 'objectstub') as $target) {
$builder = $generatorConfig->getConfiguredBuilder($table, $target);
$this->log("Adding class mapping: " . $builder->getClassname() . ' => ' . $builder->getClassFilePath());
$classMap[$builder->getClassname()] = $builder->getClassFilePath();
}
if ($table->getChildrenColumn()) {
$col = $table->getChildrenColumn();
if ($col->isEnumeratedClasses()) {
foreach ($col->getChildren() as $child) {
$builder = $generatorConfig->getConfiguredBuilder($table, 'objectmultiextend');
$builder->setChild($child);
$this->log("Adding class mapping: " . $builder->getClassname() . ' => ' . $builder->getClassFilePath());
$classMap[$builder->getClassname()] = $builder->getClassFilePath();
}
}
}
$baseClass = $table->getBaseClass();
if ($baseClass !== null) {
$className = ClassTools::classname($baseClass);
if (!isset($classMap[$className])) {
$classPath = ClassTools::getFilePath($baseClass);
$this->log('Adding class mapping: ' . $className . ' => ' . $classPath);
$classMap[$className] = $classPath;
}
}
$basePeer = $table->getBasePeer();
if ($basePeer !== null) {
$className = ClassTools::classname($basePeer);
if (!isset($classMap[$className])) {
$classPath = ClassTools::getFilePath($basePeer);
$this->log('Adding class mapping: ' . $className . ' => ' . $classPath);
$classMap[$className] = $classPath;
}
}
// -----------------------------------------------------------------------------------------
// Create tree Node classes
// -----------------------------------------------------------------------------------------
if ('MaterializedPath' == $table->treeMode()) {
foreach (array('nodepeerstub', 'nodestub') as $target) {
$builder = $generatorConfig->getConfiguredBuilder($table, $target);
$this->log("Adding class mapping: " . $builder->getClassname() . ' => ' . $builder->getClassFilePath());
$classMap[$builder->getClassname()] = $builder->getClassFilePath();
}
}
// if Table->treeMode() == 'MaterializedPath'
}
// if (!$table->isReferenceOnly())
}
$phpconfClassmap['propel']['datasources'][$database->getName()]['classes'] = $classMap;
}
}
// $phpconf['propel']['classes'] = $classMap;
$phpconf['propel']['generator_version'] = $this->getGeneratorConfig()->getBuildProperty('version');
// Write resulting PHP data to output file:
$outfile = new PhingFile($this->outputDirectory, $this->outputFile);
$output = '<' . '?' . "php\n";
$output .= "// This file generated by Propel " . $phpconf['propel']['generator_version'] . " convert-props target" . ($this->getGeneratorConfig()->getBuildProperty('addTimestamp') ? " on " . strftime("%c") : '') . "\n";
$output .= "// from XML runtime conf file " . $this->xmlConfFile->getPath() . "\n";
$output .= "return array_merge_recursive(";
//.........这里部分代码省略.........