src/Common/Console/Command/Make/Model.php
private function addLocalisedUseStatement(\stdClass $oModel): self
    {
        $sFile = file_get_contents($oModel->path . $oModel->filename);

        // --------------------------------------------------------------------------

        //  Add the imports
        $aClasses = [];
        if (preg_match_all('/^use (.+);$/m', $sFile, $aMatches)) {
            if (!empty($aMatches[1])) {
                $aClasses = $aMatches[1];
            }
        }

        $aClasses[] = Localised::class;
        $aClasses   = array_unique($aClasses);
        $aClasses   = array_filter($aClasses);
        sort($aClasses);
        $aClasses    = array_values($aClasses);
        $sStatements = implode("\n", array_map(function ($sClass) {
            return 'use ' . $sClass . ';';
        }, $aClasses));

        //  Write the imports after `namespace`
        $sFile = preg_replace('/^use.+?;(\n\n|\nclass)/sm', '', $sFile);
        $sFile = preg_replace('/^(namespace .+)$\n/m', "$1\n\n" . $sStatements . "\n", $sFile);

        // --------------------------------------------------------------------------

        $aClasses = [];
        if (preg_match_all('/^    use (.+);$/m', $sFile, $aMatches)) {
            if (!empty($aMatches[1])) {
                $aClasses = $aMatches[1];
            }
        }

        $aTraitBits = explode('\\', Localised::class);
        $aClasses[] = end($aTraitBits);
        $aClasses   = array_unique($aClasses);
        $aClasses   = array_filter($aClasses);
        sort($aClasses);
        $aClasses    = array_values($aClasses);
        $sStatements = implode("\n", array_map(function ($sClass) {
            return '    use ' . $sClass . ';';
        }, $aClasses));

        //  Write the statements after the class definition
        $sFile = preg_replace('/^    use.+?;(\n\n|\nclass)/sm', '', $sFile);
        $sFile = preg_replace('/^(class .+)$\n^{$/m', "$1\n{\n" . $sStatements . "\n", $sFile);

        // --------------------------------------------------------------------------

        file_put_contents(
            $oModel->path . $oModel->filename,
            $sFile
        );

        return $this;
    }
private function addLocalisedUseStatement(\stdClass $oModel): self
    {
        $sFile = file_get_contents($oModel->path . $oModel->filename);

        // --------------------------------------------------------------------------

        //  Add the imports
        $aClasses = [];
        if (preg_match_all('/^use (.+);$/m', $sFile, $aMatches)) {
            if (!empty($aMatches[1])) {
                $aClasses = $aMatches[1];
            }
        }

        $aClasses[] = Localised::class;
        $aClasses   = array_unique($aClasses);
        $aClasses   = array_filter($aClasses);
        sort($aClasses);
        $aClasses    = array_values($aClasses);
        $sStatements = implode("\n", array_map(function ($sClass) {
            return 'use ' . $sClass . ';';
        }, $aClasses));

        //  Write the imports after `namespace`
        $sFile = preg_replace('/^use.+?;(\n\n|\nclass)/sm', '', $sFile);
        $sFile = preg_replace('/^(namespace .+)$\n/m', "$1\n\n" . $sStatements . "\n", $sFile);

        // --------------------------------------------------------------------------

        $aClasses = [];
        if (preg_match_all('/^    use (.+);$/m', $sFile, $aMatches)) {
            if (!empty($aMatches[1])) {
                $aClasses = $aMatches[1];
            }
        }

        $aTraitBits = explode('\\', Localised::class);
        $aClasses[] = end($aTraitBits);
        $aClasses   = array_unique($aClasses);
        $aClasses   = array_filter($aClasses);
        sort($aClasses);
        $aClasses    = array_values($aClasses);
        $sStatements = implode("\n", array_map(function ($sClass) {
            return '    use ' . $sClass . ';';
        }, $aClasses));

        //  Write the statements after the class definition
        $sFile = preg_replace('/^    use.+?;(\n\n|\nclass)/sm', '', $sFile);
        $sFile = preg_replace('/^(class .+)$\n^{$/m', "$1\n{\n" . $sStatements . "\n", $sFile);

        // --------------------------------------------------------------------------

        file_put_contents(
            $oModel->path . $oModel->filename,
            $sFile
        );

        return $this;
    }
private function addLocalisedUseStatement ( \ stdClass $ oModel ) : self { $ sFile = file_get_contents ( $ oModel -> path . $ oModel -> filename ) ; // -------------------------------------------------------------------------- //  Add the imports $ aClasses = [ ] ; if ( preg_match_all ( '/^use (.+);$/m' , $ sFile , $ aMatches ) ) { if ( ! empty ( $ aMatches [ 1 ] ) ) { $ aClasses = $ aMatches [ 1 ] ; } } $ aClasses [ ] = Localised :: class ; $ aClasses = array_unique ( $ aClasses ) ; $ aClasses = array_filter ( $ aClasses ) ; sort ( $ aClasses ) ; $ aClasses = array_values ( $ aClasses ) ; $ sStatements = implode ( "\n" , array_map ( function ( $ sClass ) { return 'use ' . $ sClass . ';' ; } , $ aClasses ) ) ; //  Write the imports after `namespace` $ sFile = preg_replace ( '/^use.+?;(\n\n|\nclass)/sm' , '' , $ sFile ) ; $ sFile = preg_replace ( '/^(namespace .+)$\n/m' , "$1\n\n" . $ sStatements . "\n" , $ sFile ) ; // -------------------------------------------------------------------------- $ aClasses = [ ] ; if ( preg_match_all ( '/^    use (.+);$/m' , $ sFile , $ aMatches ) ) { if ( ! empty ( $ aMatches [ 1 ] ) ) { $ aClasses = $ aMatches [ 1 ] ; } } $ aTraitBits = explode ( '\\' , Localised :: class ) ; $ aClasses [ ] = end ( $ aTraitBits ) ; $ aClasses = array_unique ( $ aClasses ) ; $ aClasses = array_filter ( $ aClasses ) ; sort ( $ aClasses ) ; $ aClasses = array_values ( $ aClasses ) ; $ sStatements = implode ( "\n" , array_map ( function ( $ sClass ) { return '    use ' . $ sClass . ';' ; } , $ aClasses ) ) ; //  Write the statements after the class definition $ sFile = preg_replace ( '/^    use.+?;(\n\n|\nclass)/sm' , '' , $ sFile ) ; $ sFile = preg_replace ( '/^(class .+)$\n^{$/m' , "$1\n{\n" . $ sStatements . "\n" , $ sFile ) ; // -------------------------------------------------------------------------- file_put_contents ( $ oModel -> path . $ oModel -> filename , $ sFile ) ; return $ this ; }
Adds a `use Localised` statement to a model

@param \stdClass $oModel The model being converted

@return $this
Adds a use Localised statement to a model