本文整理汇总了PHP中Zend\Stdlib\ArrayUtils类的典型用法代码示例。如果您正苦于以下问题:PHP ArrayUtils类的具体用法?PHP ArrayUtils怎么用?PHP ArrayUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ArrayUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: forwardAction
public function forwardAction()
{
$alias = $this->params('alias');
$instance = $this->getInstanceManager()->getInstanceFromRequest();
try {
$location = $this->aliasManager->findCanonicalAlias($alias, $instance);
$this->redirect()->toUrl($location);
$this->getResponse()->setStatusCode(301);
return false;
} catch (CanonicalUrlNotFoundException $e) {
}
try {
$source = $this->aliasManager->findSourceByAlias($alias);
} catch (AliasNotFoundException $e) {
$this->getResponse()->setStatusCode(404);
return false;
}
$router = $this->getServiceLocator()->get('Router');
$request = new Request();
$request->setMethod(Request::METHOD_GET);
$request->setUri($source);
$routeMatch = $router->match($request);
if ($routeMatch === null) {
$this->getResponse()->setStatusCode(404);
return false;
}
$this->getEvent()->setRouteMatch($routeMatch);
$params = $routeMatch->getParams();
$controller = $params['controller'];
$return = $this->forward()->dispatch($controller, ArrayUtils::merge($params, ['forwarded' => true]));
return $return;
}
示例2: factory
/**
* Create and return a StorageInterface instance
*
* @param string $type
* @param array|Traversable $options
* @return StorageInterface
* @throws Exception\InvalidArgumentException for unrecognized $type or individual options
*/
public static function factory($type, $options = array())
{
if (!is_string($type)) {
throw new Exception\InvalidArgumentException(sprintf('%s expects the $type argument to be a string class name; received "%s"', __METHOD__, is_object($type) ? get_class($type) : gettype($type)));
}
if (!class_exists($type)) {
$class = __NAMESPACE__ . '\\' . $type;
if (!class_exists($class)) {
throw new Exception\InvalidArgumentException(sprintf('%s expects the $type argument to be a valid class name; received "%s"', __METHOD__, $type));
}
$type = $class;
}
if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
}
if (!is_array($options)) {
throw new Exception\InvalidArgumentException(sprintf('%s expects the $options argument to be an array or Traversable; received "%s"', __METHOD__, is_object($options) ? get_class($options) : gettype($options)));
}
switch (true) {
case in_array('Zend\\Session\\Storage\\AbstractSessionArrayStorage', class_parents($type)):
return static::createSessionArrayStorage($type, $options);
break;
case $type === 'Zend\\Session\\Storage\\ArrayStorage':
case in_array('Zend\\Session\\Storage\\ArrayStorage', class_parents($type)):
return static::createArrayStorage($type, $options);
break;
case in_array('Zend\\Session\\Storage\\StorageInterface', class_implements($type)):
return new $type($options);
break;
default:
throw new Exception\InvalidArgumentException(sprintf('Unrecognized type "%s" provided; expects a class implementing %s\\StorageInterface', $type, __NAMESPACE__));
}
}
示例3: init
public static function init()
{
// Load the user-defined test configuration file, if it exists; otherwise, load
if (is_readable(__DIR__ . '/TestConfig.php')) {
$testConfig = (include __DIR__ . '/TestConfig.php');
} else {
$testConfig = (include __DIR__ . '/TestConfig.php.dist');
}
$zf2ModulePaths = array();
if (isset($testConfig['module_listener_options']['module_paths'])) {
$modulePaths = $testConfig['module_listener_options']['module_paths'];
foreach ($modulePaths as $modulePath) {
if ($path = static::findParentPath($modulePath)) {
$zf2ModulePaths[] = $path;
}
}
}
$zf2ModulePaths = implode(PATH_SEPARATOR, $zf2ModulePaths) . PATH_SEPARATOR;
$zf2ModulePaths .= getenv('ZF2_MODULES_TEST_PATHS') ?: (defined('ZF2_MODULES_TEST_PATHS') ? ZF2_MODULES_TEST_PATHS : '');
static::initAutoloader();
// use ModuleManager to load this module and it's dependencies
$baseConfig = array('module_listener_options' => array('module_paths' => explode(PATH_SEPARATOR, $zf2ModulePaths)));
$config = ArrayUtils::merge($baseConfig, $testConfig);
$serviceManager = new ServiceManager(new ServiceManagerConfig());
$serviceManager->setService('ApplicationConfig', $config);
$serviceManager->get('ModuleManager')->loadModules();
static::$serviceManager = $serviceManager;
static::$config = $config;
}
示例4: factory
/**
* Create a captcha adapter instance
*
* @param array|Traversable $options
* @return AdapterInterface
* @throws Exception\InvalidArgumentException for a non-array, non-Traversable $options
* @throws Exception\DomainException if class is missing or invalid
*/
public static function factory($options)
{
if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
}
if (!is_array($options)) {
throw new Exception\InvalidArgumentException(sprintf('%s expects an array or Traversable argument; received "%s"', __METHOD__, is_object($options) ? get_class($options) : gettype($options)));
}
if (!isset($options['class'])) {
throw new Exception\DomainException(sprintf('%s expects a "class" attribute in the options; none provided', __METHOD__));
}
$class = $options['class'];
if (isset(static::$classMap[strtolower($class)])) {
$class = static::$classMap[strtolower($class)];
}
if (!class_exists($class)) {
throw new Exception\DomainException(sprintf('%s expects the "class" attribute to resolve to an existing class; received "%s"', __METHOD__, $class));
}
unset($options['class']);
if (isset($options['options'])) {
$options = $options['options'];
}
$captcha = new $class($options);
if (!$captcha instanceof AdapterInterface) {
throw new Exception\DomainException(sprintf('%s expects the "class" attribute to resolve to a valid Zend\\Captcha\\AdapterInterface instance; received "%s"', __METHOD__, $class));
}
return $captcha;
}
示例5: __construct
/**
* Sets validator options
*
* Mimetype to accept
* - NULL means default PHP usage by using the environment variable 'magic'
* - FALSE means disabling searching for mimetype, should be used for PHP 5.3
* - A string is the mimetype file to use
*
* @param string|array|Traversable $options
*/
public function __construct($options = null)
{
if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
} elseif (is_string($options)) {
$this->setMimeType($options);
$options = [];
} elseif (is_array($options)) {
if (isset($options['magicFile'])) {
$this->setMagicFile($options['magicFile']);
unset($options['magicFile']);
}
if (isset($options['enableHeaderCheck'])) {
$this->enableHeaderCheck($options['enableHeaderCheck']);
unset($options['enableHeaderCheck']);
}
if (array_key_exists('mimeType', $options)) {
$this->setMimeType($options['mimeType']);
unset($options['mimeType']);
}
// Handle cases where mimetypes are interspersed with options, or
// options are simply an array of mime types
foreach (array_keys($options) as $key) {
if (!is_int($key)) {
continue;
}
$this->addMimeType($options[$key]);
unset($options[$key]);
}
}
parent::__construct($options);
}
示例6: setData
public function setData($data)
{
if ($data instanceof Traversable) {
$data = ArrayUtils::iteratorToArray($data);
}
$isAts = isset($data['atsEnabled']) && $data['atsEnabled'];
$isUri = isset($data['uriApply']) && !empty($data['uriApply']);
$email = isset($data['contactEmail']) ? $data['contactEmail'] : '';
if ($isAts && $isUri) {
$data['atsMode']['mode'] = 'uri';
$data['atsMode']['uri'] = $data['uriApply'];
$uri = new Http($data['uriApply']);
if ($uri->getHost() == $this->host) {
$data['atsMode']['mode'] = 'intern';
}
} elseif ($isAts && !$isUri) {
$data['atsMode']['mode'] = 'intern';
} elseif (!$isAts && !empty($email)) {
$data['atsMode']['mode'] = 'email';
$data['atsMode']['email'] = $email;
} else {
$data['atsMode']['mode'] = 'none';
}
if (!array_key_exists('job', $data)) {
$data = array('job' => $data);
}
return parent::setData($data);
}
示例7: __construct
/**
* Sets validator options
*
* @param string|array|\Traversable $options
*/
public function __construct($options = null)
{
if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
}
$case = null;
if (1 < func_num_args()) {
$case = func_get_arg(1);
}
if (is_array($options)) {
if (isset($options['case'])) {
$case = $options['case'];
unset($options['case']);
}
if (!array_key_exists('extension', $options)) {
$options = array('extension' => $options);
}
} else {
$options = array('extension' => $options);
}
if ($case !== null) {
$options['case'] = $case;
}
parent::__construct($options);
}
示例8: __invoke
/**
* Create and return a NoRecordExists validator.
*
* @param ContainerInterface $container
* @param string $requestedName
* @param null|array $options
* @return NoRecordExists
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
if (isset($options['adapter'])) {
return new NoRecordExists(ArrayUtils::merge($options, ['adapter' => $container->get($options['adapter'])]));
}
return new NoRecordExists($options);
}
示例9: createService
/**
* Create service
*
* @param ServiceLocatorInterface $serviceLocator
* @return AdapterManager
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$config = $serviceLocator->get('config');
$config = $config['bsb_flysystem'];
$serviceConfig = isset($config['adapter_manager']['config']) ? $config['adapter_manager']['config'] : [];
$adapterMap = $this->adapterMap;
if (isset($config['adapter_map'])) {
$adapterMap = ArrayUtils::merge($this->adapterMap, $config['adapter_map']);
}
foreach ($config['adapters'] as $name => $adapterConfig) {
if (!isset($adapterConfig['type'])) {
throw new UnexpectedValueException(sprintf("Missing 'type' key for the adapter '%s' configuration", $name));
}
$type = strtolower($adapterConfig['type']);
foreach (array_keys($adapterMap) as $serviceKind) {
if (isset($adapterMap[$serviceKind][$type])) {
$serviceConfig[$serviceKind][$name] = $adapterMap[$serviceKind][$type];
if (isset($adapterConfig['shared'])) {
$serviceConfig['shared'][$name] = filter_var($adapterConfig['shared'], FILTER_VALIDATE_BOOLEAN);
}
continue 2;
}
}
throw new UnexpectedValueException(sprintf("Unknown adapter type '%s'", $type));
}
$serviceConfig = new Config($serviceConfig);
return new AdapterManager($serviceConfig);
}
示例10: __construct
/**
* Constructor
*
* @param array|Traversable $options
*/
public function __construct($options = array())
{
if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
}
if (!is_array($options)) {
throw new Exception\InvalidArgumentException('Invalid options provided');
}
if (!isset($options[self::AWS_ACCESS_KEY]) || !isset($options[self::AWS_SECRET_KEY])) {
throw new Exception\InvalidArgumentException('AWS keys not specified!');
}
try {
$this->_s3 = new AmazonS3($options[self::AWS_ACCESS_KEY], $options[self::AWS_SECRET_KEY]);
} catch (\ZendService\Amazon\S3\Exception $e) {
throw new Exception\RuntimeException('Error on create: ' . $e->getMessage(), $e->getCode(), $e);
}
if (isset($options[self::HTTP_ADAPTER])) {
$this->_s3->getHttpClient()->setAdapter($options[self::HTTP_ADAPTER]);
}
if (isset($options[self::BUCKET_NAME])) {
$this->_defaultBucketName = $options[self::BUCKET_NAME];
}
if (isset($options[self::BUCKET_AS_DOMAIN])) {
$this->_defaultBucketAsDomain = $options[self::BUCKET_AS_DOMAIN];
}
}
示例11: setData
/**
* Set the data
* @param array $data [description]
*/
public function setData(array $data)
{
if (ArrayUtils::isHashTable($data)) {
$data = array($data);
}
$this->data = $data;
}
示例12: create
/**
* @param array $spec
* @return TransportInterface
* @throws Exception\InvalidArgumentException
* @throws Exception\DomainException
*/
public static function create($spec = array())
{
if ($spec instanceof Traversable) {
$spec = ArrayUtils::iteratorToArray($spec);
}
if (!is_array($spec)) {
throw new Exception\InvalidArgumentException(sprintf('%s expects an array or Traversable argument; received "%s"', __METHOD__, is_object($spec) ? get_class($spec) : gettype($spec)));
}
$type = isset($spec['type']) ? $spec['type'] : 'sendmail';
$normalizedType = strtolower($type);
if (isset(static::$classMap[$normalizedType])) {
$type = static::$classMap[$normalizedType];
}
if (!class_exists($type)) {
throw new Exception\DomainException(sprintf('%s expects the "type" attribute to resolve to an existing class; received "%s"', __METHOD__, $type));
}
$transport = new $type();
if (!$transport instanceof TransportInterface) {
throw new Exception\DomainException(sprintf('%s expects the "type" attribute to resolve to a valid' . ' Zend\\Mail\\Transport\\TransportInterface instance; received "%s"', __METHOD__, $type));
}
if ($transport instanceof Smtp && isset($spec['options'])) {
$transport->setOptions(new SmtpOptions($spec['options']));
}
if ($transport instanceof File && isset($spec['options'])) {
$transport->setOptions(new FileOptions($spec['options']));
}
return $transport;
}
示例13: createModelFromConfigArrays
public function createModelFromConfigArrays(array $global, array $local)
{
$this->configWriter->toFile($this->globalConfigPath, $global);
$this->configWriter->toFile($this->localConfigPath, $local);
$mergedConfig = ArrayUtils::merge($global, $local);
$globalConfig = new ConfigResource($mergedConfig, $this->globalConfigPath, $this->configWriter);
$localConfig = new ConfigResource($mergedConfig, $this->localConfigPath, $this->configWriter);
$moduleEntity = $this->getMockBuilder('ZF\Apigility\Admin\Model\ModuleEntity')
->disableOriginalConstructor()
->getMock();
$moduleEntity->expects($this->any())
->method('getName')
->will($this->returnValue('Foo'));
$moduleEntity->expects($this->any())
->method('getVersions')
->will($this->returnValue(array(1,2)));
$moduleModel = $this->getMockBuilder('ZF\Apigility\Admin\Model\ModuleModel')
->disableOriginalConstructor()
->getMock();
$moduleModel->expects($this->any())
->method('getModules')
->will($this->returnValue(array('Foo' => $moduleEntity)));
return new AuthenticationModel($globalConfig, $localConfig, $moduleModel);
}
示例14: init
public static function init()
{
if (is_readable(__DIR__ . '/config.php')) {
$testConfig = (include __DIR__ . '/config.php');
} else {
$testConfig = (include __DIR__ . '/config.php.dist');
}
$moduleName = pathinfo(realpath(dirname(__DIR__)), PATHINFO_BASENAME);
if (defined('MODULE_NAME')) {
$moduleName = MODULE_NAME;
}
$zf2ModulePaths = array(dirname(dirname(__DIR__)));
if ($path = static::findParentPath('vendor')) {
$modulePaths[] = $path;
}
if (($path = static::findParentPath('module')) !== $modulePaths[0]) {
$modulePaths[] = $path;
}
if (isset($additionalModulePaths)) {
$zf2ModulePaths = array_merge($modulePaths, $additionalModulePaths);
} else {
$zf2ModulePaths = $modulePaths;
}
$zf2ModulePaths = implode(PATH_SEPARATOR, $zf2ModulePaths) . PATH_SEPARATOR;
static::initAutoloader();
$baseConfig = ['module_listener_options' => ['module_paths' => explode(PATH_SEPARATOR, $zf2ModulePaths)], 'modules' => [$moduleName]];
$config = ArrayUtils::merge($baseConfig, $testConfig);
$serviceManager = new ServiceManager(new ServiceManagerConfig());
$serviceManager->setService('ApplicationConfig', $config);
$serviceManager->get('ModuleManager')->loadModules();
static::$serviceManager = $serviceManager;
}
示例15: __construct
/**
* Class constructor
*
* @param string|array|Traversable $options (Optional) Options to set, if null mcrypt is used
*/
public function __construct($options = null)
{
if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
}
$this->setAdapter($options);
}