Merge branch 'master' into Eole

This commit is contained in:
josselin 2016-01-25 22:12:25 +01:00
commit 793a61475e
32 changed files with 1476 additions and 211 deletions

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "server/vendor/php-opencloud/openstack"]
path = server/vendor/php-opencloud/openstack
url = https://github.com/php-opencloud/openstack.git

BIN
client/images/logo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

View file

@ -1,6 +1,6 @@
<!doctype html>
<html lang="en">
<html lang="en" ng-app="mainApp">
<head>
<meta charset="utf-8">
@ -8,34 +8,66 @@
<meta name="description" content="Istic-Openstack project">
<meta name="author" content="IOTeam">
<link rel="stylesheet" href="./vendors/bootstrap/css/bootstrap.css">
<link rel="stylesheet" href="./css/style.css">
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<div class="container">
<div class="row">
<div class="col-sm-4">
<div class="panel panel-info">
<div class="panel-heading">
<h2>Simple Boostrap Testing</h2>
</div>
<div class="panel-body">
<p>Simple content</p>
</div>
</div>
</div>
</div>
</div>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="./vendors/bootstrap/js/bootstrap.min.js"></script>
<!-- MAIN GRID -->
<div class="container-lg">
<!-- Status bar -->
<div class="row" ng-controller="statusCtrl">
<div class="col-lg-12">
<!-- Nav -->
<div ng-include="'./partials/nav.html'"></div>
</div>
</div>
<!-- Page content -->
<div class="row">
<div class="col-lg-12">
<div class="container-fluid">
<div class="row">
<div class="col-lg-2">
<!-- Logo -->
<div ng-include="'./partials/favicon.html'"></div>
<!-- Left Menu -->
<div ng-include="'./partials/menu.html'"></div>
</div>
<div class="col-lg-10">
<div class="container-lg" >
<div class="row">
<div class="col-lg-12">
<div ng-view></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
<!-- Include JQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include Bootstrap -->
<script src="./vendors/bootstrap/js/bootstrap.min.js"></script>
<!-- Include AngularJS and dependencies-->
<script src="./vendors/angularjs/angular.min.js"></script>
<script src="./vendors/angularjs/angular-route.js"></script>
<script src="./js/app.js"></script>
<script src="./js/controllers/home.js"></script>
<script src="./js/controllers/network.js"></script>
<script src="./js/controllers/status.js"></script>
</html>

View file

@ -0,0 +1,18 @@
// Declare main app
var mainApp=angular.module("mainApp",['ngRoute']);
mainApp.config(['$routeProvider', function($routeProvider){
$routeProvider.
when('/home',{
templateUrl: 'partials/home.html',
controller: 'homeCtrl'
}).
when('/network',{
templateUrl: 'partials/network.html',
controller: 'networkCtrl'
}).otherwise({
redirectTo: '/home'
});
}]);

View file

@ -0,0 +1,10 @@
/*
* home Controller
*/
mainApp.controller('homeCtrl', function ($scope)
{
$scope.test="Home view";
});

View file

@ -0,0 +1,10 @@
/*
* network Controller
*/
mainApp.controller('networkCtrl', function ($scope)
{
$scope.test="Network View";
});

View file

@ -0,0 +1,12 @@
/*
* mainApp Controller
*/
mainApp.controller('statusCtrl', function ($scope)
{
$scope.username="User 1";
$scope.connection="Online";
$scope.lastconnection="1 Septembre";
});

View file

View file

@ -0,0 +1,3 @@
<a href="#" class="thumbnail">
<img class="media-object" src='./images/logo.gif' />
</a>

View file

@ -0,0 +1,9 @@
<div class="panel panel-default">
<div class="panel-heading">
{{ test }}
</div>
<div class="panel-body">
Main Content
</div>
</div>
</div>

View file

@ -0,0 +1,4 @@
<div class="list-group">
<a href="#/home" class="list-group-item">Home</a>
<a href="#/network" class="list-group-item">Network</a>
</div>

40
client/partials/nav.html Normal file
View file

