@param string $stub
@param bool $rewrite

@return string
510264
public static function copy(string $stub, bool $rewrite = false): string
    {
        if (! file_exists(static::QUEUE_CLASS_PATH) || $rewrite) {
            copy($stub, static::QUEUE_CLASS_PATH);
        }

        return static::QUEUE_CLASS;
    }
5396
public function getParams(array $rewrite = []): array
    {
        $params = $this->params;

        // change page to first for each new grid (with new filters or orders, or other stuff)
        $page = $rewrite['page'] ?? 1;

        if ($page > 1) {
            $params[$this->prefix . 'page'] = $page;
        }

        // change limit
        $limit = $rewrite['limit'] ?? $this->getLimit();

        if ($limit !== $this->defaultLimit) {
            $params[$this->prefix . 'limit'] = $limit;
        }

        // change orders
        $orders = $rewrite['orders'] ?? $this->getOrders();

        foreach ($orders as $column => $order) {
            $column = $this->applyAlias($column);
            $params[$this->prefix . 'order-' . $column] = $order;
        }

        // change filters
        $filters = $rewrite['filters'] ?? $this->getFilters();

        foreach ($filters as $column => $columnFilters) {
            /** @var array $columnFilters */
            $column = $this->applyAlias($column);
            if (\count($columnFilters) === 1 && isset($columnFilters[self::FILTER_EQ])) {
                $params[$this->prefix . 'filter-' . $column] = $columnFilters[self::FILTER_EQ];
                continue;
            }

            $columnFilter = [];
            foreach ($columnFilters as $filterName => $filterValue) {
                $columnFilter[] = $filterName . '-' . $filterValue;
            }
            $params[$this->prefix . 'filter-' . $column] = implode('_', $columnFilter);
        }
        return $params;
    }
781631
protected function replaceClass($stub, $name)
    {
        $stub = str_replace('{{class}}',$this->parseName($name), $stub);
        return $stub;
    }
1353976
protected function replaceUserNamespace($stub)
    {
        $model = $this->userProviderModel();

        if (! $model) {
            return $stub;
        }

        return str_replace(
            $this->rootNamespace().'User',
            $model,
            $stub
        );
    }
603256
protected function getStubContent($stubName)
    {
        $stubPath = $this->getStubsPath() .$stubName;

        $content = $this->files->get($stubPath);

        return $this->formatContent($content);
    }
475406
protected function beforeApplyOptions($stub)
	{
		$refModel = new ReflectionClass($this->model);
		$refIntermeidateModel = new ReflectionClass($this->defaultOptions['intermediate_model']);
		
		$model = $refIntermeidateModel->getShortName();
		
		if ($refModel->getNamespaceName() !== $refIntermeidateModel->getNamespaceName()) {
			$model = '\\'.$refIntermeidateModel->getName();
		}

		return str_replace('DummyIntermediateModel', $model, $stub);
	}
1329398
protected function replaceUserNamespace($stub): string
    {
        if (! $userModel = config('auth.providers.'.config('auth.guards.'.config('auth.defaults.guard').'.provider').'.model')) {
            return $stub;
        }

        return str_replace(
            $this->rootNamespace().'User',
            $userModel,
            $stub
        );
    }
867487
protected function getIndent($stub, $template)
    {
        $lines = explode("\n", $stub);

        foreach ($lines as $line) {
            if (($index = strpos($line, $template)) !== false) {
                return $index;
            }
        }

        return 0;
    }
591961
public function getPage($stub)
    {
        $this->logger->addNotice(print_r($this->cfg->getAll(), 1));

        $stmtManager = $this->getStatementManager(Simple::class);

        /** @var Select $stmtBuilder */
        $stmtBuilder = $stmtManager->getStatementBuilder(Select::class);

        /** @var PageCollection $collection */
        $collection = $stmtManager->setStatement($stmtBuilder->setWhere(['stub = :stub']))
            ->setArguments(['stub' => $stub])
            ->execute();

        /** @var PageDataModel $c */
        $c = $collection->current();

        return $c;
    }
