本文整理汇总了PHP中Cake\Utility\Hash::merge方法的典型用法代码示例。如果您正苦于以下问题:PHP Hash::merge方法的具体用法?PHP Hash::merge怎么用?PHP Hash::merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Utility\Hash
的用法示例。
在下文中一共展示了Hash::merge方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: toCake
/**
* Transform a PSR7 request into a CakePHP one.
*
* @param \Psr\Http\Message\ServerRequestInterface $request The PSR7 request.
* @return \Cake\Network\Request The transformed request.
*/
public static function toCake(PsrRequest $request)
{
$post = $request->getParsedBody();
$server = $request->getServerParams();
$files = static::getFiles($request);
if (!empty($files)) {
$post = Hash::merge($post, $files);
}
return new CakeRequest(['query' => $request->getQueryParams(), 'post' => $post, 'cookies' => $request->getCookieParams(), 'environment' => $server, 'params' => static::getParams($request), 'url' => $request->getUri()->getPath(), 'base' => $request->getAttribute('base', ''), 'webroot' => $request->getAttribute('webroot', '/')]);
}
示例2: __construct
/**
* Constructor
*
* @param string $code One of Types::CODE_*, or an array containing 'code' and 'data' keys
* @param array $data data to return
*/
public function __construct($code, array $data = array())
{
if (is_array($code)) {
$body = \Cake\Utility\Hash::merge(array('code' => 'success', 'data' => array()), $code);
} else {
$body = array('code' => $code, 'data' => $data);
}
$options = array('type' => 'json', 'body' => json_encode($body));
parent::__construct($options);
}
示例3: loadDataCsv
public function loadDataCsv($fileName, $column_list, $delimiter = ",", $array_encoding = 'utf8', $import_encoding = 'sjis-win')
{
//保存をするのでモデルを読み込み
try {
$data = array();
$csvData = array();
$file = fopen($fileName, "r");
while ($data = $this->fgetcsv_reg($file, 65536, $delimiter)) {
//CSVファイルを","区切りで配列に
mb_convert_variables($array_encoding, $import_encoding, $data);
$csvData[] = $data;
}
$i = 0;
foreach ($csvData as $line) {
$this_data = array();
foreach ($column_list as $k => $v) {
if (isset($line[$k])) {
//先頭と末尾の"を削除
$b = $line[$k];
//カラムの数だけセット
$this_data = Hash::merge($this_data, array($v => $b));
} else {
$this_data = Hash::merge($this_data, array($v => ''));
}
}
$data[$i] = $this_data;
$i++;
}
} catch (\Exception $e) {
return false;
}
return $data;
}
示例4: neighbors
/**
* @param int $id
* @param array $options
*
* @return array
*/
public function neighbors($id, array $options = [])
{
if (!$id) {
throw new InvalidArgumentException("The 'id' key is required for find('neighbors')");
}
$sortField = $this->_table->hasField('created') ? 'created' : $this->_table->primaryKey();
$defaults = ['sortField' => $this->_table->alias() . '.' . $sortField];
$options += $defaults;
$normalDirection = !empty($options['reverse']) ? false : true;
$sortDirWord = $normalDirection ? ['ASC', 'DESC'] : ['DESC', 'ASC'];
$sortDirSymb = $normalDirection ? ['>=', '<='] : ['<=', '>='];
if (empty($options['value'])) {
$data = $this->_table->find('all', ['conditions' => [$this->_table->primaryKey() => $id]])->first();
list($model, $sortField) = pluginSplit($options['sortField']);
$options['value'] = $data[$sortField];
}
$return = [];
$findOptions = [];
if (isset($options['contain'])) {
$findOptions['contain'] = $options['contain'];
}
if (!empty($options['fields'])) {
$findOptions['fields'] = $options['fields'];
}
$findOptions['conditions'][$this->_table->alias() . '.' . $this->_table->primaryKey() . ' !='] = $id;
$prevOptions = $findOptions;
$prevOptions['conditions'] = Hash::merge($prevOptions['conditions'], [$options['sortField'] . ' ' . $sortDirSymb[1] => $options['value']]);
$prevOptions['order'] = [$options['sortField'] => $sortDirWord[1]];
$return['prev'] = $this->_table->find('all', $prevOptions)->first();
$nextOptions = $findOptions;
$nextOptions['conditions'] = Hash::merge($nextOptions['conditions'], [$options['sortField'] . ' ' . $sortDirSymb[0] => $options['value']]);
$nextOptions['order'] = [$options['sortField'] => $sortDirWord[0]];
$return['next'] = $this->_table->find('all', $nextOptions)->first();
return $return;
}
示例5: format
/**
* Get format permission data.
*
* @param $acos
* @param array $aros
* @param array $options
* @return array
* @SuppressWarnings("unused")
*/
public function format($acos, array $aros, array $options = [])
{
$options = Hash::merge(['perms' => true, 'model' => 'Roles'], $options);
$permissions = [];
/** @var \Acl\Model\Entity\Aco $aco */
foreach ($acos as $aco) {
$acoId = $aco->get('id');
$acoAlias = $aco->get('alias');
$path = $this->Acos->find('path', ['for' => $acoId]);
$path = join('/', collection($path)->extract('alias')->toArray());
$data = ['path' => $path, 'alias' => $acoAlias, 'depth' => substr_count($path, '/')];
foreach ($aros as $key => $aroId) {
$role = ['foreign_key' => $key, 'model' => $options['model']];
if ($options['perms']) {
$isCheck = $this->check($role, $path);
if ($key == Role::ADMIN_ID || $isCheck) {
$data['roles'][$key] = 1;
} else {
$data['roles'][$key] = (int) $isCheck;
}
}
$permissions[$acoId] = new Data($data);
}
}
return $permissions;
}
示例6: initialize
/**
* Initialization hook method.
*
* @return void
*/
public function initialize()
{
parent::initialize();
if (Configure::read('Swagger')) {
$this->config = Hash::merge(static::$defaultConfig, Configure::read('Swagger'));
}
}
示例7: counter
/**
* Returns a counter string for the paged result set
*
* ### Options
*
* - `model` The model to use, defaults to PaginatorHelper::defaultModel();
* - `format` The format string you want to use, defaults to 'pages' Which generates output like '1 of 5'
* set to 'range' to generate output like '1 - 3 of 13'. Can also be set to a custom string, containing
* the following placeholders `{{page}}`, `{{pages}}`, `{{current}}`, `{{count}}`, `{{model}}`, `{{start}}`, `{{end}}` and any
* custom content you would like.
*
* @param string|array $options Options for the counter string. See #options for list of keys.
* If string it will be used as format.
* @return string Counter string.
* @link http://book.cakephp.org/3.0/en/views/helpers/paginator.html#creating-a-page-counter
*/
public function counter($options = [])
{
if (is_string($options)) {
$options = ['format' => $options];
}
$default = ['model' => $this->defaultModel(), 'format' => 'pages'];
$options = \Cake\Utility\Hash::merge($default, $options);
$paging = $this->params($options['model']);
if (!$paging['pageCount']) {
$paging['pageCount'] = 1;
}
$start = 0;
if ($paging['count'] >= 1) {
$start = ($paging['page'] - 1) * $paging['perPage'] + 1;
}
$end = $start + $paging['perPage'] - 1;
if ($paging['count'] < $end) {
$end = $paging['count'];
}
switch ($options['format']) {
case 'range':
case 'pages':
$template = 'counter' . ucfirst($options['format']);
break;
default:
$template = 'counterCustom';
$this->templater()->add([$template => $options['format']]);
}
$map = array_map([$this->Number, 'format'], ['page' => $paging['page'], 'pages' => $paging['pageCount'], 'current' => $paging['current'], 'count' => $paging['count'], 'start' => $start, 'end' => $end]);
$map += ['model' => strtolower(Inflector::humanize(Inflector::tableize($options['model'])))];
return $this->templater()->format($template, $map);
}
示例8: mergeConfig
/**
* Merge Configuration
*
* @param string $key Configure key
* @param array $config New configuration to merge
* @param return array Array of merged configurations
*/
public static function mergeConfig($key, $config)
{
$values = Configure::read($key);
$values = Hash::merge((array) $values, $config);
Configure::write($key, $values);
return $values;
}
示例9: render
/**
* Create and render navigation menu.
*
* @param array $items
* @param string|int $key
* @param array $options
* @param int $level
* @return string
*/
public function render($key, array $items = [], array $options = [], $level = 1)
{
$_options = ['active' => 'active', 'type' => self::MENU_TYPE_COLLAPSE, 'menuAttr' => ['class' => 'menu', 'id' => 'level-' . $level]];
$counter = 0;
$out = '';
$options = Hash::merge($_options, $options);
$menuAttr = $options['menuAttr'];
$type = $options['type'];
$sorted = Hash::sort($items, '{s}.weight', 'ASC');
foreach ($sorted as $link) {
$child = '';
$counter = $counter + 1;
$title = h($link['title']);
$liAttr = $this->_setLiAttr($counter, $link, $options);
$linkAttr = $this->_setLinkAttr($counter, $link, $options);
if (count($link['children']) > 0) {
list($child, $link, $linkAttr, $title, $level) = $this->_createChild($key, $link, $level, $linkAttr, $type);
}
$title = $this->_createIcon($title, $link);
$linkItem = $this->link($title, $link['url'], $linkAttr);
$out .= $this->tag('li', $linkItem . $child, $liAttr);
$counter++;
}
return $this->tag('ul', $out, $menuAttr);
}
示例10: __construct
/**
* Creates a Transport instance
*
* @param array $config transport-specific configuration options
*/
public function __construct(array $config)
{
$config = Hash::merge(Configure::read('Notifications.transports.sms'), $config);
parent::__construct($config);
$keys = Configure::read('Notifications.transports.sms');
$this->_smsClient = new \WebSmsCom_Client($keys['username'], $keys['password'], $keys['gateway']);
}
示例11: api
/**
* Wrap Moxiemanager's api.php in a controller action.
*
* @return void
*/
public function api()
{
try {
$pluginPath = Plugin::path('CkTools');
define('MOXMAN_CLASSES', $pluginPath . 'src/Lib/moxiemanager/classes');
define('MOXMAN_PLUGINS', $pluginPath . 'src/Lib/moxiemanager/plugins');
define('MOXMAN_ROOT', $pluginPath . 'src/Lib/moxiemanager');
define('MOXMAN_API_FILE', __FILE__);
$appConfig = Configure::read('CkTools.moxiemanager');
Configure::load('CkTools.moxiemanager');
$moxieManagerConfig = Configure::read('moxiemanager');
if (is_array($appConfig)) {
$moxieManagerConfig = Hash::merge($moxieManagerConfig, $appConfig);
}
$GLOBALS['moxieManagerConfig'] = $moxieManagerConfig;
require_once MOXMAN_CLASSES . '/MOXMAN.php';
$context = \MOXMAN_Http_Context::getCurrent();
$pluginManager = \MOXMAN::getPluginManager();
foreach ($pluginManager->getAll() as $plugin) {
if ($plugin instanceof \MOXMAN_Http_IHandler) {
$plugin->processRequest($context);
}
}
} catch (Exception $e) {
\MOXMAN_Exception::printException($e);
}
return $this->render(false, false);
}
示例12: send
/**
* Send mail using Mandrill (by MailChimp)
*
* @param \Cake\Network\Email\Email $email Cake Email
* @return array
*/
public function send(Email $email)
{
$this->transportConfig = Hash::merge($this->transportConfig, $this->_config);
// Initiate a new Mandrill Message parameter array
$message = ['html' => $email->message(\Cake\Network\Email\Email::MESSAGE_HTML), 'text' => $email->message(\Cake\Network\Email\Email::MESSAGE_TEXT), 'subject' => $this->_decode($email->subject()), 'from_email' => key($email->from()), 'from_name' => current($email->from()), 'to' => [], 'headers' => ['Reply-To' => is_null(key($email->replyTo())) ? key($email->from()) : key($email->replyTo())], 'recipient_metadata' => [], 'attachments' => [], 'images' => []];
// Merge Mandrill Parameters
$message = array_merge($message, Hash::merge($this->defaultParameters, $email->profile()['Mandrill']));
// Add receipients
foreach (['to', 'cc', 'bcc'] as $type) {
foreach ($email->{$type}() as $mail => $name) {
$message['to'][] = ['email' => $mail, 'name' => $name, 'type' => $type];
}
}
// Attachments
$message = $this->_attachments($email, $message);
// Create a new scoped Http Client
$this->http = new Client(['host' => 'mandrillapp.com', 'scheme' => 'https', 'headers' => ['User-Agent' => 'CakePHP Mandrill Plugin']]);
// Sending as a template? Then in case we find mail content, we add this as a 'template_content'.
// In you Mandrill template, use <div mc:edit="content"></div> to get the contents of your email
if (!is_null($message['template_name']) && $message['html']) {
if (!isset($message['template_content']) || !is_array($message['template_content'])) {
$message['template_content'] = [];
}
$message['template_content'][] = ['name' => 'content', 'content' => $message['html']];
}
// Are we sending a template?
if (!is_null($message['template_name']) && !empty($message['template_content'])) {
return $this->_sendTemplate($message, $this->transportConfig['async'], $this->transportConfig['ip_pool'], $message['send_at']);
} else {
return $this->_send($message, $this->transportConfig['async'], $this->transportConfig['ip_pool'], $message['send_at']);
}
}
示例13: __construct
/**
* Class Constructor
*
* Merges defaults with
* - Configure::read(Meta)
* - Helper options
* - viewVars _meta
* in that order (the latter trumps)
*
* @param array $options
*/
public function __construct(View $View, $options = [])
{
parent::__construct($View, $options);
$configureMeta = (array) Configure::read('Meta');
if (Configure::read('Meta.robots') && is_array(Configure::read('Meta.robots'))) {
$configureMeta['robots'] = Hash::merge($this->meta['robots'], Configure::read('Meta.robots'));
}
$this->meta = $configureMeta + $this->meta;
if (!empty($options['robots']) && is_array($options['robots'])) {
$options['robots'] = Hash::merge($this->meta['robots'], $options['robots']);
}
$this->meta = $options + $this->meta;
if (!empty($this->_View->viewVars['_meta'])) {
$viewVarsMeta = (array) $this->_View->viewVars['_meta'];
if (!empty($viewVarsMeta['robots']) && is_array($viewVarsMeta['robots'])) {
$viewVarsMeta['robots'] = Hash::merge($this->meta['robots'], $viewVarsMeta['robots']);
}
$this->meta = $viewVarsMeta + $this->meta;
}
if ($this->meta['charset'] === null) {
// By default include this
$this->meta['charset'] = true;
}
if ($this->meta['icon'] === null) {
// By default include this
$this->meta['icon'] = true;
}
if ($this->meta['title'] === null) {
$this->meta['title'] = __(Inflector::humanize(Inflector::underscore($this->request->params['controller']))) . ' - ' . __(Inflector::humanize(Inflector::underscore($this->request->params['action'])));
}
}
示例14: attachmentsArea
/**
* Render an attachments area for the given entity
*
* @param EntityInterface $entity Entity to attach files to
* @param array $options Override default options
* @return string
*/
public function attachmentsArea(EntityInterface $entity, array $options = [])
{
if ($this->config('includeDependencies')) {
$this->addDependencies();
}
$options = Hash::merge(['label' => false, 'id' => 'fileupload-' . uniqid(), 'formFieldName' => false, 'mode' => 'full', 'style' => '', 'taggable' => false, 'isAjax' => false, 'panelHeading' => __d('attachments', 'attachments'), 'showIconColumn' => true, 'additionalButtons' => null], $options);
return $this->_View->element('Attachments.attachments_area', compact('options', 'entity'));
}
示例15: toggle
/**
* Render ajax toggle element.
*
* @param array|string $url
* @param array $data
* @param Entity|\Cake\ORM\Entity $entity
* @return string
*/
public function toggle($entity, $url = [], array $data = [])
{
if (empty($url)) {
$url = ['action' => 'toggle', 'prefix' => $this->request->param('prefix'), 'plugin' => $this->request->param('plugin'), 'controller' => $this->request->param('controller'), (int) $entity->get('id'), (int) $entity->get('status')];
}
$data = Hash::merge(['url' => $url, 'entity' => $entity], $data);
return $this->_View->element(__FUNCTION__, $data);
}