@ -0,0 +1,40 @@
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><b>Status</b></a>
</div>
<div class="navbar-"></div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="nav-divider"></li>
<li><a href="#">User : {{ username }}</a></li>
<li><a href="#">Last Connection : {{ lastconnection }}</a></li>
<li><a href="#">Connection : {{ connection }}</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Account<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Informations</a></li>
<li><a href="#">Settings</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Logout</a></li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>

View file

@ -0,0 +1,9 @@
<div class="panel panel-default">
<div class="panel-heading">
{{ test }}
</div>
<div class="panel-body">
Main Content
</div>
</div>
</div>

1008
client/vendors/angularjs/angular-route.js vendored Normal file

File diff suppressed because it is too large Load diff

36
server/composer.lock generated
View file

@ -122,16 +122,16 @@
},
{
"name": "guzzlehttp/psr7",
"version": "1.2.1",
"version": "1.2.2",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "4d0bdbe1206df7440219ce14c972aa57cc5e4982"
"reference": "f5d04bdd2881ac89abde1fb78cc234bce24327bb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/4d0bdbe1206df7440219ce14c972aa57cc5e4982",
"reference": "4d0bdbe1206df7440219ce14c972aa57cc5e4982",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/f5d04bdd2881ac89abde1fb78cc234bce24327bb",
"reference": "f5d04bdd2881ac89abde1fb78cc234bce24327bb",
"shasum": ""
},
"require": {
@ -176,24 +176,24 @@
"stream",
"uri"
],
"time": "2015-11-03 01:34:55"
"time": "2016-01-23 01:23:02"
},
{
"name": "justinrainbow/json-schema",
"version": "v1.6.0",
"version": "1.6.1",
"source": {
"type": "git",
"url": "https://github.com/justinrainbow/json-schema.git",
"reference": "f9e27c3e202faf14fd581ef41355d83bb4b7eb7d"
"reference": "cc84765fb7317f6b07bd8ac78364747f95b86341"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/justinrainbow/json-schema/zipball/f9e27c3e202faf14fd581ef41355d83bb4b7eb7d",
"reference": "f9e27c3e202faf14fd581ef41355d83bb4b7eb7d",
"url": "https://api.github.com/repos/justinrainbow/json-schema/zipball/cc84765fb7317f6b07bd8ac78364747f95b86341",
"reference": "cc84765fb7317f6b07bd8ac78364747f95b86341",
"shasum": ""
},
"require": {
"php": ">=5.3.2"
"php": ">=5.3.29"
},
"require-dev": {
"json-schema/json-schema-test-suite": "1.1.0",
@ -206,7 +206,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4.x-dev"
"dev-master": "1.6.x-dev"
}
},
"autoload": {
@ -242,7 +242,7 @@
"json",
"schema"
],
"time": "2016-01-06 14:37:04"
"time": "2016-01-25 15:43:01"
},
{
"name": "php-opencloud/openstack",
@ -250,12 +250,12 @@
"source": {
"type": "git",
"url": "https://github.com/php-opencloud/openstack.git",
"reference": "8a6ec703597f0440e558d8f1f21b2ff303117dbd"
"reference": "15aca73f423166c7ef8337ba08615c103c66e931"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-opencloud/openstack/zipball/8a6ec703597f0440e558d8f1f21b2ff303117dbd",
"reference": "8a6ec703597f0440e558d8f1f21b2ff303117dbd",
"url": "https://api.github.com/repos/php-opencloud/openstack/zipball/15aca73f423166c7ef8337ba08615c103c66e931",
"reference": "15aca73f423166c7ef8337ba08615c103c66e931",
"shasum": ""
},
"require": {
@ -275,7 +275,9 @@
"type": "library",
"autoload": {
"psr-4": {
"OpenStack\\": "src/"
"OpenStack\\": "src/",
"OpenStack\\Test\\": "tests/unit/",
"OpenStack\\Integration\\": "tests/integration/"
}
},
"notification-url": "https://packagist.org/downloads/",
@ -286,7 +288,7 @@
"homepage": "https://github.com/jamiehannaford"
}
],
"time": "2016-01-20 12:27:59"
"time": "2016-01-25 10:35:10"
},
{
"name": "psr/http-message",

View file

@ -7,6 +7,8 @@ $baseDir = dirname($vendorDir);
return array(
'Psr\\Http\\Message\\' => array($vendorDir . '/psr/http-message/src'),
'OpenStack\\Test\\' => array($vendorDir . '/php-opencloud/openstack/tests/unit'),
'OpenStack\\Integration\\' => array($vendorDir . '/php-opencloud/openstack/tests/integration'),
'OpenStack\\' => array($vendorDir . '/php-opencloud/openstack/src'),
'JsonSchema\\' => array($vendorDir . '/justinrainbow/json-schema/src/JsonSchema'),
'GuzzleHttp\\Psr7\\' => array($vendorDir . '/guzzlehttp/psr7/src'),

View file

@ -1,72 +1,4 @@
[
{
"name": "justinrainbow/json-schema",
"version": "v1.6.0",
"version_normalized": "1.6.0.0",
"source": {
"type": "git",
"url": "https://github.com/justinrainbow/json-schema.git",
"reference": "f9e27c3e202faf14fd581ef41355d83bb4b7eb7d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/justinrainbow/json-schema/zipball/f9e27c3e202faf14fd581ef41355d83bb4b7eb7d",
"reference": "f9e27c3e202faf14fd581ef41355d83bb4b7eb7d",
"shasum": ""
},
"require": {
"php": ">=5.3.2"
},
"require-dev": {
"json-schema/json-schema-test-suite": "1.1.0",
"phpdocumentor/phpdocumentor": "~2",
"phpunit/phpunit": "~3.7"
},
"time": "2016-01-06 14:37:04",
"bin": [
"bin/validate-json"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4.x-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"JsonSchema\\": "src/JsonSchema/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Bruno Prieto Reis",
"email": "bruno.p.reis@gmail.com"
},
{
"name": "Justin Rainbow",
"email": "justin.rainbow@gmail.com"
},
{
"name": "Igor Wiedler",
"email": "igor@wiedler.ch"
},
{
"name": "Robert Schönthal",
"email": "seroscho@googlemail.com"
}
],
"description": "A library to validate a json schema.",
"homepage": "https://github.com/justinrainbow/json-schema",
"keywords": [
"json",
"schema"
]
},
{
"name": "guzzlehttp/promises",
"version": "1.0.3",
@ -171,66 +103,6 @@
"response"
]
},
{
"name": "guzzlehttp/psr7",
"version": "1.2.1",
"version_normalized": "1.2.1.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "4d0bdbe1206df7440219ce14c972aa57cc5e4982"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/4d0bdbe1206df7440219ce14c972aa57cc5e4982",
"reference": "4d0bdbe1206df7440219ce14c972aa57cc5e4982",
"shasum": ""
},
"require": {
"php": ">=5.4.0",
"psr/http-message": "~1.0"
},
"provide": {
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"time": "2015-11-03 01:34:55",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "PSR-7 message implementation",
"keywords": [
"http",
"message",
"stream",
"uri"
]
},
{
"name": "guzzlehttp/guzzle",
"version": "6.1.1",
@ -302,12 +174,12 @@
"source": {
"type": "git",
"url": "https://github.com/php-opencloud/openstack.git",
"reference": "8a6ec703597f0440e558d8f1f21b2ff303117dbd"
"reference": "15aca73f423166c7ef8337ba08615c103c66e931"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-opencloud/openstack/zipball/8a6ec703597f0440e558d8f1f21b2ff303117dbd",
"reference": "8a6ec703597f0440e558d8f1f21b2ff303117dbd",
"url": "https://api.github.com/repos/php-opencloud/openstack/zipball/15aca73f423166c7ef8337ba08615c103c66e931",
"reference": "15aca73f423166c7ef8337ba08615c103c66e931",
"shasum": ""
},
"require": {
@ -324,12 +196,14 @@
"sami/sami": "dev-master",
"satooshi/php-coveralls": "~1.0"
},
"time": "2016-01-20 12:27:59",
"time": "2016-01-25 10:35:10",
"type": "library",
"installation-source": "source",
"autoload": {
"psr-4": {
"OpenStack\\": "src/"
"OpenStack\\": "src/",
"OpenStack\\Test\\": "tests/unit/",
"OpenStack\\Integration\\": "tests/integration/"
}
},
"notification-url": "https://packagist.org/downloads/",
@ -340,5 +214,133 @@
"homepage": "https://github.com/jamiehannaford"
}
]
},
{
"name": "justinrainbow/json-schema",
"version": "1.6.1",
"version_normalized": "1.6.1.0",
"source": {
"type": "git",
"url": "https://github.com/justinrainbow/json-schema.git",
"reference": "cc84765fb7317f6b07bd8ac78364747f95b86341"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/justinrainbow/json-schema/zipball/cc84765fb7317f6b07bd8ac78364747f95b86341",
"reference": "cc84765fb7317f6b07bd8ac78364747f95b86341",
"shasum": ""
},
"require": {
"php": ">=5.3.29"
},
"require-dev": {
"json-schema/json-schema-test-suite": "1.1.0",
"phpdocumentor/phpdocumentor": "~2",
"phpunit/phpunit": "~3.7"
},
"time": "2016-01-25 15:43:01",
"bin": [
"bin/validate-json"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.6.x-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"JsonSchema\\": "src/JsonSchema/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Bruno Prieto Reis",
"email": "bruno.p.reis@gmail.com"
},
{
"name": "Justin Rainbow",
"email": "justin.rainbow@gmail.com"
},
{
"name": "Igor Wiedler",
"email": "igor@wiedler.ch"
},
{
"name": "Robert Schönthal",
"email": "seroscho@googlemail.com"
}
],
"description": "A library to validate a json schema.",
"homepage": "https://github.com/justinrainbow/json-schema",
"keywords": [
"json",
"schema"
]
},
{
"name": "guzzlehttp/psr7",
"version": "1.2.2",
"version_normalized": "1.2.2.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "f5d04bdd2881ac89abde1fb78cc234bce24327bb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/f5d04bdd2881ac89abde1fb78cc234bce24327bb",
"reference": "f5d04bdd2881ac89abde1fb78cc234bce24327bb",
"shasum": ""
},
"require": {
"php": ">=5.4.0",
"psr/http-message": "~1.0"
},
"provide": {
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"time": "2016-01-23 01:23:02",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "PSR-7 message implementation",
"keywords": [
"http",
"message",
"stream",
"uri"
]
}
]

