本文整理汇总了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);
}
}
示例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);
}
}
示例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;
}