gpt4 book ai didi

namespaces - 如何将 LESS 集成到 ZendFramework 2

转载 作者:行者123 更新时间:2023-12-02 02:03:40 25 4
gpt4 key购买 nike

我找到了 this tutorial适用于 ZendFramework 1。我下载的比较少,放在project/vendor/下。

Leafo
└── Less
├── Lessc.php
└── Lessify.php

project/module/Application/Module.php

...
public function onBootstrap(MvcEvent $e)
{
...
$this->compileLess();
}
...
public function compileLess()
{
if (APPLICATION_ENV == 'production') {
return;
}
require_once PROJECT_PATH . '/vendor/Leafo/Less/Lessc.php';

$less_file = PROJECT_PATH . '/public/less/style.less';
$css_file = PROJECT_PATH . '/public/css/style.css';

$lessc = new \Leafo\Less\Lessc($less_file);
file_put_contents($css_file, $lessc->parse());
}

不幸的是,我得到以下错误

Fatal error: Class 'Leafo\Less\Lessc' not found in /Users/jslim/public_html/littlepinktree/module/Application/Module.php on line 53

我有几个问题:

  1. 如何将第 3 方库集成到 ZF2(如果第 3 方库未使用命名空间)?
  2. 是否有任何示例显示如何集成 LESS到 ZF2?

最佳答案

我通过将整个导演放在 ./module/Application/src/Less 中解决了这个问题

注意:我用回原来的结构如下

src
├── Application
│   └── Controller
│   └── IndexController.php
└── Less
├── LICENSE
├── Makefile
├── README.md
├── composer.json
├── docs
│   └── docs.md
├── lessc.inc.php
├── lessify
├── lessify.inc.php
├── package.sh
├── plessc
└── tests
├── ApiTest.php
├── InputTest.php
├── README.md
├── bootstrap.sh
├── inputs
├── outputs
└── sort.php

在Application模块./module/Application/Module.php中使用class map

public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}

然后生成autoload_classmap.php

<?php
// Generated by ZF2's ./bin/classmap_generator.php
return array(
'Application\Module' => __DIR__ . '/Module.php',
'Application\Controller\IndexController' => __DIR__ . '/src/Application/Controller/IndexController.php',
'lessc' => __DIR__ . '/src/Less/lessc.inc.php',
'lessc_parser' => __DIR__ . '/src/Less/lessc.inc.php',
'lessc_formatter_classic' => __DIR__ . '/src/Less/lessc.inc.php',
'lessc_formatter_compressed' => __DIR__ . '/src/Less/lessc.inc.php',
'lessc_formatter_lessjs' => __DIR__ . '/src/Less/lessc.inc.php',
'easyparse' => __DIR__ . '/src/Less/lessify.inc.php',
'tagparse' => __DIR__ . '/src/Less/lessify.inc.php',
'nodecounter' => __DIR__ . '/src/Less/lessify.inc.php',
'lessify' => __DIR__ . '/src/Less/lessify.inc.php',
'ApiTest' => __DIR__ . '/src/Less/tests/ApiTest.php',
'InputTest' => __DIR__ . '/src/Less/tests/InputTest.php',
'lesscNormalized' => __DIR__ . '/src/Less/tests/sort.php',
'SortingFormatter' => __DIR__ . '/src/Less/tests/sort.php',
);

终于可以用了

public function compileLess()
{
if (APPLICATION_ENV == 'production') {
return;
}
$less_file = PROJECT_PATH . '/public/less/style.less';
$css_file = PROJECT_PATH . '/public/css/style.css';

$lessc = new \lessc($less_file);
file_put_contents($css_file, $lessc->parse());
}

关于namespaces - 如何将 LESS 集成到 ZendFramework 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16013935/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com