src/MvcCore/Ext/Views/Helpers/DataUrlHelper.php
public function DataUrl ($relativeOrAbsolutePath) {
		$currentDirFullPath = $this->view->GetCurrentViewDirectory();
		$searchedPaths = [];
		// first - try to find file relatively from currently rendered view
		array_unshift($searchedPaths, $currentDirFullPath . '/' . $relativeOrAbsolutePath);
		if (!file_exists($searchedPaths[0])) {
			// second - try to find file relatively from application root
			array_unshift($searchedPaths, $this->appRoot . '/' . ltrim($relativeOrAbsolutePath, '/'));
			if (!file_exists($searchedPaths[0])) {
				// third - try to find file absolutely
				array_unshift($searchedPaths, $relativeOrAbsolutePath);
				if (!file_exists($searchedPaths[0])) {
					// throw an error at last
					$selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__;
					throw new \InvalidArgumentException(
						"[".$selfClass."] File not found in paths: '" . implode("', '", array_reverse($searchedPaths)) . "'."
					);
				}
			}
		}
		// get last searched path
		$fileFullPath = $searchedPaths[0];
		// Read image path, convert to base64 encoding
		$imageData = base64_encode(file_get_contents($fileFullPath));
		// Format the image SRC:  data:{mime};base64,{data};
		$result = 'data: '.mime_content_type($fileFullPath).';base64,'.$imageData;
		return $result;
	}
public function DataUrl ($relativeOrAbsolutePath) {
		$currentDirFullPath = $this->view->GetCurrentViewDirectory();
		$searchedPaths = [];
		// first - try to find file relatively from currently rendered view
		array_unshift($searchedPaths, $currentDirFullPath . '/' . $relativeOrAbsolutePath);
		if (!file_exists($searchedPaths[0])) {
			// second - try to find file relatively from application root
			array_unshift($searchedPaths, $this->appRoot . '/' . ltrim($relativeOrAbsolutePath, '/'));
			if (!file_exists($searchedPaths[0])) {
				// third - try to find file absolutely
				array_unshift($searchedPaths, $relativeOrAbsolutePath);
				if (!file_exists($searchedPaths[0])) {
					// throw an error at last
					$selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__;
					throw new \InvalidArgumentException(
						"[".$selfClass."] File not found in paths: '" . implode("', '", array_reverse($searchedPaths)) . "'."
					);
				}
			}
		}
		// get last searched path
		$fileFullPath = $searchedPaths[0];
		// Read image path, convert to base64 encoding
		$imageData = base64_encode(file_get_contents($fileFullPath));
		// Format the image SRC:  data:{mime};base64,{data};
		$result = 'data: '.mime_content_type($fileFullPath).';base64,'.$imageData;
		return $result;
	}
public function DataUrl ( $ relativeOrAbsolutePath ) { $ currentDirFullPath = $ this -> view -> GetCurrentViewDirectory ( ) ; $ searchedPaths = [ ] ; // first - try to find file relatively from currently rendered view array_unshift ( $ searchedPaths , $ currentDirFullPath . '/' . $ relativeOrAbsolutePath ) ; if ( ! file_exists ( $ searchedPaths [ 0 ] ) ) { // second - try to find file relatively from application root array_unshift ( $ searchedPaths , $ this -> appRoot . '/' . ltrim ( $ relativeOrAbsolutePath , '/' ) ) ; if ( ! file_exists ( $ searchedPaths [ 0 ] ) ) { // third - try to find file absolutely array_unshift ( $ searchedPaths , $ relativeOrAbsolutePath ) ; if ( ! file_exists ( $ searchedPaths [ 0 ] ) ) { // throw an error at last $ selfClass = version_compare ( PHP_VERSION , '5.5' , '>' ) ? self :: class : __CLASS__ ; throw new \ InvalidArgumentException ( "[" . $ selfClass . "] File not found in paths: '" . implode ( "', '" , array_reverse ( $ searchedPaths ) ) . "'." ) ; } } } // get last searched path $ fileFullPath = $ searchedPaths [ 0 ] ; // Read image path, convert to base64 encoding $ imageData = base64_encode ( file_get_contents ( $ fileFullPath ) ) ; // Format the image SRC:  data:{mime};base64,{data}; $ result = 'data: ' . mime_content_type ( $ fileFullPath ) . ';base64,' . $ imageData ; return $ result ; }
Return any file content by given relative or absolute path in data url.
Path could be relative from currently rendered view,
relative from application root or absolute path to file.
@see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
@param string $relativeOrAbsolutePath
@throws \InvalidArgumentException If file not found by given path in any searched place.
@return string Data URL value like: `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgA...`
Return any file content by given relative or absolute path in data url . Path could be relative from currently rendered view relative from application root or absolute path to file .