public function init($initialiser = null) { $toolbarConfig = $this->config("bundl\\debugtoolbar"); $baseUrl = $toolbarConfig->getStr("base_url", '/_debugbar'); if (starts_with($baseUrl, '/')) { $passthroughs = $this->config("dispatch")->getArr("passthrough"); if (!isset($passthroughs[substr($baseUrl, 1)])) { throw new \Exception("Please add the following to your defaults.ini within [dispatch]\n" . "passthrough[" . substr($baseUrl, 1) . "] = " . "../vendor/maximebf/debugbar/src/DebugBar/Resources"); } } EventManager::listen(EventManager::CUBEX_WEBPAGE_RENDER_BODY, [$this, "renderBody"]); EventManager::listen(EventManager::CUBEX_WEBPAGE_RENDER_HEAD, [$this, "renderHead"]); EventManager::listen(EventManager::CUBEX_LOG, [$this, "catchLog"]); $this->_debugBar = new DebugBar(); $this->_debugBar->addCollector(new PhpInfoCollector()); $this->_debugBar->addCollector(new MessagesCollector()); $this->_debugBar->addCollector(new TranslationDataCollector()); $this->_debugBar->addCollector(new RequestDataCollector()); $this->_debugBar->addCollector(new CubexCoreTimeData()); $this->_debugBar->addCollector(new CassandraDataCollector()); $this->_debugBar->addCollector(new QueryDataCollector()); $this->_debugBar->addCollector(new MemoryCollector()); $this->_debugBar->addCollector(new ExceptionsCollector()); $this->_debugRender = $this->_debugBar->getJavascriptRenderer(); $this->_debugRender->setBaseUrl($baseUrl); }
/** * Load the Laravel routes into the application routes for * permission assignment. * * @param $routeNameRegEx * * @return int The number of Laravel routes loaded. */ public static function loadLaravelRoutes($routeNameRegEx) { $AppRoutes = \Route::getRoutes(); $cnt = 0; foreach ($AppRoutes as $appRoute) { $name = $appRoute->getName(); $methods = $appRoute->getMethods(); $path = $appRoute->getPath(); $actionName = $appRoute->getActionName(); // Skip AuthController and PasswordController routes, Those are always authorized. if (!str_contains($actionName, 'AuthController') && !str_contains($actionName, 'PasswordController')) { // Include only if the name matches the requested Regular Expression. if (preg_match($routeNameRegEx, $name)) { foreach ($methods as $method) { $route = null; if ('HEAD' !== $method && !starts_with($path, '_debugbar')) { // Skip all DebugBar routes. // TODO: Use Repository 'findWhere' when its fixed!! // $route = $this->route->findWhere([ // 'method' => $method, // 'action_name' => $actionName, // ])->first(); $route = \App\Models\Route::ofMethod($method)->ofActionName($actionName)->ofPath($path)->first(); if (!isset($route)) { $cnt++; Route::create(['name' => $name, 'method' => $method, 'path' => $path, 'action_name' => $actionName, 'enabled' => 1]); } } } } } } return $cnt; }
/** * Tests that the authorization method is attached to all routes except for the / and /home * */ public function testAllRoutesHaveAuthorization() { $routesArr = Route::getRoutes(); //get all routes foreach ($routesArr as $route) { $path = $route->getPath(); // Log::info('testing route ' . $path); $vals = array_values($route->middleware()); $found = false; foreach ($vals as $index => $el) { if (FALSE !== strpos($el, "auth")) { $found = true; break; } } /** Temporary hack to handle resource routes until we finish the api * **/ if (starts_with($route->getPath(), "api")) { $found = true; } if ('/' === $path || 'home' === $path || 'index.php' === $path || 'mainlogin' === $path || 'register' === $path || 'login' === $path || 'forgotpassword' === $path) { $this->assertFalse($found); } else { $this->assertTrue($found, 'Route: ' . $route->getPath() . ' doesn\'t have the Authorize middleware attached (keyword \'auth\' not found in middleware array)'); } } }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if (!starts_with($request->getClientIp(), '192.168.0')) { $this->analysis(); } return $next($request); }
public function evaluateOne($text, $dependencies = []) { $parts = explode('>', $text); if (count($parts) < 2) { return ''; } if ($parts[0] == 'Dict') { $default = ''; $item = $this->getOneDict($parts[1], $default); if (count($parts) == 3) { $array = array_dot($item->toArray()); if (!array_key_exists($parts[2], $array)) { return ''; } return $array[$parts[2]]; } return $item; } else { $identifier = $parts[1]; if (starts_with($identifier, ':')) { $identifier = str_replace(':', '', $identifier); $identifier = $dependencies[$identifier]; } $item = $this->getOneEntity($parts[0], $identifier); if (!$item) { return ''; } $array = array_dot($item->toArray()); if (!array_key_exists($parts[2], $array)) { return ''; } return $array[$parts[2]]; } }
/** * Load the file corresponding to a given class. * * This method is registerd in the bootstrap file as an SPL auto-loader. * * @param string $class * @return void */ public static function load($class) { // First, we will check to see if the class has been aliased. If it has, // we will register the alias, which may cause the auto-loader to be // called again for the "real" class name to load its file. if (isset(static::$aliases[$class])) { class_alias(static::$aliases[$class], $class); } elseif (isset(static::$mappings[$class])) { require static::$mappings[$class]; return; } // If the class namespace is mapped to a directory, we will load the // class using the PSR-0 standards from that directory accounting // for the root of the namespace by trimming it off. foreach (static::$namespaces as $namespace => $directory) { if (starts_with($class, $namespace)) { return static::load_namespaced($class, $namespace, $directory); } } // If the class uses PEAR-ish style underscores for indicating its // directory structure we'll load the class using PSR-0 standards // standards from that directory, trimming the root. foreach (static::$underscored as $prefix => $directory) { if (starts_with($class, $prefix)) { return static::load_namespaced($class, $prefix, $directory); } } // If all else fails we will just iterator through the mapped // PSR-0 directories looking for the class. This is the last // resort and slowest loading option for the class. static::load_psr($class); }
/** * parse username to get userid * */ protected function getUserId($username) { if (starts_with($username, "@:")) { return substr($username, 2); } return \Veer\Models\User::where('username', '=', substr($username, 1))->pluck('id'); }
/** * Gets the value of an environment variable. Supports boolean, empty and null. * @param string $key * @param mixed $default * @return mixed */ function env($key, $default = null) { $value = getenv($key); if ($value === false) { return value($default); } switch (strtolower($value)) { case 'true': case '(true)': return true; case 'false': case '(false)': return false; case 'empty': case '(empty)': return ''; case 'null': case '(null)': return; } if (strlen($value) > 1 && starts_with($value, '"') && str_finish($value, '"')) { return substr($value, 1, -1); } return $value; }
/** * Generate a URL to an application asset. * * @param string $path * @param bool $secure * @return string */ protected function configAssetUrl($path, $secure = null) { static $assetUrl; // Remove this. $i = 'index.php'; if (URL::isValidUrl($path)) { return $path; } // Finding asset url config. if (is_null($assetUrl)) { $assetUrl = \Config::get('theme.assetUrl', ''); } // Using asset url, if available. if ($assetUrl) { $base = rtrim($assetUrl, '/'); // Asset URL without index. $basePath = str_contains($base, $i) ? str_replace('/' . $i, '', $base) : $base; } else { if (is_null($secure)) { $scheme = Request::getScheme() . '://'; } else { $scheme = $secure ? 'https://' : 'http://'; } // Get root URL. $root = Request::root(); $start = starts_with($root, 'http://') ? 'http://' : 'https://'; $root = preg_replace('~' . $start . '~', $scheme, $root, 1); // Asset URL without index. $basePath = str_contains($root, $i) ? str_replace('/' . $i, '', $root) : $root; } return $basePath . '/' . $path; }
protected function initForm($model) { $this->html = ""; $this->model = $model; foreach ($this->model->getFieldSpec() as $key => $property) { if (starts_with($key, 'seo') && $this->showSeo or !starts_with($key, 'seo') && !$this->showSeo) { $this->formModelHandler($property, $key, $this->model->{$key}); } } if (isset($this->model->translatedAttributes) && count($this->model->translatedAttributes) > 0) { $this->model->fieldspec = $this->model->getFieldSpec(); foreach (config('app.locales') as $locale => $value) { if (config('app.locale') != $locale) { $target = "language_box_" . str_slug($value) . "_" . str_random(160); $this->html .= $this->containerLanguage($value, $target); $this->html .= "<div class=\"collapse\" id=\"" . $target . "\">"; foreach ($this->model->translatedAttributes as $attribute) { $value = isset($this->model->translate($locale)->{$attribute}) ? $this->model->translate($locale)->{$attribute} : ''; $this->property = $this->model->fieldspec[$attribute]; if (starts_with($attribute, 'seo') && $this->showSeo or !starts_with($attribute, 'seo') && !$this->showSeo) { $this->formModelHandler($this->model->fieldspec[$attribute], $attribute . '_' . $locale, $value); } } $this->html .= "</div>"; } } } }
public static function summary(Account $account) { // create 3 months range : this month and 2 months before $months = []; foreach (range(0, 2) as $val) { $months[] = date('Y-m', strtotime('-' . $val . ' months')); } sort($months); $range = [$months[0] . date('-01 00:00:00'), $months[count($months) - 1] . date('-d H:i:s')]; $ledger = $account->ledgers()->whereBetween('created_at', $range)->get(['created_at', 'debit', 'credit', 'balance'])->toArray(); if (!count($ledger)) { return []; } // $months = array_flip($months); foreach ($months as $monthsKey => $month) { $month_data = ['debit' => 0, 'credit' => 0, 'balance' => 0, 'month' => date('M Y', strtotime($month . '-01'))]; foreach ($ledger as $ledgerKey => $transaction) { if (!starts_with($transaction['created_at'], $month)) { continue; } $month_data['debit'] += $transaction['debit'] / 100; $month_data['credit'] += $transaction['credit'] / 100; $month_data['balance'] = $transaction['balance'] / 100; } $months[$monthsKey] = $month_data; } return $months; }
/** * Put a breadcrumb into the collection. * * @param string $key * @param string $value */ public function put($key, $value) { if (!starts_with($value, 'http')) { $value = url($value); } parent::put($key, $value); }
/** * Register the handlers for the client. * * @param array $handlers */ public function registerHandlers(array $handlers = []) { foreach ($handlers as $handlerClass => $configuration) { // If the handler takes a configuration, load that from the array and // build the class. If not, then just build the class. if (is_numeric($handlerClass)) { $handlerClass = $configuration; $class = new $handlerClass(); } else { $class = new $handlerClass($configuration); } // Use reflection to figure out what Elasticsearch methods the handler handles. $reflect = new ReflectionClass($class); // Find the handled methods and merge them into the client's list. $classMethods = $reflect->getMethods(ReflectionMethod::IS_PUBLIC); array_walk($classMethods, function ($classMethod) use($handlerClass) { if (starts_with($classMethod->name, 'handle')) { $method = lcfirst(substr($classMethod->name, 6)); $this->handledMethods[$method][] = $handlerClass; } }); // Save the handler instance. $this->handlers[$handlerClass] = $class; } // Boot all the handlers with the client instance. foreach ($this->handlers as $handler) { $handler->boot($this); } }
/** * Dynamically bind parameters to the view. * * @param string $method * @param array $parameters * @return View * @throws \BadMethodCallException */ public function __call($method, $parameters) { if (starts_with($method, 'using')) { return $this->using(snake_case(substr($method, 5))); } return parent::__call($method, $parameters); }
public function __call($method, $parameters) { if (starts_with($method, 'with')) { return $this->with(snake_case(substr($method, 4)), $parameters[0]); } throw new BadMethodCallException("方法 [{$method}] 不存在!."); }
/** * @return string */ public function getRouteKeyName() { if (!starts_with(app('request')->getRequestUri(), ['/admin', '/api'])) { return isset($this->sluggable['save_to']) ? $this->sluggable['save_to'] : 'slug'; } return $this->getKeyName(); }
/** * Determine if the given controller method is routable. * * @param \ReflectionMethod $method * @return bool */ public function isRoutable(ReflectionMethod $method) { if ($method->class == 'Nova\\Routing\\Controller') { return false; } return starts_with($method->name, $this->verbs); }
/** * Call the Artisan command * * @param Request $request * @param string $command */ public function command(Request $request, $command) { if (array_key_exists('argument_name', $request->all())) { $this->validate($request, ['argument_name' => 'required']); } if (array_key_exists('argument_id', $request->all())) { $this->validate($request, ['argument_id' => 'required']); } $inputs = $request->except('_token', 'command'); $params = []; foreach ($inputs as $key => $value) { if ($value != '') { $name = starts_with($key, 'argument') ? substr($key, 9) : '--' . substr($key, 7); $params[$name] = $value; } } try { Artisan::call($command, $params); $output = Artisan::output(); $http_code = 200; } catch (Exception $e) { $output = $e->getMessage(); $http_code = 400; } if ($request->ajax()) { $response = new Response($output, $http_code); $response->header('Content-Type', 'text/plain'); return $response; } else { return back()->with($http_code == 400 ? 'error' : 'output', $output); } }
/** * Load the Laravel routes into the application routes for * permission assignment. * * @return int The number of Laravel routes loaded. */ public static function loadLaravelRoutes() { $AppRoutes = \Route::getRoutes(); $cnt = 0; foreach ($AppRoutes as $appRoute) { $name = $appRoute->getName(); $methods = $appRoute->getMethods(); $path = $appRoute->getPath(); $actionName = $appRoute->getActionName(); if (!str_contains($actionName, 'AuthController') && !str_contains($actionName, 'PasswordController')) { foreach ($methods as $method) { $route = null; if ('HEAD' !== $method && !starts_with($path, '_debugbar')) { // Skip all DebugBar routes. // TODO: Use Repository 'findWhere' when its fixed!! // $route = $this->route->findWhere([ // 'method' => $method, // 'action_name' => $actionName, // ])->first(); $route = \App\Models\Route::ofMethod($method)->ofActionName($actionName)->ofPath($path)->first(); if (!isset($route)) { $cnt++; $newRoute = Route::create(['name' => $name, 'method' => $method, 'path' => $path, 'action_name' => $actionName, 'enabled' => 1]); } } } } } return $cnt; }
public static function checkPhoneNumber($string) { if (!starts_with($string, '+')) { throw CouldNotCreateMessage::invalidPhoneNumber(); } return $string; }
public function test01StartsWith() { $this->assertTrue(function_exists('starts_with')); $this->assertTrue(starts_with('starts_with', 'start')); $this->assertFalse(starts_with('start', 'starts_with')); $this->assertTrue(starts_with('starts_with', '')); }
/** * Compare the amount of the relations with the limitation. * * @param \Illuminate\Database\Eloquent\Model $model * * @return mixed */ public function compare($model) { // Flush session before each check $session = session()->get(null); foreach ($session as $key => $value) { if (starts_with($key, 'doorkeeper_')) { session()->forget($key); } } // Limits $limits = $model->limitations; // No limits if ($limits->isEmpty()) { return $model; } // Check each relation and limitation $overallCount = 0; foreach ($limits as $relation => $limit) { if (!$model->{$relation}) { continue; } $relationCount = $model->{$relation}->count(); $overallCount += $relationCount; if ($relationCount >= $limit) { session()->put('doorkeeper_reached_' . $relation, true); } session()->put('doorkeeper_count_' . $relation, $relationCount); } // Check if the overall limit has been reached if ($overallCount >= $limits->sum()) { session()->put('doorkeeper_reached_maximum', true); } session()->put('doorkeeper_overall_count', $overallCount); }
public function index() { $urls = []; $routes = Route::getRoutes(); foreach ($routes as $route) { $path = $route->getPath(); $actions = $route->getAction(); $params = $route->parameterNames(); $controller = $actions['controller']; if (starts_with($path, '_') or str_contains($controller, 'RedirectController') or count($params)) { continue; } $urls[] = url($path); } foreach (Campus::all() as $item) { $urls[] = url($item->url); } foreach (Event::all() as $item) { $urls[] = url($item->url); } foreach (Series::withDrafts()->get() as $item) { $urls[] = url($item->url); } foreach (Staff::all() as $item) { $urls[] = url($item->url); } foreach (MissionLocation::all() as $item) { $urls[] = url($item->url); } foreach (Video::withDrafts()->get() as $item) { $urls[] = url($item->url); } return response()->json($urls); }
/** * Determine if the given controller method is routable. * * @param ReflectionMethod $method * @param string $controller * @return bool */ public function isRoutable(ReflectionMethod $method, $controller) { if ($method->class == 'Illuminate\\Routing\\Controller') { return false; } return $method->isPublic() && starts_with($method->name, $this->verbs); }
protected function download(Request $request, $prefix, $attachment = false) { $path = $request->path(); // trim prefix if (starts_with($path, $prefix)) { $path = substr($path, strlen($prefix)); } debug_log('File Download[File Path]', $path); // make absolute file path $path = wordpress_path($path); // ERROR: file not found if (!is_file($path)) { debug_log('File Download: [Abort]: not found'); abort(404); } $extension = pathinfo($path, PATHINFO_EXTENSION); // ERROR: file extension is .php if ($extension == 'php') { debug_log('File Download: [Abort]: .php'); abort(404); } debug_log('File Download[Content Type]', $this->getMimeType($path, $extension)); $headers = ['Content-Type' => $this->getMimeType($path, $extension)]; if ($attachment === false) { return response()->make(file_get_contents($path), 200, $headers); } return response()->download($path, 200, $headers); }
/** * Compile the include statements into valid PHP. * * @param string $expression * @return string */ protected function compileRaw($expression) { if (starts_with($expression, '(')) { $expression = substr($expression, 1, -1); } return "<?php echo \$__env->make({$expression}, ['raw' => true], array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>"; }
public function call() { // The Slim application $app = $this->app; // The Environment object $environment = $app->environment; // The Request object $request = $app->request; // The Response object $response = $app->response; // Route Configuration $routeConfig = ['/api/user' => \App\Http\ApiUserController::class, '/api' => \App\Http\ApiSiteController::class, '/' => \App\Http\SiteController::class]; // Request path info $pathInfo = $request->getPathInfo(); // Searching per directory foreach ($routeConfig as $basePath => $controller) { if ($pathInfo === $basePath) { with(new $controller($app, $basePath))->map(); break; } if (starts_with(ltrim($pathInfo, '/'), ltrim($basePath, '/'))) { with(new $controller($app, $basePath))->map(); break; } } // Call next middleware $this->next->call(); }
/** * Emulates LIKE '%STR' behavior * @param $str string the haystack * @param $query string the needle * @return bool */ private function startsWith($str, $query) { $str = strtolower($str); $query = strtolower($query); // testing this function return starts_with($str, $query); }
public function boot() { $this->app['validator']->extend('LangRequired', function ($attribute, $value) { $fields = $this->app['request']->all(); $protocol = 'xe_lang_preprocessor://'; $prefix = null; foreach ($fields as $key => $val) { if (starts_with($key, $protocol)) { if ($val == $attribute) { $prefix = substr($key, 0, strrpos($key, '/')); break; } } } $locale = $this->app['xe.translator']->getLocale(); $name = $prefix . '/locale/' . $locale; $validator = null; foreach ($fields as $key => $val) { if ($name == $key) { $validator = $this->app['validator']->make([$attribute => $val], [$attribute => 'Required']); } } if ($validator === null) { return false; } return $validator->passes(); }, 'The :attribute field is required.'); }
/** * @param $item * @return string */ protected function createItem($item) { $itemIdAttribute = $this->field->item_id_attribute ?: "id"; $itemId = null; $isTemplate = $item === null; if (!$isTemplate) { if ($this->instance->__sharp_duplication) { // Duplication case: we change each existing item ID to make // them like new ones. $itemId = (!starts_with($item->{$itemIdAttribute}, "N_") ? "N_" : "") . $item->{$itemIdAttribute}; $item->__sharp_duplication = true; } else { $itemId = $item->{$itemIdAttribute}; } } $hiddenKey = $this->key . "[" . ($isTemplate ? "--N--" : $itemId) . "][{$itemIdAttribute}]"; $strItem = '<li class="list-group-item sharp-list-item ' . ($isTemplate ? "template" : "") . '">' . '<div class="row">' . Form::hidden($hiddenKey, $isTemplate ? "N" : $itemId, ["class" => "sharp-list-item-id"]) . $this->createItemField($item) . '</div>'; if ($this->field->sortable || $this->field->removable) { $strItem .= '<div class="row"><div class="col-md-12">'; if ($this->field->sortable) { $strItem .= '<a class="sort-handle btn btn-sm"><i class="fa fa-sort"></i></a>'; } if ($this->field->removable) { $strRemove = $this->field->remove_button_text ?: Lang::get('sharp::ui.form_listField_deleteItem'); $strItem .= '<a class="sharp-list-remove btn btn-sm"><i class="fa fa-times"></i> ' . $strRemove . '</a>'; } $strItem .= '</div></div>'; } $strItem .= '</li>'; return $strItem; }