LeanQuery/Relationship.php
/**
	 * @param string $definition
	 * @return self
	 * @throws InvalidArgumentException
	 */
@param string $definition
@return self
@throws InvalidArgumentException
@param string $definition @return self @throws InvalidArgumentException
public static function createFromString($definition)
	{
		$matches = array();
		if (!preg_match('#^\s*(' . self::RE_IDENTIFIER . ')(?:\((' . self::RE_IDENTIFIER . ')\))?\.(' . self::RE_IDENTIFIER . ')\s*(' . self::DIRECTION_REFERENCED . '|' . self::DIRECTION_REFERENCING . '|' . self::DIRECTION_BOTH . ')\s*(' . self::RE_IDENTIFIER . ')(?:\((' . self::RE_IDENTIFIER . ')\))?\.(' . self::RE_IDENTIFIER . ')\s*$#', $definition, $matches)) {
			throw new InvalidArgumentException("Invalid relationships definition given: $definition");
		}
		if ($matches[4] === self::DIRECTION_REFERENCED) {
			$direction = self::DIRECTION_REFERENCED;
		} elseif ($matches[4] === self::DIRECTION_REFERENCING) {
			$direction = self::DIRECTION_REFERENCING;
		} else {
			$direction = self::DIRECTION_BOTH;
		}
		return new self(
			$matches[1],
			$matches[2] !== '' ? $matches[2] : $matches[1],
			$matches[3],
			$direction,
			$matches[5],
			$matches[6] !== '' ? $matches[6] : $matches[5],
			$matches[7]
		);
	}
public static function createFromString ( $ definition ) { $ matches = array ( ) ; if ( ! preg_match ( '#^\s*(' . self :: RE_IDENTIFIER . ')(?:\((' . self :: RE_IDENTIFIER . ')\))?\.(' . self :: RE_IDENTIFIER . ')\s*(' . self :: DIRECTION_REFERENCED . '|' . self :: DIRECTION_REFERENCING . '|' . self :: DIRECTION_BOTH . ')\s*(' . self :: RE_IDENTIFIER . ')(?:\((' . self :: RE_IDENTIFIER . ')\))?\.(' . self :: RE_IDENTIFIER . ')\s*$#' , $ definition , $ matches ) ) { throw new InvalidArgumentException ( " Invalid relationships definition given:  $ definition " ) ; } if ( $ matches [ 4 ] === self :: DIRECTION_REFERENCED ) { $ direction = self :: DIRECTION_REFERENCED ; } elseif ( $ matches [ 4 ] === self :: DIRECTION_REFERENCING ) { $ direction = self :: DIRECTION_REFERENCING ; } else { $ direction = self :: DIRECTION_BOTH ; } return new self ( $ matches [ 1 ] , $ matches [ 2 ] !== '' ? $ matches [ 2 ] : $ matches [ 1 ] , $ matches [ 3 ] , $ direction , $ matches [ 5 ] , $ matches [ 6 ] !== '' ? $ matches [ 6 ] : $ matches [ 5 ] , $ matches [ 7 ] ) ; }
@param string $definition
 @return self
 @throws InvalidArgumentException
@param string $definition @return self @throws InvalidArgumentException
// brackets hell matching <sourcePrefix>[(<sourceTable)].<relationshipColumn><direction><targetPrefix>[(<targetTable)].<primaryKeyColumn>