php – assetic – 无法写资产

前端之家收集整理的这篇文章主要介绍了php – assetic – 无法写资产前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的目录结构(这只是一个测试项目):
stan@mypc:/generate_assets$sudo tree -L 3 -p
.
├── [drwxr-xr-x]  assets
│ └── [drwxr-xr-x]  css
│     ├── [-rw-r--r--]  test1.css
│     └── [-rw-r--r--]  test2.css
├── [-rw-r--r--]  composer.json
├── [-rw-r--r--]  composer.lock
├── [drwxrwxrwx]  public
├── [-rwxr-xr-x]  run
└── [drwxr-xr-x]  vendor
     ....skipping...

这是我的简单脚本(‘run’文件),它应该生成资产:

#!/usr/bin/env PHP

<?PHP
    //loading composer's autoload
    chdir(__DIR__);
    if (file_exists('vendor/autoload.PHP')) {
        include 'vendor/autoload.PHP';
    }

    use Assetic\Asset\AssetCollection;
    use Assetic\Factory\AssetFactory;
    use Assetic\Asset\FileAsset;
    use Assetic\Asset\GlobAsset;
    use Assetic\Filter\LessFilter;
    use Assetic\Filter\CssMinFilter;
    use Assetic\AssetWriter;
    use Assetic\AssetManager;

    //Asset manager
    $am = new AssetManager();

    //Add all css files
    $css = new GlobAsset('assets/css/*.css',array(new CssMinFilter()));
    $am->set('basecss',$css);

    // Dumping assets into public
    $writer = new AssetWriter('public');
    $writer->writeManagerAssets($am);

所以 – 我预计来自资产/ css的css文件将被组合,被细分并转储到名为“basecss.css”的公共目录中.这是我得到的例外:

PHP Fatal error:  Uncaught exception 'RuntimeException' with message 'Unable to write file public/' in /generate_assets/vendor/kriswallsmith/assetic/src/Assetic/AssetWriter.PHP:106
Stack trace:
#0 /generate_assets/vendor/kriswallsmith/assetic/src/Assetic/AssetWriter.PHP(65): Assetic\AssetWriter::write('public/','*{color:green}?...')
#1 /generate_assets/vendor/kriswallsmith/assetic/src/Assetic/AssetWriter.PHP(54): Assetic\AssetWriter->writeAsset(Object(Assetic\Asset\GlobAsset))
#2 /generate_assets/run(31): Assetic\AssetWriter->writeManagerAssets(Object(Assetic\AssetManager))
#3 {main}
  thrown in /generate_assets/vendor/kriswallsmith/assetic/src/Assetic/AssetWriter.PHP on line 106

所以 – 似乎assetic试图转储名为’public’而不是’public / basecss.css’的文件?任何帮助?

附:解析度:

好.洙.显然我必须跑

$css->setTargetPath('css_file_name.css');

然后它工作…

从文档中不完全清楚,但在 Dumping Assets to static files部分中提到
$writer->writeManagerAssets($am);

“将利用资产的目标路径”.所以是的,你建议在编写资产之前设置目标路径可以解决问题:

$css->setTargetPath('css_file_name.css');
原文链接:https://www.f2er.com/php/132502.html

猜你在找的PHP相关文章