975380
protected function writeCommand($file, $stub)
	{
		if ( ! file_exists($file))
		{
			$this->files->put($file, $this->formatStub($stub));

			$this->info('Command created successfully.');
		}
		else
		{
			$this->error('Command already exists!');
		}
	}
1355282
protected function addMethods($stub, array $options)
	{
		// Once we have the applicable methods, we can just spin through those methods
		// and add each one to our array of method stubs. Then we will implode them
		// them all with end-of-line characters and return the final joined list.
		$stubs = $this->getMethodStubs($options);

		$methods = implode(PHP_EOL.PHP_EOL, $stubs);

		return str_replace('{{methods}}', $methods, $stub);
	}
785127
protected function compileMethods($stub, array $methods)
    {
        foreach ($methods as $method) {
            $stub = str_replace(['{{' . $method . '}}', '{{/' . $method . '}}'], '', $stub);
        }

        foreach ($this->methods as $method) {
            $stub = preg_replace('/{{' . $method . '}}(.*){{\/' . $method . '}}(\r\n)?/s', '', $stub);
        }

        return $stub;
    }
290962
protected function replaceConnectionName(&$stub, $name)
    {
        $connectionLine = !empty($name) ? sprintf("connection('%s')->", $name) : '';

        return $this->replaceTemplate('connection_name', $connectionLine, $stub);
    }
198896
protected function replaceBaseRepositoryClass(&$stub, $name)
    {
        $baseClass = str_replace($this->getNamespace($name) . '\\', '', $name);
        $stub      = str_replace('BaseRepositoryClass', $baseClass, $stub);

        return $this;
    }
934476
public function compile($stub, $modelName, $modelData, stdClass $scaffolderConfig, $hash, array $extensions, $extra = null)
    {
        if (File::exists(base_path('scaffolder-config/cache/controller_' . $hash . self::CACHE_EXT)))
        {
            return $this->store($modelName, $scaffolderConfig, '', new FileToCompile(true, $hash));
        }
        else
        {
            $this->stub = $stub;

            $this->replaceClassName($modelName)
                ->setValidations($modelData)
                ->replacePrimaryKey($modelData)
                ->replaceRoutePrefix($scaffolderConfig->routing->prefix);

            foreach ($extensions as $extension)
            {
                $this->stub = $extension->runAfterControllerIsCompiled($this->stub, $modelData, $scaffolderConfig);
            }

            return $this->store($modelName, $scaffolderConfig, $this->stub, new FileToCompile(false, $hash));
        }
    }
934429
protected function extendStub($stub)
    {
        /** @var \Illuminate\Filesystem\Filesystem $files */
        $files = App::make('Illuminate\Filesystem\Filesystem');
        $content = $files->get(__DIR__.DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'command.stub');

        $replacements = [
            'use Illuminate\Console\Command' => "use Indatus\\Dispatcher\\Scheduling\\ScheduledCommand;\n".
                "use Indatus\\Dispatcher\\Scheduling\\Schedulable;\n".
                "use Indatus\\Dispatcher\\Drivers\\".ucwords(Config::get('dispatcher::driver'))."\\Scheduler",
            'extends Command {' => 'extends ScheduledCommand {',
            'parent::__construct();' => $content,
        ];

        $stub = str_replace(array_keys($replacements), array_values($replacements), $stub);

        return $stub;
    }
549486
private static function applyRewrites(string $requestedUri, array $rewrites): string
    {
        foreach ($rewrites as $route) {
            $pattern      = $route['pattern'];
            $replacement  = $route['replacement'];
            $requestedUri = preg_replace($pattern, $replacement, $requestedUri);

            if (isset($route['last'])) {
                break;
            }
        }

        return $requestedUri;
    }