-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from mucan54/phalcon-implementation
Phalcon framework implementation.
- Loading branch information
Showing
4 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace Clickfwd\Yoyo\ViewProviders; | ||
|
||
use Clickfwd\Yoyo\Interfaces\ViewProviderInterface; | ||
use Clickfwd\Yoyo\ViewProviders\BaseViewProvider; | ||
use Phalcon\Mvc\View; | ||
|
||
class PhalconViewProvider extends BaseViewProvider implements ViewProviderInterface | ||
{ | ||
protected $view; | ||
|
||
protected $template; | ||
|
||
protected $vars; | ||
|
||
private $viewExtention = '.phtml'; | ||
|
||
public function __construct($view) | ||
{ | ||
$this->view = $view; | ||
} | ||
|
||
public function exists($view): bool | ||
{ | ||
return file_exists($this->view->getViewsDir() . $view . $this->viewExtention); | ||
} | ||
|
||
public function render($template, $vars = []): ViewProviderInterface | ||
{ | ||
$this->template = $template; | ||
$this->vars = $vars; | ||
|
||
return $this; | ||
} | ||
|
||
public function setViewExtention($viewExtention) | ||
{ | ||
$this->viewExtention = $viewExtention; | ||
|
||
return $this; | ||
} | ||
public function makeFromString($content, $vars = []): string | ||
{ | ||
$this->view->start(); | ||
$this->view->setContent($content); | ||
$this->view->setVars($vars); | ||
$this->view->finish(); | ||
return $this->view->render(); | ||
} | ||
|
||
public function startYoyoRendering($component): void | ||
{ | ||
} | ||
|
||
public function stopYoyoRendering(): void | ||
{ | ||
} | ||
|
||
public function __toString() | ||
{ | ||
return $this->view->render($this->template, $this->vars); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Clickfwd\Yoyo; | ||
|
||
use Phalcon\Mvc\Controller; | ||
use Clickfwd\Yoyo\Request; | ||
use Clickfwd\Yoyo\Yoyo; | ||
|
||
class YoyoPhalconController extends Controller | ||
{ | ||
public function handleAction() | ||
{ | ||
$this->view->disable(); | ||
/** @var Yoyo $yoyo */ | ||
$yoyo = $this->di->get('yoyo'); | ||
$yoyoRequest = new Request(); | ||
$yoyoRequest->mock($_REQUEST, $_SERVER); | ||
$yoyo->bindRequest($yoyoRequest); | ||
$this->response->setContent($yoyo->update()); | ||
return $this->response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Clickfwd\Yoyo; | ||
|
||
use Clickfwd\Yoyo\ViewProviders\PhalconViewProvider; | ||
use Phalcon\Di\DiInterface; | ||
use Phalcon\Di\ServiceProviderInterface; | ||
use Phalcon\Mvc\View\Simple as SimpleView; | ||
|
||
class YoyoPhalconServiceProvider implements ServiceProviderInterface | ||
{ | ||
private $yoyoConfig = []; | ||
|
||
private $viewExtention = null; | ||
|
||
public function setYoyoConfig($yoyoConfig) | ||
{ | ||
$this->yoyoConfig = $yoyoConfig; | ||
|
||
return $this; | ||
} | ||
|
||
public function setViewExtention($viewExtention) | ||
{ | ||
$this->viewExtention = $viewExtention; | ||
|
||
return $this; | ||
} | ||
|
||
public function register(DiInterface $di): void | ||
{ | ||
$di->setShared('yoyo', function () use ($di) { | ||
$yoyo = new Yoyo(); | ||
$yoyoConfig = $this->yoyoConfig ?? [ | ||
'url' => '/yoyo', | ||
'namespace' => 'App\Components\\', | ||
'scriptsPath' => 'js/', | ||
]; | ||
|
||
$yoyo->configure($yoyoConfig); | ||
$viewExtention = $this->viewExtention ?? null; | ||
|
||
$yoyo->container()->singleton('yoyo.view.default', function () use ($di, $viewExtention) { | ||
$view = $di->get('view'); | ||
$simpleView = new SimpleView(); | ||
$simpleView->setViewsDir($view->getViewsDir()); | ||
/** @var PhalconViewProvider $viewProvider */ | ||
$viewProvider = new PhalconViewProvider($simpleView); | ||
if($viewExtention){ | ||
$viewProvider->setViewExtention($this->viewExtention); | ||
} | ||
|
||
return $viewProvider; | ||
}); | ||
|
||
return $yoyo; | ||
}); | ||
} | ||
} |