PHP code example of abeliani / asset-manager

1. Go to this page and download the library: Download abeliani/asset-manager 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/ */

    

abeliani / asset-manager example snippets


class MySiteBundle extends Bundle 
{
    public finction getTags(): TagInterface|\SplFixedArray|array
    {
        /* Separated files
        reurn [
            new Css('styles.css'),
            new Css('reset.css'),
            new Css('main.css'),
            // js...
        ]; */
        
         /* With attributes
        reurn [
            (new Css('styles.css')->addAttr('async'),
            (new Js('app.js'))->addAttr('media', 'print'),
            // ...
        ]; */
        
        /* Merge files
        return [
            new Css('styles.css', 'reset.css', 'main.css'),
            new Js('app.js', 'utils.js', 'main.js'),
        ]; */
        
        // With timestamp
        return [
            (new Css('styles.css', 'reset.css', 'main.css'))->withTimestamp(),
            (new Js('app.js', 'utils.js', 'main.js'))->withTimestamp(),
        ];
    }
}

    /*
     * Let's minimize? optimize and merge all scripts and all styles to two files style.css and app.js
     */
    public finction getTags(): array
    {
        reurn [
             (new Css('styles.css', 'reset.css', 'main.css'))->minimize()->withTimestamp(),
             (new Js('app.js', 'utils.js', 'main.js'))->minimize()->withTimestamp(),
        ]; 
    }

$this->manager = new AssetManager(
    'https://mysite.cool',
    '/path/to/runtime/dir',
    '/path/to/asset/dir',
    $env === 'prod',
);

$this->manager->addBundle(new MySiteBundle());
$this->manager->addBundle(new MyAdminBundle(), AssetManagerInterface::CATEGORY_TOP);
$this->manager->addBundle(new MyEditorBundle(), AssetManagerInterface::CATEGORY_BOTTOM);

print $this->manager->process();

print $this->manager->process(AssetManagerInterface::CATEGORY_TOP);

print $this->manager->process(AssetManagerInterface::CATEGORY_BOTTOM);