/** * Bind controller methods into a path * * @param string $path * @param string $controller_klass * * @example * * class MyController { * // Mount callback * public static function mounted($path) { * var_dump("Successfully mounted at " . $path); * } * * // GET /path * function getIndex() {} * * // POST /path/create * function postCreate() {} * * // PUT /path/update * function putUpdate() {} * * // DELETE /path * function deleteIndex() {} * } * Hook\Http\Router::mount('/', 'MyController'); * */ public static function mount($path, $controller_klass) { $mounted = null; $methods = get_class_methods($controller_klass); // skip if (!$methods) { debug("'{$controller_klass}' has no methods."); return; } foreach ($methods as $method_name) { // skip invalid methods if ($method_name == '__construct') { continue; } // call 'mounted' method if ($method_name == 'mounted') { $mounted = call_user_func(array($controller_klass, 'mounted'), $path); continue; } preg_match_all('/^(get|put|post|patch|delete)(.*)/', $method_name, $matches); $has_matches = count($matches[1]) > 0; $http_method = $has_matches ? $matches[1][0] : 'any'; $route_name = $has_matches ? $matches[2][0] : $method_name; $route = str_finish($path, '/'); if ($route_name !== 'index') { $route .= snake_case($route_name); } static::$instance->{$http_method}($route, "{$controller_klass}:{$method_name}"); } return $mounted; }
private function _initConfig() { $basePath = str_finish(dirname(__FILE__), '/'); $configPath = $basePath . '../../../config'; $loader = new FileLoader(new Filesystem(), $configPath); $this->config = new Repository($loader, $this->environment); }
/** * 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; }
/** * Publishes all themes files in the given package to their * respective themes. * * @param string $source * @return bool * @throws \InvalidArgumentException * @throws \RuntimeException */ public function publish($source) { if (!$this->filesystem->isDirectory($source)) { throw new InvalidArgumentException("Source [{$source}] does not exist."); } $paths = $this->getThemeSourcePaths($source); foreach ($paths as $path) { $relativePath = str_replace(str_finish($source, '/'), '', $path); $slugs = $this->extractSlugsFromPath($relativePath); // If we cannot resolve a theme, the user has probably got assets // for a theme which isn't in this installation. Let's not punish // them for supporting more than the installed themes, we'll just // let them know we've skipped it. try { $theme = $this->getThemeForSlugs($slugs); } catch (RuntimeException $e) { $this->note(sprintf('Couln\'t load theme for slug(s) [%s] in source [%s], skipping.', implode(', ', $slugs), $source)); continue; } $mappings = $this->getCopyMappings($path, $theme); foreach ($mappings as $_source => $destination) { $success = $this->filesystem->copyDirectory($_source, $destination); if (!$success) { throw new RuntimeException("Failed to publish [{$_source}] to [{$destination}]."); } } } return true; }
public function registerSlackMethod($name) { $contract = str_finish($this->contractsNamespace, "\\") . "Slack{$name}"; $shortcut = $this->shortcutPrefix . snake_case($name); $class = str_finish($this->methodsNamespace, "\\") . $name; $this->registerSlackSingletons($contract, $class, $shortcut); }
public static function adjustPath($path) { if (!isset($path) || $path == '') { return ""; } return str_finish(str_replace('\\', '/', $path), '/'); }
/** * Build the Site Map */ protected function buildSiteMap() { $postsInfo = $this->getPostsInfo(); $dates = array_values($postsInfo); sort($dates); $lastmod = last($dates); // $url = trim(url(), '/') . '/'; $url = str_finish(url(), '/'); $xml = []; $xml[] = '<?xml version="1.0" encoding="UTF-8"?' . '>'; $xml[] = '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; $xml[] = ' <url>'; $xml[] = " <loc>{$url}</loc>"; $xml[] = " <lastmod>{$lastmod}</lastmod>"; $xml[] = ' <changefreq>daily</changefreq>'; $xml[] = ' <priority>0.8</priority>'; $xml[] = ' </url>'; foreach ($postsInfo as $slug => $lastmod) { $xml[] = ' <url>'; $xml[] = " <loc>{$url}blog/{$slug}</loc>"; $xml[] = " <lastmod>{$lastmod}</lastmod>"; $xml[] = " </url>"; } $xml[] = '</urlset>'; return join("\n", $xml); }
/** * @return \Illuminate\Support\Collection */ private function resetIndexes() { $storagePath = str_finish(realpath(storage_path()), DIRECTORY_SEPARATOR) . '*.index'; return collect(\File::glob($storagePath))->each(function ($index) { unlink($index); }); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $mcid * @return \Illuminate\Http\Response */ public function update(Request $request, $mcid_id) { $this->validate($request, ['file' => 'required']); $mcid = MCID::findOrFail($mcid_id); $file = $_FILES['file']; $fileName = md5($mcid_id . $file['name'] . time()); $path = str_finish($this->skin_path, '/') . $fileName; $content = File::get($file['tmp_name']); if (is_image($file['type']) && $file['size'] <= 150 * 1000) { list($img_w, $img_h) = getimagesize($file['tmp_name']); if ($img_w > 64 || $img_h > 64) { $error = "皮肤文件 '{$fileName}' 尺寸不正确."; } else { $result = $this->manager->saveFile($path, $content); if ($result === true) { $skin = Skin::where('mcid_id', $mcid->id)->first(); if ($skin == null) { $skin = new Skin(); } $skin->mcid_id = $mcid->id; $skin->url = $path; $skin->save(); return redirect()->back()->withSuccess("皮肤文件 '{$fileName}' 上传成功."); } else { $error = $result ?: "皮肤文件 '{$fileName}' 上传失败."; } } } else { $error = "皮肤文件 '{$fileName}' 格式或大小不正确."; } return redirect()->back()->withErrors([$error]); }
/** * 响应一个视图 * * @param string $view * @param array $data * @param array $mergeData * * @return \Illuminate\View\View */ public function view($view = null, array $data = array(), array $mergeData = array()) { if (!is_null($view)) { //添加view目录前缀 $view = str_finish($this->viewPrefix, '.') . $view; } return view($view, $data, $mergeData); }
protected function setupPaths() { $basePath = str_finish(get_template_directory(), '/'); $controllersDirectory = $basePath . 'controllers'; $modelsDirectory = $basePath . 'models'; Illuminate\Support\ClassLoader::register(); Illuminate\Support\ClassLoader::addDirectories(array($controllersDirectory, $modelsDirectory)); }
public function getTitleAttribute() { $title = str_replace(array('http://', 'https://'), '', $this->url); $title = str_replace('www.', '', $title); $title = str_finish($title, '/'); $title = substr($title, 0, strlen($title) - 1); return $title; }
/** * Main constructor. * * Loads up the config and service container * * Utilizes 'illuminate/config' package. */ protected function __construct() { $basePath = str_finish(dirname(__DIR__), '/'); $configPath = $basePath . 'config'; $loader = new FileLoader(new Filesystem(), $configPath); $this->config = new Repository($loader, null); $this->container = new Container(); $this->bootstrapWebserviceContainer($this->container); }
public function compilePath($name) { $nextpath = str_replace('/_', '/', strtolower(implode('_', array_slice(preg_split('/(?=[A-Z])/', $this->argument('name')), 1)))); if (empty($nextpath)) { $nextpath = str_finish($this->argument('name'), '/'); } $path = str_finish($this->path, '/') . $nextpath; return $path; }
public static function url($src, $key = null) { if (static::is_url($src)) { return $src; } if ($key && ($static = static::config("paths.{$key}"))) { $src = str_finish($static, '/') . $src; } return esc_url(get_template_directory_uri() . '/' . $src); }
public function setConfiguration($creds) { $basePath = str_finish(dirname(__FILE__), '/../../'); $defaultConfigPath = $basePath . 'config'; $defaultLoader = new FileLoader(new Filesystem(), $defaultConfigPath); $this->config = new Repository($defaultLoader, 'production'); $this->config->set('pexconnection.username', $creds['username']); $this->config->set('pexconnection.password', $creds['password']); $this->creds = ['password' => $this->config->get('pexconnection.password'), 'username' => $this->config->get('pexconnection.username')]; }
private function namespaceChecker($string) { if (!is_null($string)) { if (Str::contains($string, '/')) { $string = str_replace('/', '\\', $string); } return str_finish($string, '\\'); } return $string; }
protected function getConfigurationFiles(Application $app) { $configPath = str_finish($app->configPath(), '/'); $files = $this->getConfigurationFilesInPath($configPath); foreach (explode('.', $app->environment()) as $env) { $configPath .= $env . '/'; $files = array_merge_recursive($files, $this->getConfigurationFilesInPath($configPath)); } return $files; }
/** * @param $path * @param $fileName * @return array */ public function findFiles($path, $fileName) { if ($path == '') { $path = base_path(); } if (File::isDirectory($path)) { $path = str_finish($path, '/'); } $path .= $fileName; return File::glob($path); }
public static function adjustPath($path) { if ($path == '') { return array(); } $p = explode(",", str_replace('\\', '/', $path)); $pathList = array_map(function ($item) { return str_finish($item, '/'); }, $p); return $pathList; }
public function postUpload(Request $request) { $dir = !empty($request->input('dir', '')) ? '/' . $request->input('dir', '') : ''; if ($request->hasFile('file')) { $extension = $request->file('file')->getClientOriginalExtension(); $name = $request->file('file')->getClientOriginalName(); $name = preg_replace("/(.*)(.[a-zA-Z]+)/U", "\$1", $name); $name = str_slug($name, '-'); $name = str_finish($name, '.' . $extension); $request->file('file')->move($this->dirRoot . $dir . '/', $name); } }
function thumbnail($image, $params = null) { if (is_string($params)) { list($w, $h, $fit) = explode('x', $params); $params = compact('w', 'h', 'fit'); } $server = app('laraglide'); $request = $server->makeImage($image, $params); $url = $server->getCachePath($request); $rootUrl = config('cubekit.laraglide.rootUrl') ?: '/'; $rootUrl = str_finish($rootUrl, '/'); return "{$rootUrl}{$url}"; }
/** * Upload new file */ public function uploadFile(UploadFileRequest $request) { $file = $request->file('file'); $fileName = $request->get('file_name'); $fileName = !$fileName ? $file->getClientOriginalName() : explode('.', $fileName)[0] . '.' . $file->getClientOriginalExtension(); $path = str_finish($request->get('folder'), '/') . $fileName; $content = File::get($file->getPathname()); $result = $this->manager->saveFile($path, $content); if ($result === true) { return redirect()->back()->withSuccess("File '{$fileName}' uploaded."); } $error = $result ?: "An error occurred uploading file."; return redirect()->back()->withErrors([$error]); }
/** * Get the path to a view using the default folder convention. * * @param string $bundle * @param string $view * @param string $directory * @return string */ public static function file($bundle, $view, $directory) { $directory = str_finish($directory, DS); // Views may have either the default PHP file extension of the "Blade" // extension, so we will need to check for both in the view path // and return the first one we find for the given view. if (file_exists($path = $directory . $view . EXT)) { return $path; } elseif (file_exists($path = $directory . $view . BLADE_EXT)) { return $path; } elseif (file_exists($path = $directory . $view . MUSTACHE_EXT)) { return $path; } }
/** * Constructor. We'll throw exceptions if the paths don't exist */ public function __construct() { $this->path = str_finish(Config::get('todo.folder'), '/'); if (!File::isDirectory($this->path)) { throw new \RuntimeException("Directory doesn't exist: {$this->path}"); } if (!File::isDirectory($this->path . 'archived')) { throw new \RuntimeException("Directory doesn't exist: {$this->path}" . 'archived'); } $this->extension = Config::get('todo.extension'); if (!starts_with($this->extension, '.')) { $this->extension = '.' . $this->extension; } }
public function uploadFile(UploadFileRequest $request) { $file = $_FILES["file"]; $fileName = $request->get("file_name"); $fileName = $fileName ?: $file["name"]; $path = str_finish($request->get("folder"), "/") . $fileName; $content = File::get($file["tmp_name"]); $result = $this->manager->saveFile($path, $content); if ($result === true) { return redirect()->back()->withSuccess("File '{$fileName}' uploaded."); } $error = $result ?: "An error occurred uploading file."; return redirect()->back()->withErrors([$error]); }
/** * 上?文件 */ public function uploadFile(UploadFileRequest $request) { $file = $_FILES['file']; $fileName = $request->get('file_name'); $fileName = $fileName ?: $file['name']; $path = str_finish($request->get('folder'), '/') . $fileName; $content = File::get($file['tmp_name']); $result = $this->manager->saveFile($path, $content); if ($result === true) { return redirect()->back()->withSuccess("文? '{$fileName}' 已上?."); } $error = $result ?: "An error occurred uploading file."; return redirect()->back()->withErrors([$error]); }
/** * Execute the console command. * * @return mixed */ public function handle() { if (Storage::exists('decks.json')) { $meta = json_decode(Storage::get('decks.json'), true); } else { $meta = []; } $decks = Storage::files('decks'); $decks = collect($decks)->map(function ($file, $key) { $deck = json_decode(Storage::get($file), true); $deck['file'] = str_replace('decks/', '', $file); unset($deck['cards']); return $deck; }); $main = $decks->pull($decks->search(function ($deck) { return $deck['name'] == 'Cards Against Humanity'; })); $main = DeckMeta::make($main); $meta['main'] = $main->add(['id' => 'main', 'locales' => $this->determineLocalesPosition($main->locales, array_get($meta, 'main.locales', [])), 'source' => 'file', 'type' => 'official'])->toArray(); $decks = $decks->map(function ($deck) use($meta) { $deck_meta = $this->getMeta($deck, $meta); if ($deck_meta) { $deck_id = head(array_keys($deck_meta)); $deck_meta = head($deck_meta); $deck['id'] = $deck_id; $deck['type'] = $deck_meta['type']; $deck['meta'] = $deck_meta; } else { $deck['id'] = $this->ask('Enter an ID for the deck <comment>' . $deck['name'] . '</comment>', str_slug(strtolower($deck['slug']), '_')); $deck['type'] = $this->anticipate('Specify deck type.', ['official' => 'o', 'pax' => 'p', 'thirdParty' => 3], 'official'); $deck['meta'] = false; } return $deck; }); // file based foreach ($decks->pluck('type')->unique() as $type) { $set = $decks->where('type', $type)->values(); $set = $this->sortSet($set, array_get($meta, $type, [])); $set = $set->keyBy('id'); $set = $set->map(function ($deck) { return DeckMeta::make($deck)->toArray(); }); $meta[$type] = $set; } // currated / cardcast // save Storage::put('decks.json', str_finish(json_encode($meta, JSON_PRETTY_PRINT), PHP_EOL)); }
public function init() { $this->transformerBasePath = str_finish(\Config::get('api.transformer_path', ''), '\\'); is_null($this->model) and $this->model = $this->guessModelName(); is_null($this->transformer) and $this->transformer = $this->getTransformer($this->model); $this->model = $this->app->make($this->model); $this->transformer = $this->app->make($this->transformer); $this->setSearchQuery(Input::get('q', '')); $this->setSortOrder(Input::get('sort', '')); $this->setPerPage(Input::get('per_page', $this->perPage)); $this->setFilters(Input::all()); $page = Input::get('page', ''); if (Input::has('fields')) { $this->transformer->transformOnly(preg_split('/\\s*,\\s*/', Input::get('fields'))); } }
/** * Upload new file */ public function uploadFile(UploadFileRequest $request) { $file = $_FILES['file']; $fileName = $request->get('file_name'); $fileName = $fileName ?: $file['name']; $mime = substr($file['name'], strpos($file['name'], '.') - strlen($file['name'])); if (strpos($fileName, '.') === false) { $fileName .= $mime; } $path = str_finish($request->get('folder'), '/') . $fileName; $content = File::get($file['tmp_name']); $result = $this->manager->saveFile($path, $content); if ($result === true) { return redirect()->back()->withSuccess("File '{$fileName}' uploaded."); } $error = $result ?: "An error ocurred uploading file."; return redirect()->back()->withErrors([$error]); }