/** * Inject Table defined by type to PizzaService when triggered * * @param EventInterface */ public function onTableSet(EventInterface $e) { $type = $e->getParam('type', 'rentals'); $tableName = StaticFilter::execute($type, 'wordunderscoretocamelcase'); $service = $this->serviceLocator->get('Rentals\\Service\\Rentals'); $form = $this->serviceLocator->get('Rentals\\Table\\' . $tableName); $service->setTable($form, $type); }
public function onBootstrap(MvcEvent $e) { $eventManager = $e->getApplication()->getEventManager(); $moduleRouteListener = new ModuleRouteListener(); $moduleRouteListener->attach($eventManager); StaticFilter::getPluginManager()->setInvokableClass("CreateLinkFriendly", "\\ZendVN\\Filter\\CreateLinkFriendly"); StaticFilter::getPluginManager()->setInvokableClass("Purifier", "\\ZendVN\\Filter\\Purifier"); }
public function onBootstrap(MvcEvent $e) { $eventManager = $e->getApplication()->getEventManager(); $moduleRouteListener = new ModuleRouteListener(); $moduleRouteListener->attach($eventManager); $filterPlugin = StaticFilter::getPluginManager(); $filterPlugin->setInvokableClass('CreateURLFriendly', '\\ZendVN\\Filter\\CreateURLFriendly'); $filterPlugin->setInvokableClass('RemoveCircumflex', '\\ZendVN\\Filter\\RemoveCircumflex'); $filterPlugin->setInvokableClass('Purifier', '\\ZendVN\\Filter\\Purifier'); }
/** * @internal */ public function onBootstrap(\Zend\EventManager\EventInterface $e) { $serviceManager = $e->getApplication()->getServiceManager(); // Register form element view helpers $formElementHelper = $serviceManager->get('ViewHelperManager')->get('formElement'); $formElementHelper->addClass('Library\\Form\\Element\\SelectSimple', 'FormSelectSimple'); $formElementHelper->addType('select_untranslated', 'FormSelectUntranslated'); \Zend\Filter\StaticFilter::setPluginManager($serviceManager->get('FilterManager')); \Zend\Validator\StaticValidator::setPluginManager($serviceManager->get('ValidatorManager')); }
public function cityAction() { $id = StaticFilter::execute($this->params()->fromRoute('id'), ToInt::class); $city = $this->worldService->getCityById($id); if (!$city) { throw new \Exception('No City found with ID ' . $id); } $country = $this->worldService->getCountryByCode($city->getCountryCode()); return new ViewModel(['city' => $city, 'country' => $country]); }
/** * Manage database schema */ public function schemaManagerAction() { $request = $this->getRequest(); // Set up logger. Log level is already validated by route. $priority = \Zend\Filter\StaticFilter::execute($request->getParam('loglevel', 'info'), 'Library\\LogLevel'); $writer = new \Zend\Log\Writer\Stream('php://stderr'); $writer->addFilter('priority', array('priority' => $priority)); $writer->setFormatter('simple', array('format' => '%priorityName%: %message%')); $this->_logger->addWriter($writer); $this->_schemaManager->updateAll($request->getParam('prune')); }
/** * Test filter() method */ public function testFilter() { // 2 common example characters $enDashBad = ""; $enDashGood = "–"; $tmBad = ""; $tmGood = "™"; // Test 1 character twice to check repeated replacements $input = $enDashBad . $tmBad . $enDashBad; $expected = $enDashGood . $tmGood . $enDashGood; $this->assertEquals($expected, \Zend\Filter\StaticFilter::execute($input, 'Library\\FixEncodingErrors')); }
public function exchangeArray(array $array) { foreach ($array as $key => $value) { if (empty($value)) { continue; } $method = 'set' . StaticFilter::execute($key, 'wordunderscoretocamelcase'); if (!method_exists($this, $method)) { continue; } $this->{$method}($value); } }
/** * Listen to the bootstrap event * * @param MvcEvent $e * * @return void */ public function onBootstrap(EventInterface $e) { // attach module listener $eventManager = $e->getApplication()->getEventManager(); $moduleRouteListener = new ModuleRouteListener(); $moduleRouteListener->attach($eventManager); // add application listener $eventManager->attachAggregate(new ApplicationListener()); // configure session // $e->getApplication()->getServiceManager()->get('Session\Config'); // add StringToUrl filter to StaticFilter StaticFilter::getPluginManager()->setInvokableClass('stringToUrl', 'Application\\Filter\\StringToUrl'); }
/** * Generate an array copy from property values */ public function getArrayCopy() { $data = []; foreach (get_object_vars($this) as $key => $value) { $getMethod = 'get' . ucfirst($key); $arrayKey = StaticFilter::execute($key, 'WordCamelCaseToUnderscore'); $arrayKey = StaticFilter::execute($arrayKey, 'StringToLower'); if (method_exists($this, $getMethod)) { $data[$arrayKey] = $this->{$getMethod}(); } } return $data; }
public function onBootstrap(MvcEvent $e) { $eventManager = $e->getApplication()->getEventManager(); $moduleRouteListener = new ModuleRouteListener(); $moduleRouteListener->attach($eventManager); $filterPlugin = StaticFilter::getPluginManager(); $filterPlugin->setInvokableClass('CreateURLFriendly', '\\ZendVN\\Filter\\CreateURLFriendly'); $filterPlugin->setInvokableClass('RemoveCircumflex', '\\ZendVN\\Filter\\RemoveCircumflex'); $filterPlugin->setInvokableClass('Purifier', '\\ZendVN\\Filter\\Purifier'); $serviceManager = $e->getApplication()->getServiceManager(); $eventManager = $e->getApplication()->getEventManager(); /** Thay đổi thông báo lỗi =)) hehe */ //* $eventManager->attach('dispatch',array($this, 'loadConfig'));*/ /* $eventManager->attach('render',array($this, 'setTitle')); */ }
/** * Create a new DB-Connected REST service * * @param DbConnectedRestServiceEntity $entity * @return DbConnectedRestServiceEntity */ public function createService(DbConnectedRestServiceEntity $entity) { $restModel = $this->restModel; $resourceName = StaticFilter::execute($entity->tableName, 'WordUnderscoreToCamelCase'); $resourceClass = sprintf( '%s\\V%s\\Rest\\%s\\%sResource', $this->restModel->module, $this->restModel->moduleEntity->getLatestVersion(), $resourceName, $resourceName ); $controllerService = $restModel->createControllerServiceName($resourceName); $entityClass = $restModel->createEntityClass($resourceName, 'entity-db-connected'); $collectionClass = $restModel->createCollectionClass($resourceName); $routeName = $restModel->createRoute( $resourceName, $entity->routeMatch, $entity->routeIdentifierName, $controllerService ); $mediaType = $restModel->createMediaType(); $entity->exchangeArray(array( 'collection_class' => $collectionClass, 'controller_service_name' => $controllerService, 'entity_class' => $entityClass, 'module' => $restModel->module, 'resource_class' => $resourceClass, 'route_name' => $routeName, 'accept_whitelist' => array( $mediaType, 'application/hal+json', 'application/json', ), 'content_type_whitelist' => array( $mediaType, 'application/json', ), )); $restModel->createRestConfig($entity, $controllerService, $resourceClass, $routeName); $restModel->createContentNegotiationConfig($entity, $controllerService); $restModel->createHalConfig($entity, $entityClass, $collectionClass, $routeName); $this->createDbConnectedConfig($entity); return $entity; }
public function filter($value) { /** cach 01 */ // $filterChain = new \Zend\Filter\FilterChain(); // $filterChain // ->attach(new \Zend\I18n\Filter\Alnum(true)) // ->attach(new \Zend\Filter\StringTrim()) // ->attach(new \Zend\Filter\PregReplace(array( // 'pattern' => '#\s+#', // 'replacement' => ' ' // ))) // ->attach(new \ZendVN\Filter\RemoveCircumflex()) // ->attach(new \Zend\Filter\StringToLower()) // ->attach(new \Zend\Filter\Word\SeparatorToDash()) // ; // return $filterChain->filter($value); $output = \Zend\Filter\StaticFilter::execute($value, 'alnum'); return $output; }
public function onBootstrap(MvcEvent $e) { $eventManager = $e->getApplication()->getEventManager(); $serviceManager = $e->getApplication()->getServiceManager(); $moduleRouteListener = new ModuleRouteListener(); $moduleRouteListener->attach($eventManager); StaticFilter::getPluginManager()->setInvokableClass("Callback", "\\ZendVN\\Event\\Callback"); $eventManager->attach(new \ZendVN\Event\ShowInfoListener()); //create Router $literal = \Zend\Mvc\Router\Http\Literal::factory(array('route' => '/new-way.html', 'defaults' => array('__NAMESPACE__' => 'Mvc\\Controller', 'controller' => 'Router', 'action' => 'contact'))); $route = $e->getRouter(); $route->addRoute('newway', $literal); //set private template Error //$eventManager->attach("dispatch",array($this,"loadError")); //$eventManager->attach("render",array($this,"setTitle")); //$serviceManager->setInvokableClass("YourService","Mvc\Service\UserService"); //set Service on Module.php //userService = $serviceManager->get("socialservice"); // $userService2 = $serviceManager->get("MSU"); // echo "<pre style='font-weight:bold'>"; // print_r($userService); // echo "</pre>"; // if($serviceManager->has("Mvc\Service\FaceBook")){ // $facebookService = $serviceManager->get("Mvc\Service\FaceBook"); // echo "<pre style='font-weight:bold'>"; // print_r($facebookService); // echo "</pre>"; // }else{ // echo "Not exists this Service"; // } // $showInfoListener = new \ZendVN\Event\ShowInfoListener(); // $showInfoListener->attach($eventManager); //set sharedEventManager // $shareEventManager = $eventManager->getSharedManager(); // $shareEventManager->attach("ZendVN\Event\Foo","showInfo",function($e){ // echo "<h3 style='color:red;font-weight:bold'>showInfo - do 1</h3>"; // echo "<pre style='font-weight:bold'>"; // print_r($e->getParams()); // echo "</pre>"; // }); }
/** * @internal */ public function onBootstrap(\Zend\EventManager\EventInterface $e) { \Zend\Filter\StaticFilter::getPluginManager()->setInvokableClass('Library\\FixEncodingErrors', 'Library\\Filter\\FixEncodingErrors'); $serviceManager = $e->getApplication()->getServiceManager(); // Register form element view helpers $formElementHelper = $serviceManager->get('ViewHelperManager')->get('formElement'); $formElementHelper->addClass('Library\\Form\\Element\\SelectSimple', 'formselectsimple'); $formElementHelper->addType('select_untranslated', 'formselectuntranslated'); if (\Locale::getPrimaryLanguage(\Locale::getDefault()) != 'en') { $mvcTranslator = $serviceManager->get('MvcTranslator'); if (Application::isDevelopment()) { $translator = $mvcTranslator->getTranslator(); $translator->enableEventManager(); $translator->getEventManager()->attach(\Zend\I18n\Translator\Translator::EVENT_MISSING_TRANSLATION, array($this, 'onMissingTranslation')); } // Validators have no translator by default. Attach translator, but // use a different text domain to avoid warnings if the Zend // translations are not loaded. For custom messages, the text domain // must be reset manually to 'default' for individual validators. \Zend\Validator\AbstractValidator::setDefaultTranslator($mvcTranslator); \Zend\Validator\AbstractValidator::setDefaultTranslatorTextDomain('Zend'); } }
public function onBootstrap(EventInterface $e) { // get managers $eventManager = $e->getApplication()->getEventManager(); /* $eventManager->attach( 'render', array($this, 'registerJsonStrategy'), 100 ); */ $serviceManager = $e->getApplication()->getServiceManager(); // attach module listener $moduleRouteListener = new ModuleRouteListener(); $moduleRouteListener->attach($eventManager); // add application listener /* if ($e->getRequest()) { $uri = $e->getRequest()->getUri(); if (false === strpos($uri, 'json')) { $eventManager->attachAggregate(new ApplicationListener()); } } */ $eventManager->attachAggregate(new ApplicationListener()); // get config $config = $serviceManager->get('config'); // configure session $sessionConfig = new SessionConfig(); $sessionConfig->setOptions($config['session']); // get filter and validator manager $filterManager = $serviceManager->get('FilterManager'); $validatorManager = $serviceManager->get('ValidatorManager'); // add custom filters and validators StaticFilter::setPluginManager($filterManager); StaticValidator::setPluginManager($validatorManager); }
/** * Filter dash to camel case * * @param string $text * * @return string */ public function filterDashToCamelCase($text) { $text = StaticFilter::execute($text, 'Word\\DashToCamelCase'); return $text; }
/** * Filter camel case to underscore * * @param string $text * * @return string */ protected function filterCamelCaseToUnderscore($text) { $text = StaticFilter::execute($text, 'Word\\CamelCaseToUnderscore'); $text = StaticFilter::execute($text, 'StringToLower'); return $text; }
/** * @param $module * @param $version * @param $tableName * @return bool */ protected function moduleHasService($module, $version, $tableName) { $resourceName = StaticFilter::execute($tableName, 'WordUnderscoreToCamelCase'); $resourceClass = sprintf('%s\\V%s\\Rest\\%s\\%sResource', $module, $version, $resourceName, $resourceName); return $this->getServiceLocator()->has($resourceClass); }
/** * Convert localized string representations to integer, float or date values * * Subclasses can support localized input formats by calling this method * from a filter. * * Non-string values get trimmed and converted to integer, float or * \DateTime, depending on $type. Invalid values are returned as string. The * input filter should validate filtered data by checking the datatype via * validateType(). * * @param string $value Localized input string * @param string $type Data type (integer, float, date). Any other value will be ignored. * @return mixed Normalized value or input string */ public function normalize($value, $type) { // Integers and floats are validated first to prevent successful parsing // of strings containing invalid characters with the invalid part simply // cut off. switch ($type) { case 'integer': $value = trim($value); if (\Zend\Validator\StaticValidator::execute($value, 'Zend\\I18n\\Validator\\IsInt')) { $value = \Zend\Filter\StaticFilter::execute($value, 'Zend\\I18n\\Filter\\NumberParse', array('type' => \NumberFormatter::TYPE_INT32)); } break; case 'float': $value = trim($value); if (\Zend\Validator\StaticValidator::execute($value, 'Zend\\I18n\\Validator\\IsFloat')) { $value = \Zend\Filter\StaticFilter::execute($value, 'Zend\\I18n\\Filter\\NumberParse', array('type' => \NumberFormatter::TYPE_DOUBLE)); } break; case 'date': $value = trim($value); $validator = new \Zend\I18n\Validator\DateTime(); $validator->setDateType(\IntlDateFormatter::SHORT); if ($validator->isValid($value)) { // Some systems accept invalid date separators, like '/' // with a de_DE locale which should accept only '.'. // An extra comparision of the locale-specific pattern and // the input string is necessary. // This also enforces 4-digit years to avoid any confusion // with 2-digit year input. $pattern = preg_quote($validator->getPattern(), '#'); // Get the year part out of the way first. $pattern = preg_replace('/y+/', '§', $pattern); // Remaining letters are placeholders for digits. $pattern = preg_replace('/[a-zA-Z]+/', '\\d+', $pattern); // Set the year pattern. $pattern = str_replace('§', '\\d{4}', $pattern); if (preg_match("#^{$pattern}\$#", $value)) { $formatter = new \IntlDateFormatter(\Locale::getDefault(), \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE, 'UTC'); $value = \DateTime::createFromFormat('U', $formatter->parse($value)); } } break; } return $value; }
public function index23Action() { echo "<h3 style='color:red;font-weight:bold'>" . __METHOD__ . "</h3>"; $input = "www.zend.vn/ Khóa học lập trình Zend Framework \$#%#\$%@ cung CẤP kiến thức căn bản và chuyên sâu về Zend Framework"; $arr = explode(".vn/", $input); $output = $arr[0] . ".vn/" . StaticFilter::execute($arr[1], "CreateLinkFriendly") . ".html"; echo "<h2>Input: {$input}</h2><br>"; echo "<h2>Output :{$output}</h2>"; return false; }
public function index34Action() { $input = 'http://www.zend.vn/Khóa học lập trình Zend Framework !@#$%^&*()_+ cung cấp những kiển thức căn bản và chuyên sâu về Zend Framework'; // http://www.zend.vn/khoa-hoc-lap-trinh-zend-framework-cng-cap-nhung-kien-thuc-can-ban-va-chuyen-sau-ve-zend-framework.html $newArr = explode('.vn/', $input); $output = \Zend\Filter\StaticFilter::execute($newArr[1], 'CreateURL'); echo "<h3>" . $input . "</h3>"; echo "<h3>" . $newArr[0] . 'vn/' . $output . "</h3>"; return false; }
/** * @return array */ protected function fetchTableColumns() { $foreignKeys = []; /** @var ConstraintObject $tableConstraint */ foreach ($this->tableData['foreignKeys'] as $tableConstraint) { $foreignKeys[$tableConstraint->getColumns()[0]] = $tableConstraint->getReferencedTableName(); } $columns = []; /** @var $tableColumn ColumnObject */ foreach ($this->tableData['columns'] as $tableColumn) { if (isset($foreignKeys[$tableColumn->getName()])) { $type = ucfirst($foreignKeys[$tableColumn->getName()]) . 'Entity'; } else { switch ($tableColumn->getDataType()) { case 'varchar': case 'char': case 'tinytext': case 'text': case 'mediumtext': case 'longtext': case 'enum': case 'set': case 'datetime': case 'timestamp': $type = 'string'; break; case 'decimal': case 'float': case 'double': case 'real': $type = 'float'; break; default: $type = 'integer'; } } $name = lcfirst(StaticFilter::execute($tableColumn->getName(), 'Word\\UnderscoreToCamelCase')); $columns[$name] = $type; } return $columns; }
<?php /** * Display confirmation form for software blacklisting * * Copyright (C) 2011-2016 Holger Schletz <*****@*****.**> * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ print $this->formYesNo(sprintf($this->translate('Software \'%s\' will be no longer be displayed. Continue?'), $this->escapeHtml(\Zend\Filter\StaticFilter::execute($this->name, 'Library\\FixEncodingErrors'))));
/** * @requires PHP 7.0 */ public function testFilterInvalidInput() { $this->setExpectedException('InvalidArgumentException', 'Input does not appear to be a zlib stream'); \Zend\Filter\StaticFilter::execute('not a zlib stream', 'Protocol\\InventoryDecode'); }
/** * Filter underscore to camel case * * @param string $text * * @return string */ public function filterUnderscoreToCamelCase($text) { $text = StaticFilter::execute($text, 'Word\\UnderscoreToCamelCase'); return $text; }
/** * Save a blog * * @param array $data input data * @param integer $id id of blog entry * @return BlogEntityInterface */ public function save(array $data, $id = null) { // check mode $mode = is_null($id) ? 'create' : 'update'; // get blog entity if ($mode == 'create') { $blog = new BlogEntity(); } else { $blog = $this->fetchSingleById($id); } // get form and set data $form = $this->getForm($mode); $form->setData($data); // check for invalid data if (!$form->isValid()) { $this->setMessage('Bitte Eingaben überprüfen!'); return false; } // get valid blog entity object $blog->exchangeArray($form->getData()); // set values if ($mode == 'create') { $blog->setCdate(date('Y-m-d H:i:s')); } $blog->setUrl(StaticFilter::execute($blog->getTitle(), 'StringToUrl')); // get insert data $saveData = $blog->getArrayCopy(); // save blog try { if ($mode == 'create') { $this->getTable()->insert($saveData); // get last insert value $id = $this->getTable()->getLastInsertValue(); } else { $this->getTable()->update($saveData, array('id' => $id)); } } catch (InvalidQueryException $e) { $this->setMessage('Blogbeitrag wurde nicht gespeichert!'); return false; } // reload blog $blog = $this->fetchSingleById($id); // set success message $this->setMessage('Blogbeitrag wurde gespeichert!'); // return blog return $blog; }
/** * Ensures that if we specify a validator class basename that doesn't * exist in the namespace, get() throws an exception. * * Refactored to conform with ZF-2724. * * @group ZF-2724 */ public function testStaticFactoryClassNotFound() { $this->setExpectedException('\\Zend\\Filter\\Exception', 'not found'); StaticFilter::execute('1234', 'UnknownFilter'); }
public function testUsesDifferentConfigurationOnEachRequest() { $first = StaticFilter::execute('foo', 'callback', array('callback' => function ($value) { return 'FOO'; })); $second = StaticFilter::execute('foo', 'callback', array('callback' => function ($value) { return 'BAR'; })); $this->assertNotSame($first, $second); $this->assertEquals('FOO', $first); $this->assertEquals('BAR', $second); }
/** * Validator callback for subkeys input * * @internal * @param string $value * @param array $context * @return bool TRUE if 'name' is empty or 'name' and 'subkeys' are not empty */ public function validateEmptySubkeys($value, $context) { $name = \Zend\Filter\StaticFilter::execute($context['name'], 'StringTrim'); if ($name != '' and $value == '') { return false; } else { return true; } }