PluginProbe
Packeta / trunk
Packeta vtrunk
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
packeta / src / Packetery / Module / Carrier / CarrierOptionsFactory.php

CarrierOptionsFactory.php in Packeta trunk, at src/Packetery/Module/Carrier/CarrierOptionsFactory.php

64 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * CarrierOptionsFactory class.
4 *
5 * @package Packetery
6 */
7
8 declare( strict_types=1 );
9
10 namespace Packetery\Module\Carrier;
11
12 use Packetery\Module\Framework\WpAdapter;
13
14 /**
15 * CarrierOptionsFactory class.
16 */
17 class CarrierOptionsFactory {
18
19 /**
20 * WP adapter.
21 *
22 * @var WpAdapter
23 */
24 private $wpAdapter;
25
26 /**
27 * Constructor.
28 *
29 * @param WpAdapter $wpAdapter WP adapter.
30 */
31 public function __construct( WpAdapter $wpAdapter ) {
32 $this->wpAdapter = $wpAdapter;
33 }
34
35 /**
36 * Creates carrier options by option id.
37 *
38 * @param string $optionId Option id.
39 *
40 * @return Options
41 */
42 public function createByOptionId( string $optionId ): Options {
43 $options = $this->wpAdapter->getOption( $optionId );
44 if ( ! isset( $options ) || $options === false ) {
45 $options = [];
46 }
47
48 return new Options( $optionId, $options );
49 }
50
51 /**
52 * Creates instance by carrier ID.
53 *
54 * @param string $carrierId Carrier ID.
55 *
56 * @return Options
57 */
58 public function createByCarrierId( string $carrierId ): Options {
59 $optionId = OptionPrefixer::getOptionId( $carrierId );
60
61 return $this->createByOptionId( $optionId );
62 }
63 }
64