Handle the command.
966864
public function handle()
    {
        $target = $this->argument('target');
        $options = [
            'compress' => $this->option('compress'),
            'json' => $this->option('json'),
            'no-lib' => $this->option('no-lib'),
            'source' => $this->option('source'),
        ];

        if ($this->generator->generate($target, $options)) {
            $this->info("Created: {$target}");

            return;
        }

        $this->error("Could not create: {$target}");
    }
122313
public function handle()
    {
        if(env('APP_ENV') == 'testing'){

            return;
        }

        $this->origins();
        $this->credentials();
        $this->methods();
        $this->headers();
    }
1260031
public function handle()
    {
        parent::handle();

        $modelGenerator = new ModelGenerator($this->commandData);
        $modelGenerator->generate();

        $this->performPostActions();
    }
627085
public function handle()
    {
        $this->line(static::$logo);
        $this->line(Admin::getLongVersion());

        $this->comment('');
        $this->comment('Available commands:');

        $this->listAdminCommands();
    }
123367
public function handle()
    {
        if ($this->checkIfCanIncrement('current')) {
            $number = app('pragmarx.version')->incrementMinor();

            $this->info("New minor version: {$number}");

            $this->displayAppVersion();
        }
    }
656622
public function handle()
    {
        foreach ($this->schedule->dueEvents($this->laravel) as $event) {
            if (! $event->filtersPass($this->laravel)) {
                continue;
            }

            if ($event->onOneServer) {
                $this->runSingleServerEvent($event);
            } else {
                $this->runEvent($event);
            }

            $this->eventsRan = true;
        }

        if (! $this->eventsRan) {
            $this->info('No scheduled commands are ready to run.');
        }
    }
1011598
public function handle()
    {

        $command = $this->argument('function') ? $this->argument('function') : 'create';
        $param = $this->argument('params') ? $this->argument('params') : '';
        if (is_callable([$this, $command])) {
            $this->$command($param);
        } else {
            $this->error(sprintf('%s command not found', $command));
        }
    }
126294
public function handle()
    {
        $this->identifier = self::normalize($this->argument('identifier'));

        $this->askImageUploads();
        $this->askFileUploads();
        $this->askMigration();
        $this->askActions();

        $this->compiler = new ResourceCompiler($this, $this->identifier, $this->resourceOptions);

        $this->createResource('config');
        $this->createResource('model');
        $this->createResource('request');
        $this->createResource('controller');

        if ($this->resourceOptions['migration']) {
            $this->createResource('migration');
        }
    }
