Adds the parser.file.pre event to the advance the progressbar.

@param InputInterface $input

@return \Symfony\Component\Console\Helper\HelperInterface|null
484330
protected function getProgressBar(InputInterface $input)
    {
        $progress = parent::getProgressBar($input);
        if (!$progress) {
            return null;
        }

        $this->getService('event_dispatcher')->addListener(
            'parser.file.pre',
            function (PreFileEvent $event) use ($progress) {
                $progress->advance();
            }
        );

        return $progress;
    }
855585
public function process(PrePush $prePushData, IOInterface $input)
    {
        $this->input = $input;
        if (true === $prePushData->isUndefined()) {
            $prePushData = PrePushConfigurator::configure($this->input, $prePushData);
        }

        if (true === $prePushData->isEnabled()) {
            $prePushData = $prePushData->setExecute($this->configTools($prePushData->getExecute()));
        }

        return $prePushData;
    }
219178
protected function shouldWait(InputInterface $input)
    {
        if ($input->hasOption('no-wait') && $input->getOption('no-wait')) {
            return false;
        }
        if ($input->hasOption('wait') && $input->getOption('wait')) {
            return true;
        }
        if ($this->detectRunningInHook()) {
            $serviceName = $this->config()->get('service.name');
            $message = "\n<comment>Warning:</comment> $serviceName hook environment detected: assuming <comment>--no-wait</comment> by default."
                . "\nTo avoid ambiguity, please specify either --no-wait or --wait."
                . "\n";
            $this->stdErr->writeln($message);

            return false;
        }

        return true;
    }
1243528
protected function makeCreator(InputInterface $input)
    {
        $path = $input->getArgument('path');

        if ($input->getOption('git')) {
            return new GitRepoCreator($input->getOption('git'), $path);
        } elseif ($input->getOption('submodule')) {
            return new GitSubmoduleCreator($input->getOption('submodule'), $path);
        } else {
            $creator = new SkeletonCreator($path);
            $this->installParts($creator);
            return $creator;
        }
    }
1095603
public function addInput($input)
    {
        if ($input === '') {
            return $this;
        }

        // read everything up until before current position
        $pre  = $this->substr($this->linebuffer, 0, $this->linepos);
        $post = $this->substr($this->linebuffer, $this->linepos);

        $this->linebuffer = $pre . $input . $post;
        $this->linepos += $this->strlen($input);

        // only redraw if input should be echo'ed (i.e. is not hidden anyway)
        if ($this->echo !== false) {
            $this->redraw();
        }

        return $this;
    }
347975
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->setInputAndOutput($input, $output);

        return $this->doExecute();
    }
292763
protected function execute(InputInterface $input, OutputInterface $output)
    {
        if (method_exists($this, 'preUpdate')) {
            $this->preUpdate();
        }

        $namespace = 'Soda\\Updater\\Cms\\';
        $updateFiles = new \RecursiveDirectoryIterator(base_path('vendor/soda-framework/cms/'.trim($this->updatesDir, '/')));
        $updateFiles = new \RecursiveCallbackFilterIterator(
            $updateFiles,
            function ($item) {
                return $item->getExtension() === 'php' ? true : false;
            }
        );

        foreach ($updateFiles as $file) {
            require_once $file->getPathName();
            $className = $namespace.basename($file->getFilename(), '.php');
            if (class_exists($className)) {
                $updateClass = new $className;

                $updateClass->run();
            }
        }
    }
1198571
private function validateInput(InputInterface $input)
    {
        if (!$input->getArgument('target')) {
            // if no target is passed, there can be no properties or methods
            foreach (['properties', 'methods', 'no-inherit'] as $option) {
                if ($input->getOption($option)) {
                    throw new RuntimeException('--' . $option . ' does not make sense without a specified target');
                }
            }

            foreach (['globals', 'vars', 'constants', 'functions', 'classes', 'interfaces', 'traits'] as $option) {
                if ($input->getOption($option)) {
                    return;
                }
            }

            // default to --vars if no other options are passed
            $input->setOption('vars', true);
        } else {
            // if a target is passed, classes, functions, etc don't make sense
            foreach (['vars', 'globals', 'functions', 'classes', 'interfaces', 'traits'] as $option) {
                if ($input->getOption($option)) {
                    throw new RuntimeException('--' . $option . ' does not make sense with a specified target');
                }
            }

            foreach (['constants', 'properties', 'methods'] as $option) {
                if ($input->getOption($option)) {
                    return;
                }
            }

            // default to --constants --properties --methods if no other options are passed
            $input->setOption('constants',  true);
            $input->setOption('properties', true);
            $input->setOption('methods',    true);
        }
    }
