protected function validateServiceFile(string $sToken = null): BaseMaker
    {
        if (empty($sToken) && empty(static::SERVICE_TOKEN)) {
            throw new ConsoleException(
                'SERVICE_TOKEN is not set'
            );
        } elseif (empty($sToken)) {
            $sToken = static::SERVICE_TOKEN;
        }

        //  Detect the services file
        if (!file_exists(static::SERVICE_PATH)) {
            throw new ConsoleException(
                'Could not detect the app\'s services.php file: ' . static::SERVICE_PATH
            );
        }

        //  Look for the generator token
        $this->fServicesHandle = fopen(static::SERVICE_PATH, 'r+');;
        $bFound                = false;
        if ($this->fServicesHandle) {
            $iLocation = 0;
            while (($sLine = fgets($this->fServicesHandle)) !== false) {
                if (preg_match('#^(\s*)// GENERATOR\[' . $sToken . '\]#', $sLine, $aMatches)) {
                    $bFound                       = true;
                    $this->iServicesIndent        = strlen($aMatches[1]);
                    $this->iServicesTokenLocation = $iLocation;
                    break;
                }
                $iLocation = ftell($this->fServicesHandle);
            }
            if (!$bFound) {
                fclose($this->fServicesHandle);
                throw new ConsoleException(
                    'Services file does not contain the generator token (i.e // GENERATOR[' . $sToken . ']) ' .
                    'This token is required so that the tool can safely insert new definitions'
                );
            }
        } else {
            throw new ConsoleException(
                'Failed to open the services file for reading and writing: ' . static::SERVICE_PATH
            );
        }

        return $this;
    }
protected function validateServiceFile(string $sToken = null): BaseMaker
    {
        if (empty($sToken) && empty(static::SERVICE_TOKEN)) {
            throw new ConsoleException(
                'SERVICE_TOKEN is not set'
            );
        } elseif (empty($sToken)) {
            $sToken = static::SERVICE_TOKEN;
        }

        //  Detect the services file
        if (!file_exists(static::SERVICE_PATH)) {
            throw new ConsoleException(
                'Could not detect the app\'s services.php file: ' . static::SERVICE_PATH
            );
        }

        //  Look for the generator token
        $this->fServicesHandle = fopen(static::SERVICE_PATH, 'r+');;
        $bFound                = false;
        if ($this->fServicesHandle) {
            $iLocation = 0;
            while (($sLine = fgets($this->fServicesHandle)) !== false) {
                if (preg_match('#^(\s*)// GENERATOR\[' . $sToken . '\]#', $sLine, $aMatches)) {
                    $bFound                       = true;
                    $this->iServicesIndent        = strlen($aMatches[1]);
                    $this->iServicesTokenLocation = $iLocation;
                    break;
                }
                $iLocation = ftell($this->fServicesHandle);
            }
            if (!$bFound) {
                fclose($this->fServicesHandle);
                throw new ConsoleException(
                    'Services file does not contain the generator token (i.e // GENERATOR[' . $sToken . ']) ' .
                    'This token is required so that the tool can safely insert new definitions'
                );
            }
        } else {
            throw new ConsoleException(
                'Failed to open the services file for reading and writing: ' . static::SERVICE_PATH
            );
        }

        return $this;
    }
protected function validateServiceFile ( string $ sToken = null ) : BaseMaker { if ( empty ( $ sToken ) && empty ( static :: SERVICE_TOKEN ) ) { throw new ConsoleException ( 'SERVICE_TOKEN is not set' ) ; } elseif ( empty ( $ sToken ) ) { $ sToken = static :: SERVICE_TOKEN ; } //  Detect the services file if ( ! file_exists ( static :: SERVICE_PATH ) ) { throw new ConsoleException ( 'Could not detect the app\'s services.php file: ' . static :: SERVICE_PATH ) ; } //  Look for the generator token $ this -> fServicesHandle = fopen ( static :: SERVICE_PATH , 'r+' ) ; ; $ bFound = false ; if ( $ this -> fServicesHandle ) { $ iLocation = 0 ; while ( ( $ sLine = fgets ( $ this -> fServicesHandle ) ) !== false ) { if ( preg_match ( '#^(\s*)// GENERATOR\[' . $ sToken . '\]#' , $ sLine , $ aMatches ) ) { $ bFound = true ; $ this -> iServicesIndent = strlen ( $ aMatches [ 1 ] ) ; $ this -> iServicesTokenLocation = $ iLocation ; break ; } $ iLocation = ftell ( $ this -> fServicesHandle ) ; } if ( ! $ bFound ) { fclose ( $ this -> fServicesHandle ) ; throw new ConsoleException ( 'Services file does not contain the generator token (i.e // GENERATOR[' . $ sToken . ']) ' . 'This token is required so that the tool can safely insert new definitions' ) ; } } else { throw new ConsoleException ( 'Failed to open the services file for reading and writing: ' . static :: SERVICE_PATH ) ; } return $ this ; }
Validate the service file is valid

@return $this
@throws ConsoleException
Validate the service file is valid