Beispiel #1
0
 /**
  * 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;
 }
Beispiel #2
0
 /**
  * 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.");
 }
Beispiel #6
0
 /**
  * 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;
 }
Beispiel #7
0
 /**
  * Parse slug name of the module.
  *
  * @param string $slug
  *
  * @return string
  */
 protected function parseSlug($slug)
 {
     return Str::slug($slug);
 }
Beispiel #8
0
 /**
  * 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);
 }
Beispiel #9
0
 /**
  * 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);
 }
Beispiel #11
0
 /**
  * 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.");
 }
Beispiel #12
0
 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');
 }
Beispiel #13
0
 /**
  * Generate a random alpha-numeric string.
  *
  * @param  int     $length
  * @return string
  *
  * @throws \RuntimeException
  */
 function str_random($length = 16)
 {
     return Str::random($length);
 }
Beispiel #14
0
 /**
  * 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');
 }
Beispiel #15
0
 /**
  * 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)));
 }
Beispiel #16
0
 /**
  * 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];
 }
Beispiel #18
0
 /**
  * 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);
 }
Beispiel #19
0
 /**
  * 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);
 }