1060531
public function execute(InputInterface $input, OutputInterface $output)
    {
        $assetsDirectory = str_replace('/', DIRECTORY_SEPARATOR, 'web/bundles');

        $manager = $this->getDocumentManager();
        $assetFactory = $this->getAssetFactory();

        if ($input->getOption('clear')) {
            $output->writeln('Clearing assets from the content repository. This should NEVER be used in a production environment unless you know what you\'re doing!');

            if ($assetNode = $manager->find(null, '/asset')) {
                $manager->remove($assetNode);
                $manager->flush();
                $manager->clear();
            }
        }

        $batchSize = (int) $input->getOption('batchSize') ?: self::$defaultBatchSize;
        $assetFileArray = $this->getAssetFileArray($assetsDirectory);
        if (count($assetFileArray) === 0) {
            $output->writeln('No assets to move, please run the assets:install command first.');
            return 1; // failure
        }

        $output->writeln('Moving assets into content repository...');
        $progress = new ProgressBar($output, count($assetFileArray));
        $progress->setFormat('verbose');
        $progress->start();

        foreach (array_chunk($assetFileArray, $batchSize) as $chunk) {
            foreach ($chunk as $fileArr) {
                /** @var \SplFileInfo $file */
                $file = $fileArr['file'];
                $linkedLocation = $fileArr['linkedLocation'];

                $parentPath = $file->getPath();
                if ($linkedLocation) {
                    $needle = DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR;
                    $pos = strpos($parentPath, $needle);
                    $parentPath = $linkedLocation . DIRECTORY_SEPARATOR . substr($parentPath, $pos + strlen($needle));
                }
                $parentPath = str_replace($assetsDirectory . DIRECTORY_SEPARATOR, '', $parentPath);
                $parentPath = str_replace('\\', '/', $parentPath);
                $parentNode = $this->findOrCreateNode('asset/' . $parentPath);

                /** @var FileDocument|ImageDocument $asset */
                $asset = $assetFactory->create($file);
                $asset
                    ->copyContentFromFile($file)
                    ->setParentDocument($parentNode)
                    ->setNodename($file->getBasename())
                ;

                $manager->persist($asset);
                $progress->advance();
            }

            $manager->flush();
            $manager->clear();
        }

        $this->deleteDirectoryContents($assetsDirectory);
        $progress->finish();
        $output->writeln("\nFinished!");

        return 0; // everything went okay
    }
1040150
public function cli(InputInterface $input = null, OutputInterface $output = null)
  {
    $input = $input ?? new ArgvInput();
    $output = $output ?? new ConsoleOutput();

    $console = $this->getConsole();
    $this->_eventChannel->trigger(ConsolePrepareEvent::i($this->getContext(), $console, $input, $output));

    try
    {
      $exitCode = $console->run($input, $output);
    }
    catch(\Throwable $e)
    {
      $output->writeln("GENERIC EXCEPTION : " . $e->getCode());
      $output->writeln($e->getMessage());
      $exitCode = 1;
    }

    return $exitCode > 255 ? 255 : $exitCode;
  }
492961
public function process(PreCommit $preCommitData, IOInterface $input)
    {
        $this->io = $input;
        if (true === $preCommitData->isUndefined()) {
            $preCommitData = PreCommitConfigurator::configure($this->io, $preCommitData);
        }

        if (true === $preCommitData->isEnabled()) {
            $preCommitData = $preCommitData->setExecute($this->configTools($preCommitData->getExecute()));
        }

        return $preCommitData;
    }
888017
private function createTracker(InputInterface $input)
    {
        switch ($input->getArgument('type')) {
            case 'github' :
                $tracker = new GithubTracker($input->getOption('username'));
                break;
            case 'jira' :
                $tracker = new JiraTracker($input->getOption('host'), $input->getOption('username'), $input->getOption('password'));
                break;
            case 'gitlab' :
                $tracker = new GitlabTracker($input->getOption('host'), $input->getOption('username'));
                break;
            case 'bitbucket' :
                $tracker = new BitbucketTracker($input->getOption('username'), $input->getOption('password'));
                break;
            default :
                throw new \InvalidArgumentException(sprintf('unknown type "%s"', $input->getArgument('type')));
        }

        return $tracker;
    }
