PHP code example of inteve / assets-manager

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

    

inteve / assets-manager example snippets


foreach ($manager->getStylesheetsTags() as $tag) {
	echo $tag;
}


foreach ($manager->getScriptsTags() as $tag) {
	echo $tag;
}


foreach ($manager->getCriticalScriptsTags() as $tag) {
	echo $tag;
}

$fileHashProvider = new Inteve\AssetsManager\Md5FileHashProvider(__DIR__ . '/real/path/to/assets');
$manager = new Inteve\AssetsManager\AssetsManager(
	$currentEnvironment,
	'/public/path/to/assets',
	[],
	$fileHashProvider
);

echo $manager->getPath('css/styles.css'); // prints something like '/public/path/to/assets/css/styles.ab9cd8ef76.css'

$manager->addScripts('https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js');

class JQueryBundle implements Inteve\AssetsManager\IAssetsBundle
{
	function getName()
	{
		return 'jquery';
	}


	function registerAssets(Bundle $bundle)
	{
		$bundle->addScripts('https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js');
	}
}


class ContactFormBundle implements Inteve\AssetsManager\IAssetsBundle
{
	function getName()
	{
		return 'myweb/contactForm';
	}


	function registerAssets(Bundle $bundle)
	{
		$bundle->
 php
$currentEnvironment = PRODUCTION_MODE ? 'production' : 'development';
$manager = new Inteve\AssetsManager\AssetsManager($currentEnvironment, '/public/path');


// get public file path
echo $manager->getPath('css/my-file.css'); // '/public/path/css/my-file.css'
echo $manager->getPath('imgs/avatar.png'); // '/public/path/imgs/avatar.png'


// stylesheets
$manager->addStylesheet(string $file, string $environment = NULL);
$manager->addStylesheet('css/style.css');
$manager->addStylesheet('css/dev.css', 'development');

$assetFiles = $manager->getStylesheet();


// scripts
$manager->addScript(string $file, string $environment = NULL);
$manager->addScript('js/script.js');
$manager->addScript('js/prod.js', 'production');

$assetFiles = $manager->getScripts();


// critical scripts (scripts in <head> for example)
$manager->addCriticalScript(string $file, string $environment = NULL);
$manager->addCriticalScript('js/script.js');
$manager->addCriticalScript('js/prod.js', 'production');

$assetFiles = $manager->getCriticalScripts();