Hi guys!
We are starting use the phalcon framework! The first impression was great. But after all I found several issues wihich I don't understand.
First of all I don't like a way in which the dependency injection is used. Now, its used as Registry pattern, not more. Let me explain a little. For ex. I'd like to make my custom View. So I wrote this
$this->di->set(
'view',
function () {
return new \stdClass();
}
);
Let me see what I'll get?
Fatal error: Phalcon\Mvc\Application::handle(): Call to undefined method start() on class stdClass
What? Are you kidding me? It's mean what Phalcon use DI in this way:
class Controller
{
public function __construct(DependencyInjectionInterface $di)
{
$this->view = $di->getShared('view');
}
}
instead of
class Controller
{
public function __construct(DependencyInjectionInterface $di, ViewInterface $view)
{
$this->view = $view
}
}
or
class Controller
{
public function __construct(DependencyInjectionInterface $di)
{
$this->setView($di->getShared('view');
}
protected function setView(ViewInterface $view)
{
$this->view = $view
}
}
It doesn't make sense.
Ok, let we move forward.
I'm creating an application that communicate via JSON protocol. Or AMF for example. Should I use hierarchical template structure? Or maybe catch output buffering? I think no. The phalcon developers do not think so. I have no way to replace default implementation of view logic. Is this a CMS or a framework? So...
My opinion is that phalcon should has a separate view logic to render, store and engine service. Let me describe a little. View -> should only store the data what you are what to represent. RenderEngine -> explain how this data will be render. Render -> render view with given engine.
For example we have some data to output:
$view = new View();
$view->test = 'hello word';
And we are want to render data to HTML template, so we are going to write follow lines:
$engine = new HTMLTemplateEngine();
$engine->setLayer('main');
$render = new Render();
$render->process($view, $engine);
Or we want to render answer in JSON format:
$engine = new JSONEngine();
$render = new Render();
$render->process($view, $engine);
Something like that. Again with this way we are keep one responsibility principle.
What are you think, does it make sense?