|
1 | 1 | # Pollora Entity WordPress Package |
2 | 2 |
|
3 | | -A modern PHP 8.2+ library for easily managing WordPress custom post types and taxonomies with a hexagonal architecture. |
| 3 | +A modern PHP 8.2+ library for easily managing WordPress custom post types and taxonomies with a fluent interface and hexagonal architecture. |
4 | 4 |
|
5 | | -## Test Structure |
| 5 | +## Features |
6 | 6 |
|
7 | | -The unit tests use PestPHP and simulate WordPress functions to test the code without requiring a complete WordPress installation. |
| 7 | +- 🚀 Modern PHP 8.2+ with type declarations |
| 8 | +- 🏗️ Fluent interface for easy configuration |
| 9 | +- 🔧 Built on top of [Extended CPTs](https://github.com/johnbillion/extended-cpts) library |
| 10 | +- 📐 Hexagonal architecture for better separation of concerns |
| 11 | +- 🧪 Fully tested with PestPHP |
| 12 | +- 💡 Intuitive method naming with dedicated methods for boolean properties |
8 | 13 |
|
9 | | -### WordPress Mocks |
| 14 | +## Installation |
10 | 15 |
|
11 | | -WordPress mocks are organized as follows: |
| 16 | +```bash |
| 17 | +composer require pollora/entity |
| 18 | +``` |
12 | 19 |
|
13 | | -1. `tests/helpers.php`: Global WordPress functions (global namespace) |
14 | | -2. `tests/ext_cpts_helpers.php`: Functions in the `ExtCPTs` namespace |
| 20 | +## Documentation |
15 | 21 |
|
16 | | -#### `helpers.php` File |
| 22 | +- [Post Types Documentation](docs/post-types.md) - Complete guide for creating and configuring custom post types |
| 23 | +- [Taxonomies Documentation](docs/taxonomies.md) - Complete guide for creating and configuring custom taxonomies |
17 | 24 |
|
18 | | -This file contains simulations of global WordPress functions such as: |
19 | | -- `add_action` (to intercept and execute callbacks) |
20 | | -- `register_post_type` and `register_taxonomy` |
21 | | -- `register_extended_post_type` and `register_extended_taxonomy` |
22 | | -- `is_admin` |
23 | | -- `did_action` |
24 | | -- `apply_filters` |
25 | | -- etc. |
| 25 | +## Quick Start |
26 | 26 |
|
27 | | -#### `ext_cpts_helpers.php` File |
| 27 | +### Post Types |
28 | 28 |
|
29 | | -This file contains simulations of WordPress functions in the `ExtCPTs` namespace used by the `johnbillion/extended-cpts` library: |
30 | | -- `ExtCPTs\apply_filters` |
31 | | -- `ExtCPTs\add_filter` |
32 | | -- `ExtCPTs\get_post_type_object` |
33 | | -- `ExtCPTs\get_taxonomies` |
34 | | -- `ExtCPTs\get_post_types` |
35 | | -- `ExtCPTs\is_wp_error` |
36 | | -- `ExtCPTs\do_action` |
37 | | -- etc. |
| 29 | +```php |
| 30 | +use Pollora\Entity\PostType; |
38 | 31 |
|
39 | | -### Bootstrap |
| 32 | +PostType::make('book', 'Book', 'Books') |
| 33 | + ->public() |
| 34 | + ->showInRest() |
| 35 | + ->hasArchive() |
| 36 | + ->supports(['title', 'editor', 'thumbnail']) |
| 37 | + ->menuIcon('dashicons-book-alt'); |
| 38 | +``` |
40 | 39 |
|
41 | | -The `tests/bootstrap.php` file loads the Composer autoloader, test helpers, and configures Mockery. |
| 40 | +### Taxonomies |
42 | 41 |
|
43 | | -## Code Structure |
| 42 | +```php |
| 43 | +use Pollora\Entity\Taxonomy; |
44 | 44 |
|
45 | | -The hexagonal architecture used here separates the code into three layers: |
| 45 | +Taxonomy::make('genre', 'book', 'Genre', 'Genres') |
| 46 | + ->hierarchical() |
| 47 | + ->showInRest() |
| 48 | + ->showInQuickEdit(); |
| 49 | +``` |
46 | 50 |
|
47 | | -1. **Domain**: Domain models (Entity, PostType, Taxonomy) |
48 | | -2. **Application**: Application services that orchestrate operations |
49 | | -3. **Adapter**: Adapters that allow interaction with WordPress |
| 51 | +## Architecture |
50 | 52 |
|
51 | | -The Domain layer is at the center and doesn't depend on any other layer. It defines ports (interfaces) that the adapters implement. |
| 53 | +This package follows hexagonal architecture principles: |
52 | 54 |
|
53 | | -The Application layer uses these interfaces to interact with the outside world, without knowing the implementation details. |
| 55 | +1. **Domain Layer**: Core business logic (Entity, PostType, Taxonomy) |
| 56 | +2. **Application Layer**: Services that orchestrate operations |
| 57 | +3. **Adapter Layer**: WordPress integration adapters |
54 | 58 |
|
55 | | -## Usage |
| 59 | +The Domain layer remains independent of external dependencies, defining interfaces (ports) that adapters implement. |
56 | 60 |
|
57 | | -```php |
58 | | -// Creating and registering a custom post type |
59 | | -use Pollora\Entity\PostType; |
| 61 | +## Testing |
60 | 62 |
|
61 | | -PostType::make('book', 'Book', 'Books') |
62 | | - ->setPublic(true) |
63 | | - ->setHasArchive(true) |
64 | | - ->setSupports(['title', 'editor', 'thumbnail']) |
65 | | - ->setMenuIcon('dashicons-book-alt') |
66 | | - ->register(); |
| 63 | +The package includes comprehensive unit tests using PestPHP with WordPress function mocks: |
67 | 64 |
|
68 | | -// Creating and registering a taxonomy |
69 | | -use Pollora\Entity\Taxonomy; |
| 65 | +```bash |
| 66 | +composer test |
| 67 | +``` |
70 | 68 |
|
71 | | -Taxonomy::make('genre', 'book', 'Genre', 'Genres') |
72 | | - ->setHierarchical(true) |
73 | | - ->setShowInRest(true) |
74 | | - ->register(); |
75 | | -``` |
| 69 | +### Test Structure |
| 70 | + |
| 71 | +- `tests/helpers.php`: Global WordPress function mocks |
| 72 | +- `tests/ext_cpts_helpers.php`: Extended CPTs namespace function mocks |
| 73 | +- `tests/bootstrap.php`: Test environment setup |
| 74 | + |
| 75 | +## License |
| 76 | + |
| 77 | +This package is open-source software licensed under the MIT license. |
0 commit comments