953774
public function handle()
    {
        $folders         = $this->manager->getPath($this->folders);
        $this->display   = ! $this->option('silent');
        $extension       = $this->option('php-file-extension');
        $obsolete_prefix = (empty($this->obsolete_array_key)) ? '' : $this->obsolete_array_key.'.';

        //////////////////////////////////////////////////
        // Display where translations are searched in //
        //////////////////////////////////////////////////
        if ($this->option('verbose')) {
            $this->writeLine("Lemmas will be searched in the following directories:");

            foreach ($folders as $path) {
                $this->writeLine('    <info>'.$path.'</info>');
            }

            $this->writeLine('');
        }

        ////////////////////////////////
        // Parse all lemmas from code //
        ////////////////////////////////
        $lemmas = $this->manager->extractTranslationsFromFolders($folders, $this->trans_methods, $extension);

        if (count($lemmas) === 0) {
            $this->writeComment("No lemma has been found in code.");
            $this->writeLine("I have searched recursively in PHP files in these directories:");

            foreach ($this->manager->getPath($this->folders) as $path) {
                $this->writeLine("    ".$path);
            }

            $this->writeLine("for these functions/methods:");

            foreach ($this->trans_methods as $k => $v) {
                $this->writeLine("    ".$k);
            }

            return self::SUCCESS;
        }

        $this->writeLine((count($lemmas) > 1) ? count($lemmas)." lemmas have been found in code" : "1 lemma has been found in code");

        if ($this->option('verbose')) {
            foreach ($lemmas as $key => $value) {
                if (strpos($key, '.') !== false) {
                    $this->writeLine('    <info>'.$key.'</info> in file <comment>'.$this->manager->getShortPath($value).'</comment>');
                }
            }
        }

        /////////////////////////////////////////////
        // Convert dot lemmas to structured lemmas //
        /////////////////////////////////////////////
        if ($this->option('output-flat')) {
            $lemmas_structured = $this->manager->convertLemmaToFlatArray($lemmas);
        } else {
            $lemmas_structured = $this->manager->convertLemmaToStructuredArray($lemmas, $this->dot_notation_split_regex, null);
        }

        $this->writeLine('');

        /////////////////////////////////////
        // Generate lang files :           //
        // - add missing lemmas on top     //
        // - keep already defined lemmas   //
        // - add obsolete lemmas on bottom //
        /////////////////////////////////////
        try {
            $dir_lang = $this->manager->getLangPath($this->lang_folder_path);
        } catch (Exception $e) {
            switch ($e->getCode()) {
                //@codeCoverageIgnoreStart
                case Localization::NO_LANG_FOLDER_FOUND_IN_THESE_PATHS:
                    $this->writeError("No lang folder found in these paths:");
                    foreach ($e->getParameter() as $path) {
                        $this->writeError("- ".$path);
                    }
                    break;
                //@codeCoverageIgnoreEnd

                case Localization::NO_LANG_FOLDER_FOUND_IN_YOUR_CUSTOM_PATH:
                    $this->writeError('No lang folder found in your custom path: "'.$e->getParameter().'"');
                    break;
            }

            $this->writeLine('');

            return self::ERROR;
        }

        $job           = [];
        $there_are_new = false;

        $this->writeLine('Scan files:');

        /**
         * Parse all lang file types
         *
         * @var LangFileAbstract $langFileType
         */
        foreach (LangFile::getLangFiles($dir_lang, $this->json_languages) as $langFileType) {
            if ($langFileType->getTypeVendor()) {
                continue;
            }

            $lang = $langFileType->getLang();

            /**
             * Parse now all extracted families
             */
            foreach ($lemmas_structured as $family => $array) {
                if ($family === Localization::JSON_HEADER) {
                    $lang_file = new LangFileJson($dir_lang, $lang);
                } else {
                    $lang_file = new LangFileGenuine($dir_lang, $lang, $family);

                    if (in_array($family, $this->ignore_lang_files) || in_array($lang_file->getShortFilePath(), $this->ignore_lang_files)) {
                        if ($this->option('verbose')) {
                            $this->writeLine('');
                            $this->writeInfo("    ! Skip lang file '$family' !");
                        }
                        continue;
                    }
                }

                if ($this->option('verbose')) {
                    $this->writeLine('');
                }

                $this->writeLine('    '.$lang_file->getShortFilePath());

                if (! $this->option('dry-run')) {

                    if (! $lang_file->ensureFolder()) {
                        // @codeCoverageIgnoreStart
                        $this->writeError("    > Unable to create directory ".$lang_file->getFileFolderPath());

                        return self::ERROR;
                        // @codeCoverageIgnoreEnd
                    }

                    if (! $lang_file->isFolderWritable()) {
                        // @codeCoverageIgnoreStart
                        $this->writeError("    > Unable to write file in directory ".$lang_file->getFileFolderPath());

                        return self::ERROR;
                        // @codeCoverageIgnoreEnd
                    }

                    if (! $lang_file->fileExists()) {
                        // @codeCoverageIgnoreStart
                        $this->writeInfo("    > File has been created");
                        // @codeCoverageIgnoreEnd
                    }

                    if (! $lang_file->touch()) {
                        // @codeCoverageIgnoreStart
                        $this->writeError("    > Unable to touch file ".$lang_file->getFilePath());

                        return self::ERROR;
                        // @codeCoverageIgnoreEnd
                    }

                    if (! $lang_file->isReadable()) {
                        // @codeCoverageIgnoreStart
                        $this->writeError("    > Unable to read file ".$lang_file->getFilePath());

                        return self::ERROR;
                        // @codeCoverageIgnoreEnd
                    }

                    if (! $lang_file->isWritable()) {
                        // @codeCoverageIgnoreStart
                        $this->writeError("    > Unable to write in file ".$lang_file->getFilePath());

                        return self::ERROR;
                        // @codeCoverageIgnoreEnd
                    }
                }

                /** @noinspection PhpIncludeInspection */
                $a                        = $lang_file->load();
                $old_lemmas_with_obsolete = (is_array($a)) ? array_dot($a) : [];
                $new_lemmas               = array_dot($array);
                $final_lemmas             = [];
                $display_already_comment  = false;
                $something_to_do          = false;
                $i                        = 0;

                // Remove the obsolete prefix key
                $old_lemmas             = [];
                $obsolete_prefix_length = strlen($obsolete_prefix);
                foreach ($old_lemmas_with_obsolete as $key => $value) {
                    if (starts_with($key, $obsolete_prefix)) {
                        $key = substr($key, $obsolete_prefix_length);
                        if (! isset($old_lemmas[$key])) {
                            $old_lemmas[$key] = $value;
                        }
                    } else {
                        $old_lemmas[$key] = $value;
                    }
                }

                // Check if keys from new lemmas are not sub-keys from old_lemma (#47)
                // Ignore them if this is the case
                $new_lemmas_clean = $new_lemmas;
                $old_lemmas_clean = $old_lemmas;

                foreach ($new_lemmas as $new_key => $new_value) {
                    foreach ($old_lemmas as $old_key => $old_value) {
                        if (starts_with($old_key, $new_key.'.')) {
                            if ($this->option('verbose')) {
                                $this->writeLine("            <info>".$new_key."</info> seems to be used to access an array and is already defined in lang file as ".$old_key);
                                $this->writeLine("            <info>".$new_key."</info> not handled!");
                            }

                            unset($new_lemmas_clean[$new_key]);
                            unset($old_lemmas_clean[$old_key]);
                        }
                    }
                }

                $obsolete_lemmas = array_diff_key($old_lemmas_clean, $new_lemmas_clean);
                $welcome_lemmas  = array_diff_key($new_lemmas_clean, $old_lemmas_clean);
                $already_lemmas  = array_intersect_key($old_lemmas_clean, $new_lemmas_clean);

                // disable check for obsolete lemma and consolidate with already_lemmas
                if ($this->option('disable-obsolete-check')) {
                    $already_lemmas  = array_unique($obsolete_lemmas + $already_lemmas);
                    $obsolete_lemmas = [];
                }

                ksort($obsolete_lemmas);
                ksort($welcome_lemmas);
                ksort($already_lemmas);

                //////////////////////////
                // Deal with new lemmas //
                //////////////////////////
                if (count($welcome_lemmas) > 0) {
                    $display_already_comment               = true;
                    $something_to_do                       = true;
                    $there_are_new                         = true;
                    $final_lemmas["POTSKY___NEW___POTSKY"] = "POTSKY___NEW___POTSKY";

                    $this->writeInfo('        '.($c = count($welcome_lemmas)).' new string'.Tools::getPlural($c).' to translate');

                    foreach ($welcome_lemmas as $key => $value) {
                        if ($this->option('verbose')) {
                            $this->writeLine("            <info>".$key."</info> in ".$this->manager->getShortPath($value));
                        }
                        if (! $this->option('no-comment')) {
                            $final_lemmas['POTSKY___COMMENT___POTSKY'.$i] = "Defined in file $value";
                            $i                                            = $i + 1;
                        }

                        $key_last_token = preg_split($this->dot_notation_split_regex, $key);

                        if ($this->option('translation')) {
                            $translation = $this->manager->translate(end($key_last_token), $lang);
                        } else {
                            $translation = end($key_last_token);
                        }

                        if (strtolower($this->option('new-value')) === 'null') {
                            $translation = null;
                        } else {
                            $translation = str_replace('%LEMMA', $translation, $this->option('new-value'));
                        }

                        Tools::arraySet($final_lemmas, $key, $translation, $this->dot_notation_split_regex);
                    }
                }

                ///////////////////////////////
                // Deal with existing lemmas //
                ///////////////////////////////
                if (count($already_lemmas) > 0) {
                    if ($this->option('verbose')) {
                        $this->writeLine('        '.($c = count($already_lemmas)).' already translated string'.Tools::getPlural($c));
                    }

                    $final_lemmas["POTSKY___OLD___POTSKY"] = "POTSKY___OLD___POTSKY";

                    foreach ($already_lemmas as $key => $value) {
                        Tools::arraySet($final_lemmas, $key, $value, $this->dot_notation_split_regex);
                    }
                }

                ///////////////////////////////
                // Deal with obsolete lemmas //
                ///////////////////////////////
                if (count($obsolete_lemmas) > 0) {
                    $protected_already_included = false;

                    // Remove all dynamic fields
                    foreach ($obsolete_lemmas as $key => $value) {
                        foreach ($this->never_obsolete_keys as $remove) {
                            if ((strpos($key, '.'.$remove.'.') !== false) || starts_with($key, $remove.'.')) {
                                if ($this->option('verbose')) {
                                    $this->writeLine("        <comment>".$key."</comment> is protected as a dynamic lemma");
                                }

                                unset($obsolete_lemmas[$key]);

                                if ($protected_already_included === false) {
                                    $final_lemmas["POTSKY___PROTECTED___POTSKY"] = "POTSKY___PROTECTED___POTSKY";
                                    $protected_already_included                  = true;
                                }

                                // Given that this lemma is never obsolete, we need to send it back to the final lemma array
                                Tools::arraySet($final_lemmas, $key, $value, $this->dot_notation_split_regex);
                            }
                        }
                    }
                }

                /////////////////////////////////////
                // Fill the final lemmas array now //
                /////////////////////////////////////
                if (count($obsolete_lemmas) > 0) {
                    $display_already_comment = true;
                    $something_to_do         = true;

                    if ($this->option('no-obsolete')) {
                        $this->writeComment("        ".($c = count($obsolete_lemmas)).' obsolete string'.Tools::getPlural($c).' (will be deleted)');
                    } else {
                        $this->writeComment("        ".($c = count($obsolete_lemmas)).' obsolete string'.Tools::getPlural($c).' (can be deleted manually in the generated file)');

                        $final_lemmas["POTSKY___OBSOLETE___POTSKY"] = "POTSKY___OBSOLETE___POTSKY";

                        foreach ($obsolete_lemmas as $key => $value) {
                            if ($this->option('verbose')) {
                                $this->writeLine("            <comment>".$key."</comment>");
                            }

                            Tools::arraySet($final_lemmas, $obsolete_prefix.$key, $value, $this->dot_notation_split_regex);
                        }
                    }
                }

                // Flat style
                if ($this->option('output-flat')) {
                    $final_lemmas = array_dot($final_lemmas);
                }

                if (($something_to_do === true) || ($this->option('force'))) {
                    $content = var_export($final_lemmas, true);
                    $content = preg_replace("@'POTSKY___COMMENT___POTSKY[0-9]*' => '(.*)',@", '// $1', $content);
                    $content = str_replace([
                        "'POTSKY___NEW___POTSKY' => 'POTSKY___NEW___POTSKY',",
                        "'POTSKY___OLD___POTSKY' => 'POTSKY___OLD___POTSKY',",
                        "'POTSKY___PROTECTED___POTSKY' => 'POTSKY___PROTECTED___POTSKY',",
                        "'POTSKY___OBSOLETE___POTSKY' => 'POTSKY___OBSOLETE___POTSKY',",
                    ], [
                        '//============================== New strings to translate ==============================//',
                        ($display_already_comment === true) ? '//==================================== Translations ====================================//' : '',
                        '//============================== Dynamic protected strings =============================//',
                        '//================================== Obsolete strings ==================================//',
                    ], $content);

                    $file_content = "<?php\n";

                    if (! $this->option('no-date')) {
                        $a            = " Generated via \"php artisan ".$this->argument('command')."\" at ".date("Y/m/d H:i:s")." ";
                        $file_content .= "/".str_repeat('*', strlen($a))."\n".$a."\n".str_repeat('*', strlen($a))."/\n";
                    }

                    $file_content                   .= "\nreturn ".$content.";";
                    $job[$lang_file->getFilePath()] = $file_content;
                } else {
                    if ($this->option('verbose')) {
                        $this->writeLine("        > <comment>Nothing to do for this file</comment>");
                    }
                }
            }
        }

        ///////////////////////////////////////////
        // Silent mode                           //
        // only return an exit code on new lemma //
        ///////////////////////////////////////////
        if ($this->option('silent')) {
            if ($there_are_new === true) {
                return self::ERROR;
            } else {
                // @codeCoverageIgnoreStart
                return self::SUCCESS;
                // @codeCoverageIgnoreEnd
            }
        }

        ///////////////////////////////////////////
        // Normal mode                           //
        ///////////////////////////////////////////
        if (count($job) > 0) {

            if ($this->option('no-interaction')) {
                $do = true;
            } // @codeCoverageIgnoreStart
            else {
                $this->writeLine('');
                $do = ($this->ask('Do you wish to apply these changes now? [yes|no]') === 'yes');
                $this->writeLine('');
            }
            // @codeCoverageIgnoreEnd

            if ($do === true) {

                if (! $this->option('no-backup')) {
                    $this->writeLine('Backup files:');

                    $now = $this->manager->getBackupDate();

                    foreach ($job as $file_lang_path => $file_content) {
                        $backup_path = $this->manager->getBackupPath($file_lang_path, $now, $extension);

                        if (! $this->option('dry-run')) {
                            rename($file_lang_path, $backup_path);
                        }

                        $this->writeLine("    <info>".$this->manager->getShortPath($file_lang_path)."</info> -> <info>".$this->manager->getShortPath($backup_path)."</info>");
                    }

                    $this->writeLine('');
                }

                $this->writeLine('Save files:');
                $open_files = '';

                foreach ($job as $file_lang_path => $file_content) {
                    if (! $this->option('dry-run')) {
                        file_put_contents($file_lang_path, $file_content);
                    }

                    $this->writeLine("    <info>".$this->manager->getShortPath($file_lang_path)."</info>");

                    // Fix code style
                    try {
                        $this->manager->fixCodeStyle($file_lang_path, $this->code_style_rules);
                    } // @codeCoverageIgnoreStart
                    catch (Exception $e) {
                        $this->writeError("    Cannot fix code style (".$e->getMessage().")");
                    }
                    // @codeCoverageIgnoreEnd

                    // @codeCoverageIgnoreStart
                    if ($this->option('editor')) {
                        $open_files .= ' '.escapeshellarg($file_lang_path);
                    }
                    // @codeCoverageIgnoreEnd

                }

                $this->writeLine('');
                $this->writeInfo('Process done!');

                // @codeCoverageIgnoreStart
                if ($this->option('editor')) {
                    exec($this->editor.$open_files);
                }
                // @codeCoverageIgnoreEnd

                // @codeCoverageIgnoreStart
            } else {
                $this->writeLine('');
                $this->writeComment('Process aborted. No file has been changed.');
            }
        } // @codeCoverageIgnoreEnd
        else {
            $this->writeLine('');
            $this->writeInfo('Drink a Piña colada and/or smoke Super Skunk, you have nothing to do!');
        }
        $this->writeLine('');

        return self::SUCCESS;
    }
