public function equals(Column $column) { foreach (['name', 'primary', 'sequence', 'null', 'unique', 'default'] as $prop) { if ($this->{$prop} !== $column->{$prop}) { return false; } } /* If one, the other, or both aren't set, they're only equal if they're exactly equal */ if (!isset($this->type, $column->type)) { return $this->type === $column->type; } return $this->type->equals($column->type); }
public function resolves(Type $a, Type $b) { if ($a->equals($b)) { return true; } if ($a->type === Type::TYPE_LONG && $b->type === Type::TYPE_DOUBLE) { return true; } if ($a->type === Type::TYPE_USER && $b->type === Type::TYPE_USER) { foreach ($b->userTypes as $bt) { $bt = strtolower($bt); foreach ($a->userTypes as $at) { $at = strtolower($at); if (!isset($this->components['resolves'][$bt][$at])) { continue 2; } } // We got here, means we found an B type that's resolved by all A types return true; } // That means there is no A type that fully resolves at least one B type return false; } if (($b->type & $a->type) === $a->type) { return true; } return false; }
public function resolves(Type $a, Type $b) { if ($a->equals($b)) { return true; } if ($b->type === Type::TYPE_CALLABLE) { return $this->resolves($a, $this->callableUnion); } if ($a->type === Type::TYPE_OBJECT && $b->type === Type::TYPE_OBJECT) { return $this->checkUserTypes($a->userType, $b->userType); } if ($a->type === Type::TYPE_LONG && $b->type === Type::TYPE_DOUBLE) { return true; } if ($a->type === Type::TYPE_ARRAY && $b->type === Type::TYPE_ARRAY) { if (!$b->subTypes) { return true; } if (!$a->subTypes) { // We need a specific array return false; } return $this->resolves($a->subTypes[0], $b->subTypes[0]); } if ($a->type === Type::TYPE_UNION) { foreach ($a->subTypes as $st) { if ($this->resolves($st, $b)) { // All must resolve return false; } } return true; } if ($a->type === Type::TYPE_INTERSECTION) { foreach ($a->subTypes as $st) { if ($this->resolves($st, $b)) { // At least one resolves it return true; } } return false; } if ($b->type === Type::TYPE_UNION) { foreach ($b->subTypes as $st) { if ($this->resolves($a, $st)) { // At least one resolves it return true; } } return false; } if ($b->type === Type::TYPE_INTERSECTION) { foreach ($b->subTypes as $st) { if (!$this->resolves($a, $st)) { // At least one resolves it return false; } } return true; } return false; }