Esempio n. 1
0
File: Parser.php Progetto: aazon/sfm
 /**
  * @param $formula
  * @param $table
  * @param $typeLeft
  * @param $typeRight
  * @return SFM_Relation
  * @throws SFM_Exception
  */
 protected function parseRelation($formula, $table, $typeLeft, $typeRight)
 {
     $sideLeft = $this->factory->relationSide();
     $sideRight = $this->factory->relationSide();
     $separator = $typeLeft . self::TYPE_SEPARATOR . $typeRight;
     $arr = explode(" {$separator} ", $formula);
     if (count($arr) == 2) {
         $arr = array_map('trim', $arr);
         $arrLeftData = explode('.', $arr[0]);
         $arrRightData = explode('.', $arr[1]);
         if (count($arrLeftData) > 3 || count($arrRightData) > 3) {
             throw new SFM_Exception("Can't parse relation string: {$formula}");
         }
         $sideLeft->isMany = $typeLeft == self::TYPE_MANY;
         $sideRight->isMany = $typeRight == self::TYPE_MANY;
         //Member names
         $sideLeft->member = $arrLeftData[0];
         $sideRight->member = $arrRightData[0];
         //Owner is a side with bigger side or left otherwise
         $isOwnerLefty = !($typeLeft == self::TYPE_ONE && $typeRight == self::TYPE_MANY);
         $sideLeft->isOwner = $isOwnerLefty;
         $sideRight->isOwner = !$isOwnerLefty;
         //Complex fields
         $sideLeft->complex = $this->parseComplex($arrLeftData, $sideRight->member, $sideLeft->isOwner);
         $sideRight->complex = $this->parseComplex($arrRightData, $sideLeft->member, $sideRight->isOwner);
         //Simple fields
         $sideLeft->simple = $this->parseSimple($arrLeftData, $sideLeft->member, $sideRight->member, $sideLeft->isOwner);
         $sideRight->simple = $this->parseSimple($arrRightData, $sideRight->member, $sideLeft->member, $sideRight->isOwner);
     } else {
         throw new SFM_Exception("Can't parse relation {$formula}");
     }
     $sideRight->table = $sideLeft->table = $table;
     return $this->factory->relation($this->engine, $formula, array($sideLeft, $sideRight));
 }
Esempio n. 2
0
File: Engine.php Progetto: aazon/sfm
 public function __construct($prefixProject, SFM_Factory $factory, SFM_DAO $dao, array $meta, array $relations)
 {
     $this->factory = $factory;
     $this->naming = $factory->naming($prefixProject);
     $this->dao = $dao;
     $this->identityMap = $factory->identityMap();
     /**@var SFM_Parser $parser */
     $parser = $this->factory->parser($this);
     $this->meta = $parser->parseMeta($meta);
     $this->relations = $parser->parseRelations($relations);
     /**@var $relation SFM_Relation */
     foreach ($this->relations as $relation) {
         foreach ($relation->getSides() as $side) {
             $this->assertMember($side->member);
             $this->meta[$side->member]['relations'][$side->complex] = $side;
         }
     }
     $arrDao = array();
     foreach ($this->meta as $member => $arr) {
         $arrDao[$member] = $arr['dao'];
     }
     $this->dao->setNaming($this->naming);
     $this->dao->setConfig($arrDao);
 }