🏡 index : ~doyle/koselig.git

author Jordan Doyle <jordan@doyle.wf> 2016-11-01 10:31:47.0 +00:00:00
committer Jordan Doyle <jordan@doyle.wf> 2016-11-01 10:31:47.0 +00:00:00
commit
fd4f37f36010033ed5e2e10006e2c10b2c111269 [patch]
tree
6924d19bd6e712d2d4973fced9bbe6c9b5cb12ad
parent
707895c027e133df481770e9151c6daa86f53abb
download
fd4f37f36010033ed5e2e10006e2c10b2c111269.tar.gz

Add helper methods



Diff

 src/Providers/WordpressTemplatingServiceProvider.php |  4 +--
 src/Proxy/Query.php                                  | 20 +++++++++++++++-
 src/Support/Wordpress.php                            |  9 +++----
 src/helpers.php                                      | 28 +++++++++++++++++++++-
 4 files changed, 54 insertions(+), 7 deletions(-)

diff --git a/src/Providers/WordpressTemplatingServiceProvider.php b/src/Providers/WordpressTemplatingServiceProvider.php
index 16a6f9e..7c3bf5f 100644
--- a/src/Providers/WordpressTemplatingServiceProvider.php
+++ b/src/Providers/WordpressTemplatingServiceProvider.php
@@ -19,8 +19,8 @@ class WordpressTemplatingServiceProvider extends ServiceProvider
    public function boot()
    {
        Blade::directive('loop', function () {
            return '<?php if (Koselig\Facades\Query::hasPosts()): while (Koselig\Facades\Query::hasPosts()): '
                . 'Koselig\Facades\Query::post(); $loop = app(\'loop\'); ?>';
            return '<?php if (query()->hasPosts()): while (query()->hasPosts()): '
                . 'query()->post(); $post = post(); ?>';
        });

        Blade::directive('endloop', function () {
diff --git a/src/Proxy/Query.php b/src/Proxy/Query.php
index a56650a..678648b 100644
--- a/src/Proxy/Query.php
+++ b/src/Proxy/Query.php
@@ -9,6 +9,26 @@ use WP_Query;
/**
 * Proxies the {@link \WP_Query} class from Wordpress for a more elegant syntax.
 *
 * @property array $query Query vars set by the user
 * @property array $queryVars Query vars, after parsing
 * @property \WP_Tax_Query $taxQuery Taxonomy query
 * @property \WP_Meta_Query $metaQuery Metadata query container
 * @property \WP_Date_Query $dateQuery Date query container
 * @property object|array $queriedObject Holds the data for a single object that is queried.
 * @property int $queriedObjectId The ID of the queried object.
 * @property string $request Get post database query
 * @property array $posts List of posts.
 * @property int $postCount The amount of posts for the current query.
 * @property int $currentPost Index of the current item in the loop.
 * @property bool $inTheLoop Whether the loop has started and the caller is in the loop.
 * @property WP_Post $post The current post.
 * @property array $comments The list of comments for current post.
 * @property int $commentCount The amount of comments for the posts.
 * @property int $currentComment The index of the comment in the comment loop.
 * @property int $comment Current comment ID.
 * @property int $foundPosts The amount of found posts for the current query.
 * @property int $maxNumPages The amount of pages.
 * @property int $maxNumCommentPages The amount of comment pages.
 * @method static void init Initiates object properties and sets default values.
 * @method static void parseQueryVars Reparse the query vars.
 * @method static array fillQueryVars(array $array) Fills in the query variables, which do not exist within the
diff --git a/src/Support/Wordpress.php b/src/Support/Wordpress.php
index 230edc8..9a5aa8b 100644
--- a/src/Support/Wordpress.php
+++ b/src/Support/Wordpress.php
@@ -1,7 +1,6 @@
<?php
namespace Koselig\Support;

use Koselig\Facades\Query;
use Koselig\Models\User;

/**
@@ -20,7 +19,7 @@ class Wordpress
    public static function id()
    {
        // can't use facades to access properties unfortunately!
        return app('query')->post->ID ?? null;
        return query()->post->ID ?? null;
    }

    /**
@@ -32,7 +31,7 @@ class Wordpress
     */
    public static function singular($types = '')
    {
        return Query::singular($types);
        return query()->singular($types);
    }

    /**
@@ -44,7 +43,7 @@ class Wordpress
     */
    public static function archive($types = null)
    {
        return $types === null || empty($types) ? Query::archive() : Query::postTypeArchive($types);
        return $types === null || empty($types) ? query()->archive() : query()->postTypeArchive($types);
    }

    /**
@@ -66,7 +65,7 @@ class Wordpress
            }
        }

        return Query::author($users);
        return query()->author($users);
    }

    /**
diff --git a/src/helpers.php b/src/helpers.php
index 3aabd44..f51492f 100644
--- a/src/helpers.php
+++ b/src/helpers.php
@@ -1,5 +1,33 @@
<?php
use Koselig\Models\Meta;
use Koselig\Models\Post;

if (!function_exists('query')) {
    /**
     * Get the main query or convert a query to a {@link \Koselig\Proxy\Query} proxy instance.
     *
     * @param WP_Query|null $query
     * @return \Koselig\Proxy\Query
     */
    function query(\WP_Query $query = null)
    {
        return ($query === null) ? app('query') : Query::instance($query);
    }
}

if (!function_exists('post')) {
    /**
     * Get the current post in The Loop, or convert a {@link \WP_Post} instance to a Koselig
     * post.
     *
     * @param WP_Post|null $post
     * @return Post|null
     */
    function post(WP_Post $post = null)
    {
        return ($post === null) ? app('loop') : Post::find($post->ID);
    }
}

if (!function_exists('meta')) {
    /**