当前位置: 首页>>代码示例>>PHP>>正文


PHP ArrayUtils::filter方法代码示例

本文整理汇总了PHP中Zend\Stdlib\ArrayUtils::filter方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayUtils::filter方法的具体用法?PHP ArrayUtils::filter怎么用?PHP ArrayUtils::filter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Stdlib\ArrayUtils的用法示例。


在下文中一共展示了ArrayUtils::filter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onRoute

 public function onRoute(MvcEvent $event)
 {
     $route = $event->getRouteMatch();
     $request = $event->getRequest();
     $app = $event->getApplication();
     $serviceManager = $app->getServiceManager();
     $config = $serviceManager->get('Config');
     if ($request instanceof Request) {
         // Set translator locale.
         if (is_array($config) && isset($config['translator'])) {
             $translator = $serviceManager->get('translator');
             $translatorConfig = $config['translator'];
             $session = new Container('language');
             $language = $translatorConfig['locale']['default'];
             if (isset($session->language)) {
                 $language = $session->language;
             }
             $language = $request->getQuery('language', $language);
             if (isset($translatorConfig['available']) && array_key_exists($language, $translatorConfig['available'])) {
                 $translator->setLocale($language);
                 $session->language = $language;
                 $route->setParam('language', $language);
             }
         }
         // Set default route pagination and order params.
         $route->setParam('page', (int) $request->getQuery('page', $route->getParam('page', 1)));
         $route->setParam('length', (int) $request->getQuery('length', $route->getParam('length', 10)));
         $route->setParam('order_by', $request->getQuery('order_by', $route->getParam('order_by')));
         $route->setParam('order', $request->getQuery('order', $route->getParam('order', 'ASC')));
         // Clean up dynamic filters.
         $filters = (array) $request->getQuery('filters', array());
         ArrayUtils::filter($filters, 'is_string');
         $route->setParam('filters', $filters);
     }
 }
开发者ID:kashandarash,项目名称:blog-example,代码行数:35,代码来源:Module.php

示例2: onRoute

 public function onRoute(MvcEvent $event)
 {
     $route = $event->getRouteMatch();
     $request = $event->getRequest();
     if ($request instanceof Request) {
         // Set default route pagination and order params.
         $route->setParam('page', (int) $request->getQuery('page', $route->getParam('page', 1)));
         $route->setParam('length', (int) $request->getQuery('length', $route->getParam('length', 10)));
         $route->setParam('order_by', $request->getQuery('order_by', $route->getParam('order_by')));
         $route->setParam('order', $request->getQuery('order', $route->getParam('order', 'ASC')));
         // Clean up dynamic filters.
         $filters = (array) $request->getQuery('filters', array());
         ArrayUtils::filter($filters, 'is_string');
         $route->setParam('filters', $filters);
     }
 }
开发者ID:jorgik1,项目名称:blog-example,代码行数:16,代码来源:Module.php

示例3: _updateUser

 /**
  * @param  User    $user
  * @param  array   $newData
  * @param  boolean $override (Optional) TRUE to override old data or FALSE to complete missing
  * @return User
  */
 protected function _updateUser(User $user, array $newData, $override = true)
 {
     $sm = $this->getServiceLocator();
     // FIXME should use aliases but not reference to API module
     /** @var $hydrator \Zend\Stdlib\Hydrator\HydratorInterface */
     $hydrator = $sm->get('HydratorManager')->get('Api\\V1\\Rest\\User\\UserHydrator');
     // filter the data array
     $newData = ArrayUtils::filter($newData, function ($value, $key) {
         return in_array($key, array('email', 'birthday', 'firstname', 'lastname', 'gender')) && !empty($value);
     }, ArrayUtils::ARRAY_FILTER_USE_BOTH);
     // retrieve and filter current values
     $oldData = $hydrator->extract($user);
     $oldData = ArrayUtils::filter($oldData, function ($value, $key) {
         return in_array($key, array('email', 'birthday', 'firstname', 'lastname', 'gender')) && !empty($value);
     }, ArrayUtils::ARRAY_FILTER_USE_BOTH);
     $data = $override ? ArrayUtils::merge($oldData, $newData) : ArrayUtils::merge($newData, $oldData);
     $user = $hydrator->hydrate($data, $user);
     return $user;
 }
开发者ID:bvoronov,项目名称:examples,代码行数:25,代码来源:CredentialsAdapterAbstract.php


注:本文中的Zend\Stdlib\ArrayUtils::filter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。