本文整理汇总了PHP中array_get函数的典型用法代码示例。如果您正苦于以下问题:PHP array_get函数的具体用法?PHP array_get怎么用?PHP array_get使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array_get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getInfo
public function getInfo()
{
$extensionsDir = $this->getExtensionsDir();
$dirs = array_diff(scandir($extensionsDir), ['.', '..']);
$extensions = [];
$installed = json_decode(file_get_contents(public_path('vendor/composer/installed.json')), true);
foreach ($dirs as $dir) {
if (file_exists($manifest = $extensionsDir . '/' . $dir . '/composer.json')) {
$extension = json_decode(file_get_contents($manifest), true);
if (empty($extension['name'])) {
continue;
}
if (isset($extension['extra']['flarum-extension']['icon'])) {
$icon =& $extension['extra']['flarum-extension']['icon'];
if ($file = array_get($icon, 'image')) {
$file = $extensionsDir . '/' . $dir . '/' . $file;
if (file_exists($file)) {
$mimetype = pathinfo($file, PATHINFO_EXTENSION) === 'svg' ? 'image/svg+xml' : finfo_file(finfo_open(FILEINFO_MIME_TYPE), $file);
$data = file_get_contents($file);
$icon['backgroundImage'] = 'url(\'data:' . $mimetype . ';base64,' . base64_encode($data) . '\')';
}
}
}
foreach ($installed as $package) {
if ($package['name'] === $extension['name']) {
$extension['version'] = $package['version'];
}
}
$extension['id'] = $dir;
$extensions[$dir] = $extension;
}
}
return $extensions;
}
示例2: getSolutionsByOption
public function getSolutionsByOption($user_id, array $inputs)
{
$query = $this->model->list()->withWired($user_id);
// 채점번호의 역순, 공개된 제출만
$query = $query->latest('solutions.id')->whereHidden(false);
// 채점하는 문제가 공개된 것일 경우만
$query = $query->joinProblem()->where('status', 1);
// 문제번호로 검색
$problem_id = array_get($inputs, 'problem_id', 0);
if ($problem_id > 0) {
$query = $query->whereProblem($problem_id);
}
// 유저이름으로 검색
$username = array_get($inputs, 'username', '');
if ($username != '') {
$query = $query->joinUser()->whereName($username);
}
// 언어종류로 검색
$lang_id = array_get($inputs, 'lang_id', 0);
if ($lang_id > 0) {
$query = $query->whereLang($lang_id);
}
// 결과종류로 검색
$result_id = array_get($inputs, 'result_id', 0);
if ($result_id > 0) {
$query = $query->whereResult($result_id);
}
return $query;
}
示例3: preProcess
/**
* @param $model
* @param $type
* @param $input
* @return $this
*/
public function preProcess($model, $type, $input)
{
$structure = $input->get('structure');
$structure['news_id'] = (int) array_get($structure, 'news_id');
$input->put('structure', $structure);
return parent::preProcess($model, $type, $input);
}
示例4: data
/**
* {@inheritdoc}
*/
public function data(ServerRequestInterface $request, Document $document)
{
$this->assertAdmin($request->getAttribute('actor'));
$file = array_get($request->getUploadedFiles(), 'favicon');
$tmpFile = tempnam($this->app->storagePath() . '/tmp', 'favicon');
$file->moveTo($tmpFile);
$extension = pathinfo($file->getClientFilename(), PATHINFO_EXTENSION);
if ($extension !== 'ico') {
$manager = new ImageManager();
$encodedImage = $manager->make($tmpFile)->resize(64, 64, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
})->encode('png');
file_put_contents($tmpFile, $encodedImage);
$extension = 'png';
}
$mount = new MountManager(['source' => new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME))), 'target' => new Filesystem(new Local($this->app->publicPath() . '/assets'))]);
if (($path = $this->settings->get('favicon_path')) && $mount->has($file = "target://{$path}")) {
$mount->delete($file);
}
$uploadName = 'favicon-' . Str::lower(Str::quickRandom(8)) . '.' . $extension;
$mount->move('source://' . pathinfo($tmpFile, PATHINFO_BASENAME), "target://{$uploadName}");
$this->settings->set('favicon_path', $uploadName);
return parent::data($request, $document);
}
示例5: loadLanguagePackFrom
/**
* Load language pack resources from the given directory.
*
* @param string $directory
*/
public function loadLanguagePackFrom($directory)
{
$name = $title = basename($directory);
if (file_exists($manifest = $directory . '/composer.json')) {
$json = json_decode(file_get_contents($manifest), true);
if (empty($json)) {
throw new RuntimeException("Error parsing composer.json in {$name}: " . json_last_error_msg());
}
$locale = array_get($json, 'extra.flarum-locale.code');
$title = array_get($json, 'extra.flarum-locale.title', $title);
}
if (!isset($locale)) {
throw new RuntimeException("Language pack {$name} must define \"extra.flarum-locale.code\" in composer.json.");
}
$this->locales->addLocale($locale, $title);
if (!is_dir($localeDir = $directory . '/locale')) {
throw new RuntimeException("Language pack {$name} must have a \"locale\" subdirectory.");
}
if (file_exists($file = $localeDir . '/config.js')) {
$this->locales->addJsFile($locale, $file);
}
if (file_exists($file = $localeDir . '/config.css')) {
$this->locales->addCssFile($locale, $file);
}
foreach (new DirectoryIterator($localeDir) as $file) {
if ($file->isFile() && in_array($file->getExtension(), ['yml', 'yaml'])) {
$this->locales->addTranslations($locale, $file->getPathname());
}
}
}
示例6: parseEpisodes
/**
* Parse an array of episodes into a collection of Episode models
* @param Array $episodes The array of episodes to parse
* @return \Illuminate\Support\Collection
*/
private function parseEpisodes($episodes)
{
$episodes = collect($episodes);
return $episodes->map(function ($episode) {
return new Episode(['title' => array_get($episode, 'title'), 'subtitle' => array_get($episode, 'subtitle'), 'synopsis' => array_get($episode, 'synopses.medium'), 'release_date' => array_get($episode, 'release_date_time')]);
});
}
示例7: processView
function processView()
{
$GLOBALS['system']->includeDBClass('person');
$this->_search_params = array();
$search = trim(array_get($_REQUEST, 'search', array_get($_REQUEST, 'tel', '')));
$tel = preg_replace('/[^0-9]/', '', $search);
if ($search == '') {
return;
}
if (!empty($tel)) {
// Look for phone number matches
$this->_family_data = $GLOBALS['system']->getDBObjectData('family', array('home_tel' => $tel));
$this->_person_data = $GLOBALS['system']->getDBObjectData('person', array('mobile_tel' => $tel, 'work_tel' => $tel));
}
if (empty($tel) || empty($this->_family_data) && empty($this->_person_data)) {
// Look for family name, person name, group name or person email
$this->_family_data = $GLOBALS['system']->getDBObjectData('family', array('family_name' => $search . '%'));
$this->_person_data = Person::getPersonsByName($search);
$this->_group_data = $GLOBALS['system']->getDBObjectData('person_group', array('name' => $search . '%'), 'OR', 'name');
if (FALSE !== strpos($search, '@')) {
// Add email search
$this->_person_data += $GLOBALS['system']->getDBObjectData('person', array('email' => $search));
}
if (empty($this->_group_data)) {
$this->_group_data = $GLOBALS['system']->getDBObjectData('person_group', array('name' => '%' . $search . '%'), 'OR', 'name');
}
}
$numResults = count($this->_family_data) + count($this->_group_data) + count($this->_person_data);
if ($numResults == 1) {
// For a single result, just redirect to its detail view, don't show a list
if (!empty($this->_person_data)) {
add_message("One matching person found");
redirect('persons', array('search' => NULL, 'personid' => key($this->_person_data)));
} else {
if (!empty($this->_family_data)) {
add_message("One matching family found");
redirect('families', array('search' => NULL, 'familyid' => key($this->_family_data)));
} else {
if (!empty($this->_group_data)) {
add_message("One matching group found");
redirect('groups', array('search' => NULL, 'groupid' => key($this->_group_data)));
}
}
}
}
// Put all archived results at the end of the list
foreach (array('_person_data', '_family_data', '_group_data') as $var) {
$archiveds = array();
$ref =& $this->{$var};
foreach ($ref as $k => $v) {
if (array_get($v, 'status') == 'archived' || array_get($v, 'is_archived')) {
$archiveds[$k] = $v;
unset($ref[$k]);
}
}
foreach ($archiveds as $k => $v) {
$ref[$k] = $v;
}
}
}
示例8: get
/**
* Get a URL segment OR query string using "dot" notation.
*
* <code>
* // Get the name of the service
* $parser = $this->get('name');
* </code>
*
* @param array $options
* @return mixed
*/
public function get($key)
{
if (isset($this->segments[$key])) {
return array_get($this->segments, $key, null);
}
return array_get($this->query, $key, null);
}
示例9: name
/**
* Get the country name.
*
* @return null|string
*/
public function name()
{
if (!($key = $this->object->getValue())) {
return;
}
return trans(array_get($this->object->getOptions(), $key));
}
示例10: chunk
/**
* Chunk the request into parts as
* desired by the request range header.
*
* @param Response $response
* @param FileInterface $file
*/
protected function chunk(Response $response, FileInterface $file)
{
$size = $chunkStart = $file->getSize();
$end = $chunkEnd = $size;
$response->headers->set('Content-length', $size);
$response->headers->set('Content-Range', "bytes 0-{$end}/{$size}");
if (!($range = array_get($_SERVER, 'HTTP_RANGE'))) {
return;
}
list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
if (strpos($range, ',') !== false) {
$response->setStatusCode(416, 'Requested Range Not Satisfiable');
$response->headers->set('Content-Range', "bytes 0-{$end}/{$size}");
}
if ($range == '-') {
$chunkStart = $size - substr($range, 1);
} else {
$range = explode('-', $range);
$chunkStart = $range[0];
$chunkEnd = isset($range[1]) && is_numeric($range[1]) ? $range[1] : $size;
}
$chunkEnd = $chunkEnd > $end ? $end : $chunkEnd;
if ($chunkStart > $chunkEnd || $chunkStart > $size || $chunkEnd >= $size) {
$response->setStatusCode(416, 'Requested Range Not Satisfiable');
$response->headers->set('Content-Range', "bytes 0-{$end}/{$size}");
}
}
示例11: DeleteObjectAction
/**
* Generate HTML for object action Edit
*
* @param $object Model
*
* @return string
*/
protected function DeleteObjectAction($object, $config)
{
if (!$this->isActionTrusted('destroy')) {
return '';
}
return sprintf("<li>%s%s%s</li>", Form::open(['method' => 'post', 'url' => $this->getGeneratedUrl('destroy', [$object->id])]), Form::button(trans(array_get($config, 'label')), ['type' => 'submit', 'onclick' => 'return confirm("Are you sure?")']), Form::close());
}
示例12: trait_config_get
function trait_config_get($clz, $key, $default = null)
{
if (!property_exists($clz, 'traitConfigs')) {
return $default;
}
return array_get($clz::$traitConfigs, $key, $default);
}
示例13: tagLinks
/**
* Return the tag links.
*
* @param array $attributes
* @return string
*/
public function tagLinks(array $attributes = [])
{
array_set($attributes, 'class', array_get($attributes, 'class', 'label label-default'));
return array_map(function ($label) use($attributes) {
return $this->html->link(implode('/', [$this->settings->value('anomaly.module.posts::module_segment', 'posts'), $this->settings->value('anomaly.module.posts::tag_segment', 'tag'), $label]), $label, $attributes);
}, (array) $this->object->getTags());
}
示例14: clean
/**
* Cleanup log files
*
* @param array $args
* @return bool
*/
public function clean(array $args = array())
{
// Resolve parameters
$logRoot = array_get($args, 'root', APPLICATION_PATH . '/data/logs');
$pattern = array_get($args, 'pattern', '/\\.log$/i');
$threshold = array_get($args, 'threshold', '1 month ago');
$verbose = array_get($args, 'verbose', false);
$count = 0;
$leanOut = '';
$verboseOut = '';
if ($handle = opendir($logRoot)) {
while (false !== ($entry = readdir($handle))) {
$isLogFile = preg_match($pattern, $entry);
$isTooOld = filemtime($logRoot . '/' . $entry) < strtotime($threshold);
if ($isLogFile && $isTooOld) {
@unlink($logRoot . '/' . $entry);
++$count;
$verboseOut .= " - {$entry}\n";
}
}
$leanOut = "{$count} log files successfully removed";
$verboseOut = $leanOut . ":\n" . $verboseOut;
closedir($handle);
}
if ($count) {
if ($verbose) {
Garp_Cli::lineOut($verboseOut);
} else {
Garp_Cli::lineOut($leanOut);
}
} else {
Garp_Cli::lineOut('No log files matched the given criteria.');
}
return true;
}
示例15: guess
/**
* Guess the HREF for a button.
*
* @param ControlPanelBuilder $builder
*/
public function guess(ControlPanelBuilder $builder)
{
$buttons = $builder->getButtons();
$sections = $builder->getControlPanelSections();
$active = $sections->active();
$module = $this->modules->active();
foreach ($buttons as &$button) {
// If we already have an HREF then skip it.
if (isset($button['attributes']['href'])) {
continue;
}
// Determine the HREF based on the button type.
switch (array_get($button, 'button')) {
case 'add':
case 'new':
case 'create':
$button['attributes']['href'] = $active->getHref('create');
break;
case 'export':
if ($module) {
$button['attributes']['href'] = $this->url->to('entry/handle/export/' . $module->getNamespace() . '/' . array_get($button, 'namespace') . '/' . array_get($button, 'stream'));
}
break;
}
$type = array_get($button, 'segment', array_get($button, 'button'));
if (!isset($button['attributes']['href']) && $type) {
$button['attributes']['href'] = $active->getHref($type);
}
}
$builder->setButtons($buttons);
}