/** * Create a new file Download Response. * * @param \SplFileInfo|string $file * @param string $name * @param array $headers * @param null|string $disposition * @return \Symfony\Component\HttpFoundation\BinaryFileResponse */ public static function download($file, $name = null, array $headers = array(), $disposition = 'attachment') { $response = new BinaryFileResponse($file, 200, $headers, true, $disposition); if (!is_null($name)) { return $response->setContentDisposition($disposition, $name, Str::ascii($name)); } return $response; }
/** * Get a module's manifest contents. * * @param string $slug * * @return Collection|null */ public function getManifest($slug) { if (is_null($slug)) { return; } $module = Str::slug($slug); $path = $this->getManifestPath($module); $contents = $this->files->get($path); $collection = collect(json_decode($contents, true)); return $collection; }
/** * Execute the console command. * * @return mixed */ public function fire() { $this->container['slug'] = Str::slug($this->argument('slug')); // $slug = $this->container['slug']; $this->container['name'] = Str::studly($slug); $this->container['namespace'] = Str::studly($slug); $this->container['version'] = '1.0'; $this->container['description'] = 'This is the description for the ' . $this->container['name'] . ' module.'; $this->container['license'] = 'MIT'; $this->container['author'] = 'John Doe'; $this->container['email'] = '*****@*****.**'; $this->container['homepage'] = 'http://www.novaframework.dev'; if ($this->option('quick')) { return $this->generate(); } $this->stepOne(); }
/** * Dispatch a Assets File Response. * * @return \Symfony\Component\HttpFoundation\Response|null */ public function dispatch(SymfonyRequest $request) { // For proper Assets serving, the file URI should be either of the following: // // /templates/default/assets/css/style.css // /modules/blog/assets/css/style.css // /assets/css/style.css if (!in_array($request->method(), array('GET', 'HEAD'))) { // The Request Method is not valid for Asset Files. return null; } // Calculate the Asset File path, , looking for a valid one. $uri = $request->path(); if (preg_match('#^(templates|modules)/([^/]+)/assets/(.*)$#i', $uri, $matches)) { $folder = $matches[2]; // Adjust the name of the requested folder, the short ones becoming uppercase. $folder = strlen($folder) > 3 ? Str::studly($folder) : strtoupper($folder); // $path = str_replace('/', DS, $matches[3]); // $baseName = strtolower($matches[1]); $filePath = APPDIR . ucfirst($baseName) . DS . $folder . DS . 'Assets' . DS . $path; } else { if (preg_match('#^(assets|vendor)/(.*)$#i', $uri, $matches)) { $path = $matches[2]; // $baseName = strtolower($matches[1]); if ($baseName == 'vendor' && !Str::startsWith($path, $this->paths)) { // The current URI is not a valid Asset File path on Vendor. return null; } $filePath = ROOTDIR . $baseName . DS . str_replace('/', DS, $path); } else { // The current URI is not a valid Asset File path. return null; } } // Create a Response for the current Asset File path. $response = $this->serve($filePath, $request); // Prepare the Response instance. $response->prepare($request); return $response; }
/** * Dynamically bind flash data in the session. * * @param string $method * @param array $parameters * @return void * * @throws \BadMethodCallException */ public function __call($method, $parameters) { if (str_starts_with($method, 'with')) { return $this->with(Str::snake(substr($method, 4)), $parameters[0]); } throw new \BadMethodCallException("Method [{$method}] does not exist on Redirect."); }
/** * Determine if the given path is a valid URL. * * @param string $path * @return bool */ public function isValidUrl($path) { if (Str::startsWith($path, ['#', '//', 'mailto:', 'tel:', 'http://', 'https://'])) { return true; } return filter_var($path, FILTER_VALIDATE_URL) !== false; }
/** * Parse slug name of the module. * * @param string $slug * * @return string */ protected function parseSlug($slug) { return Str::slug($slug); }
/** * Determine if the MAC for the given payload is valid. * * @param array $payload * @return bool * * @throws \RuntimeException */ protected function validMac(array $payload) { $bytes = Str::randomBytes(16); $calcMac = hash_hmac('sha256', $this->hash($payload['iv'], $payload['value']), $bytes, true); return Str::equals(hash_hmac('sha256', $payload['mac'], $bytes, true), $calcMac); }
/** * Determine if the relationship is nested. * * @param string $name * @param string $relation * @return bool */ protected function isNested($name, $relation) { $dots = str_contains($name, '.'); return $dots && Str::startsWith($name, $relation . '.'); }
/** * Generate a random key for the application. * * @return string */ protected function getRandomKey() { return Str::random(32); }
/** * Handle dynamic calls to class methods. * * @param string $method * @param array $parameters * @return mixed * * @throws \BadMethodCallException */ public function __call($method, $parameters) { $rule = Str::snake(substr($method, 8)); if (isset($this->extensions[$rule])) { return $this->callExtension($rule, $parameters); } throw new \BadMethodCallException("Method [{$method}] does not exist."); }
public function getModules() { if (isset(static::$modules)) { return static::$modules; } // $modules = $this->config->get('modules.modules', array()); $modules = array_map(function ($slug, $properties) { $autoload = array('config', 'events', 'filters', 'routes'); $options = array_get($properties, 'autoload', array()); if (!empty($options)) { $autoload = array_intersect($options, $autoload); } array_push($autoload, 'bootstrap'); // $namespace = isset($properties['namespace']) ? $properties['namespace'] : Str::studly($slug); return array_merge(array('slug' => $slug, 'name' => isset($properties['name']) ? $properties['name'] : $namespace, 'namespace' => $namespace, 'enabled' => isset($properties['enabled']) ? $properties['enabled'] : true, 'order' => isset($properties['order']) ? $properties['order'] : 9001, 'autoload' => $autoload), $properties); }, array_keys($modules), $modules); return static::$modules = Collection::make($modules)->sortBy('order'); }
/** * Generate a random alpha-numeric string. * * @param int $length * @return string * * @throws \RuntimeException */ function str_random($length = 16) { return Str::random($length); }
/** * Determine if a set mutator exists for an attribute. * * @param string $key * @return bool */ public function hasSetMutator($key) { return method_exists($this, 'set' . Str::studly($key) . 'Attribute'); }
/** * Get the Table for the Model. * * @return string */ public function getTable() { if (isset($this->table)) { return $this->table; } return str_replace('\\', '', Str::snake(class_basename($this))); }
/** * Convert a value to studly caps case. * * @param string $value * @return string */ function studly_case($value) { return Str::studly($value); }
/** * Parse the connection into an array of the name and read / write type. * * @param string $name * @return array */ protected function parseConnectionName($name) { $name = $name ?: $this->getDefaultConnection(); return Str::endsWith($name, ['::read', '::write']) ? explode('::', $name, 2) : [$name, null]; }
/** * Attempt to guess the name of the inverse of the relation. * * @return string */ protected function guessInverseRelation() { $relation = Str::plural(class_basename($this->getParent())); return Str::camel($relation); }
/** * Add a single dynamic where clause statement to the query. * * @param string $segment * @param string $connector * @param array $parameters * @param int $index * @return void */ protected function addDynamic($segment, $connector, $parameters, $index) { $bool = strtolower($connector); $this->where(Str::snake($segment), '=', $parameters[$index], $bool); }