Beispiel #1
0
 /**
  * buildLines
  *
  * @param string $rawResult
  *
  * @return array
  */
 private function buildLines($rawResult)
 {
     if (preg_match('@^CREATE TABLE `[^`]+` \\(@', $rawResult, $matches)) {
         $rawResult = substr($rawResult, strlen($matches[0]));
     }
     $parseHelper = new ParseHelper();
     $lines = array();
     while (strlen($rawResult) > 0) {
         $section = $parseHelper->parseSection($rawResult, ',');
         $lines[] = $section;
         $rawResult = substr($rawResult, strlen($section) + 1);
         if ($parseHelper->isTooManyClosingParenthesis()) {
             break;
         }
     }
     $lineObjects = [];
     $keyObjects = [];
     $constraintObjects = [];
     foreach ($lines as $line) {
         $line = trim($line);
         if ($line[0] == '`') {
             $lineObject = new Line($line);
             $lineObjects[$lineObject->getName()] = $lineObject;
         } elseif (preg_match('@^(PRIMARY |UNIQUE |)KEY @', $line)) {
             $keyObject = new Key($line);
             $keyObjects[$keyObject->getName()] = $keyObject;
         } elseif (preg_match('@^CONSTRAINT @', $line)) {
             $constraintObject = new Constraint($line);
             $constraintObjects[$constraintObject->getName()] = $constraintObject;
         }
     }
     $this->setLines($lineObjects);
     $this->setKeys($keyObjects);
     $this->setConstraints($constraintObjects);
     return $rawResult;
 }
Beispiel #2
0
 /**
  * Compares two keys, and returns any errors of non matches
  *
  * @param Constraint $constraint
  * @param string $prefix
  *
  * @return string[]
  * @throws \Exception
  */
 public function equals(Constraint $constraint, $prefix)
 {
     $prefix .= ': Constraint (' . $this->getName() . '):';
     $errors = [];
     if ($constraint->getName() !== $this->getName()) {
         throw new \Exception('Comparing Incomparable Constraints');
     }
     if ($constraint->getRemoteTable() !== $this->getRemoteTable()) {
         $errors[] = $prefix . 'Remote Table Does Not Match:' . "\n" . $constraint->getRemoteTable() . "\n" . $this->getRemoteTable();
     }
     $diff = array_diff($constraint->getLocalColumns(), $this->getLocalColumns());
     if (!empty($diff)) {
         $errors[] = $prefix . 'Extra Local Columns: ' . "\n" . implode("\n", $diff);
     }
     $diff = array_diff($this->getLocalColumns(), $constraint->getLocalColumns());
     if (!empty($diff)) {
         $errors[] = $prefix . 'Missing Local Columns: ' . "\n" . implode("\n", $diff);
     }
     $diff = array_diff($constraint->getRemoteColumns(), $this->getRemoteColumns());
     if (!empty($diff)) {
         $errors[] = $prefix . 'Extra Remote Columns: ' . "\n" . implode("\n", $diff);
     }
     $diff = array_diff($this->getRemoteColumns(), $constraint->getRemoteColumns());
     if (!empty($diff)) {
         $errors[] = $prefix . 'Missing Remote Columns: ' . "\n" . implode("\n", $diff);
     }
     if ($constraint->getUpdateAction() !== $this->getUpdateAction()) {
         $errors[] = $prefix . 'Update Action Does Not Match:' . "\n" . $constraint->getUpdateAction() . "\n" . $this->getUpdateAction();
     }
     if ($constraint->getDeleteAction() !== $this->getDeleteAction()) {
         $errors[] = $prefix . 'Delete Action Does Not Match:' . "\n" . $constraint->getDeleteAction() . "\n" . $this->getDeleteAction();
     }
     return $errors;
 }