コード例 #1
0
ファイル: CompileCommand.php プロジェクト: netson/l4gettext
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     /**
      * compiler settings
      */
     $compiler_input = app_path() . DIRECTORY_SEPARATOR . $this->option('input_folder') . DIRECTORY_SEPARATOR;
     $compiler_output = storage_path() . DIRECTORY_SEPARATOR . $this->option('output_folder') . DIRECTORY_SEPARATOR;
     $compiler_levels = $this->option("levels");
     // add info
     $this->comment("  checking folder [{$compiler_input}] for blade templates, [{$compiler_levels}] levels deep");
     /**
      * determine glob pattern based on number of levels
      */
     $pattern = getGlobPattern($compiler_levels);
     // set final patterns
     $compiler_pattern = $compiler_input . "{" . $pattern . "}*.blade.php";
     /**
      * set proper cache path for compiler
      */
     BladeCompiler::setCachePath($compiler_output);
     /**
      * check if compiler output folder exists
      * and if not, attempt to create it
      */
     if (!File::isDirectory($compiler_output)) {
         File::makeDirectory($compiler_output);
     }
     /**
      * get all blade templates from the input folder using the generated pattern
      * the GLOB_BRACE constant is used to transform the {x, y, z} pattern to OR x, OR y, OR z
      */
     $templates = File::glob($compiler_pattern, GLOB_BRACE);
     // sanity check
     if (count($templates) < 1) {
         throw new \Netson\L4gettext\NoTemplatesToCompileException("No templates were found to compile in [{$compiler_input}]");
     }
     // file array and counter
     $f = array();
     $i = 0;
     // loop through all files and compile each
     foreach ($templates as $tpl) {
         $f[] = BladeCompiler::compile($tpl);
         $i++;
     }
     // output success
     $this->info("  [{$i}] blade templates found and successfully compiled");
 }
