diff --git a/README.md b/README.md index 56de5ed..c74f40a 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,11 @@ -# Laravel Transformers +# Zaltana Transformers -[![Build Status](https://travis-ci.org/Apiness/laravel-transformers.svg?branch=master)](https://travis-ci.org/Apiness/laravel-transformers) +[![Build Status](https://travis-ci.org/marfurt/zaltana-transformers.svg?branch=master)](https://travis-ci.org/marfurt/zaltana-transformers) + +> **Note:** This package is part of the _Zaltana components_, a serie of small packages made to provide useful features to Laravel projects. + +This package provides a presentation layer for transforming data output when building an API. -This package is a presentation layer for transforming data output when building an API. ## Requirements @@ -12,33 +15,33 @@ This package is a presentation layer for transforming data output when building ## Installation -Pull this package in through Composer, by updating the `composer.json` as follows: +Pull this package in through [Composer](https://getcomposer.org), by updating the `composer.json` file as follows: -``` +```json { "repositories": [ { "type": "vcs", - "url": "https://github.com/Apiness/laravel-transformers" + "url": "https://github.com/marfurt/zaltana-transformers" } ], "require": { - "apiness/laravel-transformers": "~1.0" + "zaltana/transformers": "~1.0" } } ``` + ## Usage -Override the abstract `Transformer` class to create a custom transformer on your entity: +Override the abstract `Transformer` class to create a custom transformer for your entity: ```php -use Apiness\Transformers\Transformer; -use Illuminate\Database\Eloquent\Model; +use Zaltana\Transformers\Transformer; -class ModelTransformer extends Transformer { +class MyModelTransformer extends Transformer { - protected function transformModel(Model $model) + protected function transform($model) { return [ 'title' => $model->title, @@ -48,22 +51,69 @@ class ModelTransformer extends Transformer { } ``` -For transforming the model, you need to call the `process` method: +For transforming a model object, you need to instantiate your transformer and to call the `process` method on it. +If you want to transform your model relationships as well, you need to inject their corresponding transformers into your model transformer. ```php -$transformer = new ModelTransformer( - [ - 'nested_model' => new NestedModelTransformer() - ] -); +$transformer = new MyModelTransformer([ + 'myRelationship' => new RelationshipTransformer() +]); -$result = $transformer->process($this->mockedModel); +$data = $transformer->process($myModelObject); ``` -##License +You can also transform a collection of objects instead of a single object. -This library is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT). +```php +// Transforming array of objects +$objectsInArray = [ $myModelObject ]; +$data = $transformer->process($objectsInArray); + +// Transforming a Laravel Collection of objects +$objectsInCollection = collect([ $myModelObject ]); +$data = $transformer->process($objectsInCollection); +``` + +### Making Models Transformable + +You can also use the `Transformable` trait on your model. + +```php +use Zaltana\Transformers\Transformable; + +class MyModel extends Model { + + use Transformable; + +} +``` + +Then you can transform you objects as follows: +```php +$transformer = new MyModelTransformer(); + +$data = $myModelObject->transform($transformer); +``` +If you only use one transformer on your model, you can define a transformer via the `$transformer` property. + +```php +$myModelObject->transformer = new MyModelTransformer(); + +$data = $myModelObject->transform(); +``` +If you don't define any transformer on your model and call `transform()`, it will dynamically look for a default transformer named `ModelClassNameTransformer` in the same namespace. +If no transformer is found, a TransformerException exception is thrown. +```php +$object = new MyModel(); + +$data = $object->transform(); // Will try to use MyModelTransformer +``` + + +##License + +This library is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT). diff --git a/composer.json b/composer.json index 1b2f35f..0755d43 100644 --- a/composer.json +++ b/composer.json @@ -1,12 +1,16 @@ { - "name": "apiness/laravel-transformers", + "name": "zaltana/transformers", "description": "A presentation layer for transforming data output when building an API.", "type": "Library", "license": "MIT", "authors": [ { - "name": "Apiness", - "email": "info@apiness.ch" + "name": "Nicolas Marfurt", + "email": "nmarfurt@gmail.com" + }, + { + "name": "Nicolas Brosy", + "email": "nicolas.brosy@gmail.com" } ], "require": { @@ -20,12 +24,12 @@ }, "autoload": { "psr-4": { - "Apiness\\Transformers\\": "src/" + "Zaltana\\Transformers\\": "src/" } }, "autoload-dev": { "psr-4" : { - "Apiness\\Transformers\\Tests\\" : "tests/" + "Tests\\" : "tests/" } } } diff --git a/composer.lock b/composer.lock index 9ac58da..6a0e744 100644 --- a/composer.lock +++ b/composer.lock @@ -4,96 +4,9 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "5a5831f2c9a361fb3812abc8b93c66c7", - "content-hash": "a937bc71be91a7862c3ce6233ed3f3c6", + "hash": "cc2466720c18011cd260bf073ee58f07", + "content-hash": "705c64eeb858119304835c7d8bc0f0bf", "packages": [ - { - "name": "classpreloader/classpreloader", - "version": "3.0.0", - "source": { - "type": "git", - "url": "https://github.com/ClassPreloader/ClassPreloader.git", - "reference": "9b10b913c2bdf90c3d2e0d726b454fb7f77c552a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/ClassPreloader/ClassPreloader/zipball/9b10b913c2bdf90c3d2e0d726b454fb7f77c552a", - "reference": "9b10b913c2bdf90c3d2e0d726b454fb7f77c552a", - "shasum": "" - }, - "require": { - "nikic/php-parser": "^1.0|^2.0", - "php": ">=5.5.9" - }, - "require-dev": { - "phpunit/phpunit": "^4.8|^5.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "autoload": { - "psr-4": { - "ClassPreloader\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com" - }, - { - "name": "Graham Campbell", - "email": "graham@alt-three.com" - } - ], - "description": "Helps class loading performance by generating a single PHP file containing all of the autoloaded files for a specific use case", - "keywords": [ - "autoload", - "class", - "preload" - ], - "time": "2015-11-09 22:51:51" - }, - { - "name": "dnoegel/php-xdg-base-dir", - "version": "0.1", - "source": { - "type": "git", - "url": "https://github.com/dnoegel/php-xdg-base-dir.git", - "reference": "265b8593498b997dc2d31e75b89f053b5cc9621a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/dnoegel/php-xdg-base-dir/zipball/265b8593498b997dc2d31e75b89f053b5cc9621a", - "reference": "265b8593498b997dc2d31e75b89f053b5cc9621a", - "shasum": "" - }, - "require": { - "php": ">=5.3.2" - }, - "require-dev": { - "phpunit/phpunit": "@stable" - }, - "type": "project", - "autoload": { - "psr-4": { - "XdgBaseDir\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "implementation of xdg base directory specification for php", - "time": "2014-10-24 07:27:01" - }, { "name": "doctrine/inflector", "version": "v1.1.0", @@ -162,77 +75,32 @@ "time": "2015-11-06 14:35:42" }, { - "name": "jakub-onderka/php-console-color", - "version": "0.1", + "name": "illuminate/container", + "version": "v5.2.37", "source": { "type": "git", - "url": "https://github.com/JakubOnderka/PHP-Console-Color.git", - "reference": "e0b393dacf7703fc36a4efc3df1435485197e6c1" + "url": "https://github.com/illuminate/container.git", + "reference": "7ec395833738b9059f829348ddc9a59d0118ac88" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/JakubOnderka/PHP-Console-Color/zipball/e0b393dacf7703fc36a4efc3df1435485197e6c1", - "reference": "e0b393dacf7703fc36a4efc3df1435485197e6c1", + "url": "https://api.github.com/repos/illuminate/container/zipball/7ec395833738b9059f829348ddc9a59d0118ac88", + "reference": "7ec395833738b9059f829348ddc9a59d0118ac88", "shasum": "" }, "require": { - "php": ">=5.3.2" - }, - "require-dev": { - "jakub-onderka/php-code-style": "1.0", - "jakub-onderka/php-parallel-lint": "0.*", - "jakub-onderka/php-var-dump-check": "0.*", - "phpunit/phpunit": "3.7.*", - "squizlabs/php_codesniffer": "1.*" + "illuminate/contracts": "5.2.*", + "php": ">=5.5.9" }, "type": "library", - "autoload": { - "psr-0": { - "JakubOnderka\\PhpConsoleColor": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-2-Clause" - ], - "authors": [ - { - "name": "Jakub Onderka", - "email": "jakub.onderka@gmail.com", - "homepage": "http://www.acci.cz" + "extra": { + "branch-alias": { + "dev-master": "5.2-dev" } - ], - "time": "2014-04-08 15:00:19" - }, - { - "name": "jakub-onderka/php-console-highlighter", - "version": "v0.3.2", - "source": { - "type": "git", - "url": "https://github.com/JakubOnderka/PHP-Console-Highlighter.git", - "reference": "7daa75df45242c8d5b75a22c00a201e7954e4fb5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/JakubOnderka/PHP-Console-Highlighter/zipball/7daa75df45242c8d5b75a22c00a201e7954e4fb5", - "reference": "7daa75df45242c8d5b75a22c00a201e7954e4fb5", - "shasum": "" - }, - "require": { - "jakub-onderka/php-console-color": "~0.1", - "php": ">=5.3.0" }, - "require-dev": { - "jakub-onderka/php-code-style": "~1.0", - "jakub-onderka/php-parallel-lint": "~0.5", - "jakub-onderka/php-var-dump-check": "~0.1", - "phpunit/phpunit": "~4.0", - "squizlabs/php_codesniffer": "~1.5" - }, - "type": "library", "autoload": { - "psr-0": { - "JakubOnderka\\PhpConsoleHighlighter": "src/" + "psr-4": { + "Illuminate\\Container\\": "" } }, "notification-url": "https://packagist.org/downloads/", @@ -241,44 +109,40 @@ ], "authors": [ { - "name": "Jakub Onderka", - "email": "acci@acci.cz", - "homepage": "http://www.acci.cz/" + "name": "Taylor Otwell", + "email": "taylorotwell@gmail.com" } ], - "time": "2015-04-20 18:58:01" + "description": "The Illuminate Container package.", + "homepage": "http://laravel.com", + "time": "2016-05-29 02:18:23" }, { - "name": "jeremeamia/SuperClosure", - "version": "2.2.0", + "name": "illuminate/contracts", + "version": "v5.2.37", "source": { "type": "git", - "url": "https://github.com/jeremeamia/super_closure.git", - "reference": "29a88be2a4846d27c1613aed0c9071dfad7b5938" + "url": "https://github.com/illuminate/contracts.git", + "reference": "f4f44d7c6d20404da8dfc655bd3d6dd788dfdce5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/jeremeamia/super_closure/zipball/29a88be2a4846d27c1613aed0c9071dfad7b5938", - "reference": "29a88be2a4846d27c1613aed0c9071dfad7b5938", + "url": "https://api.github.com/repos/illuminate/contracts/zipball/f4f44d7c6d20404da8dfc655bd3d6dd788dfdce5", + "reference": "f4f44d7c6d20404da8dfc655bd3d6dd788dfdce5", "shasum": "" }, "require": { - "nikic/php-parser": "^1.2|^2.0", - "php": ">=5.4", - "symfony/polyfill-php56": "^1.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.0|^5.0" + "php": ">=5.5.9" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.2-dev" + "dev-master": "5.2-dev" } }, "autoload": { "psr-4": { - "SuperClosure\\": "src/" + "Illuminate\\Contracts\\": "" } }, "notification-url": "https://packagist.org/downloads/", @@ -287,118 +151,42 @@ ], "authors": [ { - "name": "Jeremy Lindblom", - "email": "jeremeamia@gmail.com", - "homepage": "https://github.com/jeremeamia", - "role": "Developer" + "name": "Taylor Otwell", + "email": "taylorotwell@gmail.com" } ], - "description": "Serialize Closure objects, including their context and binding", - "homepage": "https://github.com/jeremeamia/super_closure", - "keywords": [ - "closure", - "function", - "lambda", - "parser", - "serializable", - "serialize", - "tokenizer" - ], - "time": "2015-12-05 17:17:57" + "description": "The Illuminate Contracts package.", + "homepage": "http://laravel.com", + "time": "2016-05-31 21:36:13" }, { - "name": "laravel/framework", - "version": "v5.2.40", + "name": "illuminate/database", + "version": "v5.2.37", "source": { "type": "git", - "url": "https://github.com/laravel/framework.git", - "reference": "6195211140ed0881e89d79a296f893abc56987be" + "url": "https://github.com/illuminate/database.git", + "reference": "c0746930dc6a6ff9b72945152609d61a3b3829c6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/6195211140ed0881e89d79a296f893abc56987be", - "reference": "6195211140ed0881e89d79a296f893abc56987be", + "url": "https://api.github.com/repos/illuminate/database/zipball/c0746930dc6a6ff9b72945152609d61a3b3829c6", + "reference": "c0746930dc6a6ff9b72945152609d61a3b3829c6", "shasum": "" }, "require": { - "classpreloader/classpreloader": "~3.0", - "doctrine/inflector": "~1.0", - "ext-mbstring": "*", - "ext-openssl": "*", - "jeremeamia/superclosure": "~2.2", - "league/flysystem": "~1.0", - "monolog/monolog": "~1.11", - "mtdowling/cron-expression": "~1.0", + "illuminate/container": "5.2.*", + "illuminate/contracts": "5.2.*", + "illuminate/support": "5.2.*", "nesbot/carbon": "~1.20", - "paragonie/random_compat": "~1.4", - "php": ">=5.5.9", - "psy/psysh": "0.7.*", - "swiftmailer/swiftmailer": "~5.1", - "symfony/console": "2.8.*|3.0.*", - "symfony/debug": "2.8.*|3.0.*", - "symfony/finder": "2.8.*|3.0.*", - "symfony/http-foundation": "2.8.*|3.0.*", - "symfony/http-kernel": "2.8.*|3.0.*", - "symfony/polyfill-php56": "~1.0", - "symfony/process": "2.8.*|3.0.*", - "symfony/routing": "2.8.*|3.0.*", - "symfony/translation": "2.8.*|3.0.*", - "symfony/var-dumper": "2.8.*|3.0.*", - "vlucas/phpdotenv": "~2.2" - }, - "replace": { - "illuminate/auth": "self.version", - "illuminate/broadcasting": "self.version", - "illuminate/bus": "self.version", - "illuminate/cache": "self.version", - "illuminate/config": "self.version", - "illuminate/console": "self.version", - "illuminate/container": "self.version", - "illuminate/contracts": "self.version", - "illuminate/cookie": "self.version", - "illuminate/database": "self.version", - "illuminate/encryption": "self.version", - "illuminate/events": "self.version", - "illuminate/exception": "self.version", - "illuminate/filesystem": "self.version", - "illuminate/hashing": "self.version", - "illuminate/http": "self.version", - "illuminate/log": "self.version", - "illuminate/mail": "self.version", - "illuminate/pagination": "self.version", - "illuminate/pipeline": "self.version", - "illuminate/queue": "self.version", - "illuminate/redis": "self.version", - "illuminate/routing": "self.version", - "illuminate/session": "self.version", - "illuminate/support": "self.version", - "illuminate/translation": "self.version", - "illuminate/validation": "self.version", - "illuminate/view": "self.version", - "tightenco/collect": "self.version" - }, - "require-dev": { - "aws/aws-sdk-php": "~3.0", - "mockery/mockery": "~0.9.4", - "pda/pheanstalk": "~3.0", - "phpunit/phpunit": "~4.1", - "predis/predis": "~1.0", - "symfony/css-selector": "2.8.*|3.0.*", - "symfony/dom-crawler": "2.8.*|3.0.*" + "php": ">=5.5.9" }, "suggest": { - "aws/aws-sdk-php": "Required to use the SQS queue driver and SES mail driver (~3.0).", "doctrine/dbal": "Required to rename columns and drop SQLite columns (~2.4).", "fzaninotto/faker": "Required to use the eloquent factory builder (~1.4).", - "guzzlehttp/guzzle": "Required to use the Mailgun and Mandrill mail drivers and the ping methods on schedules (~5.3|~6.0).", - "league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (~1.0).", - "league/flysystem-rackspace": "Required to use the Flysystem Rackspace driver (~1.0).", - "pda/pheanstalk": "Required to use the beanstalk queue driver (~3.0).", - "predis/predis": "Required to use the redis cache and queue drivers (~1.0).", - "pusher/pusher-php-server": "Required to use the Pusher broadcast driver (~2.0).", - "symfony/css-selector": "Required to use some of the crawler integration testing tools (2.8.*|3.0.*).", - "symfony/dom-crawler": "Required to use most of the crawler integration testing tools (2.8.*|3.0.*).", - "symfony/psr-http-message-bridge": "Required to psr7 bridging features (0.2.*)." + "illuminate/console": "Required to use the database commands (5.2.*).", + "illuminate/events": "Required to use the observers with Eloquent (5.2.*).", + "illuminate/filesystem": "Required to use the migrations (5.2.*).", + "illuminate/pagination": "Required to paginate the result set (5.2.*)." }, "type": "library", "extra": { @@ -407,15 +195,8 @@ } }, "autoload": { - "classmap": [ - "src/Illuminate/Queue/IlluminateQueueClosure.php" - ], - "files": [ - "src/Illuminate/Foundation/helpers.php", - "src/Illuminate/Support/helpers.php" - ], "psr-4": { - "Illuminate\\": "src/Illuminate/" + "Illuminate\\Database\\": "" } }, "notification-url": "https://packagist.org/downloads/", @@ -428,200 +209,57 @@ "email": "taylorotwell@gmail.com" } ], - "description": "The Laravel Framework.", + "description": "The Illuminate Database package.", "homepage": "http://laravel.com", "keywords": [ - "framework", - "laravel" - ], - "time": "2016-07-19 19:46:25" - }, - { - "name": "league/flysystem", - "version": "1.0.25", - "source": { - "type": "git", - "url": "https://github.com/thephpleague/flysystem.git", - "reference": "a76afa4035931be0c78ca8efc6abf3902362f437" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/a76afa4035931be0c78ca8efc6abf3902362f437", - "reference": "a76afa4035931be0c78ca8efc6abf3902362f437", - "shasum": "" - }, - "require": { - "php": ">=5.4.0" - }, - "conflict": { - "league/flysystem-sftp": "<1.0.6" - }, - "require-dev": { - "ext-fileinfo": "*", - "mockery/mockery": "~0.9", - "phpspec/phpspec": "^2.2", - "phpunit/phpunit": "~4.8" - }, - "suggest": { - "ext-fileinfo": "Required for MimeType", - "league/flysystem-aws-s3-v2": "Allows you to use S3 storage with AWS SDK v2", - "league/flysystem-aws-s3-v3": "Allows you to use S3 storage with AWS SDK v3", - "league/flysystem-azure": "Allows you to use Windows Azure Blob storage", - "league/flysystem-cached-adapter": "Flysystem adapter decorator for metadata caching", - "league/flysystem-copy": "Allows you to use Copy.com storage", - "league/flysystem-dropbox": "Allows you to use Dropbox storage", - "league/flysystem-eventable-filesystem": "Allows you to use EventableFilesystem", - "league/flysystem-rackspace": "Allows you to use Rackspace Cloud Files", - "league/flysystem-sftp": "Allows you to use SFTP server storage via phpseclib", - "league/flysystem-webdav": "Allows you to use WebDAV storage", - "league/flysystem-ziparchive": "Allows you to use ZipArchive adapter" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.1-dev" - } - }, - "autoload": { - "psr-4": { - "League\\Flysystem\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Frank de Jonge", - "email": "info@frenky.net" - } + "database", + "laravel", + "orm", + "sql" ], - "description": "Filesystem abstraction: Many filesystems, one API.", - "keywords": [ - "Cloud Files", - "WebDAV", - "abstraction", - "aws", - "cloud", - "copy.com", - "dropbox", - "file systems", - "files", - "filesystem", - "filesystems", - "ftp", - "rackspace", - "remote", - "s3", - "sftp", - "storage" - ], - "time": "2016-07-18 12:22:57" + "time": "2016-06-06 13:12:46" }, { - "name": "monolog/monolog", - "version": "1.20.0", + "name": "illuminate/support", + "version": "v5.2.37", "source": { "type": "git", - "url": "https://github.com/Seldaek/monolog.git", - "reference": "55841909e2bcde01b5318c35f2b74f8ecc86e037" + "url": "https://github.com/illuminate/support.git", + "reference": "6e86ac2b4e3d0c42c2dc846dbac3e74d378a812b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/55841909e2bcde01b5318c35f2b74f8ecc86e037", - "reference": "55841909e2bcde01b5318c35f2b74f8ecc86e037", + "url": "https://api.github.com/repos/illuminate/support/zipball/6e86ac2b4e3d0c42c2dc846dbac3e74d378a812b", + "reference": "6e86ac2b4e3d0c42c2dc846dbac3e74d378a812b", "shasum": "" }, "require": { - "php": ">=5.3.0", - "psr/log": "~1.0" - }, - "provide": { - "psr/log-implementation": "1.0.0" - }, - "require-dev": { - "aws/aws-sdk-php": "^2.4.9", - "doctrine/couchdb": "~1.0@dev", - "graylog2/gelf-php": "~1.0", - "jakub-onderka/php-parallel-lint": "0.9", - "php-amqplib/php-amqplib": "~2.4", - "php-console/php-console": "^3.1.3", - "phpunit/phpunit": "~4.5", - "phpunit/phpunit-mock-objects": "2.3.0", - "ruflin/elastica": ">=0.90 <3.0", - "sentry/sentry": "^0.13", - "swiftmailer/swiftmailer": "~5.3" + "doctrine/inflector": "~1.0", + "ext-mbstring": "*", + "illuminate/contracts": "5.2.*", + "paragonie/random_compat": "~1.4", + "php": ">=5.5.9" }, "suggest": { - "aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB", - "doctrine/couchdb": "Allow sending log messages to a CouchDB server", - "ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)", - "ext-mongo": "Allow sending log messages to a MongoDB server", - "graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server", - "mongodb/mongodb": "Allow sending log messages to a MongoDB server via PHP Driver", - "php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib", - "php-console/php-console": "Allow sending log messages to Google Chrome", - "rollbar/rollbar": "Allow sending log messages to Rollbar", - "ruflin/elastica": "Allow sending log messages to an Elastic Search server", - "sentry/sentry": "Allow sending log messages to a Sentry server" + "illuminate/filesystem": "Required to use the composer class (5.2.*).", + "jeremeamia/superclosure": "Required to be able to serialize closures (~2.2).", + "symfony/polyfill-php56": "Required to use the hash_equals function on PHP 5.5 (~1.0).", + "symfony/process": "Required to use the composer class (2.8.*|3.0.*).", + "symfony/var-dumper": "Improves the dd function (2.8.*|3.0.*)." }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "5.2-dev" } }, "autoload": { "psr-4": { - "Monolog\\": "src/Monolog" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jordi Boggiano", - "email": "j.boggiano@seld.be", - "homepage": "http://seld.be" - } - ], - "description": "Sends your logs to files, sockets, inboxes, databases and various web services", - "homepage": "http://github.com/Seldaek/monolog", - "keywords": [ - "log", - "logging", - "psr-3" - ], - "time": "2016-07-02 14:02:10" - }, - { - "name": "mtdowling/cron-expression", - "version": "v1.1.0", - "source": { - "type": "git", - "url": "https://github.com/mtdowling/cron-expression.git", - "reference": "c9ee7886f5a12902b225a1a12f36bb45f9ab89e5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/mtdowling/cron-expression/zipball/c9ee7886f5a12902b225a1a12f36bb45f9ab89e5", - "reference": "c9ee7886f5a12902b225a1a12f36bb45f9ab89e5", - "shasum": "" - }, - "require": { - "php": ">=5.3.2" - }, - "require-dev": { - "phpunit/phpunit": "~4.0|~5.0" - }, - "type": "library", - "autoload": { - "psr-0": { - "Cron": "src/" - } + "Illuminate\\Support\\": "" + }, + "files": [ + "helpers.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -629,17 +267,13 @@ ], "authors": [ { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" + "name": "Taylor Otwell", + "email": "taylorotwell@gmail.com" } ], - "description": "CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due", - "keywords": [ - "cron", - "schedule" - ], - "time": "2016-01-26 21:23:30" + "description": "The Illuminate Support package.", + "homepage": "http://laravel.com", + "time": "2016-05-30 02:40:53" }, { "name": "nesbot/carbon", @@ -688,57 +322,6 @@ ], "time": "2015-11-04 20:07:17" }, - { - "name": "nikic/php-parser", - "version": "v2.1.0", - "source": { - "type": "git", - "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "47b254ea51f1d6d5dc04b9b299e88346bf2369e3" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/47b254ea51f1d6d5dc04b9b299e88346bf2369e3", - "reference": "47b254ea51f1d6d5dc04b9b299e88346bf2369e3", - "shasum": "" - }, - "require": { - "ext-tokenizer": "*", - "php": ">=5.4" - }, - "require-dev": { - "phpunit/phpunit": "~4.0" - }, - "bin": [ - "bin/php-parse" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - }, - "autoload": { - "psr-4": { - "PhpParser\\": "lib/PhpParser" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Nikita Popov" - } - ], - "description": "A PHP parser written in PHP", - "keywords": [ - "parser", - "php" - ], - "time": "2016-04-19 13:41:41" - }, { "name": "paragonie/random_compat", "version": "v1.4.1", @@ -788,605 +371,24 @@ "time": "2016-03-18 20:34:03" }, { - "name": "psr/log", - "version": "1.0.0", + "name": "symfony/polyfill-mbstring", + "version": "v1.2.0", "source": { "type": "git", - "url": "https://github.com/php-fig/log.git", - "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b" + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "dff51f72b0706335131b00a7f49606168c582594" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b", - "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/dff51f72b0706335131b00a7f49606168c582594", + "reference": "dff51f72b0706335131b00a7f49606168c582594", "shasum": "" }, - "type": "library", - "autoload": { - "psr-0": { - "Psr\\Log\\": "" - } + "require": { + "php": ">=5.3.3" }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for logging libraries", - "keywords": [ - "log", - "psr", - "psr-3" - ], - "time": "2012-12-21 11:40:51" - }, - { - "name": "psy/psysh", - "version": "v0.7.2", - "source": { - "type": "git", - "url": "https://github.com/bobthecow/psysh.git", - "reference": "e64e10b20f8d229cac76399e1f3edddb57a0f280" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/bobthecow/psysh/zipball/e64e10b20f8d229cac76399e1f3edddb57a0f280", - "reference": "e64e10b20f8d229cac76399e1f3edddb57a0f280", - "shasum": "" - }, - "require": { - "dnoegel/php-xdg-base-dir": "0.1", - "jakub-onderka/php-console-highlighter": "0.3.*", - "nikic/php-parser": "^1.2.1|~2.0", - "php": ">=5.3.9", - "symfony/console": "~2.3.10|^2.4.2|~3.0", - "symfony/var-dumper": "~2.7|~3.0" - }, - "require-dev": { - "fabpot/php-cs-fixer": "~1.5", - "phpunit/phpunit": "~3.7|~4.0|~5.0", - "squizlabs/php_codesniffer": "~2.0", - "symfony/finder": "~2.1|~3.0" - }, - "suggest": { - "ext-pcntl": "Enabling the PCNTL extension makes PsySH a lot happier :)", - "ext-pdo-sqlite": "The doc command requires SQLite to work.", - "ext-posix": "If you have PCNTL, you'll want the POSIX extension as well.", - "ext-readline": "Enables support for arrow-key history navigation, and showing and manipulating command history." - }, - "bin": [ - "bin/psysh" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-develop": "0.8.x-dev" - } - }, - "autoload": { - "files": [ - "src/Psy/functions.php" - ], - "psr-4": { - "Psy\\": "src/Psy/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Justin Hileman", - "email": "justin@justinhileman.info", - "homepage": "http://justinhileman.com" - } - ], - "description": "An interactive shell for modern PHP.", - "homepage": "http://psysh.org", - "keywords": [ - "REPL", - "console", - "interactive", - "shell" - ], - "time": "2016-03-09 05:03:14" - }, - { - "name": "swiftmailer/swiftmailer", - "version": "v5.4.3", - "source": { - "type": "git", - "url": "https://github.com/swiftmailer/swiftmailer.git", - "reference": "4cc92842069c2bbc1f28daaaf1d2576ec4dfe153" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/4cc92842069c2bbc1f28daaaf1d2576ec4dfe153", - "reference": "4cc92842069c2bbc1f28daaaf1d2576ec4dfe153", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "mockery/mockery": "~0.9.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "5.4-dev" - } - }, - "autoload": { - "files": [ - "lib/swift_required.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Chris Corbyn" - }, - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - } - ], - "description": "Swiftmailer, free feature-rich PHP mailer", - "homepage": "http://swiftmailer.org", - "keywords": [ - "email", - "mail", - "mailer" - ], - "time": "2016-07-08 11:51:25" - }, - { - "name": "symfony/console", - "version": "v3.0.8", - "source": { - "type": "git", - "url": "https://github.com/symfony/console.git", - "reference": "a7abb7153f6d1da47f87ec50274844e246b09d9f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/a7abb7153f6d1da47f87ec50274844e246b09d9f", - "reference": "a7abb7153f6d1da47f87ec50274844e246b09d9f", - "shasum": "" - }, - "require": { - "php": ">=5.5.9", - "symfony/polyfill-mbstring": "~1.0" - }, - "require-dev": { - "psr/log": "~1.0", - "symfony/event-dispatcher": "~2.8|~3.0", - "symfony/process": "~2.8|~3.0" - }, - "suggest": { - "psr/log": "For using the console logger", - "symfony/event-dispatcher": "", - "symfony/process": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Console\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Console Component", - "homepage": "https://symfony.com", - "time": "2016-06-29 07:02:21" - }, - { - "name": "symfony/debug", - "version": "v3.0.8", - "source": { - "type": "git", - "url": "https://github.com/symfony/debug.git", - "reference": "c54bc3539c3b87e86799533801e8ae0e971d78c2" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/debug/zipball/c54bc3539c3b87e86799533801e8ae0e971d78c2", - "reference": "c54bc3539c3b87e86799533801e8ae0e971d78c2", - "shasum": "" - }, - "require": { - "php": ">=5.5.9", - "psr/log": "~1.0" - }, - "conflict": { - "symfony/http-kernel": ">=2.3,<2.3.24|~2.4.0|>=2.5,<2.5.9|>=2.6,<2.6.2" - }, - "require-dev": { - "symfony/class-loader": "~2.8|~3.0", - "symfony/http-kernel": "~2.8|~3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Debug\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Debug Component", - "homepage": "https://symfony.com", - "time": "2016-06-29 05:40:00" - }, - { - "name": "symfony/event-dispatcher", - "version": "v3.1.2", - "source": { - "type": "git", - "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "7f9839ede2070f53e7e2f0849b9bd14748c434c5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/7f9839ede2070f53e7e2f0849b9bd14748c434c5", - "reference": "7f9839ede2070f53e7e2f0849b9bd14748c434c5", - "shasum": "" - }, - "require": { - "php": ">=5.5.9" - }, - "require-dev": { - "psr/log": "~1.0", - "symfony/config": "~2.8|~3.0", - "symfony/dependency-injection": "~2.8|~3.0", - "symfony/expression-language": "~2.8|~3.0", - "symfony/stopwatch": "~2.8|~3.0" - }, - "suggest": { - "symfony/dependency-injection": "", - "symfony/http-kernel": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.1-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\EventDispatcher\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony EventDispatcher Component", - "homepage": "https://symfony.com", - "time": "2016-06-29 05:41:56" - }, - { - "name": "symfony/finder", - "version": "v3.0.8", - "source": { - "type": "git", - "url": "https://github.com/symfony/finder.git", - "reference": "3eb4e64c6145ef8b92adefb618a74ebdde9e3fe9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/3eb4e64c6145ef8b92adefb618a74ebdde9e3fe9", - "reference": "3eb4e64c6145ef8b92adefb618a74ebdde9e3fe9", - "shasum": "" - }, - "require": { - "php": ">=5.5.9" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Finder\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Finder Component", - "homepage": "https://symfony.com", - "time": "2016-06-29 05:40:00" - }, - { - "name": "symfony/http-foundation", - "version": "v3.0.8", - "source": { - "type": "git", - "url": "https://github.com/symfony/http-foundation.git", - "reference": "1341139f906d295baa4f4abd55293d07e25a065a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/http-foundation/zipball/1341139f906d295baa4f4abd55293d07e25a065a", - "reference": "1341139f906d295baa4f4abd55293d07e25a065a", - "shasum": "" - }, - "require": { - "php": ">=5.5.9", - "symfony/polyfill-mbstring": "~1.1" - }, - "require-dev": { - "symfony/expression-language": "~2.8|~3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\HttpFoundation\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony HttpFoundation Component", - "homepage": "https://symfony.com", - "time": "2016-06-29 07:02:21" - }, - { - "name": "symfony/http-kernel", - "version": "v3.0.8", - "source": { - "type": "git", - "url": "https://github.com/symfony/http-kernel.git", - "reference": "177b63b2d50b63fa6d82ea41359ed9928cc7a1fb" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/http-kernel/zipball/177b63b2d50b63fa6d82ea41359ed9928cc7a1fb", - "reference": "177b63b2d50b63fa6d82ea41359ed9928cc7a1fb", - "shasum": "" - }, - "require": { - "php": ">=5.5.9", - "psr/log": "~1.0", - "symfony/debug": "~2.8|~3.0", - "symfony/event-dispatcher": "~2.8|~3.0", - "symfony/http-foundation": "~2.8.8|~3.0.8|~3.1.2|~3.2" - }, - "conflict": { - "symfony/config": "<2.8" - }, - "require-dev": { - "symfony/browser-kit": "~2.8|~3.0", - "symfony/class-loader": "~2.8|~3.0", - "symfony/config": "~2.8|~3.0", - "symfony/console": "~2.8|~3.0", - "symfony/css-selector": "~2.8|~3.0", - "symfony/dependency-injection": "~2.8|~3.0", - "symfony/dom-crawler": "~2.8|~3.0", - "symfony/expression-language": "~2.8|~3.0", - "symfony/finder": "~2.8|~3.0", - "symfony/process": "~2.8|~3.0", - "symfony/routing": "~2.8|~3.0", - "symfony/stopwatch": "~2.8|~3.0", - "symfony/templating": "~2.8|~3.0", - "symfony/translation": "~2.8|~3.0", - "symfony/var-dumper": "~2.8|~3.0" - }, - "suggest": { - "symfony/browser-kit": "", - "symfony/class-loader": "", - "symfony/config": "", - "symfony/console": "", - "symfony/dependency-injection": "", - "symfony/finder": "", - "symfony/var-dumper": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\HttpKernel\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony HttpKernel Component", - "homepage": "https://symfony.com", - "time": "2016-06-30 16:30:17" - }, - { - "name": "symfony/polyfill-mbstring", - "version": "v1.2.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "dff51f72b0706335131b00a7f49606168c582594" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/dff51f72b0706335131b00a7f49606168c582594", - "reference": "dff51f72b0706335131b00a7f49606168c582594", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "suggest": { - "ext-mbstring": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Mbstring\\": "" - }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for the Mbstring extension", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "mbstring", - "polyfill", - "portable", - "shim" - ], - "time": "2016-05-18 14:26:46" - }, - { - "name": "symfony/polyfill-php56", - "version": "v1.2.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php56.git", - "reference": "3edf57a8fbf9a927533344cef65ad7e1cf31030a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php56/zipball/3edf57a8fbf9a927533344cef65ad7e1cf31030a", - "reference": "3edf57a8fbf9a927533344cef65ad7e1cf31030a", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "symfony/polyfill-util": "~1.0" + "suggest": { + "ext-mbstring": "For best performance" }, "type": "library", "extra": { @@ -1396,7 +398,7 @@ }, "autoload": { "psr-4": { - "Symfony\\Polyfill\\Php56\\": "" + "Symfony\\Polyfill\\Mbstring\\": "" }, "files": [ "bootstrap.php" @@ -1416,204 +418,29 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions", + "description": "Symfony polyfill for the Mbstring extension", "homepage": "https://symfony.com", "keywords": [ "compatibility", + "mbstring", "polyfill", "portable", "shim" ], "time": "2016-05-18 14:26:46" }, - { - "name": "symfony/polyfill-util", - "version": "v1.2.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-util.git", - "reference": "ef830ce3d218e622b221d6bfad42c751d974bf99" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-util/zipball/ef830ce3d218e622b221d6bfad42c751d974bf99", - "reference": "ef830ce3d218e622b221d6bfad42c751d974bf99", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Util\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony utilities for portability of PHP codes", - "homepage": "https://symfony.com", - "keywords": [ - "compat", - "compatibility", - "polyfill", - "shim" - ], - "time": "2016-05-18 14:26:46" - }, - { - "name": "symfony/process", - "version": "v3.0.8", - "source": { - "type": "git", - "url": "https://github.com/symfony/process.git", - "reference": "d7cde1f9d94d87060204f863779389b61c382eeb" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/d7cde1f9d94d87060204f863779389b61c382eeb", - "reference": "d7cde1f9d94d87060204f863779389b61c382eeb", - "shasum": "" - }, - "require": { - "php": ">=5.5.9" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Process\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Process Component", - "homepage": "https://symfony.com", - "time": "2016-06-29 05:40:00" - }, - { - "name": "symfony/routing", - "version": "v3.0.8", - "source": { - "type": "git", - "url": "https://github.com/symfony/routing.git", - "reference": "9038984bd9c05ab07280121e9e10f61a7231457b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/routing/zipball/9038984bd9c05ab07280121e9e10f61a7231457b", - "reference": "9038984bd9c05ab07280121e9e10f61a7231457b", - "shasum": "" - }, - "require": { - "php": ">=5.5.9" - }, - "conflict": { - "symfony/config": "<2.8" - }, - "require-dev": { - "doctrine/annotations": "~1.0", - "doctrine/common": "~2.2", - "psr/log": "~1.0", - "symfony/config": "~2.8|~3.0", - "symfony/expression-language": "~2.8|~3.0", - "symfony/http-foundation": "~2.8|~3.0", - "symfony/yaml": "~2.8|~3.0" - }, - "suggest": { - "doctrine/annotations": "For using the annotation loader", - "symfony/config": "For using the all-in-one router or any loader", - "symfony/dependency-injection": "For loading routes from a service", - "symfony/expression-language": "For using expression matching", - "symfony/http-foundation": "For using a Symfony Request object", - "symfony/yaml": "For using the YAML loader" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Routing\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Routing Component", - "homepage": "https://symfony.com", - "keywords": [ - "router", - "routing", - "uri", - "url" - ], - "time": "2016-06-29 05:40:00" - }, { "name": "symfony/translation", - "version": "v3.0.8", + "version": "v3.1.2", "source": { "type": "git", "url": "https://github.com/symfony/translation.git", - "reference": "6bf844e1ee3c820c012386c10427a5c67bbefec8" + "reference": "d63a94528530c3ea5ff46924c8001cec4a398609" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation/zipball/6bf844e1ee3c820c012386c10427a5c67bbefec8", - "reference": "6bf844e1ee3c820c012386c10427a5c67bbefec8", + "url": "https://api.github.com/repos/symfony/translation/zipball/d63a94528530c3ea5ff46924c8001cec4a398609", + "reference": "d63a94528530c3ea5ff46924c8001cec4a398609", "shasum": "" }, "require": { @@ -1637,7 +464,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "3.1-dev" } }, "autoload": { @@ -1664,120 +491,7 @@ ], "description": "Symfony Translation Component", "homepage": "https://symfony.com", - "time": "2016-06-29 05:40:00" - }, - { - "name": "symfony/var-dumper", - "version": "v3.0.8", - "source": { - "type": "git", - "url": "https://github.com/symfony/var-dumper.git", - "reference": "2f046e9a9d571f22cc8b26783564876713b06579" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/2f046e9a9d571f22cc8b26783564876713b06579", - "reference": "2f046e9a9d571f22cc8b26783564876713b06579", - "shasum": "" - }, - "require": { - "php": ">=5.5.9", - "symfony/polyfill-mbstring": "~1.0" - }, - "require-dev": { - "twig/twig": "~1.20|~2.0" - }, - "suggest": { - "ext-symfony_debug": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "autoload": { - "files": [ - "Resources/functions/dump.php" - ], - "psr-4": { - "Symfony\\Component\\VarDumper\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony mechanism for exploring and dumping PHP variables", - "homepage": "https://symfony.com", - "keywords": [ - "debug", - "dump" - ], - "time": "2016-06-29 05:40:00" - }, - { - "name": "vlucas/phpdotenv", - "version": "v2.3.0", - "source": { - "type": "git", - "url": "https://github.com/vlucas/phpdotenv.git", - "reference": "9ca5644c536654e9509b9d257f53c58630eb2a6a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/9ca5644c536654e9509b9d257f53c58630eb2a6a", - "reference": "9ca5644c536654e9509b9d257f53c58630eb2a6a", - "shasum": "" - }, - "require": { - "php": ">=5.3.9" - }, - "require-dev": { - "phpunit/phpunit": "^4.8 || ^5.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.3-dev" - } - }, - "autoload": { - "psr-4": { - "Dotenv\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause-Attribution" - ], - "authors": [ - { - "name": "Vance Lucas", - "email": "vance@vancelucas.com", - "homepage": "http://www.vancelucas.com" - } - ], - "description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.", - "keywords": [ - "dotenv", - "env", - "environment" - ], - "time": "2016-06-14 14:14:52" + "time": "2016-06-29 05:41:56" } ], "packages-dev": [ @@ -2441,16 +1155,16 @@ }, { "name": "phpunit/phpunit", - "version": "5.4.6", + "version": "5.4.7", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "2f1fc94b77ea6418bd6a06c64a1dac0645fbce59" + "reference": "6c8a756c17a1a92a066c99860eb57922e8b723da" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/2f1fc94b77ea6418bd6a06c64a1dac0645fbce59", - "reference": "2f1fc94b77ea6418bd6a06c64a1dac0645fbce59", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/6c8a756c17a1a92a066c99860eb57922e8b723da", + "reference": "6c8a756c17a1a92a066c99860eb57922e8b723da", "shasum": "" }, "require": { @@ -2515,7 +1229,7 @@ "testing", "xunit" ], - "time": "2016-06-16 06:01:15" + "time": "2016-07-21 06:55:27" }, { "name": "phpunit/phpunit-mock-objects", @@ -3194,7 +1908,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">= 5.5.9" + "php": ">= 5.6" }, "platform-dev": [] } diff --git a/src/Transformable.php b/src/Transformable.php new file mode 100644 index 0000000..31b805f --- /dev/null +++ b/src/Transformable.php @@ -0,0 +1,46 @@ +getDefaultTransformer(); + } + + return $transformer->process($this); + } + + public function getDefaultTransformer() + { + $transformer = null; + + if (isset($this->transformer)) { + $transformer = $this->transformer; + } + else { + $class = $this->transformerClass(); + + if(!class_exists($class)) { + throw new TransformerException('Unknown transformer class! You have to set a default transformer class to the $transformer property, or create a ' . $this->transformerClass() . ' class.'); + } + + $transformer = new $class(); + } + + if (! $transformer instanceof Transformer) { + throw new TransformerException('Default transformer should be an instance of Transformer class, instead of '.get_class($transformer).'.'); + } + + return $transformer; + } + + public function transformerClass() + { + return static::class.'Transformer'; + } + +} diff --git a/src/Transformer.php b/src/Transformer.php index 3ff086c..cbdacf0 100644 --- a/src/Transformer.php +++ b/src/Transformer.php @@ -1,69 +1,96 @@ -nestedTransformers = $transformers; } - public function process($data) + /** + * Initialize and return a new Tranformer object with nested transformers used to transform relationships. + * + * @param array $transformers Nested transformers used to transform relationships. + * + * @return static A newly initialized transformer object with the given nested transformers. + */ + public static function with(array $transformers = []) { - if (!$data instanceof Collection && !$data instanceof Model) { - throw new TypeErrorException('$data must be a collection or a model'); - } + return new static($transformers); + } - $result = []; + /** + * @param mixed $data The data to be transformed. + * + * @return array The transformed data. + */ + public function process($data) + { + // If the data is a collection of items, we need to transform each item + // Otherwise, we transform the object directly - if ($data instanceof Collection) { - $data->each(function($model) use(&$result) { - $result[] = $this->transform($model); - }); - } - else if ($data instanceof Model) { - $result = array_merge($result, $this->transform($data)); + if (($collection = $this->normalizeToCollection($data)) instanceof Collection) { + return $collection->map(function($model) { + return $this->performTransformation($model); + })->all(); } - return $result; + return $this->performTransformation($data); } - public function perform($data) + protected function normalizeToCollection($data) { - return $this->process($data); + if (is_array($data)) { + return new Collection($data); + } + else if ($data instanceof Paginator) { + return new Collection($data->items()); + } + + return $data; } - private function transform(Model $model) + protected function performTransformation($model) { - $result = []; - - $flatModel = $this->transformModel($model); - $result = array_merge($result, $flatModel); + $result = $this->transform($model); if (!empty($this->nestedTransformers)) { - $relations = $this->transformRelations($model); - $result = array_merge($result, $relations); + $result = array_merge($result, $this->transformRelations($model)); } return $result; } - protected abstract function transformModel(Model $model); + protected abstract function transform($model); - protected function transformRelations(Model $model) + protected function transformRelations($model) { - $relations = $model->getRelations(); + if (!$model instanceof Model) { + throw new InvalidArgumentException("Nested transformations can only be applied on ".Model::class." subclasses, not on ".get_class($model)."!"); + } $result = []; - foreach ($this->nestedTransformers as $key => $transformer) { - if (array_key_exists($key, $relations)) { - $data = $transformer->process($relations[$key]); - $result[$key] = $data; + $relations = $model->getRelations(); + + foreach ($this->nestedTransformers as $relation => $transformer) { + if (array_key_exists($relation, $relations)) { + $result[ $relation ] = $transformer->process($relations[ $relation ]); } } diff --git a/src/TransformerException.php b/src/TransformerException.php new file mode 100644 index 0000000..f01c24a --- /dev/null +++ b/src/TransformerException.php @@ -0,0 +1,3 @@ + $model->title, @@ -14,3 +13,5 @@ protected function transformModel(Model $model) } } + +class ModelStubTransformer extends ModelTransformer {} diff --git a/tests/Stubs/NestedModelStub.php b/tests/Stubs/NestedModelStub.php index c874b3a..8f4715d 100644 --- a/tests/Stubs/NestedModelStub.php +++ b/tests/Stubs/NestedModelStub.php @@ -1,9 +1,12 @@ - $model->history diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..2aa4cd3 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,38 @@ + 'my_name', 'title' => 'my_title', 'is_active' => true, 'date' => Carbon::now()]); + $nestedModel = new NestedModelStub([ 'history' => 'my_history', 'date' => Carbon::now() ]); + + $mockedModel = Mockery::mock($model); + $mockedModel->shouldReceive('getRelations')->once()->andReturn([ + 'nested_model' => $nestedModel + ]); + + $otherModel = new ModelStub(['name' => 'your_name', 'title' => 'your_title', 'is_active' => true, 'date' => Carbon::now()]); + $otherNestedModel = new NestedModelStub([ 'history' => 'your_history', 'date' => Carbon::now() ]); + + $otherMockedModel = Mockery::mock($otherModel); + $otherMockedModel->shouldReceive('getRelations')->once()->andReturn([ + 'nested_model' => $otherNestedModel + ]); + + $this->models = new Collection([ $mockedModel, $otherMockedModel ]); + } + +} diff --git a/tests/TransformableTest.php b/tests/TransformableTest.php new file mode 100644 index 0000000..aa6da72 --- /dev/null +++ b/tests/TransformableTest.php @@ -0,0 +1,47 @@ +models->first(); + + $result = $model->transform(new ModelTransformer()); + + $this->assertCount(2, $result); + $this->assertTrue($result[ 'is_active' ]); + $this->assertEquals($model->title, $result[ 'title' ]); + } + + /** @test */ + public function it_transforms_a_tranformable_model_using_property_transformer() + { + $model = $this->models->first(); + + $model->transformer = new ModelTransformer(); + + $result = $model->transform(/* No provided transformer, use property one */); + + $this->assertCount(2, $result); + $this->assertTrue($result[ 'is_active' ]); + $this->assertEquals($model->title, $result[ 'title' ]); + } + + /** @test */ + public function it_transforms_a_tranformable_model_using_default_transformer() + { + $model = $this->models->first(); + + $result = $model->transform(/* No provided transformer, use default one */); + + $this->assertCount(2, $result); + $this->assertTrue($result[ 'is_active' ]); + $this->assertEquals($model->title, $result[ 'title' ]); + } +} diff --git a/tests/TransformerTest.php b/tests/TransformerTest.php index 68aca24..496d038 100644 --- a/tests/TransformerTest.php +++ b/tests/TransformerTest.php @@ -1,73 +1,51 @@ - 'my_name', 'title' => 'my_title', 'is_active' => true, 'my_date' => Carbon::now()]); - $modelSecond = new ModelStub(['name' => 'your_name', 'title' => 'your_title', 'is_active' => true, 'your_date' => Carbon::now()]); - - $this->nestedModel = new NestedModelStub([ 'history' => 'my_history', 'date' => Carbon::now() ]); - $nestedModelSecond = new NestedModelStub([ 'history' => 'your_history', 'date' => Carbon::now() ]); - - $this->mockedModel = Mockery::mock($model); - $this->mockedModel->shouldReceive('getRelations')->once()->andReturn([ - 'nested_model' => $this->nestedModel, - ]); - - $nestedMockedModelSecond = Mockery::mock($modelSecond); - $nestedMockedModelSecond->shouldReceive('getRelations')->once()->andReturn([ - 'nested_model' => $nestedModelSecond, - ]); - - $this->collections = new Collection([ $this->mockedModel, $nestedMockedModelSecond ]); - - } +class TransformerTest extends TestCase { /** @test */ public function it_performs_a_transformation_without_nested_transformers() { + $model = $this->models->first(); $transformer = new ModelTransformer(); - $result = $transformer->process($this->mockedModel); + + $result = $transformer->process($model); $this->assertCount(2, $result); - $this->assertTrue($result['is_active']); - $this->assertEquals('my_title', $result['title']); + $this->assertTrue($result[ 'is_active' ]); + $this->assertEquals($model->title, $result[ 'title' ]); } /** @test */ - public function it_performs_a_transformation_with_nesteds_transformers() + public function it_performs_a_transformation_with_nested_transformers() { - $transformer = new ModelTransformer( - [ - 'nested_model' => new NestedModelTransformer() - ] - ); - - $result = $transformer->process($this->mockedModel); + $model = $this->models->first(); + $transformer = new ModelTransformer([ + 'nested_model' => new NestedModelTransformer() + ]); + $result = $transformer->process($model); $this->assertCount(3, $result); - $this->assertTrue($result['is_active']); - $this->assertEquals('my_title', $result['title']); + $this->assertTrue($result[ 'is_active' ]); + $this->assertEquals($model->title, $result[ 'title' ]); $this->assertTrue(array_key_exists('nested_model', $result)); + $this->assertTrue(array_key_exists('history', $result[ 'nested_model' ])); + } - $this->assertTrue(array_key_exists('history', $result['nested_model'])); + /** @test */ + public function it_creates_a_transformer_with_nested_transformers() + { + $model = $this->models->first(); + + $transformer1 = new ModelTransformer([ 'nested_model' => new NestedModelTransformer() ]); + $transformer2 = ModelTransformer::with([ 'nested_model' => new NestedModelTransformer() ]); + + $this->assertEquals($transformer1->process($model), $transformer2->process($model)); } /** @test */ @@ -75,65 +53,54 @@ public function it_transforms_a_collection_without_nested_transformers() { $transformer = new ModelTransformer(); - $result = $transformer->process($this->collections); + $result = $transformer->process($this->models); $this->assertCount(2, $result); - $result1 = $result[0]; - $this->assertCount(2, $result1); + $this->assertCount(2, $result[0]); + $this->assertTrue($result[0][ 'is_active' ]); + $this->assertEquals('my_title', $result[0][ 'title' ]); - $this->assertTrue($result1['is_active']); - $this->assertEquals('my_title', $result1['title']); - - $result2 = $result[1]; - $this->assertCount(2, $result2); - - $this->assertTrue($result2['is_active']); - $this->assertEquals('your_title', $result2['title']); + $this->assertCount(2, $result[1]); + $this->assertTrue($result[1][ 'is_active' ]); + $this->assertEquals('your_title', $result[1][ 'title' ]); } /** @test */ - public function it_transforms_collection_with_nested_transformers() + public function it_transforms_a_collection_with_nested_transformers() { - $transformer = new ModelTransformer( - [ - 'nested_model' => new NestedModelTransformer() - ] - ); + $transformer = new ModelTransformer([ + 'nested_model' => new NestedModelTransformer() + ]); - $result = $transformer->process($this->collections); + $result = $transformer->process($this->models); $this->assertCount(2, $result); - $result1 = $result[0]; - $this->assertCount(3, $result1); - - $this->assertTrue($result1['is_active']); - $this->assertEquals('my_title', $result1['title']); - $this->assertTrue(array_key_exists('nested_model', $result1)); - - $this->assertTrue(array_key_exists('history', $result1['nested_model'])); - - $result2 = $result[1]; - $this->assertCount(3, $result2); - - $this->assertTrue($result2['is_active']); - $this->assertEquals('your_title', $result2['title']); - $this->assertTrue(array_key_exists('nested_model', $result2)); - - $this->assertTrue(array_key_exists('history', $result2['nested_model'])); + $this->assertCount(3, $result[0]); + $this->assertTrue($result[0][ 'is_active' ]); + $this->assertEquals('my_title', $result[0][ 'title' ]); + $this->assertTrue(array_key_exists('nested_model', $result[0])); + $this->assertTrue(array_key_exists('history', $result[0][ 'nested_model' ])); + + $this->assertCount(3, $result[1]); + $this->assertTrue($result[1][ 'is_active' ]); + $this->assertEquals('your_title', $result[1][ 'title' ]); + $this->assertTrue(array_key_exists('nested_model', $result[1])); + $this->assertTrue(array_key_exists('history', $result[1][ 'nested_model' ])); } /** @test **/ - public function it_throws_an_exception_if_the_data_given_is_not_a_model_or_a_collection() + public function nested_transformations_are_only_available_on_laravel_model_objects() { - $transformer = new ModelTransformer( - [ - 'nested' => new NestedModelTransformer() - ] - ); - - $this->expectException(TypeErrorException::class); - $transformer->process([]); + $nonModelObject = new \stdClass(); + + $transformer = new EmptyTransformer([ + 'nested_model' => new NestedModelTransformer() + ]); + + $this->expectException(InvalidArgumentException::class); + + $transformer->process($nonModelObject); } }