<?php
namespace Koselig\Providers;
use Illuminate\Support\ServiceProvider;
use Koselig\Models\Post;
use Koselig\Proxy\Query;
use Koselig\Support\Wordpress;
* Service provider that provides bindings for the several queries that Wordpress
* has running at once.
*
* @author Jordan Doyle <jordan@doyle.wf>
*/
class QueryServiceProvider extends ServiceProvider
{
private $cached = [];
* Bootstrap any application services.
*
* @return void
*/
public function register()
{
$this->app->singleton('query', function () {
return Query::instance($GLOBALS['wp_the_query']);
});
$this->app->bind('loop', function () {
$post = $GLOBALS['post']->ID;
return $this->cached[$post] ?? $this->cached[$post] = Post::find($post);
});
$this->app->singleton(Post::class, function () {
return Post::find(Wordpress::id());
});
}
}