本文整理汇总了PHP中Zend\Filter\FilterChain::attachByName方法的典型用法代码示例。如果您正苦于以下问题:PHP FilterChain::attachByName方法的具体用法?PHP FilterChain::attachByName怎么用?PHP FilterChain::attachByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Filter\FilterChain
的用法示例。
在下文中一共展示了FilterChain::attachByName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCamelCaseToUnderscoreFilter
/**
* @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;
}
示例2: testDoctrineService
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;
}
}
}
示例3: testAllowsConnectingViaClassShortName
public function testAllowsConnectingViaClassShortName()
{
$chain = new FilterChain();
$chain->attachByName('string_trim', array('encoding' => 'utf-8'), 100)->attachByName('strip_tags')->attachByName('string_to_lower', array('encoding' => 'utf-8'), 900);
$value = '<a name="foo"> ABC </a>';
$valueExpected = 'abc';
$this->assertEquals($valueExpected, $chain->filter($value));
}
示例4: getNormalizationFilter
/**
* 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;
}
示例5: 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;
}
示例6: getRouteNameFilter
/**
* 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;
}
示例7: 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;
}
示例8: getRouteNameFilter
/**
* 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;
}
示例9: testAllowsConnectingViaClassShortName
public function testAllowsConnectingViaClassShortName()
{
if (!function_exists('mb_strtolower')) {
$this->markTestSkipped('mbstring required');
}
$chain = new FilterChain();
$chain->attachByName('string_trim', null, 100)->attachByName('strip_tags')->attachByName('string_to_lower', array('encoding' => 'utf-8'), 900);
$value = '<a name="foo"> ABC </a>';
$valueExpected = 'abc';
$this->assertEquals($valueExpected, $chain->filter($value));
}
示例10: extract
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;
}
示例11: extract
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;
}
示例12: testBuildOrmApi
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;
}
}
}
示例13: testClone
public function testClone()
{
$chain = new FilterChain();
$clone = clone $chain;
$chain->attachByName('strip_tags');
$this->assertCount(0, $clone);
}
示例14: index18Action
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;
}
示例15: populateFilters
/**
* @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');
}
}