PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
2.4.9 2.4.8 2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Application / Services / Cache / CacheApplicationService.php
ameliabooking / src / Application / Services / Cache Last commit date
CacheApplicationService.php 6 days ago
CacheApplicationService.php
96 lines
1 <?php
2
3 namespace AmeliaBooking\Application\Services\Cache;
4
5 use AmeliaBooking\Domain\Entity\Cache\Cache;
6 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
7 use AmeliaBooking\Infrastructure\Common\Container;
8 use AmeliaBooking\Infrastructure\Repository\Cache\CacheRepository;
9 use AmeliaBooking\Infrastructure\WP\Integrations\WooCommerce\StarterWooCommerceService;
10 use Interop\Container\Exception\ContainerException;
11 use InvalidArgumentException;
12 use Slim\Exception\ContainerValueNotFoundException;
13
14 /**
15 * Class CacheApplicationService
16 *
17 * @package AmeliaBooking\Application\Services\Cache
18 */
19 class CacheApplicationService
20 {
21 private $container;
22
23 /**
24 * CacheApplicationService constructor.
25 *
26 * @param Container $container
27 *
28 * @throws InvalidArgumentException
29 */
30 public function __construct(Container $container)
31 {
32 $this->container = $container;
33 }
34
35 /**
36 * @param string $name
37 *
38 * @return array|null
39 *
40 * @throws ContainerValueNotFoundException
41 * @throws QueryExecutionException
42 */
43 public function getCacheByName($name)
44 {
45 /** @var CacheRepository $cacheRepository */
46 $cacheRepository = $this->container->get('domain.cache.repository');
47
48 /** @var Cache $cache */
49 $cache = ($data = explode('_', $name)) && isset($data[0], $data[1]) ?
50 $cacheRepository->getByIdAndName($data[0], $data[1]) : null;
51
52 if ($cache && $cache->getData()) {
53 $cacheData = json_decode($cache->getData()->getValue(), true);
54
55 return $this->withNonce(apply_filters('amelia_mollie_cache_data_filter', $cacheData));
56 }
57
58 return null;
59 }
60
61 /**
62 * @param string $name
63 *
64 * @return array|null
65 *
66 * @throws ContainerValueNotFoundException
67 * @throws ContainerException
68 */
69 public function getWcCacheByName($name)
70 {
71 $cacheData = ($data = explode('_', $name)) && isset($data[0], $data[1]) ?
72 StarterWooCommerceService::getCacheData($data[0]) : null;
73 return $this->withNonce(apply_filters('amelia_woocommerce_cache_data_filter', $cacheData));
74 }
75
76 /**
77 * The page that restores the cache is reached after a redirect from the payment gateway, so the nonce the
78 * booking request handed back is long gone. Mint a new one here - this runs while rendering the page for the
79 * returning visitor, so it is valid for the requests the restored form fires (i.e. "/bookings/success").
80 *
81 * @param array|null $cacheData
82 *
83 * @return array|null
84 */
85 private function withNonce($cacheData)
86 {
87 if (!is_array($cacheData)) {
88 return $cacheData;
89 }
90
91 $cacheData['wpAmeliaNonce'] = wp_create_nonce('ajax-nonce');
92
93 return $cacheData;
94 }
95 }
96