Class Factory
Post entity factory.
Allows for easy instantiation of post entity objects. Classes can be
instantiated based on their post type. 'post' and 'page' are registered
by default.
Methods summary
public
|
|
public
Tev\Post\Factory
|
#
register( string $postType, string $className )
Register a new post type to class name mapping.
Register a new post type to class name mapping.
Parameters
- $postType
- Post type identifier
- $className
Class name to instantiate for $postType. Class
must inherit from \Tev\Post\Model\AbstractPost
Returns
Throws
Exception If class name does not inherit from \Tev\Post\Model\AbstractPost
|
public
string|null
|
#
registered( string $postType )
Get the registered class name for the given post type.
Get the registered class name for the given post type.
Parameters
- $postType
- Post type identifier
Returns
string|null Class name or null if no registration
|
public
Tev\Post\Model\AbstractPost
|
#
create( WP_Post $base = null, string $className = null )
Instantiate a post entity from a given post object.
Instantiate a post entity from a given post object.
Parameters
- $base
Optional. Base post object. If not
supplied will attempt to get the current
post from The Loop
- $className
Optional. Class name to instantiate. Will
use registered default if not supplied
Returns
Throws
Exception If $base is not given and not in the The Loop
|
public
Tev\Post\Model\AbstractPost
|
#
current( string $className = null )
Instantiate a post entity from the current post object.
Instantiate a post entity from the current post object.
Only works within The Loop.
Parameters
- $className
Optional. Class name to instantiate. Will
use registered default if not supplied
Returns
Throws
Exception If not in the The Loop
|