View file

@ -1,5 +1,12 @@
# CHANGELOG
## 1.2.2 - 2016-01-22
* Added support for URIs without any authority.
* Added support for HTTP 451 'Unavailable For Legal Reasons.'
* Added support for using '0' as a filename.
* Added support for including non-standard ports in Host headers.
## 1.2.1 - 2015-11-02
* Now supporting negative offsets when seeking to SEEK_END.

View file

@ -9,5 +9,21 @@ coverage:
view-coverage:
open artifacts/coverage/index.html
check-tag:
$(if $(TAG),,$(error TAG is not defined. Pass via "make tag TAG=4.2.1"))
tag: check-tag
@echo Tagging $(TAG)
chag update $(TAG)
git commit -a -m '$(TAG) release'
chag tag
@echo "Release has been created. Push using 'make release'"
@echo "Changes made in the release commit"
git diff HEAD~1 HEAD
release: check-tag
git push origin master
git push origin $(TAG)
clean:
rm -rf artifacts/*

View file

@ -6,6 +6,9 @@ functionality like query string parsing. Currently missing
ServerRequestInterface and UploadedFileInterface; a pull request for these features is welcome.
[![Build Status](https://travis-ci.org/guzzle/psr7.svg?branch=master)](https://travis-ci.org/guzzle/psr7)
# Stream implementation
This package comes with a number of stream implementations and stream
@ -25,7 +28,7 @@ $a = Psr7\stream_for('abc, ');
$b = Psr7\stream_for('123.');
$composed = new Psr7\AppendStream([$a, $b]);
$composed->addStream(Psr7\stream_for(' Above all listen to me').
$composed->addStream(Psr7\stream_for(' Above all listen to me'));
echo $composed(); // abc, 123. Above all listen to me.
```

View file

@ -113,7 +113,7 @@ class MultipartStream implements StreamInterface
// Set a default content-disposition header if one was no provided
$disposition = $this->getHeader($headers, 'content-disposition');
if (!$disposition) {
$headers['Content-Disposition'] = $filename
$headers['Content-Disposition'] = ($filename === '0' || $filename)
? sprintf('form-data; name="%s"; filename="%s"',
$name,
basename($filename))
@ -130,7 +130,7 @@ class MultipartStream implements StreamInterface
// Set a default Content-Type if one was not supplied
$type = $this->getHeader($headers, 'content-type');
if (!$type && $filename) {
if (!$type && ($filename === '0' || $filename)) {
if ($type = mimetype_from_filename($filename)) {
$headers['Content-Type'] = $type;
}

View file

@ -59,6 +59,7 @@ class Response implements ResponseInterface
428 => 'Precondition Required',
429 => 'Too Many Requests',
431 => 'Request Header Fields Too Large',
451 => 'Unavailable For Legal Reasons',
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',

View file

@ -477,21 +477,28 @@ class Uri implements UriInterface
$uri = '';
if (!empty($scheme)) {
$uri .= $scheme . '://';
$uri .= $scheme . ':';
}
$hierPart = '';
if (!empty($authority)) {
$uri .= $authority;
if (!empty($scheme)) {
$hierPart .= '//';
}
$hierPart .= $authority;
}
if ($path != null) {
// Add a leading slash if necessary.
if ($uri && substr($path, 0, 1) !== '/') {
$uri .= '/';
if ($hierPart && substr($path, 0, 1) !== '/') {
$hierPart .= '/';
}
$uri .= $path;
$hierPart .= $path;
}
$uri .= $hierPart;
if ($query != null) {
$uri .= '?' . $query;
}

View file

@ -209,6 +209,14 @@ function modify_request(RequestInterface $request, array $changes)
// Remove the host header if one is on the URI
if ($host = $changes['uri']->getHost()) {
$changes['set_headers']['Host'] = $host;
if ($port = $changes['uri']->getPort()) {
$standardPorts = ['http' => 80, 'https' => 443];
$scheme = $changes['uri']->getScheme();
if (isset($standardPorts[$scheme]) && $port != $standardPorts[$scheme]) {
$changes['set_headers']['Host'] .= ':'.$port;
}
}
}
$uri = $changes['uri'];
}

View file

@ -546,6 +546,16 @@ class FunctionsTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('www.foo.com', (string) $r2->getHeaderLine('host'));
}
public function testCanModifyRequestWithUriAndPort()
{
$r1 = new Psr7\Request('GET', 'http://foo.com:8000');
$r2 = Psr7\modify_request($r1, [
'uri' => new Psr7\Uri('http://www.foo.com:8000')
]);
$this->assertEquals('http://www.foo.com:8000', (string) $r2->getUri());
$this->assertEquals('www.foo.com:8000', (string) $r2->getHeaderLine('host'));
}
public function testCanModifyRequestWithCaseInsensitiveHeader()
{
$r1 = new Psr7\Request('GET', 'http://foo.com', ['User-Agent' => 'foo']);

View file

@ -244,4 +244,38 @@ class UriTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('foo', $uri->getPath());
$this->assertEquals('bar.com/foo', (string) $uri);
}
/**
* @dataProvider pathTestNoAuthority
*/
public function testNoAuthority($input)
{
$uri = new Uri($input);
$this->assertEquals($input, (string) $uri);
}
public function pathTestNoAuthority()
{
return [
// path-rootless
['urn:example:animal:ferret:nose'],
// path-absolute
['urn:/example:animal:ferret:nose'],
['urn:/'],
// path-empty
['urn:'],
['urn'],
];
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Unable to parse URI
*/
public function testNoAuthorityWithInvalidPath()
{
$input = 'urn://example:animal:ferret:nose';
$uri = new Uri($input);
}
}

