{"id":15029254,"url":"https://github.com/assetic-php/assetic","last_synced_at":"2025-05-15T13:04:18.585Z","repository":{"id":38715690,"uuid":"201322508","full_name":"assetic-php/assetic","owner":"assetic-php","description":"Asset Management for PHP","archived":false,"fork":false,"pushed_at":"2025-02-01T05:23:33.000Z","size":2096,"stargazers_count":98,"open_issues_count":6,"forks_count":21,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-07T16:11:45.348Z","etag":null,"topics":["assetic","assets","assets-management","hacktoberfest","php","php-library","php7"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"kriswallsmith/assetic","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/assetic-php.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-08T19:17:26.000Z","updated_at":"2025-02-06T18:05:07.000Z","dependencies_parsed_at":"2024-12-07T01:04:47.749Z","dependency_job_id":"78370f28-ed08-4976-b72d-c95a5084141a","html_url":"https://github.com/assetic-php/assetic","commit_stats":{"total_commits":1098,"total_committers":154,"mean_commits":7.12987012987013,"dds":0.4972677595628415,"last_synced_commit":"3ac665d4b4ffb8f54e26c3f8f6cef30fa894b76b"},"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/assetic-php%2Fassetic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/assetic-php%2Fassetic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/assetic-php%2Fassetic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/assetic-php%2Fassetic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/assetic-php","download_url":"https://codeload.github.com/assetic-php/assetic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248961186,"owners_count":21189991,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["assetic","assets","assets-management","hacktoberfest","php","php-library","php7"],"created_at":"2024-09-24T20:10:08.066Z","updated_at":"2025-04-14T20:56:56.520Z","avatar_url":"https://github.com/assetic-php.png","language":"PHP","readme":"# Assetic\n[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/assetic-php/assetic.svg)](http://isitmaintained.com/project/assetic-php/assetic \"Average time to resolve an issue\")\n[![Percentage of issues still open](https://isitmaintained.com/badge/open/assetic-php/assetic.svg)](https://isitmaintained.com/project/assetic-php/assetic \"Percentage of issues still open\")\n\nAssetic is an asset management framework for PHP maintained by the [Winter CMS team](https://github.com/wintercms).\n\n``` php\n\u003c?php\n\nuse Assetic\\Asset\\AssetCollection;\nuse Assetic\\Asset\\FileAsset;\nuse Assetic\\Asset\\GlobAsset;\n\n$js = new AssetCollection(array(\n    new GlobAsset('/path/to/js/*'),\n    new FileAsset('/path/to/another.js'),\n));\n\n// the code is merged when the asset is dumped\necho $js-\u003edump();\n```\n\nAssets\n------\n\nAn Assetic asset is something with filterable content that can be loaded and\ndumped. An asset also includes metadata, some of which can be manipulated and\nsome of which is immutable.\n\n| **Property** | **Accessor**    | **Mutator**   |\n|--------------|-----------------|---------------|\n| content      | getContent      | setContent    |\n| mtime        | getLastModified | n/a           |\n| source root  | getSourceRoot   | n/a           |\n| source path  | getSourcePath   | n/a           |\n| target path  | getTargetPath   | setTargetPath |\n\nThe \"target path\" property denotes where an asset (or an collection of assets) should be dumped.\n\nFilters\n-------\n\nFilters can be applied to manipulate assets.\n\n``` php\n\u003c?php\n\nuse Assetic\\Asset\\AssetCollection;\nuse Assetic\\Asset\\FileAsset;\nuse Assetic\\Asset\\GlobAsset;\nuse Assetic\\Filter\\LessFilter;\nuse Assetic\\Filter\\UglifyCssFilter;\n\n$css = new AssetCollection(array(\n    new FileAsset('/path/to/src/styles.less', array(new LessFilter())),\n    new GlobAsset('/path/to/css/*'),\n), array(\n    new UglifyCssFilter('/path/to/uglifycss'),\n));\n\n// this will echo CSS compiled by LESS and compressed by uglifycss\necho $css-\u003edump();\n```\n\nThe filters applied to the collection will cascade to each asset leaf if you\niterate over it.\n\n``` php\n\u003c?php\n\nforeach ($css as $leaf) {\n    // each leaf is compressed by uglifycss\n    echo $leaf-\u003edump();\n}\n```\n\nThe core provides the following filters in the `Assetic\\Filter` namespace:\n\n * `CoffeeScriptFilter`: compiles CoffeeScript into Javascript\n * `CssImportFilter`: inlines imported stylesheets\n * `CSSMinFilter`: minifies CSS\n * `CssRewriteFilter`: fixes relative URLs in CSS assets when moving to a new URL\n * `GoogleClosure\\CompilerApiFilter`: compiles Javascript using the Google Closure Compiler API\n * `HandlebarsFilter`: compiles Handlebars templates into Javascript\n * `JavaScriptMinifierFilter`: minifies Javascript\n * `JpegoptimFilter`: optimize your JPEGs\n * `JpegtranFilter`: optimize your JPEGs\n * `LessFilter`: parses LESS into CSS (using less.js with node.js)\n * `LessphpFilter`: parses LESS into CSS (using lessphp)\n * `OptiPngFilter`: optimize your PNGs\n * `PackerFilter`: compresses Javascript using Dean Edwards's Packer\n * `PhpCssEmbedFilter`: embeds image data in your stylesheet\n * `ReactJsxFilter`: compiles React JSX into JavaScript\n * `ScssphpFilter`: parses SCSS into CSS\n * `SeparatorFilter`: inserts a separator between assets to prevent merge failures\n * `StylesheetMinifyFilter`: compresses stylesheet CSS files\n * `StylusFilter`: parses STYL into CSS\n * `TailwindCssFilter`: builds a Tailwind CSS stylesheet using the Tailwind CSS standalone CLI utility\n * `TypeScriptFilter`: parses TypeScript into Javascript\n * `UglifyCssFilter`: minifies CSS\n * `UglifyJs2Filter`: minifies Javascript\n * `UglifyJs3Filter`: minifies Javascript\n\nAsset Manager\n-------------\n\nAn asset manager is provided for organizing assets.\n\n``` php\n\u003c?php\n\nuse Assetic\\AssetManager;\nuse Assetic\\Asset\\FileAsset;\nuse Assetic\\Asset\\GlobAsset;\n\n$am = new AssetManager();\n$am-\u003eset('jquery', new FileAsset('/path/to/jquery.js'));\n$am-\u003eset('base_css', new GlobAsset('/path/to/css/*'));\n```\n\nThe asset manager can also be used to reference assets to avoid duplication.\n\n``` php\n\u003c?php\n\nuse Assetic\\Asset\\AssetCollection;\nuse Assetic\\Asset\\AssetReference;\nuse Assetic\\Asset\\FileAsset;\n\n$am-\u003eset('my_plugin', new AssetCollection(array(\n    new AssetReference($am, 'jquery'),\n    new FileAsset('/path/to/jquery.plugin.js'),\n)));\n```\n\nFilter Manager\n--------------\n\nA filter manager is also provided for organizing filters.\n\n``` php\n\u003c?php\n\nuse Assetic\\FilterManager;\nuse Assetic\\Filter\\ScssFilter;\nuse Assetic\\Filter\\CssMinFilter;\n\n$fm = new FilterManager();\n$fm-\u003eset('sass', new ScssFilter('/path/to/parser/scss'));\n$fm-\u003eset('cssmin', new CssMinFilter());\n```\n\nAsset Factory\n-------------\n\nIf you'd rather not create all these objects by hand, you can use the asset\nfactory, which will do most of the work for you.\n\n``` php\n\u003c?php\n\nuse Assetic\\Factory\\AssetFactory;\n\n$factory = new AssetFactory('/path/to/asset/directory/');\n$factory-\u003esetAssetManager($am);\n$factory-\u003esetFilterManager($fm);\n$factory-\u003esetDebug(true);\n\n$css = $factory-\u003ecreateAsset(array(\n    '@reset',         // load the asset manager's \"reset\" asset\n    'css/src/*.scss', // load every scss files from \"/path/to/asset/directory/css/src/\"\n), array(\n    'scss',           // filter through the filter manager's \"scss\" filter\n    '?cssmin',        // don't use this filter in debug mode\n));\n\necho $css-\u003edump();\n```\n\nThe `AssetFactory` is constructed with a root directory which is used as the base directory for relative asset paths.\n\nPrefixing a filter name with a question mark, as `cssmin` is here, will cause\nthat filter to be omitted when the factory is in debug mode.\n\nYou can also register [Workers](src/Assetic/Contracts/Factory/Worker/WorkerInterface.php) on the factory and all assets created\nby it will be passed to the worker's `process()` method before being returned. See _Cache Busting_ below for an example.\n\nDumping Assets to static files\n------------------------------\n\nYou can dump all the assets an AssetManager holds to files in a directory. This will probably be below your webserver's document root\nso the files can be served statically.\n\n``` php\n\u003c?php\n\nuse Assetic\\AssetWriter;\n\n$writer = new AssetWriter('/path/to/web');\n$writer-\u003ewriteManagerAssets($am);\n```\n\nThis will make use of the assets' target path.\n\nCache Busting\n-------------\n\nIf you serve your assets from static files as just described, you can use the CacheBustingWorker to rewrite the target\npaths for assets. It will insert an identifier before the filename extension that is unique for a particular version\nof the asset.\n\nThis identifier is based on the modification time of the asset and will also take depended-on assets into\nconsideration if the applied filters support it.\n\n``` php\n\u003c?php\n\nuse Assetic\\Factory\\AssetFactory;\nuse Assetic\\Factory\\Worker\\CacheBustingWorker;\n\n$factory = new AssetFactory('/path/to/asset/directory/');\n$factory-\u003esetAssetManager($am);\n$factory-\u003esetFilterManager($fm);\n$factory-\u003esetDebug(true);\n$factory-\u003eaddWorker(new CacheBustingWorker());\n\n$css = $factory-\u003ecreateAsset(array(\n    '@reset',         // load the asset manager's \"reset\" asset\n    'css/src/*.scss', // load every scss files from \"/path/to/asset/directory/css/src/\"\n), array(\n    'scss',           // filter through the filter manager's \"scss\" filter\n    '?yui_css',       // don't use this filter in debug mode\n));\n\necho $css-\u003edump();\n```\n\nInternal caching\n-------\n\nA simple caching mechanism is provided to avoid unnecessary work.\n\n``` php\n\u003c?php\n\nuse Assetic\\Asset\\AssetCache;\nuse Assetic\\Asset\\FileAsset;\nuse Assetic\\Cache\\FilesystemCache;\nuse Assetic\\Filter\\JavaScriptMinifierFilter;\n\n$jsMinifier = new JavaScriptMinifierFilter();\n$js = new AssetCache(\n    new FileAsset('/path/to/some.js', array($jsMinifier)),\n    new FilesystemCache('/path/to/cache')\n);\n\n// the JavaScriptMinifierFilter compressor will only run on the first call\n$js-\u003edump();\n$js-\u003edump();\n$js-\u003edump();\n```\n\nTwig\n----\n\nTo use the Assetic [Twig][3] extension you must register it to your Twig\nenvironment:\n\n``` php\n\u003c?php\n\n$twig-\u003eaddExtension(new AsseticExtension($factory));\n```\n\nOnce in place, the extension exposes a stylesheets and a javascripts tag with a syntax similar\nto what the asset factory uses:\n\n``` html+jinja\n{% stylesheets '/path/to/sass/main.sass' filter='sass,?yui_css' output='css/all.css' %}\n    \u003clink href=\"{{ asset_url }}\" type=\"text/css\" rel=\"stylesheet\" /\u003e\n{% endstylesheets %}\n```\n\nThis example will render one `link` element on the page that includes a URL\nwhere the filtered asset can be found.\n\nWhen the extension is in debug mode, this same tag will render multiple `link`\nelements, one for each asset referenced by the `css/src/*.sass` glob. The\nspecified filters will still be applied, unless they are marked as optional\nusing the `?` prefix.\n\nThis behavior can also be triggered by setting a `debug` attribute on the tag:\n\n``` html+jinja\n{% stylesheets 'css/*' debug=true %} ... {% stylesheets %}\n```\n\nThese assets need to be written to the web directory so these URLs don't\nreturn 404 errors.\n\n``` php\n\u003c?php\n\nuse Assetic\\AssetWriter;\nuse Assetic\\Extension\\Twig\\TwigFormulaLoader;\nuse Assetic\\Extension\\Twig\\TwigResource;\nuse Assetic\\Factory\\LazyAssetManager;\n\n$am = new LazyAssetManager($factory);\n\n// enable loading assets from twig templates\n$am-\u003esetLoader('twig', new TwigFormulaLoader($twig));\n\n// loop through all your templates\nforeach ($templates as $template) {\n    $resource = new TwigResource($twigLoader, $template);\n    $am-\u003eaddResource($resource, 'twig');\n}\n\n$writer = new AssetWriter('/path/to/web');\n$writer-\u003ewriteManagerAssets($am);\n```\n\n---\n\nAssetic is based on the Python [webassets][1] library (available on\n[GitHub][2]).\n\n[1]: http://elsdoerfer.name/docs/webassets\n[2]: https://github.com/miracle2k/webassets\n[3]: http://twig.sensiolabs.org\n","funding_links":[],"categories":["PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fassetic-php%2Fassetic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fassetic-php%2Fassetic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fassetic-php%2Fassetic/lists"}