/** * Check if given argument is acceptable as a Composite Views * * Check if given Object is acceptable in Composite Views Lists * To be valid, the Object must implement Next\View\View Interface * * @param Next\Components\Object $object * An Object object * * The checking for Next\View\View Interface * will be done inside the method. * * @return boolean * Always TRUE, because if given value is not a valid Composite View * an Exception will be thrown * * @throws Next\View\ViewException * Given argument is not acceptable as a Composite View */ public function accept(Object $object) { /** * @internal * Checking Object Type * * Partial Views must implement View Interface */ if (!$object instanceof View) { throw ViewException::invalidPartial($object); } return TRUE; }
/** * Find given Template View file in defined Views Directories * * @param string|optional $file * Template View File * * @return string * Template View Filepath * * @throws Next\View\ViewException * There are no directories assigned to iterate and search the file * * @throws Next\View\ViewException * No file could be found */ private function findFile($file = NULL) { // Do we have a Default Template? So let's use it! $file = !empty($this->_defaultTemplate) ? $this->_defaultTemplate : $file; // Cleaning dots and slashes around Template View Filename $file = trim($file, './'); // If still empty, let's check if FileSpec detection is enabled if (empty($file) && !$this->_useFileSpec) { throw ViewException::disabledFileSpec(); } // No paths to iterate? if (count($this->_paths) == 0 && is_null($this->_basepath)) { throw ViewException::noPaths($file); } // If we don't have a Template View Name, we will use the FileSpec ability $file = !empty($file) ? $file : $this->findFileBySpec(); // Adding File extension, if no one was defined yet if (strrpos($file, $added = sprintf('.%s', $this->_extension)) === FALSE) { $file .= $added; } // Do we have more than one View Path? /** * @internal * Test if this separation is REALLY necessary */ if (count($this->_paths) == 0) { // Building the Filename $templateFile = sprintf('%s/%s%s', $this->_basepath, $this->_subpath, $file); // And a cleaned version (without basepath) for possible Exceptions $file = sprintf('%s%s', $this->_subpath, $file); // Checking if the file exists and if it is readable if (file_exists($templateFile) && is_readable($templateFile)) { return $templateFile; } } else { foreach ($this->_paths as $path) { // Building the Filename $templateFile = sprintf('%s/%s/%s%s', $this->_basepath, $path, $this->_subpath, $file); // And a cleaned version (without basepath) for possible Exceptions $file = sprintf('%s/%s%s', $path, $this->_subpath, $file); // Checking if the file exists and if it is readable if (file_exists($templateFile) && is_readable($templateFile)) { return $templateFile; } } } // No file could be found, let's condition Exceptions' Messages if ($this->_useFileSpec) { if (!empty($this->_subpath)) { throw ViewException::wrongUseOfSubpath($file); } else { throw ViewException::unableToFindUnderFileSpec($file); } } else { throw ViewException::missingFile($file); } }
/** * Template Variable Removal Failure * * @param Next\View\ViewException $e * ViewException caught * * @return Next\Controller\ControllerException * Exception for Template Variable removal failure */ public static function removalFailure(ViewException $e) { return new self($e->getMessage(), self::TEMPLATE_VARIABLE_REMOVAL_FAILURE); }