├── CHANGELOG.md
├── CONTRIBUTING.md
├── LICENSE.md
├── README.md
├── composer.json
├── src
├── Abstracts
│ ├── AbstractApp.php
│ ├── AbstractCustomContent.php
│ ├── AbstractFacade.php
│ ├── AbstractHook.php
│ ├── AbstractQuery.php
│ ├── AbstractRepository.php
│ └── AbstractServiceProvider.php
├── Admin
│ ├── Option.php
│ └── Page.php
├── Config
│ ├── Config.php
│ ├── ConfigFactory.php
│ └── ConfigRepository.php
├── Container
│ └── ContainerResolver.php
├── Content
│ ├── PostType.php
│ ├── Shortcode.php
│ └── Taxonomy.php
├── Contracts
│ ├── ArrInterface.php
│ ├── ExceptionHandlerInterface.php
│ ├── ExceptionLoggerInterface.php
│ └── JsonInterface.php
├── Database
│ ├── Parameter
│ │ ├── Author.php
│ │ ├── Category.php
│ │ ├── Comment.php
│ │ ├── Date.php
│ │ ├── DateArgument.php
│ │ ├── Fields.php
│ │ ├── Meta.php
│ │ ├── MetaArgument.php
│ │ ├── Order.php
│ │ ├── Pagination.php
│ │ ├── Password.php
│ │ ├── PostAndPage.php
│ │ ├── PostStatus.php
│ │ ├── PostType.php
│ │ ├── Search.php
│ │ ├── Tag.php
│ │ ├── Tax.php
│ │ └── TaxArgument.php
│ └── Query.php
├── Exceptions
│ ├── ContainerResolverException.php
│ ├── HookGroupException.php
│ ├── HookResolverException.php
│ ├── LoggerException.php
│ └── Support
│ │ ├── Handler.php
│ │ └── Logger.php
├── Gutenberg
│ ├── Block.php
│ ├── BlockLoader.php
│ └── Group.php
├── Hooks
│ ├── Action.php
│ ├── Filter.php
│ ├── Group.php
│ ├── Hook.php
│ ├── HookLoader.php
│ └── HookRepository.php
├── Providers
│ ├── ConfigServiceProvider.php
│ ├── ExceptionServiceProvider.php
│ ├── GutenbergServiceProvider.php
│ ├── HooksServiceProvider.php
│ └── ViewServiceProvider.php
├── Routing
│ └── Api.php
├── Support
│ ├── Arr.php
│ ├── Collection.php
│ ├── Is.php
│ └── Str.php
├── Traits
│ ├── AppSingleton.php
│ ├── Factoryable.php
│ ├── Macroable.php
│ └── QueryParameter.php
├── Utils
│ ├── Enqueue.php
│ ├── Post.php
│ ├── Template.php
│ ├── Theme.php
│ └── ThemeMod.php
└── View
│ └── View.php
└── stubs
├── app
└── Facades
│ ├── Action.stub
│ ├── Block.stub
│ ├── Config.stub
│ ├── Filter.stub
│ └── View.stub
└── config
└── app.stub
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All notable changes to `mjolnir` will be documented in this file
4 |
5 | ## 0.1 - 2021-05-30
6 |
7 | - initial release
8 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | Contributions are **welcome** and will be fully **credited**.
4 |
5 | Please read and understand the contribution guide before creating an issue or pull request.
6 |
7 | ## Etiquette
8 |
9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code
10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be
11 | extremely unfair for them to suffer abuse or anger for their hard work.
12 |
13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
14 | world that developers are civilized and selfless people.
15 |
16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
18 |
19 | ## Viability
20 |
21 | When requesting or submitting new features, first consider whether it might be useful to others. Open
22 | source projects are used by many developers, who may have entirely different needs to your own. Think about
23 | whether or not your feature is likely to be used by other users of the project.
24 |
25 | ## Procedure
26 |
27 | Before filing an issue:
28 |
29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
30 | - Check to make sure your feature suggestion isn't already present within the project.
31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
32 | - Check the pull requests tab to ensure that the feature isn't already in progress.
33 |
34 | Before submitting a pull request:
35 |
36 | - Check the codebase to ensure that your feature doesn't already exist.
37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
38 |
39 | ## Requirements
40 |
41 | If the project maintainer has any additional requirements, you will find them listed here.
42 |
43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer).
44 |
45 | - **Add tests!** - If you can.
46 |
47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
48 |
49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.
50 |
51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
52 |
53 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
54 |
55 | **Happy coding**!
56 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Dorin Lazar
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | # Mjölnir, WordPress Utility Framework
6 |
7 | [](https://github.com/codebjorn/mjolnir/releases)
8 | [](https://shields.io/)
9 |
10 | Mjölnir is small utility framework that gives utilities and possibilities to create WordPress plugins & themes using
11 | best of PHP. This package is compliant with PSR-1, PSR-2, PSR-4 and PSR-11.
12 |
13 | If you think this approach is not working, please open an issue and let's discuss :)
14 |
15 | ## Already made implementations
16 |
17 | To see already made implementations please check official boilerplates:
18 |
19 | - [Loki](https://github.com/codebjorn/loki) - WordPress Theme Boilerplate
20 | - [Thor](https://github.com/codebjorn/thor) - WordPress Plugin Boilerplate
21 |
22 | ## Pre-Requirements
23 |
24 | Before we proceed further:
25 |
26 | 1. I suggest you to read documentation of [PHP League Container](https://container.thephpleague.com/3.x/).
27 | Mjölnir it uses as to provide Dependency Injection in your application.
28 |
29 | 2. Also, if you will use default template engine, check documentation of [BladeOne](https://github.com/EFTEC/BladeOne)
30 |
31 | ## Requirements
32 |
33 | Requirements for this framework are:
34 |
35 | - PHP 7.1+
36 | - Composer
37 |
38 | ## Installation
39 |
40 | You can install framework via composer:
41 |
42 | ```bash
43 | composer require codebjorn/mjolnir
44 | ```
45 |
46 | Copy stubs from folder `stubs` to your folder, rename `app` folder if is need it and update `{{namespace}}` with
47 | application namespace
48 |
49 | ## In a nutshell
50 |
51 | Base of framework is dependency injection container, that stores some utility classes for: configuration, render,
52 | exception handling, hooks, blocks and all other services that you add and resolve, after all of that you add your
53 | service to hook.
54 |
55 | As example, you have class that add some WP functionality `PostTypes.php`, you resolve all dependencies
56 | in `ServiceProvider` and after apply it to a hook
57 |
58 | ## Utilities
59 |
60 | To explain how utilities works, let's take a look to each namespace that has utilities
61 |
62 | #### Admin
63 |
64 | Admin namespace contains utilities for add new features on admin side:
65 |
66 | 1. `Option.php` is a wrapper of functions related to Option Api, examples:
67 |
68 | ``` php
69 | \Mjolnir\Admin\Option::get('someOption');
70 | \Mjolnir\Admin\Option::update('someOption', 'someContent');
71 | ```
72 |
73 | 2. `Page.php` is a wrapper for all functions related to creating a page in admin, examples:
74 |
75 | ``` php
76 | \Mjolnir\Admin\Page::dashboard('Page', 'Page', 'read', 'page');
77 | \Mjolnir\Admin\Page::management('Page', 'Page', 'read', 'page');
78 | ```
79 |
80 | #### Content
81 |
82 | Content namespace contains utilities for creating different content solutions that WordPress has:
83 |
84 | 1. `PostType.php` allows you easy to create different custom post types, example:
85 |
86 | ``` php
87 | $books = \Mjolnir\Content\PostType::make('Books')
88 | ->supports(['title', 'editor'])
89 | ->public(true)
90 | ->showInRest(true);
91 |
92 | $books->register(); //Call register to exit creating of arguments
93 | ```
94 |
95 | 2. `Taxonomy.php` allows you easy to create different taxonomies, example:
96 |
97 | ``` php
98 | $countries = \Mjolnir\Content\Taxonomy::make('Countries')
99 | ->postTypes(['books'])
100 | ->public(true)
101 | ->showInRest(true);
102 |
103 | $countries->register(); //Call register to exit creating of arguments
104 | ```
105 |
106 | 3. `Shortcode.php` is a wrapper for functions related to Shortcode Api, example:
107 |
108 | ``` php
109 | \Mjolnir\Content\Shortcode::add('hello', [$this, 'hello']);
110 | \Mjolnir\Content\Shortcode::do('[hello]');
111 | ```
112 |
113 | #### Database
114 |
115 | Database namespace contains utilities for database interaction:
116 |
117 | 1. `Query.php` is a wrapper for WP Query arguments
118 |
119 | ``` php
120 | $metaQuery = new \Mjolnir\Database\Parameter\Meta([
121 | new \Mjolnir\Database\Parameter\MetaArgument('key', 'value', 'NUMERIC', '='),
122 | new \Mjolnir\Database\Parameter\MetaArgument('key', 'value', 'DATE', '>'),
123 | ]);
124 | $tax = new \Mjolnir\Database\Parameter\Tax(null, [
125 | new \Mjolnir\Database\Parameter\TaxArgument('taxonomy', 'field', 'term1'),
126 | new \Mjolnir\Database\Parameter\TaxArgument('taxonomy', 'field', 'term2'),
127 | ]);
128 |
129 | $posts = new \Mjolnir\Database\Query();
130 | $posts->postType('posts')
131 | ->meta($metaQuery)
132 | ->tax($tax)
133 | ->pagination(5);
134 |
135 | $posts->make(); // return new WP_Query
136 | $posts->get(); // returns Collection
137 | $posts->getRaw(); //return Array
138 | ```
139 |
140 | #### Routing
141 |
142 | Routing namespace contains utilities related to routing system of WordPress such as Api:
143 |
144 | 1. `Api.php` is a wrapper of all functions related to REST API, example:
145 |
146 | ``` php
147 | \Mjolnir\Routing\Api::make('/namespace', '/users')
148 | ->get([$this, 'getUsers'], '_return_true')
149 | ->post([$this, 'postUsers'], [$this, 'isAdmin']);
150 | ```
151 |
152 | #### Support
153 |
154 | Support namespace contains utilities that will help you work with data:
155 |
156 | 1. `Arr.php` is utility class that allows you to manipulate with array, examples:
157 |
158 | ``` php
159 | $first = \Mjolnir\Support\Arr::first($array);
160 | $key = \Mjolnir\Support\Arr::get($array, 'key');
161 | ```
162 |
163 | 2. `Collection.php` is class for working with arrays of data, examples:
164 |
165 | ``` php
166 | $collection = \Mjolnir\Support\Collection::make($array);
167 | $filtered = $collection->where('key', 'value');
168 | $reversed = $filtered->reverse();
169 | ```
170 |
171 | 2. `Is.php` is wrapper for functions to determine type of variable, examples:
172 |
173 | ``` php
174 | \Mjolnir\Support\Is::file($value);
175 | \Mjolnir\Support\Is::str($value);
176 | \Mjolnir\Support\Is::int($value);
177 | ```
178 |
179 | 3. `Str.php` is class to manipulate with string, examples:
180 |
181 | ``` php
182 | $string = \Mjolnir\Support\Str::make('some string');
183 | $reversed = $string->flip();
184 | $contains = $string->has('some');
185 | ```
186 |
187 | #### Utils
188 |
189 | Utils namespace contains utilities for working with plugins and themes:
190 |
191 | 1. `Enqueue.php` is wrapper of functions related to enqueue, example:
192 |
193 | ``` php
194 | \Mjolnir\Utils\Enqueue::style('theme-style', 'folder/style.css', [], '1.0.0', 'all');
195 | \Mjolnir\Utils\Enqueue::script('theme-script', 'folder/script.css', [], '1.0.0', true);
196 | \Mjolnir\Utils\Enqueue::all();
197 | ```
198 |
199 | 2. `Post.php` is wrapper of WP_Post that gives better API to get post, example:
200 |
201 | ``` php
202 | $currentPost = \Mjolnir\Utils\Post::current();
203 | $post = \Mjolnir\Utils\Post::get(1);
204 | $postId = $post->getId();
205 | $postSlug = $post->getSlug();
206 | ```
207 |
208 | 3. `Theme.php` is wrapper of functions related to theme, example:
209 |
210 | ``` php
211 | \Mjolnir\Utils\Theme::support('feature');
212 | \Mjolnir\Utils\Theme::textDomain('domain', 'path');
213 | \Mjolnir\Utils\Theme::mod()->set('item', 'value');
214 | \Mjolnir\Utils\Theme::mod()->get('item');
215 | ```
216 |
217 | ## Facades
218 |
219 | Facades are API that allows you to create a class that will get resolved class from container, check `stubs/app/Facades`
220 | to check default facades:
221 |
222 | 1. `Action.php` give access to action hook, example:
223 |
224 | ``` php
225 | {{Namespace}}\Facades\Action::do('hook');
226 | {{Namespace}}\Facades\Action::add('hook', [$this, 'function']);
227 | {{Namespace}}\Facades\Action::group('hook')
228 | ->add([$this, 'function'])
229 | ->add(SomeClass::class)
230 | ->add(function () {
231 | echo "something todo";
232 | });
233 | ```
234 |
235 | 2. `Filter.php` give access to filter hook, example:
236 |
237 | ``` php
238 | {{Namespace}}\Facades\Filter::apply('filter');
239 | {{Namespace}}\Facades\Filter::add('filter', [$this, 'function']);
240 | {{Namespace}}\Facades\Filter::group('filter')
241 | ->add([$this, 'function'])
242 | ->add(SomeClass::class)
243 | ->add(function () {
244 | echo "something todo";
245 | });
246 | ```
247 |
248 | 3. `Block.php` give access to class related to block, example:
249 |
250 | ``` php
251 | {{Namespace}}\Facades\Block::add('namespace', 'name');
252 | {{Namespace}}\Facades\Block::exists('namespace/name');
253 | {{Namespace}}\Facades\Block::group('namespace')
254 | ->add('name')
255 | ->add('name');
256 | ```
257 |
258 | 4. `Config.php` give access to config files, example:
259 |
260 | ``` php
261 | {{Namespace}}\Facades\Config::get('configFile.index.anotherIndex');
262 | {{Namespace}}\Facades\Config::get('app.view.folder');
263 | ```
264 |
265 | 5. `View.php` give access to view file for render, example:
266 |
267 | ``` php
268 | {{Namespace}}\Facades\View::render('books.single');
269 | {{Namespace}}\Facades\View::render('books/single.blade.php');
270 | ```
271 |
272 | ### Testing
273 |
274 | //TODO
275 |
276 | ### Changelog
277 |
278 | Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
279 |
280 | ## Contributing
281 |
282 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
283 |
284 | ### Security
285 |
286 | If you discover any security related issues, please email quotesun@gmail.com instead of using the issue tracker.
287 |
288 | ## Credits
289 |
290 | - [Dorin Lazar](https://github.com/codebjorn)
291 | - [All Contributors](../../contributors)
292 |
293 | ## License
294 |
295 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
296 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "codebjorn/mjolnir",
3 | "description": "WordPress Utility Framework",
4 | "keywords": [
5 | "quotesun",
6 | "mjolnir"
7 | ],
8 | "homepage": "https://github.com/quotesun/mjolnir",
9 | "license": "MIT",
10 | "type": "library",
11 | "authors": [
12 | {
13 | "name": "Dorin Lazar",
14 | "email": "quotesun@gmail.com",
15 | "role": "Developer"
16 | }
17 | ],
18 | "minimum-stability": "stable",
19 | "require": {
20 | "php": ">=7.1",
21 | "eftec/bladeone": "^3.52",
22 | "league/container": "^3.3"
23 | },
24 | "require-dev": {
25 | "phpunit/phpunit": "^7.0"
26 | },
27 | "autoload": {
28 | "psr-4": {
29 | "Mjolnir\\": "src"
30 | }
31 | },
32 | "autoload-dev": {
33 | "psr-4": {
34 | "Mjolnir\\Tests\\": "tests"
35 | }
36 | },
37 | "scripts": {
38 | "test": "vendor/bin/phpunit",
39 | "test-coverage": "vendor/bin/phpunit --coverage-html coverage"
40 | },
41 | "config": {
42 | "sort-packages": true
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/Abstracts/AbstractApp.php:
--------------------------------------------------------------------------------
1 | setPath($basePath);
30 |
31 | $this->addBaseShared();
32 | $this->addServiceProviders();
33 | $this->loadHooks();
34 | $this->loadBlocks();
35 | }
36 |
37 | /**
38 | * @return string|null
39 | */
40 | public function getPath()
41 | {
42 | return $this->basePath;
43 | }
44 |
45 | /**
46 | * @param $path
47 | */
48 | public function setPath($path)
49 | {
50 | $this->basePath = $path ?? dirname(__DIR__);
51 | }
52 |
53 | /**
54 | * @return void
55 | */
56 | private function addBaseShared()
57 | {
58 | $this->share('resolver', ContainerResolver::class)
59 | ->addArguments(['container' => $this]);
60 | }
61 |
62 | /**
63 | * @return void
64 | */
65 | private function addServiceProviders()
66 | {
67 | $this->addServiceProvider(ConfigServiceProvider::class);
68 |
69 | $providers = $this->config('app.providers');
70 | if ($providers) {
71 | foreach ($providers as $provider) {
72 | $this->addServiceProvider($provider);
73 | }
74 | }
75 | }
76 |
77 | /**
78 | * @return void
79 | */
80 | private function loadHooks()
81 | {
82 | HookLoader::load($this);
83 | }
84 |
85 | /**
86 | * @return void
87 | */
88 | private function loadBlocks()
89 | {
90 | BlockLoader::load($this);
91 | }
92 |
93 | /**
94 | * @param string $identifier
95 | * @return mixed
96 | */
97 | public function config(string $identifier)
98 | {
99 | return $this->get('configAccessor')
100 | ->get($identifier);
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/src/Abstracts/AbstractCustomContent.php:
--------------------------------------------------------------------------------
1 | name = $name;
33 | $this->arguments = $arguments ?: ['public' => true];
34 | }
35 |
36 | /**
37 | * @return array
38 | */
39 | public function getArguments()
40 | {
41 | return $this->arguments;
42 | }
43 |
44 | /**
45 | * @return mixed
46 | */
47 | abstract public function register();
48 |
49 | /**
50 | * @param array $labels
51 | * @return static
52 | */
53 | public function labels(array $labels)
54 | {
55 | $this->setArgument('labels', $labels);
56 | return $this;
57 | }
58 |
59 | /**
60 | * @param string $description
61 | * @return static
62 | */
63 | public function description(string $description)
64 | {
65 | $this->setArgument('description', $description);
66 | return $this;
67 | }
68 |
69 | /**
70 | * @param bool $hierarchical
71 | * @return static
72 | */
73 | public function hierarchical(bool $hierarchical = true)
74 | {
75 | $this->setArgument('hierarchical', $hierarchical);
76 | return $this;
77 | }
78 |
79 | /**
80 | * @param bool $value
81 | * @return static
82 | */
83 | public function public($value = true)
84 | {
85 | $this->setArgument('public', $value);
86 | return $this;
87 | }
88 |
89 | /**
90 | * @param bool $value
91 | * @return static
92 | */
93 | public function publicyQueryable(bool $value = true)
94 | {
95 | $this->setArgument('publicly_queryable', $value);
96 | return $this;
97 | }
98 |
99 | /**
100 | * @param $rewrite
101 | * @return static
102 | */
103 | public function rewrite($rewrite)
104 | {
105 | $this->setArgument('rewrite', $rewrite);
106 | return $this;
107 | }
108 |
109 | /**
110 | * @param bool $show
111 | * @return static
112 | */
113 | public function showUi(bool $show = true)
114 | {
115 | $this->setArgument('show_ui', $show);
116 | return $this;
117 | }
118 |
119 | /**
120 | * @param bool $show
121 | * @return static
122 | */
123 | public function showInMenu($show = true)
124 | {
125 | $this->setArgument('show_in_menu', $show);
126 | return $this;
127 | }
128 |
129 | /**
130 | * @param bool $show
131 | * @return static
132 | */
133 | public function showInNavMenus($show = true)
134 | {
135 | $this->setArgument('show_in_nav_menus', $show);
136 | return $this;
137 | }
138 |
139 | /**
140 | * @param bool $show
141 | * @return static
142 | */
143 | public function showInRest(bool $show = true)
144 | {
145 | $this->setArgument('show_in_rest', $show);
146 | return $this;
147 | }
148 |
149 | /**
150 | * @param string $base
151 | * @return static
152 | */
153 | public function restBase(string $base)
154 | {
155 | $this->setArgument('rest_base', $base);
156 | return $this;
157 | }
158 |
159 | /**
160 | * @param string $base
161 | * @return static
162 | */
163 | public function restControllerClass(string $base)
164 | {
165 | $this->setArgument('rest_controller_class', $base);
166 | return $this;
167 | }
168 |
169 | /**
170 | * @param string $key
171 | * @param $value
172 | */
173 | protected function setArgument(string $key, $value)
174 | {
175 | $this->arguments[$key] = $value;
176 | }
177 | }
178 |
--------------------------------------------------------------------------------
/src/Abstracts/AbstractFacade.php:
--------------------------------------------------------------------------------
1 | get($name);
40 | }
41 |
42 | return null;
43 | }
44 |
45 |
46 | /**
47 | * @param string $method
48 | * @param array $args
49 | * @return mixed
50 | * @throws RuntimeException
51 | */
52 | public static function __callStatic(string $method, array $args)
53 | {
54 | $instance = static::resolveInstance(static::$accessor);
55 |
56 | if (!$instance) {
57 | throw new RuntimeException('A facade root has not been set.');
58 | }
59 |
60 | return $instance->$method(...$args);
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/Abstracts/AbstractHook.php:
--------------------------------------------------------------------------------
1 | app = $app;
26 | }
27 |
28 | /**
29 | * @param string $tag
30 | * @return Group
31 | */
32 | public function group(string $tag): Group
33 | {
34 | return new Group($this->app, $this->action, $tag);
35 | }
36 |
37 | /**
38 | * @param string $tag
39 | * @param $function
40 | * @param int $priority
41 | * @param int $args
42 | */
43 | public function add(string $tag, $function, int $priority = 10, int $args = 1)
44 | {
45 | $hook = new Hook($this->action, $tag, [
46 | 'function' => $function,
47 | 'priority' => $priority,
48 | 'args' => $args
49 | ]);
50 |
51 | $this->app->extend('hooks')
52 | ->addMethodCall('add', [$hook]);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/Abstracts/AbstractQuery.php:
--------------------------------------------------------------------------------
1 | arguments = $arguments;
22 | }
23 |
24 | /**
25 | * @return mixed
26 | */
27 | abstract public function make();
28 |
29 | /**
30 | * @return mixed
31 | */
32 | abstract public function get();
33 |
34 | /**
35 | * @return mixed
36 | */
37 | abstract public function getRaw();
38 |
39 | /**
40 | * @param $concrete
41 | * @param $object
42 | * @param mixed ...$arguments
43 | * @return array|null
44 | * @throws ReflectionException
45 | */
46 | protected function updateArgs($concrete, $object, ...$arguments): ?array
47 | {
48 | if (Is::obj($object)) {
49 | $newArgs = $object->toArray();
50 | } else {
51 | $args = Collection::make($arguments)->prepend($object);
52 | $reflection = new ReflectionClass($concrete);
53 | $obj = $reflection->newInstanceArgs($args->toArray());
54 | $newArgs = $obj->toArray();
55 | }
56 |
57 | $this->arguments = array_merge_recursive($this->arguments, $newArgs);
58 |
59 | return $this->arguments;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/Abstracts/AbstractRepository.php:
--------------------------------------------------------------------------------
1 | items = $items;
23 | }
24 |
25 | /**
26 | * @return array
27 | */
28 | public function all(): array
29 | {
30 | return $this->items;
31 | }
32 |
33 | /**
34 | * @return Collection
35 | */
36 | public function collection(): Collection
37 | {
38 | return new Collection($this->items);
39 | }
40 |
41 | /**
42 | * @param string $key
43 | * @return false|mixed
44 | */
45 | public function get(string $key)
46 | {
47 | return $this->items[$key];
48 | }
49 |
50 | /**
51 | * @param string $key
52 | * @return bool|false
53 | */
54 | public function has(string $key): bool
55 | {
56 | return isset($this->items[$key]) ?? false;
57 | }
58 |
59 | /**
60 | * @param $element
61 | */
62 | public function add($element)
63 | {
64 | $this->items[] = $element;
65 | }
66 |
67 | /**
68 | * @param array $items
69 | */
70 | public function set(array $items)
71 | {
72 | $this->items = $items;
73 | }
74 |
75 | /**
76 | * @return ArrayIterator
77 | */
78 | public function getIterator(): ArrayIterator
79 | {
80 | return new ArrayIterator($this->items);
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/Abstracts/AbstractServiceProvider.php:
--------------------------------------------------------------------------------
1 | container = $container;
20 | }
21 |
22 | /**
23 | * @param string $identifier
24 | * @return mixed|null
25 | */
26 | public function get(string $identifier)
27 | {
28 | return $this->resolveIdentifier($identifier);
29 | }
30 |
31 | /**
32 | * @param string $identifier
33 | * @return mixed|null
34 | */
35 | private function resolveIdentifier(string $identifier)
36 | {
37 | $keys = Collection::make(explode('.', $identifier));
38 | $config = $this->container->get('config');
39 |
40 | if (!$config->has($keys->first())) {
41 | return null;
42 | }
43 |
44 | if ($keys->count() === 1) {
45 | return $config->get($keys->first())
46 | ->toArray();
47 | }
48 |
49 | $identifierWithoutFirst = $keys->except(0)->implode('.');
50 | $items = $config->get($keys->first())
51 | ->toArray();
52 |
53 | return Arr::get($items, $identifierWithoutFirst);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/Config/ConfigFactory.php:
--------------------------------------------------------------------------------
1 | buildInstances();
31 | }
32 |
33 | /**
34 | * @return array
35 | */
36 | public function getInstances(): array
37 | {
38 | return $this->instances;
39 | }
40 |
41 | /**
42 | * @param string $identifier
43 | * @return false|mixed
44 | */
45 | public function getInstance(string $identifier)
46 | {
47 | if (!$this->hasInstance($identifier)) {
48 | return $this->instances[$identifier];
49 | }
50 |
51 | return false;
52 | }
53 |
54 | /**
55 | * @param string $identifier
56 | * @param $value
57 | * @return $this
58 | */
59 | public function setInstance(string $identifier, $value): ConfigFactory
60 | {
61 | if (!$this->hasInstance($identifier)) {
62 | $this->instances[$identifier] = new ConfigFactory($value);
63 | }
64 |
65 | return $this;
66 | }
67 |
68 | /**
69 | * @return $this
70 | * @throws Exception
71 | */
72 | public function buildInstances(): ConfigFactory
73 | {
74 | foreach ($this->dirFiles() as $file) {
75 | $configName = pathinfo($file, PATHINFO_FILENAME);
76 | $config = include "{$this->path}/{$file}";
77 |
78 | if ($config === null) {
79 | throw new Exception('Config file is empty');
80 | }
81 |
82 | if (!$this->hasInstance($configName)) {
83 | $this->instances[$configName] = new Collection($config);
84 | }
85 | }
86 |
87 | return $this;
88 | }
89 |
90 | /**
91 | * @param string $identifier
92 | * @return bool
93 | */
94 | public function hasInstance(string $identifier): bool
95 | {
96 | return array_key_exists($identifier, $this->instances);
97 | }
98 |
99 | /**
100 | * @return array|false
101 | */
102 | private function dirFiles()
103 | {
104 | return array_diff(scandir($this->path), array('..', '.'));
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/src/Config/ConfigRepository.php:
--------------------------------------------------------------------------------
1 | container = $container;
28 | $this->function = $function ?? "";
29 | }
30 |
31 | /**
32 | * @param mixed $function
33 | * @return callable
34 | * @throws ContainerResolverException
35 | */
36 | public function resolve($function): callable
37 | {
38 | return (new static($this->container, $function))
39 | ->return();
40 | }
41 |
42 | /**
43 | * @return array|mixed|object
44 | * @throws ContainerResolverException
45 | */
46 | private function return()
47 | {
48 | if (Is::arr($this->function)) {
49 | return $this->array();
50 | }
51 |
52 | if (Is::callable($this->function)) {
53 | return $this->callable();
54 | }
55 |
56 | if (Is::str($this->function)) {
57 | return $this->invoke();
58 | }
59 |
60 | throw new ContainerResolverException('Incorrect type of given function in hook');
61 | }
62 |
63 | /**
64 | * @return array
65 | * @throws ContainerResolverException
66 | */
67 | private function array()
68 | {
69 | if (Is::obj($this->function['0'])) {
70 | return $this->function;
71 | }
72 |
73 | if (!$this->container->has($this->function['0'])) {
74 | throw new ContainerResolverException('Class or method applied to hook not exists');
75 | }
76 |
77 | return [$this->container->get($this->function['0']), $this->function['1']];
78 | }
79 |
80 | /**
81 | * @return mixed
82 | */
83 | private function callable()
84 | {
85 | return $this->function;
86 | }
87 |
88 | /**
89 | * @return array|mixed|object
90 | * @throws ContainerResolverException
91 | */
92 | private function invoke()
93 | {
94 | if (!class_exists($this->function) ||
95 | !$this->container->has($this->function)) {
96 | throw new ContainerResolverException('Class or method applied to hook not exists');
97 | }
98 |
99 | return $this->container->get($this->function);
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/src/Content/PostType.php:
--------------------------------------------------------------------------------
1 | arguments = $arguments ?: [
18 | 'label' => ucfirst($name),
19 | 'public' => true
20 | ];
21 | }
22 |
23 | /**
24 | * @return void
25 | */
26 | public function register()
27 | {
28 | register_post_type($this->name, $this->arguments);
29 | }
30 |
31 | /**
32 | * @param string $label
33 | * @return $this
34 | */
35 | public function label(string $label): PostType
36 | {
37 | $this->setArgument('label', $label);
38 | return $this;
39 | }
40 |
41 | /**
42 | * @param int $position
43 | * @return $this
44 | */
45 | public function menuPosition(int $position = 5): PostType
46 | {
47 | $this->setArgument('menu_position', $position);
48 | return $this;
49 | }
50 |
51 | /**
52 | * @param string $icon
53 | * @return $this
54 | */
55 | public function menuIcon(string $icon): PostType
56 | {
57 | $this->setArgument('icon', $icon);
58 | return $this;
59 | }
60 |
61 | /**
62 | * @param array|string[] $supports
63 | * @return $this
64 | */
65 | public function supports(array $supports = ['title']): PostType
66 | {
67 | $this->setArgument('supports', $supports);
68 | return $this;
69 | }
70 |
71 | /**
72 | * @param callable $callback
73 | * @return $this
74 | */
75 | public function registerMetabox(callable $callback): PostType
76 | {
77 | $this->setArgument('register_meta_box_cb', $callback);
78 | return $this;
79 | }
80 |
81 | /**
82 | * @param array $taxonomies
83 | * @return $this
84 | */
85 | public function taxonomies(array $taxonomies): PostType
86 | {
87 | $this->setArgument('taxonomies', $taxonomies);
88 | return $this;
89 | }
90 |
91 | /**
92 | * @param bool $hasArchive
93 | * @return $this
94 | */
95 | public function hasArchive(bool $hasArchive = true): PostType
96 | {
97 | $this->setArgument('has_archive', $hasArchive);
98 | return $this;
99 | }
100 |
101 | }
102 |
--------------------------------------------------------------------------------
/src/Content/Shortcode.php:
--------------------------------------------------------------------------------
1 | name);
19 | $this->arguments = $arguments ?: [
20 | 'labels' => [
21 | 'name' => _x($uName, 'taxonomy general name', 'app'),
22 | 'singular_name' => _x($uName, 'taxonomy singular name', 'app'),
23 | 'search_items' => __('Search ' . $uName, 'app'),
24 | 'all_items' => __('All ' . $uName, 'app'),
25 | 'parent_item' => __('Parent ' . $uName, 'app'),
26 | 'parent_item_colon' => __('Parent: ' . $uName, 'app'),
27 | 'edit_item' => __('Edit ' . $uName, 'app'),
28 | 'update_item' => __('Update ' . $uName, 'app'),
29 | 'add_new_item' => __('Add New ' . $uName, 'app'),
30 | 'new_item_name' => __('New Genre ' . $uName, 'app'),
31 | 'menu_name' => __($uName, 'app'),
32 | ],
33 | 'public' => true
34 | ];
35 | }
36 |
37 | /**
38 | * @return void
39 | */
40 | public function register()
41 | {
42 | register_taxonomy($this->name, $this->postTypes ?? ['post'], $this->arguments);
43 | }
44 |
45 | /**
46 | * @param array $postTypes
47 | * @return $this
48 | */
49 | public function postTypes(array $postTypes): Taxonomy
50 | {
51 | $this->postTypes = $postTypes;
52 | return $this;
53 | }
54 |
55 | /**
56 | * @param bool $show
57 | * @return $this
58 | */
59 | public function showTagCloud(bool $show = true): Taxonomy
60 | {
61 | $this->setArgument('show_tagcloud', $show);
62 | return $this;
63 | }
64 |
65 | /**
66 | * @param bool $show
67 | * @return $this
68 | */
69 | public function showInQuickEdit(bool $show = true): Taxonomy
70 | {
71 | $this->setArgument('show_in_quick_edit', $show);
72 | return $this;
73 | }
74 |
75 | /**
76 | * @param bool $show
77 | * @return $this
78 | */
79 | public function showAdminColumn(bool $show = false): Taxonomy
80 | {
81 | $this->setArgument('show_admin_column', $show);
82 | return $this;
83 | }
84 |
85 | /**
86 | * @param $metabox
87 | * @return $this
88 | */
89 | public function metabox($metabox): Taxonomy
90 | {
91 | $this->setArgument('meta_box_cb', $metabox);
92 | return $this;
93 | }
94 |
95 | /**
96 | * @param $metabox
97 | * @return $this
98 | */
99 | public function metaboxSanitize($metabox): Taxonomy
100 | {
101 | $this->setArgument('meta_box_sanitize_cb', $metabox);
102 | return $this;
103 | }
104 |
105 | /**
106 | * @param array $capabilities
107 | * @return $this
108 | */
109 | public function capabilities(array $capabilities): Taxonomy
110 | {
111 | $this->setArgument('capabilities', $capabilities);
112 | return $this;
113 | }
114 |
115 | /**
116 | * @param $term
117 | * @return $this
118 | */
119 | public function defaultTerm($term): Taxonomy
120 | {
121 | $this->setArgument('default_term', $term);
122 | return $this;
123 | }
124 |
125 | }
126 |
--------------------------------------------------------------------------------
/src/Contracts/ArrInterface.php:
--------------------------------------------------------------------------------
1 | author = $author;
38 | $this->author_name = $author_name;
39 | $this->author__in = $author__in;
40 | $this->author__not_in = $author__not_in;
41 | }
42 |
43 | /**
44 | * @return int|null
45 | */
46 | public function getAuthor()
47 | {
48 | return $this->author;
49 | }
50 |
51 | /**
52 | * @return string|null
53 | */
54 | public function getName()
55 | {
56 | return $this->author_name;
57 | }
58 |
59 | /**
60 | * @return array|null
61 | */
62 | public function getIn()
63 | {
64 | return $this->author__in;
65 | }
66 |
67 | /**
68 | * @return array|null
69 | */
70 | public function getNotIn()
71 | {
72 | return $this->author__not_in;
73 | }
74 |
75 | /**
76 | * @param int|null $author
77 | */
78 | public function setAuthor($author)
79 | {
80 | $this->author = $author;
81 | }
82 |
83 | /**
84 | * @param string|null $author_name
85 | */
86 | public function setName($author_name)
87 | {
88 | $this->author_name = $author_name;
89 | }
90 |
91 | /**
92 | * @param array|null $author__in
93 | */
94 | public function setIn($author__in)
95 | {
96 | $this->author__in = $author__in;
97 | }
98 |
99 | /**
100 | * @param array|null $author__not_in
101 | */
102 | public function setNotIn($author__not_in)
103 | {
104 | $this->author__not_in = $author__not_in;
105 | }
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/src/Database/Parameter/Category.php:
--------------------------------------------------------------------------------
1 | cat = $cat;
43 | $this->category_name = $category_name;
44 | $this->category__and = $category__and;
45 | $this->category__in = $category__in;
46 | $this->category__not_in = $category__not_in;
47 | }
48 |
49 | /**
50 | * @return mixed|null
51 | */
52 | public function getCat()
53 | {
54 | return $this->cat;
55 | }
56 |
57 | /**
58 | * @return string|null
59 | */
60 | public function getCategoryName()
61 | {
62 | return $this->category_name;
63 | }
64 |
65 | /**
66 | * @return array|null
67 | */
68 | public function getCategoryAnd()
69 | {
70 | return $this->category__and;
71 | }
72 |
73 | /**
74 | * @return array|null
75 | */
76 | public function getCategoryIn()
77 | {
78 | return $this->category__in;
79 | }
80 |
81 | /**
82 | * @return array|null
83 | */
84 | public function getCategoryNotIn()
85 | {
86 | return $this->category__not_in;
87 | }
88 |
89 | /**
90 | * @param mixed|null $cat
91 | */
92 | public function setCat($cat)
93 | {
94 | $this->cat = $cat;
95 | }
96 |
97 | /**
98 | * @param string|null $category_name
99 | */
100 | public function setCategoryName($category_name)
101 | {
102 | $this->category_name = $category_name;
103 | }
104 |
105 | /**
106 | * @param array|null $category__and
107 | */
108 | public function setCategoryAnd($category__and)
109 | {
110 | $this->category__and = $category__and;
111 | }
112 |
113 | /**
114 | * @param array|null $category__in
115 | */
116 | public function setCategoryIn($category__in)
117 | {
118 | $this->category__in = $category__in;
119 | }
120 |
121 | /**
122 | * @param array|null $category__not_in
123 | */
124 | public function setCategoryNotIn($category__not_in)
125 | {
126 | $this->category__not_in = $category__not_in;
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/src/Database/Parameter/Comment.php:
--------------------------------------------------------------------------------
1 | comment_count = $comment_count;
19 | }
20 |
21 | /**
22 | * @return null
23 | */
24 | public function getCommentCount()
25 | {
26 | return $this->comment_count;
27 | }
28 |
29 | /**
30 | * @param null $comment_count
31 | */
32 | public function setCommentCount($comment_count)
33 | {
34 | $this->comment_count = $comment_count;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Database/Parameter/Date.php:
--------------------------------------------------------------------------------
1 | date_query = $date_query;
65 | $this->year = $year;
66 | $this->monthnum = $monthnum;
67 | $this->w = $w;
68 | $this->day = $day;
69 | $this->hour = $hour;
70 | $this->minute = $minute;
71 | $this->second = $second;
72 | $this->m = $m;
73 | }
74 |
75 | /**
76 | * @return array
77 | */
78 | public function getDateQuery(): array
79 | {
80 | return $this->date_query;
81 | }
82 |
83 | /**
84 | * @param array $date_query
85 | */
86 | public function setDateQuery(array $date_query)
87 | {
88 | $this->date_query = $date_query;
89 | }
90 |
91 | /**
92 | * @return int|null
93 | */
94 | public function getYear()
95 | {
96 | return $this->year;
97 | }
98 |
99 | /**
100 | * @param int|null $year
101 | */
102 | public function setYear($year)
103 | {
104 | $this->year = $year;
105 | }
106 |
107 | /**
108 | * @return int|null
109 | */
110 | public function getMonthnum()
111 | {
112 | return $this->monthnum;
113 | }
114 |
115 | /**
116 | * @param int|null $monthnum
117 | */
118 | public function setMonthnum($monthnum)
119 | {
120 | $this->monthnum = $monthnum;
121 | }
122 |
123 | /**
124 | * @return int|null
125 | */
126 | public function getW()
127 | {
128 | return $this->w;
129 | }
130 |
131 | /**
132 | * @param int|null $w
133 | */
134 | public function setW($w)
135 | {
136 | $this->w = $w;
137 | }
138 |
139 | /**
140 | * @return int|null
141 | */
142 | public function getDay()
143 | {
144 | return $this->day;
145 | }
146 |
147 | /**
148 | * @param int|null $day
149 | */
150 | public function setDay($day)
151 | {
152 | $this->day = $day;
153 | }
154 |
155 | /**
156 | * @return int|null
157 | */
158 | public function getHour()
159 | {
160 | return $this->hour;
161 | }
162 |
163 | /**
164 | * @param int|null $hour
165 | */
166 | public function setHour($hour)
167 | {
168 | $this->hour = $hour;
169 | }
170 |
171 | /**
172 | * @return int|null
173 | */
174 | public function getMinute()
175 | {
176 | return $this->minute;
177 | }
178 |
179 | /**
180 | * @param int|null $minute
181 | */
182 | public function setMinute($minute)
183 | {
184 | $this->minute = $minute;
185 | }
186 |
187 | /**
188 | * @return int|null
189 | */
190 | public function getSecond()
191 | {
192 | return $this->second;
193 | }
194 |
195 | /**
196 | * @param int|null $second
197 | */
198 | public function setSecond($second)
199 | {
200 | $this->second = $second;
201 | }
202 |
203 | /**
204 | * @return int|null
205 | */
206 | public function getM()
207 | {
208 | return $this->m;
209 | }
210 |
211 | /**
212 | * @param int|null $m
213 | */
214 | public function setM($m)
215 | {
216 | $this->m = $m;
217 | }
218 |
219 | /**
220 | * @return array
221 | */
222 | public function toArray(): array
223 | {
224 | $props = Collection::make(get_class_vars(static::class));
225 | $resolvedProps = $props->map(function ($item, $index) {
226 | if ($index === "date_query") {
227 | return Collection::make($this->{$index} ?? [])
228 | ->map(function ($class) {
229 | return Is::obj($class) ? $class->toArray() : $class;
230 | })
231 | ->toArray();
232 | }
233 |
234 | return $this->{$index};
235 | });
236 |
237 | return $resolvedProps->filter(function ($item) {
238 | return $item !== null;
239 | })
240 | ->toArray();
241 | }
242 | }
243 |
--------------------------------------------------------------------------------
/src/Database/Parameter/DateArgument.php:
--------------------------------------------------------------------------------
1 | year = $year;
83 | $this->month = $month;
84 | $this->week = $week;
85 | $this->day = $day;
86 | $this->hour = $hour;
87 | $this->minute = $minute;
88 | $this->second = $second;
89 | $this->after = $after;
90 | $this->before = $before;
91 | $this->inclusive = $inclusive;
92 | $this->compare = $compare;
93 | $this->column = $column;
94 | $this->relation = $relation;
95 | }
96 |
97 | /**
98 | * @return int|null
99 | */
100 | public function getYear()
101 | {
102 | return $this->year;
103 | }
104 |
105 | /**
106 | * @param int|null $year
107 | */
108 | public function setYear($year)
109 | {
110 | $this->year = $year;
111 | }
112 |
113 | /**
114 | * @return int|null
115 | */
116 | public function getMonth()
117 | {
118 | return $this->month;
119 | }
120 |
121 | /**
122 | * @param int|null $month
123 | */
124 | public function setMonth($month)
125 | {
126 | $this->month = $month;
127 | }
128 |
129 | /**
130 | * @return int|null
131 | */
132 | public function getWeek()
133 | {
134 | return $this->week;
135 | }
136 |
137 | /**
138 | * @param int|null $week
139 | */
140 | public function setWeek($week)
141 | {
142 | $this->week = $week;
143 | }
144 |
145 | /**
146 | * @return int|null
147 | */
148 | public function getDay()
149 | {
150 | return $this->day;
151 | }
152 |
153 | /**
154 | * @param int|null $day
155 | */
156 | public function setDay($day)
157 | {
158 | $this->day = $day;
159 | }
160 |
161 | /**
162 | * @return int|null
163 | */
164 | public function getHour()
165 | {
166 | return $this->hour;
167 | }
168 |
169 | /**
170 | * @param int|null $hour
171 | */
172 | public function setHour($hour)
173 | {
174 | $this->hour = $hour;
175 | }
176 |
177 | /**
178 | * @return int|null
179 | */
180 | public function getMinute()
181 | {
182 | return $this->minute;
183 | }
184 |
185 | /**
186 | * @param int|null $minute
187 | */
188 | public function setMinute($minute)
189 | {
190 | $this->minute = $minute;
191 | }
192 |
193 | /**
194 | * @return int|null
195 | */
196 | public function getSecond()
197 | {
198 | return $this->second;
199 | }
200 |
201 | /**
202 | * @param int|null $second
203 | */
204 | public function setSecond($second)
205 | {
206 | $this->second = $second;
207 | }
208 |
209 | /**
210 | * @return array|string|null
211 | */
212 | public function getAfter()
213 | {
214 | return $this->after;
215 | }
216 |
217 | /**
218 | * @param array|string|null $after
219 | */
220 | public function setAfter($after)
221 | {
222 | $this->after = $after;
223 | }
224 |
225 | /**
226 | * @return array|string|null
227 | */
228 | public function getBefore()
229 | {
230 | return $this->before;
231 | }
232 |
233 | /**
234 | * @param array|string|null $before
235 | */
236 | public function setBefore($before)
237 | {
238 | $this->before = $before;
239 | }
240 |
241 | /**
242 | * @return bool|null
243 | */
244 | public function getInclusive()
245 | {
246 | return $this->inclusive;
247 | }
248 |
249 | /**
250 | * @param bool|null $inclusive
251 | */
252 | public function setInclusive($inclusive)
253 | {
254 | $this->inclusive = $inclusive;
255 | }
256 |
257 | /**
258 | * @return string|null
259 | */
260 | public function getCompare()
261 | {
262 | return $this->compare;
263 | }
264 |
265 | /**
266 | * @param string|null $compare
267 | */
268 | public function setCompare($compare)
269 | {
270 | $this->compare = $compare;
271 | }
272 |
273 | /**
274 | * @return string|null
275 | */
276 | public function getColumn()
277 | {
278 | return $this->column;
279 | }
280 |
281 | /**
282 | * @param string|null $column
283 | */
284 | public function setColumn($column)
285 | {
286 | $this->column = $column;
287 | }
288 |
289 | /**
290 | * @return string|null
291 | */
292 | public function getRelation()
293 | {
294 | return $this->relation;
295 | }
296 |
297 | /**
298 | * @param string|null $relation
299 | */
300 | public function setRelation($relation)
301 | {
302 | $this->relation = $relation;
303 | }
304 | }
305 |
--------------------------------------------------------------------------------
/src/Database/Parameter/Fields.php:
--------------------------------------------------------------------------------
1 | fields = $fields;
23 | }
24 |
25 | /**
26 | * @return string|null
27 | */
28 | public function getFields()
29 | {
30 | return $this->fields;
31 | }
32 |
33 | /**
34 | * @param string|null $fields
35 | */
36 | public function setFields($fields)
37 | {
38 | $this->fields = $fields;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/Database/Parameter/Meta.php:
--------------------------------------------------------------------------------
1 | meta_query = $meta_query;
45 | $this->meta_key = $meta_key;
46 | $this->meta_value = $meta_value;
47 | $this->meta_value_num = $meta_value_num;
48 | $this->meta_compare = $meta_compare;
49 | }
50 |
51 | /**
52 | * @return array|null
53 | */
54 | public function getMetaQuery()
55 | {
56 | return $this->meta_query;
57 | }
58 |
59 | /**
60 | * @param array|null $meta_query
61 | */
62 | public function setMetaQuery($meta_query)
63 | {
64 | $this->meta_query = $meta_query;
65 | }
66 |
67 | /**
68 | * @return string|null
69 | */
70 | public function getMetaKey()
71 | {
72 | return $this->meta_key;
73 | }
74 |
75 | /**
76 | * @param string|null $meta_key
77 | */
78 | public function setMetaKey($meta_key)
79 | {
80 | $this->meta_key = $meta_key;
81 | }
82 |
83 | /**
84 | * @return string|null
85 | */
86 | public function getMetaValue()
87 | {
88 | return $this->meta_value;
89 | }
90 |
91 | /**
92 | * @param string|null $meta_value
93 | */
94 | public function setMetaValue($meta_value)
95 | {
96 | $this->meta_value = $meta_value;
97 | }
98 |
99 | /**
100 | * @return string|null
101 | */
102 | public function getMetaValueNum()
103 | {
104 | return $this->meta_value_num;
105 | }
106 |
107 | /**
108 | * @param string|null $meta_value_num
109 | */
110 | public function setMetaValueNum($meta_value_num)
111 | {
112 | $this->meta_value_num = $meta_value_num;
113 | }
114 |
115 | /**
116 | * @return string|null
117 | */
118 | public function getMetaCompare()
119 | {
120 | return $this->meta_compare;
121 | }
122 |
123 | /**
124 | * @param string|null $meta_compare
125 | */
126 | public function setMetaCompare($meta_compare)
127 | {
128 | $this->meta_compare = $meta_compare;
129 | }
130 |
131 | /**
132 | * @return array
133 | */
134 | public function toArray()
135 | {
136 | $props = Collection::make(get_class_vars(static::class));
137 | $resolvedProps = $props->map(function ($item, $index) {
138 | if ($index === "meta_query") {
139 | return Collection::make($this->{$index} ?? [])
140 | ->map(function ($class) {
141 | return Is::obj($class) ? $class->toArray() : $class;
142 | })
143 | ->toArray();
144 | }
145 |
146 | return $this->{$index};
147 | });
148 |
149 | return $resolvedProps->filter(function ($item) {
150 | return $item !== null;
151 | })
152 | ->toArray();
153 | }
154 | }
155 |
--------------------------------------------------------------------------------
/src/Database/Parameter/MetaArgument.php:
--------------------------------------------------------------------------------
1 | key = $key;
38 | $this->value = $value;
39 | $this->type = $type;
40 | $this->compare = $compare;
41 | }
42 |
43 | /**
44 | * @return string|null
45 | */
46 | public function getKey()
47 | {
48 | return $this->key;
49 | }
50 |
51 | /**
52 | * @param string|null $key
53 | */
54 | public function setKey($key)
55 | {
56 | $this->key = $key;
57 | }
58 |
59 | /**
60 | * @return null
61 | */
62 | public function getValue()
63 | {
64 | return $this->value;
65 | }
66 |
67 | /**
68 | * @param null $value
69 | */
70 | public function setValue($value)
71 | {
72 | $this->value = $value;
73 | }
74 |
75 | /**
76 | * @return string|null
77 | */
78 | public function getType()
79 | {
80 | return $this->type;
81 | }
82 |
83 | /**
84 | * @param string|null $type
85 | */
86 | public function setType($type)
87 | {
88 | $this->type = $type;
89 | }
90 |
91 | /**
92 | * @return string|null
93 | */
94 | public function getCompare()
95 | {
96 | return $this->compare;
97 | }
98 |
99 | /**
100 | * @param string|null $compare
101 | */
102 | public function setCompare($compare)
103 | {
104 | $this->compare = $compare;
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/src/Database/Parameter/Order.php:
--------------------------------------------------------------------------------
1 | order = $order;
28 | $this->orderby = $orderby;
29 | }
30 |
31 | /**
32 | * @return string|null
33 | */
34 | public function getOrder()
35 | {
36 | return $this->order;
37 | }
38 |
39 | /**
40 | * @param string|null $order
41 | */
42 | public function setOrder($order)
43 | {
44 | $this->order = $order;
45 | }
46 |
47 | /**
48 | * @return string|null
49 | */
50 | public function getOrderby()
51 | {
52 | return $this->orderby;
53 | }
54 |
55 | /**
56 | * @param string|null $orderby
57 | */
58 | public function setOrderby($orderby)
59 | {
60 | $this->orderby = $orderby;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/Database/Parameter/Pagination.php:
--------------------------------------------------------------------------------
1 | posts_per_page = $posts_per_page;
53 | $this->nopaging = $nopaging;
54 | $this->paged = $paged;
55 | $this->posts_per_archive_page = $posts_per_archive_page;
56 | $this->offset = $offset;
57 | $this->page = $page;
58 | $this->ignore_sticky_posts = $ignore_sticky_posts;
59 | }
60 |
61 | /**
62 | * @return int|null
63 | */
64 | public function getPostsPerPage()
65 | {
66 | return $this->posts_per_page;
67 | }
68 |
69 | /**
70 | * @param int|null $posts_per_page
71 | */
72 | public function setPostsPerPage($posts_per_page)
73 | {
74 | $this->posts_per_page = $posts_per_page;
75 | }
76 |
77 | /**
78 | * @return bool|null
79 | */
80 | public function getNopaging()
81 | {
82 | return $this->nopaging;
83 | }
84 |
85 | /**
86 | * @param bool|null $nopaging
87 | */
88 | public function setNopaging($nopaging)
89 | {
90 | $this->nopaging = $nopaging;
91 | }
92 |
93 | /**
94 | * @return int|null
95 | */
96 | public function getPaged()
97 | {
98 | return $this->paged;
99 | }
100 |
101 | /**
102 | * @param int|null $paged
103 | */
104 | public function setPaged($paged)
105 | {
106 | $this->paged = $paged;
107 | }
108 |
109 | /**
110 | * @return int|null
111 | */
112 | public function getPostsPerArchivePage()
113 | {
114 | return $this->posts_per_archive_page;
115 | }
116 |
117 | /**
118 | * @param int|null $posts_per_archive_page
119 | */
120 | public function setPostsPerArchivePage($posts_per_archive_page)
121 | {
122 | $this->posts_per_archive_page = $posts_per_archive_page;
123 | }
124 |
125 | /**
126 | * @return int|null
127 | */
128 | public function getOffset()
129 | {
130 | return $this->offset;
131 | }
132 |
133 | /**
134 | * @param int|null $offset
135 | */
136 | public function setOffset($offset)
137 | {
138 | $this->offset = $offset;
139 | }
140 |
141 | /**
142 | * @return int|null
143 | */
144 | public function getPage()
145 | {
146 | return $this->page;
147 | }
148 |
149 | /**
150 | * @param int|null $page
151 | */
152 | public function setPage($page)
153 | {
154 | $this->page = $page;
155 | }
156 |
157 | /**
158 | * @return bool|null
159 | */
160 | public function getIgnoreStickyPosts()
161 | {
162 | return $this->ignore_sticky_posts;
163 | }
164 |
165 | /**
166 | * @param bool|null $ignore_sticky_posts
167 | */
168 | public function setIgnoreStickyPosts($ignore_sticky_posts)
169 | {
170 | $this->ignore_sticky_posts = $ignore_sticky_posts;
171 | }
172 | }
173 |
--------------------------------------------------------------------------------
/src/Database/Parameter/Password.php:
--------------------------------------------------------------------------------
1 | has_password = $has_password;
28 | $this->post_password = $post_password;
29 | }
30 |
31 | /**
32 | * @return bool|null
33 | */
34 | public function getHasPassword()
35 | {
36 | return $this->has_password;
37 | }
38 |
39 | /**
40 | * @param bool|null $has_password
41 | */
42 | public function setHasPassword($has_password)
43 | {
44 | $this->has_password = $has_password;
45 | }
46 |
47 | /**
48 | * @return string|null
49 | */
50 | public function getPostPassword()
51 | {
52 | return $this->post_password;
53 | }
54 |
55 | /**
56 | * @param string|null $post_password
57 | */
58 | public function setPostPassword($post_password)
59 | {
60 | $this->post_password = $post_password;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/Database/Parameter/PostAndPage.php:
--------------------------------------------------------------------------------
1 | p = $p;
73 | $this->name = $name;
74 | $this->title = $title;
75 | $this->page_id = $page_id;
76 | $this->pagename = $pagename;
77 | $this->post_name__in = $post_name__in;
78 | $this->post_parent = $post_parent;
79 | $this->post_parent__in = $post_parent__in;
80 | $this->post_parent__not_in = $post_parent__not_in;
81 | $this->post__in = $post__in;
82 | $this->post__not_in = $post__not_in;
83 | }
84 |
85 | /**
86 | * @return int|null
87 | */
88 | public function getP()
89 | {
90 | return $this->p;
91 | }
92 |
93 | /**
94 | * @param int|null $p
95 | */
96 | public function setP($p)
97 | {
98 | $this->p = $p;
99 | }
100 |
101 | /**
102 | * @return string|null
103 | */
104 | public function getName()
105 | {
106 | return $this->name;
107 | }
108 |
109 | /**
110 | * @param string|null $name
111 | */
112 | public function setName($name)
113 | {
114 | $this->name = $name;
115 | }
116 |
117 | /**
118 | * @return string|null
119 | */
120 | public function getTitle()
121 | {
122 | return $this->title;
123 | }
124 |
125 | /**
126 | * @param string|null $title
127 | */
128 | public function setTitle($title)
129 | {
130 | $this->title = $title;
131 | }
132 |
133 | /**
134 | * @return int|null
135 | */
136 | public function getPageId()
137 | {
138 | return $this->page_id;
139 | }
140 |
141 | /**
142 | * @param int|null $page_id
143 | */
144 | public function setPageId($page_id)
145 | {
146 | $this->page_id = $page_id;
147 | }
148 |
149 | /**
150 | * @return string|null
151 | */
152 | public function getPagename()
153 | {
154 | return $this->pagename;
155 | }
156 |
157 | /**
158 | * @param string|null $pagename
159 | */
160 | public function setPagename($pagename)
161 | {
162 | $this->pagename = $pagename;
163 | }
164 |
165 | /**
166 | * @return array|null
167 | */
168 | public function getPostNameIn()
169 | {
170 | return $this->post_name__in;
171 | }
172 |
173 | /**
174 | * @param array|null $post_name__in
175 | */
176 | public function setPostNameIn($post_name__in)
177 | {
178 | $this->post_name__in = $post_name__in;
179 | }
180 |
181 | /**
182 | * @return array|null
183 | */
184 | public function getPostParent()
185 | {
186 | return $this->post_parent;
187 | }
188 |
189 | /**
190 | * @param array|null $post_parent
191 | */
192 | public function setPostParent($post_parent)
193 | {
194 | $this->post_parent = $post_parent;
195 | }
196 |
197 | /**
198 | * @return array|null
199 | */
200 | public function getPostParentIn()
201 | {
202 | return $this->post_parent__in;
203 | }
204 |
205 | /**
206 | * @param array|null $post_parent__in
207 | */
208 | public function setPostParentIn($post_parent__in)
209 | {
210 | $this->post_parent__in = $post_parent__in;
211 | }
212 |
213 | /**
214 | * @return array|null
215 | */
216 | public function getPostParentNotIn()
217 | {
218 | return $this->post_parent__not_in;
219 | }
220 |
221 | /**
222 | * @param array|null $post_parent__not_in
223 | */
224 | public function setPostParentNotIn($post_parent__not_in)
225 | {
226 | $this->post_parent__not_in = $post_parent__not_in;
227 | }
228 |
229 | /**
230 | * @return array|null
231 | */
232 | public function getPostIn()
233 | {
234 | return $this->post__in;
235 | }
236 |
237 | /**
238 | * @param array|null $post__in
239 | */
240 | public function setPostIn($post__in)
241 | {
242 | $this->post__in = $post__in;
243 | }
244 |
245 | /**
246 | * @return array|null
247 | */
248 | public function getPostNotIn()
249 | {
250 | return $this->post__not_in;
251 | }
252 |
253 | /**
254 | * @param array|null $post__not_in
255 | */
256 | public function setPostNotIn($post__not_in)
257 | {
258 | $this->post__not_in = $post__not_in;
259 | }
260 | }
261 |
--------------------------------------------------------------------------------
/src/Database/Parameter/PostStatus.php:
--------------------------------------------------------------------------------
1 | post_status = $post_status;
19 | }
20 |
21 | /**
22 | * @return null
23 | */
24 | public function getPostStatus()
25 | {
26 | return $this->post_status;
27 | }
28 |
29 | /**
30 | * @param null $post_status
31 | */
32 | public function setPostStatus($post_status)
33 | {
34 | $this->post_status = $post_status;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Database/Parameter/PostType.php:
--------------------------------------------------------------------------------
1 | post_type = $post_type;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Database/Parameter/Search.php:
--------------------------------------------------------------------------------
1 | s = $s;
33 | $this->exact = $exact;
34 | $this->sentence = $sentence;
35 | }
36 |
37 | /**
38 | * @return string|null
39 | */
40 | public function getS()
41 | {
42 | return $this->s;
43 | }
44 |
45 | /**
46 | * @param string|null $s
47 | */
48 | public function setS($s)
49 | {
50 | $this->s = $s;
51 | }
52 |
53 | /**
54 | * @return bool|null
55 | */
56 | public function getExact()
57 | {
58 | return $this->exact;
59 | }
60 |
61 | /**
62 | * @param bool|null $exact
63 | */
64 | public function setExact($exact)
65 | {
66 | $this->exact = $exact;
67 | }
68 |
69 | /**
70 | * @return bool|null
71 | */
72 | public function getSentence()
73 | {
74 | return $this->sentence;
75 | }
76 |
77 | /**
78 | * @param bool|null $sentence
79 | */
80 | public function setSentence($sentence)
81 | {
82 | $this->sentence = $sentence;
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/Database/Parameter/Tag.php:
--------------------------------------------------------------------------------
1 | tag = $tag;
53 | $this->tag_id = $tag_id;
54 | $this->tag__and = $tag__and;
55 | $this->tag__in = $tag__in;
56 | $this->tag__not_in = $tag__not_in;
57 | $this->tag_slug__and = $tag_slug__and;
58 | $this->tag_slug__in = $tag_slug__in;
59 | }
60 |
61 | /**
62 | * @return string|null
63 | */
64 | public function getTag()
65 | {
66 | return $this->tag;
67 | }
68 |
69 | /**
70 | * @return int|null
71 | */
72 | public function getTagId()
73 | {
74 | return $this->tag_id;
75 | }
76 |
77 | /**
78 | * @return array|null
79 | */
80 | public function getTagAnd()
81 | {
82 | return $this->tag__and;
83 | }
84 |
85 | /**
86 | * @return array|null
87 | */
88 | public function getTagIn()
89 | {
90 | return $this->tag__in;
91 | }
92 |
93 | /**
94 | * @return array|null
95 | */
96 | public function getTagNotIn()
97 | {
98 | return $this->tag__not_in;
99 | }
100 |
101 | /**
102 | * @return array|null
103 | */
104 | public function getTagSlugAnd()
105 | {
106 | return $this->tag_slug__and;
107 | }
108 |
109 | /**
110 | * @return array|null
111 | */
112 | public function getTagSlugIn()
113 | {
114 | return $this->tag_slug__in;
115 | }
116 |
117 | /**
118 | * @param string|null $tag
119 | */
120 | public function setTag($tag)
121 | {
122 | $this->tag = $tag;
123 | }
124 |
125 | /**
126 | * @param int|null $tag_id
127 | */
128 | public function setTagId($tag_id)
129 | {
130 | $this->tag_id = $tag_id;
131 | }
132 |
133 | /**
134 | * @param array|null $tag__and
135 | */
136 | public function setTagAnd($tag__and)
137 | {
138 | $this->tag__and = $tag__and;
139 | }
140 |
141 | /**
142 | * @param array|null $tag__in
143 | */
144 | public function setTagIn($tag__in)
145 | {
146 | $this->tag__in = $tag__in;
147 | }
148 |
149 | /**
150 | * @param array|null $tag__not_in
151 | */
152 | public function setTagNotIn($tag__not_in)
153 | {
154 | $this->tag__not_in = $tag__not_in;
155 | }
156 |
157 | /**
158 | * @param array|null $tag_slug__and
159 | */
160 | public function setTagSlugAnd($tag_slug__and)
161 | {
162 | $this->tag_slug__and = $tag_slug__and;
163 | }
164 |
165 | /**
166 | * @param array|null $tag_slug__in
167 | */
168 | public function setTagSlugIn($tag_slug__in)
169 | {
170 | $this->tag_slug__in = $tag_slug__in;
171 | }
172 | }
173 |
--------------------------------------------------------------------------------
/src/Database/Parameter/Tax.php:
--------------------------------------------------------------------------------
1 | relation = $relation;
30 | $this->arguments = $arguments;
31 | }
32 |
33 | /**
34 | * @return string|null
35 | */
36 | public function getRelation()
37 | {
38 | return $this->relation;
39 | }
40 |
41 | /**
42 | * @return array|null
43 | */
44 | public function getArguments()
45 | {
46 | return $this->arguments;
47 | }
48 |
49 | /**
50 | * @param string|null $relation
51 | */
52 | public function setRelation($relation)
53 | {
54 | $this->relation = $relation;
55 | }
56 |
57 | /**
58 | * @param array|null $arguments
59 | */
60 | public function setArguments($arguments)
61 | {
62 | $this->arguments = $arguments;
63 | }
64 |
65 | /**
66 | * @return array[]
67 | */
68 | public function toArray(): array
69 | {
70 | $props = Collection::make(get_class_vars(static::class));
71 | $resolvedProps = $props->map(function ($item, $index) {
72 | if (Is::arr($this->{$index})) {
73 | return Collection::make($this->{$index})
74 | ->map(function ($class) {
75 | return Is::obj($class) ? $class->toArray() : $class;
76 | })
77 | ->toArray();
78 | }
79 |
80 | return $this->{$index};
81 | });
82 |
83 | return [
84 | 'tax_query' => [
85 | 'relation' => $resolvedProps->get('relation'),
86 | $resolvedProps->get('arguments')
87 | ]
88 | ];
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/src/Database/Parameter/TaxArgument.php:
--------------------------------------------------------------------------------
1 | taxonomy = $taxonomy;
43 | $this->field = $field;
44 | $this->terms = $terms;
45 | $this->include_children = $include_children;
46 | $this->operator = $operator;
47 | }
48 |
49 | /**
50 | * @return string|null
51 | */
52 | public function getTaxonomy()
53 | {
54 | return $this->taxonomy;
55 | }
56 |
57 | /**
58 | * @return string|null
59 | */
60 | public function getField()
61 | {
62 | return $this->field;
63 | }
64 |
65 | /**
66 | * @return array|int|string
67 | */
68 | public function getTerms()
69 | {
70 | return $this->terms;
71 | }
72 |
73 | /**
74 | * @return
75 | */
76 | public function isIncludeChildren()
77 | {
78 | return $this->include_children;
79 | }
80 |
81 | /**
82 | * @return string|null
83 | */
84 | public function getOperator()
85 | {
86 | return $this->operator;
87 | }
88 |
89 | /**
90 | * @param string|null $taxonomy
91 | */
92 | public function setTaxonomy($taxonomy)
93 | {
94 | $this->taxonomy = $taxonomy;
95 | }
96 |
97 | /**
98 | * @param string|null $field
99 | */
100 | public function setField($field)
101 | {
102 | $this->field = $field;
103 | }
104 |
105 | /**
106 | * @param array|int|string $terms
107 | */
108 | public function setTerms($terms)
109 | {
110 | $this->terms = $terms;
111 | }
112 |
113 | /**
114 | * @param $include_children
115 | */
116 | public function setIncludeChildren($include_children)
117 | {
118 | $this->include_children = $include_children;
119 | }
120 |
121 | /**
122 | * @param string|null $operator
123 | */
124 | public function setOperator($operator)
125 | {
126 | $this->operator = $operator;
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/src/Database/Query.php:
--------------------------------------------------------------------------------
1 | arguments);
35 | }
36 |
37 | /**
38 | * @return Collection
39 | */
40 | public function get(): Collection
41 | {
42 | return new Collection($this->make()->get_posts());
43 | }
44 |
45 | /**
46 | * @return int[]|WP_Post[]
47 | */
48 | public function getRaw()
49 | {
50 | return $this->make()->get_posts();
51 | }
52 |
53 | /**
54 | * @param null|Author|string $author
55 | * @param string|null $author_name
56 | * @param array|null $author__in
57 | * @param array|null $author__not_in
58 | * @return $this
59 | * @throws ReflectionException
60 | */
61 | public function author($author = null, string $author_name = null, array $author__in = null, array $author__not_in = null): Query
62 | {
63 | $this->updateArgs(Author::class, $author, $author_name, $author__in, $author__not_in);
64 | return $this;
65 | }
66 |
67 | /**
68 | * @param null|Category|string $cat
69 | * @param string|null $category_name
70 | * @param array|null $category__and
71 | * @param array|null $category__in
72 | * @param array|null $category__not_in
73 | * @return $this
74 | * @throws ReflectionException
75 | */
76 | public function category($cat = null, string $category_name = null, array $category__and = null, array $category__in = null, array $category__not_in = null): Query
77 | {
78 | $this->updateArgs(Category::class, $cat, $category_name, $category__and, $category__in, $category__not_in);
79 | return $this;
80 | }
81 |
82 | /**
83 | * @param null|Tag|string $tag
84 | * @param int|null $tag_id
85 | * @param array|null $tag__and
86 | * @param array|null $tag__in
87 | * @param array|null $tag__not_in
88 | * @param array|null $tag_slug__and
89 | * @param array|null $tag_slug__in
90 | * @return $this
91 | * @throws ReflectionException
92 | */
93 | public function tag($tag = null, int $tag_id = null, array $tag__and = null, array $tag__in = null, array $tag__not_in = null, array $tag_slug__and = null, array $tag_slug__in = null): Query
94 | {
95 | $this->updateArgs(Tag::class, $tag, $tag_id, $tag__and, $tag__in, $tag__not_in, $tag_slug__and, $tag_slug__in);
96 | return $this;
97 | }
98 |
99 | /**
100 | * @param null|Tax|string $relation
101 | * @param array|null $arguments
102 | * @return $this
103 | * @throws ReflectionException
104 | */
105 | public function tax($relation = null, array $arguments = null): Query
106 | {
107 | $this->updateArgs(Tax::class, $relation, $arguments);
108 |
109 | return $this;
110 | }
111 |
112 | /**
113 | * @param null|PostAndPage|string $p
114 | * @param string|null $name
115 | * @param string|null $title
116 | * @param int|null $page_id
117 | * @param string|null $pagename
118 | * @param array|null $post_name__in
119 | * @param array|null $post_parent
120 | * @param array|null $post_parent__in
121 | * @param array|null $post_parent__not_in
122 | * @param array|null $post__in
123 | * @param array|null $post__not_in
124 | * @return $this
125 | * @throws ReflectionException
126 | */
127 | public function postAndPage($p = null, string $name = null, string $title = null, int $page_id = null, string $pagename = null, array $post_name__in = null, array $post_parent = null, array $post_parent__in = null, array $post_parent__not_in = null, array $post__in = null, array $post__not_in = null): Query
128 | {
129 | $this->updateArgs(PostAndPage::class, $p, $name, $title, $page_id, $pagename, $post_name__in, $post_parent, $post_parent__in, $post_parent__not_in, $post__in, $post__not_in);
130 |
131 | return $this;
132 | }
133 |
134 | /**
135 | * @param null|Password|bool|string $has_password
136 | * @param string|null $post_password
137 | * @return $this
138 | * @throws ReflectionException
139 | */
140 | public function password($has_password = null, string $post_password = null): Query
141 | {
142 | $this->updateArgs(Password::class, $has_password, $has_password);
143 |
144 | return $this;
145 | }
146 |
147 | /**
148 | * @param null|PostType|string $post_type
149 | * @return $this
150 | * @throws ReflectionException
151 | */
152 | public function postType($post_type = null): Query
153 | {
154 | $this->updateArgs(PostType::class, $post_type);
155 |
156 | return $this;
157 | }
158 |
159 | /**
160 | * @param null|PostStatus|mixed $post_status
161 | * @return $this
162 | * @throws ReflectionException
163 | */
164 | public function postStatus($post_status = null): Query
165 | {
166 | $this->updateArgs(PostStatus::class, $post_status);
167 |
168 | return $this;
169 | }
170 |
171 | /**
172 | * @param null|Comment|mixed $comment_count
173 | * @return $this
174 | * @throws ReflectionException
175 | */
176 | public function comment($comment_count = null): Query
177 | {
178 | $this->updateArgs(Comment::class, $comment_count);
179 |
180 | return $this;
181 | }
182 |
183 | /**
184 | * @param null|Pagination|string $posts_per_page
185 | * @param bool|null $nopaging
186 | * @param int|null $paged
187 | * @param int|null $posts_per_archive_page
188 | * @param int|null $offset
189 | * @param int|null $page
190 | * @param bool|null $ignore_sticky_posts
191 | * @return $this
192 | * @throws ReflectionException
193 | */
194 | public function pagination($posts_per_page = null, bool $nopaging = null, int $paged = null, int $posts_per_archive_page = null, int $offset = null, int $page = null, bool $ignore_sticky_posts = null): Query
195 | {
196 | $this->updateArgs(Pagination::class, $posts_per_page, $nopaging, $paged, $posts_per_archive_page, $offset, $page, $ignore_sticky_posts);
197 |
198 | return $this;
199 | }
200 |
201 | /**
202 | * @param null|Order|string $order
203 | * @param string|null $orderby
204 | * @return $this
205 | * @throws ReflectionException
206 | */
207 | public function order($order = null, string $orderby = null): Query
208 | {
209 | $this->updateArgs(Order::class, $order, $orderby);
210 | return $this;
211 | }
212 |
213 | /**
214 | * @param Date|null|array $date_query
215 | * @param int|null $year
216 | * @param int|null $monthnum
217 | * @param int|null $w
218 | * @param int|null $day
219 | * @param int|null $hour
220 | * @param int|null $minute
221 | * @param int|null $second
222 | * @param int|null $m
223 | * @return $this
224 | * @throws ReflectionException
225 | */
226 | public function date($date_query, int $year = null, int $monthnum = null, int $w = null, int $day = null, int $hour = null, int $minute = null, int $second = null, int $m = null): Query
227 | {
228 | $this->updateArgs(Date::class, $date_query, $year, $monthnum, $w, $day, $hour, $minute, $second, $m);
229 |
230 | return $this;
231 | }
232 |
233 | /**
234 | * @param Meta|null|array $meta_query
235 | * @param string|null $meta_key
236 | * @param string|null $meta_value
237 | * @param string|null $meta_value_num
238 | * @param string|null $meta_compare
239 | * @return $this
240 | * @throws ReflectionException
241 | */
242 | public function meta($meta_query, string $meta_key = null, string $meta_value = null, string $meta_value_num = null, string $meta_compare = null): Query
243 | {
244 | $this->updateArgs(Meta::class, $meta_query, $meta_key, $meta_value, $meta_value_num, $meta_compare);
245 |
246 | return $this;
247 | }
248 |
249 | /**
250 | * @param null|Search|string $s
251 | * @param bool|null $exact
252 | * @param bool|null $sentence
253 | * @return $this
254 | * @throws ReflectionException
255 | */
256 | public function search($s = null, bool $exact = null, bool $sentence = null): Query
257 | {
258 | $this->updateArgs(Search::class, $s, $exact, $sentence);
259 |
260 | return $this;
261 | }
262 |
263 | /**
264 | * @param null|Fields|array $fields
265 | * @return $this
266 | * @throws ReflectionException
267 | */
268 | public function fields($fields = null): Query
269 | {
270 | $this->updateArgs(Fields::class, $fields);
271 | return $this;
272 | }
273 | }
274 |
--------------------------------------------------------------------------------
/src/Exceptions/ContainerResolverException.php:
--------------------------------------------------------------------------------
1 | setLogger($logger);
25 | $this->setExceptionHandler();
26 | }
27 |
28 | /**
29 | * @param Logger $logger
30 | */
31 | public function setLogger(Logger $logger)
32 | {
33 | $this->logger = $logger;
34 | }
35 |
36 | /**
37 | * @return void
38 | * @throws LoggerException
39 | */
40 | private function setExceptionHandler()
41 | {
42 | set_exception_handler(function (Throwable $e) {
43 | return $this->handle($e);
44 | });
45 | }
46 |
47 | /**
48 | * @param Throwable $e
49 | * @return mixed
50 | * @throws LoggerException
51 | */
52 | private function handle(Throwable $e)
53 | {
54 | return $this->report($e)
55 | ->render($e);
56 | }
57 |
58 | /**
59 | * @param Throwable $e
60 | * @return mixed
61 | */
62 | public function render(Throwable $e)
63 | {
64 | //TODO: Move to external file
65 | $template = "
66 | Something went wrong
67 |
68 |
File: {$this->logger->absToRelPath($e->getFile())} [
{$e->getLine()}]: {$e->getMessage()}
69 |
70 |
{$e->getTraceAsString()}
71 |
72 | ";
73 |
74 | wp_die($template, 'Oops');
75 | }
76 |
77 | /**
78 | * @param Throwable $e
79 | * @return $this
80 | * @throws LoggerException
81 | */
82 | public function report(Throwable $e): Handler
83 | {
84 | $this->logger->fatal($e->getMessage(), $e->getTrace());
85 | return $this;
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/src/Exceptions/Support/Logger.php:
--------------------------------------------------------------------------------
1 | logFile = $logFile ?: $_SERVER['DOCUMENT_ROOT'] . "/logs/error.log";
33 | $this->file = $file;
34 | $this->options = $options ?: [
35 | 'dateFormat' => 'd-M-Y',
36 | 'logFormat' => 'H:i:s d-M-Y'
37 | ];
38 | }
39 |
40 | /**
41 | *
42 | */
43 | public function createLogFile()
44 | {
45 | if (!Is::dir($_SERVER['DOCUMENT_ROOT'] . '/logs')) {
46 | mkdir($_SERVER['DOCUMENT_ROOT'] . '/logs', 0777, true);
47 | }
48 |
49 | if (!Is::file($this->logFile)) {
50 | fopen($this->logFile, 'w') or exit("Can't create {$this->logFile}");
51 | }
52 |
53 | if (!Is::writable($this->logFile)) {
54 | throw new LoggerException("Unable to write to file");
55 | }
56 | }
57 |
58 | /**
59 | * @param array $options
60 | * @return $this
61 | */
62 | public function setOptions(array $options = []): Logger
63 | {
64 | $this->options = array_merge($this->options, $options);
65 |
66 | return $this;
67 | }
68 |
69 | /**
70 | * @param $message
71 | * @param array $context
72 | * @throws LoggerException
73 | */
74 | public function info($message, array $context = [])
75 | {
76 | $bt = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 1);
77 |
78 | $this->writeLog([
79 | 'message' => $message,
80 | 'bt' => $bt,
81 | 'severity' => 'INFO',
82 | 'context' => $context
83 | ]);
84 | }
85 |
86 | /**
87 | * @param $message
88 | * @param array $context
89 | * @throws LoggerException
90 | */
91 | public function notice($message, array $context = [])
92 | {
93 | $bt = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 1);
94 |
95 | $this->writeLog([
96 | 'message' => $message,
97 | 'bt' => $bt,
98 | 'severity' => 'NOTICE',
99 | 'context' => $context
100 | ]);
101 | }
102 |
103 | /**
104 | * @param $message
105 | * @param array $context
106 | * @throws LoggerException
107 | */
108 | public function debug($message, array $context = [])
109 | {
110 |
111 | $bt = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 1);
112 |
113 | $this->writeLog([
114 | 'message' => $message,
115 | 'bt' => $bt,
116 | 'severity' => 'DEBUG',
117 | 'context' => $context
118 | ]);
119 | }
120 |
121 | /**
122 | * @param $message
123 | * @param array $context
124 | * @throws LoggerException
125 | */
126 | public function warning($message, array $context = [])
127 | {
128 | $bt = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 1);
129 |
130 | $this->writeLog([
131 | 'message' => $message,
132 | 'bt' => $bt,
133 | 'severity' => 'WARNING',
134 | 'context' => $context
135 | ]);
136 | }
137 |
138 | /**
139 | * @param $message
140 | * @param array $context
141 | * @throws LoggerException
142 | */
143 | public function error($message, array $context = [])
144 | {
145 | $bt = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 1);
146 |
147 | $this->writeLog([
148 | 'message' => $message,
149 | 'bt' => $bt,
150 | 'severity' => 'ERROR',
151 | 'context' => $context
152 | ]);
153 | }
154 |
155 | /**
156 | * @param $message
157 | * @param array $context
158 | * @throws LoggerException
159 | */
160 | public function fatal($message, array $context = [])
161 | {
162 | $bt = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 1);
163 |
164 | $this->writeLog([
165 | 'message' => $message,
166 | 'bt' => $bt,
167 | 'severity' => 'FATAL',
168 | 'context' => $context
169 | ]);
170 | }
171 |
172 | /**
173 | * @param array $args
174 | * @throws LoggerException
175 | */
176 | public function writeLog($args = [])
177 | {
178 | $this->createLogFile();
179 |
180 | if (!Is::res($this->logFile)) {
181 | $this->openLog();
182 | }
183 |
184 | $time = date($this->options['logFormat']);
185 |
186 | $context = $this->prettyTrace($args['context']);
187 |
188 | $caller = array_shift($args['bt']);
189 | $btLine = $caller['line'];
190 | $btPath = $caller['file'];
191 |
192 | $path = $this->absToRelPath($btPath);
193 |
194 | $timeLog = is_null($time) ? "[N/A] " : "[{$time}] ";
195 | $pathLog = is_null($path) ? "[N/A] " : "[{$path}] ";
196 | $lineLog = is_null($btLine) ? "[N/A] " : "[{$btLine}] ";
197 | $severityLog = is_null($args['severity']) ? "[N/A]" : "[{$args['severity']}]";
198 | $messageLog = is_null($args['message']) ? "N/A" : "{$args['message']}";
199 | $contextLog = empty($args['context']) ? "" : "{$context}";
200 |
201 | fwrite($this->file, "{$timeLog}{$pathLog}{$lineLog}: {$severityLog} - {$messageLog} " . PHP_EOL . "{$contextLog}" . PHP_EOL);
202 |
203 | $this->closeFile();
204 | }
205 |
206 | /**
207 | *
208 | */
209 | private function openLog()
210 | {
211 | $openFile = $this->logFile;
212 | $this->file = fopen($openFile, 'a') or exit("Unable to open file {$openFile}");
213 | }
214 |
215 | /**
216 | *
217 | */
218 | public function closeFile()
219 | {
220 | if ($this->file) {
221 | fclose($this->file);
222 | }
223 | }
224 |
225 | /**
226 | * @param $pathToConvert
227 | * @return string
228 | */
229 | public function absToRelPath($pathToConvert): string
230 | {
231 | $pathAbs = str_replace(['/', '\\'], '/', $pathToConvert);
232 | $documentRoot = str_replace(['/', '\\'], '/', $_SERVER['DOCUMENT_ROOT']);
233 | return $_SERVER['SERVER_NAME'] . str_replace($documentRoot, '', $pathAbs);
234 | }
235 |
236 | /**
237 | * @param $trace
238 | * @param string $newLine
239 | * @return string|string[]|null
240 | */
241 | public function prettyTrace($trace, string $newLine = PHP_EOL)
242 | {
243 | $context = json_encode($trace, JSON_UNESCAPED_SLASHES);
244 | return preg_replace('/},/', "}," . $newLine, $context);
245 | }
246 |
247 | }
248 |
--------------------------------------------------------------------------------
/src/Gutenberg/Block.php:
--------------------------------------------------------------------------------
1 | view = $view;
22 | $this->path = $path;
23 | }
24 |
25 | /**
26 | * @param string $namespace
27 | * @return Group
28 | */
29 | public function group(string $namespace): Group
30 | {
31 | return new Group($this, $namespace);
32 | }
33 |
34 | /**
35 | * @param string $namespace
36 | * @param string $name
37 | * @param string|null $path
38 | * @return Block
39 | */
40 | public function add(string $namespace, string $name, string $path = null): self
41 | {
42 | $path = $path ?? "{$this->path}/{$name}";
43 | $attributes = json_decode(file_get_contents("/{$path}/data/attributes.json"), true);
44 |
45 | $this->register("{$namespace}/{$name}", [
46 | 'render_callback' => function ($attributes) use ($name, $path) {
47 | $attributes = (object)$attributes;
48 | return $this->view->run("{$name}.view.block", ['attributes' => $attributes]);
49 | },
50 | 'attributes' => $attributes,
51 | ]);
52 |
53 | return $this;
54 | }
55 |
56 | /**
57 | * @param $name
58 | * @param array $args
59 | */
60 | public function register($name, array $args = [])
61 | {
62 | register_block_type($name, $args);
63 | }
64 |
65 | /**
66 | * @param $name
67 | */
68 | public function unregister($name)
69 | {
70 | unregister_block_type($name);
71 | }
72 |
73 | /**
74 | * @param $resource
75 | * @param array $args
76 | */
77 | public function registerFromMetadata($resource, array $args = [])
78 | {
79 | register_block_type_from_metadata($resource, $args);
80 | }
81 |
82 | /**
83 | * @param string $blockName
84 | * @param null $post
85 | * @return bool
86 | */
87 | public function exists(string $blockName, $post = null): bool
88 | {
89 | return has_block($blockName, $post);
90 | }
91 |
92 | /**
93 | * @param array $parsedBlock
94 | * @return string
95 | */
96 | public function render(array $parsedBlock): string
97 | {
98 | return render_block($parsedBlock);
99 | }
100 |
101 | /**
102 | * @param string $content
103 | * @return array[]
104 | */
105 | public function parse(string $content): array
106 | {
107 | return parse_blocks($content);
108 | }
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/src/Gutenberg/BlockLoader.php:
--------------------------------------------------------------------------------
1 | setContainer($container);
21 | $this->requireFiles();
22 | }
23 |
24 | /**
25 | * @param $container
26 | * @return static
27 | */
28 | public static function load($container): BlockLoader
29 | {
30 | return new static($container);
31 | }
32 |
33 | /**
34 | * @param $container
35 | */
36 | public function setContainer($container)
37 | {
38 | $this->container = $container;
39 | }
40 |
41 | /**
42 | *
43 | */
44 | private function requireFiles()
45 | {
46 | $path = $this->container->getPath();
47 | $require = "{$path}/blocks/blocks.php";
48 | if (file_exists($require)) {
49 | require $require;
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/Gutenberg/Group.php:
--------------------------------------------------------------------------------
1 | block = $block;
24 | $this->namespace = $namespace;
25 | }
26 |
27 | /**
28 | * @param string $name
29 | * @param string|null $path
30 | * @return $this
31 | */
32 | public function add(string $name, string $path = null): self
33 | {
34 | $this->block->add($this->namespace, $name, $path);
35 |
36 | return $this;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/Hooks/Action.php:
--------------------------------------------------------------------------------
1 | app = $app;
31 | $this->type = $type;
32 | $this->tag = $tag;
33 | }
34 |
35 | /**
36 | * @param $function
37 | * @param int $priority
38 | * @param int $args
39 | * @return $this
40 | */
41 | public function add($function, int $priority = 10, int $args = 1): Group
42 | {
43 | $hook = new Hook($this->type, $this->tag, [
44 | 'function' => $function,
45 | 'priority' => $priority,
46 | 'args' => $args
47 | ]);
48 |
49 | $this->app->extend('hooks')
50 | ->addMethodCall('add', [$hook]);
51 |
52 | return $this;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/Hooks/Hook.php:
--------------------------------------------------------------------------------
1 | setName($name);
29 | $this->setTag($tag);
30 | $this->setArguments($arguments);
31 | }
32 |
33 | /**
34 | * @return string|null
35 | */
36 | public function getName()
37 | {
38 | return $this->name;
39 | }
40 |
41 | /**
42 | * @return string|null
43 | */
44 | public function getTag()
45 | {
46 | return $this->tag;
47 | }
48 |
49 | /**
50 | * @return array
51 | */
52 | public function getArguments(): array
53 | {
54 | return $this->arguments;
55 | }
56 |
57 | /**
58 | * @param string|null $name
59 | */
60 | public function setName($name)
61 | {
62 | $this->name = $name;
63 | }
64 |
65 | /**
66 | * @param string|null $tag
67 | */
68 | public function setTag($tag)
69 | {
70 | $this->tag = $tag;
71 | }
72 |
73 | /**
74 | * @param array $arguments
75 | */
76 | public function setArguments($arguments)
77 | {
78 | $this->arguments = $arguments;
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/src/Hooks/HookLoader.php:
--------------------------------------------------------------------------------
1 | setContainer($container);
22 | $this->requireFiles();
23 | $this->enableHooks();
24 | }
25 |
26 | /**
27 | * @param $container
28 | * @return static
29 | */
30 | public static function load($container): HookLoader
31 | {
32 | return new static($container);
33 | }
34 |
35 | /**
36 | * @param $container
37 | */
38 | public function setContainer($container)
39 | {
40 | $this->container = $container;
41 | }
42 |
43 | /**
44 | *
45 | */
46 | private function requireFiles()
47 | {
48 | $path = $this->container->getPath();
49 | foreach (self::HOOKS as $hook) {
50 | $require = "{$path}/hooks/{$hook}.php";
51 | if (file_exists($require)) {
52 | require $require;
53 | }
54 | }
55 | }
56 |
57 | /**
58 | *
59 | */
60 | private function enableHooks()
61 | {
62 | $hooks = $this->container->get('hooks');
63 | $resolver = $this->container->get('resolver', true);
64 |
65 | foreach ($hooks as $hook) {
66 | $hookName = $hook->getName();
67 | $params = $hook->getArguments();
68 | $params['tag'] = $hook->getTag();
69 | $params['function'] = $resolver->resolve($params['function']);
70 |
71 | call_user_func_array($hookName, [$params['tag'], $params['function'], $params['priority'], $params['args']]);
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/Hooks/HookRepository.php:
--------------------------------------------------------------------------------
1 | container->add('config', ConfigRepository::class, true)
29 | ->addArgument($this->configs());
30 |
31 | $this->container->share('configAccessor', Config::class)
32 | ->addArgument($this->container);
33 | }
34 |
35 | /**
36 | * @return array
37 | * @throws Exception
38 | */
39 | public function configs(): array
40 | {
41 | $path = $this->container->getPath();
42 | return ConfigFactory::make(['path' => "{$path}/config"])
43 | ->getInstances();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/Providers/ExceptionServiceProvider.php:
--------------------------------------------------------------------------------
1 | container->add(ExceptionLoggerInterface::class, Logger::class);
31 | $this->container->add(ExceptionHandlerInterface::class, Handler::class)
32 | ->addArgument(ExceptionLoggerInterface::class);
33 |
34 | $this->runExceptionHandler();
35 | }
36 |
37 | private function runExceptionHandler()
38 | {
39 | $this->container->get(ExceptionHandlerInterface::class);
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/Providers/GutenbergServiceProvider.php:
--------------------------------------------------------------------------------
1 | container->config('app.blocks.useSSR') ?? true;
27 | $blocksFolder = $this->container->config('app.blocks.folder') ?? "blocks";
28 |
29 | if (!$blocksSSR) {
30 | return;
31 | }
32 |
33 | $this->container->share('block', Block::class)
34 | ->addArguments([
35 | 'view' => $this->container->get('view'),
36 | 'path' => $this->container->getPath() . "/{$blocksFolder}"
37 | ]);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/Providers/HooksServiceProvider.php:
--------------------------------------------------------------------------------
1 | container->share('hooks', HookRepository::class);
29 | $this->container->share('action', Action::class)
30 | ->addArguments(['app' => $this->container, 'action' => 'add_action']);
31 | $this->container->share('filter', Filter::class)
32 | ->addArguments(['app' => $this->container, 'action' => 'add_filter']);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Providers/ViewServiceProvider.php:
--------------------------------------------------------------------------------
1 | setTemplatesFolder();
29 | $this->setShares();
30 | }
31 |
32 | private function setShares()
33 | {
34 | $blocksSSR = $this->container->config('app.blocks.useSSR') ?? true;
35 | $blocksFolder = $this->container->config('app.blocks.folder') ?? "blocks";
36 | $templatePath = [$this->container->config('app.view.templatePath')];
37 |
38 | if ($blocksSSR) {
39 | $templatePath = Arr::prepend($templatePath, $this->container->getPath() . "/{$blocksFolder}");
40 | }
41 |
42 | $this->container->share('view', View::class)
43 | ->addArguments([
44 | 'templatePath' => $templatePath,
45 | 'compiledPath' => $this->container->config('app.view.compiledPath'),
46 | 'baseUrl' => $this->container->config('app.uri.base')
47 | ]);
48 | }
49 |
50 | private function setTemplatesFolder()
51 | {
52 | $templatesFolder = $this->container->config('theme.templates.folder');
53 |
54 | if (!$templatesFolder) {
55 | return;
56 | }
57 |
58 | Collection::make([
59 | 'index',
60 | '404',
61 | 'archive',
62 | 'author',
63 | 'category',
64 | 'tag',
65 | 'taxonomy',
66 | 'date',
67 | 'embed',
68 | 'home',
69 | 'frontpage',
70 | 'privacypolicy',
71 | 'page',
72 | 'paged',
73 | 'search',
74 | 'single',
75 | 'singular',
76 | 'attachment'
77 | ])->each(function ($type) use ($templatesFolder) {
78 | $this->container->get('filter')
79 | ->add("{$type}_template_hierarchy", function ($templates) use ($templatesFolder) {
80 | return Collection::make($templates)->map(function ($template) use ($templatesFolder) {
81 | return "{$templatesFolder}/{$template}";
82 | })->toArray();
83 | });
84 | });
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/Routing/Api.php:
--------------------------------------------------------------------------------
1 | namespace = $namespace;
34 | $this->route = $route;
35 | $this->args = $args;
36 | $this->override = $override;
37 | }
38 |
39 | /**
40 | * @param string $namespace
41 | * @param string $route
42 | * @param array|null $args
43 | * @param bool $override
44 | * @return static
45 | */
46 | public static function make(string $namespace, string $route, array $args = null, bool $override = false): Api
47 | {
48 | return new static($namespace, $route, $args, $override);
49 | }
50 |
51 | /**
52 | * @return void
53 | */
54 | public function register()
55 | {
56 | register_rest_route($this->namespace, $this->route, $this->args, $this->override);
57 | }
58 |
59 | /**
60 | * @param $callback
61 | * @param $permissionCallback
62 | * @param array $args
63 | * @return $this
64 | */
65 | public function get($callback, $permissionCallback, array $args = []): Api
66 | {
67 | $this->args[] = [
68 | 'methods' => "GET",
69 | 'callback' => $callback,
70 | 'permission_callback' => $permissionCallback,
71 | 'args' => $args,
72 | ];
73 |
74 | return $this;
75 | }
76 |
77 | /**
78 | * @param $callback
79 | * @param $permissionCallback
80 | * @param array $args
81 | * @return $this
82 | */
83 | public function post($callback, $permissionCallback, array $args = []): Api
84 | {
85 | $this->args[] = [
86 | 'methods' => "POST",
87 | 'callback' => $callback,
88 | 'permission_callback' => $permissionCallback,
89 | 'args' => $args,
90 | ];
91 |
92 | return $this;
93 | }
94 |
95 | /**
96 | * @param $callback
97 | * @param $permissionCallback
98 | * @param array $args
99 | * @return $this
100 | */
101 | public function put($callback, $permissionCallback, array $args = []): Api
102 | {
103 | $this->args[] = [
104 | 'methods' => "PUT",
105 | 'callback' => $callback,
106 | 'permission_callback' => $permissionCallback,
107 | 'args' => $args,
108 | ];
109 |
110 | return $this;
111 | }
112 |
113 | /**
114 | * @param $callback
115 | * @param $permissionCallback
116 | * @param array $args
117 | * @return $this
118 | */
119 | public function path($callback, $permissionCallback, array $args = []): Api
120 | {
121 | $this->args[] = [
122 | 'methods' => "PATH",
123 | 'callback' => $callback,
124 | 'permission_callback' => $permissionCallback,
125 | 'args' => $args,
126 | ];
127 |
128 | return $this;
129 | }
130 |
131 | /**
132 | * @param $callback
133 | * @param $permissionCallback
134 | * @param array $args
135 | * @return $this
136 | */
137 | public function delete($callback, $permissionCallback, array $args = []): Api
138 | {
139 | $this->args[] = [
140 | 'methods' => "DELETE",
141 | 'callback' => $callback,
142 | 'permission_callback' => $permissionCallback,
143 | 'args' => $args,
144 | ];
145 |
146 | return $this;
147 | }
148 |
149 | }
150 |
--------------------------------------------------------------------------------
/src/Support/Arr.php:
--------------------------------------------------------------------------------
1 | has($key);
34 | }
35 |
36 | if ($array instanceof ArrayAccess) {
37 | return $array->offsetExists($key);
38 | }
39 |
40 | return array_key_exists($key, $array);
41 | }
42 |
43 | /**
44 | * Array contains key
45 | * @param array $array
46 | * @param mixed $key
47 | * @return bool
48 | */
49 | public static function has(array $array, $key): bool
50 | {
51 | if (!$array) {
52 | return false;
53 | }
54 |
55 | if (is_null($key)) {
56 | return false;
57 | }
58 |
59 | if (static::exists($array, $key)) {
60 | return true;
61 | }
62 |
63 | foreach (explode('.', $key) as $segment) {
64 | if (static::accessible($array) && static::exists($array, $segment)) {
65 | $array = $array[$segment];
66 | } else {
67 | return false;
68 | }
69 | }
70 |
71 | return true;
72 | }
73 |
74 | /**
75 | * @param $array
76 | * @param $keys
77 | * @return bool
78 | */
79 | public static function hasAny($array, $keys): bool
80 | {
81 | if (is_null($keys)) {
82 | return false;
83 | }
84 |
85 | $keys = (array)$keys;
86 |
87 | if (!$array) {
88 | return false;
89 | }
90 |
91 | if ($keys === []) {
92 | return false;
93 | }
94 |
95 | foreach ($keys as $key) {
96 | if (static::has($array, $key)) {
97 | return true;
98 | }
99 | }
100 |
101 | return false;
102 | }
103 |
104 | /**
105 | * @param array $array
106 | * @return bool
107 | */
108 | public static function isAssociative(array $array): bool
109 | {
110 | $keys = array_keys($array);
111 |
112 | return array_keys($keys) !== $keys;
113 | }
114 |
115 | /**
116 | * @param $array
117 | * @param $key
118 | * @param null $default
119 | * @return mixed
120 | */
121 | public static function get($array, $key, $default = null)
122 | {
123 | if (!static::accessible($array)) {
124 | return static::value($default);
125 | }
126 |
127 | if (is_null($key)) {
128 | return $array;
129 | }
130 |
131 | if (static::exists($array, $key)) {
132 | return $array[$key];
133 | }
134 |
135 | if (strpos($key, '.') === false) {
136 | return $array[$key] ?? static::value($default);
137 | }
138 |
139 | foreach (explode('.', $key) as $segment) {
140 | if (static::accessible($array) && static::exists($array, $segment)) {
141 | $array = $array[$segment];
142 | } else {
143 | return static::value($default);
144 | }
145 | }
146 |
147 | return $array;
148 | }
149 |
150 | /**
151 | * @param $array
152 | * @param $key
153 | * @param $value
154 | * @return array|mixed
155 | */
156 | public static function set(&$array, $key, $value)
157 | {
158 | if (is_null($key)) {
159 | return $array = $value;
160 | }
161 |
162 | $keys = explode('.', $key);
163 |
164 | while (count($keys) > 1) {
165 | $key = array_shift($keys);
166 |
167 | if (!isset($array[$key]) || !is_array($array[$key])) {
168 | $array[$key] = [];
169 | }
170 |
171 | $array = &$array[$key];
172 | }
173 |
174 | $array[array_shift($keys)] = $value;
175 |
176 | return $array;
177 | }
178 |
179 | /**
180 | * @param $array
181 | * @param $key
182 | * @param $value
183 | * @return mixed
184 | */
185 | public static function add($array, $key, $value)
186 | {
187 | if (is_null(static::get($array, $key))) {
188 | static::set($array, $key, $value);
189 | }
190 |
191 | return $array;
192 | }
193 |
194 | /**
195 | * @param $array
196 | * @param $keys
197 | */
198 | public static function forget(&$array, $keys)
199 | {
200 | $original = &$array;
201 |
202 | $keys = (array)$keys;
203 |
204 | if (count($keys) === 0) {
205 | return;
206 | }
207 |
208 | foreach ($keys as $key) {
209 | $parts = explode('.', $key);
210 |
211 | $array = &$original;
212 |
213 | while (count($parts) > 1) {
214 | $part = array_shift($parts);
215 |
216 | if (isset($array[$part]) && is_array($array[$part])) {
217 | $array = &$array[$part];
218 | } else {
219 | continue 2;
220 | }
221 | }
222 |
223 | unset($array[array_shift($parts)]);
224 | }
225 | }
226 |
227 | /**
228 | * @param $array
229 | * @param null $callback
230 | * @param null $default
231 | * @return false|mixed
232 | */
233 | public static function first($array, $callback = null, $default = null)
234 | {
235 | if (is_null($callback)) {
236 | return empty($array) ? static::value($default) : reset($array);
237 | }
238 |
239 | foreach ($array as $key => $value) {
240 | if (call_user_func($callback, $key, $value)) {
241 | return $value;
242 | }
243 | }
244 |
245 | return static::value($default);
246 | }
247 |
248 | /**
249 | * @param $array
250 | * @param null $callback
251 | * @param null $default
252 | * @return false|mixed
253 | */
254 | public static function last($array, $callback = null, $default = null)
255 | {
256 | if (is_null($callback)) {
257 | return empty($array) ? static::value($default) : end($array);
258 | }
259 |
260 | return static::first(array_reverse($array), $callback, $default);
261 | }
262 |
263 | /**
264 | * @param $array
265 | * @return array
266 | */
267 | public static function collapse($array): array
268 | {
269 | $results = [];
270 |
271 | foreach ($array as $values) {
272 | if ($values instanceof Collection) {
273 | $values = $values->all();
274 | } elseif (!is_array($values)) {
275 | continue;
276 | }
277 |
278 | $results = array_merge($results, $values);
279 | }
280 |
281 | return $results;
282 | }
283 |
284 | /**
285 | * @param $array
286 | * @return array
287 | */
288 | public static function divide($array): array
289 | {
290 | return [array_keys($array), array_values($array)];
291 | }
292 |
293 | /**
294 | * @param $array
295 | * @param $keys
296 | * @return mixed
297 | */
298 | public static function except($array, $keys)
299 | {
300 | static::forget($array, $keys);
301 |
302 | return $array;
303 | }
304 |
305 | /**
306 | * @param $array
307 | * @param $depth
308 | * @return array
309 | */
310 | public static function flatten($array, $depth = INF): array
311 | {
312 | $result = [];
313 |
314 | foreach ($array as $item) {
315 | $item = $item instanceof Collection ? $item->all() : $item;
316 |
317 | if (is_array($item)) {
318 | if ($depth === 1) {
319 | $result = array_merge($result, $item);
320 | continue;
321 | }
322 |
323 | $result = array_merge($result, static::flatten($item, $depth - 1));
324 | continue;
325 | }
326 |
327 | $result[] = $item;
328 | }
329 |
330 | return $result;
331 | }
332 |
333 | /**
334 | * @param $array
335 | * @param $keys
336 | * @return array
337 | */
338 | public static function only($array, $keys): array
339 | {
340 | return array_intersect_key($array, array_flip((array)$keys));
341 | }
342 |
343 | /**
344 | * @param $array
345 | * @param $value
346 | * @param null $key
347 | * @return array
348 | */
349 | public static function pluck($array, $value, $key = null): array
350 | {
351 | $results = [];
352 |
353 | list($value, $key) = static::explodePluckParameters($value, $key);
354 |
355 | foreach ($array as $item) {
356 | $itemValue = static::get($item, $value);
357 |
358 | if (is_null($key)) {
359 | $results[] = $itemValue;
360 | } else {
361 | $itemKey = static::get($item, $key);
362 |
363 | $results[$itemKey] = $itemValue;
364 | }
365 | }
366 |
367 | return $results;
368 | }
369 |
370 | /**
371 | * @param $value
372 | * @param $key
373 | * @return array
374 | */
375 | protected static function explodePluckParameters($value, $key): array
376 | {
377 | $value = is_string($value) ? explode('.', $value) : $value;
378 |
379 | $key = is_null($key) || is_array($key) ? $key : explode('.', $key);
380 |
381 | return [$value, $key];
382 | }
383 |
384 | /**
385 | * @param $value
386 | * @return mixed
387 | */
388 | public static function value($value)
389 | {
390 | return $value instanceof Closure ? $value() : $value;
391 | }
392 |
393 | /**
394 | * @param $array
395 | * @param $value
396 | * @param null $key
397 | * @return array|mixed
398 | */
399 | public static function prepend($array, $value, $key = null)
400 | {
401 | if (is_null($key)) {
402 | array_unshift($array, $value);
403 | } else {
404 | $array = [$key => $value] + $array;
405 | }
406 |
407 | return $array;
408 | }
409 |
410 | /**
411 | * @param $array
412 | * @param $key
413 | * @param null $default
414 | * @return mixed
415 | */
416 | public static function pull(&$array, $key, $default = null)
417 | {
418 | $value = static::get($array, $key, $default);
419 |
420 | static::forget($array, $key);
421 |
422 | return $value;
423 | }
424 |
425 | /**
426 | * @param $array
427 | * @param Closure $callback
428 | * @return array
429 | */
430 | public static function sort($array, Closure $callback): array
431 | {
432 | return Collection::make($array)->sortBy($callback)->all();
433 | }
434 |
435 | /**
436 | * @param $array
437 | * @return mixed
438 | */
439 | public static function sortRecursive($array)
440 | {
441 | foreach ($array as &$value) {
442 | if (is_array($value)) {
443 | $value = static::sortRecursive($value);
444 | }
445 | }
446 |
447 | if (static::isAssociative($array)) {
448 | ksort($array);
449 | } else {
450 | sort($array);
451 | }
452 |
453 | return $array;
454 | }
455 |
456 | /**
457 | * @param $array
458 | * @param Closure $callback
459 | * @return array
460 | */
461 | public static function where($array, Closure $callback): array
462 | {
463 | $filtered = [];
464 |
465 | foreach ($array as $key => $value) {
466 | if (call_user_func($callback, $key, $value)) {
467 | $filtered[$key] = $value;
468 | }
469 | }
470 |
471 | return $filtered;
472 | }
473 | }
--------------------------------------------------------------------------------
/src/Support/Is.php:
--------------------------------------------------------------------------------
1 | string = $string;
24 | }
25 |
26 | /**
27 | * @param string $string
28 | * @return static
29 | */
30 | public static function make(string $string = ''): Str
31 | {
32 | return new static($string);
33 | }
34 |
35 | /**
36 | * @param null $encoding
37 | * @return $this
38 | */
39 | public function lower($encoding = null): Str
40 | {
41 | return new static(mb_strtolower($this->string, $encoding));
42 | }
43 |
44 | /**
45 | * @param null $encoding
46 | * @return $this
47 | */
48 | public function upper($encoding = null): Str
49 | {
50 | return new static(mb_strtoupper($this->string, $encoding));
51 | }
52 |
53 | /**
54 | * @param int $length
55 | * @return array
56 | */
57 | public function split(int $length = 1): array
58 | {
59 | return str_split($this->string, $length);
60 | }
61 |
62 | /**
63 | * @param $search
64 | * @param $replace
65 | * @param bool $registerSensitive
66 | * @return $this
67 | */
68 | public function replace($search, $replace, bool $registerSensitive = true): Str
69 | {
70 | $res = call_user_func($registerSensitive ? 'str_replace' : 'str_ireplace', $search, $replace, $this->string);
71 | return new static($res);
72 | }
73 |
74 | /**
75 | * @param string $charlist
76 | * @return $this
77 | */
78 | public function trim(string $charlist = " \t\n\r\0\x0B"): Str
79 | {
80 | return new static(trim($this->string, $charlist));
81 | }
82 |
83 | /**
84 | * @param string $charlist
85 | * @return $this
86 | */
87 | public function ltrim(string $charlist = " \t\n\r\0\x0B"): Str
88 | {
89 | return new static(ltrim($this->string, $charlist));
90 | }
91 |
92 | /**
93 | * @param string $charlist
94 | * @return $this
95 | */
96 | public function rtrim(string $charlist = " \t\n\r\0\x0B"): Str
97 | {
98 | return new static(rtrim($this->string, $charlist));
99 | }
100 |
101 | /**
102 | * @param $delimiter
103 | * @param null $limit
104 | * @return Collection
105 | */
106 | public function explode($delimiter, $limit = null): Collection
107 | {
108 | return Collection::make(explode($delimiter, $this->string, $limit));
109 | }
110 |
111 | /**
112 | * @return $this
113 | */
114 | public function upperFirst(): Str
115 | {
116 | return new static(ucfirst($this->string));
117 | }
118 |
119 | /**
120 | * @return $this
121 | */
122 | public function lowerFirst(): Str
123 | {
124 | return new static(lcfirst($this->string));
125 | }
126 |
127 | /**
128 | * @param bool $rawOutput
129 | * @return $this
130 | */
131 | public function md5(bool $rawOutput = false): Str
132 | {
133 | return new static(md5($this->string, $rawOutput));
134 | }
135 |
136 | /**
137 | * @param bool $xhtml
138 | * @return $this
139 | */
140 | public function nl2br(bool $xhtml = true): Str
141 | {
142 | return new static(nl2br($this->string, $xhtml));
143 | }
144 |
145 | /**
146 | * @param string $search
147 | * @param float|int $similarPercent
148 | * @return bool
149 | */
150 | public function isSimilar(string $search, float $similarPercent = 100): bool
151 | {
152 | similar_text($this->string, $search, $prc);
153 | return $prc >= $similarPercent;
154 | }
155 |
156 | /**
157 | * @return string
158 | */
159 | public function soundex(): string
160 | {
161 | return soundex($this->string);
162 | }
163 |
164 | /**
165 | * @param int $count
166 | * @return $this
167 | */
168 | public function repeat(int $count): Str
169 | {
170 | return new static(str_repeat($this->string, $count));
171 | }
172 |
173 | /**
174 | * @return $this
175 | */
176 | public function shuffle(): Str
177 | {
178 | return new static(str_shuffle($this->string));
179 | }
180 |
181 | /**
182 | * @return int|string[]
183 | */
184 | public function wordCount()
185 | {
186 | return str_word_count($this->string);
187 | }
188 |
189 | /**
190 | * @param string $search
191 | * @param bool $registerSensitive
192 | * @return false|mixed
193 | */
194 | public function equal(string $search, bool $registerSensitive = true)
195 | {
196 | return call_user_func($registerSensitive ? 'strcmp' : 'strcasecmp', $this->string, $search);
197 | }
198 |
199 | /**
200 | * @param null $encoding
201 | * @return false|int
202 | */
203 | public function length($encoding = null)
204 | {
205 | return mb_strlen($this->string, $encoding);
206 | }
207 |
208 | /**
209 | * @return $this
210 | */
211 | public function flip(): Str
212 | {
213 | return new static(strrev($this->string));
214 | }
215 |
216 | /**
217 | * @param string $search
218 | * @return $this
219 | */
220 | public function before(string $search): Str
221 | {
222 | return new static(strstr($this->string, $search, true));
223 | }
224 |
225 | /**
226 | * @param string $search
227 | * @return $this
228 | */
229 | public function after(string $search): Str
230 | {
231 | return new static(substr($this->string, strpos($this->string, "_") + strlen($search)));
232 | }
233 |
234 | /**
235 | * @param string $from
236 | * @param string $to
237 | * @return $this|string
238 | */
239 | public function between(string $from, string $to)
240 | {
241 | $string = ' ' . $this->string;
242 | $ini = strpos($string, $from);
243 | if ($ini == 0) return '';
244 | $ini += strlen($from);
245 | $len = strpos($string, $to, $ini) - $ini;
246 | return new static(substr($string, $ini, $len));
247 | }
248 |
249 | /**
250 | * @param string $search
251 | * @return bool
252 | */
253 | public function has(string $search): bool
254 | {
255 | return substr_count($this->string, $search) > 0;
256 | }
257 |
258 | /**
259 | * @param array $search
260 | * @return bool
261 | */
262 | public function hasAll(array $search): bool
263 | {
264 |
265 | foreach ($search as $word)
266 | if (!$this->has($word))
267 | return false;
268 |
269 | return true;
270 | }
271 |
272 | /**
273 | * @param string $delimiters
274 | * @return $this
275 | */
276 | public function upperWords(string $delimiters = " \t\r\n\f\v"): Str
277 | {
278 | return new static(ucwords($this->string, $delimiters));
279 | }
280 |
281 | /**
282 | * @param $pattern
283 | * @param $replace
284 | * @return $this
285 | */
286 | public function pregReplace($pattern, $replace): Str
287 | {
288 | return new static(preg_replace($pattern, $replace, $this->string));
289 | }
290 |
291 | /**
292 | * @param string $delimiter
293 | * @return string|Str
294 | */
295 | public function snake(string $delimiter = '_')
296 | {
297 | if (ctype_lower($this->string)) {
298 | return $this->string;
299 | }
300 |
301 | return $this->upperWords()
302 | ->pregReplace('/\s+/u', '')
303 | ->pregReplace('/(.)(?=[A-Z])/u', '$1' . $delimiter)
304 | ->lower();
305 | }
306 |
307 | /**
308 | * @return string|Str
309 | */
310 | public function kebab()
311 | {
312 | return $this->snake('-');
313 | }
314 |
315 | /**
316 | * @param int $words
317 | * @param string $end
318 | * @return $this|string
319 | */
320 | public function words(int $words = 100, string $end = '...')
321 | {
322 | preg_match('/^\s*+(?:\S++\s*+){1,' . $words . '}/u', $this->string, $matches);
323 |
324 | if (!isset($matches[0]) || $this->length() === static::make($matches[0])->length()) {
325 | return $this->string;
326 | }
327 |
328 | return new static(static::make($matches[0])->rtrim() . $end);
329 | }
330 |
331 | /**
332 | * @param int $length
333 | * @return string
334 | * @throws Exception
335 | */
336 | public static function random(int $length = 16): string
337 | {
338 | $string = '';
339 |
340 | while (($len = strlen($string)) < $length) {
341 | $size = $length - $len;
342 | $bytes = random_bytes($size);
343 | $string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size);
344 | }
345 |
346 | return $string;
347 | }
348 |
349 | /**
350 | * @param string $encoding
351 | * @return $this
352 | */
353 | public function title(string $encoding = 'UTF-8'): Str
354 | {
355 | return new static(mb_convert_case($this->string, MB_CASE_TITLE, $encoding));
356 | }
357 |
358 | /**
359 | * @param array $delimiters
360 | * @return Str
361 | */
362 | public function studly(array $delimiters = []): Str
363 | {
364 | return $this->kebab()
365 | ->replace(['-', '_'] + $delimiters, ' ')
366 | ->upperWords()
367 | ->replace(' ', '');
368 | }
369 |
370 | /**
371 | * @return $this
372 | */
373 | public function camel(): Str
374 | {
375 | return $this->studly()
376 | ->lowerFirst();
377 | }
378 |
379 | /**
380 | * @param $start
381 | * @param null $length
382 | * @param string $encoding
383 | * @return $this
384 | */
385 | public function cut($start, $length = null, string $encoding = 'UTF-8'): Str
386 | {
387 | return new static(mb_substr($this->string, $start, $length, $encoding));
388 | }
389 |
390 | /**
391 | * @return string
392 | */
393 | public function __toString()
394 | {
395 | return $this->string;
396 | }
397 | }
398 |
--------------------------------------------------------------------------------
/src/Traits/AppSingleton.php:
--------------------------------------------------------------------------------
1 | setInstance();
19 | parent::__construct($basePath);
20 | }
21 |
22 | /**
23 | * @param null $basePath
24 | * @return static
25 | */
26 | public static function boot($basePath = null): self
27 | {
28 | return new static($basePath);
29 | }
30 |
31 | /**
32 | * @return mixed
33 | */
34 | public static function getInstance(): self
35 | {
36 | if (is_null(self::$instance)) {
37 | self::$instance = new self;
38 | }
39 |
40 | return self::$instance;
41 | }
42 |
43 | /**
44 | *
45 | */
46 | public function setInstance()
47 | {
48 | self::$instance = $this;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/Traits/Factoryable.php:
--------------------------------------------------------------------------------
1 | getProperties(ReflectionProperty::IS_PRIVATE) as $reflectionProperty) {
18 | $property = $reflectionProperty->getName();
19 | if (isset($parameters[$property])) {
20 | $this->{$property} = $parameters[$property];
21 | }
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Traits/Macroable.php:
--------------------------------------------------------------------------------
1 | bindTo($this, static::class), $parameters);
62 | }
63 |
64 | return call_user_func_array(static::$macros[$method], $parameters);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/Traits/QueryParameter.php:
--------------------------------------------------------------------------------
1 | map(function ($item, $index) {
16 | return $this->{$index};
17 | })
18 | ->filter(function ($item) {
19 | return $item !== null;
20 | })
21 | ->toArray();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Utils/Enqueue.php:
--------------------------------------------------------------------------------
1 | id = $post->ID;
108 | $this->author = $post->post_author;
109 | $this->date = $post->post_date;
110 | $this->dateGMT = $post->post_date_gmt;
111 | $this->content = $post->post_content;
112 | $this->title = $post->post_title;
113 | $this->excerpt = $post->post_excerpt;
114 | $this->status = $post->post_status;
115 | $this->commentStatus = $post->comment_status;
116 | $this->pingStatus = $post->ping_status;
117 | $this->password = $post->post_password;
118 | $this->slug = $post->post_name;
119 | $this->toPing = $post->to_ping;
120 | $this->pinged = $post->pinged;
121 | $this->modified = $post->post_modified;
122 | $this->modifiedGMT = $post->post_modified_gmt;
123 | $this->contentFiltered = $post->post_content_filtered;
124 | $this->parent = $post->post_parent;
125 | $this->order = $post->menu_order;
126 | $this->postType = $post->post_type;
127 | $this->mimeType = $post->post_mime_type;
128 | $this->commentCount = $post->comment_count;
129 | $this->filter = $post->filter;
130 | }
131 |
132 | /**
133 | * @param int|null $id
134 | * @return Post
135 | */
136 | public static function get(int $id = null): Post
137 | {
138 | return new static($id);
139 | }
140 |
141 | /**
142 | * @return Post
143 | */
144 | public static function current(): Post
145 | {
146 | return new static(get_the_ID());
147 | }
148 |
149 | /**
150 | * @return int
151 | */
152 | public function getId(): int
153 | {
154 | return $this->id;
155 | }
156 |
157 | /**
158 | * @return int
159 | */
160 | public function getAuthor()
161 | {
162 | return $this->author;
163 | }
164 |
165 | /**
166 | * @return string
167 | */
168 | public function getDate(): string
169 | {
170 | return $this->date;
171 | }
172 |
173 | /**
174 | * @return string
175 | */
176 | public function getDateGMT(): string
177 | {
178 | return $this->dateGMT;
179 | }
180 |
181 | /**
182 | * @return string
183 | */
184 | public function getContent(): string
185 | {
186 | return $this->content;
187 | }
188 |
189 | /**
190 | * @return string
191 | */
192 | public function getTitle(): string
193 | {
194 | return $this->title;
195 | }
196 |
197 | /**
198 | * @return string
199 | */
200 | public function getExcerpt(): string
201 | {
202 | return $this->excerpt;
203 | }
204 |
205 | /**
206 | * @return string
207 | */
208 | public function getStatus(): string
209 | {
210 | return $this->status;
211 | }
212 |
213 | /**
214 | * @return string
215 | */
216 | public function getCommentStatus(): string
217 | {
218 | return $this->commentStatus;
219 | }
220 |
221 | /**
222 | * @return string
223 | */
224 | public function getPingStatus(): string
225 | {
226 | return $this->pingStatus;
227 | }
228 |
229 | /**
230 | * @return string
231 | */
232 | public function getPassword(): string
233 | {
234 | return $this->password;
235 | }
236 |
237 | /**
238 | * @return string
239 | */
240 | public function getSlug(): string
241 | {
242 | return $this->slug;
243 | }
244 |
245 | /**
246 | * @return string
247 | */
248 | public function getToPing(): string
249 | {
250 | return $this->toPing;
251 | }
252 |
253 | /**
254 | * @return string
255 | */
256 | public function getPinged(): string
257 | {
258 | return $this->pinged;
259 | }
260 |
261 | /**
262 | * @return string
263 | */
264 | public function getModified(): string
265 | {
266 | return $this->modified;
267 | }
268 |
269 | /**
270 | * @return string
271 | */
272 | public function getModifiedGMT(): string
273 | {
274 | return $this->modifiedGMT;
275 | }
276 |
277 | /**
278 | * @return string
279 | */
280 | public function getContentFiltered(): string
281 | {
282 | return $this->contentFiltered;
283 | }
284 |
285 | /**
286 | * @return int
287 | */
288 | public function getParent(): int
289 | {
290 | return $this->parent;
291 | }
292 |
293 | /**
294 | * @return int
295 | */
296 | public function getOrder(): int
297 | {
298 | return $this->order;
299 | }
300 |
301 | /**
302 | * @return string
303 | */
304 | public function getPostType(): string
305 | {
306 | return $this->postType;
307 | }
308 |
309 | /**
310 | * @return string
311 | */
312 | public function getMimeType(): string
313 | {
314 | return $this->mimeType;
315 | }
316 |
317 | /**
318 | * @return int
319 | */
320 | public function getCommentCount(): int
321 | {
322 | return $this->commentCount;
323 | }
324 |
325 | /**
326 | * @return string
327 | */
328 | public function getFilter(): string
329 | {
330 | return $this->filter;
331 | }
332 | }
333 |
--------------------------------------------------------------------------------
/src/Utils/Template.php:
--------------------------------------------------------------------------------
1 | templatePath = $templatePaths;
19 | $this->compiledPath = $compiledPath;
20 | $this->baseUrl = $baseUrl;
21 | }
22 |
23 | /**
24 | * @param string $view
25 | * @param array $variables
26 | * @throws Exception
27 | */
28 | public function render(string $view, array $variables = [])
29 | {
30 | echo $this->run($view, $variables);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/stubs/app/Facades/Action.stub:
--------------------------------------------------------------------------------
1 | group($tag);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/stubs/app/Facades/Block.stub:
--------------------------------------------------------------------------------
1 | group($namespace);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/stubs/app/Facades/Config.stub:
--------------------------------------------------------------------------------
1 | group($tag);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/stubs/app/Facades/View.stub:
--------------------------------------------------------------------------------
1 | [
5 | 'base' => dirname(__DIR__),
6 | 'assets' => dirname(__DIR__) . "/assets"
7 | ],
8 |
9 | 'uri' => [
10 | 'base' => {{baseURI}},
11 | 'assets' => {{baseAssetsURI}}
12 | ],
13 |
14 | 'view' => [
15 | 'templatesFolder' => {{templatesFolder}},
16 | 'templatePath' => {{templatePath}},
17 | 'compiledPath' => {{compiledPath}},
18 | ],
19 |
20 | 'providers' => [
21 | //Base Providers
22 | \Mjolnir\Providers\ExceptionServiceProvider::class,
23 | \Mjolnir\Providers\HooksServiceProvider::class,
24 | \Mjolnir\Providers\ViewServiceProvider::class,
25 | \Mjolnir\Providers\GutenbergServiceProvider::class,
26 |
27 | //App Providers
28 | \Wapu\Providers\AppServiceProvider::class
29 | ]
30 | ];
31 |
--------------------------------------------------------------------------------