本文整理汇总了PHP中sfInflector类的典型用法代码示例。如果您正苦于以下问题:PHP sfInflector类的具体用法?PHP sfInflector怎么用?PHP sfInflector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了sfInflector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: populateWithFacebook
public function populateWithFacebook(m14tFacebook $fb, $force = true)
{
$sfGuardUser = $this->getInvoker();
foreach ($this->_options['fields'] as $fb_key => $sfg_key) {
$func = 'get' . sfInflector::camelize($fb_key);
switch ($fb_key) {
case 'location':
case 'hometown':
case 'languages':
case 'education':
$sfGuardUser->{$sfg_key}($fb->{$func}(), $force);
break;
case 'birthday':
if ($force || "" == $sfGuardUser[$sfg_key]) {
$sfGuardUser[$sfg_key] = date('Y-m-d', strtotime($fb->{$func}()));
}
break;
default:
if ($force || "" == $sfGuardUser[$sfg_key]) {
$sfGuardUser[$sfg_key] = $fb->{$func}();
}
break;
}
}
}
示例2: addFields
public function addFields()
{
// Information object attribute (db column) to perform s/r on
$map = new InformationObjectI18nTableMap();
foreach ($map->getColumns() as $col) {
if (!$col->isPrimaryKey() && !$col->isForeignKey()) {
$col_name = $col->getPhpName();
$choices[$col_name] = sfInflector::humanize(sfInflector::underscore($col_name));
}
}
$this->form->setValidator('column', new sfValidatorString());
$this->form->setWidget('column', new sfWidgetFormSelect(array('choices' => $choices), array('style' => 'width: auto')));
// Search-replace values
$this->form->setValidator('pattern', new sfValidatorString());
$this->form->setWidget('pattern', new sfWidgetFormInput());
$this->form->setValidator('replacement', new sfValidatorString());
$this->form->setWidget('replacement', new sfWidgetFormInput());
$this->form->setValidator('caseSensitive', new sfValidatorBoolean());
$this->form->setWidget('caseSensitive', new sfWidgetFormInputCheckbox());
$this->form->setValidator('allowRegex', new sfValidatorBoolean());
$this->form->setWidget('allowRegex', new sfWidgetFormInputCheckbox());
if ($this->request->isMethod('post') && !isset($this->request->confirm) && !empty($this->request->pattern) && !empty($this->request->replacement)) {
$this->form->setValidator('confirm', new sfValidatorBoolean());
$this->form->setWidget('confirm', new sfWidgetFormInputHidden(array(), array('value' => true)));
}
}
示例3: getLinkToAction
public function getLinkToAction($actionName, $params, $pk_link = false)
{
$options = isset($params['params']) && !is_array($params['params']) ? sfToolkit::stringToArray($params['params']) : array();
// default values
if ($actionName[0] == '_') {
$actionName = substr($actionName, 1);
$name = $actionName;
//$icon = sfConfig::get('sf_admin_web_dir').'/images/'.$actionName.'_icon.png';
$action = $actionName;
if ($actionName == 'delete') {
$options['post'] = true;
if (!isset($options['confirm'])) {
$options['confirm'] = 'Are you sure?';
}
}
} else {
$name = isset($params['name']) ? $params['name'] : $actionName;
//$icon = isset($params['icon']) ? sfToolkit::replaceConstants($params['icon']) : sfConfig::get('sf_admin_web_dir').'/images/default_icon.png';
$action = isset($params['action']) ? $params['action'] : 'List' . sfInflector::camelize($actionName);
}
$url_params = $pk_link ? '?' . $this->getPrimaryKeyUrlParams() : '\'';
$phpOptions = var_export($options, true);
// little hack
$phpOptions = preg_replace("/'confirm' => '(.+?)(?<!\\\\)'/", '\'confirm\' => __(\'$1\')', $phpOptions);
return '<li class="sf_admin_action_' . sfInflector::underscore($name) . '">[?php echo link_to(__(\'' . $params['label'] . '\'), \'' . $this->getModuleName() . '/' . $action . $url_params . ($options ? ', ' . $phpOptions : '') . ') ?]</li>' . "\n";
}
示例4: __call
/**
* magic method to use listen to some event
*
* @param string $methodName
* @param array $args
*/
public function __call($methodName, $args)
{
if (0 === strpos($methodName, 'listenTo')) {
$name = sfInflector::underscore(substr($methodName, 8));
if (!in_array($name, array_keys(self::getPointConfig()))) {
throw new BadMethodCallException();
}
if (!(1 === count($args) && $args[0] instanceof sfEvent)) {
throw new InvalidArgumentException();
}
$event = $args[0];
if (0 === strpos($event->getName(), 'op_action.post_execute')) {
if (isset(self::$pointConfig[$name]['check'])) {
$check = self::$pointConfig[$name]['check'];
if ('redirect' === $check && $event->getSubject() instanceof opFrontWebController && sfView::SUCCESS === $event['result'] || $event['result'] === $check) {
$this->pointUp($name);
}
return;
}
$this->pointUp($name);
}
return;
}
throw new BadMethodCallException();
}
示例5: retrieveGadgetsByTypesName
public function retrieveGadgetsByTypesName($typesName)
{
if (isset($this->gadgets[$typesName])) {
return $this->gadgets[$typesName];
}
if (sfConfig::get('op_is_enable_gadget_cache', true)) {
$dir = sfConfig::get('sf_app_cache_dir') . '/config';
$file = $dir . '/' . sfInflector::underscore($typesName) . "_gadgets.php";
if (is_readable($file)) {
$results = unserialize(file_get_contents($file));
$this->gadgets[$typesName] = $results;
return $results;
}
}
$types = $this->getTypes($typesName);
foreach ($types as $type) {
$results[$type] = $this->retrieveByType($type);
}
if (sfConfig::get('op_is_enable_gadget_cache', true)) {
if (!is_dir($dir)) {
@mkdir($dir, 0777, true);
}
file_put_contents($file, serialize($results));
}
$this->gadgets[$typesName] = $results;
return $results;
}
示例6: getObjectsForParameters
protected function getObjectsForParameters($parameters)
{
$this->options['model'] = Doctrine::getTable($this->options['model']);
if (!isset($this->options['method'])) {
$variables = $this->getRealVariables();
switch (count($variables)) {
case 0:
$this->options['method'] = 'findAll';
break;
case 1:
$this->options['method'] = 'findOneBy' . sfInflector::camelize($variables[0]);
$parameters = $parameters[$variables[0]];
break;
default:
$this->options['method'] = 'findByDQL';
$wheres = array();
foreach ($variables as $variable) {
$variable = $this->options['model']->getFieldName($variable);
$wheres[] = $variable . " = '" . $parameters[$variable] . "'";
}
$parameters = implode(' AND ', $wheres);
}
}
return parent::getObjectsForParameters($parameters);
}
示例7: compile
protected function compile()
{
parent::compile();
// ===================================
// = Add for exporting configuration =
// ===================================
$this->configuration['credentials']['export'] = array();
$this->configuration['export'] = array('fields' => array(), 'title' => $this->getExportTitle(), 'actions' => $this->getExportActions() ? $this->getExportActions() : array('_list' => array('action' => 'index', 'label' => 'Back')));
$config = $this->getConfig();
foreach (array_keys($config['default']) as $field) {
$formConfig = array_merge($config['default'][$field], isset($config['form'][$field]) ? $config['form'][$field] : array());
$this->configuration['export']['fields'][$field] = new sfModelGeneratorConfigurationField($field, array_merge(array('label' => sfInflector::humanize(sfInflector::underscore($field))), $config['default'][$field], isset($config['export'][$field]) ? $config['export'][$field] : array()));
}
foreach ($this->getExportDisplay() as $field) {
list($field, $flag) = sfModelGeneratorConfigurationField::splitFieldWithFlag($field);
$this->configuration['export']['fields'][$field] = new sfModelGeneratorConfigurationField($field, array_merge(array('type' => 'Text', 'label' => sfInflector::humanize(sfInflector::underscore($field))), isset($config['default'][$field]) ? $config['default'][$field] : array(), isset($config['export'][$field]) ? $config['export'][$field] : array(), array('flag' => $flag)));
}
// export actions
foreach ($this->configuration['export']['actions'] as $action => $parameters) {
$this->configuration['export']['actions'][$action] = $this->fixActionParameters($action, $parameters);
}
$this->configuration['export']['display'] = array();
foreach ($this->getExportDisplay() as $name) {
list($name, $flag) = sfModelGeneratorConfigurationField::splitFieldWithFlag($name);
if (!isset($this->configuration['export']['fields'][$name])) {
throw new InvalidArgumentException(sprintf('The field "%s" does not exist.', $name));
}
$field = $this->configuration['export']['fields'][$name];
$field->setFlag($flag);
$this->configuration['export']['display'][$name] = $field;
}
}
示例8: execute
/**
* Executes this filter.
*
* @param sfFilterChain $filterChain A sfFilterChain instance
*/
public function execute($filterChain)
{
// disable stateful security checking on signin and secure actions
if (sfConfig::get('sf_login_module') == $this->context->getModuleName() && sfConfig::get('sf_login_action') == $this->context->getActionName() || sfConfig::get('sf_secure_module') == $this->context->getModuleName() && sfConfig::get('sf_secure_action') == $this->context->getActionName()) {
$filterChain->execute();
return;
}
$sf_user = $this->context->getUser();
// retrieve the current action
$action = $this->context->getController()->getActionStack()->getLastEntry()->getActionInstance();
// get the current module and action names
$module_name = sfInflector::camelize($action->getModuleName());
$action_name = sfInflector::camelize($action->getActionName());
// get the object for the current route
$object = $this->getObjectForRoute($action->getRoute());
// i.e.: canIndexDefault
$method = "can{$action_name}{$module_name}";
// if the method exist
if (method_exists($sf_user, $method)) {
// execute it
if (!$sf_user->{$method}($object)) {
$this->forwardToSecureAction();
}
} else {
// get the default policy
$default_policy = $this->getParameter('default_policy', 'allow');
// if the default policy is not 'allow'
if ($default_policy != 'allow') {
$this->forwardToSecureAction();
}
}
$filterChain->execute();
return;
}
示例9: execute
/**
* @see sfTask
*/
protected function execute($arguments = array(), $options = array())
{
/**
* include path to propel generator
*/
sfToolkit::addIncludePath(array(sfConfig::get('sf_propel_path') . '/generator/lib'));
/**
* first check the db connectivity for all connections
*/
$this->logBlock('Checking Db Connectivity', "QUESTION");
if (!$this->createTask('afs:db-connectivity')->run()) {
return;
}
$this->logBlock('Creating specific AppFlower folders', "QUESTION");
$this->createFolders();
$this->logBlock('Setting Symfony project permissions', "QUESTION");
$this->createTask('project:permissions')->run();
$type_method = 'execute' . sfInflector::camelize($options['type']);
if (!method_exists($this, $type_method)) {
throw new sfCommandException("Type method '{$type_method}' not defined.");
}
call_user_func(array($this, $type_method), $arguments, $options);
$this->logBlock('Creating models from current schema', "QUESTION");
$this->createTask('propel:build-model')->run();
$this->logBlock('Creating forms from current schema', "QUESTION");
$this->createTask('propel:build-forms')->run();
$this->logBlock('Setting AppFlower project permissions', "QUESTION");
$this->createTask('afs:fix-perms')->run();
$this->logBlock('Creating AppFlower validator cache', "QUESTION");
$this->createTask('appflower:validator-cache')->run(array('frontend', 'cache', 'yes'));
$this->logBlock('Clearing Symfony cache', "QUESTION");
$this->createTask('cc')->run();
}
示例10: getObjects
public function getObjects($fk = null)
{
if (!$this->_tableMethod) {
$query = Doctrine_Core::getTable($this->_model)->createQuery();
if (is_array($order = $this->_orderBy)) {
$query->addOrderBy($order[0] . ' ' . $order[1]);
}
if ($fk) {
$refColumn = str_replace('get_', '', sfInflector::underscore($this->_refMethod));
$query->addWhere("{$refColumn} = ?", $fk);
}
$objects = $query->execute();
} else {
$tableMethod = $this->_tableMethod;
$results = Doctrine_Core::getTable($this->_model)->{$tableMethod}($fk);
if ($results instanceof Doctrine_Query) {
$objects = $results->execute();
} else {
if ($results instanceof Doctrine_Collection) {
$objects = $results;
} else {
if ($results instanceof Doctrine_Record) {
$objects = new Doctrine_Collection($this->_model);
$objects[] = $results;
} else {
$objects = array();
}
}
}
}
return $objects;
}
示例11: processSave
/**
* Saving changed page information
*
* @return afResponse
* @author Sergey Startsev
*/
protected function processSave()
{
// Getting needed parameters - page, application name, and sure definition
$page_name = pathinfo($this->getParameter('page'), PATHINFO_FILENAME);
$application = $this->getParameter('app');
$definition = $this->getParameter('definition', array());
$module = $this->getParameter('module', self::PAGES_MODULE);
$permissions = new Permissions();
$is_writable = $permissions->isWritable(sfConfig::get('sf_apps_dir') . '/' . $application . '/config/pages/');
if ($is_writable !== true) {
return $is_writable;
}
//idXml is stored inside the portal_state table from appFlowerPlugin
$idXml = "pages/{$page_name}";
$page = afsPageModelHelper::retrieve($page_name, $application);
$is_new = $page->isNew();
$page->setTitle(sfInflector::humanize(sfInflector::underscore($page_name)));
$page->setDefinition($definition);
$saveResponse = $page->save();
$response = afResponseHelper::create();
if ($saveResponse->getParameter(afResponseSuccessDecorator::IDENTIFICATOR)) {
$console = afStudioConsole::getInstance()->execute(array("sf appflower:portal-state-cc {$idXml}", "sf appflower:validator-cache frontend cache yes", 'sf afs:fix-perms'));
return $response->success(true)->content(!$is_new ? sprintf('Page <b>%s</b> has been saved', $page_name) : sprintf('Page <b>%s</b> has been created', $page_name))->console($console);
}
$response->success(false);
if ($saveResponse->hasParameter(afResponseMessageDecorator::IDENTIFICATOR)) {
$response->content($saveResponse->getParameter(afResponseMessageDecorator::IDENTIFICATOR));
}
return $response;
}
示例12: __construct
public function __construct($feed_array = array(), $extensions = array())
{
$version = '1.0';
parent::__construct();
/// we call initialize() later so we don't need to pass feed_array in yet
$encoding = 'UTF-8';
// sensible default
$dom = $this->dom = new DOMDocument($version, $encoding);
$this->setEncoding($encoding);
// needed to avoid trying to set encoding to ''
$this->context = sfContext::getInstance();
$this->plugin_path = realpath(dirname(__FILE__) . '/../');
$prefix = 'sfDomFeedExtension';
$this->extensions = array();
foreach ($extensions as $extension) {
$class_name = $prefix . sfInflector::camelize($extension);
$extension = new $class_name();
if (!$extension instanceof sfDomFeedExtension) {
throw new sfException("{$class_name} is not a sfDomFeedExtension");
}
// unfortunately ^ class_exists() is useless here; it will error instead of exception.
$this->extensions[] = $extension;
}
if ($feed_array) {
$this->initialize($feed_array);
}
if (!$dom->load($this->genTemplatePath(), LIBXML_NOERROR)) {
throw new sfDomFeedException("DOMDocument::load failed");
}
}
示例13: executeGenerate
protected function executeGenerate($arguments = array(), $options = array())
{
// generate module
$tmpDir = sfConfig::get('sf_cache_dir') . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . md5(uniqid(rand(), true));
$generatorManager = new sfGeneratorManager($this->configuration, $tmpDir);
$generatorManager->generate('sfDoctrineGenerator', array('model_class' => $arguments['model'], 'moduleName' => $arguments['module'], 'theme' => $options['theme'], 'non_verbose_templates' => $options['non-verbose-templates'], 'with_show' => $options['with-show'], 'singular' => $options['singular'] ? $options['singular'] : sfInflector::underscore($arguments['model']), 'plural' => $options['plural'] ? $options['plural'] : sfInflector::underscore($arguments['model'] . 's'), 'route_prefix' => $options['route-prefix'], 'with_doctrine_route' => $options['with-doctrine-route'], 'actions_base_class' => $options['actions-base-class']));
$moduleDir = sfConfig::get('sf_app_module_dir') . '/' . $arguments['module'];
// copy our generated module
$this->getFilesystem()->mirror($tmpDir . DIRECTORY_SEPARATOR . 'auto' . ucfirst($arguments['module']), $moduleDir, sfFinder::type('any'));
if (!$options['with-show']) {
$this->getFilesystem()->remove($moduleDir . '/templates/showSuccess.php');
}
// change module name
$finder = sfFinder::type('file')->name('*.php');
$this->getFilesystem()->replaceTokens($finder->in($moduleDir), '', '', array('auto' . ucfirst($arguments['module']) => $arguments['module']));
// customize php and yml files
$finder = sfFinder::type('file')->name('*.php', '*.yml');
$this->getFilesystem()->replaceTokens($finder->in($moduleDir), '##', '##', $this->constants);
// create basic test
$this->getFilesystem()->copy(sfConfig::get('sf_symfony_lib_dir') . DIRECTORY_SEPARATOR . 'task' . DIRECTORY_SEPARATOR . 'generator' . DIRECTORY_SEPARATOR . 'skeleton' . DIRECTORY_SEPARATOR . 'module' . DIRECTORY_SEPARATOR . 'test' . DIRECTORY_SEPARATOR . 'actionsTest.php', sfConfig::get('sf_test_dir') . DIRECTORY_SEPARATOR . 'functional' . DIRECTORY_SEPARATOR . $arguments['application'] . DIRECTORY_SEPARATOR . $arguments['module'] . 'ActionsTest.php');
// customize test file
$this->getFilesystem()->replaceTokens(sfConfig::get('sf_test_dir') . DIRECTORY_SEPARATOR . 'functional' . DIRECTORY_SEPARATOR . $arguments['application'] . DIRECTORY_SEPARATOR . $arguments['module'] . 'ActionsTest.php', '##', '##', $this->constants);
// delete temp files
$this->getFilesystem()->remove(sfFinder::type('any')->in($tmpDir));
}
示例14: retrieveOrCreateByObject
public static function retrieveOrCreateByObject(BaseObject $object)
{
if ($object->isNew() === true || $object->isModified() === true || $object->isDeleted() === true) {
throw new Exception('You can only approve an object which has already been saved');
}
$columnName = sfConfig::get('propel_behavior_sfPropelApprovableBehavior_' . get_class($object) . '_column', 'is_approved');
$approvedValue = sfConfig::get('propel_behavior_sfPropelApprovableBehavior_' . get_class($object) . '_approved_value', true);
$disabledApplications = sfConfig::get('propel_behavior_sfPropelApprovableBehavior_' . get_class($object) . '_disabled_applications');
// Test if we should crated an approval - is the column value different to out required value?
// If our object is already approved then we can delete other
$columnGetter = 'get' . sfInflector::camelize($columnName);
if ($approvedValue != $object->{$columnGetter}()) {
$c = new Criteria();
$c->add(sfApprovalPeer::APPROVABLE_ID, $object->getPrimaryKey());
$c->add(sfApprovalPeer::APPROVABLE_MODEL, get_class($object));
$approval = sfApprovalPeer::doSelectOne($c);
if (!$approval) {
$approval = new sfApproval();
$approval->setApprovableModel(get_class($object));
$approval->setApprovableId($object->getPrimaryKey());
$approval->setUuid(sfPropelApprovableToolkit::generateUuid());
$approval->save();
}
return $approval;
} else {
sfApprovalPeer::deleteByObject($object);
return null;
}
return $approval;
}
示例15: __get
public function __get($name)
{
if (in_array($name, array('base_amount', 'discount_amount', 'net_amount', 'tax_amount', 'gross_amount'))) {
$m = sfInflector::camelize("get_{$name}");
return $this->{$m}();
}
return parent::__get($name);
}