View file

@ -36,7 +36,7 @@
}
}],
"require": {
"php": ">=5.3.2"
"php": ">=5.3.29"
},
"require-dev": {
"json-schema/JSON-Schema-Test-Suite": "1.1.0",
@ -52,7 +52,7 @@
"bin": ["bin/validate-json"],
"extra": {
"branch-alias": {
"dev-master": "1.4.x-dev"
"dev-master": "1.6.x-dev"
}
}
}

View file

@ -19,10 +19,27 @@ use JsonSchema\Validator;
class Factory
{
/**
* @var UriRetriever
* @var UriRetriever $uriRetriever
*/
protected $uriRetriever;
/**
* @var array $constraintMap
*/
protected $constraintMap = array(
'array' => 'JsonSchema\Constraints\CollectionConstraint',
'collection' => 'JsonSchema\Constraints\CollectionConstraint',
'object' => 'JsonSchema\Constraints\ObjectConstraint',
'type' => 'JsonSchema\Constraints\TypeConstraint',
'undefined' => 'JsonSchema\Constraints\UndefinedConstraint',
'string' => 'JsonSchema\Constraints\StringConstraint',
'number' => 'JsonSchema\Constraints\NumberConstraint',
'enum' => 'JsonSchema\Constraints\EnumConstraint',
'format' => 'JsonSchema\Constraints\FormatConstraint',
'schema' => 'JsonSchema\Constraints\SchemaConstraint',
'validator' => 'JsonSchema\Validator',
);
/**
* @param UriRetriever $uriRetriever
*/
@ -43,6 +60,25 @@ class Factory
return $this->uriRetriever;
}
/**
* @param string $name
* @param string $class
* @return Factory
*/
public function setConstraintClass($name, $class)
{
// Ensure class exists
if (!class_exists($class)) {
throw new InvalidArgumentException('Unknown constraint ' . $name);
}
// Ensure class is appropriate
if (!in_array('JsonSchema\Constraints\ConstraintInterface', class_implements($class))) {
throw new InvalidArgumentException('Invalid class ' . $name);
}
$this->constraintMap[$name] = $class;
return $this;
}
/**
* Create a constraint instance for the given constraint name.
*
@ -52,30 +88,9 @@ class Factory
*/
public function createInstanceFor($constraintName)
{
switch ($constraintName) {
case 'array':
case 'collection':
return new CollectionConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this);
case 'object':
return new ObjectConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this);
case 'type':
return new TypeConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this);
case 'undefined':
return new UndefinedConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this);
case 'string':
return new StringConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this);
case 'number':
return new NumberConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this);
case 'enum':
return new EnumConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this);
case 'format':
return new FormatConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this);
case 'schema':
return new SchemaConstraint(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this);
case 'validator':
return new Validator(Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this);
if (array_key_exists($constraintName, $this->constraintMap)) {
return new $this->constraintMap[$constraintName](Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this);
}
throw new InvalidArgumentException('Unknown constraint ' . $constraintName);
}
}

