本文整理汇总了PHP中Zend_Filter_Inflector::filter方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Filter_Inflector::filter方法的具体用法?PHP Zend_Filter_Inflector::filter怎么用?PHP Zend_Filter_Inflector::filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Filter_Inflector
的用法示例。
在下文中一共展示了Zend_Filter_Inflector::filter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _transformColumn
/**
* Inflektor pro ziskani nazvu atributu
* camelCase -> under_score
*
* @param string $columnName
* @return string
*/
protected function _transformColumn($columnName)
{
$inflector = new Zend_Filter_Inflector(":string");
$inflector->setRules(array(':string' => array('Word_CamelCaseToUnderscore', 'StringToLower')));
$columnName = $inflector->filter(array('string' => $columnName));
return $columnName;
}
示例2: _dasherise
/**
* Uses Zend's inflector rules to convert from class names to url segments
*
* @param string $name
* @return string
*/
protected function _dasherise($name)
{
$name = str_replace('Action', '', $name);
$inflector = new Zend_Filter_Inflector(':name');
$inflector->setRules(array(':name' => array('Word_CamelCaseToDash', 'StringToLower')));
return $inflector->filter(array('name' => $name));
}
示例3: filterText
public function filterText($text)
{
$inflector = new Zend_Filter_Inflector(':text');
$inflector->setRules(array(':text' => array(new Zend_Filter_StringToLower(), new Zend_Filter_StripTags(), new Zend_Filter_Word_DashToSeparator(), new Zend_Filter_Word_SeparatorToSeparator('/', '_'), new Zend_Filter_Word_UnderscoreToSeparator(), new Zend_Filter_StringTrim(), new Zend_Filter_Alnum(true), new Zend_Filter_Word_SeparatorToSeparator(' ', '_'))));
$text = $inflector->filter(array('text' => $text));
return $text;
}
示例4: render
/**
* Render layout
*
* Sets internal script path as last path on script path stack, assigns
* layout variables to view, determines layout name using inflector, and
* renders layout view script.
*
* $name will be passed to the inflector as the key 'script'.
*
* @param mixed $name
* @return mixed
*/
public function render($name = null)
{
if (null === $name) {
$name = $this->getLayout();
}
if ($this->inflectorEnabled() && (null !== ($inflector = $this->getInflector())))
{
$name = $this->_inflector->filter(array('script' => $name));
}
$view = $this->getView();
if (null !== ($path = $this->getViewScriptPath())) {
if (method_exists($view, 'addScriptPath')) {
$view->addScriptPath($path);
} else {
$view->setScriptPath($path);
}
} elseif (null !== ($path = $this->getViewBasePath())) {
$view->addBasePath($path, $this->_viewBasePrefix);
}
return $view->render($name);
}
示例5: generateSlug
public function generateSlug($rawSlug)
{
$inflector = new Zend_Filter_Inflector(':slug');
$inflector->setRules(array(':slug' => array(new Zend_Filter_StringToLower(), new Zend_Filter_StringTrim(), new Zend_Filter_StripTags(), new Zend_Filter_Word_DashToSeparator(), new Zend_Filter_PregReplace(array('match' => '/[^A-Za-z0-9]/', 'replace' => ' ')), new Zend_Filter_Alnum(true), new Zend_Filter_Word_SeparatorToDash())));
$slug = $inflector->filter(array('slug' => $rawSlug));
return $slug;
}
示例6: __construct
public function __construct($config = array())
{
parent::__construct($config);
// strip filename_orig from weird characters and transform underscores to camelcase
$pattern = '/(.*[\\\\\\/])?(.*)$/';
preg_match($pattern, $this->filename_orig, $matches);
$sanatized = str_replace(array(' ', ':', '*', '?', '"', '<', '>', '|'), '_', $matches[2]);
$inflector = new Zend_Filter_Inflector(':name');
$inflector->setRules(array(':name' => array('Word_UnderscoreToCamelCase')));
$filtered = $inflector->filter(array('name' => $sanatized));
$this->filename_orig = $filtered;
}
示例7: render
/**
* Render layout
*
* Sets internal script path as last path on script path stack, assigns
* layout variables to view, determines layout name using inflector, and
* renders layout view script.
*
* $name will be passed to the inflector as the key 'script'.
*
* @param mixed $name
* @return mixed
*/
public function render($name = null)
{
if (null === $name) {
$name = $this->getLayout();
}
if ($this->inflectorEnabled() && null !== ($inflector = $this->getInflector())) {
$name = $this->_inflector->filter(array('script' => $name));
}
$view = $this->getView();
if (null !== ($path = $this->getLayoutPath())) {
$view->addScriptPath($path);
}
return $view->render($name);
}
示例8: testNoInflectableTarget
/**
* @issue ZF-2964
*/
public function testNoInflectableTarget()
{
$inflector = new Zend_Filter_Inflector('abc');
$inflector->addRules(array(':foo' => array()));
$this->assertEquals($inflector->filter(array('fo' => 'bar')), 'abc');
}
示例9: _getInflected
/**
* Inflect the name using the inflector filter
*
* Changes camelCaseWord to Camel_Case_Word
*
* @param string $name The name to inflect
* @return string The inflected string
*/
private function _getInflected($name)
{
$inflector = new Zend_Filter_Inflector(':class');
$inflector->setRules(array(':class' => array('Word_CamelCaseToUnderscore')));
return ucfirst($inflector->filter(array('class' => $name)));
}
示例10: getTemplateName
/**
* Returns the template name.
*
* @return string
*/
public function getTemplateName()
{
$request = $this->viewRenderer->Action()->Request();
$dispatcher = $this->viewRenderer->Front()->Dispatcher();
$moduleName = $dispatcher->formatModuleName($request->getModuleName());
$controllerName = $dispatcher->formatControllerName($request->getControllerName());
$inflector = new Zend_Filter_Inflector($this->target);
$inflector->setRules($this->filterRules);
$inflector->setThrowTargetExceptionsOn(false);
$fileNames = (array) $request->getParam('file', $this->defaultFile);
$templateNames = array();
foreach ($fileNames as $fileName) {
$fileName = ltrim(dirname($fileName) . '/' . basename($fileName, '.js'), '/.');
if (empty($fileName)) {
continue;
}
$templateNames[] = $inflector->filter(array('module' => $moduleName, 'controller' => $controllerName, 'file' => $fileName));
}
$count = count($templateNames);
if ($count === 0) {
return null;
} elseif ($count === 1) {
return $templateNames[0];
} else {
return 'snippet:string:{include file="' . implode("\"}\n{include file=\"", $templateNames) . '"}';
}
}
示例11: run
/**
* Factory method that runs a given migration.
*
* @param string $fileName
* @param string $direction
*/
public static function run($fileName, $direction, $verbose)
{
if ($direction == 'drop') {
// We create a fake instance here since drop is not associated
// with any real migration class.
$dropper = new self('', __CLASS__);
$dropper->migrate('drop');
return;
}
$inflector = new Zend_Filter_Inflector(':class', array(':class' => 'Word_DashToCamelCase'));
preg_match('/(\\d+)_(.+)\\.php/', basename($fileName), $matches);
$version = $matches[1];
$class = $inflector->filter(array(':class' => $matches[2]));
include $fileName;
if (class_exists($class)) {
$migration = new $class($version, $class, $verbose);
$migration->migrate($direction);
$migration->updateInstalledVersions($version, $direction);
} else {
$msg = "Class '{$class}' is not present in the migration file";
$this->write($msg);
throw new Svenax_Migration_Exception($msg);
}
}
示例12: submitAction
/**
* Submit Feed to website
*
* @return
*/
public function submitAction()
{
$this->view->keywords = implode('', array('ifphp', 'news aggragator', 'submit rss feed'));
$form = $this->getSubmitForm();
//setup the available categories
$categories = new Categories();
$this->view->categories = $categories->getAll();
foreach ($this->view->categories as $category) {
$form->category->addMultiOptions(array($category->id => $category->title));
}
//setup the available languages
$languages = new Languages();
$this->view->languages = $languages->getAll();
foreach ($this->view->languages as $language) {
$form->language->addMultiOptions(array($language->id => $language->title));
}
//if it's a post submit let's save the information
if ($this->getRequest()->isPost() && $form->isValid($_POST)) {
//TODO this shoudl be wrapped in a transaction
//create user
$users = new Users();
//check for existance of a user
$user = $users->getByEmail($form->email->getValue());
if (!$user) {
$user = $users->createRow();
$user->email = $form->email->getValue();
$user->fullName = $form->fullname->getValue();
$user->username = 'temporaryusername';
//TODO put real username here eventually
$user->password = '';
$user->roleId = Role::SUBMITTER;
$user->statusId = Status::ACTIVE;
$user->save();
}
try {
$feedSource = Zend_Feed_Reader::import($form->url->getValue());
//convert/parse feed to strongly typed objects
$defaultFilterChain = new Zend_Filter();
$defaultFilterChain->addFilter(new Ifphp_Filter_XSSClean());
$defaultFilterChain->addFilter(new Zend_Filter_StringTrim());
$defaultFilterChain->addFilter(new Zend_Filter_StripTags());
$feeds = new Feeds();
$feed = $feeds->createRow();
$feed->token = md5(uniqid($user->id));
$feed->url = $defaultFilterChain->filter($form->url->getValue());
$feed->title = $defaultFilterChain->filter($feedSource->getTitle());
$inflector = new Zend_Filter_Inflector(':title');
$inflector->setRules(array(':title' => array('Word_SeparatorToDash', 'StringToLower', 'HtmlEntities')));
$feed->slug = $inflector->filter(array('title' => $feed->title));
$feed->description = $defaultFilterChain->filter($feedSource->getDescription());
$feed->categoryId = $form->category->getValue();
$feed->languageId = $form->language->getValue();
$feed->siteUrl = $form->siteUrl->getValue();
$feed->statusId = Status::PENDING;
$feed->userId = $user->id;
$feed->refreshRate = 120;
//TODO this is sometimes stored in the feed
$feed->save();
//parse feed
$posts = new Posts();
foreach ($feedSource as $feedEntry) {
$post = $posts->createRow();
$post->title = $defaultFilterChain->filter($feedEntry->getTitle());
$post->description = $defaultFilterChain->filter($feedEntry->getDescription());
$post->link = $defaultFilterChain->filter($feedEntry->getPermaLink());
$post->feedId = $feed->id;
$date = new Zend_Date($feedEntry->getDateModified());
$post->publishDate = $date->toValue();
$post->save();
}
// $this->_flashMessenger->addMessage('Your feed has been added to the site. Your ping back url is http://ifphp.com/feed/ping-back/'.$feed->token);
$this->sendActivationEmail($feed, $user);
$this->_forward('submit-thank-you');
} catch (Zend_Feed_Exception $error) {
$form->url->markAsError();
Zend_Registry::getInstance()->logger->err($error);
return;
}
}
$this->view->form = $form;
}
示例13: extendsAction
public function extendsAction()
{
$request = $this->Request();
$moduleName = 'backend';
$controllerName = $this->Request()->getParam('baseController');
$inflector = new Zend_Filter_Inflector(':module/:controller/:file:suffix');
$inflector->setRules(array(
':module' => array('Word_CamelCaseToUnderscore', 'StringToLower'),
':controller' => array('Word_CamelCaseToUnderscore', 'StringToLower'),
':file' => array('Word_CamelCaseToUnderscore', 'StringToLower'),
'suffix' => '.js'
));
$inflector->setThrowTargetExceptionsOn(false);
$fileNames = (array) $request->getParam('file');
if(empty($fileNames)) {
return;
}
$this->Response()->setHeader('Content-Type', 'application/javascript; charset=utf-8', true);
$template = 'snippet:string:';
$this->View()->Engine()->setCompileId($this->View()->Engine()->getCompileId() . '_' . $this->Request()->getControllerName());
foreach($fileNames as $fileName) {
$fileName = ltrim(dirname($fileName) . '/' . basename($fileName, '.js'), '/.');
if (empty($fileName)) {
continue;
}
$templateBase = $inflector->filter(array(
'module' => $moduleName,
'controller' => $controllerName,
'file' => $fileName)
);
$templateExtend = $inflector->filter(array(
'module' => $moduleName,
'controller' => $this->Request()->getControllerName(),
'file' => $fileName)
);
if($this->View()->templateExists($templateBase)) {
$template .= '{include file="' . $templateBase. '"}' . "\n";
}
if($this->View()->templateExists($templateExtend)) {
$template .= '{include file="' . $templateExtend. '"}' . "\n";
}
}
$toFind = $this->Request()->getParam('find');
$toReplace = $this->Request()->getParam('replace');
$toFind = rtrim($toFind, '.') . '.';
$toReplace = rtrim($toReplace, '.') . '.';
$this->View()->setTemplate();
$template = $this->View()->fetch($template);
$template = str_replace($toFind, $toReplace, $template);
echo $template;
}
示例14: getTemplateName
/**
* Returns the template name.
*
* @return string
*/
public function getTemplateName()
{
$request = $this->viewRenderer->Action()->Request();
$dispatcher = $this->viewRenderer->Front()->Dispatcher();
$moduleName = $dispatcher->formatModuleName($request->getModuleName());
$controllerName = $dispatcher->formatControllerName($request->getControllerName());
$inflector = new Zend_Filter_Inflector($this->target);
$inflector->setRules($this->filterRules);
$inflector->setThrowTargetExceptionsOn(false);
$fileName = $request->getParam('file', $this->defaultFile);
$fileName = ltrim(dirname($fileName) . '/' . basename($fileName, '.js'), '/.');
if (empty($fileName)) {
return null;
}
$templateName = $inflector->filter(array('module' => $moduleName, 'controller' => $controllerName, 'file' => $fileName));
return $templateName;
}
示例15: fixAction
/**
* @todo Remove when done
*/
public function fixAction()
{
$posts = new Posts();
$tposts = $posts->fetchAll($posts->select()->where('id > 0'));
$defaultFilterChain = new Zend_Filter();
$defaultFilterChain->addFilter(new Ifphp_Filter_XSSClean());
$defaultFilterChain->addFilter(new Zend_Filter_StringTrim());
$defaultFilterChain->addFilter(new Zend_Filter_StripTags());
$defaultFilterChain->addFilter(new Zend_Filter_HtmlEntities(array('quotestyle' => ENT_QUOTES, 'charset' => 'UTF-8')));
$defaultFilterChain->addFilter(new Ifphp_Filter_HtmlEntityNames());
foreach ($tposts as $post) {
$post->title = $defaultFilterChain->filter($post->title);
$post->description = $defaultFilterChain->filter($post->description);
$post->feedId = $defaultFilterChain->filter($post->feedId);
$post->link = $defaultFilterChain->filter($post->link);
$post->publishDate = $post->publishDate;
// Zend_Debug::dump($post->description);
$post->save();
}
$feeds = new Feeds();
$tfeeds = $feeds->fetchAll($feeds->select()->where('id > 0'));
$inflector = new Zend_Filter_Inflector(':title');
$inflector->setRules(array(':title' => array('Word_SeparatorToDash', 'StringToLower', 'HtmlEntities')));
foreach ($tfeeds as $feed) {
$feed->title = $defaultFilterChain->filter($feed->title);
$feed->description = $defaultFilterChain->filter($feed->description);
$feed->slug = $inflector->filter(array('title' => $feed->title));
$feed->save();
}
die;
}