Hi, I love the project, I'm having a lot of fun tinkering with it, thanks a lot.
Right now, I'm looking at how deep I can go trying to use phel as laravel controllers.
Why ? Just because it's fun.
Getting it to run was really easy, just add the package to composer and install, slap
$this->app->singleton(Runtime::class, function ($app) {
$runtime = Runtime::initialize();
$runtime->addPath('app\\', [app_path()]);
$runtime->loadNs('phel\core');
return $runtime;
});
into AppServiceProvider->register
, add a route macro for convenience
$router = $this->app['router'];
$router::macro('phel', function ($path, $controller) use ($router) {
return $router->get($path, function (Runtime $runtime) use ($controller) {
$runtime->loadNs("app\\Http\\Controllers\\$controller");
});
});
into AppServiceProvider->boot
, and now I can match urls to phel script files with
Route::phel('/foo', 'bar'); // matches "example.com/foo" to `App\Http\Controllers\bar.phel`
(ns app\Http\Controllers\bar)
(print "Phel sends his regards.")
And it works... Kinda.
I have one issue and a few questions or suggestions
ERROR : output contains some error message
Phel sends his regards.<p>Unterminatend list<br/>in <em>C:\laragon\www\laraphel\app\Http\Controllers\bar.phel:4</em></p><pre><code>4|
</pre></code>
Even if I remove (print "Phel sends his regards.")
, I still get this error message.
Current implementation uses php's exit
liberally
This prevents any one to do anything after phel has run, or even using ob_ functions to work with output.
Is there any way to pass a few global php variables to phel scripts ?
Something like $runtime->loadNs('phel\core', ['request' => $request, ...])
I was able to get Laravel app/container and assign it in phel, as it's a singleton, but it can be quite verbose quite fast.
(ns app\boot
(:use \Illuminate\Foundation\Application))
(def app (php/:: Application (getInstance)))
(defn resolve [binding]
(php/-> app (make binding)))
Is there a way to call global php functions in phel ?
I don't see anything in the docs on that front, it only works with object or classes as far as I can tell.
I wanted to convert view('welcome')
in php to something akin to (php\call view "welcome")
in Phel. So far I have to redefine it in Phel
# I'm using my previously defined resolve function
(defn view [viewfile]
(php/-> (resolve "view") (make viewfile)))
Is there any way to return something from phel to php ?
Even if phel didn't "hard exit" the script, I don't know how I can pass something back to the php side of things... loadNs
return a boolean, and ob_ functions can't really deal with anything more than output.