/** * @param AST\Bag\Context $element Element to visit. * * @return string */ private function flattenAccessPath(AST\Bag\Context $element) { $flattenedDimensions = [$element->getId()]; foreach ($element->getDimensions() as $dimension) { $flattenedDimensions[] = $dimension[1]; } return implode('.', $flattenedDimensions); }
/** * {@inheritDoc} */ public function visitAccess(AST\Bag\Context $element, &$handle = null, $eldnah = null) { $flattenedDimensions = [sprintf('["%s"]', $element->getId())]; foreach ($element->getDimensions() as $dimension) { $flattenedDimensions[] = sprintf('["%s"]', $dimension[AST\Bag\Context::ACCESS_VALUE]); } return '$target' . implode('', $flattenedDimensions); }
/** * @inheritDoc */ public function visitAccess(AST\Bag\Context $element, &$handle = null, $eldnah = null) { $dimensions = $element->getDimensions(); // nested path if (!empty($dimensions)) { return $this->flattenAccessPath($element); } return $element->getId(); }
/** * {@inheritDoc} */ public function visitAccess(AST\Bag\Context $element, &$handle = null, $eldnah = null) { $contextPointer = $this->context[$element->getId()]; foreach ($element->getDimensions() as $dimension) { $rawAattribute = $dimension[AST\Bag\Context::ACCESS_VALUE]; $attribute = is_array($contextPointer) ? '[' . $rawAattribute . ']' : $rawAattribute; $contextPointer = $this->accessor->getValue($contextPointer, $attribute); } return $contextPointer; }
/** * {@inheritDoc} */ public function visitAccess(AST\Bag\Context $element, &$handle = null, $eldnah = null) { $dimensions = $element->getDimensions(); // simple column access if (count($dimensions) === 0) { return sprintf('%s.%s', self::ROOT_ALIAS_PLACEHOLDER, parent::visitAccess($element, $handle, $eldnah)); } // this is the real column that we are trying to access $finalColumn = array_pop($dimensions)[1]; // and this is a list of tables that need to be joined $tablesToJoin = array_map(function ($dimension) { return $dimension[1]; }, $dimensions); $tablesToJoin = array_merge([$element->getId()], $tablesToJoin); $this->detectedJoins[] = $tablesToJoin; return sprintf('" . $this->getJoinAlias($target, "%s") . ".%s', end($tablesToJoin), $finalColumn); }
/** * {@inheritDoc} */ public function visitAccess(AST\Bag\Context $element, &$handle = null, $eldnah = null) { $dimensions = $element->getDimensions(); // simple column access if (count($dimensions) === 0) { return sprintf('%s.%s', $this->getRootAlias(), $element->getId()); } // this is the real column that we are trying to access $finalColumn = array_pop($dimensions); // and this is a list of tables that need to be joined $tablesToJoin = array_map(function ($dimension) { return $dimension[1]; }, $dimensions); $tablesToJoin = array_merge([$element->getId()], $tablesToJoin); // check if the first dimension is a known alias if (isset($this->knownAliases[$tablesToJoin[0]])) { $joinTo = $tablesToJoin[0]; array_pop($tablesToJoin); } else { // if not, it's the root table $joinTo = $this->getRootAlias(); } // and here is the auto-join magic foreach ($tablesToJoin as $table) { $joinAlias = 'j_' . $table; $join = sprintf('%s.%s', $joinTo, $table); if (!isset($this->joinMap[$join])) { $this->joinMap[$join] = $joinAlias; $this->qb->join(sprintf('%s.%s', $joinTo, $table), $joinAlias); } else { $joinAlias = $this->joinMap[$join]; } $joinTo = $joinAlias; } return sprintf('%s.%s', $joinTo, $finalColumn[1]); }
/** * Visit a context * * @param \Hoa\Visitor\Element $element Element to visit. * @param mixed &$handle Handle (reference). * @param mixed $eldnah Handle (not reference). * @return mixed */ protected function visitContext(Ruler\Model\Bag\Context $element, &$handle = null, $eldnah = null) { $context = $this->getContext(); if (null === $context) { throw new Ruler\Exeption\Asserter('Assert needs a context to work properly.', 1); } $id = $element->getId(); if (!isset($context[$id])) { throw new Ruler\Exception\Asserter('Context reference %s does not exists.', 2, $id); } $contextPointer = $context[$id]; foreach ($element->getDimensions() as $dimensionNumber => $dimension) { ++$dimensionNumber; switch ($dimension[Ruler\Model\Bag\Context::ACCESS_TYPE]) { case Ruler\Model\Bag\Context::ARRAY_ACCESS: $this->visitContextArray($contextPointer, $dimension, $dimensionNumber, $id, $handle, $eldnah); break; case Ruler\Model\Bag\Context::ATTRIBUTE_ACCESS: $this->visitContextAttribute($contextPointer, $dimension, $dimensionNumber, $id, $handle, $eldnah); break; case Ruler\Model\Bag\Context::METHOD_ACCESS: $this->visitContextMethod($contextPointer, $dimension, $dimensionNumber, $id, $handle, $eldnah); break; } } return $contextPointer; }