base.php
3 weeks ago
exporter.php
3 weeks ago
helpers.php
3 weeks ago
resolver.php
3 weeks ago
updater.php
3 weeks ago
view.php
3 weeks ago
resolver.php
35 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Wpae\AddonAPI; |
| 4 | |
| 5 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 6 | |
| 7 | class PMXE_Addon_Resolver { |
| 8 | |
| 9 | public PMXE_Addon_Base $addon; |
| 10 | public $record; |
| 11 | public $recordId; |
| 12 | |
| 13 | public function __construct( PMXE_Addon_Base $addon, $object, $recordId ) { |
| 14 | $this->addon = $addon; |
| 15 | $this->record = $object; |
| 16 | $this->recordId = $recordId; |
| 17 | } |
| 18 | |
| 19 | public function getCast( $type ) { |
| 20 | return $this->addon->casts[ $type ] ?? null; |
| 21 | } |
| 22 | |
| 23 | public function resolveFieldValue( PMXE_Addon_Field $field ) { |
| 24 | $value = $this->addon->resolveFieldValue( $field, $this->record, $this->recordId ); |
| 25 | |
| 26 | return $this->processValue( $field, $value ); |
| 27 | } |
| 28 | |
| 29 | public function processValue( PMXE_Addon_Field $field, $value ) { |
| 30 | $cast = $this->getCast( $field->type ); |
| 31 | |
| 32 | return $cast ? ( new $cast )( $field, $value ) : $value; |
| 33 | } |
| 34 | } |
| 35 |