From 9e009c015ae7b9b3681a691e810be2df41f122f8 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Sat, 22 Oct 2016 00:46:47 +0100 Subject: [PATCH] better facade phpdocs --- src/Facades/Loop.php | 1 + src/Facades/Query.php | 1 + src/Facades/WPHash.php | 1 + src/Models/Comment.php | 24 ++++++++++++++++++++++++ src/Proxy/Query.php | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------- src/Support/Wordpress.php | 1 + 6 files changed, 92 insertions(+), 51 deletions(-) diff --git a/src/Facades/Loop.php b/src/Facades/Loop.php index 5c95126..6475051 100644 --- a/src/Facades/Loop.php +++ b/src/Facades/Loop.php @@ -7,6 +7,7 @@ use Illuminate\Support\Facades\Facade; * Facade for {@link Koselig\Models\Post}. Provides access to the current post in "The Loop" * * @see \Koselig\Models\Post + * @mixin \Koselig\Models\Post * @author Jordan Doyle */ class Loop extends Facade diff --git a/src/Facades/Query.php b/src/Facades/Query.php index 47d6b31..9a21b8b 100644 --- a/src/Facades/Query.php +++ b/src/Facades/Query.php @@ -7,6 +7,7 @@ use Illuminate\Support\Facades\Facade; * Facade for {@link Koselig\Proxy\Query} proxy. Provides access to the main query. * * @see \Koselig\Proxy\Query + * @mixin \Koselig\Proxy\Query * @author Jordan Doyle */ class Query extends Facade diff --git a/src/Facades/WPHash.php b/src/Facades/WPHash.php index 80ab20d..d5f8d04 100644 --- a/src/Facades/WPHash.php +++ b/src/Facades/WPHash.php @@ -7,6 +7,7 @@ use Illuminate\Support\Facades\Facade; * Facade for {@link \Koselig\Hashing\WordpressHasher}. * * @see \Koselig\Hashing\WordpressHasher + * @mixin \Koselig\Hashing\WordpressHasher * @author Jordan Doyle */ class WPHash extends Facade diff --git a/src/Models/Comment.php b/src/Models/Comment.php index 1dff841..bdc92b5 100644 --- a/src/Models/Comment.php +++ b/src/Models/Comment.php @@ -1,12 +1,31 @@ */ class Comment extends Model @@ -51,4 +70,9 @@ class Comment extends Model { return $this->belongsTo(User::class); } + + public function parent() + { + return $this->belongsTo(Comment::class, 'comment_parent'); + } } diff --git a/src/Proxy/Query.php b/src/Proxy/Query.php index a0b077e..8466bd3 100644 --- a/src/Proxy/Query.php +++ b/src/Proxy/Query.php @@ -9,57 +9,62 @@ use WP_Query; /** * Proxies the {@link \WP_Query} class from Wordpress for a more elegant syntax. * - * @method void init Initiates object properties and sets default values. - * @method void parseQueryVars Reparse the query vars. - * @method array fillQueryVars Fills in the query variables, which do not exist within the parameter. - * @method void parseQuery Parse a query string and set query type booleans. - * @method void parseTaxQuery Parses various taxonomy related query vars. - * @method void set404 Sets the 404 property and saves whether query is feed. - * @method mixed get Retrieve query variable. - * @method void set Set query variable. - * @method array posts Retrieve the posts based on query variables. - * @method WP_Post nextPost Set up the next post and iterate current post index. - * @method WP_Post post Sets up the current post. - * @method bool hasPosts Determines whether there are more posts available in the loop. - * @method void rewindPosts Rewind the posts and reset post index. - * @method WP_Comment nextComment Iterate current comment index and return WP_Comment object. - * @method WP_Comment comment Sets up the current comment. - * @method bool hasComments Whether there are more comments available. - * @method void rewindComments Rewind the comments, resets the comment index and comment to first. - * @method array query Sets up the WordPress query by parsing query string. - * @method object queriedObject Retrieve queried object. - * @method int queriedObjectId Retrieve ID of the current queried object. - * @method bool archive Is the query for an existing archive page? - * @method bool postTypeArchive Is the query for an existing post type archive page? - * @method bool attachment Is the query for an existing attachment page? - * @method bool author Is the query for an existing author archive page? - * @method bool category Is the query for an existing category archive page? - * @method bool tag Is the query for an existing tag archive page? - * @method bool tax Is the query for an existing custom taxonomy archive page? - * @method bool date Is the query for an existing date archive? - * @method bool day Is the query for an existing day archive? - * @method bool feed Is the query for a feed? - * @method bool commentFeed Is the query for a comments feed? - * @method bool frontPage Is the query for the front page of the site? - * @method bool home Is the query for the blog homepage? - * @method bool month Is the query for an existing month archive? - * @method bool page Is the query for an existing single page? - * @method bool paged Is the query for paged result and not for the first page? - * @method bool preview Is the query for a post or page preview? - * @method bool robots Is the query for the robots file? - * @method bool search Is the query for a search? - * @method bool single Is the query for an existing single post? - * @method bool singular Is the query for an existing single post of any post type (post, attachment, page, ...)? - * @method bool time Is the query for a specific time? - * @method bool trackback Is the query for a trackback endpoint call? - * @method bool year Is the query for an existing year archive? - * @method bool 404 Is the query a 404 (returns no results)? - * @method bool embed Is the query for an embedded post? - * @method bool mainQuery Is the query the main query? - * @method true setupPostdata Set up global post data. - * @method void resetPostdata After looping through a query, restores the $post global to the current post in this obj. - * @method mixed lazyloadTermMeta Lazyload term meta for posts in the loop. - * @method mixed lazyloadCommentMeta Lazyload comment meta for comments in the loop. + * @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 + * parameter. + * @method static void parseQuery(string|array $query) Parse a query string and set query type booleans. + * @method static void parseTaxQuery(array $q) Parses various taxonomy related query vars. + * @method static void set404 Sets the 404 property and saves whether query is feed. + * @method static mixed get(string $query_var, mixed $default) Retrieve query variable. + * @method static void set(string $query_var, mixed $default) Set query variable. + * @method static array posts Retrieve the posts based on query variables. + * @method static WP_Post nextPost Set up the next post and iterate current post index. + * @method static WP_Post post Sets up the current post. + * @method static bool hasPosts Determines whether there are more posts available in the loop. + * @method static void rewindPosts Rewind the posts and reset post index. + * @method static WP_Comment nextComment Iterate current comment index and return WP_Comment object. + * @method static WP_Comment comment Sets up the current comment. + * @method static bool hasComments Whether there are more comments available. + * @method static void rewindComments Rewind the comments, resets the comment index and comment to first. + * @method static array query(string $query) Sets up the WordPress query by parsing query string. + * @method static object queriedObject Retrieve queried object. + * @method static int queriedObjectId Retrieve ID of the current queried object. + * @method static bool archive Is the query for an existing archive page? + * @method static bool postTypeArchive(array|string $post_types) Is the query for an existing post type archive page? + * @method static bool attachment(array|string $attachment) Is the query for an existing attachment page? + * @method static bool author(array|string|integer $author) Is the query for an existing author archive page? + * @method static bool category(array|string|integer $category) Is the query for an existing category archive page? + * @method static bool tag(array|string|integer $tag) Is the query for an existing tag archive page? + * @method static bool tax(string $taxonomy, integer|string|array $term) Is the query for an existing custom taxonomy + * archive page? + * @method static bool date Is the query for an existing date archive? + * @method static bool day Is the query for an existing day archive? + * @method static bool feed(string|array $feeds) Is the query for a feed? + * @method static bool commentFeed Is the query for a comments feed? + * @method static bool frontPage Is the query for the front page of the site? + * @method static bool home Is the query for the blog homepage? + * @method static bool month Is the query for an existing month archive? + * @method static bool page(int|string|array $page) Is the query for an existing single page? + * @method static bool paged Is the query for paged result and not for the first page? + * @method static bool preview Is the query for a post or page preview? + * @method static bool robots Is the query for the robots file? + * @method static bool search Is the query for a search? + * @method static bool single(int|string|array $post) Is the query for an existing single post? + * @method static bool singular(string|array $post_types) Is the query for an existing single post of any post type + * (post, attachment, page, ...)? + * @method static bool time Is the query for a specific time? + * @method static bool trackback Is the query for a trackback endpoint call? + * @method static bool year Is the query for an existing year archive? + * @method static bool is404 Is the query a 404 (returns no results)? + * @method static bool embed Is the query for an embedded post? + * @method static bool mainQuery Is the query the main query? + * @method static true setupPostdata(WP_Post|object|int $post) Set up global post data. + * @method static void resetPostdata After looping through a query, restores the $post global to the current post in + * this obj. + * @method static mixed lazyloadTermMeta(mixed $check, integer $term_id) Lazyload term meta for posts in the loop. + * @method static mixed lazyloadCommentMeta(mixed $check, integer $comment_id) Lazyload comment meta for comments in + * the loop. * @author Jordan Doyle */ class Query @@ -103,6 +108,14 @@ class Query if (!method_exists($this->query, $name)) { // try and find the method that was attempted to be called. Makes for a lot nicer code when reading over it. + if (preg_match('/^is([0-9]+)$/', $name, $matches)) { + $name = $matches[1]; + } + + if (preg_match('/^set([0-9]+)$/', $name, $matches)) { + $name = 'set_' . $matches[1]; + } + if (method_exists($this->query, 'the_' . $name)) { $name = 'the_' . $name; } elseif (method_exists($this->query, 'is_' . $name)) { diff --git a/src/Support/Wordpress.php b/src/Support/Wordpress.php index 0d0b32a..ba36cee 100644 --- a/src/Support/Wordpress.php +++ b/src/Support/Wordpress.php @@ -19,6 +19,7 @@ class Wordpress */ public static function id() { + // can't use facades to access properties unfortunately! return app('query')->post->ID; } -- libgit2 1.7.2