src/Commands/MakeRepositoryCommand.php
protected function createContract()
    {
        $content = $this->fileManager->get($this->stubs['contract']);

        $replacements = [
            '%namespaces.contracts%' => $this->appNamespace.$this->config('namespaces.contracts'),
            '%modelName%'            => $this->modelName,
        ];

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

        $fileName      = $this->modelName.'Repository';
        $fileDirectory = app()->basePath().'/app/'.$this->config('paths.contracts');
        $filePath      = $fileDirectory.$fileName.'.php';

        if (!$this->fileManager->exists($fileDirectory)) {
            $this->fileManager->makeDirectory($fileDirectory, 0755, true);
        }

        if ($this->laravel->runningInConsole() && $this->fileManager->exists($filePath)) {
            $response = $this->ask("The contract [{$fileName}] already exists. Do you want to overwrite it?", 'Yes');

            if (!$this->isResponsePositive($response)) {
                $this->line("The contract [{$fileName}] will not be overwritten.");
                return;
            }

            $this->fileManager->put($filePath, $content);
        } else {
            $this->fileManager->put($filePath, $content);
        }

        $this->line("The contract [{$fileName}] has been created.");

        return [$this->config('namespaces.contracts').'\\'.$fileName, $fileName];
    }
protected function createContract()
    {
        $content = $this->fileManager->get($this->stubs['contract']);

        $replacements = [
            '%namespaces.contracts%' => $this->appNamespace.$this->config('namespaces.contracts'),
            '%modelName%'            => $this->modelName,
        ];

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

        $fileName      = $this->modelName.'Repository';
        $fileDirectory = app()->basePath().'/app/'.$this->config('paths.contracts');
        $filePath      = $fileDirectory.$fileName.'.php';

        if (!$this->fileManager->exists($fileDirectory)) {
            $this->fileManager->makeDirectory($fileDirectory, 0755, true);
        }

        if ($this->laravel->runningInConsole() && $this->fileManager->exists($filePath)) {
            $response = $this->ask("The contract [{$fileName}] already exists. Do you want to overwrite it?", 'Yes');

            if (!$this->isResponsePositive($response)) {
                $this->line("The contract [{$fileName}] will not be overwritten.");
                return;
            }

            $this->fileManager->put($filePath, $content);
        } else {
            $this->fileManager->put($filePath, $content);
        }

        $this->line("The contract [{$fileName}] has been created.");

        return [$this->config('namespaces.contracts').'\\'.$fileName, $fileName];
    }
protected function createContract ( ) { $ content = $ this -> fileManager -> get ( $ this -> stubs [ 'contract' ] ) ; $ replacements = [ '%namespaces.contracts%' => $ this -> appNamespace . $ this -> config ( 'namespaces.contracts' ) , '%modelName%' => $ this -> modelName , ] ; $ content = str_replace ( array_keys ( $ replacements ) , array_values ( $ replacements ) , $ content ) ; $ fileName = $ this -> modelName . 'Repository' ; $ fileDirectory = app ( ) -> basePath ( ) . '/app/' . $ this -> config ( 'paths.contracts' ) ; $ filePath = $ fileDirectory . $ fileName . '.php' ; if ( ! $ this -> fileManager -> exists ( $ fileDirectory ) ) { $ this -> fileManager -> makeDirectory ( $ fileDirectory , 0755 , true ) ; } if ( $ this -> laravel -> runningInConsole ( ) && $ this -> fileManager -> exists ( $ filePath ) ) { $ response = $ this -> ask ( "The contract [{$fileName}] already exists. Do you want to overwrite it?" , 'Yes' ) ; if ( ! $ this -> isResponsePositive ( $ response ) ) { $ this -> line ( "The contract [{$fileName}] will not be overwritten." ) ; return ; } $ this -> fileManager -> put ( $ filePath , $ content ) ; } else { $ this -> fileManager -> put ( $ filePath , $ content ) ; } $ this -> line ( "The contract [{$fileName}] has been created." ) ; return [ $ this -> config ( 'namespaces.contracts' ) . '\\' . $ fileName , $ fileName ] ; }
Create a new contract
Create a new contract