當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。