_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
33
8k
language
stringclasses
1 value
meta_information
dict
q21100
ForgotPasswordController.sendResetLinkResponse
train
protected function sendResetLinkResponse(Request $request, $response) { if ($request->expectsJson()) { return response()->json([ 'status' => trans($response)
php
{ "resource": "" }
q21101
ControllerRoute.obtainReplacements
train
protected function obtainReplacements() { return [ 'ROUTE_LINK' => $link = $this->getReplacements()[0], 'ROUTE_CONTROLLER' => $this->controller($this->getReplacements()[1]),
php
{ "resource": "" }
q21102
AdminLTE.publicAssets
train
public function publicAssets() { return [ ADMINLTETEMPLATE_PATH.'/public/css' => public_path('css'), ADMINLTETEMPLATE_PATH.'/public/js' => public_path('js'), ADMINLTETEMPLATE_PATH.'/public/fonts' => public_path('fonts'), ...
php
{ "resource": "" }
q21103
AdminLTE.views
train
public function views() { return [ ADMINLTETEMPLATE_PATH.'/resources/views/auth' => resource_path('views/vendor/adminlte/auth'), ADMINLTETEMPLATE_PATH.'/resources/views/errors' => resource_path('views/vendor/adminlte/errors'), ...
php
{ "resource": "" }
q21104
AdminLTE.resourceAssets
train
public function resourceAssets() { return [ ADMINLTETEMPLATE_PATH.'/resources/assets/css' => resource_path('assets/css'), ADMINLTETEMPLATE_PATH.'/resources/assets/img' => resource_path('assets/img'), ADMINLTETEMPLATE_PATH.'/resources/assets/js' => resource_path('assets/...
php
{ "resource": "" }
q21105
Installable.install
train
private function install($files) { foreach ($files as $fileSrc => $fileDst) { if (file_exists($fileDst) && !$this->force && !$this->confirmOverwrite(basename($fileDst))) { return; } if ($this->files->isFile($fileSrc)) { $this->publishFile($...
php
{ "resource": "" }
q21106
MakeV.command
train
protected function command() { $api = $this->option('api') ? ' --api ' : ''; $action = $this->argument('action') ? ' ' . $this->argument('action') . ' ' : ''; return 'php artisan make:route '
php
{ "resource": "" }
q21107
Controller.controllerMethod
train
protected function controllerMethod($controllername) { if (str_contains($controller = $controllername, '@'))
php
{ "resource": "" }
q21108
HasEmail.email
train
protected function email() { if (($email = env('ADMIN_EMAIL', null)) != null) { return $email; }
php
{ "resource": "" }
q21109
HasUsername.username
train
public function username() { if (($username = env('ADMIN_USERNAME', null)) != null) { return $username; }
php
{ "resource": "" }
q21110
MakeRoute.routeExists
train
protected function routeExists($link) { if ($this->option('api')) { return $this->apiRouteExists($link);
php
{ "resource": "" }
q21111
MakeRoute.webRouteExists
train
protected function webRouteExists($link) { $link = $this->removeTrailingSlashIfExists($link); $link = $this->removeDuplicatedTrailingSlashes($link); foreach (Route::getRoutes() as $value) { if (in_array(strtoupper($this->option('method')),
php
{ "resource": "" }
q21112
MakeRoute.action
train
protected function action() { if ($this->argument('action') != null) { return $this->argument('action');
php
{ "resource": "" }
q21113
MakeRoute.validateMethod
train
protected function validateMethod() { if (! in_array(strtoupper($this->option('method')), $methods = array_merge(Router::$verbs, ['ANY']))) {
php
{ "resource": "" }
q21114
MakeRoute.createMenu
train
protected function createMenu() { try { $this->warnIfSpatieMenuIsNotInstalled(); } catch (\Exception $e) { //Skip installation of menu $this->error($e->getMessage()); return; } Artisan::call('make:menu', [
php
{ "resource": "" }
q21115
MakeRoute.createView
train
protected function createView($name = null) { if ($name == null) { $name = $this->action(); } Artisan::call('make:view', [ 'name' => $name
php
{ "resource": "" }
q21116
MakeRoute.createController
train
protected function createController() { Artisan::call('make:controller', [ 'name' => $controller = $this->controllerWithoutMethod($this->action()) ]); $this->addMethodToController($controller,
php
{ "resource": "" }
q21117
MakeRoute.createResourceController
train
protected function createResourceController() { Artisan::call('make:controller', [ 'name' => $controller = $this->controllerWithoutMethod($this->action()),
php
{ "resource": "" }
q21118
MakeRoute.addMethodToController
train
protected function addMethodToController($controller, $controllerMethod) { $tmpfile = $this->createTmpFileWithMethod($controllerMethod); $path = $this->getPath($tmpfile);
php
{ "resource": "" }
q21119
MakeRoute.createTmpFileWithMethod
train
protected function createTmpFileWithMethod($controllerMethod) { $temp = tmpfile();
php
{ "resource": "" }
q21120
Route.code
train
public function code() { return $this->compiler->compile( $this->filesystem->get($this->getStubPath()),
php
{ "resource": "" }
q21121
Collection.findOne
train
public function findOne($criteria = null, $projection = null) { $items = $this->find($criteria,
php
{ "resource": "" }
q21122
App.service
train
public function service($name, $callable) { $this->registry[$name] = function($c) use($callable) { static $object; if (null === $object) {
php
{ "resource": "" }
q21123
App.baseUrl
train
public function baseUrl($path) { $url = ''; if (\strpos($path, ':')===false) { /* if ($this->registry['base_port'] != '80') { $url .= $this->registry['site_url']; }
php
{ "resource": "" }
q21124
App.set
train
public function set($key, $value) { $keys = \explode('/',$key); if (\count($keys)>5) return false; switch (\count($keys)){ case 1: $this->registry[$keys[0]] = $value; break; case 2: $this->registry[$keys[0]][$keys[1]] = $value; ...
php
{ "resource": "" }
q21125
App.path
train
public function path(){ $args = \func_get_args(); switch (\count($args)){ case 1: $file = $args[0]; if ($this->isAbsolutePath($file) && \file_exists($file)) { return $file; } $parts = \explode(':', $fi...
php
{ "resource": "" }
q21126
App.cache
train
public function cache(){ $args = \func_get_args(); switch(\count($args)){ case 1: return $this->helper('cache')->read($args[0]); case 2:
php
{ "resource": "" }
q21127
App.block
train
public function block($name, $options=[]) { if (!isset($this->blocks[$name])) return null; $options = \array_merge([ 'print' => true ], $options); $block = \implode("\n",
php
{ "resource": "" }
q21128
App.param
train
public function param($index=null, $default = null, $source = null) { $src = $source ? $source : $_REQUEST; $cast = null; if (\strpos($index, ':') !== false) { list($index, $cast) = \explode(':', $index, 2); } $value = fetch_from_array($src, $index, $default); ...
php
{ "resource": "" }
q21129
App.get
train
public function get($path, $callback, $condition = true){ if (!$this->req_is('get')) return;
php
{ "resource": "" }
q21130
App.post
train
public function post($path, $callback, $condition = true){ if (!$this->req_is('post')) return;
php
{ "resource": "" }
q21131
App.bindClass
train
public function bindClass($class, $alias = false) { $self = $this; $clean = $alias ? $alias : \trim(\strtolower(\str_replace("\\", "/", $class)), "\\"); $this->bind('/'.$clean.'/*', function() use($self, $class, $clean) { $parts = \explode('/', \trim(\preg_replace("#$clean#"...
php
{ "resource": "" }
q21132
App.bind
train
public function bind($path, $callback, $condition = true) { if (!$condition) return; if (!isset($this->routes[$path])) { $this->routes[$path] = []; } // make $this available in closures if (\is_object($callback) && $callback instanceof \Closure) { $call...
php
{ "resource": "" }
q21133
App.render_route
train
protected function render_route($route, $params = []) { $output = false; if (isset($this->routes[$route])) { $ret = null; if
php
{ "resource": "" }
q21134
App.invoke
train
public function invoke($class, $action="index", $params=[]) { $controller = new $class($this); return \method_exists($controller, $action) && \is_callable([$controller, $action])
php
{ "resource": "" }
q21135
App.getClientIp
train
public function getClientIp(){ if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])){ // Use the forwarded IP address, typically set when the // client is using a proxy server. return $_SERVER['HTTP_X_FORWARDED_FOR']; }elseif (isset($_SERVER['HTTP_CLIENT_IP'])){ /...
php
{ "resource": "" }
q21136
Utils.resolveDependencies
train
public function resolveDependencies(array $data) { $new_data = array(); $original_count = \count($data); while (\count($new_data) < $original_count) { foreach ($data as $name => $dependencies) { if (!\count($dependencies)) { $new_data[] = ...
php
{ "resource": "" }
q21137
Utils.url_get_contents
train
public function url_get_contents($url) { $content = ''; if (\function_exists('curl_exec')){ $conn = \curl_init($url); \curl_setopt($conn, CURLOPT_SSL_VERIFYPEER, true); \curl_setopt($conn, CURLOPT_FRESH_CONNECT, true); \curl_setopt($conn, CURLOPT_RETURNTRANSF...
php
{ "resource": "" }
q21138
Utils.isEmail
train
public function isEmail($email) { if (\function_exists('idn_to_ascii')) { $email = @\idn_to_ascii($email);
php
{ "resource": "" }
q21139
Utils.fixStringBooleanValues
train
public function fixStringBooleanValues(&$input) { if (!\is_array($input)) { if (\is_string($input) && ($input === 'true' || $input === 'false')) { $input = filter_var($input, FILTER_VALIDATE_BOOLEAN); } return $input; } foreach ($input as $k => $v) { if (\is...
php
{ "resource": "" }
q21140
Utils.fixStringNumericValues
train
public function fixStringNumericValues(&$input) { if (!\is_array($input)) { if (\is_string($input) && \is_numeric($input)) { $input += 0; } return $input; } foreach ($input as $k => $v) { if (\is_array($input[$k])) {
php
{ "resource": "" }
q21141
Utils.retry
train
public function retry($times, callable $fn) { retrybeginning: try { return $fn(); } catch (\Exception $e) { if (!$times) {
php
{ "resource": "" }
q21142
Assets.style
train
public function style($assets, $name, $path="", $cache=0, $version=false) { $path = $this->path($path); if(!$path) return null; $href = rtrim($this->pathToUrl($path), '/')."/{$name}.css".($version ? "?ver={$version}":""); $path.= "/{$name}.css"; $tag = '<link href="'.$href.'"...
php
{ "resource": "" }
q21143
Assets.style_and_script
train
public function style_and_script($assets, $name, $path="", $cache=0, $version=false) { echo $this->script($assets, $name, $path, $cache, $version);
php
{ "resource": "" }
q21144
Lexy.compile_default_structures
train
protected function compile_default_structures($value) { $value = preg_replace('/(?(R)\((?:[^\(\)]|(?R))*\)|(?<!\w)(\s*)@(if|foreach|for|while)(\s*(?R)+))/', '$1<?php $2 $3 { ?>', $value); $value = preg_replace('/(\s*)@elseif(\s*\(.*\))/', '$1<?php } elseif$2 { ?>', $value);
php
{ "resource": "" }
q21145
RedisLite.keys
train
public function keys($pattern = null) { $keys = array(); $stmt = $this->connection->query("SELECT `key` FROM ".$this->table." ORDER BY `key`;"); $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); if (!$pattern) { foreach ($res as $record) { $keys[] = $record["key"...
php
{ "resource": "" }
q21146
Database.registerCriteriaFunction
train
public function registerCriteriaFunction($criteria) { $id = \uniqid('criteria'); if (\is_callable($criteria)) { $this->document_criterias[$id] = $criteria; return $id; } if (is_array($criteria)) { $fn
php
{ "resource": "" }
q21147
Database.callCriteriaFunction
train
public function callCriteriaFunction($id, $document) { return isset($this->document_criterias[$id]) ?
php
{ "resource": "" }
q21148
Database.getCollectionNames
train
public function getCollectionNames() { $stmt = $this->connection->query("SELECT name FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence';");
php
{ "resource": "" }
q21149
Database.listCollections
train
public function listCollections() { foreach ($this->getCollectionNames() as $name) { if(!isset($this->collections[$name])) { $this->collections[$name]
php
{ "resource": "" }
q21150
Cookie.set
train
public function set($name, $value, $ttl = 86400 /* 1 day */, $path = '/', $domain = '', $secure = false, $http_only = false) { $this->_cookies[$name] = $value; $result = \setcookie($name, $value, time() + $ttl, $path, $domain, $secure,
php
{ "resource": "" }
q21151
Cookie.get
train
public function get($name) { if (isset($this->_deleted_cookies[$name])) { return null; } if (\array_key_exists($name, $this->_cookies)) { return $this->_cookies[$name]; } $value =
php
{ "resource": "" }
q21152
Cookie.delete
train
public function delete($name, $path = '/', $domain = '', $secure = false, $http_only = false) { $success = $this->set($name, null, -10, $path, $domain, $secure, $http_only); $this->_deleted_cookies[$name] = $name;
php
{ "resource": "" }
q21153
Cookie.getAndDelete
train
public function getAndDelete($name, $path = '/', $domain = '', $secure = false, $http_only = false) { $value = $this->get($name);
php
{ "resource": "" }
q21154
Cursor.getData
train
protected function getData() { $sql = ['SELECT document FROM '.$this->collection->name]; if ($this->criteria) { $sql[] = 'WHERE document_criteria("'.$this->criteria.'", document)'; } if ($this->sort) { $orders = []; foreach ($this->sort as $field...
php
{ "resource": "" }
q21155
I18n.get
train
public function get($key, $alternative=null, $lang=null){ if (!$lang) { $lang = $this->locale; } if (!$alternative){ $alternative = $key;
php
{ "resource": "" }
q21156
I18n.getstr
train
public function getstr($key, $params=[], $alternative=null, $lang=null){ if (!$lang) { $lang = $this->locale; } if (!$alternative){ $alternative = $key;
php
{ "resource": "" }
q21157
I18n.load
train
public function load($langfile, $lang=null) { if (!$lang) { $lang = $this->locale; } if ($path = $this->app->path($langfile)){ if (!isset($this->_languages[$lang])){ $this->_languages[$lang] = []; }
php
{ "resource": "" }
q21158
I18n.data
train
public function data($lang=null) { if ($lang) { return isset($this->_languages[$lang])
php
{ "resource": "" }
q21159
Client.hincrby
train
public function hincrby($collection, $key, $field, $by = 1) { $current = $this->hget($collection, $key, $field, 0); $newone = $current+$by;
php
{ "resource": "" }
q21160
Client.hmget
train
public function hmget($key) { $set = $this->getKey($collection, $key, []); $fields = func_get_args(); $values = []; for ($i=1; $i<count($fields); $i++){ $field = $fields[$i];
php
{ "resource": "" }
q21161
ContainerArray.offsetSet
train
public function offsetSet($key, $value) { if (strpos($key, '/')) { $keys = explode('/', $key); $mem = $this->props; foreach($keys as $keyname) { if (!isset($mem[$keyname])) { $mem[$keyname] = new ArrayObject([]); } ...
php
{ "resource": "" }
q21162
TokenRepository.findForUser
train
public function findForUser($id, $userId) { return
php
{ "resource": "" }
q21163
TokenRepository.findValidToken
train
public function findValidToken($user, $client) { return $client->tokens() ->whereUserId($user->getKey()) ->where('revoked', 0)
php
{ "resource": "" }
q21164
ClientCommand.createClientCredentialsClient
train
protected function createClientCredentialsClient(ClientRepository $clients) { $name = $this->option('name') ?: $this->ask( 'What should we name the client?', config('app.name').' ClientCredentials Grant Client' ); $client =
php
{ "resource": "" }
q21165
ClientCommand.outputClientDetails
train
protected function outputClientDetails(Client $client) { $this->line('<comment>Client ID:</comment> '.$client->id);
php
{ "resource": "" }
q21166
ApiTokenCookieFactory.make
train
public function make($userId, $csrfToken) { $config = $this->config->get('session'); $expiration = Carbon::now()->addMinutes($config['lifetime']); return new Cookie( Passport::cookie(), $this->createToken($userId, $csrfToken, $expiration), $expiration,
php
{ "resource": "" }
q21167
ApiTokenCookieFactory.createToken
train
protected function createToken($userId, $csrfToken, Carbon $expiration) { return JWT::encode([ 'sub' => $userId, 'csrf' => $csrfToken,
php
{ "resource": "" }
q21168
PersonalAccessTokenFactory.make
train
public function make($userId, $name, array $scopes = []) { $response = $this->dispatchRequestToAuthorizationServer( $this->createRequest($this->clients->personalAccessClient(), $userId, $scopes) ); $token = tap($this->findAccessToken($response), function ($token) use ($userId, $...
php
{ "resource": "" }
q21169
PersonalAccessTokenFactory.dispatchRequestToAuthorizationServer
train
protected function dispatchRequestToAuthorizationServer(ServerRequest $request) { return json_decode($this->server->respondToAccessTokenRequest(
php
{ "resource": "" }
q21170
PersonalAccessTokenFactory.findAccessToken
train
protected function findAccessToken(array $response) { return $this->tokens->find(
php
{ "resource": "" }
q21171
TransientTokenController.refresh
train
public function refresh(Request $request) { return (new Response('Refreshed.'))->withCookie($this->cookieFactory->make(
php
{ "resource": "" }
q21172
RetrievesAuthRequestFromSession.getAuthRequestFromSession
train
protected function getAuthRequestFromSession(Request $request) { return tap($request->session()->get('authRequest'), function ($authRequest) use ($request) { if (! $authRequest) { throw new Exception('Authorization request was not present in the session.');
php
{ "resource": "" }
q21173
PassportServiceProvider.registerAuthorizationServer
train
protected function registerAuthorizationServer() { $this->app->singleton(AuthorizationServer::class, function () { return tap($this->makeAuthorizationServer(), function ($server) { $server->setDefaultScope(Passport::$defaultScope); $server->enableGrantType( ...
php
{ "resource": "" }
q21174
PassportServiceProvider.buildAuthCodeGrant
train
protected function buildAuthCodeGrant() { return new AuthCodeGrant( $this->app->make(Bridge\AuthCodeRepository::class),
php
{ "resource": "" }
q21175
PassportServiceProvider.makeRefreshTokenGrant
train
protected function makeRefreshTokenGrant() { $repository = $this->app->make(RefreshTokenRepository::class); return tap(new RefreshTokenGrant($repository), function ($grant) {
php
{ "resource": "" }
q21176
PassportServiceProvider.makeCryptKey
train
protected function makeCryptKey($type) { $key = str_replace('\\n', "\n", $this->app->make(Config::class)->get('passport.'.$type.'_key')); if (! $key) {
php
{ "resource": "" }
q21177
PassportServiceProvider.registerGuard
train
protected function registerGuard() { Auth::extend('passport', function ($app, $name, array $config) {
php
{ "resource": "" }
q21178
PassportServiceProvider.makeGuard
train
protected function makeGuard(array $config) { return new RequestGuard(function ($request) use ($config) { return (new TokenGuard( $this->app->make(ResourceServer::class), Auth::createUserProvider($config['provider']), $this->app->make(TokenReposito...
php
{ "resource": "" }
q21179
PassportServiceProvider.deleteCookieOnLogout
train
protected function deleteCookieOnLogout() { Event::listen(Logout::class, function () { if (Request::hasCookie(Passport::cookie())) {
php
{ "resource": "" }
q21180
AuthorizedAccessTokenController.forUser
train
public function forUser(Request $request) { $tokens = $this->tokenRepository->forUser($request->user()->getKey()); return $tokens->load('client')->filter(function ($token) {
php
{ "resource": "" }
q21181
AuthorizedAccessTokenController.destroy
train
public function destroy(Request $request, $tokenId) { $token = $this->tokenRepository->findForUser( $tokenId, $request->user()->getKey() ); if (is_null($token)) { return new Response('',
php
{ "resource": "" }
q21182
TokenGuard.user
train
public function user(Request $request) { if ($request->bearerToken()) { return $this->authenticateViaBearerToken($request); }
php
{ "resource": "" }
q21183
TokenGuard.client
train
public function client(Request $request) { if ($request->bearerToken()) { if (! $psr = $this->getPsrRequestViaBearerToken($request)) { return; } return $this->clients->findActive( $psr->getAttribute('oauth_client_id') );
php
{ "resource": "" }
q21184
TokenGuard.getPsrRequestViaBearerToken
train
protected function getPsrRequestViaBearerToken($request) { // First, we will convert the Symfony request to a PSR-7 implementation which will // be compatible with the base OAuth2 library. The Symfony bridge can perform a // conversion for us to a Zend Diactoros implementation of the PSR-7 r...
php
{ "resource": "" }
q21185
TokenGuard.getTokenViaCookie
train
protected function getTokenViaCookie($request) { // If we need to retrieve the token from the cookie, it'll be encrypted so we must // first decrypt the cookie and then attempt to find the token value within the // database. If we can't decrypt the value we'll bail out with a null return. ...
php
{ "resource": "" }
q21186
ClientRepository.find
train
public function find($id) { $client = Passport::client();
php
{ "resource": "" }
q21187
ClientRepository.findActive
train
public function findActive($id) { $client = $this->find($id);
php
{ "resource": "" }
q21188
ClientRepository.findForUser
train
public function findForUser($clientId, $userId) { $client = Passport::client(); return $client
php
{ "resource": "" }
q21189
ClientRepository.activeForUser
train
public function activeForUser($userId) { return $this->forUser($userId)->reject(function ($client) {
php
{ "resource": "" }
q21190
ClientRepository.createPasswordGrantClient
train
public function createPasswordGrantClient($userId, $name, $redirect) {
php
{ "resource": "" }
q21191
ClientRepository.revoked
train
public function revoked($id) { $client = $this->find($id);
php
{ "resource": "" }
q21192
ClientController.forUser
train
public function forUser(Request $request) { $userId = $request->user()->getKey();
php
{ "resource": "" }
q21193
Token.can
train
public function can($scope) { return in_array('*', $this->scopes)
php
{ "resource": "" }
q21194
RouteRegistrar.all
train
public function all() { $this->forAuthorization(); $this->forAccessTokens();
php
{ "resource": "" }
q21195
AuthorizationController.parseScopes
train
protected function parseScopes($authRequest) { return Passport::scopesFor( collect($authRequest->getScopes())->map(function ($scope) {
php
{ "resource": "" }
q21196
CreateFreshApiToken.alreadyContainsToken
train
protected function alreadyContainsToken($response) { foreach ($response->headers->getCookies() as $cookie) { if ($cookie->getName() ===
php
{ "resource": "" }
q21197
Passport.scopes
train
public static function scopes() { return collect(static::$scopes)->map(function ($description,
php
{ "resource": "" }
q21198
Passport.refreshTokensExpireIn
train
public static function refreshTokensExpireIn(DateTimeInterface $date = null) { if (is_null($date)) { return static::$refreshTokensExpireAt ? Carbon::now()->diff(static::$refreshTokensExpireAt)
php
{ "resource": "" }
q21199
Passport.personalAccessTokensExpireIn
train
public static function personalAccessTokensExpireIn(DateTimeInterface $date = null) { if (is_null($date)) { return static::$personalAccessTokensExpireAt ? Carbon::now()->diff(static::$personalAccessTokensExpireAt) : new
php
{ "resource": "" }