788946
public function handle()
    {
        $command = $this->option('command');

        ob_start();
        $result = $this->executeCode(
            trim(trim($command), ';').';'
        );
        $output = ob_get_clean();

        if (empty($output) === false) {
            $this->line($output);
            $result = null;
        }

        $this->getOutput()->write('=> ');
        switch (gettype($result)) {
            case 'object':
            case 'array':
                $this->line(var_export($result, true));
                break;
            case 'string':
                $this->comment($result);
                break;
            case 'NULL':
                $this->line('');
                break;
            default:
                is_numeric($result) === true ? $this->info($result) : $this->line($result);
                break;
        }
    }
708669
public function handle()
    {
        $alphabets = $this->generateRandomAlphabets(
            $this->getTimes(),
            (string) $this->option('characters')
        );

        $this->comment(implode(PHP_EOL, $alphabets));
    }
1136739
public function handle()
    {

        $this->modelName = $this->formatModel($this->argument('ModelName'));

        $this->modelPath = $this->formatModelPath($this->argument('ModelName'));

        if ( ! $this->chartExists()){

            $this->error('Error, can\'t find ' .$this->modelName . ' chart');
            die();

        }


        if ( $this->removeChartFromFiles() ) {

            $this->sendSuccessMessage();

            return;

        }

        $this->error('Oops, something went wrong!');


    }
