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
Discriminator.php
67 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 Exception; |
| 12 | /** |
| 13 | * @api |
| 14 | * @since 3.1.0 |
| 15 | */ |
| 16 | class Discriminator |
| 17 | { |
| 18 | private $table; |
| 19 | private $discriminatorColumn; |
| 20 | private $discriminatorValue; |
| 21 | /** |
| 22 | * Join constructor. |
| 23 | * @param string $table unprefixed table name |
| 24 | * @param null|string $discriminatorColumn |
| 25 | * @param null|int $discriminatorValue should be only hard coded, safe values. |
| 26 | * @throws Exception |
| 27 | */ |
| 28 | public function __construct($table, $discriminatorColumn = null, $discriminatorValue = null) |
| 29 | { |
| 30 | if (empty($discriminatorColumn) || !isset($discriminatorValue)) { |
| 31 | throw new Exception('Both discriminatorColumn and discriminatorValue need to be defined'); |
| 32 | } |
| 33 | $this->table = $table; |
| 34 | $this->discriminatorColumn = $discriminatorColumn; |
| 35 | $this->discriminatorValue = $discriminatorValue; |
| 36 | if (!$this->isValid()) { |
| 37 | // if adding another string value please post an event instead to get a list of allowed values |
| 38 | throw new Exception('$discriminatorValue needs to be null or numeric'); |
| 39 | } |
| 40 | } |
| 41 | public function isValid() |
| 42 | { |
| 43 | return isset($this->discriminatorColumn) && is_numeric($this->discriminatorValue); |
| 44 | } |
| 45 | /** |
| 46 | * @return string |
| 47 | */ |
| 48 | public function getTable() |
| 49 | { |
| 50 | return $this->table; |
| 51 | } |
| 52 | /** |
| 53 | * @return string |
| 54 | */ |
| 55 | public function getColumn() |
| 56 | { |
| 57 | return $this->discriminatorColumn; |
| 58 | } |
| 59 | /** |
| 60 | * @return int|null |
| 61 | */ |
| 62 | public function getValue() |
| 63 | { |
| 64 | return $this->discriminatorValue; |
| 65 | } |
| 66 | } |
| 67 |