/** * @covers phpDocumentor\Descriptor\Filter\Filter::filter */ public function testFilter() { $filterableMock = m::mock('phpDocumentor\\Descriptor\\Filter\\Filterable'); $this->filterChainMock->shouldReceive('filter')->with($filterableMock)->andReturn($filterableMock); $this->classFactoryMock->shouldReceive('getChainFor')->with(get_class($filterableMock))->andReturn($this->filterChainMock); $this->assertSame($filterableMock, $this->fixture->filter($filterableMock)); }
public static function injectValidatorPluginManager(Form $form, ServiceLocatorInterface $sl) { $plugins = $sl->get('ValidatorManager'); $chain = new FilterChain(); $chain->setPluginManager($plugins); $form->getFormFactory()->getInputFilterFactory()->setDefaultFilterChain($chain); }
public function testDoctrineService() { $serviceManager = $this->getApplication()->getServiceManager(); $em = $serviceManager->get('doctrine.entitymanager.orm_default'); $tool = new SchemaTool($em); $res = $tool->createSchema($em->getMetadataFactory()->getAllMetadata()); // Create DB $resourceDefinition = array("objectManager" => "doctrine.entitymanager.orm_default", "serviceName" => "Artist", "entityClass" => "Db\\Entity\\Artist", "routeIdentifierName" => "artist_id", "entityIdentifierName" => "id", "routeMatch" => "/db-test/artist"); $this->resource = $serviceManager->get('ZF\\Apigility\\Doctrine\\Admin\\Model\\DoctrineRestServiceResource'); $this->resource->setModuleName('DbApi'); $entity = $this->resource->create($resourceDefinition); $this->assertInstanceOf('ZF\\Apigility\\Doctrine\\Admin\\Model\\DoctrineRestServiceEntity', $entity); $controllerServiceName = $entity->controllerServiceName; $this->assertNotEmpty($controllerServiceName); $this->assertContains('DbApi\\V1\\Rest\\Artist\\Controller', $controllerServiceName); $filter = new FilterChain(); $filter->attachByName('WordCamelCaseToUnderscore')->attachByName('StringToLower'); $em = $serviceManager->get('doctrine.entitymanager.orm_default'); $metadataFactory = $em->getMetadataFactory(); $entityMetadata = $metadataFactory->getMetadataFor("Db\\Entity\\Artist"); foreach ($entityMetadata->associationMappings as $mapping) { switch ($mapping['type']) { case 4: $rpcServiceResource = $serviceManager->get('ZF\\Apigility\\Doctrine\\Admin\\Model\\DoctrineRpcServiceResource'); $rpcServiceResource->setModuleName('DbApi'); $rpcServiceResource->create(array('service_name' => 'Artist' . $mapping['fieldName'], 'route' => '/db-test/artist[/:parent_id]/' . $filter($mapping['fieldName']) . '[/:child_id]', 'http_methods' => array('GET', 'PUT', 'POST'), 'options' => array('target_entity' => $mapping['targetEntity'], 'source_entity' => $mapping['sourceEntity'], 'field_name' => $mapping['fieldName']), 'selector' => 'custom selector')); break; default: break; } } }
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); }
/** * Ensures that filters can be prepended and will be executed in the * expected order */ public function testFilterPrependOrder() { $filter = new FilterChain(); $filter->appendFilter(new StripUpperCase())->prependFilter(new LowerCase()); $value = 'AbC'; $valueExpected = 'abc'; $this->assertEquals($valueExpected, $filter($value)); }
/** * @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; }
/** * @return FilterChain */ protected function getCamelCaseToUnderscoreFilter() { if (static::$camelCaseToUnderscoreFilter instanceof FilterChain) { return static::$camelCaseToUnderscoreFilter; } $filter = new FilterChain(); $filter->attachByName('WordCamelCaseToUnderscore'); $filter->attachByName('StringToLower'); return static::$camelCaseToUnderscoreFilter = $filter; }
/** * 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; }
/** * 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); }
public function _filter(&$value) { $filtered = parent::filter($value); $changed = $filtered != $value; $value = $filtered; return $changed; }
/** * 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); }
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); }
/** * {@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; }
/** * Retrieve the filter chain for generating the route name * * @return FilterChain */ protected function getRouteNameFilter() { if ($this->routeNameFilter instanceof FilterChain) { return $this->routeNameFilter; } $this->routeNameFilter = new FilterChain(); $this->routeNameFilter->attachByName('Word\\CamelCaseToDash')->attachByName('StringToLower'); return $this->routeNameFilter; }
/** * @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; }
/** * @return FilterChain */ private function filterNamespaceToDirectory() { if (null === $this->filterNamespaceToDirectory) { $this->filterNamespaceToDirectory = new FilterChain(); $this->filterNamespaceToDirectory->attachByName('wordseparatortocamelcase', ['separator' => '\\']); $this->filterNamespaceToDirectory->attachByName('wordcamelcasetoseparator', ['separator' => '/']); } return $this->filterNamespaceToDirectory; }
/** * @return FilterChain */ private function filterNamespaceToDirectory() { if (null === $this->filterNamespaceToDirectory) { $this->filterNamespaceToDirectory = new FilterChain(); $this->filterNamespaceToDirectory->attachByName('wordseparatortoseparator', ['search_separator' => '\\', 'replacement_separator' => '|']); $this->filterNamespaceToDirectory->attachByName('wordseparatortoseparator', ['search_separator' => '|', 'replacement_separator' => DIRECTORY_SEPARATOR]); } return $this->filterNamespaceToDirectory; }
/** * Retrieve the filter chain for generating the route name * * @return FilterChain */ protected function getRouteNameFilter() { if ($this->routeNameFilter instanceof FilterChain) { return $this->routeNameFilter; } $this->routeNameFilter = new FilterChain(); $this->routeNameFilter->attachByName(CamelCaseToDash::class)->attachByName(StringToLower::class); return $this->routeNameFilter; }
/** * Retrieve and/or initialize the normalization filter chain * * @return FilterChain */ protected function getNormalizationFilter() { if ($this->filter instanceof FilterChain) { return $this->filter; } $this->filter = new FilterChain(); $this->filter->attachByName('WordCamelCaseToDash')->attachByName('StringToLower'); return $this->filter; }
/** * Get current input filter factory * * If none provided, uses an unconfigured instance. * * @return InputFilterFactory */ public function getInputFilterFactory() { $inputFilterFactory = parent::getInputFilterFactory(); if (!$this->inputFilterFactoryDefaultsInitialized) { $this->inputFilterFactoryDefaultsInitialized = true; $dfc = $inputFilterFactory->getDefaultFilterChain(); $dvc = $inputFilterFactory->getDefaultValidatorChain(); if (empty($dfc)) { $inputFilterFactory->setDefaultFilterChain($dfc = new FilterChain()); } if (empty($dvc)) { $inputFilterFactory->setDefaultValidatorChain($dvc = new ValidatorChain()); } $initializer = array($this, 'initializeApplicationServiceLocators'); $dfc->getPluginManager()->addInitializer($initializer, false); $dvc->getPluginManager()->addInitializer($initializer, false); } return $inputFilterFactory; }
/** * 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 function extract($value) { $config = $this->getServiceManager()->get('Config'); if (!method_exists($value, 'getTypeClass') || !isset($config['zf-hal']['metadata_map'][$value->getTypeClass()->name])) { return; } $config = $config['zf-hal']['metadata_map'][$value->getTypeClass()->name]; $mapping = $value->getMapping(); $filter = new FilterChain(); $filter->attachByName('WordCamelCaseToUnderscore')->attachByName('StringToLower'); $link = new Link($filter($mapping['fieldName'])); $link->setRoute($config['route_name']); $link->setRouteParams(array('id' => null)); if (isset($config['zf-doctrine-querybuilder-options']['filter_key'])) { $filterKey = $config['zf-doctrine-querybuilder-options']['filter_key']; } else { $filterKey = 'filter'; } $link->setRouteOptions(array('query' => array($filterKey => array(array('field' => $mapping['mappedBy'], 'type' => 'eq', 'value' => $value->getOwner()->getId()))))); return $link; }
public function extract($value) { if (!method_exists($value, 'getTypeClass')) { return; } $config = $this->getMetadataMap()[$value->getTypeClass()->name]; $filter = new FilterChain(); $filter->attachByName('WordCamelCaseToUnderscore')->attachByName('StringToLower'); // Better way to create mapping name? // FIXME: use zf-hal collection_name $link = new Link('self'); $link->setRoute($config['route_name']); $link->setRouteParams(array('id' => null)); $filterValue = array('field' => $value->getMapping()['mappedBy'] ?: $value->getMapping()['inversedBy'], 'type' => isset($value->getMapping()['joinTable']) ? 'ismemberof' : 'eq', 'value' => $value->getOwner()->getId()); $link->setRouteOptions(array('query' => array($this->getFilterKey() => array($filterValue)))); $linkCollection = new LinkCollection(); $linkCollection->add($link); $halEntity = new HalEntity(new stdClass()); $halEntity->setLinks($linkCollection); return $halEntity; }
public function testFactoryInjectsComposedFilterAndValidatorChainsIntoInputObjectsWhenCreatingNewInputFilterObjects() { $factory = new Factory(); $filterPlugins = new Filter\FilterPluginManager(); $validatorPlugins = new Validator\ValidatorPluginManager(); $filterChain = new Filter\FilterChain(); $validatorChain = new Validator\ValidatorChain(); $filterChain->setPluginManager($filterPlugins); $validatorChain->setPluginManager($validatorPlugins); $factory->setDefaultFilterChain($filterChain); $factory->setDefaultValidatorChain($validatorChain); $inputFilter = $factory->createInputFilter(array('foo' => array('name' => 'foo'))); $this->assertInstanceOf('Zend\\InputFilter\\InputFilterInterface', $inputFilter); $this->assertEquals(1, count($inputFilter)); $input = $inputFilter->get('foo'); $this->assertInstanceOf('Zend\\InputFilter\\InputInterface', $input); $inputFilterChain = $input->getFilterChain(); $inputValidatorChain = $input->getValidatorChain(); $this->assertSame($filterPlugins, $inputFilterChain->getPluginManager()); $this->assertSame($validatorPlugins, $inputValidatorChain->getPluginManager()); }
/** * 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; } }
public function testBuildOrmApi() { $serviceManager = $this->getApplication()->getServiceManager(); $em = $serviceManager->get('doctrine.entitymanager.orm_default'); $tool = new SchemaTool($em); $res = $tool->createSchema($em->getMetadataFactory()->getAllMetadata()); // Create DB $resource = $serviceManager->get('ZF\\Apigility\\Doctrine\\Admin\\Model\\DoctrineRestServiceResource'); $artistResourceDefinition = array("objectManager" => "doctrine.entitymanager.orm_default", "serviceName" => "Artist", "entityClass" => "ZFTestApigilityDb\\Entity\\Artist", "routeIdentifierName" => "artist_id", "entityIdentifierName" => "id", "routeMatch" => "/test/rest/artist", "collectionHttpMethods" => array(0 => 'GET', 1 => 'POST', 2 => 'PATCH', 3 => 'DELETE')); $artistResourceDefinitionWithNonKeyIdentifer = array("objectManager" => "doctrine.entitymanager.orm_default", "serviceName" => "ArtistByName", "entityClass" => "ZFTestApigilityDb\\Entity\\Artist", "routeIdentifierName" => "artist_name", "entityIdentifierName" => "name", "routeMatch" => "/test/rest/artist-by-name", "collectionHttpMethods" => array(0 => 'GET')); // This route is what should be an rpc service, but an user could do $albumResourceDefinition = array("objectManager" => "doctrine.entitymanager.orm_default", "serviceName" => "Album", "entityClass" => "ZFTestApigilityDb\\Entity\\Album", "routeIdentifierName" => "album_id", "entityIdentifierName" => "id", "routeMatch" => "/test/rest[/artist/:artist_id]/album[/:album_id]", "collectionHttpMethods" => array(0 => 'GET', 1 => 'POST', 2 => 'PATCH', 3 => 'DELETE')); $resource->setModuleName('ZFTestApigilityDbApi'); $artistEntity = $resource->create($artistResourceDefinition); $artistEntity = $resource->create($artistResourceDefinitionWithNonKeyIdentifer); $albumEntity = $resource->create($albumResourceDefinition); $this->assertInstanceOf('ZF\\Apigility\\Doctrine\\Admin\\Model\\DoctrineRestServiceEntity', $artistEntity); $this->assertInstanceOf('ZF\\Apigility\\Doctrine\\Admin\\Model\\DoctrineRestServiceEntity', $albumEntity); // Build relation $filter = new FilterChain(); $filter->attachByName('WordCamelCaseToUnderscore')->attachByName('StringToLower'); $em = $serviceManager->get('doctrine.entitymanager.orm_default'); $metadataFactory = $em->getMetadataFactory(); $entityMetadata = $metadataFactory->getMetadataFor("ZFTestApigilityDb\\Entity\\Artist"); $rpcServiceResource = $serviceManager->get('ZF\\Apigility\\Doctrine\\Admin\\Model\\DoctrineRpcServiceResource'); $rpcServiceResource->setModuleName('ZFTestApigilityDbApi'); foreach ($entityMetadata->associationMappings as $mapping) { switch ($mapping['type']) { case 4: $rpcServiceResource->create(array('service_name' => 'Artist' . $mapping['fieldName'], 'route' => '/test/artist[/:parent_id]/' . $filter($mapping['fieldName']) . '[/:child_id]', 'http_methods' => array('GET', 'PUT', 'POST'), 'options' => array('target_entity' => $mapping['targetEntity'], 'source_entity' => $mapping['sourceEntity'], 'field_name' => $mapping['fieldName']), 'selector' => 'custom selector')); break; default: break; } } }
/** * @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); }