コード例 #2
0
ファイル: ExtractCommand.php プロジェクト: netson/l4gettext
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     /**
      * check if any php files exist in the input folder
      */
     $input_folder = app_path() . DIRECTORY_SEPARATOR . $this->option('input_folder') . DIRECTORY_SEPARATOR;
     $views_folder = app_path() . DIRECTORY_SEPARATOR . $this->option('views_folder') . DIRECTORY_SEPARATOR;
     $additional_folders = base_path() . DIRECTORY_SEPARATOR;
     /**
      * determine file pattern to search for
      */
     $pattern = getGlobPattern($this->option("levels"));
     $phpFiles = $views_folder . "{" . $pattern . "}*.php";
     /**
      * Merge the php files in compiled folder as well as views folder
      * The array_filter weeds out the blade templates from view since they are already
      * in the compiled folder
      */
     $templates = array_merge(File::glob($input_folder . "*.php"), array_filter(File::glob($phpFiles, GLOB_BRACE), function ($path) {
         return substr_count($path, 'blade.php') === 0;
     }));
     /**
      * sanity check
      */
     if (!is_array($this->option("additional_input_folders"))) {
         throw new \Netson\L4gettext\AdditionalInputFoldersNotArrayException("The additional_input_folders option should be an array, [" . gettype($this->option("additional_input_folders")) . "] given");
     }
     /**
      * fetch any additional input folders from the command line or config option
      */
     foreach ($this->option("additional_input_folders") as $additional_folder) {
         // sanity check
         if (!File::isDirectory($additional_folder)) {
             throw new \Netson\L4gettext\AdditionalInputFolderNotFoundException("The additional input folder [{$additional_folder}] does not exist; please check your configuration");
         }
         // generate the pattern for this folder
         $compiler_additional_pattern = $additional_folders . $additional_folder . DIRECTORY_SEPARATOR . "{" . $pattern . "}*.php";
         // merge with additional input folders
         $templates = array_merge($templates, File::glob($compiler_additional_pattern, GLOB_BRACE));
     }
     // determine number of files in input folder
     $i = count($templates);
     // sanity check
     if ($i < 1) {
         // throw exception
         throw new \Netson\L4gettext\NoFilesToExtractFromException("No templates found");
         /* CODE TO BE USED ONCE UNIT TESTING OF INTERACTIVE COMMANDS IS WORKING
                       // print error
                       $this->error("  the given input folder [$input_folder] does not contain any php files to parse");
         
                       // ask if compiler should be run
                       if ($this->confirm("  would you like to run the compiler using the default settings? [y|n]"))
                       {
                       $this->line(""); // add empty line
                       $this->call('l4gettext:compile'); // call compile command
                       // re-check
                       $templates = File::glob($input_folder . "*.php");
         
                       // determine number of files in input folder
                       $i = count($templates);
                       }
                       else
                       {
                       $this->line(""); // add empty line
                       return;
                       }
                      */
     }
     // add info
     $this->comment("  [{$i}] files found in input folder [{$input_folder}], views folder [{$views_folder}]");
     /**
      * array containging all xgettext parameters
      */
     $xgettext_arguments = array();
     /**
      * fetch path to xgettext binary and set binary
      */
     $path = $this->option('binary_path') == "" ? "" : $this->option('binary_path') . DIRECTORY_SEPARATOR;
     $xgettext_arguments[] = $path . $this->option('binary');
     /**
      * add language argument
      */
     if ($this->option('language')) {
         $xgettext_arguments[] = "--language=" . $this->option('language');
     }
     /**
      * add comments argument
      */
     if ($this->option('comments')) {
         $xgettext_arguments[] = "--add-comments=" . $this->option('comments');
     }
     /**
      * add force_po argument
      */
     if ($this->option('force_po') == true) {
         $xgettext_arguments[] = "--force-po";
     }
     /**
      * add output folder argument
      */
     $xgettext_output_file = storage_path() . DIRECTORY_SEPARATOR . $this->option("output_folder") . DIRECTORY_SEPARATOR . Config::get("l4gettext::config.textdomain") . ".pot";
     if ($this->option('output_folder')) {
         $xgettext_arguments[] = "--output=" . $xgettext_output_file;
     }
     /**
      * add from code argument
      */
     if ($this->option('from_code')) {
         $xgettext_arguments[] = "--from-code=" . $this->option('from_code');
     }
     /**
      * add copyright holder argument
      */
     if ($this->option('copyright_holder')) {
         $xgettext_arguments[] = "--copyright-holder=" . $this->option('copyright_holder');
     }
     /**
      * add package name argument
      */
     if ($this->option('package_name')) {
         $xgettext_arguments[] = "--package-name=" . $this->option('package_name');
     }
     /**
      * add package version argument
      */
     if ($this->option('package_version')) {
         $xgettext_arguments[] = "--package-version=" . $this->option('package_version');
     }
     /**
      * add email address option
      */
     if ($this->option('email_address')) {
         $xgettext_arguments[] = "--msgid-bugs-address=" . $this->option('email_address');
     }
     /**
      * add keyword options
      */
     $keyword_list = array_merge($this->option('keywords'), $this->option('additional_keywords'));
     // loop through all keywords
     foreach ($keyword_list as $k) {
         $xgettext_arguments[] = "--keyword={$k}";
         // using the shorthand xgettext notation for the keywords: -k%k
     }
     // add info
     $this->comment("  [" . count($keyword_list) . "] keywords found");
     /**
      * add join-existing argument
      */
     if ($this->option('join-existing')) {
         $this->comment($this->option('join-existing'));
         $xgettext_arguments[] = "-j";
     }
     /**
      * add input folder argument
      */
     if ($this->option('input_folder')) {
         foreach ($templates as $t) {
             $xgettext_arguments[] = $t;
         }
     }
     /**
      * create symfony process and execute
      */
     $builder = $this->procBuilder;
     $builder->setArguments($xgettext_arguments);
     // fetch and execute process
     $process = $builder->getProcess();
     $process->run();
     /**
      * check if process completed successfully
      */
     if (!$process->isSuccessful()) {
         throw new \Netson\L4gettext\XgettextException("The xgettext command could not be executed:" . PHP_EOL . "[" . $process->getExitCode() . "] " . $process->getExitCodeText() . PHP_EOL . PHP_EOL . "Attempted to execute the following command:" . PHP_EOL . $process->getCommandLine());
     }
     /**
      * add output info for user
      */
     $this->info("  POT file located in [{$xgettext_output_file}]");
     $this->info("  xgettext successfully executed");
 }