Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ The format is based on [Keep a Changelog], and this project adheres to
### Added

- Added support for operator chaining (e.g. `a > b > c`).
- Added support for `shortestPath` and `allShortestPaths` pattern constructs.
- Added support for shortest path constructs (`SHORTEST k`, `ALL SHORTEST`, `SHORTEST k GROUPS`, and `ANY`).

### Changed

Expand Down
52 changes: 52 additions & 0 deletions src/Patterns/AllShortest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php declare(strict_types=1);
/*
* This file is part of php-cypher-dsl.
*
* Copyright (C) Wikibase Solutions
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace WikibaseSolutions\CypherDSL\Patterns;

use WikibaseSolutions\CypherDSL\Traits\PatternTraits\PatternTrait;

/**
* Represents the ALL SHORTEST construct.
*
* @see https://neo4j.com/docs/cypher-manual/current/patterns/shortest-paths/
*/
final class AllShortest implements CompletePattern
{
use PatternTrait;

/**
* @var CompletePattern The pattern to match
*/
private CompletePattern $pattern;

/**
* @param CompletePattern $pattern The pattern to find all shortest paths for
*/
public function __construct(CompletePattern $pattern)
{
$this->pattern = $pattern;
}

/**
* @inheritDoc
*/
public function toQuery(): string
{
$cql = '';

if (isset($this->variable)) {
$cql = $this->variable->toQuery() . ' = ';
}

$cql .= sprintf("ALL SHORTEST (%s)", $this->pattern->toQuery());

return $cql;
}
}
52 changes: 52 additions & 0 deletions src/Patterns/AllShortestPaths.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php declare(strict_types=1);
/*
* This file is part of php-cypher-dsl.
*
* Copyright (C) Wikibase Solutions
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace WikibaseSolutions\CypherDSL\Patterns;

use WikibaseSolutions\CypherDSL\Traits\PatternTraits\PatternTrait;

/**
* Represents an allShortestPaths pattern.
*
* @see https://neo4j.com/docs/cypher-manual/current/patterns/reference/#shortest-functions
*/
final class AllShortestPaths implements CompletePattern
{
use PatternTrait;

/**
* @var CompletePattern The pattern to match
*/
private CompletePattern $pattern;

/**
* @param CompletePattern $pattern The pattern to find all shortest paths for
*/
public function __construct(CompletePattern $pattern)
{
$this->pattern = $pattern;
}

/**
* @inheritDoc
*/
public function toQuery(): string
{
$cql = '';

if (isset($this->variable)) {
$cql = $this->variable->toQuery() . ' = ';
}

$cql .= sprintf("allShortestPaths(%s)", $this->pattern->toQuery());

return $cql;
}
}
52 changes: 52 additions & 0 deletions src/Patterns/AnyPath.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php declare(strict_types=1);
/*
* This file is part of php-cypher-dsl.
*
* Copyright (C) Wikibase Solutions
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace WikibaseSolutions\CypherDSL\Patterns;

use WikibaseSolutions\CypherDSL\Traits\PatternTraits\PatternTrait;

/**
* Represents the ANY construct.
*
* @see https://neo4j.com/docs/cypher-manual/current/patterns/shortest-paths/
*/
final class AnyPath implements CompletePattern
{
use PatternTrait;

/**
* @var CompletePattern The pattern to match
*/
private CompletePattern $pattern;

/**
* @param CompletePattern $pattern The pattern to find any path for
*/
public function __construct(CompletePattern $pattern)
{
$this->pattern = $pattern;
}

/**
* @inheritDoc
*/
public function toQuery(): string
{
$cql = '';

if (isset($this->variable)) {
$cql = $this->variable->toQuery() . ' = ';
}

$cql .= sprintf("ANY (%s)", $this->pattern->toQuery());

return $cql;
}
}
61 changes: 61 additions & 0 deletions src/Patterns/Shortest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php declare(strict_types=1);
/*
* This file is part of php-cypher-dsl.
*
* Copyright (C) Wikibase Solutions
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace WikibaseSolutions\CypherDSL\Patterns;

use WikibaseSolutions\CypherDSL\Traits\PatternTraits\PatternTrait;
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\IntegerType;
use WikibaseSolutions\CypherDSL\Utils\CastUtils;

/**
* Represents the SHORTEST k construct.
*
* @see https://neo4j.com/docs/cypher-manual/current/patterns/shortest-paths/
*/
final class Shortest implements CompletePattern
{
use PatternTrait;

/**
* @var CompletePattern The pattern to match
*/
private CompletePattern $pattern;

/**
* @var IntegerType The number of paths to match
*/
private IntegerType $k;

/**
* @param CompletePattern $pattern The pattern to find the shortest path for
* @param int|IntegerType $k The number of paths to match
*/
public function __construct(CompletePattern $pattern, int|IntegerType $k)
{
$this->pattern = $pattern;
$this->k = CastUtils::toIntegerType($k);
}

/**
* @inheritDoc
*/
public function toQuery(): string
{
$cql = '';

if (isset($this->variable)) {
$cql = $this->variable->toQuery() . ' = ';
}

$cql .= sprintf("SHORTEST %s (%s)", $this->k->toQuery(), $this->pattern->toQuery());

return $cql;
}
}
61 changes: 61 additions & 0 deletions src/Patterns/ShortestGroups.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php declare(strict_types=1);
/*
* This file is part of php-cypher-dsl.
*
* Copyright (C) Wikibase Solutions
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace WikibaseSolutions\CypherDSL\Patterns;

use WikibaseSolutions\CypherDSL\Traits\PatternTraits\PatternTrait;
use WikibaseSolutions\CypherDSL\Types\PropertyTypes\IntegerType;
use WikibaseSolutions\CypherDSL\Utils\CastUtils;

/**
* Represents the SHORTEST k GROUPS construct.
*
* @see https://neo4j.com/docs/cypher-manual/current/patterns/shortest-paths/
*/
final class ShortestGroups implements CompletePattern
{
use PatternTrait;

/**
* @var CompletePattern The pattern to match
*/
private CompletePattern $pattern;

/**
* @var IntegerType The number of groups to match
*/
private IntegerType $k;

/**
* @param CompletePattern $pattern The pattern to find the shortest groups for
* @param int|IntegerType $k The number of groups to match
*/
public function __construct(CompletePattern $pattern, int|IntegerType $k)
{
$this->pattern = $pattern;
$this->k = CastUtils::toIntegerType($k);
}

/**
* @inheritDoc
*/
public function toQuery(): string
{
$cql = '';

if (isset($this->variable)) {
$cql = $this->variable->toQuery() . ' = ';
}

$cql .= sprintf("SHORTEST %s GROUPS (%s)", $this->k->toQuery(), $this->pattern->toQuery());

return $cql;
}
}
52 changes: 52 additions & 0 deletions src/Patterns/ShortestPath.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php declare(strict_types=1);
/*
* This file is part of php-cypher-dsl.
*
* Copyright (C) Wikibase Solutions
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace WikibaseSolutions\CypherDSL\Patterns;

use WikibaseSolutions\CypherDSL\Traits\PatternTraits\PatternTrait;

/**
* Represents a shortestPath pattern.
*
* @see https://neo4j.com/docs/cypher-manual/current/patterns/reference/#shortest-functions
*/
final class ShortestPath implements CompletePattern
{
use PatternTrait;

/**
* @var CompletePattern The pattern to match
*/
private CompletePattern $pattern;

/**
* @param CompletePattern $pattern The pattern to find the shortest path for
*/
public function __construct(CompletePattern $pattern)
{
$this->pattern = $pattern;
}

/**
* @inheritDoc
*/
public function toQuery(): string
{
$cql = '';

if (isset($this->variable)) {
$cql = $this->variable->toQuery() . ' = ';
}

$cql .= sprintf("shortestPath(%s)", $this->pattern->toQuery());

return $cql;
}
}
Loading
Loading