727286
public function handle()
    {
        $table = trim($this->input->getArgument('table_name'));
        $name = "create_{$table}_table";

        $this->writeMigration($name, $table);

        $this->composer->dumpAutoloads();
    }
777794
public function handle()
    {
        $this->copyright();

        $locale = (string) $this->argument('locale');

        if ($this->publisher->isDefault($locale))
            $this->info("The locale [{$locale}] is a default lang and it's shipped with laravel.");
        else
            $this->publish($locale, (bool) $this->option('force'));

        $this->line('');
    }
555802
public function handle()
    {
        $version = $this->version();

        $all = $this->option('all');

        $currentOS = OperatingSystem::id();

        foreach ($this->slugs as $os => $slug) {
            if ($all || ($os === $currentOS)) {
                $archive = $this->download($version, $slug);

                $binary = $this->extract($archive);

                $this->rename($binary, $os);
            }
        }

        $message = 'ChromeDriver %s successfully installed for version %s.';

        $this->info(sprintf($message, $all ? 'binaries' : 'binary', $version));
    }
316506
public function handle()
    {
        $rootDirectory = $this->argument('directory') ?? '';

        if( $rootDirectory == '' ) {

            $files = $this->getConfigFiles();

            foreach ( $files as $file )
                $this->generateRoutes(realpath(implode('/', array_slice(explode('/', $file), 0, -3))) . '/');
        } else
            $this->generateRoutes($rootDirectory);
    }
360404
public function handle()
    {
        $id = $this->argument('id');
        $rule = $this->argument('rule');

        if( $id && $rule ) {
            $this->generateThumbByRule($id, $rule);
        } else {
            if( $id ) {
                $this->generateGlobalThumb($id);
            } else {

                if( $this->confirm('Are you sure you want to generate thumbs for all resources?') ) {
                    $list = HCResources::all()->pluck('id');

                    foreach ( $list as $id )
                        $this->generateGlobalThumb($id);
                }
            }
        }
    }