/** * This method exists only for BC */ public static function arrayKeyCamelize(array $array) { foreach ($array as $key => $value) { unset($array[$key]); $array[sfInflector::classify($key)] = $value; } return $array; }
public function getAttachmentsByType($type) { if (in_array($type, $this->_options['types'])) { return $this->getAttachmentsByTypeQuery($type)->execute(); } $table = strtolower($type) == 'other' ? 'Attachment' : sfInflector::classify($type . '_attachment'); return new Doctrine_Collection($table); }
public function preExecute() { $this->getResponse()->setHttpHeader('Content-Type', 'application/atom+xml'); $request = sfContext::getInstance()->getRequest(); $model = $request->getParameter('model'); $className = 'opAPI' . sfInflector::classify($model); $this->forward404Unless(class_exists($className)); $params = $request->getParameterHolder()->getAll(); $this->api = new $className($params, $this->getRoute()); if ($this->getUser()->hasAttribute('member_id')) { $this->api->setMemberId($this->getUser()->getAttribute('member_id')); } $this->dispatcher->notify(new sfEvent($this, 'feeds_action.pre_execute')); }
public function addField($space, $name, $options = array()) { $type = isset($options['type']) ? strtolower($options['type']) : 'text'; $class = sfInflector::classify($type) . 'ConfigField'; if (class_exists($class)) { if (!isset($options['options']['label'])) { $options['options']['label'] = sfInflector::humanize($name); } $this->_fields[$space][$name] = new $class($options['options']); $this->widgetSchema[$space][$name] = $this->_fields[$space][$name]->getWidget(); $this->validatorSchema[$space][$name] = $this->_fields[$space][$name]->getValidator(); } else { throw new InvalidArgumentException('This field type doesn\'t, you need to create a classe named ' . $class); } }
/** * Creates a table node * * @param object $table The table * @return object The table node instance */ protected function createTableNode($table) { $this->log("Processing table: " . $table->toString()); $node = $this->doc->createElement("table"); $node->setAttribute("name", $table->getName()); $tablePrefix = $this->getProject()->getProperty('propel.builder.tablePrefix'); if ($this->isSamePhpName()) { $node->setAttribute("phpName", $table->getName()); } elseif ($tablePrefix) { $prefix = '/^' . $tablePrefix . '/im'; $tmp = sfInflector::classify(preg_replace($prefix, '', $table->getName())); $node->setAttribute("phpName", $tmp); } if ($vendorNode = $this->createVendorInfoNode($table->getVendorSpecificInfo())) { $node->appendChild($vendorNode); } // Create and add column nodes, register column validators $columns = $table->getColumns(); foreach($columns as $column) { $columnNode = $this->createColumnNode($column); $node->appendChild($columnNode); $this->registerValidatorsForColumn($column); if ($column->isAutoIncrement()) { $idMethod = 'native'; } } if (isset($idMethod)) { $node->setAttribute("idMethod", $idMethod); } // Create and add foreign key nodes. $foreignKeys = $table->getForeignKeys(); foreach($foreignKeys as $foreignKey) { $foreignKeyNode = $this->createForeignKeyNode($foreignKey); $node->appendChild($foreignKeyNode); } // Create and add index nodes. $indices = $table->getIndices(); foreach($indices as $index) { $indexNode = $this->createIndexNode($index); $node->appendChild($indexNode); } // add an id-method-parameter if we have a sequence that matches table_colname_seq // // $pkey = $table->getPrimaryKey(); if ($pkey) { $cols = $pkey->getColumns(); if (count($cols) === 1) { $col = array_shift($cols); if ($col->isAutoIncrement()) { $seq_name = $table->getName().'_'.$col->getName().'_seq'; if ($table->getDatabase()->isSequence($seq_name)) { $idMethodParameterNode = $this->doc->createElement("id-method-parameter"); $idMethodParameterNode->setAttribute("value", $seq_name); $node->appendChild($idMethodParameterNode); } } } } // Create and add validator and rule nodes. $nodes = array(); $tableName = $table->getName(); if (isset($this->validatorInfos[$tableName])) { foreach ($this->validatorInfos[$tableName] as $colName => $rules) { $column = $table->getColumn($colName); $colName = $column->getName(); foreach ($rules as $rule) { if (!isset($nodes[$colName])) { $nodes[$colName] = $this->createValidator($column, $rule['type']); $node->appendChild($nodes[$colName]); } $ruleNode = $this->createRuleNode($column, $rule); $nodes[$colName]->appendChild($ruleNode); } } } return $node; }
/** * Registers a smarty helper function * * @var array * @var Smarty_Internal_TemplateCompilerBase * @return string $phpcode */ public function compilerFunctionUseSmartyHelper(array $args, Smarty_Internal_TemplateCompilerBase $compiler = null, $compiler_class = 'Smarty_Internal_SmartyTemplateCompiler') { $compiler === null && ($compiler = new $compiler_class(null, null, $this->smarty)); // PARSE THE ARGUMENTS eval('$helpers = ' . $args['helper'] . ';'); if (!is_array($helpers)) { $helpers = explode(',', trim($helpers)); $helpers = array_map('trim', $helpers); } $module_name = $this->getContext()->getModuleName(); $helper_dirs = $this->getSmartyHelperDirs($module_name); $php = ''; foreach ($helpers as $helper) { $helper_class_name = 'HelperSmarty' . sfInflector::classify($helper); $helper_class_filename = sfInflector::classify($helper) . '.class.php'; foreach ($helper_dirs as $helper_dir) { $path_to_class = $helper_dir . '/' . $helper_class_filename; if (file_exists($path_to_class)) { $php .= '<?php require_once(\'' . $path_to_class . '\');?>'; if (count($class_methods = get_class_methods($helper_class_name)) < 1) { continue; } $class_methods = array_filter($class_methods, create_function('$helper', "return (strpos(\$helper, '_') !== 0) || strpos(\$helper, '__') === 0;")); if (count($class_methods) < 1) { continue; } // $php .= '<?php $___smarty_factory=sfSmartyFactory::getInstance();'; foreach ($class_methods as $class_method) { // SMARTY MAGIC COMPILES THE TEMPLATE CORRECTLY ... IF THE CLASS // EXISTS AT COMPILE TIME $this->getSmarty()->register->templateFunction($class_method, array($helper_class_name, $class_method)); //$php .= '$___smarty_factory->registerSmartyHelperFunction(\'' . $class_method . '\', array(\'' . $helper_class_name . '\', \'' . $class_method . '\'), $_smarty_tpl->smarty);'; } // $php .= '? >'; } } } return $php; }
/** * Purge tasks. */ protected function purge($task) { $method = 'purge' . sfInflector::classify(sfConfig::get('sf_orm')); return $this->{$method}($task); }
/** * Check if a task with was already run today. */ protected function countDayBatch($task) { $method = 'count' . sfInflector::classify(sfConfig::get('sf_orm')) . 'DayBatch'; return $this->{$method}($task); }
/** * run_doctrine_load_nested_set * * @param mixed $task * @param mixed $args * @access public * @return void */ function run_doctrine_load_nested_set($task, $args) { if (!count($args)) { throw new Exception('You must provide the app.'); } $app = $args[0]; if (!is_dir(sfConfig::get('sf_app_dir') . DIRECTORY_SEPARATOR . $app)) { throw new Exception('The app "' . $app . '" does not exist.'); } if (!isset($args[1])) { throw new Exception('You must provide a filename.'); } $filename = $args[1]; $env = empty($args[2]) ? 'dev' : $args[2]; _load_application_environment($app, $env); $model = sfInflector::classify($args[1]); $ymlName = sfInflector::tableize($args[1]); $ymlPath = sfConfig::get('sf_data_dir') . '/' . $ymlName . '.yml'; pake_echo_action('doctrine', 'loading nested set data for ' . $model); pake_echo_action('doctrine', 'loading ' . $ymlPath); $nestedSetData = sfYaml::load($ymlPath); _doctrine_load_nested_set_data($model, $nestedSetData); }