Access
1 year ago
Admin
1 year ago
Db
1 year ago
Emails
1 year ago
Forms
1 year ago
Frontend
1 year ago
Helpers
1 year ago
Integrations
1 year ago
Lite
1 year ago
Logger
1 year ago
Migrations
1 year ago
Providers
1 year ago
Requirements
1 year ago
SmartTags
1 year ago
Tasks
1 year ago
API.php
1 year ago
ErrorHandler.php
1 year ago
Loader.php
1 year ago
WPForms.php
1 year ago
API.php
53 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPForms; |
| 4 | |
| 5 | use WPForms\Admin\Tools\Views\Import; |
| 6 | |
| 7 | /** |
| 8 | * Class API. |
| 9 | * |
| 10 | * @since 1.8.6 |
| 11 | */ |
| 12 | class API { |
| 13 | |
| 14 | /** |
| 15 | * Registry. |
| 16 | * Contains name of the class and method to be called. |
| 17 | * For non-static methods, should contain the id to operate via wpforms->get( 'class' ). |
| 18 | * |
| 19 | * @todo Add non-static methods processing. |
| 20 | * |
| 21 | * @since 1.8.6 |
| 22 | * |
| 23 | * @var array[] |
| 24 | */ |
| 25 | private $registry = [ |
| 26 | 'import_forms' => [ |
| 27 | 'class' => Import::class, |
| 28 | 'method' => 'import_forms', |
| 29 | ], |
| 30 | ]; |
| 31 | |
| 32 | /** |
| 33 | * Magic method to call a method from registry. |
| 34 | * |
| 35 | * @since 1.8.6 |
| 36 | * |
| 37 | * @param string $name Method name. |
| 38 | * @param array $args Arguments. |
| 39 | * |
| 40 | * @return mixed|null |
| 41 | */ |
| 42 | public function __call( string $name, array $args ) { |
| 43 | |
| 44 | $callback = $this->registry[ $name ] ?? null; |
| 45 | |
| 46 | if ( $callback === null ) { |
| 47 | return null; |
| 48 | } |
| 49 | |
| 50 | return call_user_func( [ $callback['class'], $callback['method'] ], ...$args ); |
| 51 | } |
| 52 | } |
| 53 |