| @@ 68-82 (lines=15) @@ | ||
| 65 | * |
|
| 66 | * @throws ModelPostTypeMismatchException |
|
| 67 | */ |
|
| 68 | public function __construct($post = []) |
|
| 69 | { |
|
| 70 | $attributes = is_array($post) ? $post : []; |
|
| 71 | ||
| 72 | if (! $post instanceof WP_Post) { |
|
| 73 | $post = new WP_Post(new stdClass); |
|
| 74 | $post->post_type = static::postTypeId(); |
|
| 75 | } elseif ($post->post_type !== static::postTypeId()) { |
|
| 76 | throw new ModelPostTypeMismatchException(static::class, $post); |
|
| 77 | } |
|
| 78 | ||
| 79 | $this->setObject($post); |
|
| 80 | ||
| 81 | $this->fill($attributes); |
|
| 82 | } |
|
| 83 | ||
| 84 | /** |
|
| 85 | * Create a new instance from a Post with the given ID |
|
| @@ 52-66 (lines=15) @@ | ||
| 49 | * |
|
| 50 | * @throws TaxonomyMismatchException |
|
| 51 | */ |
|
| 52 | public function __construct($term = []) |
|
| 53 | { |
|
| 54 | $attributes = is_array($term) ? $term : []; |
|
| 55 | ||
| 56 | if (! $term instanceof WP_Term) { |
|
| 57 | $term = new WP_Term(new stdClass); |
|
| 58 | $term->taxonomy = static::TAXONOMY; |
|
| 59 | } elseif ($term->taxonomy != static::TAXONOMY) { |
|
| 60 | throw new TaxonomyMismatchException(); |
|
| 61 | } |
|
| 62 | ||
| 63 | $this->setObject($term); |
|
| 64 | ||
| 65 | $this->fill($attributes); |
|
| 66 | } |
|
| 67 | ||
| 68 | /** |
|
| 69 | * Create a new instance from a term ID. |
|