예제 #1
0
 /**
  * Filter an array's values
  * @param mixed $value
  * @return mixed
  */
 public function filter($value)
 {
     // Don't touch non-array things
     if (!is_array($value) || !$this->chain) {
         return $value;
     }
     // Apply sub-filters to all values
     foreach ($value as &$v) {
         $v = $this->chain->filter($v);
     }
     return $value;
 }
예제 #2
0
 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;
 }
예제 #3
0
 public function _filter(&$value)
 {
     $filtered = parent::filter($value);
     $changed = $filtered != $value;
     $value = $filtered;
     return $changed;
 }
예제 #4
0
파일: Icon.php 프로젝트: acplo/acploui
 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);
 }
예제 #5
0
 protected function _convertTableNameToClassName($tableName)
 {
     if ($this->_nameFilter == null) {
         $this->_nameFilter = new \Zend\Filter\FilterChain();
         $this->_nameFilter->addFilter(new \Zend\Filter\Word\UnderscoreToCamelCase());
     }
     return $this->_nameFilter->filter($tableName);
 }
예제 #6
0
 /**
  * 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);
 }
예제 #7
0
 /**
  * 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());
 }
예제 #8
0
 /**
  * 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);
 }
예제 #9
0
 /**
  * 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);
 }
예제 #10
0
 /**
  * @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);
 }
예제 #11
0
 /**
  * {@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;
 }
예제 #12
0
파일: Module.php 프로젝트: gotcms/gotcms
 /**
  * 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);
         }
     }
 }
예제 #13
0
 /**
  * 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;
     }
 }
예제 #14
0
 protected function _convertActionNameToFilesystemName($actionName)
 {
     $filter = new FilterChain();
     $filter->attach(new CamelCaseToDashFilter())->attach(new StringToLowerFilter());
     return $filter->filter($actionName);
 }
예제 #15
0
 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);
 }
예제 #16
0
파일: Module.php 프로젝트: zource/zource
 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;
 }
예제 #17
0
 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;
 }
예제 #18
0
 /**
  * Processes a view script and returns the output.
  *
  * @param  string|Model $nameOrModel Either the template to use, or a
  *                                   ViewModel. The ViewModel must have the
  *                                   template as an option in order to be
  *                                   valid.
  * @param  null|array|Traversable $values Values to use when rendering. If none
  *                                provided, uses those in the composed
  *                                variables container.
  * @return string The script output.
  * @throws Exception\DomainException if a ViewModel is passed, but does not
  *                                   contain a template option.
  * @throws Exception\InvalidArgumentException if the values passed are not
  *                                            an array or ArrayAccess object
  * @throws Exception\RuntimeException if the template cannot be rendered
  */
 public function render($nameOrModel, $values = null)
 {
     if ($nameOrModel instanceof Model) {
         $model = $nameOrModel;
         $nameOrModel = $model->getTemplate();
         if (empty($nameOrModel)) {
             throw new Exception\DomainException(sprintf('%s: received View Model argument, but template is empty', __METHOD__));
         }
         $options = $model->getOptions();
         foreach ($options as $setting => $value) {
             $method = 'set' . $setting;
             if (method_exists($this, $method)) {
                 $this->{$method}($value);
             }
             unset($method, $setting, $value);
         }
         unset($options);
         // Give view model awareness via ViewModel helper
         $helper = $this->plugin('view_model');
         $helper->setCurrent($model);
         $values = $model->getVariables();
         unset($model);
     }
     // find the script file name using the parent private method
     $this->addTemplate($nameOrModel);
     unset($nameOrModel);
     // remove $name from local scope
     $this->__varsCache[] = $this->vars();
     if (null !== $values) {
         $this->setVars($values);
     }
     unset($values);
     // extract all assigned vars (pre-escaped), but not 'this'.
     // assigns to a double-underscored variable, to prevent naming collisions
     $__vars = $this->vars()->getArrayCopy();
     if (array_key_exists('this', $__vars)) {
         unset($__vars['this']);
     }
     extract($__vars);
     unset($__vars);
     // remove $__vars from local scope
     while ($this->__template = array_pop($this->__templates)) {
         $this->__file = $this->resolver($this->__template);
         if (!$this->__file) {
             throw new Exception\RuntimeException(sprintf('%s: Unable to render template "%s"; resolver could not resolve to a file', __METHOD__, $this->__template));
         }
         try {
             ob_start();
             $includeReturn = (include $this->__file);
             $this->__content = ob_get_clean();
         } catch (\Exception $ex) {
             ob_end_clean();
             throw $ex;
         }
         if ($includeReturn === false && empty($this->__content)) {
             throw new Exception\UnexpectedValueException(sprintf('%s: Unable to render template "%s"; file include failed', __METHOD__, $this->__file));
         }
     }
     $this->setVars(array_pop($this->__varsCache));
     if ($this->__filterChain instanceof FilterChain) {
         return $this->__filterChain->filter($this->__content);
         // filter output
     }
     return $this->__content;
 }
예제 #19
0
 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));
 }
 /**
  * Sanitizes action name to use in route.
  *
  * @param string $name
  * @return string
  */
 protected function filterActionMethodName($name)
 {
     $filter = new FilterChain();
     $filter->attachByName('Zend\\Filter\\Word\\CamelCaseToDash');
     $filter->attachByName('StringToLower');
     return rtrim(preg_replace('/action$/', '', $filter->filter($name)), '-');
 }
예제 #21
0
 /**
  * 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()));
 }
예제 #22
0
 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;
 }
예제 #23
0
 public function testConfigurationAllowsTraversableObjects()
 {
     $config = $this->getChainConfig();
     $config = new \ArrayIterator($config);
     $chain  = new FilterChain($config);
     $value = '<a name="foo"> abc </a>';
     $valueExpected = 'ABC';
     $this->assertEquals($valueExpected, $chain->filter($value));
 }
예제 #24
0
 public function testCanRetrieveFilterWithUndefinedConstructor()
 {
     $chain = new FilterChain(array('filters' => array(array('name' => 'int'))));
     $filtered = $chain->filter('127.1');
     $this->assertEquals(127, $filtered);
 }
예제 #25
0
 public function index18Action()
 {
     echo "<h3 style='color:red;font-weight:bold'>" . __METHOD__ . "</h3>";
     $input = "            Trongle123123-Handsome-Talent         ";
     $filterChain = new ZFilter\FilterChain();
     $filterChain->attachByName("StringTrim");
     $filterChain->attachByName("PregReplace", array("pattern" => "#[0-9]#", "replacement" => "!"));
     $filterChain->attachByName("Word\\DashToUnderscore");
     $output = $filterChain->filter($input);
     echo "<h2>Input: {$input}</h2><br>";
     echo "<h2>Output : {$output}</h2>";
     return false;
 }
예제 #26
0
 /**
  * {@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;
 }