PHP Classes

Legato PHP Asset Management: Get versioned URLs for CSS, JavaScript and images

Recommend this page to a friend!
  Info   View files Example   View files View files (10)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 76 All time: 10,126 This week: 177Up
Version License PHP version Categories
legato-asset 1.0.0MIT/X Consortium ...5.3.9HTML, PHP 5
Description 

Author

This package can get versioned URLs for CSS, JavaScript and images.

It can take the name of a file to be served as part of a Web page like an image, CSS or JavaScript and returns a URL to be used in the page to refer to those asset files.

The class serve the specified asset files from the generated URLs.

Those URLs include a parameter with a value that may be passed to the package explicitly or be generated by it using a random value.

Picture of Ogbemudia Osayawe
  Performance   Level  
Name: Ogbemudia Osayawe <contact>
Classes: 8 packages by
Country: Germany Germany
Age: 40
All time rank: 2943174 in Germany Germany
Week rank: 312 Up18 in Germany Germany Up
Innovation award
Innovation award
Nominee: 5x

Example

<?php

if(!file_exists('asset')){

   
/**
     * Get versioned url for assets
     *
     * @param $path
     * @param $query
     * @return string
     */
   
function asset($path, $query = null)
    {
       
$version = is_null($query) ? "%s?%s" : "%s?$query=%s";
       
$random = md5('random');

       
$strategy = new \Legato\Framework\src\asset\StaticVersionStrategy(
           
$random, $version
       
);

        return
$strategy->url($path);
    }
}


Details

Legato Asset

A simple tool for generating unique versioned URLs for images, stylesheet, javascript, etc.

Installation

composer require legato/asset

Usage


Relative Path
<link href="<?= asset('css/style.css') ?>" rel="stylesheet">

Absolute Path
<link href="<?= asset('/css/style.css') ?>" rel="stylesheet">

Relative Path Output

css/style.css?7ddf32e17a6ac5ce04a8ecbf782ca509

<link href="css/style.css?7ddf32e17a6ac5ce04a8ecbf782ca509" rel="stylesheet">

Absolute Path Output

/css/style.css?7ddf32e17a6ac5ce04a8ecbf782ca509

<link href="/css/style.css?7ddf32e17a6ac5ce04a8ecbf782ca509" rel="stylesheet">

Specifying A query String


<link href="<?= asset('css/style.css', 'v1') ?>" rel="stylesheet">

css/style.css?v1=7ddf32e17a6ac5ce04a8ecbf782ca509

<link href="css/style.css?v1=7ddf32e17a6ac5ce04a8ecbf782ca509" rel="stylesheet">


  Files folder image Files  
File Role Description
Files folder imageexample (1 file, 2 directories)
Files folder imagesrc (2 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file readme.md Doc. Documentation

  Files folder image Files  /  example  
File Role Description
Files folder imagecss (1 file)
Files folder imagejs (1 file)
  Accessible without login Plain text file index.php Example Example script

  Files folder image Files  /  example  /  css  
File Role Description
  Accessible without login Plain text file style.css Data Auxiliary data

  Files folder image Files  /  example  /  js  
File Role Description
  Accessible without login Plain text file script.js Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
Files folder imageasset (3 files)
Files folder imagefunctions (1 directory)

  Files folder image Files  /  src  /  asset  
File Role Description
  Plain text file Asset.php Class Class source
  Plain text file AssetStrategyContract.php Class Class source
  Plain text file StaticVersionStrategy.php Class Class source

  Files folder image Files  /  src  /  functions  
File Role Description
Files folder imageasset (1 file)

  Files folder image Files  /  src  /  functions  /  asset  
File Role Description
  Accessible without login Plain text file helpers.php Example Example script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:76
This week:0
All time:10,126
This week:177Up