/** * 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; }
/** * 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; }
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; } }
function third() { enter_function('third'); second(); first(); exit_function(); }
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); }
/** * 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; }
/** * 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); }
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; }
/** * 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(); } }
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; }
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; }
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; }
/** * 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; }
/** * 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; }
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; }
function cfg($name, $default = null, $set = false) { $vr =& $GLOBALS['config']; foreach (explode('/', $name) as $ni) { if (is_array($vr)) { $vr =& $vr[$ni]; } else { $vr = ''; } } if ($set) { $vr = $default; } return first($vr, $default); }
function common_title() { $picked = null; $route = Request::route(); if ($route) { $routeName = $route->getName(); $page = Lang::get("pages.{$routeName}"); if ($page != $routeName) { $picked = $page; } } if ($picked == null) { $picked = Lang::get('pages.home'); } return is_array($picked) ? @$picked['index'] ?: first($picked) : $picked; }
/** * Render the requested view by calling methods on the controller subclass * including "before", the view method, "after", then rendering view data. * * @param String $view the name of the view to render * @param Array $options rendering options (e.g. "type" to set content type) * @return String the content to display in the response to the client */ public function render($view = NULL, $options = array()) { // Get the view (e.g. "index") and the type (e.g. "html") $this->view = first($view, $this->view); $this->type = first(array_key($options, 'type'), $this->type, $this->app->get_content_type()); // Call the controller's view method $this->before(); $method = strtr($this->view, '-', '_'); if (method_exists($this, $method)) { $this->{$method}(); } $this->after(); // Render the view with a data array $this->render->content = $this->app->render_view($this->view, $this->render, $options); return $this->app->render_type($this->type, $this->render); }
/** * register the provider * * @return mixed */ public function register() { Paginator::setCurrentPageFinder(function () { if (isset($_GET['page'])) { $page = first(GUMP::xss_clean([$_GET['page']])); return $page; } else { return 1; } }); $request = App::make('http.request'); Paginator::setRequestPathFinder(function () use($request) { if ($request instanceof Request) { return $request->getBaseWithoutQuery(); } }); }
public function parse($template) { $vars = self::$vars; $vars['_alnum'] = 'a-zA-Z0-9_'; // Replace {{variables}} $template = preg_replace_callback('/{{([' . $vars['_alnum'] . ']+)(\\/[' . $vars['_alnum'] . ' \\.,+\\-\\/!\\?]+)?}}/', function ($matches) use($vars) { if (count($matches) === 3) { $matches[1] = $matches[1] . '/' . $matches[2]; unset($matches[2]); } // Discard the first match, and check for fallbacks $matches = explode('/', last($matches)); // There will always be a first key $match = first($matches); // Set the fallback value, if it exists $fallback = isset($matches[1]) ? $matches[1] : ''; // Return matching variables, if they exist // AND are not null or empty-ish if (isset($vars[$match])) { return $vars[$match]; } // Try a fallback return $fallback; }, $template); // [conditionals][/conditionals] $template = preg_replace_callback('/(\\[[\\!?' . $vars['_alnum'] . ']+\\])(.*?\\[\\/[' . $vars['_alnum'] . ']+\\])/s', function ($matches) use($vars) { $match = str_replace(array('[', ']'), '', $matches[1]); $cond = isset($vars[$match]) and !empty($vars[$match]); // [!inverse][/inverse] if (strpos($match, '!') !== false) { $match = str_replace('!', '', $match); $cond = !isset($vars[$match]) or empty($vars[$match]); } if ($cond !== false) { return trim(preg_replace('/\\[[\\/!]?' . $match . '\\]/', '', $matches[0])); } return ''; }, $template); // Include partials (~partial~) $template = preg_replace_callback('/~([' . $vars['_alnum'] . ']+)~/', function ($matches) use($vars) { return grab(APP_BASE . 'partials/' . preg_replace('/[^' . $vars['_alnum'] . ']+/', '', $matches[0]) . '.php', $vars); }, $template); return $template; }
function display() { ?> <table class="datatable" id="table1"> <thead> <?php foreach ($this->props['cols'] as $ck => $cprop) { ?> <th><?php echo htmlspecialchars(first($cprop['caption'], $ck)); ?> </th><?php } ?> </thead> <tbody> <?php foreach ($this->data as $dRow) { ?> <tr><?php foreach ($this->props['cols'] as $ck => $cprop) { ?> <td><?php if ($cprop['onDisplay']) { print $cprop['onDisplay']($ck, $dRow); } else { print htmlspecialchars($dRow[$ck]); } ?> </td><?php } ?> </tr><?php } ?> </tbody> </table><?php return $this; }
<?php /* * This file is part of the async generator runtime project. * * (c) Julien Bianchi <*****@*****.**> * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ require_once __DIR__ . '/../../vendor/autoload.php'; use function jubianchi\async\runtime\{await, all, wrap}; use function jubianchi\async\time\{delay}; $start = microtime(true); function second() { var_dump(__FUNCTION__ . ' - ' . 3); yield from delay(1000); var_dump(__FUNCTION__ . ' - ' . 4); } function first() { var_dump(__FUNCTION__ . ' - ' . 1); yield from delay(1000); var_dump(__FUNCTION__ . ' - ' . 2); yield from delay(1000); yield from second(); return 5; } var_dump(await(all(first(), second()))); echo 'Time spent: ' . ($with = microtime(true) - $start) . PHP_EOL;
<!DOCTYPE html><link rel="stylesheet" href="assets/style.css"> <h1>Tracy Fatal Error demo</h1> <?php require __DIR__ . '/../src/tracy.php'; use Tracy\Debugger; Debugger::enable(Debugger::DETECT, __DIR__ . '/log'); function first($arg1, $arg2) { second(TRUE, FALSE); } function second($arg1, $arg2) { third(array(1, 2, 3)); } function third($arg1) { missing_funcion(); } first(10, 'any string');
<style> body { font-size: 25px; } </style> </head> <body> <h3>Functions </h3> <?php function first() { echo "Hello World"; } first(); ?> <br /> <br /> <p>Function With Variable </p> <?php function second($var) { echo "Hello {$var} <br>"; } $t = "everybody"; // we pass the variable $t in to the function second($t); second("gg"); ?> <br />
<?php $panelSize = first($_REQUEST['zoom'], 640); ?> <div id="camsPanel"><?php $camTitle = ''; $thisCam = array(); foreach (cfg('cameras/cams') as $cam) { if ($cam['id'] == $_REQUEST['id']) { $thisCam = $cam; $camTitle = htmlspecialchars(first($cam['title'], $cam['id'])); ?> <a href="<?php echo actionUrl('index', 'cam'); ?> "><img src="data/cam/<?php echo $cam['id']; ?> _mid.jpg" width="80%"/></a><?php } } ?> </div> <div style="text-align: center;"> <?php if ($thisCam['videoUrl']) { ?> <a href="<?php echo actionUrl('video', 'cam', array('id' => $thisCam['id'])); ?>
/** * Gets an account by subdomain * * @param string $subdomain * @return \App\Model\Account */ public function getBySubdomain($subdomain) { return $this->where('subdomain', $subdomain) - first(); }
/** * Grabs sources from the remote repo via ApiQueryVideoInfo.php entry point. * * Because this works with commons regardless of whether TimedMediaHandler is installed or not */ static public function getRemoteSources(&$file , $options = array() ){ global $wgMemc; // Setup source attribute options $dataPrefix = in_array( 'nodata', $options )? '': 'data-'; // Use descriptionCacheExpiry as our expire for timed text tracks info if ( $file->repo->descriptionCacheExpiry > 0 ) { wfDebug("Attempting to get sources from cache..."); $key = $file->repo->getLocalCacheKey( 'WebVideoSources', 'url', $file->getName() ); $sources = $wgMemc->get($key); if ( $sources ) { wfDebug("Success found sources in local cache\n"); return $sources; } wfDebug("source cache miss\n"); } wfDebug("Get Video sources from remote api \n"); $data = $file->repo->fetchImageQuery( array( 'action' => 'query', 'prop' => 'videoinfo', 'viprop' => 'derivatives', 'title' => $file->getTitle()->getDBKey() ) ); if( isset( $data['warnings'] ) && isset( $data['warnings']['query'] ) && $data['warnings']['query']['*'] == "Unrecognized value for parameter 'prop': videoinfo" ) { // Commons does not yet have TimedMediaHandler. // Use the normal file repo system single source: return array( self::getPrimarySourceAttributes( $file, array( $dataPrefix ) ) ); } $sources = array(); // Generate the source list from the data response: if( $data['query'] && $data['query']['pages'] ){ $vidResult = first( $data['query']['pages'] ); if( $vidResult['videoinfo'] ){ $derResult = first( $vidResult['videoinfo'] ); $derivatives = $derResult['derivatives']; foreach( $derivatives as $derivativeSource ){ $sources[] = $derivativeSource; } } } // Update the cache: if ( $sources && $this->file->repo->descriptionCacheExpiry > 0 ) { $wgMemc->set( $key, $sources, $this->file->repo->descriptionCacheExpiry ); } return $sources; }
/** * Return the last element in an array passing a given truth test. * * @param array $array * @param \Closure $callback * @param mixed $default * @return mixed */ function array_last($array, $callback, $default = null) { return first(array_reverse($array), $callback, $default); }
<!--Napisz funkcję sprawdzającą czy podana liczba jest liczbą pierwszą (jest podzielna tylko przez 1 i samą siebie). Żeby dostać resztę z dzielenia użyj operatora %, np.: 12 % 5 = 2--> <!DOCTYPE html> <html lang="pl-PL"> <head> <meta charset="utf-8"> </head> <?php function first($number) { $s = 0; for ($i = 1; $i <= $number; $i++) { echo "obrot {$i} <br>"; if ($number % $i == 0) { $s++; } } return $s; } $number = 6; //liczba którą sprawdzamy if (first($number) == 2) { echo "{$number} jest liczbą pierwszą"; } else { echo "{$number} nie jest liczbą pierwszą"; }
/** * Get the first accepted charset * * @return string */ public function getCharset() { return first(empty($this->_charsets) ? $this->_setCharsets() : $this->_charsets); }