72678
protected function getConfiguration(InputInterface $input): ConsoleConfigInterface
    {
        // If the configuration to use is the default.
        if ($input->getOption('default')) {
            $this->validatePathsExist($input);
            // If it is a directory.
            if ($input->getOption('dir')) {
                return (new DefaultConsoleConfigFactory())
                    ->invokeDir($input->getArgument('source'), $input->getArgument('target'));
            }
            return (new DefaultConsoleConfigFactory())
                ->invokeFile($input->getArgument('source'), $input->getArgument('target'));
        }

        $path = $input->getOption('config');
        // If we have a "=" at the beginning of the option value
        $path = preg_replace('/^\=/', '', $path);

        $factory = $this->getConfigurationFactory($path);

        if ($input->getOption('dir')) {
            $this->validatePathsExist($input);
            return $factory->invokeDir(
                $path,
                $input->getArgument('source'),
                $input->getArgument('target')
            );
        }
        if ($input->getOption('file')) {
            $this->validatePathsExist($input);
            return $factory->invokeFile(
                $path,
                $input->getArgument('source'),
                $input->getArgument('target')
            );
        }
        return $factory->invoke($path);
    }
1160274
protected function getTemplate(InputInterface $input)
    {
        $template = $this->getTemplateFactory()->get('twig');
        $template->setName($input->getOption('template'));

        return $template;
    }
810741
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $themeName = $input->getArgument('theme');
        $kernel = $this->getContainer()->get('kernel');
        $themePath = $kernel->locateResource('@' . $themeName);

        $slots = array();
        $finder = new \Symfony\Component\Finder\Finder();
        $templateFiles = $finder->files('*.twig')->in($themePath  . '/Resources/views/Theme');
        foreach ($templateFiles as $template) {
            $template = (string) $template;
            $templateContents = file_get_contents($template);

            $currentTemplateContents = $templateContents;
            preg_match_all('/([^%]+)[^\w]+BEGIN-SLOT.*?\{% endblock[^%\}]+%\}/si', $templateContents, $matches, PREG_SET_ORDER);
            foreach ($matches as $match) {
                $block = '{%' . $match[0];
                $blockName = trim(str_replace('block ', '', $match[1]));
                $currentTemplateContents = str_replace($block, "{{ block('$blockName') }}", $currentTemplateContents);

                preg_match('/([\r\n][\s]+)\{# BEGIN-SLOT/', $block, $spacesMatch);
                if (array_key_exists(1, $spacesMatch)) {
                    $block = str_replace($spacesMatch[1], "\n    ", $block);
                    $block = preg_replace('/([\r\n][\s]+)\{% endblock/', "\n{% endblock", $block);
                }
                $slots[] = $block;
            }

            $useStatement = "{% use '$themeName:Slots:slots.html.twig' %}\n";
            preg_match('/\{% extend[^\}]+\}/', $currentTemplateContents, $m);
            $currentTemplateContents = (array_key_exists(0, $m)) ? str_replace($m[0], $m[0] . "\n\n" . $useStatement, $currentTemplateContents) : $currentTemplateContents = $useStatement . $currentTemplateContents;
            file_put_contents($template, $currentTemplateContents);
        }

        $slotsDir = $themePath  . '/Resources/views/Slots';
        @mkdir($slotsDir);
        file_put_contents($slotsDir . '/slots.html.twig', implode("\n\n", $slots));

        $message = sprintf('The theme <info>%s</info> has been migrated', $themeName);
        $output->writeln($message);
    }
617810
public function parseFragment(HTML5_Inputstream_Interface $input) {
        $events = new HTML5_Parser_DOMTreeBuilder(true, $this->options);
        $scanner = new HTML5_Parser_Scanner($input);
        $parser = new HTML5_Parser_Tokenizer($scanner, $events);

        $parser->parse();
        $this->errors = $events->getErrors();

        return $events->fragment();
    }
959992
protected function setIblocks(InputInterface $input)
    {
        $iblocks = IblockTable::query()
            ->setFilter([
                'IBLOCK_TYPE_ID' => $input->getArgument('type'),
                'CODE' => $input->getArgument('code')
            ])
            ->setSelect(['ID', 'CODE'])
            ->exec();

        if ($iblocks->getSelectedRowsCount() <= 0) {
            $this->errors[] = 'Iblock(s) not found';
        }

        $this->iblocks = $iblocks->fetchAll();
    }