/** * Generates link * * @return string * * @throws Exceptions\InvalidStateException */ public function getLink() { $hasArgs = func_num_args() > 0; if ($hasArgs) { // Backup files $backup = $this->files; // Clear files collection $this->clear(); // Get all arguments which could be files $args = func_get_args(); $args = reset($args); // Create new collection from arguments $newFiles = new Files\FilesCollection(); $newFiles->addFiles($args); // Create new files collection $this->setFiles($newFiles); } if (!$this->asset->getJoinFiles()) { throw new Exceptions\InvalidStateException("Can't generate link with disabled joinFiles."); } // Compile files collection $result = $this->compiler->generate($this->files->getFiles(), $this->contentType); $link = $this->getPresenter()->link(':IPub:AssetsLoader:assets', ['type' => 'js', 'id' => $result->hash, 'timestamp' => $result->lastModified]); if ($hasArgs) { $this->setFiles($backup); } return $link; }
/** * Generates and render link */ public function renderLink() { $hasArgs = func_num_args() > 0; if ($hasArgs) { // Backup files $backup = $this->files; // Clear files collection $this->clear(); // Get all arguments which could be files $args = func_get_args(); $args = reset($args); // Create new collection from arguments $newFiles = new Files\FilesCollection(); $newFiles->addFiles($args); // Create new files collection $this->setFiles($newFiles); } echo $this->getLink(); if ($hasArgs) { $this->setFiles($backup); } }