Recommend this page to a friend! |
Download |
Info | Documentation | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not enough user ratings | Total: 144 | All time: 9,155 This week: 206 |
Version | License | PHP version | Categories | |||
php-asset 1.1.7 | MIT/X Consortium ... | 5.6 | HTML, PHP 5 |
Description | Author | |
This class can generate HTML to include JavaScript and CSS files. |
PHP library for handling styles and scripts; Add, minify, unify and print.
This library is supported by PHP versions 5.6 or higher and is compatible with HHVM versions 3.0 or higher.
The preferred way to install this extension is through Composer.
To install PHP Asset library, simply:
$ composer require Josantonius/Asset
The previous command will only install the necessary files, if you prefer to download the entire source code you can use:
$ composer require Josantonius/Asset --prefer-source
You can also clone the complete repository with Git:
$ git clone https://github.com/Josantonius/PHP-Asset.git
Or install it manually:
$ wget https://raw.githubusercontent.com/Josantonius/PHP-Asset/master/src/Asset.php
$ wget https://raw.githubusercontent.com/Josantonius/PHP-Json/master/src/Json.php
Available methods in this library:
Asset::add($type, $data);
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $type | 'script' or 'style' | string | Yes | |
| Attribute | key | Description | Type | Required | Default | --- | --- | --- | --- | --- | --- | | $data | | Settings | array | Yes | | | | name | Unique ID | string | Yes | | | | url | Url to file | string | Yes | | | | version | Version | string | No | false | | | footer | Only for scripts - Attach in footer | boolean | No | true | | | attr | Only for scripts - Attribute (defer/sync) | string | No | |
# Return (boolean)
Asset::isAdded($type, $name);
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $type | 'script' or 'style' | string | Yes | | | $name | Unique ID | string | Yes | |
# Return (boolean)
Asset::remove($type, $name);
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $type | 'script' or 'style' | string | Yes | | | $name | Unique ID | string | Yes | |
# Return (boolean true)
Asset::unify($uniqueID, $params, $minify);
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $uniqueID | Unique identifier for unified file | string | Yes | | | $params | Path urls | mixed | Yes | | | $minify | Minimize file content | boolean | No | false |
# Return (boolean true)
Asset::outputStyles($output);
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $output | Output for styles | string | No | '' |
# Return (string|false) ? Output or false
Asset::outputScripts($place, $output);
| Attribute | Description | Type | Required | Default | --- | --- | --- | --- | --- | | $place | 'header' or 'footer' | string | Yes | | | $output | Output for scripts | string | No | '' |
# Return (string|false) ? Output or false
To use this class with Composer:
require __DIR__ . '/vendor/autoload.php';
use Josantonius\Asset\Asset;
Or If you installed it manually, use it:
require_once __DIR__ . '/Asset.php';
require_once __DIR__ . '/Json.php';
use Josantonius\Asset\Asset;
Example of use for this library:
Asset::add('style', [
'name' => 'style-first',
'url' => 'http://josantonius.com/css/style.css',
]);
Asset::add('style', [
'name' => 'style-second',
'url' => 'http://josantonius.com/css/custom.css',
'version' => '1.1.1'
]);
Asset::add('script', [
'name' => 'script-first',
'url' => 'http://josantonius.com/js/script.js',
]);
Asset::add('script', [
'name' => 'script-second',
'url' => 'http://josantonius.com/js/custom.js',
'attr' => 'defer',
'version' => '1.1.3',
'footer' => false
]);
Asset::isAdded('script', 'script-first'); // true
Asset::isAdded('style', 'style-first'); // true
Asset::remove('style', 'style-first') // true
Asset::remove('script', 'script-first'); // true
Asset::unify('UniqueID', 'http://josantonius.com/min/');
Asset::unify('UniqueID', 'http://josantonius.com/min/', true);
Asset::unify('UniqueID', [
'styles' => 'http://josantonius.com/min/css/',
'scripts' => 'http://josantonius.com/min/js/'
]);
Asset::unify('UniqueID', [
'styles' => 'http://josantonius.com/min/css/',
'scripts' => 'http://josantonius.com/min/js/'
], true);
echo Asset::outputStyles();
echo Asset::outputScripts('footer');
echo Asset::outputScripts('header');
To run tests you just need composer and to execute the following:
$ git clone https://github.com/Josantonius/PHP-Asset.git
$ cd PHP-Asset
$ composer install
Run unit tests with PHPUnit:
$ composer phpunit
Run PSR2 code standard tests with PHPCS:
$ composer phpcs
Run PHP Mess Detector tests to detect inconsistencies in code style:
$ composer phpmd
Run all previous tests:
$ composer tests
If you would like to help, please take a look at the list of issues or the To Do checklist.
Pull requests
The file structure from this repository was created with PHP-Skeleton.
This project is licensed under MIT license. See the LICENSE file for more info.
2016 - 2018 Josantonius, josantonius.com
If you find it useful, let me know :wink:
Files (20) |
File | Role | Description | ||
---|---|---|---|---|
src (1 file) | ||||
tests (3 files, 1 directory) | ||||
.editorconfig | Data | Auxiliary data | ||
.php_cs.dist | Example | Example script | ||
.travis.yml | Data | Auxiliary data | ||
CHANGELOG.md | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
CONDUCT.md | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
phpcs.xml | Data | Auxiliary data | ||
phpmd.xml | Data | Auxiliary data | ||
phpunit.xml | Data | Auxiliary data | ||
README-ES.md | Doc. | Documentation | ||
README.md | Doc. | Documentation |
Files (20) | / | tests |
File | Role | Description | ||
---|---|---|---|---|
assets (2 directories) | ||||
ScriptsTest.php | Class | Class source | ||
StylesTest.php | Class | Class source | ||
UnifyFilesTest.php | Class | Class source |
Files (20) | / | tests | / | assets | / | css |
File | Role | Description |
---|---|---|
custom.css | Data | Auxiliary data |
style.css | Data | Auxiliary data |
Files (20) | / | tests | / | assets | / | js |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.