本文整理汇总了PHP中a::first方法的典型用法代码示例。如果您正苦于以下问题:PHP a::first方法的具体用法?PHP a::first怎么用?PHP a::first使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类a
的用法示例。
在下文中一共展示了a::first方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: crawl
function crawl()
{
$path = url::strip_query($this->raw);
$path = (array) str::split($path, '/');
if (a::first($path) == 'index.php') {
array_shift($path);
}
// parse params
foreach ($path as $p) {
if (str::contains($p, ':')) {
$parts = explode(':', $p);
if (count($parts) < 2) {
continue;
}
$this->params->{$parts}[0] = $parts[1];
} else {
$this->path->_[] = $p;
}
}
// get the extension from the last part of the path
$this->extension = f::extension($this->path->last());
if ($this->extension != false) {
// remove the last part of the path
$last = array_pop($this->path->_);
$this->path->_[] = f::name($last);
}
return $this->path;
}
示例2: testSort
public function testSort()
{
$users = $this->users;
$users = a::sort($users, 'username', 'asc');
$first = a::first($users);
$last = a::last($users);
$this->assertEquals('mary', $first['username']);
$this->assertEquals('peter', $last['username']);
}
示例3: avatar
public function avatar()
{
if (isset($this->cache['avatar'])) {
return $this->cache['avatar'];
}
// try to find the avatar
$root = c::get('root') . DS . 'assets' . DS . 'avatars' . DS . $this->username() . '.{jpg,png}';
if ($avatar = a::first((array) glob($root, GLOB_BRACE))) {
return $this->cache['avatar'] = new Media($avatar, url('assets/avatars/' . f::filename($avatar)));
} else {
return $this->cache['avatar'] = false;
}
}
示例4: find
function find()
{
global $site;
$args = func_get_args();
// find multiple pages
if (count($args) > 1) {
$result = array();
foreach ($args as $arg) {
$page = $this->find($arg);
if ($page) {
$result[] = $page;
}
}
return empty($result) ? false : new relatedPages($result);
}
return $site->pages()->find(a::first($args));
}
示例5: randomimage
function randomimage($dir)
{
$files = dir::read(c::get('root') . '/' . $dir);
shuffle($files);
return url($dir . '/' . a::first($files));
}
示例6: parse
/**
* Parses the hashed value from a cookie
* and tries to extract the value
*
* @param string $hash
* @return mixed
*/
protected static function parse($string)
{
// extract hash and value
$parts = str::split($string, '+');
$hash = a::first($parts);
$value = a::last($parts);
// if the hash or the value is missing at all return null
if (empty($hash) or empty($value)) {
return null;
}
// compare the extracted hash with the hashed value
if ($hash !== static::hash($value)) {
return null;
}
return $value;
}
示例7: find
function find()
{
$args = func_get_args();
// find multiple pages
if (count($args) > 1) {
$result = array();
foreach ($args as $arg) {
$page = $this->find($arg);
if ($page) {
$result[$page->uid] = $page;
}
}
return empty($result) ? false : new pages($result);
}
// find a single page
$path = a::first($args);
$array = str::split($path, '/');
$obj = $this;
$page = false;
foreach ($array as $p) {
$next = $obj->{$p};
if (!$next) {
return $page;
}
$page = $next;
$obj = $next->children();
}
return $page;
}
示例8: email
/**
* Generates an "a mailto" tag
*
* @param string $email The url for the a tag
* @param mixed $text The optional text. If null, the url will be used as text
* @param array $attr Additional attributes for the tag
* @return string the generated html
*/
public static function email($email, $text = null, $attr = array())
{
if (empty($text)) {
// show only the eMail address without additional parameters (if the 'text' argument is empty)
$text = str::encode(a::first(str::split($email, '?')));
}
$email = str::encode($email);
$attr = array_merge(array('href' => 'mailto:' . $email), $attr);
return static::tag('a', $text, $attr);
}
示例9: acceptance
/**
* Returns a number between 0 and 1 that defines how "accepted"
* a specified MIME type is for the visitor's browser using the
* HTTP Accept header
*
* @param string $type MIME type like "text/html"
* @return float Number between 0 (not accepted) and 1 (very accepted)
*/
public static function acceptance($type)
{
$accept = a::get($_SERVER, 'HTTP_ACCEPT');
// if there is no header, everything is accepted
if (!$accept) {
return 1;
}
// check each type in the Accept header
foreach (str::split($accept, ',') as $item) {
$item = str::split($item, ';');
$mime = a::first($item);
// $item now only contains params
// check if the type matches
if (!fnmatch($mime, $type, FNM_PATHNAME)) {
continue;
}
// check for the q param ("quality" of the type)
foreach ($item as $param) {
$param = str::split($param, '=');
if (a::get($param, 0) === 'q' && ($value = a::get($param, 1))) {
return (double) $value;
}
}
// no quality param, default to a quality of 1
return 1;
}
// no match at all, the type is not accepted
return 0;
}
示例10: languageSetup
function languageSetup()
{
// check for activated language support
if (!c::get('lang.support')) {
return false;
}
// get the available languages
$available = c::get('lang.available');
// sanitize the available languages
if (!is_array($available)) {
// switch off language support
c::set('lang.support', false);
return false;
}
// get the raw uri
$uri = uri::raw();
// get the current language code
$code = a::first(explode('/', $uri));
// try to detect the language code if the code is empty
if (empty($code)) {
if (c::get('lang.detect')) {
// detect the current language
$detected = str::split(server::get('http_accept_language'), '-');
$detected = str::trim(a::first($detected));
$detected = !in_array($detected, $available) ? c::get('lang.default') : $detected;
// set the detected code as current code
$code = $detected;
} else {
$code = c::get('lang.default');
}
// go to the default homepage
go(url(false, $code));
}
// http://yourdomain.com/error
// will redirect to http://yourdomain.com/en/error
if ($code == c::get('404')) {
go(url('error', c::get('lang.default')));
}
// validate the code and switch back to the homepage if it is invalid
if (!in_array($code, c::get('lang.available'))) {
go(url());
}
// set the current language
c::set('lang.current', $code);
// mark if this is a translated version or the default version
$code != c::get('lang.default') ? c::set('lang.translated', true) : c::set('lang.translated', false);
// load the additional language files if available
load::language();
}
示例11: find
function find()
{
$args = func_get_args();
// find multiple files
if (count($args) > 1) {
$result = array();
foreach ($args as $arg) {
$file = $this->find($arg);
if ($file) {
$result[$file->filename] = $file;
}
}
return empty($result) ? false : new files($result);
}
// find a single file
$key = a::first($args);
if (!$key) {
return $this->_;
}
return a::get($this->_, $key);
}
示例12: inventory
/**
* Modified inventory fetcher
*
* @return array
*/
public function inventory()
{
$inventory = parent::inventory();
$defaultLang = $this->site->defaultLanguage->code;
$expression = '!(.*?)(\\.(' . implode('|', $this->site->languages->codes()) . ')|)\\.' . $this->kirby->options['content.file.extension'] . '$!i';
foreach ($inventory['meta'] as $key => $meta) {
$inventory['meta'][$key] = array($defaultLang => $meta);
}
foreach ($inventory['content'] as $key => $content) {
preg_match($expression, $content, $match);
$file = $match[1];
$lang = isset($match[3]) ? $match[3] : null;
if (in_array($file, $inventory['files'])) {
$inventory['meta'][$file][$lang] = $content;
} else {
if (is_null($lang)) {
$lang = f::extension($file);
if (empty($lang)) {
$lang = $defaultLang;
}
}
$inventory['content'][$lang] = $content;
}
unset($inventory['content'][$key]);
}
// try to fill the default language with something else
if (!isset($inventory['content'][$defaultLang])) {
$inventory['content'][$defaultLang] = a::first($inventory['content']);
}
return $inventory;
}
示例13: first
function first()
{
return a::first($this->_);
}
示例14: find
function find()
{
$args = func_get_args();
// find multiple pages
if (count($args) > 1) {
$result = array();
foreach ($args as $arg) {
$page = $this->find($arg);
if ($page) {
$result[$page->uid] = $page;
}
}
return empty($result) ? false : new pages($result);
}
// find a single page
$path = a::first($args);
$array = str::split($path, '/');
$obj = $this;
$page = false;
// check if we need to search for translated urls
$translated = c::get('lang.support');
foreach ($array as $p) {
$next = $translated ? $obj->findBy('translatedUID', $p) : $obj->{'_' . $p};
if (!$next) {
return $page;
}
$page = $next;
$obj = $next->children();
}
return $page;
}
示例15: html
" />
</div>
<!-- manually prevented the popup from being shown when the page is of type 'project'.
the population of the menu is then limited to "media type" - templates
in the end i made sure that the default-template is chosen if the panel is "home"
so that we can add categories which are then NOT of type 'project' but use the
default template -->
<div class="field">
<?php
if (count($templates) == 1) {
?>
<?php
$template = a::first($templates);
?>
<label><?php
echo l::get('pages.add.label.template');
?>
: <em><?php
echo html(data::templateName($template));
?>
(<?php
echo html($template);
?>
)</em></label>
<input type="hidden" name="template" value="<?php
echo html($template);
?>
" />