Cookie.php
1 week ago
Noop.php
1 week ago
Store.php
1 week ago
Strategy.php
1 week ago
WcSession.php
1 week ago
Store.php
46 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\User\Store; |
| 4 | |
| 5 | |
| 6 | class Store implements Strategy { |
| 7 | |
| 8 | public function get( $key ) { |
| 9 | |
| 10 | $key = $this->adjustKey( $key ); |
| 11 | |
| 12 | return $this->getStrategy( $key )->get( $key ); |
| 13 | } |
| 14 | |
| 15 | public function set( $key, $value ) { |
| 16 | |
| 17 | $key = $this->adjustKey( $key ); |
| 18 | |
| 19 | $this->getStrategy( $key )->set( $key, $value ); |
| 20 | } |
| 21 | |
| 22 | private function getStrategy( $key ) { |
| 23 | global $woocommerce; |
| 24 | |
| 25 | switch ( apply_filters( 'wcml_user_store_strategy', 'wc-session', $key ) ) { |
| 26 | case 'cookie': |
| 27 | $store = \WPML\Container\make( Cookie::class ); |
| 28 | break; |
| 29 | |
| 30 | case 'wc-session': |
| 31 | default: |
| 32 | $store = isset( $woocommerce->session ) ? new WcSession( $woocommerce->session ) : new Noop(); |
| 33 | } |
| 34 | |
| 35 | return $store; |
| 36 | } |
| 37 | |
| 38 | private function adjustKey( $key ) { |
| 39 | |
| 40 | $prefix = 'wcml_'; |
| 41 | |
| 42 | return strpos( $key, $prefix ) === 0 ? $key : $prefix . $key; |
| 43 | } |
| 44 | |
| 45 | } |
| 46 |