Example #1
0
 /**
  * Loads the configuration file.
  *
  * @access  protected
  * @param   string     $file  File name
  * @return  array
  */
 protected function load($file)
 {
     // Load configuration
     foreach ($this->getCascadingFilePaths($file) as $path) {
         if ($this->fileSystem->exists($path)) {
             $config = $this->fileSystem->includeFile($path);
             break;
         }
     }
     if (!isset($config)) {
         throw new RuntimeException(vsprintf("%s(): The [ %s ] config file does not exist.", [__METHOD__, $file]));
     }
     // Merge environment specific configuration
     if ($this->environment !== null) {
         $namespace = strpos($file, '::');
         $namespaced = $namespace === false ? $this->environment . '.' . $file : substr_replace($file, $this->environment . '.', $namespace + 2, 0);
         foreach ($this->getCascadingFilePaths($namespaced) as $path) {
             if ($this->fileSystem->exists($path)) {
                 $config = array_replace_recursive($config, $this->fileSystem->includeFile($path));
                 break;
             }
         }
     }
     $this->configuration[$file] = $config;
 }
Example #2
0
 /**
  * Executes the command.
  *
  * @access  public
  * @param   \mako\application\Application  $application  Application instance
  * @param   \mako\file\FileSystem          $fileSystem   File system instance
  * @param   string                         $package      Package name
  * @param   string                         $description  Migration description
  */
 public function execute(Application $application, FileSystem $fileSystem, $package = null, $description = null)
 {
     // Get file path and namespace
     if (empty($package)) {
         $namespace = $application->getNamespace() . '\\migrations';
         $path = $application->getPath() . '/migrations/';
     } else {
         $package = $application->getPackage($package);
         $namespace = $package->getClassNamespace() . '\\migrations';
         $path = $package->getPath() . '/src/migrations/';
     }
     $path .= 'Migration_' . ($version = gmdate('YmdHis')) . '.php';
     // Create migration
     $description = str_replace("'", "\\'", $description);
     $search = ['{{namespace}}', '{{version}}', '{{description}}'];
     $replace = [$namespace, $version, $description];
     $migration = str_replace($search, $replace, $fileSystem->getContents(__DIR__ . '/resources/migration.template'));
     try {
         $fileSystem->putContents($path, $migration);
     } catch (Exception $e) {
         $this->error('Failed to create migration. Make sure that the migrations directory is writable.');
         return;
     }
     $this->write(vsprintf('Migration created at [ %s ].', [$path]));
 }
Example #3
0
 /**
  * Constructor.
  *
  * @access  public
  * @param   string  $file     File path
  * @param   array   $options  Options
  */
 public function __construct($file, array $options = [])
 {
     $this->fileSystem = $this->getFileSystem();
     if ($this->fileSystem->exists($file) === false || $this->fileSystem->isReadable($file) === false) {
         throw new RuntimeException(vsprintf("%s(): File [ %s ] is not readable.", [__METHOD__, $file]));
     }
     $this->filePath = $file;
     $this->fileSize = $this->fileSystem->size($file);
     $this->options = $options + ['file_name' => basename($file), 'disposition' => 'attachment', 'content_type' => $this->fileSystem->mime($file) ?: 'application/octet-stream', 'callback' => null];
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function gc($dataTTL)
 {
     $files = $this->fileSystem->glob($this->sessionPath . '/*');
     if (is_array($files)) {
         foreach ($files as $file) {
             if ($this->fileSystem->lastModified($file) + $dataTTL < time() && $this->fileSystem->isWritable($file)) {
                 $this->fileSystem->delete($file);
             }
         }
     }
 }
Example #5
0
 /**
  * Loads and returns language strings.
  *
  * @access  public
  * @param   string  $language  Name of the language pack
  * @param   string  $file      File we want to load
  * @return  array
  */
 public function loadStrings($language, $file)
 {
     $strings = false;
     foreach ($this->getCascadingFilePaths($file, null, $language . '/strings') as $file) {
         if ($this->fileSystem->exists($file)) {
             $strings = $this->fileSystem->includeFile($file);
             break;
         }
     }
     if ($strings === false) {
         throw new RuntimeException(vsprintf("%s(): The [ %s ] language file does not exist in the [ %s ] language pack.", [__METHOD__, $file, $language]));
     }
     return $strings;
 }
 /**
  * Executes the command.
  *
  * @access  public
  * @param   \mako\application\Application  $application  Application instance
  * @param   \mako\file\FileSystem          $fileSystem   File system instance
  */
 public function execute(Application $application, FileSystem $fileSystem)
 {
     $configFile = $application->getPath() . '/config/application.php';
     if (!$fileSystem->isWritable($configFile)) {
         $this->error('Unable to generate a new secret. Make sure that the [ app/config/application.php ] file is writable.');
         return;
     }
     if (function_exists('openssl_random_pseudo_bytes')) {
         $secret = bin2hex(openssl_random_pseudo_bytes(32));
     } else {
         $secret = str_replace(['"', '\''], ['|', '/'], Str::random(Str::ALNUM . Str::SYMBOLS, 64));
     }
     $contents = $fileSystem->getContents($configFile);
     $contents = preg_replace('/\'secret\'(\\s*)=>(\\s*)\'(.*)\',/', '\'secret\'$1=>$2\'' . $secret . '\',', $contents);
     $fileSystem->putContents($configFile, $contents);
     $this->write('A new application secret has been generated.');
 }
Example #7
0
 /**
  * Returns all package migrations.
  *
  * @access  protected
  * @return  array
  */
 protected function findPackageMigrations()
 {
     $migrations = [];
     foreach ($this->application->getPackages() as $package) {
         foreach ($this->fileSystem->glob($package->getPath() . '/src/migrations/*.php') as $migration) {
             $migrations[] = (object) ['package' => $package->getName(), 'version' => $this->getBasename($migration)];
         }
     }
     return $migrations;
 }
 /**
  * Compiles templates into views.
  *
  * @access  public
  * @return  string
  */
 public function compile()
 {
     // Get teplate contents
     $contents = $this->fileSystem->getContents($this->template);
     // Compile template
     foreach ($this->compileOrder as $method) {
         $contents = $this->{$method}($contents);
     }
     // Store compiled template
     $this->fileSystem->putContents($this->cachePath . '/' . md5($this->template) . '.php', trim($contents));
 }
Example #9
0
 /**
  * {@inheritdoc}
  */
 public function clear()
 {
     $files = $this->fileSystem->glob($this->cachePath . '/*');
     if (is_array($files)) {
         foreach ($files as $file) {
             if ($this->fileSystem->isFile($file) && $this->fileSystem->delete($file) === false) {
                 return false;
             }
         }
     }
     return true;
 }