├── .coveralls.yml ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── composer.json ├── composer.lock ├── phpunit.xml ├── sql └── oauth2.sql ├── src ├── Config.php ├── Mongo.php ├── OAuth2 │ ├── AccessTokenStorage.php │ ├── ClientStorage.php │ ├── RefreshTokenStorage.php │ ├── Resource.php │ ├── ScopeStorage.php │ ├── SessionStorage.php │ └── StorageAdapter.php ├── Object.php ├── Profiler.php ├── Resource.php ├── Router.php ├── String.php └── Time.php └── tests ├── Pickles ├── ConfigTest.php ├── ObjectTest.php ├── ProfilerTest.php ├── ResourceTest.php ├── RouterTest.php ├── StringTest.php └── TimeTest.php ├── bootstrap.php ├── schema.sql └── travis.sh /.coveralls.yml: -------------------------------------------------------------------------------- 1 | service_name: travis-ci 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Mostly taken from https://github.com/github/gitignore # 2 | ######################################################### 3 | 4 | # Global/Linux.gitignore # 5 | ########################## 6 | .* 7 | !.gitignore 8 | !.travis.yml 9 | !.coveralls.yml 10 | *~ 11 | vendor 12 | 13 | # Global/OSX.gitignore # 14 | ######################## 15 | .DS_Store 16 | .AppleDouble 17 | .LSOverride 18 | Icon 19 | 20 | # Thumbnails 21 | ._* 22 | 23 | # Files that might appear on external disk 24 | .Spotlight-V100 25 | .Trashes 26 | 27 | # Global/vim.gitignore # 28 | ######################## 29 | .*.sw[a-z] 30 | *.un~ 31 | Session.vim 32 | .netrwhist 33 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.4 5 | - 5.5 6 | - 5.6 7 | - hhvm 8 | 9 | matrix: 10 | allow_failures: 11 | - php: hhvm 12 | 13 | branches: 14 | only: 15 | - master 16 | - 2.0 17 | - 1.9 18 | 19 | services: 20 | - memcache 21 | - memcached 22 | - redis 23 | 24 | install: 25 | - composer self-update 26 | - composer install 27 | 28 | before_script: 29 | - ./tests/travis.sh 30 | - mysql -e "create database IF NOT EXISTS test;" -u root 31 | - mysql test < tests/schema.sql -u root 32 | - mkdir -p build/logs 33 | - phpenv rehash 34 | 35 | script: 36 | - phpunit --coverage-clover /home/travis/build/joshtronic/pickles/build/logs/clover.xml 37 | 38 | after_success: 39 | - php vendor/bin/coveralls --config ../.coveralls.yml -v 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2007-2014 Josh Sherman 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pickles 2 | 3 | [![License](http://img.shields.io/packagist/l/joshtronic/pickles.svg?style=flat)][packagist] 4 | [![Build](http://img.shields.io/travis/joshtronic/pickles.svg?style=flat)][travis] 5 | [![Coverage](http://img.shields.io/coveralls/joshtronic/pickles.svg?style=flat)][coveralls] 6 | [![Downloads](http://img.shields.io/packagist/dt/joshtronic/pickles.svg?style=flat)][packagist] 7 | 8 | Pickles f/k/a PICKLES (PHP Interface Collection of Killer Libraries to Enhance 9 | Stuff) is an open source framework for the rapid development of RESTful 10 | services. The intention of this framework is to allow developers to a means to 11 | develop service-oriented backend systems that are completely decoupled from the 12 | front end components. Thus allowing the freedom to build the front end 13 | implementation(s) using whichever tools they choose, be it Ember.js, Angular.js 14 | or some cool new system I’ve yet to hear of. 15 | 16 | ## Thanks 17 | 18 | Special thanks to [Geoff Oliver][GeoffOliver] for being a long time user and 19 | contributor, [Justin Davis][JustinDavis] for romanticizing the v2 reimagining 20 | and [Dean Jones][DeanJones] for helping to come up with the original PICKLES v1 21 | acronym. 22 | 23 | [coveralls]: https://coveralls.io/r/joshtronic/pickles 24 | [packagist]: https://packagist.org/packages/joshtronic/pickles 25 | [travis]: http://travis-ci.org/joshtronic/pickles 26 | [DeanJones]: https://github.com/deanproxy 27 | [GeoffOliver]: https://github.com/geoffoliver 28 | [JustinDavis]: http://justindavis.co 29 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "joshtronic/pickles", 3 | "description": "Pickles is a PHP framework for building kick-ass services", 4 | "type": "library", 5 | "keywords": ["framework", "api", "soa", "oauth"], 6 | "homepage": "http://picklesphp.com", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Josh Sherman", 11 | "email": "josh@gravityblvd.com", 12 | "homepage": "http://joshtronic.com" 13 | } 14 | ], 15 | "support": { 16 | "issues": "https://github.com/joshtronic/pickles/issues", 17 | "source": "https://github.com/joshtronic/pickles" 18 | }, 19 | "minimum-stability" : "dev", 20 | "require-dev": { 21 | "phpunit/phpunit": "dev-master", 22 | "satooshi/php-coveralls": "dev-master" 23 | }, 24 | "require": { 25 | "php": ">=5.4", 26 | "league/oauth2-server": "4.0.x-dev" 27 | }, 28 | "suggest": { 29 | "mongodb/mongo-php-driver": "Required to use the Mongo storage engine", 30 | "predis/predis": "Required to use the Redis storage engine" 31 | }, 32 | "autoload": { 33 | "psr-4": { 34 | "Pickles\\" : "src/" 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "hash": "65e330b4eb2873d61093fc36aa624d0f", 8 | "packages": [ 9 | { 10 | "name": "league/event", 11 | "version": "1.0.0", 12 | "source": { 13 | "type": "git", 14 | "url": "https://github.com/thephpleague/event.git", 15 | "reference": "06adb7ce55b93346be43a3ba677ac613bbf288a2" 16 | }, 17 | "dist": { 18 | "type": "zip", 19 | "url": "https://api.github.com/repos/thephpleague/event/zipball/06adb7ce55b93346be43a3ba677ac613bbf288a2", 20 | "reference": "06adb7ce55b93346be43a3ba677ac613bbf288a2", 21 | "shasum": "" 22 | }, 23 | "require": { 24 | "php": ">=5.4.0" 25 | }, 26 | "require-dev": { 27 | "henrikbjorn/phpspec-code-coverage": "1.0.*@dev", 28 | "phpspec/phpspec": "2.0.*@dev" 29 | }, 30 | "type": "library", 31 | "autoload": { 32 | "psr-4": { 33 | "League\\Event\\": "src/" 34 | } 35 | }, 36 | "notification-url": "https://packagist.org/downloads/", 37 | "license": [ 38 | "MIT" 39 | ], 40 | "authors": [ 41 | { 42 | "name": "Frank de Jonge", 43 | "email": "info@frenky.net" 44 | } 45 | ], 46 | "description": "Event package", 47 | "keywords": [ 48 | "emitter", 49 | "event", 50 | "listener" 51 | ], 52 | "time": "2014-09-09 14:40:43" 53 | }, 54 | { 55 | "name": "league/oauth2-server", 56 | "version": "dev-develop", 57 | "source": { 58 | "type": "git", 59 | "url": "https://github.com/thephpleague/oauth2-server.git", 60 | "reference": "6333a975f8fb51111b447a7e85806e4519fb52b9" 61 | }, 62 | "dist": { 63 | "type": "zip", 64 | "url": "https://api.github.com/repos/thephpleague/oauth2-server/zipball/6333a975f8fb51111b447a7e85806e4519fb52b9", 65 | "reference": "6333a975f8fb51111b447a7e85806e4519fb52b9", 66 | "shasum": "" 67 | }, 68 | "require": { 69 | "league/event": "1.0.*", 70 | "php": ">=5.4.0", 71 | "symfony/http-foundation": "~2.1" 72 | }, 73 | "replace": { 74 | "league/oauth2server": "*", 75 | "lncd/oauth2": "*" 76 | }, 77 | "require-dev": { 78 | "alexbilbie/fizzfuzz": "dev-develop", 79 | "codeception/codeception": "2.0.*", 80 | "league/phpunit-coverage-listener": "~1.0", 81 | "mockery/mockery": "~0.9", 82 | "phpunit/phpunit": "~4.0", 83 | "squizlabs/php_codesniffer": "~1.5" 84 | }, 85 | "type": "library", 86 | "extra": { 87 | "branch-alias": { 88 | "dev-develop": "4.0.x-dev" 89 | } 90 | }, 91 | "autoload": { 92 | "psr-4": { 93 | "League\\OAuth2\\Server\\": "src/" 94 | } 95 | }, 96 | "notification-url": "https://packagist.org/downloads/", 97 | "license": [ 98 | "MIT" 99 | ], 100 | "authors": [ 101 | { 102 | "name": "Alex Bilbie", 103 | "email": "hello@alexbilbie.com", 104 | "homepage": "http://www.alexbilbie.com", 105 | "role": "Developer" 106 | } 107 | ], 108 | "description": "A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.", 109 | "homepage": "http://oauth2.thephpleague.com/", 110 | "keywords": [ 111 | "Authentication", 112 | "api", 113 | "auth", 114 | "authorisation", 115 | "authorization", 116 | "oauth", 117 | "oauth 2", 118 | "oauth 2.0", 119 | "oauth2", 120 | "protect", 121 | "resource", 122 | "secure", 123 | "server" 124 | ], 125 | "time": "2014-10-03 13:42:01" 126 | }, 127 | { 128 | "name": "symfony/http-foundation", 129 | "version": "dev-master", 130 | "target-dir": "Symfony/Component/HttpFoundation", 131 | "source": { 132 | "type": "git", 133 | "url": "https://github.com/symfony/HttpFoundation.git", 134 | "reference": "c24942a7ec2d8409d1f60d02c4460ca8317e885a" 135 | }, 136 | "dist": { 137 | "type": "zip", 138 | "url": "https://api.github.com/repos/symfony/HttpFoundation/zipball/c24942a7ec2d8409d1f60d02c4460ca8317e885a", 139 | "reference": "c24942a7ec2d8409d1f60d02c4460ca8317e885a", 140 | "shasum": "" 141 | }, 142 | "require": { 143 | "php": ">=5.3.3" 144 | }, 145 | "require-dev": { 146 | "symfony/expression-language": "~2.4" 147 | }, 148 | "type": "library", 149 | "extra": { 150 | "branch-alias": { 151 | "dev-master": "2.6-dev" 152 | } 153 | }, 154 | "autoload": { 155 | "psr-0": { 156 | "Symfony\\Component\\HttpFoundation\\": "" 157 | }, 158 | "classmap": [ 159 | "Symfony/Component/HttpFoundation/Resources/stubs" 160 | ] 161 | }, 162 | "notification-url": "https://packagist.org/downloads/", 163 | "license": [ 164 | "MIT" 165 | ], 166 | "authors": [ 167 | { 168 | "name": "Symfony Community", 169 | "homepage": "http://symfony.com/contributors" 170 | }, 171 | { 172 | "name": "Fabien Potencier", 173 | "email": "fabien@symfony.com" 174 | } 175 | ], 176 | "description": "Symfony HttpFoundation Component", 177 | "homepage": "http://symfony.com", 178 | "time": "2014-10-07 14:06:18" 179 | } 180 | ], 181 | "packages-dev": [ 182 | { 183 | "name": "doctrine/instantiator", 184 | "version": "dev-master", 185 | "source": { 186 | "type": "git", 187 | "url": "https://github.com/doctrine/instantiator.git", 188 | "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119" 189 | }, 190 | "dist": { 191 | "type": "zip", 192 | "url": "https://api.github.com/repos/doctrine/instantiator/zipball/f976e5de371104877ebc89bd8fecb0019ed9c119", 193 | "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119", 194 | "shasum": "" 195 | }, 196 | "require": { 197 | "php": ">=5.3,<8.0-DEV" 198 | }, 199 | "require-dev": { 200 | "athletic/athletic": "~0.1.8", 201 | "ext-pdo": "*", 202 | "ext-phar": "*", 203 | "phpunit/phpunit": "~4.0", 204 | "squizlabs/php_codesniffer": "2.0.*@ALPHA" 205 | }, 206 | "type": "library", 207 | "extra": { 208 | "branch-alias": { 209 | "dev-master": "1.0.x-dev" 210 | } 211 | }, 212 | "autoload": { 213 | "psr-0": { 214 | "Doctrine\\Instantiator\\": "src" 215 | } 216 | }, 217 | "notification-url": "https://packagist.org/downloads/", 218 | "license": [ 219 | "MIT" 220 | ], 221 | "authors": [ 222 | { 223 | "name": "Marco Pivetta", 224 | "email": "ocramius@gmail.com", 225 | "homepage": "http://ocramius.github.com/" 226 | } 227 | ], 228 | "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", 229 | "homepage": "https://github.com/doctrine/instantiator", 230 | "keywords": [ 231 | "constructor", 232 | "instantiate" 233 | ], 234 | "time": "2014-10-13 12:58:55" 235 | }, 236 | { 237 | "name": "guzzle/guzzle", 238 | "version": "dev-master", 239 | "source": { 240 | "type": "git", 241 | "url": "https://github.com/guzzle/guzzle3.git", 242 | "reference": "3c0ca2255751631f1dd64eb16bbe3b9440258297" 243 | }, 244 | "dist": { 245 | "type": "zip", 246 | "url": "https://api.github.com/repos/guzzle/guzzle3/zipball/3c0ca2255751631f1dd64eb16bbe3b9440258297", 247 | "reference": "3c0ca2255751631f1dd64eb16bbe3b9440258297", 248 | "shasum": "" 249 | }, 250 | "require": { 251 | "ext-curl": "*", 252 | "php": ">=5.3.3", 253 | "symfony/event-dispatcher": "~2.1" 254 | }, 255 | "replace": { 256 | "guzzle/batch": "self.version", 257 | "guzzle/cache": "self.version", 258 | "guzzle/common": "self.version", 259 | "guzzle/http": "self.version", 260 | "guzzle/inflection": "self.version", 261 | "guzzle/iterator": "self.version", 262 | "guzzle/log": "self.version", 263 | "guzzle/parser": "self.version", 264 | "guzzle/plugin": "self.version", 265 | "guzzle/plugin-async": "self.version", 266 | "guzzle/plugin-backoff": "self.version", 267 | "guzzle/plugin-cache": "self.version", 268 | "guzzle/plugin-cookie": "self.version", 269 | "guzzle/plugin-curlauth": "self.version", 270 | "guzzle/plugin-error-response": "self.version", 271 | "guzzle/plugin-history": "self.version", 272 | "guzzle/plugin-log": "self.version", 273 | "guzzle/plugin-md5": "self.version", 274 | "guzzle/plugin-mock": "self.version", 275 | "guzzle/plugin-oauth": "self.version", 276 | "guzzle/service": "self.version", 277 | "guzzle/stream": "self.version" 278 | }, 279 | "require-dev": { 280 | "doctrine/cache": "~1.3", 281 | "monolog/monolog": "~1.0", 282 | "phpunit/phpunit": "3.7.*", 283 | "psr/log": "~1.0", 284 | "symfony/class-loader": "~2.1", 285 | "zendframework/zend-cache": "2.*,<2.3", 286 | "zendframework/zend-log": "2.*,<2.3" 287 | }, 288 | "type": "library", 289 | "extra": { 290 | "branch-alias": { 291 | "dev-master": "3.9-dev" 292 | } 293 | }, 294 | "autoload": { 295 | "psr-0": { 296 | "Guzzle": "src/", 297 | "Guzzle\\Tests": "tests/" 298 | } 299 | }, 300 | "notification-url": "https://packagist.org/downloads/", 301 | "license": [ 302 | "MIT" 303 | ], 304 | "authors": [ 305 | { 306 | "name": "Michael Dowling", 307 | "email": "mtdowling@gmail.com", 308 | "homepage": "https://github.com/mtdowling" 309 | }, 310 | { 311 | "name": "Guzzle Community", 312 | "homepage": "https://github.com/guzzle/guzzle/contributors" 313 | } 314 | ], 315 | "description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients", 316 | "homepage": "http://guzzlephp.org/", 317 | "keywords": [ 318 | "client", 319 | "curl", 320 | "framework", 321 | "http", 322 | "http client", 323 | "rest", 324 | "web service" 325 | ], 326 | "time": "2014-10-15 19:36:56" 327 | }, 328 | { 329 | "name": "phpunit/php-code-coverage", 330 | "version": "dev-master", 331 | "source": { 332 | "type": "git", 333 | "url": "https://github.com/sebastianbergmann/php-code-coverage.git", 334 | "reference": "28d21b57c189cb72829056353de603c4d4da55a0" 335 | }, 336 | "dist": { 337 | "type": "zip", 338 | "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/28d21b57c189cb72829056353de603c4d4da55a0", 339 | "reference": "28d21b57c189cb72829056353de603c4d4da55a0", 340 | "shasum": "" 341 | }, 342 | "require": { 343 | "php": ">=5.3.3", 344 | "phpunit/php-file-iterator": "~1.3", 345 | "phpunit/php-text-template": "~1.2", 346 | "phpunit/php-token-stream": "~1.3", 347 | "sebastian/environment": "~1.0", 348 | "sebastian/version": "~1.0" 349 | }, 350 | "require-dev": { 351 | "ext-xdebug": ">=2.1.4", 352 | "phpunit/phpunit": "dev-master" 353 | }, 354 | "suggest": { 355 | "ext-dom": "*", 356 | "ext-xdebug": ">=2.2.1", 357 | "ext-xmlwriter": "*" 358 | }, 359 | "type": "library", 360 | "extra": { 361 | "branch-alias": { 362 | "dev-master": "3.0.x-dev" 363 | } 364 | }, 365 | "autoload": { 366 | "classmap": [ 367 | "src/" 368 | ] 369 | }, 370 | "notification-url": "https://packagist.org/downloads/", 371 | "license": [ 372 | "BSD-3-Clause" 373 | ], 374 | "authors": [ 375 | { 376 | "name": "Sebastian Bergmann", 377 | "email": "sb@sebastian-bergmann.de", 378 | "role": "lead" 379 | } 380 | ], 381 | "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", 382 | "homepage": "https://github.com/sebastianbergmann/php-code-coverage", 383 | "keywords": [ 384 | "coverage", 385 | "testing", 386 | "xunit" 387 | ], 388 | "time": "2014-10-05 10:46:54" 389 | }, 390 | { 391 | "name": "phpunit/php-file-iterator", 392 | "version": "1.3.4", 393 | "source": { 394 | "type": "git", 395 | "url": "https://github.com/sebastianbergmann/php-file-iterator.git", 396 | "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb" 397 | }, 398 | "dist": { 399 | "type": "zip", 400 | "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/acd690379117b042d1c8af1fafd61bde001bf6bb", 401 | "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb", 402 | "shasum": "" 403 | }, 404 | "require": { 405 | "php": ">=5.3.3" 406 | }, 407 | "type": "library", 408 | "autoload": { 409 | "classmap": [ 410 | "File/" 411 | ] 412 | }, 413 | "notification-url": "https://packagist.org/downloads/", 414 | "include-path": [ 415 | "" 416 | ], 417 | "license": [ 418 | "BSD-3-Clause" 419 | ], 420 | "authors": [ 421 | { 422 | "name": "Sebastian Bergmann", 423 | "email": "sb@sebastian-bergmann.de", 424 | "role": "lead" 425 | } 426 | ], 427 | "description": "FilterIterator implementation that filters files based on a list of suffixes.", 428 | "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", 429 | "keywords": [ 430 | "filesystem", 431 | "iterator" 432 | ], 433 | "time": "2013-10-10 15:34:57" 434 | }, 435 | { 436 | "name": "phpunit/php-text-template", 437 | "version": "1.2.0", 438 | "source": { 439 | "type": "git", 440 | "url": "https://github.com/sebastianbergmann/php-text-template.git", 441 | "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a" 442 | }, 443 | "dist": { 444 | "type": "zip", 445 | "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", 446 | "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", 447 | "shasum": "" 448 | }, 449 | "require": { 450 | "php": ">=5.3.3" 451 | }, 452 | "type": "library", 453 | "autoload": { 454 | "classmap": [ 455 | "Text/" 456 | ] 457 | }, 458 | "notification-url": "https://packagist.org/downloads/", 459 | "include-path": [ 460 | "" 461 | ], 462 | "license": [ 463 | "BSD-3-Clause" 464 | ], 465 | "authors": [ 466 | { 467 | "name": "Sebastian Bergmann", 468 | "email": "sb@sebastian-bergmann.de", 469 | "role": "lead" 470 | } 471 | ], 472 | "description": "Simple template engine.", 473 | "homepage": "https://github.com/sebastianbergmann/php-text-template/", 474 | "keywords": [ 475 | "template" 476 | ], 477 | "time": "2014-01-30 17:20:04" 478 | }, 479 | { 480 | "name": "phpunit/php-timer", 481 | "version": "1.0.5", 482 | "source": { 483 | "type": "git", 484 | "url": "https://github.com/sebastianbergmann/php-timer.git", 485 | "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c" 486 | }, 487 | "dist": { 488 | "type": "zip", 489 | "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/19689d4354b295ee3d8c54b4f42c3efb69cbc17c", 490 | "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c", 491 | "shasum": "" 492 | }, 493 | "require": { 494 | "php": ">=5.3.3" 495 | }, 496 | "type": "library", 497 | "autoload": { 498 | "classmap": [ 499 | "PHP/" 500 | ] 501 | }, 502 | "notification-url": "https://packagist.org/downloads/", 503 | "include-path": [ 504 | "" 505 | ], 506 | "license": [ 507 | "BSD-3-Clause" 508 | ], 509 | "authors": [ 510 | { 511 | "name": "Sebastian Bergmann", 512 | "email": "sb@sebastian-bergmann.de", 513 | "role": "lead" 514 | } 515 | ], 516 | "description": "Utility class for timing", 517 | "homepage": "https://github.com/sebastianbergmann/php-timer/", 518 | "keywords": [ 519 | "timer" 520 | ], 521 | "time": "2013-08-02 07:42:54" 522 | }, 523 | { 524 | "name": "phpunit/php-token-stream", 525 | "version": "dev-master", 526 | "source": { 527 | "type": "git", 528 | "url": "https://github.com/sebastianbergmann/php-token-stream.git", 529 | "reference": "f8d5d08c56de5cfd592b3340424a81733259a876" 530 | }, 531 | "dist": { 532 | "type": "zip", 533 | "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/f8d5d08c56de5cfd592b3340424a81733259a876", 534 | "reference": "f8d5d08c56de5cfd592b3340424a81733259a876", 535 | "shasum": "" 536 | }, 537 | "require": { 538 | "ext-tokenizer": "*", 539 | "php": ">=5.3.3" 540 | }, 541 | "require-dev": { 542 | "phpunit/phpunit": "~4.2" 543 | }, 544 | "type": "library", 545 | "extra": { 546 | "branch-alias": { 547 | "dev-master": "1.3-dev" 548 | } 549 | }, 550 | "autoload": { 551 | "classmap": [ 552 | "src/" 553 | ] 554 | }, 555 | "notification-url": "https://packagist.org/downloads/", 556 | "license": [ 557 | "BSD-3-Clause" 558 | ], 559 | "authors": [ 560 | { 561 | "name": "Sebastian Bergmann", 562 | "email": "sebastian@phpunit.de" 563 | } 564 | ], 565 | "description": "Wrapper around PHP's tokenizer extension.", 566 | "homepage": "https://github.com/sebastianbergmann/php-token-stream/", 567 | "keywords": [ 568 | "tokenizer" 569 | ], 570 | "time": "2014-08-31 06:12:13" 571 | }, 572 | { 573 | "name": "phpunit/phpunit", 574 | "version": "dev-master", 575 | "source": { 576 | "type": "git", 577 | "url": "https://github.com/sebastianbergmann/phpunit.git", 578 | "reference": "cd4014775069d7d39d20f617037c2c0f9b4bc25b" 579 | }, 580 | "dist": { 581 | "type": "zip", 582 | "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/cd4014775069d7d39d20f617037c2c0f9b4bc25b", 583 | "reference": "cd4014775069d7d39d20f617037c2c0f9b4bc25b", 584 | "shasum": "" 585 | }, 586 | "require": { 587 | "ext-dom": "*", 588 | "ext-json": "*", 589 | "ext-pcre": "*", 590 | "ext-reflection": "*", 591 | "ext-spl": "*", 592 | "php": ">=5.3.3", 593 | "phpunit/php-code-coverage": "3.0.*@dev", 594 | "phpunit/php-file-iterator": "~1.3.1", 595 | "phpunit/php-text-template": "~1.2", 596 | "phpunit/php-timer": "~1.0.2", 597 | "phpunit/phpunit-mock-objects": "2.4.*@dev", 598 | "sebastian/comparator": "~1.0", 599 | "sebastian/diff": "~1.1", 600 | "sebastian/environment": "~1.1", 601 | "sebastian/exporter": "~1.0", 602 | "sebastian/global-state": "1.0.*@dev", 603 | "sebastian/version": "~1.0", 604 | "symfony/yaml": "~2.0" 605 | }, 606 | "suggest": { 607 | "phpunit/php-invoker": "~1.1" 608 | }, 609 | "bin": [ 610 | "phpunit" 611 | ], 612 | "type": "library", 613 | "extra": { 614 | "branch-alias": { 615 | "dev-master": "4.4.x-dev" 616 | } 617 | }, 618 | "autoload": { 619 | "classmap": [ 620 | "src/" 621 | ] 622 | }, 623 | "notification-url": "https://packagist.org/downloads/", 624 | "license": [ 625 | "BSD-3-Clause" 626 | ], 627 | "authors": [ 628 | { 629 | "name": "Sebastian Bergmann", 630 | "email": "sebastian@phpunit.de", 631 | "role": "lead" 632 | } 633 | ], 634 | "description": "The PHP Unit Testing framework.", 635 | "homepage": "https://phpunit.de/", 636 | "keywords": [ 637 | "phpunit", 638 | "testing", 639 | "xunit" 640 | ], 641 | "time": "2014-10-17 09:28:50" 642 | }, 643 | { 644 | "name": "phpunit/phpunit-mock-objects", 645 | "version": "dev-master", 646 | "source": { 647 | "type": "git", 648 | "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", 649 | "reference": "96c5b81f9842f38fe6c73ad0020306cc4862a9e3" 650 | }, 651 | "dist": { 652 | "type": "zip", 653 | "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/96c5b81f9842f38fe6c73ad0020306cc4862a9e3", 654 | "reference": "96c5b81f9842f38fe6c73ad0020306cc4862a9e3", 655 | "shasum": "" 656 | }, 657 | "require": { 658 | "doctrine/instantiator": "~1.0,>=1.0.2", 659 | "php": ">=5.3.3", 660 | "phpunit/php-text-template": "~1.2" 661 | }, 662 | "require-dev": { 663 | "phpunit/phpunit": "4.4.*@dev" 664 | }, 665 | "suggest": { 666 | "ext-soap": "*" 667 | }, 668 | "type": "library", 669 | "extra": { 670 | "branch-alias": { 671 | "dev-master": "2.4.x-dev" 672 | } 673 | }, 674 | "autoload": { 675 | "classmap": [ 676 | "src/" 677 | ] 678 | }, 679 | "notification-url": "https://packagist.org/downloads/", 680 | "license": [ 681 | "BSD-3-Clause" 682 | ], 683 | "authors": [ 684 | { 685 | "name": "Sebastian Bergmann", 686 | "email": "sb@sebastian-bergmann.de", 687 | "role": "lead" 688 | } 689 | ], 690 | "description": "Mock Object library for PHPUnit", 691 | "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", 692 | "keywords": [ 693 | "mock", 694 | "xunit" 695 | ], 696 | "time": "2014-10-04 10:04:20" 697 | }, 698 | { 699 | "name": "psr/log", 700 | "version": "1.0.0", 701 | "source": { 702 | "type": "git", 703 | "url": "https://github.com/php-fig/log.git", 704 | "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b" 705 | }, 706 | "dist": { 707 | "type": "zip", 708 | "url": "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b", 709 | "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b", 710 | "shasum": "" 711 | }, 712 | "type": "library", 713 | "autoload": { 714 | "psr-0": { 715 | "Psr\\Log\\": "" 716 | } 717 | }, 718 | "notification-url": "https://packagist.org/downloads/", 719 | "license": [ 720 | "MIT" 721 | ], 722 | "authors": [ 723 | { 724 | "name": "PHP-FIG", 725 | "homepage": "http://www.php-fig.org/" 726 | } 727 | ], 728 | "description": "Common interface for logging libraries", 729 | "keywords": [ 730 | "log", 731 | "psr", 732 | "psr-3" 733 | ], 734 | "time": "2012-12-21 11:40:51" 735 | }, 736 | { 737 | "name": "satooshi/php-coveralls", 738 | "version": "dev-master", 739 | "source": { 740 | "type": "git", 741 | "url": "https://github.com/satooshi/php-coveralls.git", 742 | "reference": "94389a0ebdb64857d6899b5e0254dffa99e5aa96" 743 | }, 744 | "dist": { 745 | "type": "zip", 746 | "url": "https://api.github.com/repos/satooshi/php-coveralls/zipball/94389a0ebdb64857d6899b5e0254dffa99e5aa96", 747 | "reference": "94389a0ebdb64857d6899b5e0254dffa99e5aa96", 748 | "shasum": "" 749 | }, 750 | "require": { 751 | "ext-json": "*", 752 | "ext-simplexml": "*", 753 | "guzzle/guzzle": ">=2.7", 754 | "php": ">=5.3", 755 | "psr/log": "1.0.0", 756 | "symfony/config": ">=2.0", 757 | "symfony/console": ">=2.0", 758 | "symfony/stopwatch": ">=2.2", 759 | "symfony/yaml": ">=2.0" 760 | }, 761 | "require-dev": { 762 | "apigen/apigen": "2.8.*@stable", 763 | "pdepend/pdepend": "dev-master as 2.0.0", 764 | "phpmd/phpmd": "dev-master", 765 | "phpunit/php-invoker": ">=1.1.0,<1.2.0", 766 | "phpunit/phpunit": "3.7.*@stable", 767 | "sebastian/finder-facade": "dev-master", 768 | "sebastian/phpcpd": "1.4.*@stable", 769 | "squizlabs/php_codesniffer": "1.4.*@stable", 770 | "theseer/fdomdocument": "dev-master" 771 | }, 772 | "suggest": { 773 | "symfony/http-kernel": "Allows Symfony integration" 774 | }, 775 | "bin": [ 776 | "composer/bin/coveralls" 777 | ], 778 | "type": "library", 779 | "extra": { 780 | "branch-alias": { 781 | "dev-master": "0.7-dev" 782 | } 783 | }, 784 | "autoload": { 785 | "psr-0": { 786 | "Satooshi\\Component": "src/", 787 | "Satooshi\\Bundle": "src/" 788 | } 789 | }, 790 | "notification-url": "https://packagist.org/downloads/", 791 | "license": [ 792 | "MIT" 793 | ], 794 | "authors": [ 795 | { 796 | "name": "Kitamura Satoshi", 797 | "email": "with.no.parachute@gmail.com", 798 | "homepage": "https://www.facebook.com/satooshi.jp" 799 | } 800 | ], 801 | "description": "PHP client library for Coveralls API", 802 | "homepage": "https://github.com/satooshi/php-coveralls", 803 | "keywords": [ 804 | "ci", 805 | "coverage", 806 | "github", 807 | "test" 808 | ], 809 | "time": "2014-07-09 10:45:38" 810 | }, 811 | { 812 | "name": "sebastian/comparator", 813 | "version": "dev-master", 814 | "source": { 815 | "type": "git", 816 | "url": "https://github.com/sebastianbergmann/comparator.git", 817 | "reference": "e54a01c0da1b87db3c5a3c4c5277ddf331da4aef" 818 | }, 819 | "dist": { 820 | "type": "zip", 821 | "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/e54a01c0da1b87db3c5a3c4c5277ddf331da4aef", 822 | "reference": "e54a01c0da1b87db3c5a3c4c5277ddf331da4aef", 823 | "shasum": "" 824 | }, 825 | "require": { 826 | "php": ">=5.3.3", 827 | "sebastian/diff": "~1.1", 828 | "sebastian/exporter": "~1.0" 829 | }, 830 | "require-dev": { 831 | "phpunit/phpunit": "~4.1" 832 | }, 833 | "type": "library", 834 | "extra": { 835 | "branch-alias": { 836 | "dev-master": "1.0.x-dev" 837 | } 838 | }, 839 | "autoload": { 840 | "classmap": [ 841 | "src/" 842 | ] 843 | }, 844 | "notification-url": "https://packagist.org/downloads/", 845 | "license": [ 846 | "BSD-3-Clause" 847 | ], 848 | "authors": [ 849 | { 850 | "name": "Sebastian Bergmann", 851 | "email": "sebastian@phpunit.de", 852 | "role": "lead" 853 | }, 854 | { 855 | "name": "Jeff Welch", 856 | "email": "whatthejeff@gmail.com" 857 | }, 858 | { 859 | "name": "Volker Dusch", 860 | "email": "github@wallbash.com" 861 | }, 862 | { 863 | "name": "Bernhard Schussek", 864 | "email": "bschussek@2bepublished.at" 865 | } 866 | ], 867 | "description": "Provides the functionality to compare PHP values for equality", 868 | "homepage": "http://www.github.com/sebastianbergmann/comparator", 869 | "keywords": [ 870 | "comparator", 871 | "compare", 872 | "equality" 873 | ], 874 | "time": "2014-05-11 23:00:21" 875 | }, 876 | { 877 | "name": "sebastian/diff", 878 | "version": "dev-master", 879 | "source": { 880 | "type": "git", 881 | "url": "https://github.com/sebastianbergmann/diff.git", 882 | "reference": "92d423df43b160006907ea4297b916fdf00415d8" 883 | }, 884 | "dist": { 885 | "type": "zip", 886 | "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/92d423df43b160006907ea4297b916fdf00415d8", 887 | "reference": "92d423df43b160006907ea4297b916fdf00415d8", 888 | "shasum": "" 889 | }, 890 | "require": { 891 | "php": ">=5.3.3" 892 | }, 893 | "require-dev": { 894 | "phpunit/phpunit": "~4.2" 895 | }, 896 | "type": "library", 897 | "extra": { 898 | "branch-alias": { 899 | "dev-master": "1.2-dev" 900 | } 901 | }, 902 | "autoload": { 903 | "classmap": [ 904 | "src/" 905 | ] 906 | }, 907 | "notification-url": "https://packagist.org/downloads/", 908 | "license": [ 909 | "BSD-3-Clause" 910 | ], 911 | "authors": [ 912 | { 913 | "name": "Kore Nordmann", 914 | "email": "mail@kore-nordmann.de" 915 | }, 916 | { 917 | "name": "Sebastian Bergmann", 918 | "email": "sebastian@phpunit.de" 919 | } 920 | ], 921 | "description": "Diff implementation", 922 | "homepage": "http://www.github.com/sebastianbergmann/diff", 923 | "keywords": [ 924 | "diff" 925 | ], 926 | "time": "2014-10-19 13:19:30" 927 | }, 928 | { 929 | "name": "sebastian/environment", 930 | "version": "dev-master", 931 | "source": { 932 | "type": "git", 933 | "url": "https://github.com/sebastianbergmann/environment.git", 934 | "reference": "205fcef5998953ec69cb79bc1ea9fee1277c8714" 935 | }, 936 | "dist": { 937 | "type": "zip", 938 | "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/205fcef5998953ec69cb79bc1ea9fee1277c8714", 939 | "reference": "205fcef5998953ec69cb79bc1ea9fee1277c8714", 940 | "shasum": "" 941 | }, 942 | "require": { 943 | "php": ">=5.3.3" 944 | }, 945 | "require-dev": { 946 | "phpunit/phpunit": "~4.3" 947 | }, 948 | "type": "library", 949 | "extra": { 950 | "branch-alias": { 951 | "dev-master": "1.1.x-dev" 952 | } 953 | }, 954 | "autoload": { 955 | "classmap": [ 956 | "src/" 957 | ] 958 | }, 959 | "notification-url": "https://packagist.org/downloads/", 960 | "license": [ 961 | "BSD-3-Clause" 962 | ], 963 | "authors": [ 964 | { 965 | "name": "Sebastian Bergmann", 966 | "email": "sebastian@phpunit.de" 967 | } 968 | ], 969 | "description": "Provides functionality to handle HHVM/PHP environments", 970 | "homepage": "http://www.github.com/sebastianbergmann/environment", 971 | "keywords": [ 972 | "Xdebug", 973 | "environment", 974 | "hhvm" 975 | ], 976 | "time": "2014-10-08 05:30:43" 977 | }, 978 | { 979 | "name": "sebastian/exporter", 980 | "version": "dev-master", 981 | "source": { 982 | "type": "git", 983 | "url": "https://github.com/sebastianbergmann/exporter.git", 984 | "reference": "c7d59948d6e82818e1bdff7cadb6c34710eb7dc0" 985 | }, 986 | "dist": { 987 | "type": "zip", 988 | "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/c7d59948d6e82818e1bdff7cadb6c34710eb7dc0", 989 | "reference": "c7d59948d6e82818e1bdff7cadb6c34710eb7dc0", 990 | "shasum": "" 991 | }, 992 | "require": { 993 | "php": ">=5.3.3" 994 | }, 995 | "require-dev": { 996 | "phpunit/phpunit": "~4.0" 997 | }, 998 | "type": "library", 999 | "extra": { 1000 | "branch-alias": { 1001 | "dev-master": "1.0.x-dev" 1002 | } 1003 | }, 1004 | "autoload": { 1005 | "classmap": [ 1006 | "src/" 1007 | ] 1008 | }, 1009 | "notification-url": "https://packagist.org/downloads/", 1010 | "license": [ 1011 | "BSD-3-Clause" 1012 | ], 1013 | "authors": [ 1014 | { 1015 | "name": "Jeff Welch", 1016 | "email": "whatthejeff@gmail.com" 1017 | }, 1018 | { 1019 | "name": "Volker Dusch", 1020 | "email": "github@wallbash.com" 1021 | }, 1022 | { 1023 | "name": "Bernhard Schussek", 1024 | "email": "bschussek@2bepublished.at" 1025 | }, 1026 | { 1027 | "name": "Sebastian Bergmann", 1028 | "email": "sebastian@phpunit.de" 1029 | }, 1030 | { 1031 | "name": "Adam Harvey", 1032 | "email": "aharvey@php.net" 1033 | } 1034 | ], 1035 | "description": "Provides the functionality to export PHP variables for visualization", 1036 | "homepage": "http://www.github.com/sebastianbergmann/exporter", 1037 | "keywords": [ 1038 | "export", 1039 | "exporter" 1040 | ], 1041 | "time": "2014-09-10 00:51:36" 1042 | }, 1043 | { 1044 | "name": "sebastian/global-state", 1045 | "version": "dev-master", 1046 | "source": { 1047 | "type": "git", 1048 | "url": "https://github.com/sebastianbergmann/global-state.git", 1049 | "reference": "231d48620efde984fd077ee92916099a3ece9a59" 1050 | }, 1051 | "dist": { 1052 | "type": "zip", 1053 | "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/231d48620efde984fd077ee92916099a3ece9a59", 1054 | "reference": "231d48620efde984fd077ee92916099a3ece9a59", 1055 | "shasum": "" 1056 | }, 1057 | "require": { 1058 | "php": ">=5.3.3" 1059 | }, 1060 | "require-dev": { 1061 | "phpunit/phpunit": "~4.2" 1062 | }, 1063 | "suggest": { 1064 | "ext-uopz": "*" 1065 | }, 1066 | "type": "library", 1067 | "extra": { 1068 | "branch-alias": { 1069 | "dev-master": "1.0-dev" 1070 | } 1071 | }, 1072 | "autoload": { 1073 | "classmap": [ 1074 | "src/" 1075 | ] 1076 | }, 1077 | "notification-url": "https://packagist.org/downloads/", 1078 | "license": [ 1079 | "BSD-3-Clause" 1080 | ], 1081 | "authors": [ 1082 | { 1083 | "name": "Sebastian Bergmann", 1084 | "email": "sebastian@phpunit.de" 1085 | } 1086 | ], 1087 | "description": "Snapshotting of global state", 1088 | "homepage": "http://www.github.com/sebastianbergmann/global-state", 1089 | "keywords": [ 1090 | "global state" 1091 | ], 1092 | "time": "2014-10-06 09:49:11" 1093 | }, 1094 | { 1095 | "name": "sebastian/version", 1096 | "version": "1.0.3", 1097 | "source": { 1098 | "type": "git", 1099 | "url": "https://github.com/sebastianbergmann/version.git", 1100 | "reference": "b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43" 1101 | }, 1102 | "dist": { 1103 | "type": "zip", 1104 | "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43", 1105 | "reference": "b6e1f0cf6b9e1ec409a0d3e2f2a5fb0998e36b43", 1106 | "shasum": "" 1107 | }, 1108 | "type": "library", 1109 | "autoload": { 1110 | "classmap": [ 1111 | "src/" 1112 | ] 1113 | }, 1114 | "notification-url": "https://packagist.org/downloads/", 1115 | "license": [ 1116 | "BSD-3-Clause" 1117 | ], 1118 | "authors": [ 1119 | { 1120 | "name": "Sebastian Bergmann", 1121 | "email": "sebastian@phpunit.de", 1122 | "role": "lead" 1123 | } 1124 | ], 1125 | "description": "Library that helps with managing the version number of Git-hosted PHP projects", 1126 | "homepage": "https://github.com/sebastianbergmann/version", 1127 | "time": "2014-03-07 15:35:33" 1128 | }, 1129 | { 1130 | "name": "symfony/config", 1131 | "version": "dev-master", 1132 | "target-dir": "Symfony/Component/Config", 1133 | "source": { 1134 | "type": "git", 1135 | "url": "https://github.com/symfony/Config.git", 1136 | "reference": "b9f7877e02682cb081585c58baf3b9760865b98e" 1137 | }, 1138 | "dist": { 1139 | "type": "zip", 1140 | "url": "https://api.github.com/repos/symfony/Config/zipball/b9f7877e02682cb081585c58baf3b9760865b98e", 1141 | "reference": "b9f7877e02682cb081585c58baf3b9760865b98e", 1142 | "shasum": "" 1143 | }, 1144 | "require": { 1145 | "php": ">=5.3.3", 1146 | "symfony/filesystem": "~2.3" 1147 | }, 1148 | "type": "library", 1149 | "extra": { 1150 | "branch-alias": { 1151 | "dev-master": "2.6-dev" 1152 | } 1153 | }, 1154 | "autoload": { 1155 | "psr-0": { 1156 | "Symfony\\Component\\Config\\": "" 1157 | } 1158 | }, 1159 | "notification-url": "https://packagist.org/downloads/", 1160 | "license": [ 1161 | "MIT" 1162 | ], 1163 | "authors": [ 1164 | { 1165 | "name": "Symfony Community", 1166 | "homepage": "http://symfony.com/contributors" 1167 | }, 1168 | { 1169 | "name": "Fabien Potencier", 1170 | "email": "fabien@symfony.com" 1171 | } 1172 | ], 1173 | "description": "Symfony Config Component", 1174 | "homepage": "http://symfony.com", 1175 | "time": "2014-09-25 18:11:49" 1176 | }, 1177 | { 1178 | "name": "symfony/console", 1179 | "version": "dev-master", 1180 | "target-dir": "Symfony/Component/Console", 1181 | "source": { 1182 | "type": "git", 1183 | "url": "https://github.com/symfony/Console.git", 1184 | "reference": "771649efa94246e63a6ab2726ba908a358bdd403" 1185 | }, 1186 | "dist": { 1187 | "type": "zip", 1188 | "url": "https://api.github.com/repos/symfony/Console/zipball/771649efa94246e63a6ab2726ba908a358bdd403", 1189 | "reference": "771649efa94246e63a6ab2726ba908a358bdd403", 1190 | "shasum": "" 1191 | }, 1192 | "require": { 1193 | "php": ">=5.3.3" 1194 | }, 1195 | "require-dev": { 1196 | "psr/log": "~1.0", 1197 | "symfony/event-dispatcher": "~2.1", 1198 | "symfony/process": "~2.1" 1199 | }, 1200 | "suggest": { 1201 | "psr/log": "For using the console logger", 1202 | "symfony/event-dispatcher": "", 1203 | "symfony/process": "" 1204 | }, 1205 | "type": "library", 1206 | "extra": { 1207 | "branch-alias": { 1208 | "dev-master": "2.6-dev" 1209 | } 1210 | }, 1211 | "autoload": { 1212 | "psr-0": { 1213 | "Symfony\\Component\\Console\\": "" 1214 | } 1215 | }, 1216 | "notification-url": "https://packagist.org/downloads/", 1217 | "license": [ 1218 | "MIT" 1219 | ], 1220 | "authors": [ 1221 | { 1222 | "name": "Symfony Community", 1223 | "homepage": "http://symfony.com/contributors" 1224 | }, 1225 | { 1226 | "name": "Fabien Potencier", 1227 | "email": "fabien@symfony.com" 1228 | } 1229 | ], 1230 | "description": "Symfony Console Component", 1231 | "homepage": "http://symfony.com", 1232 | "time": "2014-10-05 13:59:22" 1233 | }, 1234 | { 1235 | "name": "symfony/event-dispatcher", 1236 | "version": "dev-master", 1237 | "target-dir": "Symfony/Component/EventDispatcher", 1238 | "source": { 1239 | "type": "git", 1240 | "url": "https://github.com/symfony/EventDispatcher.git", 1241 | "reference": "e133748fd9165e24f8e9498ef5862f8bd37004e5" 1242 | }, 1243 | "dist": { 1244 | "type": "zip", 1245 | "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/e133748fd9165e24f8e9498ef5862f8bd37004e5", 1246 | "reference": "e133748fd9165e24f8e9498ef5862f8bd37004e5", 1247 | "shasum": "" 1248 | }, 1249 | "require": { 1250 | "php": ">=5.3.3" 1251 | }, 1252 | "require-dev": { 1253 | "psr/log": "~1.0", 1254 | "symfony/config": "~2.0", 1255 | "symfony/dependency-injection": "~2.6", 1256 | "symfony/expression-language": "~2.6", 1257 | "symfony/stopwatch": "~2.2" 1258 | }, 1259 | "suggest": { 1260 | "symfony/dependency-injection": "", 1261 | "symfony/http-kernel": "" 1262 | }, 1263 | "type": "library", 1264 | "extra": { 1265 | "branch-alias": { 1266 | "dev-master": "2.6-dev" 1267 | } 1268 | }, 1269 | "autoload": { 1270 | "psr-0": { 1271 | "Symfony\\Component\\EventDispatcher\\": "" 1272 | } 1273 | }, 1274 | "notification-url": "https://packagist.org/downloads/", 1275 | "license": [ 1276 | "MIT" 1277 | ], 1278 | "authors": [ 1279 | { 1280 | "name": "Symfony Community", 1281 | "homepage": "http://symfony.com/contributors" 1282 | }, 1283 | { 1284 | "name": "Fabien Potencier", 1285 | "email": "fabien@symfony.com" 1286 | } 1287 | ], 1288 | "description": "Symfony EventDispatcher Component", 1289 | "homepage": "http://symfony.com", 1290 | "time": "2014-10-04 06:08:58" 1291 | }, 1292 | { 1293 | "name": "symfony/filesystem", 1294 | "version": "dev-master", 1295 | "target-dir": "Symfony/Component/Filesystem", 1296 | "source": { 1297 | "type": "git", 1298 | "url": "https://github.com/symfony/Filesystem.git", 1299 | "reference": "7d97789ea01c3c76ecaa59b954d162777033cbd4" 1300 | }, 1301 | "dist": { 1302 | "type": "zip", 1303 | "url": "https://api.github.com/repos/symfony/Filesystem/zipball/7d97789ea01c3c76ecaa59b954d162777033cbd4", 1304 | "reference": "7d97789ea01c3c76ecaa59b954d162777033cbd4", 1305 | "shasum": "" 1306 | }, 1307 | "require": { 1308 | "php": ">=5.3.3" 1309 | }, 1310 | "type": "library", 1311 | "extra": { 1312 | "branch-alias": { 1313 | "dev-master": "2.6-dev" 1314 | } 1315 | }, 1316 | "autoload": { 1317 | "psr-0": { 1318 | "Symfony\\Component\\Filesystem\\": "" 1319 | } 1320 | }, 1321 | "notification-url": "https://packagist.org/downloads/", 1322 | "license": [ 1323 | "MIT" 1324 | ], 1325 | "authors": [ 1326 | { 1327 | "name": "Symfony Community", 1328 | "homepage": "http://symfony.com/contributors" 1329 | }, 1330 | { 1331 | "name": "Fabien Potencier", 1332 | "email": "fabien@symfony.com" 1333 | } 1334 | ], 1335 | "description": "Symfony Filesystem Component", 1336 | "homepage": "http://symfony.com", 1337 | "time": "2014-09-22 15:54:44" 1338 | }, 1339 | { 1340 | "name": "symfony/stopwatch", 1341 | "version": "dev-master", 1342 | "target-dir": "Symfony/Component/Stopwatch", 1343 | "source": { 1344 | "type": "git", 1345 | "url": "https://github.com/symfony/Stopwatch.git", 1346 | "reference": "f7cca9c342ce395d2aa17383d0f9a409d81ca585" 1347 | }, 1348 | "dist": { 1349 | "type": "zip", 1350 | "url": "https://api.github.com/repos/symfony/Stopwatch/zipball/f7cca9c342ce395d2aa17383d0f9a409d81ca585", 1351 | "reference": "f7cca9c342ce395d2aa17383d0f9a409d81ca585", 1352 | "shasum": "" 1353 | }, 1354 | "require": { 1355 | "php": ">=5.3.3" 1356 | }, 1357 | "type": "library", 1358 | "extra": { 1359 | "branch-alias": { 1360 | "dev-master": "2.6-dev" 1361 | } 1362 | }, 1363 | "autoload": { 1364 | "psr-0": { 1365 | "Symfony\\Component\\Stopwatch\\": "" 1366 | } 1367 | }, 1368 | "notification-url": "https://packagist.org/downloads/", 1369 | "license": [ 1370 | "MIT" 1371 | ], 1372 | "authors": [ 1373 | { 1374 | "name": "Symfony Community", 1375 | "homepage": "http://symfony.com/contributors" 1376 | }, 1377 | { 1378 | "name": "Fabien Potencier", 1379 | "email": "fabien@symfony.com" 1380 | } 1381 | ], 1382 | "description": "Symfony Stopwatch Component", 1383 | "homepage": "http://symfony.com", 1384 | "time": "2014-09-22 11:59:59" 1385 | }, 1386 | { 1387 | "name": "symfony/yaml", 1388 | "version": "dev-master", 1389 | "target-dir": "Symfony/Component/Yaml", 1390 | "source": { 1391 | "type": "git", 1392 | "url": "https://github.com/symfony/Yaml.git", 1393 | "reference": "499f7d7aa96747ad97940089bd7a1fb24ad8182a" 1394 | }, 1395 | "dist": { 1396 | "type": "zip", 1397 | "url": "https://api.github.com/repos/symfony/Yaml/zipball/499f7d7aa96747ad97940089bd7a1fb24ad8182a", 1398 | "reference": "499f7d7aa96747ad97940089bd7a1fb24ad8182a", 1399 | "shasum": "" 1400 | }, 1401 | "require": { 1402 | "php": ">=5.3.3" 1403 | }, 1404 | "type": "library", 1405 | "extra": { 1406 | "branch-alias": { 1407 | "dev-master": "2.6-dev" 1408 | } 1409 | }, 1410 | "autoload": { 1411 | "psr-0": { 1412 | "Symfony\\Component\\Yaml\\": "" 1413 | } 1414 | }, 1415 | "notification-url": "https://packagist.org/downloads/", 1416 | "license": [ 1417 | "MIT" 1418 | ], 1419 | "authors": [ 1420 | { 1421 | "name": "Symfony Community", 1422 | "homepage": "http://symfony.com/contributors" 1423 | }, 1424 | { 1425 | "name": "Fabien Potencier", 1426 | "email": "fabien@symfony.com" 1427 | } 1428 | ], 1429 | "description": "Symfony Yaml Component", 1430 | "homepage": "http://symfony.com", 1431 | "time": "2014-10-05 13:53:50" 1432 | } 1433 | ], 1434 | "aliases": [], 1435 | "minimum-stability": "dev", 1436 | "stability-flags": { 1437 | "league/oauth2-server": 20, 1438 | "phpunit/phpunit": 20, 1439 | "satooshi/php-coveralls": 20 1440 | }, 1441 | "prefer-stable": false, 1442 | "platform": { 1443 | "php": ">=5.4" 1444 | }, 1445 | "platform-dev": [] 1446 | } 1447 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | ./tests/Pickles 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /sql/oauth2.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE `oauth_clients` ( 2 | `id` CHAR(40) NOT NULL, 3 | `secret` CHAR(40) NOT NULL, 4 | `name` VARCHAR(255) NOT NULL, 5 | `auto_approve` TINYINT(1) NOT NULL DEFAULT '0', 6 | PRIMARY KEY (`id`), 7 | UNIQUE KEY `u_oacl_clse_clid` (`secret`,`id`) 8 | ) ENGINE=INNODB DEFAULT CHARSET=utf8 COLLATE utf8_unicode_ci; 9 | 10 | CREATE TABLE `oauth_endpoints` ( 11 | `id` int(10) unsigned NOT NULL AUTO_INCREMENT, 12 | `client_id` char(40) NOT NULL, 13 | `redirect_uri` varchar(255) NOT NULL, 14 | PRIMARY KEY (`id`), 15 | KEY `i_oaclen_clid` (`client_id`), 16 | CONSTRAINT `f_oaclen_clid` 17 | FOREIGN KEY (`client_id`) 18 | REFERENCES `oauth_clients` (`id`) 19 | ON DELETE CASCADE ON UPDATE CASCADE 20 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_unicode_ci; 21 | 22 | CREATE TABLE `oauth_sessions` ( 23 | `id` int(10) unsigned NOT NULL AUTO_INCREMENT, 24 | `client_id` char(40) NOT NULL, 25 | `owner_type` enum('user','client') NOT NULL DEFAULT 'user', 26 | `owner_id` varchar(255) NOT NULL, 27 | PRIMARY KEY (`id`), 28 | KEY `i_uase_clid_owty_owid` (`client_id`,`owner_type`,`owner_id`), 29 | CONSTRAINT `f_oase_clid` 30 | FOREIGN KEY (`client_id`) 31 | REFERENCES `oauth_clients` (`id`) 32 | ON DELETE CASCADE ON UPDATE CASCADE 33 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_unicode_ci; 34 | 35 | CREATE TABLE `oauth_access_tokens` ( 36 | `id` int(10) unsigned NOT NULL AUTO_INCREMENT, 37 | `session_id` int(10) unsigned NOT NULL, 38 | `access_token` char(40) NOT NULL, 39 | `expires_at` int(10) unsigned NOT NULL, 40 | PRIMARY KEY (`id`), 41 | UNIQUE KEY `u_oaseacto_acto_seid` (`access_token`,`session_id`), 42 | KEY `f_oaseto_seid` (`session_id`), 43 | CONSTRAINT `f_oaseto_seid` 44 | FOREIGN KEY (`session_id`) 45 | REFERENCES `oauth_sessions` (`id`) 46 | ON DELETE CASCADE ON UPDATE NO ACTION 47 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_unicode_ci; 48 | 49 | CREATE TABLE `oauth_authorization_codes` ( 50 | `id` int(10) unsigned NOT NULL AUTO_INCREMENT, 51 | `session_id` int(10) unsigned NOT NULL, 52 | `authorization_code` char(40) NOT NULL, 53 | `expires_at` int(10) unsigned NOT NULL, 54 | PRIMARY KEY (`id`), 55 | KEY `session_id` (`session_id`), 56 | CONSTRAINT `oauth_authorization_codes_ibfk_1` 57 | FOREIGN KEY (`session_id`) 58 | REFERENCES `oauth_sessions` (`id`) 59 | ON DELETE CASCADE 60 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_unicode_ci; 61 | 62 | CREATE TABLE `oauth_redirect_uris` ( 63 | `session_id` int(10) unsigned NOT NULL, 64 | `redirect_uri` varchar(255) NOT NULL, 65 | PRIMARY KEY (`session_id`), 66 | CONSTRAINT `f_oasere_seid` 67 | FOREIGN KEY (`session_id`) 68 | REFERENCES `oauth_sessions` (`id`) 69 | ON DELETE CASCADE ON UPDATE NO ACTION 70 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_unicode_ci; 71 | 72 | CREATE TABLE `oauth_refresh_tokens` ( 73 | `access_token_id` int(10) unsigned NOT NULL, 74 | `refresh_token` char(40) NOT NULL, 75 | `expires_at` int(10) unsigned NOT NULL, 76 | `client_id` char(40) NOT NULL, 77 | PRIMARY KEY (`access_token_id`), 78 | KEY `client_id` (`client_id`), 79 | CONSTRAINT `oauth_refresh_tokens_ibfk_1` 80 | FOREIGN KEY (`client_id`) 81 | REFERENCES `oauth_clients` (`id`) 82 | ON DELETE CASCADE, 83 | CONSTRAINT `f_oasetore_setoid` 84 | FOREIGN KEY (`access_token_id`) 85 | REFERENCES `oauth_access_tokens` (`id`) 86 | ON DELETE CASCADE ON UPDATE NO ACTION 87 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_unicode_ci; 88 | 89 | CREATE TABLE `oauth_scopes` ( 90 | `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, 91 | `scope` varchar(255) NOT NULL, 92 | `name` varchar(255) NOT NULL, 93 | `description` varchar(255) DEFAULT NULL, 94 | PRIMARY KEY (`id`), 95 | UNIQUE KEY `u_oasc_sc` (`scope`) 96 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_unicode_ci; 97 | 98 | CREATE TABLE `oauth_access_token_scopes` ( 99 | `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, 100 | `access_token_id` int(10) unsigned DEFAULT NULL, 101 | `scope_id` smallint(5) unsigned NOT NULL, 102 | PRIMARY KEY (`id`), 103 | UNIQUE KEY `u_setosc_setoid_scid` (`access_token_id`,`scope_id`), 104 | KEY `f_oasetosc_scid` (`scope_id`), 105 | CONSTRAINT `f_oasetosc_scid` 106 | FOREIGN KEY (`scope_id`) 107 | REFERENCES `oauth_scopes` (`id`) 108 | ON DELETE CASCADE ON UPDATE NO ACTION, 109 | CONSTRAINT `f_oasetosc_setoid` 110 | FOREIGN KEY (`access_token_id`) 111 | REFERENCES `oauth_access_tokens` (`id`) 112 | ON DELETE CASCADE ON UPDATE NO ACTION 113 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_unicode_ci; 114 | 115 | CREATE TABLE `oauth_authorization_code_scopes` ( 116 | `authorization_code_id` int(10) unsigned NOT NULL, 117 | `scope_id` smallint(5) unsigned NOT NULL, 118 | KEY `authorization_code_id` (`authorization_code_id`), 119 | KEY `scope_id` (`scope_id`), 120 | CONSTRAINT `oauth_authorization_code_scopes_ibfk_2` 121 | FOREIGN KEY (`scope_id`) 122 | REFERENCES `oauth_scopes` (`id`) 123 | ON DELETE CASCADE, 124 | CONSTRAINT `oauth_authorization_code_scopes_ibfk_1` 125 | FOREIGN KEY (`authorization_code_id`) 126 | REFERENCES `oauth_authorization_codes` (`id`) 127 | ON DELETE CASCADE 128 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_unicode_ci; 129 | 130 | -------------------------------------------------------------------------------- /src/Config.php: -------------------------------------------------------------------------------- 1 | )'); 75 | } 76 | 77 | // Loops through the environments and looks for a match 78 | foreach ($config['environments'] as $name => $hosts) 79 | { 80 | if (!is_array($hosts)) 81 | { 82 | $hosts = [$hosts]; 83 | } 84 | 85 | // Tries to determine the environment name 86 | foreach ($hosts as $host) 87 | { 88 | if ($cli) 89 | { 90 | // Checks the first argument on the command line 91 | if ($_SERVER['argv'][1] == $name) 92 | { 93 | $environment = $name; 94 | break; 95 | } 96 | } 97 | else 98 | { 99 | // Exact match 100 | if ((preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $host) 101 | && $_SERVER['SERVER_ADDR'] == $host) 102 | || (isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] == $host)) 103 | { 104 | $environment = $name; 105 | break; 106 | } 107 | // Fuzzy match 108 | elseif (substr($host, 0, 1) == '/' 109 | && (preg_match($host, $_SERVER['SERVER_NAME'], $matches) > 0 110 | || preg_match($host, $_SERVER['HTTP_HOST'], $matches) > 0)) 111 | { 112 | $environments[$name] = $matches[0]; 113 | $environment = $name; 114 | $config['environments'][$name] = $matches[0]; 115 | break; 116 | } 117 | } 118 | } 119 | } 120 | 121 | if (!$environment) 122 | { 123 | throw new \Exception('Unable to determine the environment.'); 124 | } 125 | 126 | // Flattens the array based on the environment 127 | $config = $this->flatten($environment, $config); 128 | 129 | // Disables display errors in production 130 | if ($environment == 'production') 131 | { 132 | ini_set('display_errors', false); 133 | } 134 | 135 | // Assigns the environment 136 | $config['environment'] = $environment; 137 | 138 | // Defaults expected Pickles variables to false 139 | foreach (['auth', 'cache', 'profiler'] as $variable) 140 | { 141 | if (!isset($config[$variable])) 142 | { 143 | $config[$variable] = false; 144 | } 145 | } 146 | 147 | // Assigns the config variables to the object 148 | foreach ($config as $variable => $value) 149 | { 150 | $this[$variable] = $value; 151 | } 152 | } 153 | catch (\Exception $e) 154 | { 155 | throw $e; 156 | } 157 | } 158 | 159 | /** 160 | * Flatten 161 | * 162 | * Flattens the configuration array around the specified environment. 163 | * 164 | * @param string $environment selected environment 165 | * @param array $array configuration error to flatten 166 | * @return array flattened configuration array 167 | */ 168 | private function flatten($environment, $array) 169 | { 170 | if (is_array($array)) 171 | { 172 | foreach ($array as $key => $value) 173 | { 174 | if (is_array($value)) 175 | { 176 | if (isset($value[$environment])) 177 | { 178 | $value = $value[$environment]; 179 | } 180 | else 181 | { 182 | $value = $this->flatten($environment, $value); 183 | } 184 | } 185 | 186 | $array[$key] = $value; 187 | } 188 | } 189 | 190 | return $array; 191 | } 192 | 193 | /** 194 | * Get instance of the object 195 | * 196 | * Let's the parent class do all the work 197 | * 198 | * @static 199 | * @param string $file name of config to load 200 | * @return object self::$_instance instance of the Config class 201 | */ 202 | public static function getInstance($file = false) 203 | { 204 | if (!self::$_instance || $file) 205 | { 206 | self::$_instance = new Config($file); 207 | } 208 | 209 | return self::$_instance; 210 | } 211 | } 212 | 213 | -------------------------------------------------------------------------------- /src/Mongo.php: -------------------------------------------------------------------------------- 1 | selectDB($mongo['database']); 41 | 42 | // Caches the instance for possible reuse later 43 | self::$instances['Mongo'] = $instance; 44 | } 45 | 46 | // Returns the instance 47 | return self::$instances['Mongo']; 48 | } 49 | } 50 | 51 | -------------------------------------------------------------------------------- /src/OAuth2/AccessTokenStorage.php: -------------------------------------------------------------------------------- 1 | = ?;'; 18 | 19 | $results = $this->db->fetch($sql, [$token, time()]); 20 | 21 | if (count($results) === 1) 22 | { 23 | return (new AccessTokenEntity($this->server)) 24 | ->setId($results[0]['access_token']) 25 | ->setExpireTime($results[0]['expires_at']); 26 | } 27 | 28 | return null; 29 | } 30 | 31 | public function getScopes(AbstractTokenEntity $token) 32 | { 33 | $sql = 'SELECT oauth_scopes.id, oauth_scopes.description' 34 | . ' FROM oauth_access_token_scopes' 35 | . ' INNER JOIN oauth_scopes' 36 | . ' ON oauth_access_token_scopes.scope_id = oauth_scopes.id' 37 | . ' WHERE oauth_access_token_scopes.access_token_id = ?;'; 38 | 39 | $results = $this->db->fetch($sql, [$token->getId()]); 40 | $response = []; 41 | 42 | if (count($results) > 0) 43 | { 44 | foreach ($results as $row) 45 | { 46 | $response[] = (new ScopeEntity($this->server))->hydrate([ 47 | 'id' => $row['id'], 48 | 'description' => $row['description'] 49 | ]); 50 | } 51 | } 52 | 53 | return $response; 54 | } 55 | 56 | public function create($token, $expiration, $session_id) 57 | { 58 | $sql = 'INSERT INTO oauth_access_tokens' 59 | . ' (access_token, session_id, expires_at)' 60 | . ' VALUES' 61 | . ' (?, ?, ?);'; 62 | 63 | $this->db->execute($sql, [$token, $session_id, $expiration]); 64 | } 65 | 66 | public function associateScope(AbstractTokenEntity $token, ScopeEntity $scope) 67 | { 68 | $sql = 'INSERT INTO oauth_access_token_scopes' 69 | . ' (access_token, scope)' 70 | . ' VALUES' 71 | . ' (?, ?);'; 72 | 73 | $this->db->execute($sql, [$token->getId(), $scope->getId()]); 74 | } 75 | 76 | public function delete(AbstractTokenEntity $token) 77 | { 78 | $sql = 'DELETE FROM oauth_access_token_scopes' 79 | . ' WHERE access_token = ?;'; 80 | 81 | $this->db->execute($sql, [$token->getId()]); 82 | } 83 | } 84 | 85 | -------------------------------------------------------------------------------- /src/OAuth2/ClientStorage.php: -------------------------------------------------------------------------------- 1 | db->fetch($sql, $parameters); 40 | 41 | if (count($results) === 1) 42 | { 43 | $client = new ClientEntity($this->server); 44 | 45 | $client->hydrate([ 46 | 'id' => $results[0]['id'], 47 | 'name' => $results[0]['name'] 48 | ]); 49 | 50 | return $client; 51 | } 52 | 53 | return null; 54 | } 55 | 56 | public function getBySession(SessionEntity $session) 57 | { 58 | $sql = 'SELECT oauth_clients.id, oauth_clients.name' 59 | . ' FROM oauth_clients' 60 | . ' INNER JOIN oauth_sessions' 61 | . ' ON oauth_clients.id = oauth_sessions.client_id' 62 | . ' WHERE oauth_sessions.id = ?'; 63 | 64 | $results = $this->db->fetch($sql, [$session->getId()]); 65 | 66 | if (count($results) === 1) 67 | { 68 | $client = new ClientEntity($this->server); 69 | 70 | $client->hydrate([ 71 | 'id' => $results[0]['id'], 72 | 'name' => $results[0]['name'] 73 | ]); 74 | 75 | return $client; 76 | } 77 | 78 | return null; 79 | } 80 | } 81 | 82 | -------------------------------------------------------------------------------- /src/OAuth2/RefreshTokenStorage.php: -------------------------------------------------------------------------------- 1 | = ?;'; 16 | 17 | $results = $this->db->fetch($sql, [$token, time()]); 18 | 19 | if (count($results) === 1) 20 | { 21 | return (new RefreshTokenEntity($this->server)) 22 | ->setId($results[0]['refresh_token']) 23 | ->setExpireTime($results[0]['expires_at']) 24 | ->setAccessTokenId($results[0]['access_token_id']); 25 | } 26 | 27 | return null; 28 | } 29 | 30 | public function create($token, $expiration, $access_token) 31 | { 32 | $sql = 'SELECT id FROM oauth_access_tokens WHERE access_token = ?;'; 33 | $results = $this->db->fetch($sql, [$access_token]); 34 | $token_id = $results[0]['id']; 35 | 36 | $sql = 'INSERT INTO oauth_refresh_tokens' 37 | . ' (refresh_token, access_token_id, expires_at, client_id)' 38 | . ' VALUES' 39 | . ' (?, ?, ?, ?);'; 40 | 41 | $this->db->execute($sql, [ 42 | $token, 43 | $token_id, 44 | $expiration, 45 | $this->server->getRequest()->request->get('client_id', null), 46 | ]); 47 | } 48 | 49 | public function delete(RefreshTokenEntity $token) 50 | { 51 | $sql = 'DELETE FROM oauth_refresh_tokens WHERE refresh_token = ?;'; 52 | 53 | $this->db->execute($sql, [$token->getId()]); 54 | } 55 | } 56 | 57 | -------------------------------------------------------------------------------- /src/OAuth2/Resource.php: -------------------------------------------------------------------------------- 1 | config['oauth'][$_SERVER['__version']])) 17 | { 18 | throw new \Exception('Forbidden.', 403); 19 | } 20 | elseif (!isset($_REQUEST['grant_type'])) 21 | { 22 | throw new \Exception('Bad Request.', 400); 23 | } 24 | 25 | $config = $this->config['oauth'][$_SERVER['__version']]; 26 | 27 | switch (substr($_REQUEST['request'], strlen($_SERVER['__version']) + 2)) 28 | { 29 | case 'oauth/access_token': 30 | try 31 | { 32 | $server = new AuthorizationServer; 33 | 34 | $server->setSessionStorage(new SessionStorage); 35 | $server->setAccessTokenStorage(new AccessTokenStorage); 36 | $server->setClientStorage(new ClientStorage); 37 | $server->setScopeStorage(new ScopeStorage); 38 | $server->setRefreshTokenStorage(new RefreshTokenStorage); 39 | 40 | $grant_type = $_REQUEST['grant_type']; 41 | $grants = ['password']; 42 | 43 | if (isset($config['grants'])) 44 | { 45 | $grants = array_unique(array_merge($grants, $config['grants'])); 46 | } 47 | 48 | if (!in_array($grant_type, $grants)) 49 | { 50 | throw new \Exception('Unsupported grant type.', 403); 51 | } 52 | 53 | // Defaults TTLs to 1 day and 1 week respectively 54 | $token_ttl = 3600; 55 | $refresh_ttl = 604800; 56 | 57 | if (isset($config['ttl']['access_token'])) 58 | { 59 | $token_ttl = $config['ttl']['access_token']; 60 | } 61 | 62 | switch ($grant_type) 63 | { 64 | case 'authorization_code': 65 | throw new \Exception('Not Implemented', 501); 66 | break; 67 | 68 | case 'client_credentials': 69 | throw new \Exception('Not Implemented', 501); 70 | break; 71 | 72 | case 'implicit': 73 | throw new \Exception('Not Implemented', 501); 74 | break; 75 | 76 | case 'password': 77 | $grant = new PasswordGrant; 78 | $grant->setAccessTokenTTL($token_ttl); 79 | 80 | $grant->setVerifyCredentialsCallback(function ($username, $password) 81 | { 82 | $user = new User([ 83 | 'conditions' => [ 84 | 'email' => $username, 85 | ], 86 | ]); 87 | 88 | return $user->count() 89 | && password_verify($password, $user->record['password']); 90 | }); 91 | 92 | break; 93 | 94 | case 'refresh_token': 95 | throw new \Exception('Not Implemented', 501); 96 | 97 | // @todo Need to work through this, appears lib is busted 98 | $grant = new RefreshTokenGrant; 99 | //$grant->setAccessTokenTTL($refresh_ttl); 100 | $server->addGrantType($grant); 101 | break; 102 | } 103 | 104 | $server->addGrantType($grant); 105 | 106 | // Adds the refresh token grant if enabled 107 | if ($grant_type != 'refresh_token' 108 | && in_array('refresh_token', $grants)) 109 | { 110 | if (isset($config['ttl']['refresh_token'])) 111 | { 112 | $refresh_ttl = $config['ttl']['refresh_token']; 113 | } 114 | 115 | $grant = new RefreshTokenGrant; 116 | $grant->setAccessTokenTTL($refresh_ttl); 117 | $server->addGrantType($grant); 118 | } 119 | 120 | $response = $server->issueAccessToken(); 121 | 122 | return $response; 123 | } 124 | catch (OAuthException $e) 125 | { 126 | throw new \Exception($e->getMessage(), $e->httpStatusCode); 127 | } 128 | catch (\Exception $e) 129 | { 130 | throw new \Exception($e->getMessage(), $e->getCode()); 131 | } 132 | 133 | break; 134 | 135 | default: 136 | throw new \Exception('Not Found.', 404); 137 | break; 138 | } 139 | } 140 | } 141 | 142 | -------------------------------------------------------------------------------- /src/OAuth2/ScopeStorage.php: -------------------------------------------------------------------------------- 1 | db->fetch($sql, [$scope]); 14 | 15 | if (count($results) === 0) 16 | { 17 | return null; 18 | } 19 | 20 | return (new ScopeEntity($this->server))->hydrate([ 21 | 'id' => $result[0]['id'], 22 | 'description' => $result[0]['description'], 23 | ]); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /src/OAuth2/SessionStorage.php: -------------------------------------------------------------------------------- 1 | db->fetch($sql, [$access_token->getId()]); 25 | 26 | if (count($results) === 1) 27 | { 28 | $session = new SessionEntity($this->server); 29 | $session->setId($result[0]['id']); 30 | $session->setOwner($result[0]['owner_type'], $result[0]['owner_id']); 31 | 32 | return $session; 33 | } 34 | 35 | return null; 36 | } 37 | 38 | public function getByAuthCode(AuthCodeEntity $auth_code) 39 | { 40 | $sql = 'SELECT oauth_sessions.id, oauth_sessions.owner_type,' 41 | . ' oauth_sessions.owner_id, oauth_sessions.client_id,' 42 | . ' oauth_sessions.client_redirect_uri' 43 | . ' FROM oauth_sessions' 44 | . ' INNER JOIN oauth_authorization_codes' 45 | . ' ON oauth_authorization_codes.session_id = oauth_sessions.id' 46 | . ' WHERE oauth_authorization_codes.authorization_code = ?;'; 47 | 48 | $results = $this->db->fetch($sql, [$auth_code->getId()]); 49 | 50 | if (count($results) === 1) 51 | { 52 | $session = new SessionEntity($this->server); 53 | $session->setId($result[0]['id']); 54 | $session->setOwner($result[0]['owner_type'], $result[0]['owner_id']); 55 | 56 | return $session; 57 | } 58 | 59 | return null; 60 | } 61 | 62 | public function getScopes(SessionEntity $session) 63 | { 64 | $sql = 'SELECT oauth_sessions.*' 65 | . ' FROM oauth_sessions' 66 | . ' INNER JOIN oauth_access_token_scopes' 67 | . ' ON oauth_sessions.id = oauth_access_token_scopes.access_token_id' 68 | . ' INNER JOIN oauth_scopes' 69 | . ' ON oauth_scopes.id = oauth_access_token_scopes.scope_id' 70 | . ' WHERE oauth_sessions.id = ?;'; 71 | 72 | $results = $this->db->fetch($sql, [$session->getId()]); 73 | $scopes = []; 74 | 75 | foreach ($results as $scope) 76 | { 77 | $scopes[] = (new ScopeEntity($this->server))->hydrate([ 78 | 'id' => $scope['id'], 79 | 'description' => $scope['description'], 80 | ]); 81 | } 82 | 83 | return $scopes; 84 | } 85 | 86 | public function create($owner_type, $owner_id, $client_id, $client_redirect_uri = null) 87 | { 88 | $sql = 'INSERT INTO oauth_sessions' 89 | . ' (owner_type, owner_id, client_id)' 90 | . ' VALUES' 91 | . ' (?, ?, ?);'; 92 | 93 | return $this->db->execute($sql, [$owner_type, $owner_id, $client_id]); 94 | } 95 | 96 | public function associateScope(SessionEntity $session, ScopeEntity $scope) 97 | { 98 | $sql = 'INSERT INTO oauth_access_token_scopes' 99 | . ' (access_token_id, scope_id)' 100 | . ' VALUES' 101 | . ' (?, ?);'; 102 | 103 | $this->db->execute($sql, [$session->getId(), $scope->getId()]); 104 | } 105 | } 106 | 107 | -------------------------------------------------------------------------------- /src/OAuth2/StorageAdapter.php: -------------------------------------------------------------------------------- 1 | config = Config::getInstance(); 17 | $this->db = Database::getInstance(); 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /src/Object.php: -------------------------------------------------------------------------------- 1 | config = Config::getInstance(); 64 | $this->mongo = Mongo::getInstance(); 65 | //$this->redis = Redis::getInstance(); 66 | 67 | // Optionally logs the constructor to the profiler 68 | if ($this->config['profiler']) 69 | { 70 | Profiler::log($this, '__construct'); 71 | } 72 | } 73 | 74 | /** 75 | * Get Instance 76 | * 77 | * Gets an instance of the passed class. Allows for easy sharing of certain 78 | * classes within the system to avoid the extra overhead of creating new 79 | * objects each time. Also avoids the hassle of passing around variables. 80 | * 81 | * @static 82 | * @param string $class name of the class 83 | * @return object instance of the class 84 | */ 85 | public static function getInstance($class = false) 86 | { 87 | if ($class) 88 | { 89 | $class = 'Pickles\\' . $class; 90 | 91 | if (!isset(self::$instances[$class])) 92 | { 93 | self::$instances[$class] = new $class(); 94 | } 95 | 96 | return self::$instances[$class]; 97 | } 98 | 99 | return false; 100 | } 101 | 102 | /** 103 | * Destructor 104 | */ 105 | public function __destruct() 106 | { 107 | // Optionally logs the destructor to the profiler 108 | if ($this->config['profiler']) 109 | { 110 | Profiler::log($this, '__destruct'); 111 | } 112 | } 113 | } 114 | 115 | -------------------------------------------------------------------------------- /src/Profiler.php: -------------------------------------------------------------------------------- 1 | Profiler::log('some action you want to track'); 26 | * @usage Profiler::log($object, 'methodName'); 27 | */ 28 | class Profiler 29 | { 30 | /** 31 | * Logs 32 | * 33 | * Array of logged events 34 | * 35 | * @static 36 | * @access private 37 | * @var array 38 | */ 39 | private static $logs = []; 40 | 41 | /** 42 | * Timers 43 | * 44 | * Array of active timers 45 | * 46 | * @static 47 | * @access private 48 | * @var array 49 | */ 50 | private static $timers = []; 51 | 52 | /** 53 | * Log 54 | * 55 | * Logs the event to be displayed later on. Due to the nature of how much 56 | * of a pain it is to determine which class method called this method I 57 | * opted to make the method a passable argument for ease of use. Perhaps 58 | * I'll revisit in the future. Handles all elapsed time calculations and 59 | * memory usage. 60 | * 61 | * @static 62 | * @param mixed $data data to log 63 | * @param string $method name of the class method being logged 64 | */ 65 | public static function log($data, $method = false, $type = false) 66 | { 67 | $time = microtime(true); 68 | $data_type = ($data == 'timer' ? $data : gettype($data)); 69 | 70 | // Tidys the data by type 71 | switch ($data_type) 72 | { 73 | case 'object': 74 | $details['class'] = get_class($data); 75 | 76 | if ($method != '') 77 | { 78 | $details['method'] = $method . '()'; 79 | } 80 | 81 | $data_type = $data_type; 82 | break; 83 | 84 | case 'timer': 85 | $details = $method; 86 | $data_type = $data_type; 87 | break; 88 | 89 | default: 90 | if ($type != false) 91 | { 92 | $data_type = $type; 93 | } 94 | 95 | $details = $data; 96 | break; 97 | } 98 | 99 | self::$logs[] = [ 100 | 'type' => $data_type, 101 | 'timestamp' => $time, 102 | 'elapsed_time' => $time - $_SERVER['REQUEST_TIME_FLOAT'], 103 | 'memory_usage' => memory_get_usage(), 104 | 'details' => $details, 105 | ]; 106 | } 107 | 108 | /** 109 | * Query 110 | * 111 | * Serves as a wrapper to get query data to the log function 112 | * 113 | * @static 114 | * @param string $query the query being executed 115 | * @param array $input_parameters optional prepared statement data 116 | * @param array $results optional results of the query 117 | * @param float $duration the speed of the query 118 | * @param array $explain EXPLAIN data for the query 119 | */ 120 | public static function query($query, $input_parameters = false, $results = false, $duration = false, $explain = false) 121 | { 122 | $log = [ 123 | 'query' => $query, 124 | 'parameters' => $input_parameters, 125 | 'results' => $results, 126 | 'execution_time' => $duration, 127 | ]; 128 | 129 | if ($explain) 130 | { 131 | $log['explain'] = $explain; 132 | } 133 | 134 | self::log($log, false, 'database'); 135 | } 136 | 137 | /** 138 | * Timer 139 | * 140 | * Logs the start and end of a timer. 141 | * 142 | * @param string $timer name of the timer 143 | * @return boolean whether or not timer profiling is enabled 144 | */ 145 | public static function timer($timer) 146 | { 147 | // Starts the timer 148 | if (!isset(self::$timers[$timer])) 149 | { 150 | self::$timers[$timer] = microtime(true); 151 | 152 | self::Log('timer', [ 153 | 'action' => 'start', 154 | 'name' => $timer 155 | ]); 156 | } 157 | // Ends the timer 158 | else 159 | { 160 | self::Log('timer', [ 161 | 'action' => 'stop', 162 | 'name' => $timer, 163 | 'elapsed_time' => (microtime(true) - self::$timers[$timer]) 164 | ]); 165 | 166 | unset(self::$timers[$timer]); 167 | } 168 | } 169 | 170 | /** 171 | * Report 172 | * 173 | * Generates the Profiler report that is displayed by the Controller. 174 | * Contains all the HTML needed to display the data properly inline on the 175 | * page. Will generally be displayed after the closing HTML tag. 176 | */ 177 | public static function report() 178 | { 179 | $report = [ 180 | 'request_time' => $_SERVER['REQUEST_TIME_FLOAT'], 181 | 'execution_time' => self::$logs[count(self::$logs) - 1]['timestamp'] 182 | - $_SERVER['REQUEST_TIME_FLOAT'], 183 | 'peak_memory_usage' => memory_get_peak_usage(), 184 | 'max_execution_time' => ini_get('max_execution_time'), 185 | 'memory_limit' => ini_get('memory_limit'), 186 | 'included_files' => count(get_included_files()), 187 | 'logs' => self::$logs, 188 | ]; 189 | 190 | self::$logs = []; 191 | self::$timers = []; 192 | 193 | return $report; 194 | } 195 | } 196 | 197 | -------------------------------------------------------------------------------- /src/Resource.php: -------------------------------------------------------------------------------- 1 | uids = $uids; 79 | $method = $_SERVER['REQUEST_METHOD']; 80 | 81 | try 82 | { 83 | // Checks if auth flag is explicity true or true for the method 84 | if ($this->auth === true 85 | || (isset($this->auth[$method]) && $this->auth[$method])) 86 | { 87 | if (isset($this->config['oauth'][$_SERVER['__version']])) 88 | { 89 | $server = new ResourceServer( 90 | new SessionStorage, 91 | new AccessTokenStorage, 92 | new ClientStorage, 93 | new ScopeStorage 94 | ); 95 | 96 | $server->isValidRequest(); 97 | } 98 | else 99 | { 100 | throw new \Exception('Authentication is not configured properly.', 401); 101 | } 102 | } 103 | 104 | // Hacks together some new globals 105 | if (in_array($method, ['PUT', 'DELETE'])) 106 | { 107 | $GLOBALS['_' . $method] = []; 108 | 109 | // @todo Populate it 110 | } 111 | 112 | $filter = isset($this->filter[$method]); 113 | $validate = isset($this->validate[$method]); 114 | 115 | if ($filter || $validate) 116 | { 117 | $global =& $GLOBALS['_' . $method]; 118 | 119 | // Checks that the required parameters are present 120 | // @todo Add in support for uid:* variables 121 | if ($validate) 122 | { 123 | $variables = []; 124 | 125 | foreach ($this->validate[$method] as $variable => $rules) 126 | { 127 | if (!is_array($rules)) 128 | { 129 | $variable = $rules; 130 | } 131 | 132 | $variables[] = $variable; 133 | } 134 | 135 | $missing_variables = array_diff($variables, array_keys($global)); 136 | 137 | if ($missing_variables !== array()) 138 | { 139 | foreach ($missing_variables as $variable) 140 | { 141 | $this->errors[$variable][] = 'The ' . $variable . ' parameter is required.'; 142 | } 143 | } 144 | } 145 | 146 | foreach ($global as $variable => $value) 147 | { 148 | // Applies any filters 149 | if ($filter && isset($this->filter[$method][$variable])) 150 | { 151 | $function = $this->filter[$method][$variable]; 152 | 153 | if ($function == 'password_hash') 154 | { 155 | $global[$variable] = password_hash($value, PASSWORD_DEFAULT); 156 | } 157 | else 158 | { 159 | $global[$variable] = $function($value); 160 | } 161 | } 162 | 163 | if ($validate && isset($this->validate[$method][$variable])) 164 | { 165 | $rules = $this->validate[$method][$variable]; 166 | 167 | if (is_array($rules)) 168 | { 169 | if (isset($global[$variable]) && !String::isEmpty($global[$variable])) 170 | { 171 | if (is_array($rules)) 172 | { 173 | foreach ($rules as $rule => $message) 174 | { 175 | $rule = explode(':', $rule); 176 | 177 | for ($i = 1; $i <= 2; $i++) 178 | { 179 | if (!isset($rule[$i])) 180 | { 181 | $rule[$i] = false; 182 | } 183 | } 184 | 185 | switch ($rule[0]) 186 | { 187 | // {{{ Checks using filter_var() 188 | 189 | case 'filter': 190 | switch ($rule[1]) 191 | { 192 | case 'boolean': 193 | case 'email': 194 | case 'float': 195 | case 'int': 196 | case 'ip': 197 | case 'url': 198 | $filter = constant('FILTER_VALIDATE_' . strtoupper($rule[1])); 199 | 200 | if (!filter_var($value, $filter)) 201 | { 202 | $this->errors[$variable][] = $message; 203 | } 204 | break; 205 | 206 | default: 207 | $this->errors[$variable] = 'Invalid filter, expecting boolean, email, float, int, ip or url.'; 208 | break; 209 | } 210 | 211 | break; 212 | 213 | // }}} 214 | // {{{ Checks using strlen() 215 | 216 | case 'length': 217 | $length = strlen($value); 218 | 219 | switch ($rule[1]) 220 | { 221 | case '<': 222 | $valid = $length < $rule[2]; 223 | break; 224 | 225 | case '<=': 226 | $valid = $length <= $rule[2]; 227 | break; 228 | 229 | case '==': 230 | $valid = $length == $rule[2]; 231 | break; 232 | 233 | case '!=': 234 | $valid = $length != $rule[2]; 235 | break; 236 | 237 | case '>=': 238 | $valid = $length >= $rule[2]; 239 | break; 240 | 241 | case '>': 242 | $valid = $length > $rule[2]; 243 | break; 244 | 245 | default: 246 | $valid = false; 247 | $message = 'Invalid operator, expecting <, <=, ==, !=, >= or >.'; 248 | break; 249 | } 250 | 251 | if (!$valid) 252 | { 253 | $this->errors[$variable][] = $message; 254 | } 255 | 256 | break; 257 | 258 | // }}} 259 | // {{{ Checks using preg_match() 260 | 261 | case 'regex': 262 | if (preg_match($rule[1], $value)) 263 | { 264 | $this->errors[$variable][] = $message; 265 | } 266 | break; 267 | 268 | // }}} 269 | // @todo case 'alpha': 270 | // @todo case 'alphanumeric': 271 | // @todo case 'date': 272 | // @todo case 'range': 273 | } 274 | } 275 | } 276 | } 277 | } 278 | } 279 | } 280 | 281 | // if PUT or DELETE, need to update the super globals directly as 282 | // they do not stay in sync. Probably need to make them global in 283 | // this class method 284 | // 285 | // $_PUT = $GLOBALS['_PUT']; 286 | } 287 | 288 | if ($this->errors) 289 | { 290 | throw new \Exception('Missing or invalid parameters.', 400); 291 | } 292 | 293 | parent::__construct(); 294 | 295 | // Checks if the request method has been implemented 296 | if (get_class($this) != 'Pickles\\Resource') 297 | { 298 | if (!method_exists($this, $method)) 299 | { 300 | throw new \Exception('Method not allowed.', 405); 301 | } 302 | else 303 | { 304 | // Starts a timer before the resource is executed 305 | if ($this->config['profiler']) 306 | { 307 | $timer = get_class($this) . '->' . $method . '()'; 308 | Profiler::timer($timer); 309 | } 310 | 311 | $this->response = $this->$method(); 312 | 313 | // Stops the resource timer 314 | if ($this->config['profiler']) 315 | { 316 | Profiler::timer($timer); 317 | } 318 | } 319 | } 320 | } 321 | catch (\Exception $e) 322 | { 323 | $code = $e->getCode(); 324 | 325 | // Anything below 200 is probably a PHP error 326 | if ($code < 200) 327 | { 328 | $code = 500; 329 | } 330 | 331 | $this->status = $code; 332 | $this->message = $e->getMessage(); 333 | } 334 | } 335 | 336 | public function respond() 337 | { 338 | http_response_code($this->status); 339 | header('Content-Type: application/json'); 340 | header('X-Powered-By: Pickles (http://picklesphp.com)'); 341 | 342 | $meta = [ 343 | 'status' => $this->status, 344 | 'message' => $this->message, 345 | ]; 346 | 347 | // Forces errors to be an array of arrays 348 | if ($this->errors) 349 | { 350 | foreach ($this->errors as $key => $error) 351 | { 352 | if (!is_array($error)) 353 | { 354 | $this->errors[$key] = [$error]; 355 | } 356 | } 357 | } 358 | 359 | foreach (['echo', 'limit', 'offset', 'errors'] as $variable) 360 | { 361 | if ($this->$variable) 362 | { 363 | $meta[$variable] = $this->$variable; 364 | } 365 | } 366 | 367 | $response = ['meta' => $meta]; 368 | 369 | foreach (['response', 'profiler'] as $variable) 370 | { 371 | if ($this->$variable) 372 | { 373 | $response[$variable] = $this->$variable; 374 | } 375 | } 376 | 377 | if ($this->config['profiler']) 378 | { 379 | $response['profiler'] = Profiler::report(); 380 | } 381 | 382 | $pretty = isset($_REQUEST['pretty']) ? JSON_PRETTY_PRINT : false; 383 | 384 | echo json_encode($response, $pretty); 385 | } 386 | } 387 | 388 | -------------------------------------------------------------------------------- /src/Router.php: -------------------------------------------------------------------------------- 1 | new Pickles\Router; 26 | */ 27 | class Router extends Object 28 | { 29 | /** 30 | * Constructor 31 | * 32 | * To save a few keystrokes, the Controller is executed as part of the 33 | * constructor instead of via a method. You either want the Controller or 34 | * you don't. 35 | */ 36 | public function __construct() 37 | { 38 | parent::__construct(); 39 | 40 | try 41 | { 42 | // Secure by default 43 | if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == false) 44 | { 45 | throw new \Exception('HTTPS is required.', 400); 46 | } 47 | 48 | // Grabs the requested page 49 | $request = $_REQUEST['request']; 50 | $components = explode('/', $request); 51 | $nouns = []; 52 | $uids = []; 53 | $version = array_shift($components); 54 | $_SERVER['__version'] = substr($version, 1); 55 | 56 | // Checks if we're trying to rock some OAuth 57 | if ($components[0] == 'oauth') 58 | { 59 | $class = 'Pickles\OAuth2\Resource'; 60 | } 61 | else 62 | { 63 | // Loops through the components to determine nouns and IDs 64 | foreach ($components as $index => $component) 65 | { 66 | if ($index % 2) 67 | { 68 | $uids[end($nouns)] = $component; 69 | } 70 | else 71 | { 72 | $nouns[] = $component; 73 | } 74 | } 75 | 76 | // Creates our class name 77 | array_unshift($nouns, '', 'Pickles', 'App', 'Resources', $version); 78 | $class = implode('\\', $nouns); 79 | } 80 | 81 | // Checks that the file is present and contains our class 82 | if (!class_exists($class)) 83 | { 84 | throw new \Exception('Not Found.', 404); 85 | } 86 | 87 | // Instantiates our resource with the UIDs 88 | $resource = new $class($uids); 89 | } 90 | catch (\Exception $e) 91 | { 92 | // Creates a resource object if we don't have one 93 | if (!isset($resource)) 94 | { 95 | $resource = new Resource; 96 | } 97 | 98 | $code = $e->getCode(); 99 | 100 | // Anything below 200 is probably a PHP error 101 | if ($code < 200) 102 | { 103 | $code = 500; 104 | } 105 | 106 | $resource->status = $code; 107 | $resource->message = $e->getMessage(); 108 | } 109 | 110 | $resource->respond(); 111 | } 112 | } 113 | 114 | -------------------------------------------------------------------------------- /src/String.php: -------------------------------------------------------------------------------- 1 | 0) 175 | { 176 | shuffle($characters); 177 | 178 | for ($i = 0; $i < $length; $i++) 179 | { 180 | $string .= $characters[array_rand($characters)]; 181 | } 182 | } 183 | 184 | return $string; 185 | } 186 | 187 | // }}} 188 | // {{{ Truncate 189 | 190 | /** 191 | * Truncate 192 | * 193 | * Truncates a string to a specified length and (optionally) adds a 194 | * span to provide a rollover to see the expanded text. 195 | * 196 | * @static 197 | * @param string $string string to truncate 198 | * @param integer $length length to truncate to 199 | * @param boolean $hover (optional) whether or not to add the rollover 200 | * @return string truncate string 201 | */ 202 | public static function truncate($string, $length, $hover = true) 203 | { 204 | if (strlen($string) > $length) 205 | { 206 | if ($hover == true) 207 | { 208 | $string = '' . mb_strcut($string, 0, $length, 'UTF-8') . '…'; 209 | } 210 | else 211 | { 212 | $string = mb_strcut($string, 0, $length, 'UTF-8') . '…'; 213 | } 214 | } 215 | 216 | return $string; 217 | } 218 | 219 | // }}} 220 | // {{{ Upper Words 221 | 222 | /** 223 | * Upper Words 224 | * 225 | * Applies strtolower() and ucwords() to the passed string. The 226 | * exception being email addresses which are not formatted at all. 227 | * 228 | * @static 229 | * @param string $string string to format 230 | * @return string formatted string 231 | */ 232 | public static function upperWords($string) 233 | { 234 | // Only formats non-email addresses 235 | if (filter_var($string, FILTER_VALIDATE_EMAIL) == false) 236 | { 237 | $string = ucwords(strtolower($string)); 238 | } 239 | 240 | return $string; 241 | } 242 | 243 | // }}} 244 | } 245 | 246 | -------------------------------------------------------------------------------- /src/Time.php: -------------------------------------------------------------------------------- 1 | $time) 159 | { 160 | $difference = $current - $time; 161 | $suffix = ' ago'; 162 | } 163 | else 164 | { 165 | $difference = $time - $current; 166 | $suffix = ' from now'; 167 | } 168 | 169 | // Less than 1 minute ago (seconds ago) 170 | if ($difference < 60) 171 | { 172 | $time_ago = 'seconds'; 173 | } 174 | // Less than 1 hour ago (minutes ago) 175 | elseif ($difference < Time::HOUR) 176 | { 177 | $minutes = round($difference / 60); 178 | 179 | if ($minutes == 60) 180 | { 181 | $time_ago = 'an hour'; 182 | } 183 | else 184 | { 185 | $time_ago = ($minutes == 1 ? 'a' : $minutes) . ' minute' . ($minutes != 1 ? 's' : ''); 186 | } 187 | } 188 | // Less than 1 day ago (hours ago) 189 | elseif ($difference < Time::DAY) 190 | { 191 | $hours = round($difference / Time::HOUR); 192 | 193 | if ($hours == 24) 194 | { 195 | $time_ago = 'a day'; 196 | } 197 | else 198 | { 199 | $time_ago = ($hours == 1 ? 'an' : $hours) . ' hour' . ($hours != 1 ? 's' : ''); 200 | } 201 | } 202 | // Less than 1 week ago (days ago) 203 | elseif ($difference < Time::WEEK) 204 | { 205 | $days = round($difference / Time::DAY); 206 | 207 | if ($days == 7) 208 | { 209 | $time_ago = 'a week'; 210 | } 211 | else 212 | { 213 | $time_ago = ($days == 1 ? 'a' : $days) . ' day' . ($days != 1 ? 's' : ''); 214 | } 215 | } 216 | // Less than 1 month ago (weeks ago) 217 | elseif ($difference < Time::MONTH) 218 | { 219 | $weeks = round($difference / Time::WEEK); 220 | 221 | if ($weeks == 4) 222 | { 223 | $time_ago = 'a month'; 224 | } 225 | else 226 | { 227 | $time_ago = ($weeks == 1 ? 'a' : $weeks) . ' week' . ($weeks != 1 ? 's' : ''); 228 | } 229 | } 230 | // Less than 1 year ago (months ago) 231 | elseif ($difference < Time::YEAR) 232 | { 233 | $months = round($difference / Time::MONTH); 234 | 235 | if ($months == 12) 236 | { 237 | $time_ago = 'a year'; 238 | } 239 | else 240 | { 241 | $time_ago = ($months == 1 ? 'a' : $months) . ' month' . ($months != 1 ? 's' : ''); 242 | } 243 | } 244 | // Over 1 year ago (years ago) 245 | else 246 | { 247 | $years = round($difference / Time::YEAR); 248 | $time_ago = ($years == 1 ? 'a' : $years) . ' year' . ($years != 1 ? 's' : ''); 249 | } 250 | 251 | $time_ago .= $suffix; 252 | } 253 | 254 | return $time_ago; 255 | } 256 | 257 | /** 258 | * Timestamp 259 | * 260 | * Current Universal Time in the specified format. 261 | * 262 | * @static 263 | * @param string $format format of the timestamp 264 | * @return string $timestamp formatted timestamp 265 | */ 266 | public static function timestamp($format = 'Y-m-d H:i:s') 267 | { 268 | return gmdate($format); 269 | } 270 | } 271 | 272 | -------------------------------------------------------------------------------- /tests/Pickles/ConfigTest.php: -------------------------------------------------------------------------------- 1 | ) 42 | */ 43 | public function testMissingCLIEnvironment() 44 | { 45 | $_SERVER['argc'] = 1; 46 | 47 | file_put_contents('/tmp/pickles.php', ' [ 50 | "local" => "127.0.0.1", 51 | "production" => "123.456.789.0", 52 | ], 53 | ]; 54 | '); 55 | 56 | new Pickles\Config('/tmp/pickles.php'); 57 | } 58 | 59 | /** 60 | * @expectedException Exception 61 | * @expectedExceptionMessage You must pass an environment (e.g. php script.php ) 62 | */ 63 | public function testCLIEnvironmentMissingParameter() 64 | { 65 | $_SERVER['argc'] = 1; 66 | 67 | new Pickles\Config('/tmp/pickles.php'); 68 | } 69 | 70 | public function testEnvironmentMatchCLI() 71 | { 72 | $_SERVER['argc'] = 2; 73 | $_SERVER['argv'][1] = 'local'; 74 | 75 | $config = new Pickles\Config('/tmp/pickles.php'); 76 | 77 | $this->assertEquals('local', $config['environment']); 78 | } 79 | 80 | public function testEnvironmentMatchExact() 81 | { 82 | $_SERVER['REQUEST_METHOD'] = 'GET'; 83 | 84 | $config = new Pickles\Config('/tmp/pickles.php'); 85 | 86 | $this->assertEquals('local', $config['environment']); 87 | } 88 | 89 | public function testEnvironmentMatchFuzzy() 90 | { 91 | $_SERVER['REQUEST_METHOD'] = 'GET'; 92 | $_SERVER['SERVER_NAME'] = '127.0.0.1'; 93 | 94 | file_put_contents('/tmp/pickles.php', ' [ 97 | "local" => "/127\.0\.0\.[0-9]+/", 98 | "production" => "123.456.789.0", 99 | ], 100 | ]; 101 | '); 102 | 103 | $config = new Pickles\Config('/tmp/pickles.php'); 104 | 105 | $this->assertEquals('local', $config['environment']); 106 | } 107 | 108 | /** 109 | * @expectedException Exception 110 | * @expectedExceptionMessage Unable to determine the environment. 111 | */ 112 | public function testEnvironmentNoMatch() 113 | { 114 | $_SERVER['REQUEST_METHOD'] = 'GET'; 115 | $_SERVER['SERVER_NAME'] = 'lolnope'; 116 | 117 | new Pickles\Config('/tmp/pickles.php'); 118 | } 119 | 120 | public function testProductionDisplayErrors() 121 | { 122 | $_SERVER['REQUEST_METHOD'] = 'GET'; 123 | $_SERVER['HTTP_HOST'] = '123.456.789.0'; 124 | 125 | ini_set('display_errors', true); 126 | 127 | $this->assertEquals('1', ini_get('display_errors')); 128 | 129 | new Pickles\Config('/tmp/pickles.php'); 130 | 131 | $this->assertEquals('', ini_get('display_errors')); 132 | } 133 | 134 | public function testFlatten() 135 | { 136 | $_SERVER['REQUEST_METHOD'] = 'GET'; 137 | $_SERVER['HTTP_HOST'] = '123.456.789.0'; 138 | 139 | file_put_contents('/tmp/pickles.php', ' [ 142 | "local" => "/127\.0\.0\.[0-9]+/", 143 | "production" => "123.456.789.0", 144 | ], 145 | "foo" => [ 146 | "local" => "barLocal", 147 | "production" => "barProduction", 148 | ], 149 | "nestedOne" => [ 150 | "nestedTwo" => [ 151 | "local" => "nestedLocal", 152 | "production" => "nestedProduction", 153 | ], 154 | ], 155 | ]; 156 | '); 157 | 158 | $config = new Pickles\Config('/tmp/pickles.php'); 159 | 160 | $this->assertEquals('barProduction', $config['foo']); 161 | $this->assertEquals('nestedProduction', $config['nestedOne']['nestedTwo']); 162 | } 163 | 164 | public function testGetInstance() 165 | { 166 | $_SERVER['REQUEST_METHOD'] = 'GET'; 167 | $_SERVER['HTTP_HOST'] = '123.456.789.0'; 168 | 169 | $config = Pickles\Config::getInstance('/tmp/pickles.php'); 170 | 171 | $this->assertInstanceOf('Pickles\\Config', $config); 172 | } 173 | } 174 | 175 | -------------------------------------------------------------------------------- /tests/Pickles/ObjectTest.php: -------------------------------------------------------------------------------- 1 | [ 13 | "local" => "127.0.0.1", 14 | "production" => "123.456.789.0", 15 | ], 16 | "pickles" => [ 17 | "datasource" => "mysql", 18 | ], 19 | "datasources" => [ 20 | "mysql" => [ 21 | "driver" => "pdo_mysql", 22 | ], 23 | ], 24 | ]; 25 | '); 26 | 27 | $config = Pickles\Config::getInstance('/tmp/pickles.php'); 28 | } 29 | 30 | public static function tearDownAfterClass() 31 | { 32 | unlink('/tmp/pickles.php'); 33 | } 34 | 35 | public function testConstructorWithoutObjects() 36 | { 37 | $object = new Pickles\Object(); 38 | 39 | $this->assertInstanceOf('Pickles\\Config', PHPUnit_Framework_Assert::readAttribute($object, 'config')); 40 | } 41 | 42 | public function testConstructorWithObjects() 43 | { 44 | $object = new Pickles\Object('cache'); 45 | $this->assertInstanceOf('Pickles\\Cache', $object->cache); 46 | 47 | $object = new Pickles\Object(['cache', 'db']); 48 | $this->assertInstanceOf('Pickles\\Cache', $object->cache); 49 | $this->assertInstanceOf('Pickles\\Database', $object->db); 50 | } 51 | 52 | public function testGetInstanceWithoutClass() 53 | { 54 | $this->assertFalse(Pickles\Object::getInstance()); 55 | } 56 | 57 | public function testProfiler() 58 | { 59 | file_put_contents('/tmp/pickles.php', ' [ 62 | "local" => "127.0.0.1", 63 | "production" => "123.456.789.0", 64 | ], 65 | "pickles" => [ 66 | "datasource" => "mysql", 67 | "profiler" => true, 68 | "foo" => "bar", 69 | ], 70 | "datasources" => [ 71 | "mysql" => [ 72 | "driver" => "pdo_mysql", 73 | ], 74 | ], 75 | ]; 76 | '); 77 | 78 | $config = Pickles\Config::getInstance('/tmp/pickles.php'); 79 | $object = new Pickles\Object(); 80 | } 81 | } 82 | 83 | -------------------------------------------------------------------------------- /tests/Pickles/ProfilerTest.php: -------------------------------------------------------------------------------- 1 | [ 16 | "local" => "127.0.0.1", 17 | "production" => "123.456.789.0", 18 | ], 19 | "pickles" => [ 20 | "profiler" => true, 21 | ], 22 | ]; 23 | '); 24 | 25 | new Pickles\Config('/tmp/pickles.php'); 26 | 27 | Pickles\Profiler::log('i am a string'); 28 | Pickles\Profiler::log(['foo' => 'bar']); 29 | Pickles\Profiler::log($this, 'testProfiler'); 30 | Pickles\Profiler::timer('swatch'); 31 | Pickles\Profiler::query('SELECT', ['foo' => 'bar'], ['results'], 1, 'EXPLAIN'); 32 | Pickles\Profiler::timer('swatch'); 33 | Pickles\Profiler::query('SELECT', ['foo' => 'bar'], ['results'], 1); 34 | 35 | $report = Pickles\Profiler::report(); 36 | 37 | $this->assertEquals(7, count($report)); 38 | $this->assertEquals(7, count($report['logs'])); 39 | $this->assertEquals(5, count($report['logs'][0])); 40 | $this->assertEquals('string', $report['logs'][0]['type']); 41 | $this->assertEquals('i am a string', $report['logs'][0]['details']); 42 | $this->assertEquals('array', $report['logs'][1]['type']); 43 | $this->assertEquals(['foo' => 'bar'], $report['logs'][1]['details']); 44 | $this->assertEquals('object', $report['logs'][2]['type']); 45 | $this->assertEquals(['class' => 'ProfilerTest', 'method' => 'testProfiler()'], $report['logs'][2]['details']); 46 | $this->assertEquals('timer', $report['logs'][3]['type']); 47 | $this->assertEquals('swatch', $report['logs'][3]['details']['name']); 48 | $this->assertEquals('start', $report['logs'][3]['details']['action']); 49 | $this->assertEquals('database', $report['logs'][4]['type']); 50 | $this->assertEquals('SELECT', $report['logs'][4]['details']['query']); 51 | $this->assertEquals(['foo' => 'bar'], $report['logs'][4]['details']['parameters']); 52 | $this->assertEquals(['results'], $report['logs'][4]['details']['results']); 53 | $this->assertEquals(1, $report['logs'][4]['details']['execution_time']); 54 | $this->assertEquals('EXPLAIN', $report['logs'][4]['details']['explain']); 55 | $this->assertEquals('timer', $report['logs'][5]['type']); 56 | $this->assertEquals('swatch', $report['logs'][5]['details']['name']); 57 | $this->assertEquals('stop', $report['logs'][5]['details']['action']); 58 | $this->assertEquals('database', $report['logs'][6]['type']); 59 | $this->assertEquals('SELECT', $report['logs'][6]['details']['query']); 60 | $this->assertEquals(['foo' => 'bar'], $report['logs'][6]['details']['parameters']); 61 | $this->assertEquals(['results'], $report['logs'][6]['details']['results']); 62 | $this->assertEquals(1, $report['logs'][6]['details']['execution_time']); 63 | $this->assertFalse(isset($report['logs'][6]['details']['explain'])); 64 | } 65 | } 66 | 67 | -------------------------------------------------------------------------------- /tests/Pickles/ResourceTest.php: -------------------------------------------------------------------------------- 1 | true, 9 | ]; 10 | 11 | public $auth = [ 12 | 'DELETE' => true, 13 | ]; 14 | 15 | public $filter = [ 16 | 'GET' => [ 17 | 'foo' => 'trim', 18 | 'bar' => 'password_hash', 19 | ], 20 | ]; 21 | 22 | public $validate = [ 23 | 'GET' => [ 24 | 'missing', 25 | 'isBoolean' => ['filter:boolean' => 'Error'], 26 | 'isNotBoolean' => ['filter:boolean' => 'Error'], 27 | 'isEmail' => ['filter:email' => 'Error'], 28 | 'isNotEmail' => ['filter:email' => 'Error'], 29 | 'isFloat' => ['filter:float' => 'Error'], 30 | 'isNotFloat' => ['filter:float' => 'Error'], 31 | 'isInt' => ['filter:int' => 'Error'], 32 | 'isNotInt' => ['filter:int' => 'Error'], 33 | 'isIP' => ['filter:ip' => 'Error'], 34 | 'isNotIP' => ['filter:ip' => 'Error'], 35 | 'isURL' => ['filter:url' => 'Error'], 36 | 'isNotURL' => ['filter:url' => 'Error'], 37 | 'invalidRule' => ['filter' => 'Error'], 38 | 'lessThan' => ['length:<:10' => 'Error'], 39 | 'lessThanEqual' => ['length:<=:10' => 'Error'], 40 | 'equal' => ['length:==:10' => 'Error'], 41 | 'notEqual' => ['length:!=:10' => 'Error'], 42 | 'greaterThan' => ['length:>=:10' => 'Error'], 43 | 'greaterThanEqual' => ['length:>:10' => 'Error'], 44 | 'greaterLessThan' => ['length:><:10' => 'Error'], 45 | 'regex' => ['regex:/[a-z]+/' => 'Error'], 46 | ], 47 | ]; 48 | 49 | public function GET() 50 | { 51 | 52 | } 53 | 54 | public function PUT() 55 | { 56 | return ['foo' => 'bar']; 57 | } 58 | 59 | public function ERROR() 60 | { 61 | throw new \Exception('Error'); 62 | } 63 | } 64 | } 65 | 66 | namespace 67 | { 68 | class ResourceTest extends PHPUnit_Framework_TestCase 69 | { 70 | public function setUp() 71 | { 72 | $_SERVER['REQUEST_METHOD'] = 'GET'; 73 | $_SERVER['SERVER_NAME'] = '127.0.0.1'; 74 | 75 | file_put_contents('/tmp/pickles.php', ' [ 78 | "local" => "127.0.0.1", 79 | "production" => "123.456.789.0", 80 | ], 81 | "pickles" => [ 82 | "namespace" => "", 83 | "datasource" => "mysql", 84 | ], 85 | "datasources" => [ 86 | "mysql" => [ 87 | "driver" => "pdo_mysql", 88 | ], 89 | ], 90 | ]; 91 | '); 92 | 93 | Pickles\Config::getInstance('/tmp/pickles.php'); 94 | } 95 | 96 | public function testFilterAndValidate() 97 | { 98 | $response = json_encode([ 99 | 'meta' => [ 100 | 'status' => 400, 101 | 'message' => 'Missing or invalid parameters.', 102 | 'errors' => [ 103 | 'missing' => ['The missing parameter is required.'], 104 | 'isNotBoolean' => ['Error'], 105 | 'isNotEmail' => ['Error'], 106 | 'isNotFloat' => ['Error'], 107 | 'isNotInt' => ['Error'], 108 | 'isNotIP' => ['Error'], 109 | 'isNotURL' => ['Error'], 110 | 'invalidRule' => ['Invalid filter, expecting boolean, email, float, int, ip or url.'], 111 | 'greaterLessThan' => ['Invalid operator, expecting <, <=, ==, !=, >= or >.'], 112 | 'regex' => ['Error'], 113 | ], 114 | ], 115 | ]); 116 | 117 | $this->expectOutputString($response); 118 | 119 | $_SERVER['REQUEST_METHOD'] = 'GET'; 120 | $_REQUEST['request'] = 'v1/resource/1'; 121 | $_GET = [ 122 | 'foo' => ' bar ', 123 | 'bar' => 'unencrypted', 124 | 'isBoolean' => true, 125 | 'isNotBoolean' => 'invalid', 126 | 'isEmail' => 'foo@bar.com', 127 | 'isNotEmail' => 'nope', 128 | 'isFloat' => 1.234567890, 129 | 'isNotFloat' => 'five', 130 | 'isInt' => 22381, 131 | 'isNotInt' => 'pretzel', 132 | 'isIP' => '127.0.0.1', 133 | 'isNotIP' => 'home', 134 | 'isURL' => 'http://joshtronic.com', 135 | 'isNotURL' => 'doubleUdoubleUdoubleUdot', 136 | 'invalidRule' => 'invalid', 137 | 'lessThan' => '...', 138 | 'lessThanEqual' => '.......', 139 | 'equal' => '..........', 140 | 'notEqual' => '.......', 141 | 'greaterThan' => '............', 142 | 'greaterThanEqual' => '............', 143 | 'greaterLessThan' => '......', 144 | 'regex' => 'abc', 145 | ]; 146 | 147 | if (version_compare(PHP_VERSION, '5.5.0', '<')) 148 | { 149 | unset($_GET['bar']); 150 | } 151 | 152 | new Pickles\Router(); 153 | 154 | $this->assertEquals('bar', $_GET['foo']); 155 | 156 | if (version_compare(PHP_VERSION, '5.5.0', '>=')) 157 | { 158 | $this->assertFalse('unencrypted' == $_GET['bar']); 159 | } 160 | } 161 | 162 | public function testHTTPS() 163 | { 164 | $response = json_encode([ 165 | 'meta' => [ 166 | 'status' => 400, 167 | 'message' => 'HTTPS is required.', 168 | ], 169 | ]); 170 | 171 | $this->expectOutputString($response); 172 | 173 | $_SERVER['REQUEST_METHOD'] = 'POST'; 174 | $_REQUEST['request'] = 'v1/resource/1'; 175 | 176 | new Pickles\Router(); 177 | } 178 | 179 | public function testPUT() 180 | { 181 | $response = json_encode([ 182 | 'meta' => [ 183 | 'status' => 200, 184 | 'message' => 'OK', 185 | ], 186 | 'response' => [ 187 | 'foo' => 'bar', 188 | ], 189 | ]); 190 | 191 | $this->expectOutputString($response); 192 | 193 | $_SERVER['REQUEST_METHOD'] = 'PUT'; 194 | $_REQUEST['request'] = 'v1/resource/1'; 195 | 196 | new Pickles\Router(); 197 | } 198 | 199 | public function testMisconfiguredAuth() 200 | { 201 | $response = json_encode([ 202 | 'meta' => [ 203 | 'status' => 401, 204 | 'message' => 'Authentication is not configured properly.', 205 | ], 206 | ]); 207 | 208 | $this->expectOutputString($response); 209 | 210 | $_SERVER['REQUEST_METHOD'] = 'DELETE'; 211 | $_REQUEST['request'] = 'v1/resource/1'; 212 | 213 | new Pickles\Router(); 214 | } 215 | 216 | public function testMethodNotAllowed() 217 | { 218 | $response = json_encode([ 219 | 'meta' => [ 220 | 'status' => 405, 221 | 'message' => 'Method not allowed.', 222 | ], 223 | ]); 224 | 225 | $this->expectOutputString($response); 226 | 227 | $_SERVER['REQUEST_METHOD'] = 'NOPE'; 228 | $_REQUEST['request'] = 'v1/resource/1'; 229 | 230 | new Pickles\Router(); 231 | } 232 | 233 | public function testLowErrorCode() 234 | { 235 | $response = json_encode([ 236 | 'meta' => [ 237 | 'status' => 500, 238 | 'message' => 'Error', 239 | ], 240 | ]); 241 | 242 | $this->expectOutputString($response); 243 | 244 | $_SERVER['REQUEST_METHOD'] = 'ERROR'; 245 | $_REQUEST['request'] = 'v1/resource/1'; 246 | 247 | new Pickles\Router(); 248 | } 249 | 250 | public function testProfiler() 251 | { 252 | $this->expectOutputRegex('/"profiler":{/'); 253 | 254 | file_put_contents('/tmp/pickles.php', ' [ 257 | "local" => "127.0.0.1", 258 | "production" => "123.456.789.0", 259 | ], 260 | "pickles" => [ 261 | "namespace" => "", 262 | "datasource" => "mysql", 263 | "profiler" => true, 264 | ], 265 | "datasources" => [ 266 | "mysql" => [ 267 | "driver" => "pdo_mysql", 268 | ], 269 | ], 270 | ]; 271 | '); 272 | 273 | Pickles\Config::getInstance('/tmp/pickles.php'); 274 | 275 | $_SERVER['REQUEST_METHOD'] = 'PUT'; 276 | $_REQUEST['request'] = 'v1/resource/1'; 277 | 278 | new Pickles\Router(); 279 | } 280 | } 281 | } 282 | 283 | -------------------------------------------------------------------------------- /tests/Pickles/RouterTest.php: -------------------------------------------------------------------------------- 1 | [ 19 | 'status' => 500, 20 | 'message' => 'Undefined index: request', 21 | ], 22 | ]); 23 | 24 | $this->expectOutputString($response); 25 | 26 | $_SERVER['REQUEST_METHOD'] = 'GET'; 27 | $_SERVER['SERVER_NAME'] = '127.0.0.1'; 28 | 29 | file_put_contents('/tmp/pickles.php', ' [ 32 | "local" => "127.0.0.1", 33 | "production" => "123.456.789.0", 34 | ], 35 | "pickles" => [ 36 | "namespace" => "", 37 | ], 38 | "datasources" => [], 39 | ]; 40 | '); 41 | 42 | Pickles\Config::getInstance('/tmp/pickles.php'); 43 | 44 | new Pickles\Router(); 45 | } 46 | 47 | public function testNotFound() 48 | { 49 | $response = json_encode([ 50 | 'meta' => [ 51 | 'status' => 404, 52 | 'message' => 'Not Found.', 53 | ], 54 | ]); 55 | 56 | $this->expectOutputString($response); 57 | 58 | $_SERVER['REQUEST_METHOD'] = 'GET'; 59 | $_REQUEST['request'] = 'v1/doesnotexist'; 60 | 61 | new Pickles\Router(); 62 | } 63 | 64 | // We're just testing that the class can be loaded, not that it will 65 | // work. That logic is off in ResourceTest 66 | public function testFoundWithUID() 67 | { 68 | Pickles\Object::$instances = []; 69 | 70 | $_SERVER['REQUEST_METHOD'] = 'GET'; 71 | $_SERVER['SERVER_NAME'] = '127.0.0.1'; 72 | 73 | file_put_contents('/tmp/pickles.php', ' [ 76 | "local" => "127.0.0.1", 77 | "production" => "123.456.789.0", 78 | ], 79 | "datasources" => [], 80 | ]; 81 | '); 82 | 83 | Pickles\Config::getInstance('/tmp/pickles.php'); 84 | 85 | $response = json_encode([ 86 | 'meta' => [ 87 | 'status' => 405, 88 | 'message' => 'Method not allowed.', 89 | ], 90 | ]); 91 | 92 | $this->expectOutputString($response); 93 | 94 | $_SERVER['REQUEST_METHOD'] = 'GET'; 95 | $_REQUEST['request'] = 'v1/router/1'; 96 | 97 | new Pickles\Router(); 98 | } 99 | } 100 | } 101 | 102 | -------------------------------------------------------------------------------- /tests/Pickles/StringTest.php: -------------------------------------------------------------------------------- 1 | assertEquals(Pickles\String::formatPhoneNumber($a), $b); 11 | } 12 | 13 | public function providerFormatPhoneNumber() 14 | { 15 | return [ 16 | ['1234567890', '123-456-7890'], 17 | ['123 456 7890', '123-456-7890'], 18 | ['123.456.7890', '123-456-7890'], 19 | ['123_456_7890', '123-456-7890'], 20 | ['1234567890', '123-456-7890'], 21 | ['1234-56-7890', '123-456-7890'], 22 | ['(123) 456-7890', '123-456-7890'], 23 | ['1234567890 x1000', '123-456-7890x1000'], 24 | ['(123) 456-7890_x10.00', '123-456-7890x1000'], 25 | ]; 26 | } 27 | 28 | public function testIsEmpty() 29 | { 30 | $this->assertTrue(Pickles\String::isEmpty('')); 31 | $this->assertTrue(Pickles\String::isEmpty(' ')); 32 | $this->assertTrue(Pickles\String::isEmpty(false)); 33 | $this->assertTrue(Pickles\String::isEmpty(null)); 34 | $this->assertTrue(Pickles\String::isEmpty(true, false)); 35 | 36 | $this->assertFalse(Pickles\String::isEmpty(0)); 37 | $this->assertFalse(Pickles\String::isEmpty('foo')); 38 | $this->assertFalse(Pickles\String::isEmpty(' bar ')); 39 | $this->assertFalse(Pickles\String::isEmpty(true)); 40 | } 41 | 42 | public function testRandom() 43 | { 44 | $this->assertEquals(strlen(Pickles\String::random()), 8); 45 | $this->assertEquals(strlen(Pickles\String::random(16)), 16); 46 | 47 | $this->assertEquals(preg_match('/[a-z0-9]/', Pickles\String::random(32, true, true)), 1); 48 | $this->assertEquals(preg_match('/[a-z]/', Pickles\String::random(32, true, false)), 1); 49 | $this->assertEquals(preg_match('/[0-9]/', Pickles\String::random(32, false, true)), 1); 50 | 51 | $this->assertEquals(preg_match('/[0-9]/', Pickles\String::random(32, true, false)), 0); 52 | $this->assertEquals(preg_match('/[a-z]/', Pickles\String::random(32, false, true)), 0); 53 | $this->assertEquals(preg_match('/[a-z0-9]/', Pickles\String::random(32, false, false)), 0); 54 | } 55 | 56 | public function testRandomSimilarFalse() 57 | { 58 | $this->assertRegExp('/[a-hj-np-z2-9]{8}/', Pickles\String::random(8, true, true, false)); 59 | } 60 | 61 | /** 62 | * @dataProvider providerTruncate 63 | */ 64 | public function testTruncate($a, $b, $c, $d) 65 | { 66 | $this->assertEquals(Pickles\String::truncate($a, $b, $c), $d); 67 | } 68 | 69 | public function providerTruncate() 70 | { 71 | return [ 72 | ['foo bar', 3, true, 'foo…'], 73 | ['foo bar', 3, false, 'foo…'], 74 | ['foo bar', 7, true, 'foo bar'], 75 | ['foo bar', 8, true, 'foo bar'], 76 | ]; 77 | } 78 | 79 | /** 80 | * @dataProvider providerUpperWords 81 | */ 82 | public function testUpperWords($a, $b) 83 | { 84 | $this->assertEquals(Pickles\String::upperWords($a), $b); 85 | } 86 | 87 | public function providerUpperWords() 88 | { 89 | return [ 90 | ['foo bar', 'Foo Bar'], 91 | ['FOO BAR', 'Foo Bar'], 92 | ['fOO bAR', 'Foo Bar'], 93 | ['foo@bar.com', 'foo@bar.com'], 94 | ['FOO@BAR.COM', 'FOO@BAR.COM'], 95 | ]; 96 | } 97 | 98 | /** 99 | * @dataProvider providerGenerateSlug 100 | */ 101 | public function testGenerateSlug($a, $b) 102 | { 103 | $this->assertEquals($b, Pickles\String::generateSlug($a)); 104 | } 105 | 106 | public function providerGenerateSlug() 107 | { 108 | return [ 109 | ['TEST STRING', 'test-string'], 110 | ['Test String', 'test-string'], 111 | ['TEST STRING', 'test-string'], 112 | ['#! Test String', 'test-string'], 113 | ['-test--string-', 'test-string'], 114 | ]; 115 | } 116 | 117 | public function testPluralize() 118 | { 119 | $this->assertEquals('test', Pickles\String::pluralize('test', 1, false)); 120 | $this->assertEquals('1 test', Pickles\String::pluralize('test', 1, true)); 121 | $this->assertEquals('tests', Pickles\String::pluralize('test', 2, false)); 122 | $this->assertEquals('2 tests', Pickles\String::pluralize('test', 2, true)); 123 | } 124 | } 125 | 126 | -------------------------------------------------------------------------------- /tests/Pickles/TimeTest.php: -------------------------------------------------------------------------------- 1 | assertEquals(Pickles\Time::age($a), $b); 16 | } 17 | 18 | public function providerAge() 19 | { 20 | $time = strtotime('-25 years'); 21 | 22 | return [ 23 | [date('Y-m-d', $time), '25'], 24 | [date('m/d/Y', $time), '25'], 25 | [date('r', $time), '25'], 26 | ['today', '0'], 27 | ['400 days ago', '1'], 28 | [true, Pickles\Time::age('1969-12-31')], 29 | ]; 30 | } 31 | 32 | public function testAgePastTime() 33 | { 34 | $this->assertEquals(18, Pickles\Time::age(date('Y-m-d', strtotime('-18 years')))); 35 | } 36 | 37 | public function testAgeFutureTime() 38 | { 39 | $this->assertEquals(-18, Pickles\Time::age(date('Y-m-d', strtotime('18 years')))); 40 | } 41 | 42 | public function testAgeWrongFormat() 43 | { 44 | $this->assertEquals(17, Pickles\Time::age(date('Ymd', strtotime('December 31st -18 years')))); 45 | } 46 | 47 | public function testAgoJustNow() 48 | { 49 | $this->assertEquals('just now', Pickles\Time::ago(Pickles\Time::timestamp())); 50 | } 51 | 52 | public function testAgoPastTimeSeconds() 53 | { 54 | $this->assertEquals('seconds ago', Pickles\Time::ago(strtotime('-30 seconds'))); 55 | } 56 | 57 | public function testAgoPastTimeMinute() 58 | { 59 | $this->assertEquals('a minute ago', Pickles\Time::ago(strtotime('-1 minutes'))); 60 | } 61 | 62 | public function testAgoPastTimeMinutes() 63 | { 64 | $this->assertEquals('5 minutes ago', Pickles\Time::ago(strtotime('-5 minutes'))); 65 | } 66 | 67 | public function testAgoPastTimeHour() 68 | { 69 | $this->assertEquals('an hour ago', Pickles\Time::ago(strtotime('-1 hours'))); 70 | } 71 | 72 | public function testAgoPastTimeHours() 73 | { 74 | $this->assertEquals('2 hours ago', Pickles\Time::ago(strtotime('-2 hours'))); 75 | } 76 | 77 | public function testAgoPastTimeDay() 78 | { 79 | $this->assertEquals('a day ago', Pickles\Time::ago(strtotime('-1 days'))); 80 | } 81 | 82 | public function testAgoPastTimeDays() 83 | { 84 | $this->assertEquals('2 days ago', Pickles\Time::ago(strtotime('-2 days'))); 85 | } 86 | 87 | public function testAgoPastTimeWeek() 88 | { 89 | $this->assertEquals('a week ago', Pickles\Time::ago(strtotime('-1 weeks'))); 90 | } 91 | 92 | public function testAgoPastTimeWeeks() 93 | { 94 | $this->assertEquals('2 weeks ago', Pickles\Time::ago(strtotime('-2 weeks'))); 95 | } 96 | 97 | public function testAgoPastTimeMonth() 98 | { 99 | $this->assertEquals('a month ago', Pickles\Time::ago(strtotime('-1 months'))); 100 | } 101 | 102 | public function testAgoPastTimeMonths() 103 | { 104 | $this->assertEquals('2 months ago', Pickles\Time::ago(strtotime('-2 months'))); 105 | } 106 | 107 | public function testAgoPastTimeYear() 108 | { 109 | $this->assertEquals('a year ago', Pickles\Time::ago(strtotime('-1 years'))); 110 | } 111 | 112 | public function testAgoPastTimeYears() 113 | { 114 | $this->assertEquals('2 years ago', Pickles\Time::ago(strtotime('-2 years'))); 115 | } 116 | 117 | public function testAgoFutureTimeSeconds() 118 | { 119 | $this->assertEquals('seconds from now', Pickles\Time::ago(strtotime('+30 seconds'))); 120 | } 121 | 122 | public function testAgoFutureTimeMinutes() 123 | { 124 | $this->assertEquals('5 minutes from now', Pickles\Time::ago(strtotime('+5 minutes'))); 125 | } 126 | 127 | public function testAgoFutureTimeHours() 128 | { 129 | $this->assertEquals('an hour from now', Pickles\Time::ago(strtotime('+1 hour'))); 130 | } 131 | 132 | public function testAgoFutureTimeDays() 133 | { 134 | $this->assertEquals('a day from now', Pickles\Time::ago(strtotime('+1 day'))); 135 | } 136 | 137 | public function testAgoFutureTimeWeeks() 138 | { 139 | $this->assertEquals('a week from now', Pickles\Time::ago(strtotime('+1 week'))); 140 | } 141 | 142 | public function testAgoFutureTimeMonths() 143 | { 144 | $this->assertEquals('a month from now', Pickles\Time::ago(strtotime('+1 month'))); 145 | } 146 | 147 | public function testAgoFutureTimeYears() 148 | { 149 | $this->assertEquals('a year from now', Pickles\Time::ago(strtotime('+1 year'))); 150 | } 151 | 152 | public function testTimestamp() 153 | { 154 | $this->assertEquals(gmdate('Y-m-d H:i:s'), Pickles\Time::timestamp()); 155 | } 156 | 157 | public function testRoundUpHour() 158 | { 159 | $this->assertEquals('an hour ago', Pickles\Time::ago(strtotime('-59 minutes -55 seconds'))); 160 | } 161 | 162 | public function testRoundUpDay() 163 | { 164 | $this->assertEquals('a day ago', Pickles\Time::ago(strtotime('-23 hours -55 minutes'))); 165 | } 166 | 167 | public function testRoundUpWeek() 168 | { 169 | $this->assertEquals('a week ago', Pickles\Time::ago(strtotime('-6 days -23 hours'))); 170 | } 171 | 172 | public function testRoundUpMonth() 173 | { 174 | $this->assertEquals('a month ago', Pickles\Time::ago(strtotime('-29 days'))); 175 | } 176 | 177 | public function testRoundUpYear() 178 | { 179 | $this->assertEquals('a year ago', Pickles\Time::ago(strtotime('-364 days'))); 180 | } 181 | } 182 | 183 | -------------------------------------------------------------------------------- /tests/bootstrap.php: -------------------------------------------------------------------------------- 1 | > $PHPINI 12 | echo "extension = memcached.so" >> $PHPINI 13 | echo "extension = redis.so" >> $PHPINI 14 | fi 15 | 16 | --------------------------------------------------------------------------------