예제 #1
0
 public function back()
 {
     $app = App::instance();
     if (Str::startsWith($app->request->referrer, 'http://localhost-router/')) {
         header("Location: " . $this->request->referrer);
         exit;
     }
     header("Location: http://localhost-router/");
     exit;
 }
 /**
  * Create a new Encrypter instance.
  *
  * @param  string $key
  * @param  string $cipher
  * @return void
  */
 public function __construct($key, $cipher = 'AES-256-CBC')
 {
     $key = (string) $key;
     if (Str::startsWith($key, 'base64:')) {
         $key = base64_decode(substr($key, 7));
     }
     if (static::supported($key, $cipher)) {
         $this->key = $key;
         $this->cipher = $cipher;
     } else {
         throw new RuntimeException('The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.');
     }
 }
 /**
  * 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;
 }
예제 #4
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 . '.');
 }
 /**
  * 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;
 }
예제 #6
0
 /**
  * Determine if the given attribute may be mass assigned.
  *
  * @param  string  $key
  * @return bool
  */
 public function isFillable($key)
 {
     if (static::$unguarded) {
         return true;
     }
     //
     if (in_array($key, $this->fillable)) {
         return true;
     }
     if ($this->isGuarded($key)) {
         return false;
     }
     return empty($this->fillable) && !Str::startsWith($key, '_');
 }
 /**
  * Test for string starts with
  * @param $haystack
  * @param $needle
  * @return bool
  */
 function str_starts_with($haystack, $needle)
 {
     return Str::startsWith($haystack, $needle);
 }