1 | <?php |
||
30 | class Tx_FeatureFlag_Service |
||
31 | { |
||
32 | /** |
||
33 | * @var int |
||
34 | */ |
||
35 | const BEHAVIOR_HIDE = 0; |
||
36 | |||
37 | /** |
||
38 | * @var int |
||
39 | */ |
||
40 | const BEHAVIOR_SHOW = 1; |
||
41 | |||
42 | /** |
||
43 | * @var Tx_FeatureFlag_Domain_Repository_FeatureFlag |
||
44 | */ |
||
45 | private $featureFlagRepository; |
||
46 | |||
47 | /** |
||
48 | * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface |
||
49 | */ |
||
50 | private $persistenceManager; |
||
51 | |||
52 | /** |
||
53 | * @var Tx_FeatureFlag_System_Typo3_Configuration |
||
54 | */ |
||
55 | private $configuration; |
||
56 | |||
57 | /** |
||
58 | * @var array |
||
59 | */ |
||
60 | private $cachedFlags = array(); |
||
61 | |||
62 | /** |
||
63 | * Tx_FeatureFlag_Service constructor. |
||
64 | * @param Tx_FeatureFlag_Domain_Repository_FeatureFlag $featureFlagRepository |
||
65 | * @param \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager |
||
66 | * @param Tx_FeatureFlag_System_Typo3_Configuration $configuration |
||
67 | */ |
||
68 | public function __construct( |
||
69 | Tx_FeatureFlag_Domain_Repository_FeatureFlag $featureFlagRepository, |
||
70 | \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager, |
||
71 | Tx_FeatureFlag_System_Typo3_Configuration $configuration |
||
72 | ) { |
||
73 | $this->featureFlagRepository = $featureFlagRepository; |
||
74 | $this->persistenceManager = $persistenceManager; |
||
75 | $this->configuration = $configuration; |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * @param string $flag |
||
80 | * @return Tx_FeatureFlag_Domain_Model_FeatureFlag |
||
81 | * @throws Tx_FeatureFlag_Service_Exception_FeatureNotFound |
||
82 | * @throws RuntimeException |
||
83 | * @return boolean |
||
84 | */ |
||
85 | protected function getFeatureFlag($flag) |
||
86 | { |
||
87 | if (false === is_array($GLOBALS['TCA']) || false === isset($GLOBALS['TCA']['tx_featureflag_domain_model_featureflag'])) { |
||
88 | // This can happen, when we call a REST-endpoint (by using restler-extension without initialized FE) and TYPO3 7: |
||
89 | // Without TCA, we would load (in this and ALL other following PHP-requests) the featureFlag without initialized |
||
90 | // 'property-values' (method 'Tx_FeatureFlag_Domain_Model_FeatureFlag::isEnabled' would return NULL), so we MUST |
||
91 | // avoid to load any featureFlag without correct loaded TCA! |
||
92 | throw new RuntimeException('TCA is not loaded - we can\'t load featureFlag "'.$flag.'"'); |
||
93 | } |
||
94 | |||
95 | if (false === array_key_exists($flag, $this->cachedFlags)) { |
||
96 | $flagModel = $this->featureFlagRepository->findByFlag($flag); |
||
97 | if (false === $flagModel instanceof Tx_FeatureFlag_Domain_Model_FeatureFlag) { |
||
98 | throw new Tx_FeatureFlag_Service_Exception_FeatureNotFound('Feature Flag not found: "' . $flag . '"', 1383842028); |
||
99 | } |
||
100 | $this->cachedFlags[$flag] = $flagModel; |
||
101 | } |
||
102 | return $this->cachedFlags[$flag]; |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * @param $flag |
||
107 | * @return bool |
||
108 | * @throws Tx_FeatureFlag_Service_Exception_FeatureNotFound |
||
109 | */ |
||
110 | public function isFeatureEnabled($flag) |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * @param $flag |
||
117 | * @param $enabled |
||
118 | * @throws Tx_FeatureFlag_Service_Exception_FeatureNotFound |
||
119 | * @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException |
||
120 | */ |
||
121 | public function updateFeatureFlag($flag, $enabled) |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * Flags entries in database |
||
134 | */ |
||
135 | public function flagEntries() |
||
139 | } |
||
140 | } |
||
141 | } |