Join
2 years ago
ComputedMetricFactory.php
2 years ago
Dimension.php
1 month ago
DimensionMetricFactory.php
1 year ago
DimensionSegmentFactory.php
6 months ago
DimensionsProvider.php
6 months ago
Discriminator.php
2 years ago
Join.php
2 years ago
MetricsList.php
3 months ago
Updater.php
3 months ago
DimensionsProvider.php
53 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Matomo - free/libre analytics platform |
| 5 | * |
| 6 | * @link https://matomo.org |
| 7 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 8 | */ |
| 9 | namespace Piwik\Columns; |
| 10 | |
| 11 | use Piwik\CacheId; |
| 12 | use Piwik\Cache as PiwikCache; |
| 13 | class DimensionsProvider |
| 14 | { |
| 15 | /** |
| 16 | * @param $dimensionId |
| 17 | * @return ?Dimension |
| 18 | */ |
| 19 | public function factory($dimensionId) |
| 20 | { |
| 21 | $listDimensions = self::getMapOfNameToDimension(); |
| 22 | if (empty($listDimensions) || !is_array($listDimensions) || !$dimensionId || !array_key_exists($dimensionId, $listDimensions)) { |
| 23 | return null; |
| 24 | } |
| 25 | return $listDimensions[$dimensionId]; |
| 26 | } |
| 27 | private static function getMapOfNameToDimension() |
| 28 | { |
| 29 | $cacheId = CacheId::siteAware(CacheId::pluginAware('DimensionFactoryMap')); |
| 30 | $cache = PiwikCache::getTransientCache(); |
| 31 | if ($cache->contains($cacheId)) { |
| 32 | $mapIdToDimension = $cache->fetch($cacheId); |
| 33 | } else { |
| 34 | $dimensions = new static(); |
| 35 | $dimensions = $dimensions->getAllDimensions(); |
| 36 | $mapIdToDimension = array(); |
| 37 | foreach ($dimensions as $dimension) { |
| 38 | $mapIdToDimension[$dimension->getId()] = $dimension; |
| 39 | } |
| 40 | $cache->save($cacheId, $mapIdToDimension); |
| 41 | } |
| 42 | return $mapIdToDimension; |
| 43 | } |
| 44 | /** |
| 45 | * Returns a list of all available dimensions. |
| 46 | * @return Dimension[] |
| 47 | */ |
| 48 | public function getAllDimensions() |
| 49 | { |
| 50 | return \Piwik\Columns\Dimension::getAllDimensions(); |
| 51 | } |
| 52 | } |
| 53 |