/** * @return \Zend\Filter\FilterChain */ private function getFilter() { if ($this->filter === null) { $filter = new FilterChain(); $filter->attach(new CamelCaseToDash()); $filter->attach(new StringToLower()); $this->filter = $filter; } return $this->filter; }
/** * @param \AGmakonts\STL\String\String $name * * @return \AGmakonts\STL\String\String */ private static function filterName(string $name) : string { $nameValue = $name->value(); $filterChain = new FilterChain(); $filterChain->attach(new StripNewlines()); $filterChain->attach(new StripTags()); $filterChain->attach(new StringTrim()); $filterChain->attach(new StringToLower()); $filterChain->attach(new Callback(function ($value) { return ucwords($value); })); $filteredValue = $filterChain->filter($nameValue); return String::get($filteredValue); }
public static function filter($input) { $filterChain = new ZFilter\FilterChain(); $filterChain->attach(new ZFilter\StringToLower(array('encoding' => 'UTF-8')))->attach(new \Zend\I18n\Filter\Alnum(true))->attach(new \ZendVN\Filter\RemoveCircuflex())->attach(new \Zend\Filter\PregReplace(array('pattern' => '#\\s+#', 'replacement' => '-')))->attach(new \Zend\Filter\Word\CamelCaseToDash()); $output = $filterChain->filter($input); return $output; }
public function __call($method, $args) { $filterChain = new FilterChain(); $filterChain->attach(new CamelCaseToDash())->attach(new StringToLower()); $icon = $filterChain->filter($method); return $this->render($icon, isset($args[0]) ? $args[0] : '', isset($args[1]) ? $args[1] : false); }
protected function _convertTableNameToClassName($tableName) { if ($this->_nameFilter == null) { $this->_nameFilter = new \Zend\Filter\FilterChain(); $this->_nameFilter->attach(new \Zend\Filter\Word\UnderscoreToCamelCase()); } return $this->_nameFilter->filter($tableName); }
/** * Normalize tag * * Ensures tag is alphanumeric characters only, and all lowercase. * * @param string $tag * @return string */ public function normalizeTag($tag) { if (!isset($this->_tagFilter)) { $this->_tagFilter = new Filter\FilterChain(); $this->_tagFilter->attach(new Filter\Alnum())->attach(new Filter\StringToLower()); } return $this->_tagFilter->filter($tag); }
/** * {@inheritDoc} */ public function provide() { $container = []; $terms = $this->taxonomyManager->findAllTerms(true); $notTrashed = new NotTrashedCollectionFilter(); $typeFilter = new TaxonomyTypeCollectionFilter(['curriculum-topic', 'curriculum-topic-folder']); $chain = new FilterChain(); $chain->attach($notTrashed); $chain->attach($typeFilter); $terms = $chain->filter($terms); /* @var $term TaxonomyTermInterface */ foreach ($terms as $term) { $result = $this->toDocument($term); $container[] = $result; } return $container; }
/** * @return FilterChain */ private function filterNamespaceToDirectory() { if (null === $this->filterNamespaceToDirectory) { $this->filterNamespaceToDirectory = new FilterChain(); $this->filterNamespaceToDirectory->attach(new SeparatorToSeparator('\\', '|')); $this->filterNamespaceToDirectory->attach(new SeparatorToSeparator('|', DIRECTORY_SEPARATOR)); } return $this->filterNamespaceToDirectory; }
public function testAllowsConnectingArbitraryCallbacks() { $chain = new FilterChain(); $chain->attach(function($value) { return strtolower($value); }); $value = 'AbC'; $this->assertEquals('abc', $chain->filter($value)); }
/** * List all modules * * @return \Zend\View\Model\ViewModel */ public function indexAction() { $collection = new ModuleCollection(); $filter = new Filter\Word\CamelCaseToSeparator(); $filter->setSeparator('-'); $filterChain = new Filter\FilterChain(); $filterChain->attach($filter)->attach(new Filter\StringToLower()); foreach ($collection->getModules() as $module) { $module->setData('route', $filterChain->filter($module->getName())); } return array('modules' => $collection->getModules()); }
/** * Display Icon * * @param string $method * @param array $argv * @throws \InvalidArgumentException * @return string */ public function __call($method, $argv) { $filterChain = new FilterChain(); $filterChain->attach(new CamelCaseToDash())->attach(new StringToLower()); $icon = $filterChain->filter($method); if (!in_array($icon, $this->icons)) { throw new InvalidArgumentException($icon . ' is not supported'); } if ($argv) { $argv = (string) $argv[0]; } return $this->render($icon, $argv); }
/** * Filters a value with given filters. * * @param mixed $value * @param array $filters * @return mixed * @throws InvalidFilterException If callback is not callable. */ public function filter($value, array $filters) { $filterChain = new FilterChain(); foreach ($filters as $name => $options) { $class = 'Zend\\Filter\\' . ucfirst($name); if (class_exists($class)) { $filterChain->attach(new $class($options)); } else { throw new InvalidFilterException("{$class} class does not exist."); } } return $filterChain->filter($value); }
/** * Load menu if module has view with name "menu.phtml" * * @param EventInterface $event Event * * @return void */ public function loadMenu(EventInterface $event) { if ($route = $event->getRouter()->getRoute('module')->match($event->getRequest())) { if ($route->getParam('module') === 'module') { return; } $filter = new Filter\Word\CamelCaseToSeparator(); $filter->setSeparator('-'); $filterChain = new Filter\FilterChain(); $filterChain->attach($filter)->attach(new Filter\StringToLower()); $template = $filterChain->filter($route->getParam('module')) . '/menu'; $target = $event->getTarget(); $resolver = $event->getApplication()->getServiceManager()->get('Zend\\View\\Resolver\\TemplatePathStack'); $navigation = $target->getServiceLocator()->get('navigation'); $navigation->findByRoute('module')->addPage(array('label' => $route->getParam('module'), 'route' => $event->getRouteMatch()->getMatchedRouteName(), 'active' => true)); if (false !== $resolver->resolve($template)) { $target->layout()->setVariable('moduleMenu', $template); } } }
/** * Public constructor * * @param SparqlClient $sparqlClient A SparQL client * @param String $query_path Path to sparQL queries * @param Cache $cache Cache * @throws \Exception */ public function __construct(SparqlClient $sparqlClient, $query_path, Cache $cache = null) { $this->sparqlClient = $sparqlClient; if (!file_exists($query_path) || !is_dir($query_path)) { $tpl = "Query path '%s' does not exist or is not a directory"; $msg = sprintf($tpl, $query_path); throw new \Exception($msg); } $filter = new FilterChain(); $filter->attach(new StringToLowerFilter())->attach(new WordFilter\SeparatorToCamelCase())->attach(new WordFilter\DashToCamelCase())->attach(new WordFilter\UnderscoreToCamelCase())->attach(new CallbackFilter('lcfirst')); $flags = \FilesystemIterator::KEY_AS_FILENAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS; $fsi = new \FilesystemIterator($query_path, $flags); $rei = new \RegexIterator($fsi, '/\\.rq$/'); foreach ($rei as $fileName => $fileInfo) { $path = $fileInfo->getPathname(); $baseName = $fileInfo->getBasename('.rq'); $propName = $filter->filter($baseName); $this->queries[$propName] = file_get_contents($path); } if (null != $cache) { $this->cache = $cache; } }
protected function _convertActionNameToFilesystemName($actionName) { $filter = new FilterChain(); $filter->attach(new CamelCaseToDashFilter())->attach(new StringToLowerFilter()); return $filter->filter($actionName); }
private function parsePayload($payload) { $filterChain = new FilterChain(); $filterChain->attach(new CamelCaseToUnderscore()); $filterChain->attach(new StringToLower()); // Collections provide an array and entities provide an array object. We need to modify the // collection else the data won't be updated. if ($payload instanceof \ArrayObject) { $backup = clone $payload; $newPayload = $payload; $newPayload->exchangeArray([]); } else { $backup = $payload; $newPayload = []; } foreach ($backup as $name => $value) { if ($value instanceof \DateTimeInterface) { $value->setTimezone(new \DateTimeZone("UTC")); $value = $value->format('c'); } $newPayload[$filterChain->filter($name)] = $value; } return $newPayload; }
public function filter($value) { $filterChain = new ZFilter\FilterChain(); $filterChain->attach(new \Zend\I18n\Filter\Alnum(true))->attach(new ZFilter\StringTrim())->attach(new ZFilter\PregReplace(array("pattern" => "#\\s+#", "replacement" => " ")))->attach(new ZFilter\StringToLower("UTF-8"))->attach(new ZFilter\Word\SeparatorToDash())->attach(new \ZendVN\Filter\RemoveCircumPlex()); return $output = $filterChain->filter($value); }
public function testMergingTwoFilterChainsKeepFiltersPriority() { $value = 'AbC'; $valueExpected = 'abc'; $chain = new FilterChain(); $chain->attach(new StripUpperCase())->attach(new LowerCase(), 1001); $this->assertEquals($valueExpected, $chain->filter($value)); $chain = new FilterChain(); $chain->attach(new LowerCase(), 1001)->attach(new StripUpperCase()); $this->assertEquals($valueExpected, $chain->filter($value)); $chain = new FilterChain(); $chain->attach(new LowerCase(), 1001); $chainToMerge = new FilterChain(); $chainToMerge->attach(new StripUpperCase()); $chain->merge($chainToMerge); $this->assertEquals(2, $chain->count()); $this->assertEquals($valueExpected, $chain->filter($value)); $chain = new FilterChain(); $chain->attach(new StripUpperCase()); $chainToMerge = new FilterChain(); $chainToMerge->attach(new LowerCase(), 1001); $chain->merge($chainToMerge); $this->assertEquals(2, $chain->count()); $this->assertEquals($valueExpected, $chain->filter($value)); }
/** * Apply a standard set of filters to elements * * @return \Zend\Filter\FilterChain */ protected function _getStandardFilter() { $baseInputFilterChain = new FilterChain(); $baseInputFilterChain->attach(new HtmlEntities())->attach(new StringTrim())->attach(new StripNewlines())->attach(new StripTags()); return $baseInputFilterChain; }
protected function _getStandardFilter() { $baseInputFilterChain = new FilterChain(); $baseInputFilterChain->attach(new Int()); return $baseInputFilterChain; }
public function index17Action() { echo "<h3 style='color:red;font-weight:bold'>" . __METHOD__ . "</h3>"; $input = " Trongle123123-Handsome-Talent "; $filterChain = new ZFilter\FilterChain(); $filterChain->attach(new ZFilter\StringTrim()); $filterChain->attach(new ZFilter\PregReplace(array("pattern" => "#[0-9]#", "replacement" => "x"))); $filterChain->attach(new ZFilter\Word\DashToUnderscore()); $output = $filterChain->filter($input); echo "<h2>Input: {$input}</h2><br>"; echo "<h2>Output : {$output}</h2>"; return false; }
public function rssAction() { $feed = new Feed(); $type = $this->params('type'); $age = (int) $this->params('age'); $maxAge = new DateTime($age . ' days ago'); $entities = $this->getEntityManager()->findEntitiesByTypeName($type); $chain = new FilterChain(); $chain->attach(new EntityAgeCollectionFilter($maxAge)); $chain->attach(new NotTrashedCollectionFilter()); $entities = $chain->filter($entities); $data = $this->normalize($entities); foreach ($data as $item) { try { $entry = $feed->createEntry(); $entry->setTitle($item['title']); $entry->setDescription($item['description']); $entry->setId($item['guid']); $entry->setLink($item['link']); foreach ($item['categories'] as $keyword) { $entry->addCategory(['term' => $keyword]); } $entry->setDateModified($item['lastModified']); $feed->addEntry($entry); } catch (\Exception $e) { // Invalid Item, do not add } } $feed->setTitle($this->brand()->getHeadTitle()); $feed->setDescription($this->brand()->getDescription()); $feed->setDateModified(time()); $feed->setLink($this->url()->fromRoute('home', [], ['force_canonical' => true])); $feed->setFeedLink($this->url()->fromRoute('entity/api/rss', ['type' => $type, 'age' => $age], ['force_canonical' => true]), 'atom'); $feed->export('atom'); $feedModel = new FeedModel(); $feedModel->setFeed($feed); return $feedModel; }
/** * @return FilterChain */ protected function getStringTrimFilterChain() { $filterChain = new FilterChain(); $filterChain->attach(new StringTrim()); return $filterChain; }
/** * @return \Zend\Filter\FilterChain */ private function getFilter() { if (self::$filter === null) { $filter = new FilterChain(); $filter->attach(new CamelCaseToUnderscore()); $filter->attach(new UnderscoreToCamelCase()); self::$filter = $filter; } return self::$filter; }
public function testCanSerializeFilterChain() { $chain = new FilterChain(); $chain->attach(new LowerCase())->attach(new StripUpperCase()); $serialized = serialize($chain); $unserialized = unserialize($serialized); $this->assertInstanceOf('Zend\\Filter\\FilterChain', $unserialized); $this->assertEquals(2, count($unserialized)); $value = 'AbC'; $valueExpected = 'abc'; $this->assertEquals($valueExpected, $unserialized->filter($value)); }
private function batchElementsArray($term) { $chain = new FilterChain(); $chain->attach(new NotTrashedCollectionFilter()); $chain->attach(new HasHeadCollectionFilter()); $elements = $term->getAssociated('entities'); $notTrashedElements = $chain->filter($elements); $options = []; foreach ($notTrashedElements as $element) { $options[$element->getId()] = $element; } return $options; }
/** * Handle the creation of a new link * * @param array $data * @return JsonModel */ protected function createLink($data) { $userLinksTable = $this->getUserLinksTable(); $filters = $userLinksTable->getInputFilter(); $filters->setData($data); if ($filters->isValid()) { $data = $filters->getValues(); $client = new Client($data['url']); $client->setEncType(Client::ENC_URLENCODED); $client->setMethod(\Zend\Http\Request::METHOD_GET); $response = $client->send(); if ($response->isSuccess()) { $html = $response->getBody(); $html = mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8"); $dom = new Query($html); $title = $dom->execute('title')->current()->nodeValue; if (!empty($title)) { $filterChain = new FilterChain(); $filterChain->attach(new StripTags()); $filterChain->attach(new StringTrim()); $filterChain->attach(new StripNewLines()); $title = $filterChain->filter($title); } else { $title = NULL; } return new JsonModel(array('result' => $userLinksTable->create($data['user_id'], $data['url'], $title))); } } return new JsonModel(array('result' => false, 'errors' => $filters->getMessages())); }
/** * @param FilterChain $chain * @param array|Traversable $filters * @throws Exception\RuntimeException * @return void */ protected function populateFilters(FilterChain $chain, $filters) { foreach ($filters as $filter) { if (is_object($filter) || is_callable($filter)) { $chain->attach($filter); continue; } if (is_array($filter)) { if (!isset($filter['name'])) { throw new Exception\RuntimeException('Invalid filter specification provided; does not include "name" key'); } $name = $filter['name']; $priority = isset($filter['priority']) ? $filter['priority'] : FilterChain::DEFAULT_PRIORITY; $options = []; if (isset($filter['options'])) { $options = $filter['options']; } $chain->attachByName($name, $options, $priority); continue; } throw new Exception\RuntimeException('Invalid filter specification provided; was neither a filter instance nor an array specification'); } }
/** * {@inheritDoc} */ public function provide() { $notTrashed = new NotTrashedCollectionFilter(); $hasCurrent = new HasCurrentRevisionCollectionFilter(); $chain = new FilterChain(); $chain->attach($notTrashed); $chain->attach($hasCurrent); $container = []; $types = $this->options->getTypes(); foreach ($types as $type) { if ($type->hasComponent('search')) { /* @var $component SearchOptions */ $component = $type->getComponent('search'); if ($component->getEnabled()) { $name = $type->getName(); $entities = $this->entityManager->findEntitiesByTypeName($name, true); $entities = $chain->filter($entities); $this->addEntitiesToContainer($entities, $container); } } } return $container; }