| @@ -22,17 +22,17 @@ | ||
| 22 | 22 | class BaseView extends AbstractView | 
| 23 | 23 |  { | 
| 24 | 24 | |
| 25 | - /** | |
| 26 | - * Check whether the Findable can handle an individual criterion. | |
| 27 | - * | |
| 28 | - * @since 0.1.0 | |
| 29 | - * | |
| 30 | - * @param mixed $criterion Criterion to check. | |
| 31 | - * | |
| 32 | - * @return bool Whether the Findable can handle the criterion. | |
| 33 | - */ | |
| 34 | - public function canHandle($criterion) | |
| 35 | -    { | |
| 36 | - return true; | |
| 37 | - } | |
| 25 | + /** | |
| 26 | + * Check whether the Findable can handle an individual criterion. | |
| 27 | + * | |
| 28 | + * @since 0.1.0 | |
| 29 | + * | |
| 30 | + * @param mixed $criterion Criterion to check. | |
| 31 | + * | |
| 32 | + * @return bool Whether the Findable can handle the criterion. | |
| 33 | + */ | |
| 34 | + public function canHandle($criterion) | |
| 35 | +	{ | |
| 36 | + return true; | |
| 37 | + } | |
| 38 | 38 | } | 
| @@ -22,14 +22,14 @@ | ||
| 22 | 22 | interface Findable | 
| 23 | 23 |  { | 
| 24 | 24 | |
| 25 | - /** | |
| 26 | - * Check whether the Findable can handle an individual criterion. | |
| 27 | - * | |
| 28 | - * @since 0.1.0 | |
| 29 | - * | |
| 30 | - * @param mixed $criterion Criterion to check. | |
| 31 | - * | |
| 32 | - * @return bool Whether the Findable can handle the criterion. | |
| 33 | - */ | |
| 34 | - public function canHandle($criterion); | |
| 25 | + /** | |
| 26 | + * Check whether the Findable can handle an individual criterion. | |
| 27 | + * | |
| 28 | + * @since 0.1.0 | |
| 29 | + * | |
| 30 | + * @param mixed $criterion Criterion to check. | |
| 31 | + * | |
| 32 | + * @return bool Whether the Findable can handle the criterion. | |
| 33 | + */ | |
| 34 | + public function canHandle($criterion); | |
| 35 | 35 | } | 
| @@ -22,38 +22,38 @@ | ||
| 22 | 22 | class URIHelper | 
| 23 | 23 |  { | 
| 24 | 24 | |
| 25 | - /** | |
| 26 | - * Check whether a given URI has a specific extension. | |
| 27 | - * | |
| 28 | - * @since 0.1.3 | |
| 29 | - * | |
| 30 | - * @param string $uri URI to check the extension of. | |
| 31 | - * @param string $extension Extension to check for. | |
| 32 | - * | |
| 33 | - * @return bool | |
| 34 | - */ | |
| 35 | - public static function hasExtension($uri, $extension) | |
| 36 | -    { | |
| 37 | - $uriLength = mb_strlen($uri); | |
| 38 | - $extensionLength = mb_strlen($extension); | |
| 39 | -        if ($extensionLength > $uriLength) { | |
| 40 | - return false; | |
| 41 | - } | |
| 25 | + /** | |
| 26 | + * Check whether a given URI has a specific extension. | |
| 27 | + * | |
| 28 | + * @since 0.1.3 | |
| 29 | + * | |
| 30 | + * @param string $uri URI to check the extension of. | |
| 31 | + * @param string $extension Extension to check for. | |
| 32 | + * | |
| 33 | + * @return bool | |
| 34 | + */ | |
| 35 | + public static function hasExtension($uri, $extension) | |
| 36 | +	{ | |
| 37 | + $uriLength = mb_strlen($uri); | |
| 38 | + $extensionLength = mb_strlen($extension); | |
| 39 | +		if ($extensionLength > $uriLength) { | |
| 40 | + return false; | |
| 41 | + } | |
| 42 | 42 | |
| 43 | - return substr_compare($uri, $extension, $uriLength - $extensionLength, $extensionLength) === 0; | |
| 44 | - } | |
| 43 | + return substr_compare($uri, $extension, $uriLength - $extensionLength, $extensionLength) === 0; | |
| 44 | + } | |
| 45 | 45 | |
| 46 | - /** | |
| 47 | - * Get the filename for an URI. | |
| 48 | - * | |
| 49 | - * @since 0.1.3 | |
| 50 | - * | |
| 51 | - * @param string $uri URI to get the filename from. | |
| 52 | - * | |
| 53 | - * @return string Filename without path. | |
| 54 | - */ | |
| 55 | - public static function getFilename($uri) | |
| 56 | -    { | |
| 57 | - return basename($uri); | |
| 58 | - } | |
| 46 | + /** | |
| 47 | + * Get the filename for an URI. | |
| 48 | + * | |
| 49 | + * @since 0.1.3 | |
| 50 | + * | |
| 51 | + * @param string $uri URI to get the filename from. | |
| 52 | + * | |
| 53 | + * @return string Filename without path. | |
| 54 | + */ | |
| 55 | + public static function getFilename($uri) | |
| 56 | +	{ | |
| 57 | + return basename($uri); | |
| 58 | + } | |
| 59 | 59 | } | 
| @@ -24,15 +24,15 @@ | ||
| 24 | 24 | interface Engine extends Findable | 
| 25 | 25 |  { | 
| 26 | 26 | |
| 27 | - /** | |
| 28 | - * Get the rendering callback for a given URI. | |
| 29 | - * | |
| 30 | - * @since 0.1.0 | |
| 31 | - * | |
| 32 | - * @param string $uri URI to render. | |
| 33 | - * @param array $context Context in which to render. | |
| 34 | - * | |
| 35 | - * @return string Rendered HTML. | |
| 36 | - */ | |
| 37 | - public function getRenderCallback($uri, array $context = []); | |
| 27 | + /** | |
| 28 | + * Get the rendering callback for a given URI. | |
| 29 | + * | |
| 30 | + * @since 0.1.0 | |
| 31 | + * | |
| 32 | + * @param string $uri URI to render. | |
| 33 | + * @param array $context Context in which to render. | |
| 34 | + * | |
| 35 | + * @return string Rendered HTML. | |
| 36 | + */ | |
| 37 | + public function getRenderCallback($uri, array $context = []); | |
| 38 | 38 | } | 
| @@ -24,39 +24,39 @@ | ||
| 24 | 24 | class BaseEngineFinder extends AbstractFinder | 
| 25 | 25 |  { | 
| 26 | 26 | |
| 27 | - /** | |
| 28 | - * Find a result based on a specific criteria. | |
| 29 | - * | |
| 30 | - * @since 0.1.0 | |
| 31 | - * | |
| 32 | - * @param array $criteria Criteria to search for. | |
| 33 | - * | |
| 34 | - * @return Engine Result of the search. | |
| 35 | - */ | |
| 36 | - public function find(array $criteria) | |
| 37 | -    { | |
| 38 | - $this->initializeFindables(); | |
| 27 | + /** | |
| 28 | + * Find a result based on a specific criteria. | |
| 29 | + * | |
| 30 | + * @since 0.1.0 | |
| 31 | + * | |
| 32 | + * @param array $criteria Criteria to search for. | |
| 33 | + * | |
| 34 | + * @return Engine Result of the search. | |
| 35 | + */ | |
| 36 | + public function find(array $criteria) | |
| 37 | +	{ | |
| 38 | + $this->initializeFindables(); | |
| 39 | 39 | |
| 40 | -        foreach ($criteria as $entry) { | |
| 41 | -            foreach ($this->findables as $engine) { | |
| 42 | -                if ($engine->canHandle($entry)) { | |
| 43 | - return $engine; | |
| 44 | - } | |
| 45 | - } | |
| 46 | - } | |
| 40 | +		foreach ($criteria as $entry) { | |
| 41 | +			foreach ($this->findables as $engine) { | |
| 42 | +				if ($engine->canHandle($entry)) { | |
| 43 | + return $engine; | |
| 44 | + } | |
| 45 | + } | |
| 46 | + } | |
| 47 | 47 | |
| 48 | - return $this->getNullObject(); | |
| 49 | - } | |
| 48 | + return $this->getNullObject(); | |
| 49 | + } | |
| 50 | 50 | |
| 51 | - /** | |
| 52 | - * Get the config key for the Findables definitions. | |
| 53 | - * | |
| 54 | - * @since 0.1.0 | |
| 55 | - * | |
| 56 | - * @return string Config key use to define the Findables. | |
| 57 | - */ | |
| 58 | - protected function getFindablesConfigKey() | |
| 59 | -    { | |
| 60 | - return 'Engines'; | |
| 61 | - } | |
| 51 | + /** | |
| 52 | + * Get the config key for the Findables definitions. | |
| 53 | + * | |
| 54 | + * @since 0.1.0 | |
| 55 | + * | |
| 56 | + * @return string Config key use to define the Findables. | |
| 57 | + */ | |
| 58 | + protected function getFindablesConfigKey() | |
| 59 | +	{ | |
| 60 | + return 'Engines'; | |
| 61 | + } | |
| 62 | 62 | } | 
| @@ -26,76 +26,76 @@ | ||
| 26 | 26 | class PHPEngine extends AbstractEngine | 
| 27 | 27 |  { | 
| 28 | 28 | |
| 29 | - const PHP_EXTENSION = '.php'; | |
| 29 | + const PHP_EXTENSION = '.php'; | |
| 30 | 30 | |
| 31 | - /** | |
| 32 | - * Check whether the Findable can handle an individual criterion. | |
| 33 | - * | |
| 34 | - * @since 0.1.0 | |
| 35 | - * | |
| 36 | - * @param mixed $criterion Criterion to check. | |
| 37 | - * | |
| 38 | - * @return bool Whether the Findable can handle the criterion. | |
| 39 | - */ | |
| 40 | - public function canHandle($criterion) | |
| 41 | -    { | |
| 42 | - return URIHelper::hasExtension($criterion, static::PHP_EXTENSION) | |
| 43 | - && is_readable($criterion); | |
| 44 | - } | |
| 31 | + /** | |
| 32 | + * Check whether the Findable can handle an individual criterion. | |
| 33 | + * | |
| 34 | + * @since 0.1.0 | |
| 35 | + * | |
| 36 | + * @param mixed $criterion Criterion to check. | |
| 37 | + * | |
| 38 | + * @return bool Whether the Findable can handle the criterion. | |
| 39 | + */ | |
| 40 | + public function canHandle($criterion) | |
| 41 | +	{ | |
| 42 | + return URIHelper::hasExtension($criterion, static::PHP_EXTENSION) | |
| 43 | + && is_readable($criterion); | |
| 44 | + } | |
| 45 | 45 | |
| 46 | - /** | |
| 47 | - * Get the rendering callback for a given URI. | |
| 48 | - * | |
| 49 | - * @since 0.1.0 | |
| 50 | - * | |
| 51 | - * @param string $uri URI to render. | |
| 52 | - * @param array $context Context in which to render. | |
| 53 | - * | |
| 54 | - * @return callable Rendering callback. | |
| 55 | - * @throws FailedToLoadView If the View URI is not accessible or readable. | |
| 56 | - * @throws FailedToLoadView If the View URI could not be loaded. | |
| 57 | - */ | |
| 58 | - public function getRenderCallback($uri, array $context = []) | |
| 59 | -    { | |
| 60 | -        if ( ! is_readable($uri)) { | |
| 61 | - throw new FailedToLoadView( | |
| 62 | - sprintf( | |
| 63 | -                    _('The View URI "%1$s" is not accessible or readable.'), | |
| 64 | - $uri | |
| 65 | - ) | |
| 66 | - ); | |
| 67 | - } | |
| 46 | + /** | |
| 47 | + * Get the rendering callback for a given URI. | |
| 48 | + * | |
| 49 | + * @since 0.1.0 | |
| 50 | + * | |
| 51 | + * @param string $uri URI to render. | |
| 52 | + * @param array $context Context in which to render. | |
| 53 | + * | |
| 54 | + * @return callable Rendering callback. | |
| 55 | + * @throws FailedToLoadView If the View URI is not accessible or readable. | |
| 56 | + * @throws FailedToLoadView If the View URI could not be loaded. | |
| 57 | + */ | |
| 58 | + public function getRenderCallback($uri, array $context = []) | |
| 59 | +	{ | |
| 60 | +		if ( ! is_readable($uri)) { | |
| 61 | + throw new FailedToLoadView( | |
| 62 | + sprintf( | |
| 63 | +					_('The View URI "%1$s" is not accessible or readable.'), | |
| 64 | + $uri | |
| 65 | + ) | |
| 66 | + ); | |
| 67 | + } | |
| 68 | 68 | |
| 69 | -        $closure = function () use ($uri, $context) { | |
| 69 | +		$closure = function () use ($uri, $context) { | |
| 70 | 70 | |
| 71 | - // Save current buffering level so we can backtrack in case of an error. | |
| 72 | - // This is needed because the view itself might also add an unknown number of output buffering levels. | |
| 73 | - $bufferLevel = ob_get_level(); | |
| 74 | - ob_start(); | |
| 71 | + // Save current buffering level so we can backtrack in case of an error. | |
| 72 | + // This is needed because the view itself might also add an unknown number of output buffering levels. | |
| 73 | + $bufferLevel = ob_get_level(); | |
| 74 | + ob_start(); | |
| 75 | 75 | |
| 76 | -            try { | |
| 77 | - include($uri); | |
| 78 | -            } catch (Exception $exception) { | |
| 76 | +			try { | |
| 77 | + include($uri); | |
| 78 | +			} catch (Exception $exception) { | |
| 79 | 79 | |
| 80 | - // Remove whatever levels were added up until now. | |
| 81 | -                while (ob_get_level() > $bufferLevel) { | |
| 82 | - ob_end_clean(); | |
| 83 | - } | |
| 80 | + // Remove whatever levels were added up until now. | |
| 81 | +				while (ob_get_level() > $bufferLevel) { | |
| 82 | + ob_end_clean(); | |
| 83 | + } | |
| 84 | 84 | |
| 85 | - throw new FailedToLoadView( | |
| 86 | - sprintf( | |
| 87 | -                        _('Could not load the View URI "%1$s". Reason: "%2$s".'), | |
| 88 | - $uri, | |
| 89 | - $exception->getMessage() | |
| 90 | - ), | |
| 91 | - $exception->getCode(), | |
| 92 | - $exception | |
| 93 | - ); | |
| 94 | - } | |
| 85 | + throw new FailedToLoadView( | |
| 86 | + sprintf( | |
| 87 | +						_('Could not load the View URI "%1$s". Reason: "%2$s".'), | |
| 88 | + $uri, | |
| 89 | + $exception->getMessage() | |
| 90 | + ), | |
| 91 | + $exception->getCode(), | |
| 92 | + $exception | |
| 93 | + ); | |
| 94 | + } | |
| 95 | 95 | |
| 96 | - return ob_get_clean(); | |
| 97 | - }; | |
| 96 | + return ob_get_clean(); | |
| 97 | + }; | |
| 98 | 98 | |
| 99 | - return $closure; | |
| 100 | - } | |
| 99 | + return $closure; | |
| 100 | + } | |
| 101 | 101 | } | 
| @@ -66,7 +66,7 @@ | ||
| 66 | 66 | ); | 
| 67 | 67 | } | 
| 68 | 68 | |
| 69 | -        $closure = function () use ($uri, $context) { | |
| 69 | +        $closure = function() use ($uri, $context) { | |
| 70 | 70 | |
| 71 | 71 | // Save current buffering level so we can backtrack in case of an error. | 
| 72 | 72 | // This is needed because the view itself might also add an unknown number of output buffering levels. | 
| @@ -24,32 +24,32 @@ | ||
| 24 | 24 | class NullEngine implements Engine, NullFindable | 
| 25 | 25 |  { | 
| 26 | 26 | |
| 27 | - /** | |
| 28 | - * Check whether the Findable can handle an individual criterion. | |
| 29 | - * | |
| 30 | - * @since 0.1.0 | |
| 31 | - * | |
| 32 | - * @param mixed $criterion Criterion to check. | |
| 33 | - * | |
| 34 | - * @return bool Whether the Findable can handle the criterion. | |
| 35 | - */ | |
| 36 | - public function canHandle($criterion) | |
| 37 | -    { | |
| 38 | - return true; | |
| 39 | - } | |
| 27 | + /** | |
| 28 | + * Check whether the Findable can handle an individual criterion. | |
| 29 | + * | |
| 30 | + * @since 0.1.0 | |
| 31 | + * | |
| 32 | + * @param mixed $criterion Criterion to check. | |
| 33 | + * | |
| 34 | + * @return bool Whether the Findable can handle the criterion. | |
| 35 | + */ | |
| 36 | + public function canHandle($criterion) | |
| 37 | +	{ | |
| 38 | + return true; | |
| 39 | + } | |
| 40 | 40 | |
| 41 | - /** | |
| 42 | - * Get the rendering callback for a given URI. | |
| 43 | - * | |
| 44 | - * @since 0.1.0 | |
| 45 | - * | |
| 46 | - * @param string $uri URI to render. | |
| 47 | - * @param array $context Context in which to render. | |
| 48 | - * | |
| 49 | - * @return string Rendered HTML. | |
| 50 | - */ | |
| 51 | - public function getRenderCallback($uri, array $context = []) | |
| 52 | -    { | |
| 53 | - return ''; | |
| 54 | - } | |
| 41 | + /** | |
| 42 | + * Get the rendering callback for a given URI. | |
| 43 | + * | |
| 44 | + * @since 0.1.0 | |
| 45 | + * | |
| 46 | + * @param string $uri URI to render. | |
| 47 | + * @param array $context Context in which to render. | |
| 48 | + * | |
| 49 | + * @return string Rendered HTML. | |
| 50 | + */ | |
| 51 | + public function getRenderCallback($uri, array $context = []) | |
| 52 | +	{ | |
| 53 | + return ''; | |
| 54 | + } | |
| 55 | 55 | } | 
| @@ -28,138 +28,138 @@ | ||
| 28 | 28 | abstract class AbstractView implements View | 
| 29 | 29 |  { | 
| 30 | 30 | |
| 31 | - /** | |
| 32 | - * URI of the view. | |
| 33 | - * | |
| 34 | - * @since 0.1.0 | |
| 35 | - * | |
| 36 | - * @var string | |
| 37 | - */ | |
| 38 | - protected $uri; | |
| 39 | - | |
| 40 | - /** | |
| 41 | - * Engine to use for the view. | |
| 42 | - * | |
| 43 | - * @since 0.1.0 | |
| 44 | - * | |
| 45 | - * @var Engine | |
| 46 | - */ | |
| 47 | - protected $engine; | |
| 48 | - | |
| 49 | - /** | |
| 50 | - * ViewBuilder instance. | |
| 51 | - * | |
| 52 | - * @since 0.2.0 | |
| 53 | - * | |
| 54 | - * @var ViewBuilder | |
| 55 | - */ | |
| 56 | - protected $builder; | |
| 57 | - | |
| 58 | - /** | |
| 59 | - * Instantiate an AbstractView object. | |
| 60 | - * | |
| 61 | - * @since 0.1.0 | |
| 62 | - * | |
| 63 | - * @param string $uri URI for the view. | |
| 64 | - * @param Engine $engine Engine to use for the view. | |
| 65 | - */ | |
| 66 | - public function __construct($uri, Engine $engine) | |
| 67 | -    { | |
| 68 | - $this->uri = $uri; | |
| 69 | - $this->engine = $engine; | |
| 70 | - } | |
| 71 | - | |
| 72 | - /** | |
| 73 | - * Render the view. | |
| 74 | - * | |
| 75 | - * @since 0.1.0 | |
| 76 | - * | |
| 77 | - * @param array $context Optional. The context in which to render the view. | |
| 78 | - * @param bool $echo Optional. Whether to echo the output immediately. Defaults to false. | |
| 79 | - * | |
| 80 | - * @return string|void Rendered HTML or nothing, depending on $echo argument. | |
| 81 | - */ | |
| 82 | - public function render(array $context = [], $echo = false) | |
| 83 | -    { | |
| 84 | - $this->initializeViewBuilder(); | |
| 85 | - $this->assimilateContext($context); | |
| 86 | - | |
| 87 | - $closure = Closure::bind( | |
| 88 | - $this->engine->getRenderCallback($this->uri, $context), | |
| 89 | - $this, | |
| 90 | - static::class | |
| 91 | - ); | |
| 92 | - | |
| 93 | -        if ( ! $echo) { | |
| 94 | - return $closure(); | |
| 95 | - } | |
| 96 | - | |
| 97 | - echo $closure(); | |
| 98 | - } | |
| 99 | - | |
| 100 | - /** | |
| 101 | - * Render a partial view for a given URI. | |
| 102 | - * | |
| 103 | - * @since 0.2.0 | |
| 104 | - * | |
| 105 | - * @param string $view View identifier to create a view for. | |
| 106 | - * @param array $context Optional. The context in which to render the view. | |
| 107 | - * @param string|null $type Type of view to create. | |
| 108 | - * | |
| 109 | - * @return string Rendered HTML content. | |
| 110 | - */ | |
| 111 | - public function renderPart($view, array $context = null, $type = null) | |
| 112 | -    { | |
| 113 | -        if (null === $context) { | |
| 114 | - $context = $this->context; | |
| 115 | - } | |
| 116 | - | |
| 117 | - $this->initializeViewBuilder(); | |
| 118 | - $viewObject = $this->builder->create($view, $type); | |
| 119 | - | |
| 120 | - return $viewObject->render($context); | |
| 121 | - } | |
| 122 | - | |
| 123 | - /** | |
| 124 | - * Associate a view builder with this view. | |
| 125 | - * | |
| 126 | - * @since 0.2.0 | |
| 127 | - * | |
| 128 | - * @param ViewBuilder $builder | |
| 129 | - * | |
| 130 | - * @return static | |
| 131 | - */ | |
| 132 | - public function setBuilder(ViewBuilder $builder) | |
| 133 | -    { | |
| 134 | - $this->builder = $builder; | |
| 135 | - | |
| 136 | - return $this; | |
| 137 | - } | |
| 138 | - | |
| 139 | - /** | |
| 140 | - * Initialize the view builder associated with the view. | |
| 141 | - * | |
| 142 | - * @since 0.2.0 | |
| 143 | - */ | |
| 144 | - protected function initializeViewBuilder() | |
| 145 | -    { | |
| 146 | -        if (null === $this->builder) { | |
| 147 | - $this->builder = Views::getViewBuilder(); | |
| 148 | - } | |
| 149 | - } | |
| 150 | - | |
| 151 | - /** | |
| 152 | - * Assimilate the context to make it available as properties. | |
| 153 | - * | |
| 154 | - * @since 0.2.0 | |
| 155 | - * | |
| 156 | - * @param array $context Context to assimilate. | |
| 157 | - */ | |
| 158 | - protected function assimilateContext(array $context = []) | |
| 159 | -    { | |
| 160 | - $this->context = $context; | |
| 161 | -        foreach ($context as $key => $value) { | |
| 162 | - $this->$key = $value; | |
| 163 | - } | |
| 164 | - } | |
| 31 | + /** | |
| 32 | + * URI of the view. | |
| 33 | + * | |
| 34 | + * @since 0.1.0 | |
| 35 | + * | |
| 36 | + * @var string | |
| 37 | + */ | |
| 38 | + protected $uri; | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * Engine to use for the view. | |
| 42 | + * | |
| 43 | + * @since 0.1.0 | |
| 44 | + * | |
| 45 | + * @var Engine | |
| 46 | + */ | |
| 47 | + protected $engine; | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * ViewBuilder instance. | |
| 51 | + * | |
| 52 | + * @since 0.2.0 | |
| 53 | + * | |
| 54 | + * @var ViewBuilder | |
| 55 | + */ | |
| 56 | + protected $builder; | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * Instantiate an AbstractView object. | |
| 60 | + * | |
| 61 | + * @since 0.1.0 | |
| 62 | + * | |
| 63 | + * @param string $uri URI for the view. | |
| 64 | + * @param Engine $engine Engine to use for the view. | |
| 65 | + */ | |
| 66 | + public function __construct($uri, Engine $engine) | |
| 67 | +	{ | |
| 68 | + $this->uri = $uri; | |
| 69 | + $this->engine = $engine; | |
| 70 | + } | |
| 71 | + | |
| 72 | + /** | |
| 73 | + * Render the view. | |
| 74 | + * | |
| 75 | + * @since 0.1.0 | |
| 76 | + * | |
| 77 | + * @param array $context Optional. The context in which to render the view. | |
| 78 | + * @param bool $echo Optional. Whether to echo the output immediately. Defaults to false. | |
| 79 | + * | |
| 80 | + * @return string|void Rendered HTML or nothing, depending on $echo argument. | |
| 81 | + */ | |
| 82 | + public function render(array $context = [], $echo = false) | |
| 83 | +	{ | |
| 84 | + $this->initializeViewBuilder(); | |
| 85 | + $this->assimilateContext($context); | |
| 86 | + | |
| 87 | + $closure = Closure::bind( | |
| 88 | + $this->engine->getRenderCallback($this->uri, $context), | |
| 89 | + $this, | |
| 90 | + static::class | |
| 91 | + ); | |
| 92 | + | |
| 93 | +		if ( ! $echo) { | |
| 94 | + return $closure(); | |
| 95 | + } | |
| 96 | + | |
| 97 | + echo $closure(); | |
| 98 | + } | |
| 99 | + | |
| 100 | + /** | |
| 101 | + * Render a partial view for a given URI. | |
| 102 | + * | |
| 103 | + * @since 0.2.0 | |
| 104 | + * | |
| 105 | + * @param string $view View identifier to create a view for. | |
| 106 | + * @param array $context Optional. The context in which to render the view. | |
| 107 | + * @param string|null $type Type of view to create. | |
| 108 | + * | |
| 109 | + * @return string Rendered HTML content. | |
| 110 | + */ | |
| 111 | + public function renderPart($view, array $context = null, $type = null) | |
| 112 | +	{ | |
| 113 | +		if (null === $context) { | |
| 114 | + $context = $this->context; | |
| 115 | + } | |
| 116 | + | |
| 117 | + $this->initializeViewBuilder(); | |
| 118 | + $viewObject = $this->builder->create($view, $type); | |
| 119 | + | |
| 120 | + return $viewObject->render($context); | |
| 121 | + } | |
| 122 | + | |
| 123 | + /** | |
| 124 | + * Associate a view builder with this view. | |
| 125 | + * | |
| 126 | + * @since 0.2.0 | |
| 127 | + * | |
| 128 | + * @param ViewBuilder $builder | |
| 129 | + * | |
| 130 | + * @return static | |
| 131 | + */ | |
| 132 | + public function setBuilder(ViewBuilder $builder) | |
| 133 | +	{ | |
| 134 | + $this->builder = $builder; | |
| 135 | + | |
| 136 | + return $this; | |
| 137 | + } | |
| 138 | + | |
| 139 | + /** | |
| 140 | + * Initialize the view builder associated with the view. | |
| 141 | + * | |
| 142 | + * @since 0.2.0 | |
| 143 | + */ | |
| 144 | + protected function initializeViewBuilder() | |
| 145 | +	{ | |
| 146 | +		if (null === $this->builder) { | |
| 147 | + $this->builder = Views::getViewBuilder(); | |
| 148 | + } | |
| 149 | + } | |
| 150 | + | |
| 151 | + /** | |
| 152 | + * Assimilate the context to make it available as properties. | |
| 153 | + * | |
| 154 | + * @since 0.2.0 | |
| 155 | + * | |
| 156 | + * @param array $context Context to assimilate. | |
| 157 | + */ | |
| 158 | + protected function assimilateContext(array $context = []) | |
| 159 | +	{ | |
| 160 | + $this->context = $context; | |
| 161 | +		foreach ($context as $key => $value) { | |
| 162 | + $this->$key = $value; | |
| 163 | + } | |
| 164 | + } | |
| 165 | 165 | } | 
| @@ -26,64 +26,64 @@ | ||
| 26 | 26 | class NullView implements View, NullFindable | 
| 27 | 27 |  { | 
| 28 | 28 | |
| 29 | - /** | |
| 30 | - * Check whether the Findable can handle an individual criterion. | |
| 31 | - * | |
| 32 | - * @since 0.1.0 | |
| 33 | - * | |
| 34 | - * @param mixed $criterion Criterion to check. | |
| 35 | - * | |
| 36 | - * @return bool Whether the Findable can handle the criterion. | |
| 37 | - */ | |
| 38 | - public function canHandle($criterion) | |
| 39 | -    { | |
| 40 | - return true; | |
| 41 | - } | |
| 29 | + /** | |
| 30 | + * Check whether the Findable can handle an individual criterion. | |
| 31 | + * | |
| 32 | + * @since 0.1.0 | |
| 33 | + * | |
| 34 | + * @param mixed $criterion Criterion to check. | |
| 35 | + * | |
| 36 | + * @return bool Whether the Findable can handle the criterion. | |
| 37 | + */ | |
| 38 | + public function canHandle($criterion) | |
| 39 | +	{ | |
| 40 | + return true; | |
| 41 | + } | |
| 42 | 42 | |
| 43 | - /** | |
| 44 | - * Render the view. | |
| 45 | - * | |
| 46 | - * @since 0.1.0 | |
| 47 | - * | |
| 48 | - * @param array $context Optional. The context in which to render the view. | |
| 49 | - * @param bool $echo Optional. Whether to echo the output immediately. Defaults to false. | |
| 50 | - * | |
| 51 | - * @return string|void Rendered HTML or nothing, depending on $echo argument. | |
| 52 | - */ | |
| 53 | - public function render(array $context = [], $echo = false) | |
| 54 | -    { | |
| 55 | -        if ( ! $echo) { | |
| 56 | - return ''; | |
| 57 | - } | |
| 58 | - } | |
| 43 | + /** | |
| 44 | + * Render the view. | |
| 45 | + * | |
| 46 | + * @since 0.1.0 | |
| 47 | + * | |
| 48 | + * @param array $context Optional. The context in which to render the view. | |
| 49 | + * @param bool $echo Optional. Whether to echo the output immediately. Defaults to false. | |
| 50 | + * | |
| 51 | + * @return string|void Rendered HTML or nothing, depending on $echo argument. | |
| 52 | + */ | |
| 53 | + public function render(array $context = [], $echo = false) | |
| 54 | +	{ | |
| 55 | +		if ( ! $echo) { | |
| 56 | + return ''; | |
| 57 | + } | |
| 58 | + } | |
| 59 | 59 | |
| 60 | - /** | |
| 61 | - * Render a partial view for a given URI. | |
| 62 | - * | |
| 63 | - * @since 0.2.0 | |
| 64 | - * | |
| 65 | - * @param string $view View identifier to create a view for. | |
| 66 | - * @param array $context Optional. The context in which to render the view. | |
| 67 | - * @param string|null $type Type of view to create. | |
| 68 | - * | |
| 69 | - * @return string Rendered HTML content. | |
| 70 | - */ | |
| 71 | - public function renderPart($view, array $context = [], $type = null) | |
| 72 | -    { | |
| 73 | - return ''; | |
| 74 | - } | |
| 60 | + /** | |
| 61 | + * Render a partial view for a given URI. | |
| 62 | + * | |
| 63 | + * @since 0.2.0 | |
| 64 | + * | |
| 65 | + * @param string $view View identifier to create a view for. | |
| 66 | + * @param array $context Optional. The context in which to render the view. | |
| 67 | + * @param string|null $type Type of view to create. | |
| 68 | + * | |
| 69 | + * @return string Rendered HTML content. | |
| 70 | + */ | |
| 71 | + public function renderPart($view, array $context = [], $type = null) | |
| 72 | +	{ | |
| 73 | + return ''; | |
| 74 | + } | |
| 75 | 75 | |
| 76 | - /** | |
| 77 | - * Associate a view builder with this view. | |
| 78 | - * | |
| 79 | - * @since 0.2.0 | |
| 80 | - * | |
| 81 | - * @param ViewBuilder $builder | |
| 82 | - * | |
| 83 | - * @return static | |
| 84 | - */ | |
| 85 | - public function setBuilder(ViewBuilder $builder) | |
| 86 | -    { | |
| 87 | - return $this; | |
| 88 | - } | |
| 76 | + /** | |
| 77 | + * Associate a view builder with this view. | |
| 78 | + * | |
| 79 | + * @since 0.2.0 | |
| 80 | + * | |
| 81 | + * @param ViewBuilder $builder | |
| 82 | + * | |
| 83 | + * @return static | |
| 84 | + */ | |
| 85 | + public function setBuilder(ViewBuilder $builder) | |
| 86 | +	{ | |
| 87 | + return $this; | |
| 88 | + } | |
| 89 | 89 | } |