Exemplo n.º 1
0
 /**
  * @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);
 }
Exemplo n.º 2
0
 /**
  * {@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);
 }
Exemplo n.º 3
0
 /**
  * {@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;
 }
Exemplo n.º 4
0
 /**
  * {@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]);
 }
 /**
  * {@inheritDoc}
  */
 public function visitAccess(AST\Bag\Context $element, &$handle = null, $eldnah = null)
 {
     return sprintf('%s.%s', $this->getRootAlias(), $element->getId());
 }
Exemplo n.º 6
0
 /**
  * {@inheritDoc}
  */
 public function visitAccess(AST\Bag\Context $element, &$handle = null, $eldnah = null)
 {
     return $element->getId();
 }
Exemplo n.º 7
0
 /**
  * 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;
 }