我通过将整个导演放在./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
在应用程序模块中使用类映射./module/Application/Module.php
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());
}