本文整理汇总了PHP中array_replace函数的典型用法代码示例。如果您正苦于以下问题:PHP array_replace函数的具体用法?PHP array_replace怎么用?PHP array_replace使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array_replace函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: transfer
/**
* {@inheritdoc}
*/
protected function transfer()
{
while (!$this->stopped && !$this->source->isConsumed()) {
if ($this->source->getContentLength() && $this->source->isSeekable()) {
// If the stream is seekable and the Content-Length known, then stream from the data source
$body = new ReadLimitEntityBody($this->source, $this->partSize, $this->source->ftell());
} else {
// We need to read the data source into a temporary buffer before streaming
$body = EntityBody::factory();
while ($body->getContentLength() < $this->partSize && $body->write($this->source->read(max(1, min(10 * Size::KB, $this->partSize - $body->getContentLength()))))) {
}
}
// @codeCoverageIgnoreStart
if ($body->getContentLength() == 0) {
break;
}
// @codeCoverageIgnoreEnd
$params = $this->state->getUploadId()->toParams();
$command = $this->client->getCommand('UploadPart', array_replace($params, array('PartNumber' => count($this->state) + 1, 'Body' => $body, 'ContentMD5' => (bool) $this->options['part_md5'], Ua::OPTION => Ua::MULTIPART_UPLOAD)));
// Notify observers that the part is about to be uploaded
$eventData = $this->getEventData();
$eventData['command'] = $command;
$this->dispatch(self::BEFORE_PART_UPLOAD, $eventData);
// Allow listeners to stop the transfer if needed
if ($this->stopped) {
break;
}
$response = $command->getResponse();
$this->state->addPart(UploadPart::fromArray(array('PartNumber' => count($this->state) + 1, 'ETag' => $response->getHeader('ETag', true), 'Size' => $body->getContentLength(), 'LastModified' => gmdate(DateFormat::RFC2822))));
// Notify observers that the part was uploaded
$this->dispatch(self::AFTER_PART_UPLOAD, $eventData);
}
}
示例2: __construct
/**
* Create new container
*
* @param array $values The parameters or objects.
*/
public function __construct(array $values = [])
{
// Initialize container for Slim and Pimple
parent::__construct($values);
$this['config'] = isset($values['config']) ? $values['config'] : [];
if (!isset($container['provider/factory'])) {
$this['provider/factory'] = function (Container $container) {
return new Factory(['base_class' => ServiceProviderInterface::class, 'resolver_options' => ['suffix' => 'ServiceProvider']]);
};
}
$defaults = ['charcoal/app/service-provider/app' => [], 'charcoal/app/service-provider/cache' => [], 'charcoal/app/service-provider/database' => [], 'charcoal/app/service-provider/logger' => [], 'charcoal/app/service-provider/translator' => [], 'charcoal/app/service-provider/view' => []];
if (!empty($this['config']['service_providers'])) {
$providers = array_replace($defaults, $this['config']['service_providers']);
} else {
$providers = $defaults;
}
foreach ($providers as $provider => $values) {
if (false === $values) {
continue;
}
if (!is_array($values)) {
$values = [];
}
$provider = $this['provider/factory']->get($provider);
$this->register($provider, $values);
}
}
示例3: executeRequest
/**
* Executing curl request
* @param array $additionalOptions
* @return mixed
*/
protected function executeRequest(array $additionalOptions)
{
$cookiesPath = __DIR__ . DIRECTORY_SEPARATOR . self::COOKIES_FILE_NAME;
$options = array_replace([CURLOPT_RETURNTRANSFER => true, CURLOPT_COOKIEFILE => $cookiesPath, CURLOPT_COOKIEJAR => $cookiesPath], $additionalOptions);
curl_setopt_array($this->ch, $options);
return curl_exec($this->ch);
}
示例4: setOptions
public function setOptions($optionsGiven)
{
$options = array_replace($this->getDefaults(), $optionsGiven);
$this->angle = $options["angle"];
$this->rotationPoint = $options["rotationPoint"];
$this->layer = $options["layer"];
}
示例5: preBind
public function preBind(FormEvent $event)
{
$form = $event->getForm();
$data = $event->getData();
$data = array_replace($this->unbind($form), $data ?: array());
$event->setData($data);
}
示例6: create
private static function create($uri, $method = 'GET', $server = array())
{
$server = array_replace(array('SERVER_NAME' => 'localhost', 'SERVER_PORT' => 80, 'HTTP_HOST' => 'localhost', 'HTTP_USER_AGENT' => 'PHP-routing request', 'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'HTTP_ACCEPT_LANGUAGE' => 'en-us,en;q=0.5', 'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'REMOTE_ADDR' => '127.0.0.1', 'SCRIPT_NAME' => '', 'SCRIPT_FILENAME' => '', 'SERVER_PROTOCOL' => 'HTTP/1.1', 'REQUEST_TIME' => time()), $server);
$server['REQUEST_URI'] = $uri;
$server['PATH_INFO'] = '';
$server['REQUEST_METHOD'] = strtoupper($method);
$components = parse_url($uri);
if (isset($components['host'])) {
$server['SERVER_NAME'] = $components['host'];
$server['HTTP_HOST'] = $components['host'];
}
if (isset($components['scheme'])) {
if ('https' === $components['scheme']) {
$server['HTTPS'] = 'on';
$server['SERVER_PORT'] = 443;
} else {
unset($server['HTTPS']);
$server['SERVER_PORT'] = 80;
}
}
if (isset($components['port'])) {
$server['SERVER_PORT'] = $components['port'];
$server['HTTP_HOST'] = $server['HTTP_HOST'] . ':' . $components['port'];
}
if (isset($components['user'])) {
$server['PHP_AUTH_USER'] = $components['user'];
}
if (isset($components['pass'])) {
$server['PHP_AUTH_PW'] = $components['pass'];
}
return new \Routing\Request($server);
}
示例7: format_json_message
/**
* 格式化表单校验消息,并进行json数组化预处理
*
* @param array $messages 未格式化之前数组
* @param array $json 原始json数组数据
* @return array
*/
function format_json_message($messages, $json)
{
$reason = format_message($messages);
$info = '失败原因为:' . $reason;
$json = array_replace($json, ['info' => $info]);
return $json;
}
示例8: toString
/**
* return token string
*
* @param string[] $token detected handlebars {{ }} token
* @param string[]|null $merge list of token strings to be merged
*
* @return string Return whole token
*
* @expect 'c' when input array(0, 'a', 'b', 'c', 'd', 'e')
* @expect 'cd' when input array(0, 'a', 'b', 'c', 'd', 'e', 'f')
* @expect 'qd' when input array(0, 'a', 'b', 'c', 'd', 'e', 'f'), array(3 => 'q')
*/
public static function toString($token, $merge = null)
{
if (is_array($merge)) {
$token = array_replace($token, $merge);
}
return implode('', array_slice($token, 3, -2));
}
示例9: register
public function register(Application $app)
{
$app['task-manager.logger'] = $app->share(function (Application $app) {
$logger = new $app['monolog.logger.class']('task-manager logger');
$logger->pushHandler(new NullHandler());
return $logger;
});
$app['task-manager'] = $app->share(function (Application $app) {
$options = $app['task-manager.listener.options'];
$manager = TaskManager::create($app['dispatcher'], $app['task-manager.logger'], $app['task-manager.task-list'], ['listener_protocol' => $options['protocol'], 'listener_host' => $options['host'], 'listener_port' => $options['port'], 'tick_period' => 1]);
$manager->addSubscriber($app['ws.task-manager.broadcaster']);
return $manager;
});
$app['task-manager.logger.configuration'] = $app->share(function (Application $app) {
$conf = array_replace(['enabled' => true, 'level' => 'INFO', 'max-files' => 10], $app['conf']->get(['main', 'task-manager', 'logger'], []));
$conf['level'] = defined('Monolog\\Logger::' . $conf['level']) ? constant('Monolog\\Logger::' . $conf['level']) : Logger::INFO;
return $conf;
});
$app['task-manager.task-list'] = $app->share(function (Application $app) {
$conf = $app['conf']->get(['registry', 'executables', 'php-conf-path']);
$finder = new PhpExecutableFinder();
$php = $finder->find();
return new TaskList($app['EM']->getRepository('Phraseanet:Task'), $app['root.path'], $php, $conf);
});
}
示例10: buildView
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars = array_replace($view->vars, array('allow_add' => $options['allow_add'], 'allow_delete' => $options['allow_delete']));
if ($form->getConfig()->hasAttribute('prototype')) {
$view->vars['prototype'] = $form->getConfig()->getAttribute('prototype')->createView($view);
}
}
示例11: buildView
public function buildView(TableView $view, TableInterface $table, array $options)
{
parent::buildView($view, $table, $options);
$view->vars['responsive'] = $options['responsive'];
$view->vars['attr'] = array('class' => $this->getElementClass($options));
$view->vars = array_replace($view->vars, array('value' => $table->getViewData(), 'data' => $table->getNormData()));
}
示例12: createConfig
/**
* {@inheritDoc}
*/
public function createConfig(array $config = array())
{
$config = ArrayObject::ensureArrayObject($config);
$config->defaults($this->defaultConfig);
$config->defaults(array('payum.template.layout' => '@PayumCore/layout.html.twig', 'payum.http_client' => HttpClientFactory::create(), 'guzzle.client' => HttpClientFactory::createGuzzle(), 'twig.env' => function (ArrayObject $config) {
$loader = new \Twig_Loader_Filesystem();
foreach ($config['payum.paths'] as $namespace => $path) {
$loader->addPath($path, $namespace);
}
return new \Twig_Environment($loader);
}, 'payum.action.get_http_request' => new GetHttpRequestAction(), 'payum.action.capture_payment' => new CapturePaymentAction(), 'payum.action.execute_same_request_with_model_details' => new ExecuteSameRequestWithModelDetailsAction(), 'payum.action.render_template' => function (ArrayObject $config) {
return new RenderTemplateAction($config['twig.env'], $config['payum.template.layout']);
}, 'payum.extension.endless_cycle_detector' => new EndlessCycleDetectorExtension(), 'payum.action.get_currency' => function (ArrayObject $config) {
return new GetCurrencyAction($config['payum.iso4217']);
}, 'payum.prepend_actions' => array(), 'payum.prepend_extensions' => array(), 'payum.prepend_apis' => array(), 'payum.default_options' => array(), 'payum.required_options' => array(), 'payum.api.http_client' => function (ArrayObject $config) {
return $config['payum.http_client'];
}, 'payum.security.token_storage' => null));
if ($config['payum.security.token_storage']) {
$config['payum.action.get_token'] = function (ArrayObject $config) {
return new GetTokenAction($config['payum.security.token_storage']);
};
}
$config['payum.paths'] = array_replace(['PayumCore' => __DIR__ . '/Resources/views'], $config['payum.paths'] ?: []);
return (array) $config;
}
示例13: flush
/**
* {@inheritdoc}
*
* Override of CsvWriter flush method to use the file buffer
*/
public function flush()
{
if (!is_file($this->bufferFile)) {
return;
}
$exportDirectory = dirname($this->getPath());
if (!is_dir($exportDirectory)) {
$this->localFs->mkdir($exportDirectory);
}
$this->writtenFiles[$this->getPath()] = basename($this->getPath());
if (false === ($csvFile = fopen($this->getPath(), 'w'))) {
throw new RuntimeErrorException('Failed to open file %path%', ['%path%' => $this->getPath()]);
}
$header = $this->isWithHeader() ? $this->headers : [];
if (false === fputcsv($csvFile, $header, $this->delimiter)) {
throw new RuntimeErrorException('Failed to write to file %path%', ['%path%' => $this->getPath()]);
}
$bufferHandle = fopen($this->bufferFile, 'r');
$hollowProduct = array_fill_keys($this->headers, '');
while (null !== ($bufferedProduct = $this->readProductFromBuffer($bufferHandle))) {
$fullProduct = array_replace($hollowProduct, $bufferedProduct);
if (false === fputcsv($csvFile, $fullProduct, $this->delimiter, $this->enclosure)) {
throw new RuntimeErrorException('Failed to write to file %path%', ['%path%' => $this->getPath()]);
} elseif (null !== $this->stepExecution) {
$this->stepExecution->incrementSummaryInfo('write');
}
}
fclose($bufferHandle);
unlink($this->bufferFile);
fclose($csvFile);
}
示例14: fix
/**
* {@inheritdoc}
*/
public function fix(\SplFileInfo $file, $content)
{
$tokens = Tokens::fromCode($content);
$namespacesImports = $tokens->getNamespaceUseIndexes(true);
$usesOrder = array();
if (!count($namespacesImports)) {
return $content;
}
foreach ($namespacesImports as $uses) {
$uses = array_reverse($uses);
$usesOrder = array_replace($usesOrder, $this->getNewOrder($uses, $tokens));
}
// First clean the old content
// This must be done first as the indexes can be scattered
foreach ($usesOrder as $use) {
for ($i = $use[1]; $i <= $use[2]; ++$i) {
$tokens[$i]->clear();
}
}
$usesOrder = array_reverse($usesOrder, true);
// Now insert the new tokens, starting from the end
foreach ($usesOrder as $index => $use) {
$declarationTokens = Tokens::fromCode('<?php use ' . $use[0] . ';');
$declarationTokens[0]->clear();
// <?php
$declarationTokens[1]->clear();
// use
$declarationTokens[2]->clear();
// space
$declarationTokens[count($declarationTokens) - 1]->clear();
// ;
$tokens->insertAt($index, $declarationTokens);
}
return $tokens->generateCode();
}
示例15: create
/**
* Create a transport.
*
* The $transport parameter can be one of the following values:
*
* * string: The short name of a transport. For instance "Http", "Memcache" or "Thrift"
* * object: An already instantiated instance of a transport
* * array: An array with a "type" key which must be set to one of the two options. All other
* keys in the array will be set as parameters in the transport instance
*
* @param mixed $transport A transport definition
* @param \Elastica\Connection $connection A connection instance
* @param array $params Parameters for the transport class
*
* @throws \Elastica\Exception\InvalidException
*
* @return AbstractTransport
*/
public static function create($transport, Connection $connection, array $params = array())
{
if (is_array($transport) && isset($transport['type'])) {
$transportParams = $transport;
unset($transportParams['type']);
$params = array_replace($params, $transportParams);
$transport = $transport['type'];
}
if (is_string($transport)) {
$className = 'Elastica\\Transport\\' . $transport;
if (!class_exists($className)) {
throw new InvalidException('Invalid transport');
}
$transport = new $className();
}
if ($transport instanceof self) {
$transport->setConnection($connection);
foreach ($params as $key => $value) {
$transport->setParam($key, $value);
}
} else {
throw new InvalidException('Invalid transport');
}
return $transport;
}