本文整理汇总了PHP中first函数的典型用法代码示例。如果您正苦于以下问题:PHP first函数的具体用法?PHP first怎么用?PHP first使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了first函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: retrieve
/**
* Retrieve request specified by id argument, if second argument is specified, array of requests from id to last
* will be returned
*/
public function retrieve($id = null, $last = null)
{
if ($id && !$last) {
if (!is_readable($this->path . '/' . $id . '.json')) {
return null;
}
return new Request(json_decode(file_get_contents($this->path . '/' . $id . '.json'), true));
}
$files = glob($this->path . '/*.json');
$id = $id ? $id . '.json' : first($files);
$last = $last ? $last . '.json' : end($files);
$requests = array();
$add = false;
foreach ($files as $file) {
if ($file == $id) {
$add = true;
} elseif ($file == $last) {
$add = false;
}
if (!$add) {
continue;
}
$requests[] = new Request(json_decode(file_get_contents($file), true));
}
return $requests;
}
示例2: get
/**
* Retrieve request specified by id argument, if second argument is specified, array of requests from id to last
* will be returned
*/
public function get($id = null, $last = null)
{
if ($id && !$last) {
if (!is_readable($this->path . '/' . $id . $this->extension)) {
return null;
}
return new Request(unserialize(file_get_contents($this->path . '/' . $id . $this->extension), true));
}
$files = glob($this->path . '/*' . $this->extension);
$id = $id ? $id . $this->extension : first($files);
$last = $last ? $last . $this->extension : end($files);
$requests = array();
$add = false;
foreach ($files as $file) {
if ($file == $id) {
$add = true;
} elseif ($file == $last) {
$add = false;
}
if (!$add) {
continue;
}
$requests[] = new Request(unserialize(file_get_contents($file), true));
}
return $requests;
}
示例3: update
public function update($tmpDir = '') {
Helper::mkdir($tmpDir, true);
$this->collect();
try {
foreach ($this->appsToUpdate as $appId) {
if (!@file_exists($this->newBase . '/' . $appId)){
continue;
}
$path = \OC_App::getAppPath($appId);
if ($path) {
Helper::move($path, $tmpDir . '/' . $appId);
// ! reverted intentionally
$this->done [] = array(
'dst' => $path,
'src' => $tmpDir . '/' . $appId
);
Helper::move($this->newBase . '/' . $appId, $path);
} else {
// The app is new and doesn't exist in the current instance
$pathData = first(\OC::$APPSROOTS);
Helper::move($this->newBase . '/' . $appId, $pathData['path'] . '/' . $appId);
}
}
$this->finalize();
} catch (\Exception $e) {
$this->rollback(true);
throw $e;
}
}
示例4: third
function third()
{
enter_function('third');
second();
first();
exit_function();
}
示例5: getEventsByTarget
static function getEventsByTarget($deviceDS)
{
$where = array('e_code LIKE ?', 'e_code LIKE ?', 'e_code LIKE ?');
$searchPatterns = array('%' . $deviceDS['d_id'] . '%', '%' . @first($deviceDS['d_alias'], 'NOMATCH') . '%');
return o(db)->get('SELECT * FROM #events WHERE
' . implode(' OR ', $where), $searchPatterns);
}
示例6: sendForgetMail
/**
* send forget mail to user
*
* @param array $parameters
* @param string $column
* @return mixed
* @throws OAuthException
* @throws QueryException
*/
protected function sendForgetMail(array $parameters = [], $column = null)
{
$username = isset($parameters['username']) ? $parameters['username'] : '';
$mailDriver = isset($parameters['mail_driver']) ? $parameters['mail_driver'] : 'default';
$callback = isset($parameters['callback']) ? $parameters['callback'] : 'auth/forget';
$table = Config::get('database.tables.table');
$database = Database::table($table);
$userColumn = null === $column ? first(Config::get('database.tables.login')) : $column;
$userInformation = $database->select(['email', 'id'])->where($userColumn, $username);
if (!$userInformation->rowCount()) {
throw new OAuthException(sprintf('%s Username is not exists', $username));
}
$datas = $userInformation->first();
// we will find user email now
$mailAddress = $datas->email;
$generator = new SecurityKeyGenerator();
$key = $generator->random($username . $mailAddress);
$forgets = Database::table('forgets');
$add = $forgets->insert(['key' => $key, 'user_id' => $datas->id]);
if (!$add->isSuccess()) {
throw new QueryException('Forget keys and user_id could not added to database, please try agein later');
}
$url = Request::getBaseWithoutQuery();
if (!Str::endsWith($callback, "/")) {
$callback .= "/";
}
$url .= $callback . $key;
$template = new TemplateGenerator(file_get_contents(RESOURCE . 'migrations/forget_mail.php.dist'));
$content = $template->generate(['url' => $url, 'username' => $username]);
$yourAddress = config('mail.your_address');
$send = Mail::send($mailDriver, function (DriverInterface $mail) use($mailAddress, $username, $content, $yourAddress) {
return $mail->from($yourAddress, '')->subject('Password Recovery')->to($mailAddress, $username)->body($content)->send();
});
return $send;
}
示例7: head
/**
* Alias for Functional\first
*
* @param Traversable|array $collection
* @param callable $callback
* @return mixed
*/
function head($collection, $callback = null)
{
Exceptions\InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1);
if ($callback !== null) {
Exceptions\InvalidArgumentException::assertCallback($callback, __FUNCTION__, 2);
}
return first($collection, $callback);
}
示例8: reduce
function reduce(callable $fn, $sq)
{
$sq = is_array($sq) ? $sq : iterator_to_array($sq);
$r = first($sq);
for ($i = 0; $i < count($sq) - 1; $i++) {
$r = $fn($r, $sq[$i + 1]);
}
return $r;
}
示例9: crearNumeroUnico
/**
* funciones de negocio
*/
public function crearNumeroUnico()
{
$numero_unico = str_random(10);
$busqueda = $this->where('numero_unico', '=', $numero_unico) - first();
if (!is_null($busqueda)) {
return $numero_unico;
} else {
$this->crearNumeroUnico();
}
}
示例10: setSabbaticalData
function setSabbaticalData($data)
{
$sabbatical = (object) [];
$sabbatical->date = $data[9];
$sabbatical->location = ['latitude' => $data[3], 'longitude' => $data[4], 'city' => first($data[2]), 'country' => last($data[2])];
$sabbatical->organization = ['title' => $data[5], 'website' => $data[8]];
$sabbatical->contact = ['name' => $data[6], 'email' => $data[7]];
$sabbatical->description = $data[10];
return $sabbatical;
}
示例11: invokeAction
function invokeAction($action)
{
$_REQUEST['action'] = basename(first($action, 'index'));
ob_start();
$this->controller->invokeAction($_REQUEST['action'], $this->params);
$this->controller->lastAction = $_REQUEST['action'];
$this->actionOutput = trim(ob_get_clean());
profile_point('H2Dispatcher.invokeAction(' . $_REQUEST['action'] . ')');
return $this;
}
示例12: create
public static function create($msg, $type = E_USER_NOTICE)
{
if (in_array($type, Config::get('error.levels'))) {
// Throw an actual error.
$callee = first(debug_backtrace());
trigger_error($msg . ' in <strong>' . $callee['file'] . '</strong> on line <strong>' . $callee['line'] . "</strong>.\n<br> Thrown", $type);
self::log($msg);
return true;
}
return false;
}
示例13: boot
/**
* Register any other events for your application.
*
* @param \Illuminate\Contracts\Events\Dispatcher $events
* @return void
*/
public function boot(DispatcherContract $events)
{
$listens = $this->listen;
$this->listen = array_merge($this->listen, $this->listen_eloquent);
parent::boot($events);
$events->listen('eloquent.*', function ($model) use($events) {
$event_type = first(explode(': ', last(explode('.', $events->firing()))));
$event = get_class($model) . '::' . $event_type;
return $events->fire($event, $model);
});
$this->listen = $listens;
}
示例14: run
/**
* Migration sınıfını yürütür
* @param string $fileName
* @return array
*/
public function run($fileName)
{
$return = [];
if ('' !== $fileName) {
$return = [$this->execute($fileName)];
} else {
$list = Finder::create()->files()->name('*.php')->in(MIGRATION);
foreach ($list as $l) {
$return[] = $this->execute(first(explode('.', $l->getFilename())));
}
}
return $return;
}
示例15: __call
public function __call($method, $args)
{
// If there's a method, call it
if (method_exists($this->_class, $method)) {
$call = call_user_func_array(array($this->_class, $method), $args);
// Don't chain if it returns something
if (!is_null($call)) {
return $call;
}
} else {
// Otherwise, just set it manually
$this->_class->set($method, first($args));
}
return $this;
}