View file

@ -25,8 +25,8 @@ class NumberConstraint extends Constraint
// Verify minimum
if (isset($schema->exclusiveMinimum)) {
if (isset($schema->minimum)) {
if ($schema->exclusiveMinimum && $element === $schema->minimum) {
$this->addError($path, "Must have a minimum value greater than boundary value of " . $schema->minimum, 'exclusiveMinimum', array('minimum' => $schema->minimum,));
if ($schema->exclusiveMinimum && $element <= $schema->minimum) {
$this->addError($path, "Must have a minimum value of " . $schema->minimum, 'exclusiveMinimum', array('minimum' => $schema->minimum,));
} else if ($element < $schema->minimum) {
$this->addError($path, "Must have a minimum value of " . $schema->minimum, 'minimum', array('minimum' => $schema->minimum,));
}
@ -40,8 +40,8 @@ class NumberConstraint extends Constraint
// Verify maximum
if (isset($schema->exclusiveMaximum)) {
if (isset($schema->maximum)) {
if ($schema->exclusiveMaximum && $element === $schema->maximum) {
$this->addError($path, "Must have a maximum value less than boundary value of " . $schema->maximum, 'exclusiveMaximum', array('maximum' => $schema->maximum,));
if ($schema->exclusiveMaximum && $element >= $schema->maximum) {
$this->addError($path, "Must have a maximum value of " . $schema->maximum, 'exclusiveMaximum', array('maximum' => $schema->maximum,));
} else if ($element > $schema->maximum) {
$this->addError($path, "Must have a maximum value of " . $schema->maximum, 'maximum', array('maximum' => $schema->maximum,));
}

@ -1 +1 @@
Subproject commit 8a6ec703597f0440e558d8f1f21b2ff303117dbd
Subproject commit 15aca73f423166c7ef8337ba08615c103c66e931