Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
tmilos committed Dec 20, 2016
1 parent 630a840 commit 7a9d864
Show file tree
Hide file tree
Showing 21 changed files with 1,050 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/tests export-ignore
.gitattributes export-ignore
.github/ export-ignore
.gitignore export-ignore
.travis.yml export-ignore
phpunit.xml.dist export-ignore
* text=auto eol=lf
*.php text whitespace=blank-at-eol,blank-at-eof,space-before-tab,tab-in-indent,tabwidth=4 diff=php
*.json text whitespace=blank-at-eol,blank-at-eof,space-before-tab,tab-in-indent,tabwidth=4
*.yml text whitespace=blank-at-eol,blank-at-eof,space-before-tab,tab-in-indent,tabwidth=4
*.md text whitespace=blank-at-eol,blank-at-eof
*.rst text whitespace=blank-at-eol,blank-at-eof
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
composer.phar
/vendor/

# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock
/composer.lock
/build/logs
26 changes: 26 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in('src')
;

$header = <<<EOT
This file is part of the tmilos/scim-filter-parser package.
(c) Milos Tomic <[email protected]>
This source file is subject to the MIT license that is bundled
with this source code in the file LICENSE.
EOT;

return PhpCsFixer\Config::create()
->setRules(array(
'@Symfony' => true,
'simplified_null_return' => false,
'phpdoc_no_empty_return' => false,
'no_mixed_echo_print' => ['use' => 'print'],
'header_comment' => ['header' => $header],
))
->setUsingCache(false)
->setFinder($finder)
;
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
language: php

php:
- 5.6
- 7.0
- 7.1

before_install:
- composer self-update
- composer --version
- wget http://get.sensiolabs.org/php-cs-fixer.phar -O php-cs-fixer.phar
- php php-cs-fixer.phar --version

install:
- COMPOSER_ROOT_VERSION=dev-master composer update --prefer-source

script:
- if [ "$TRAVIS_PHP_VERSION" == "7.0" ]; then php php-cs-fixer.phar fix --dry-run -v; fi
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml

after_script:
- if [ "$TRAVIS_PHP_VERSION" == "7.0" ]; then vendor/bin/coveralls -v; fi
8 changes: 8 additions & 0 deletions autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

// if library is in dev environement with its own vendor, include its autoload
if(file_exists(__DIR__ . '/vendor'))
require_once __DIR__ . '/vendor/autoload.php';
// if library is in vendor of another project, include the global autolaod
else
require_once __DIR__ . '/../../autoload.php';
26 changes: 26 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "tmilos/scim-filter-parser",
"description": "SCIM AST filter parser library",
"keywords": ["SCIM", "AST", "parser", "SCIM parser", "SCIM filter parser", "SCIM AST"],
"license": "MIT",
"authors": [
{
"name": "Milos Tomic",
"email": "[email protected]"
}
],
"autoload": {
"psr-4": {
"Tmilos\\ScimFilterParser\\": "src/",
"Tests\\Tmilos\\ScimFilterParser\\": "tests/"
}
},
"minimum-stability": "stable",
"require": {
"tmilos/lexer": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"satooshi/php-coveralls": "^1.0"
}
}
40 changes: 40 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit
backupGlobals = "false"
backupStaticAttributes = "false"
colors = "false"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
processIsolation = "false"
stopOnFailure = "false"
syntaxCheck = "false"
bootstrap = "autoload.php"
>

<logging>
<log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
</logging>

<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<!--
<php>
<server name="KERNEL_DIR" value="/path/to/your/app/" />
</php>
-->

<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>


</phpunit>
35 changes: 35 additions & 0 deletions src/Ast/AttributePath.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* This file is part of the tmilos/scim-filter-parser package.
*
* (c) Milos Tomic <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Tmilos\ScimFilterParser\Ast;

class AttributePath extends Node
{
/** @var string[] */
public $attributeNames = [];

public function add($attributeName)
{
$this->attributeNames[] = $attributeName;
}

public function __toString()
{
return implode('.', $this->attributeNames);
}

public function dump()
{
return [
'AttributePath: '.implode('.', $this->attributeNames),
];
}
}
52 changes: 52 additions & 0 deletions src/Ast/ComparisonExpression.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/*
* This file is part of the tmilos/scim-filter-parser package.
*
* (c) Milos Tomic <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Tmilos\ScimFilterParser\Ast;

class ComparisonExpression extends Factor
{
/** @var AttributePath */
public $attributePath;

/** @var string */
public $operator;

/** @var mixed */
public $compareValue;

/**
* @param AttributePath $attributePath
* @param string $operator
* @param mixed $compareValue
*/
public function __construct(AttributePath $attributePath, $operator, $compareValue = null)
{
$this->attributePath = $attributePath;
$this->operator = $operator;
$this->compareValue = $compareValue;
}

public function __toString()
{
if ($this->operator === 'pr') {
return sprintf('%s %s', $this->attributePath, $this->operator);
} else {
return sprintf('%s %s %s', $this->attributePath, $this->operator, $this->compareValue instanceof \DateTime ? $this->compareValue->format('Y-m-d\TH:i:s\Z') : $this->compareValue);
}
}

public function dump()
{
return [
'ComparisonExpression' => (string) $this,
];
}
}
61 changes: 61 additions & 0 deletions src/Ast/Conjunction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/*
* This file is part of the tmilos/scim-filter-parser package.
*
* (c) Milos Tomic <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Tmilos\ScimFilterParser\Ast;

class Conjunction extends Term
{
/** @var Filter[] */
private $factors = [];

/**
* @param Filter[] $factors
*/
public function __construct(array $factors = [])
{
foreach ($factors as $factor) {
$this->add($factor);
}
}

/**
* @param Filter $factor
*/
public function add(Filter $factor)
{
$this->factors[] = $factor;
}

/**
* @return Filter[]
*/
public function getFactors()
{
return $this->factors;
}

public function dump()
{
$arr = [];
foreach ($this->factors as $factor) {
$arr[] = $factor->dump();
}

return [
'Conjunction' => $arr,
];
}

public function __toString()
{
return implode(' and ', $this->factors);
}
}
61 changes: 61 additions & 0 deletions src/Ast/Disjunction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/*
* This file is part of the tmilos/scim-filter-parser package.
*
* (c) Milos Tomic <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Tmilos\ScimFilterParser\Ast;

class Disjunction extends Filter
{
/** @var Term[] */
private $terms = [];

/**
* @param Term[] $terms
*/
public function __construct(array $terms = [])
{
foreach ($terms as $term) {
$this->add($term);
}
}

/**
* @param Term $term
*/
public function add(Term $term)
{
$this->terms[] = $term;
}

/**
* @return Term[]
*/
public function getTerms()
{
return $this->terms;
}

public function __toString()
{
return implode(' or ', $this->terms);
}

public function dump()
{
$arr = [];
foreach ($this->terms as $term) {
$arr[] = $term->dump();
}

return [
'Disjunction' => $arr,
];
}
}
16 changes: 16 additions & 0 deletions src/Ast/Factor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the tmilos/scim-filter-parser package.
*
* (c) Milos Tomic <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Tmilos\ScimFilterParser\Ast;

abstract class Factor extends Term
{
}
16 changes: 16 additions & 0 deletions src/Ast/Filter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the tmilos/scim-filter-parser package.
*
* (c) Milos Tomic <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Tmilos\ScimFilterParser\Ast;

abstract class Filter extends Node
{
}
Loading

0 comments on commit 7a9d864

Please sign in to comment.