https://github.com/mathiasreker/php-script-cache
php-script-cache is a PHP library for caching external scripts locally.
https://github.com/mathiasreker/php-script-cache
Last synced: about 1 year ago
JSON representation
php-script-cache is a PHP library for caching external scripts locally.
- Host: GitHub
- URL: https://github.com/mathiasreker/php-script-cache
- Owner: MathiasReker
- License: mit
- Created: 2022-10-30T18:28:08.000Z (over 3 years ago)
- Default Branch: develop
- Last Pushed: 2024-11-11T08:36:52.000Z (over 1 year ago)
- Last Synced: 2025-04-06T11:24:40.591Z (about 1 year ago)
- Language: PHP
- Size: 30.3 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
PHP script cache
[](https://packagist.org/packages/MathiasReker/php-script-cache)
[](https://packagist.org/packages/MathiasReker/php-script-cache)
[](https://github.com/MathiasReker/php-script-cache/actions/workflows/ci.yml)
[](https://github.com/MathiasReker/php-script-cache/graphs/contributors)
[](https://github.com/MathiasReker/php-script-cache/network/members)
[](https://github.com/MathiasReker/php-script-cache/stargazers)
[](https://github.com/MathiasReker/php-script-cache/issues)
[](https://github.com/MathiasReker/php-script-cache/blob/develop/LICENSE.txt)
`php-script-cache` is a PHP library for caching external scripts locally.
> ✅ Cache
> ✅ Bundle
> ✅ Minify
### Versions & Dependencies
| Version | PHP | Documentation |
|---------|------|---------------|
| ^1.0 | ^7.4 | current |
### Requirements
- `PHP` >= 7.4
- php-extension `ext-json`
### Installation
Run:
```bash
composer require mathiasreker/php-script-cache
```
### Examples
Set up a cronjob to build the assets.
```php
setPath(__DIR__ . '/assets/js')
->doMinify()
->add([
'src' => [
'https://example1.com/script.js',
'https://example2.com/script.js'
], // multiple scripts will get bundled
])
->add([
'src' => ['https://example3.com/script.js'],
])
->build();
```
Place this code where you want to output the script tags. You can add attributes to the scripts.
```php
setPath(__DIR__ . '/assets/js')
->add([
'src' => [
'https://example1.com/script.js',
'https://example2.com/script.js'
],
])
->add([
'src' => ['https://example3.com/script.js'],
'id' => 'test',
'defer' => '',
])
->fetch();
// Result:
```
### Documentation
Instantiate the object.
```php
$result = new ScriptCache();
```
```php
$result->setPath(__DIR__ . '/assets/js');
```
`setPath` sets the path of the output folder for built files.
```php
$result->doMinify();
```
`doMinify` minifies the content.
```php
$result->add(['src' => ['https://example.com/script.js']]);
```
`add` sets the attributes of the script. The `src` can be an array of several scripts.
All the scripts in the collection will get bundled. You can use any attributes.
You do not need to set attributes when you build the cache.
```php
$result->build();
```
`build` builds the assets.
```php
$result->fetch();
```
`fetch` returns a string of the script tags.
### Roadmap
See the [open issues](https://github.com/MathiasReker/php-script-cache/issues) for a complete list of proposed
features (and known issues).
### Contributing
If you have a suggestion to improve this, please fork the repo and create a pull request. You can also open an issue
with the tag "enhancement". Finally, don't forget to give the project a star! Thanks again!
#### Docker
If you are using docker, you can use the following command to get started:
```bash
docker-compose up -d
```
Next, access the container:
```bash
docker exec -it php-script-cache bash
```
#### Tools
PHP Coding Standards Fixer:
```bash
composer cs-fix
```
PHP Coding Standards Checker:
```bash
composer cs-check
```
PHP Stan:
```bash
composer phpstan
```
Unit tests:
```bash
composer test
```
### License
It is distributed under the MIT License. See `LICENSE` for more information.