/** * Constructor asset * * @access public * * @param IView $view * * @result void * @throws \Micro\Base\Exception */ public function __construct(IView $view) { $this->view = $view; if (!$this->sourcePath) { $this->sourcePath = dirname(Autoload::getClassPath(get_class($this))); } $this->hash = md5($this->sourcePath); $this->publishPath = '/' . (($dir = (new Injector())->param('assetsDirName')) ? $dir : 'assets') . '/' . $this->hash; $web = (new KernelInjector())->build()->getWebDir(); if (!file_exists($this->sourcePath)) { throw new Exception('Asset dir not exists: ' . $this->sourcePath); } if (!is_dir($web . $this->publishPath) && (!mkdir($web . $this->publishPath, 0777) && !is_dir($web . $this->publishPath))) { throw new Exception('Could not access to publish dir: ' . $this->publishPath); } FileHelper::recurseCopyIfEdited($this->sourcePath, $web . $this->publishPath, $this->excludes); }
/** * Constructor asset * * @access public * * @param IView $view * * @result void * @throws \Micro\base\Exception */ public function __construct(IView $view) { $this->view = $view; if (!$this->sourcePath) { $this->sourcePath = dirname(Autoload::getClassPath(get_class($this))); } $this->hash = md5($this->sourcePath); $this->publishPath = '/' . (($dir = $view->container->assetsDirName) ? $dir : 'assets') . '/' . $this->hash; $web = $this->view->container->kernel->getWebDir(); if (!file_exists($this->sourcePath)) { throw new Exception('Asset dir not exists: ' . $this->sourcePath); } if (!file_exists($web . $this->publishPath)) { mkdir($web . $this->publishPath, 0777); } FileHelper::recurseCopyIfEdited($this->sourcePath, $web . $this->publishPath, $this->excludes); }
/** * @inheritdoc */ public function clean() { FileHelper::removeDir($this->driver); }