src/Template/TemplateLoader.php
public function load (string $name) : TemplateInterface
    {
        $supportedExtensions = array_keys(self::$providers);

        $fsPathLength = strlen($this->fs->path());

        $files = $this->fs
            ->find("{$name}.*")
            ->files()
            ->asArray();

        $found = [];
        foreach ($files as $file) {
            $ext = $file->extension();
            if (!in_array($ext, $supportedExtensions))
                continue;
            $found[] = [
                'name' => substr($file->path(), $fsPathLength),
                'extension' => $ext
            ];
        }

        if (count($found) == 0) {
            throw new \InvalidArgumentException("Unable to find template with name '{$name}' on '{$this->fs->path()}'");
        }

        if (count($found) > 1) {
            throw new \InvalidArgumentException("Mutiple templates found for the name '{$name}' on '{$this->fs->path()}'");
        }

        return $this->loaders[$found[0]['extension']]->load($found[0]['name']);
    }
public function load (string $name) : TemplateInterface
    {
        $supportedExtensions = array_keys(self::$providers);

        $fsPathLength = strlen($this->fs->path());

        $files = $this->fs
            ->find("{$name}.*")
            ->files()
            ->asArray();

        $found = [];
        foreach ($files as $file) {
            $ext = $file->extension();
            if (!in_array($ext, $supportedExtensions))
                continue;
            $found[] = [
                'name' => substr($file->path(), $fsPathLength),
                'extension' => $ext
            ];
        }

        if (count($found) == 0) {
            throw new \InvalidArgumentException("Unable to find template with name '{$name}' on '{$this->fs->path()}'");
        }

        if (count($found) > 1) {
            throw new \InvalidArgumentException("Mutiple templates found for the name '{$name}' on '{$this->fs->path()}'");
        }

        return $this->loaders[$found[0]['extension']]->load($found[0]['name']);
    }
public function load ( string $ name ) : TemplateInterface { $ supportedExtensions = array_keys ( self :: $ providers ) ; $ fsPathLength = strlen ( $ this -> fs -> path ( ) ) ; $ files = $ this -> fs -> find ( "{$name}.*" ) -> files ( ) -> asArray ( ) ; $ found = [ ] ; foreach ( $ files as $ file ) { $ ext = $ file -> extension ( ) ; if ( ! in_array ( $ ext , $ supportedExtensions ) ) continue ; $ found [ ] = [ 'name' => substr ( $ file -> path ( ) , $ fsPathLength ) , 'extension' => $ ext ] ; } if ( count ( $ found ) == 0 ) { throw new \ InvalidArgumentException ( "Unable to find template with name '{$name}' on '{$this->fs->path()}'" ) ; } if ( count ( $ found ) > 1 ) { throw new \ InvalidArgumentException ( "Mutiple templates found for the name '{$name}' on '{$this->fs->path()}'" ) ; } return $ this -> loaders [ $ found [ 0 ] [ 'extension' ] ] -> load ( $ found [ 0 ] [ 'name' ] ) ; }
Load a template by name. The name is the relative
path of the template file from the templates folder
The name is given without extension; Exceptions are
thrown if no file with supported extension is found
or if many exists.

@param  string $name
@return Tarsana\Command\Interfaces\TemplateInterface
@throws Tarsana\Command\Exceptions\TemplateNotFound
@throws Tarsana\Command\Exceptions\TemplateNameConflict
Load a template by name . The name is the relative path of the template file from the templates folder The name is given without extension ; Exceptions are thrown if no file with supported extension is found or if many exists .