I took a look at the view resolver handling this evening and I think I've come up with a nice solution.
I added the halo_view_InternalResourceViewResolver to the repository. It is actually very close to aek's initial solution with some spelling changes and abstracting about 95% of it to the halo_view_AbstractResourceViewResolver. I believe this should satisfy your needs, aek?
In testing this worked:
$context->add(array(
'className' => 'halo_view_InternalResourceViewResolver',
'properties' => array(
'prefix' => './WebContent/WEB-INF/views/',
'suffix' => '.php',
'viewClass' => 'halo_view_skittle_SkittleUriView',
),
'lazyLoad' => false,
));
You'll note that I created a new skittle view class specifically for this simple purpose. (source can be seen here:
http://github.com/dflydev/halo-php/blob/master/lib/halo_view_skittle_SkittleUriView.php ) It extends halo_view_AbstractUriView.
I realized that there was a pretty serious disconnect between some of the ideas I had for view resolving and the intention of some more simple URI based views. Like you said, aek, it hands the off to the view class and hopes for the best. (and error in case of missing is acceptable) While this isn't what I want, I realize this is preferable to some people.
On my side of things, where maybe I want to do some more advanced configuration of the view class itself, I created halo_view_IViewFactory. This works perfectly for me and is a lot cleaner than the solution I was hacking together last night. The end result in this case is a completely different view class, halo_view_skittle_SkittleResourceLocatorView.
The philosophy here is different. Intention of this view resolver is to only return view objects if the view actually exists. Would adapter be a better name for this than factory? I am hoping that factory better portrays the intention.
$context->add('lithe.views.defaultViewResolver', array(
'className' => 'halo_view_ViewFactoryResourceViewResolver',
'constructorArgs' => array(
'viewFactory' => $context->ref('lithe.views.skittle.viewFactory'),
),
'properties' => array(
'suffix' => '.php',
),
));
$context->add('lithe.views.skittle.viewFactory', array(
'className' => 'halo_view_skittle_SkittleViewFactory',
'constructorArgs' => array(
'resourceLocator' => $context->ref('lithe.views.resourceLocator'),
),
));
The new halo_view_ViewFactoryResourceViewResolver follows mostly the same pattern as the internal resource view resolver with the exception that it accepts a view factory instead of a view class. The job of the view factory is to determine whether or not the request can be satisfied by the object the factory is capable of building and then building an instance of the view class for the request.
From halo_view_ViewFactoryResourceViewResolver:
public function doResolveViewUri($viewUri, $viewName, halo_HttpRequest $httpRequest, halo_HttpResponse $httpResponse) {
if ( $this->viewFactory->supports($viewUri, $viewName, $httpRequest, $httpResponse) ) {
return $this->viewFactory->buildView($viewUri, $viewName, $httpRequest, $httpResponse);
}
return null;
}
From halo_view_skittle_SkittleViewFactory:
public function __construct(substrate_IResourceLocator $resourceLocator) {
$this->substrateResourceLocatorAdapter = new halo_view_skittle_SubstrateResourceLocatorAdapter($resourceLocator);
}
public function supports($viewUri, $viewName, halo_HttpRequest $httpRequest, halo_HttpResponse $httpResponse) {
if ( $this->substrateResourceLocatorAdapter->find($viewUri) ) {
return true;
}
return false;
}
public function buildView($viewUri, $viewName, halo_HttpRequest $httpRequest, halo_HttpResponse $httpResponse) {
return new halo_view_skittle_SkittleResourceLocatorView($viewUri, $this->substrateResourceLocatorAdapter);
}
From halo_view_skittle_SkittleResourceLocatorView:
public function __construct($uri, skittle_IResourceLocator $resourceLocator) {
parent::__construct($uri);
$this->resourceLocator = $resourceLocator;
}
public function render(array $model, halo_HttpRequest $httpRequest, halo_HttpResponse $httpResponse) {
$skittle = new skittle_Skittle($this->resourceLocator);
return $skittle->stringInc($this->uri, $model);
}