PHP code example of tatter / assets

1. Go to this page and download the library: Download tatter/assets library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tatter / assets example snippets




use Tatter\Assets\Asset;

$asset = new Asset('<link href="/assets/styles.css" rel="stylesheet" type="text/css" />');
echo view('main', ['asset' => $asset]);

<html>
<head>
	<title>Hello World</title>
	<?= $asset 

<html>
<head>
	<title>Hello World</title>
	<?= \Tatter\Assets\Asset::createFromPath('styles.css') 

 namespace App\Bundles;

use Tatter\Assets\Bundle;

class FrontendBundle extends Bundle
{
    protected $bundles = [
        StylesBundle::class,
    ];

    protected $paths = [
        'bootstrap/dist/css/bootstrap.min.css',
        'bootstrap/dist/js/bootstrap.bundle.min.js',
    ];

    protected $uris = [
        'https://pagecdn.io/lib/cleave/1.6.0/cleave.min.js',
    ];
}

 namespace App\Bundles;

use Tatter\Assets\Asset;
use Tatter\Assets\Bundle;

class ColorBundle extends Bundle
{
    protected function define()
    {
        $this
            ->add(Asset::createFromPath('styles.css')) // Add individual Assets
            ->merge($someOtherBundle); // Or combine multiple Bundles

        // Create more complex Assets
        $source = '<script src="https://pagecdn.io/lib/cleave/1.6.0/cleave.min.js" type="text/javascript"></script>';
        $inHead = true; // Force a JavaScript Asset to the <head> tag
        $asset  = new Asset($source, $inHead);
    }
}

 namespace Config;

use Tatter\Assets\Config\Assets as AssetsConfig;

class Assets extends AssetsConfig
{
    public $routes = [
        '*' => [
            'bootstrap/bootstrap.min.css',
            'bootstrap/bootstrap.bundle.min.js',
            'font-awesome/css/all.min.css',
            'styles/main.css',
        ],
        'files' => [
            'dropzone/dropzone.min.css',
            'dropzone/dropzone.min.js',
        ],
    ];
}

// **app/Config/Routes.php**
$routes->add('files', 'Files::index', ['filter' => 'assets:\App\Filters\FilesFilter']);

    /**
     * List of filter aliases that are always
     * applied before and after every request.
     *
     * @var array
     */
    public $globals = [
        'before' => [
            // 'honeypot',
            // 'csrf',
        ],
        'after'  => [
            'assets' => ['except' => 'api/*'],
        ],
    ];

 namespace App\Bundles;

use Tatter\Assets\Bundle;

class DropzoneJS extends Bundle
{
    protected $paths = [
        'dropzone/dropzone.min.css',
        'dropzone/dropzone.min.js',
    ];
}

public $routes = [
    '*' => [
        'bootstrap/dist/css/bootstrap.min.css',
        'bootstrap/dist/js/bootstrap.bundle.min.js',
    ],
    'files/*' => [
        \App\Bundles\DropzoneJS::class,
    ],
    'upload' => [
        \App\Bundles\DropzoneJS::class,
    ],
];



namespace App\Publishers;

use Tatter\Assets\VendorPublisher;

class BootstrapPublisher extends VendorPublisher
{
    protected $source = 'vendor/twbs/bootstrap/dist';
    protected $path   = 'bootstrap';
}




namespace App\Bundles;

use Tatter\Assets\VendorBundle;

class BootstrapBundle extends VendorBundle
{
    protected function define(): void
    {
        $this
            ->addPath('bootstrap/bootstrap.min.css')
            ->addPath('bootstrap/bootstrap.bundle.min.js');
    }
}

public $routes = [
    '*' => [\App\Bundles\BootstrapBundle::class],
];