From d04eb3827ba9b83959dd16a5f44528a759446260 Mon Sep 17 00:00:00 2001 From: Alejandro S Date: Wed, 8 Feb 2023 17:21:02 -0400 Subject: [PATCH 1/3] Include reference to Laravel app --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8bd8aba..cb33c79 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,9 @@ Inspired by [Laravel Livewire](https://laravel-livewire.com/) and [Sprig](https: Check out the [Yoyo Demo App](https://app.getyoyo.dev) to get a better idea of what you can build with Yoyo. It showcases many different types of Yoyo components. You can also clone and install the demo apps: -- [Yoyo App with built-in templating](https://github.com/clickfwd/yoyo-app) - [Yoyo Blade App](https://github.com/clickfwd/yoyo-blade-app) +- [Yoyo Laravel App](https://github.com/clickfwd/yoyo-laravel-app) +- [Yoyo PHP template App](https://github.com/clickfwd/yoyo-app) - [Yoyo Twig App](https://github.com/clickfwd/yoyo-twig-app) ## Documentation From 031b27f1d1af4413558a95c4cd41ea7247b42209 Mon Sep 17 00:00:00 2001 From: Muhammed Can Date: Wed, 19 Jun 2024 18:42:29 +0300 Subject: [PATCH 2/3] Phalcon framework implementation. --- README.md | 20 ++++++ .../ViewProviders/PhalconViewProvider.php | 64 +++++++++++++++++++ src/yoyo/YoyoPhalconController.php | 22 +++++++ src/yoyo/YoyoPhalconServiceProvider.php | 59 +++++++++++++++++ 4 files changed, 165 insertions(+) create mode 100644 src/yoyo/ViewProviders/PhalconViewProvider.php create mode 100644 src/yoyo/YoyoPhalconController.php create mode 100644 src/yoyo/YoyoPhalconServiceProvider.php diff --git a/README.md b/README.md index cb33c79..16da61a 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,26 @@ Yes, it's that simple! One thing to note above is the use of the protected prope composer require clickfwd/yoyo ``` +#### Phalcon Framework Installation + +For phalcon, you need to add di + +```php +$di->register(new \Clickfwd\Yoyo\YoyoPhalconServiceProvider()); +``` + +and you need to add router: + +```php +$router->add('/yoyo', [ + 'controller' => 'yoyo', + 'action' => 'handle', + ]); +``` + +and you should create a controller and inherit from `Clickfwd\Yoyo\PhalconController` class. + + ## Updating After performing the usual `composer update`, remember to also update the `yoyo.js` script per the [Load Assets](#load-assets) instructions. diff --git a/src/yoyo/ViewProviders/PhalconViewProvider.php b/src/yoyo/ViewProviders/PhalconViewProvider.php new file mode 100644 index 0000000..145864f --- /dev/null +++ b/src/yoyo/ViewProviders/PhalconViewProvider.php @@ -0,0 +1,64 @@ +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); + } +} \ No newline at end of file diff --git a/src/yoyo/YoyoPhalconController.php b/src/yoyo/YoyoPhalconController.php new file mode 100644 index 0000000..34f8ac7 --- /dev/null +++ b/src/yoyo/YoyoPhalconController.php @@ -0,0 +1,22 @@ +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; + } +} \ No newline at end of file diff --git a/src/yoyo/YoyoPhalconServiceProvider.php b/src/yoyo/YoyoPhalconServiceProvider.php new file mode 100644 index 0000000..336a870 --- /dev/null +++ b/src/yoyo/YoyoPhalconServiceProvider.php @@ -0,0 +1,59 @@ +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; + + $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; + }); + } +} \ No newline at end of file From 33d0937518fc031a8c76896626a0d20aac73e376 Mon Sep 17 00:00:00 2001 From: Muhammed Can Date: Wed, 19 Jun 2024 19:59:44 +0300 Subject: [PATCH 3/3] Phalcon framework implementation update. --- src/yoyo/YoyoPhalconServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/yoyo/YoyoPhalconServiceProvider.php b/src/yoyo/YoyoPhalconServiceProvider.php index 336a870..2200f72 100644 --- a/src/yoyo/YoyoPhalconServiceProvider.php +++ b/src/yoyo/YoyoPhalconServiceProvider.php @@ -38,7 +38,7 @@ public function register(DiInterface $di): void ]; $yoyo->configure($yoyoConfig); - $viewExtention = $this->viewExtention; + $viewExtention = $this->viewExtention ?? null; $yoyo->container()->singleton('yoyo.view.default', function () use ($di, $viewExtention) { $view = $di->get('view');