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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016-present Mark Scherer
Copyright (c) 2019-present Mark Scherer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# CakePHP DTO plugin
# DTO Generator for PHP

[![Build Status](https://travis-ci.org/dereuromark/cakephp-dto.svg?branch=master)](https://travis-ci.org/dereuromark/cakephp-dto)
[![codecov](https://img.shields.io/codecov/c/github/dereuromark/cakephp-dto/master.svg)](https://codecov.io/gh/dereuromark/cakephp-dto)
Expand Down Expand Up @@ -26,7 +26,7 @@ For more see [Motivation and Background](/docs/Motivation.md).

This plugin will provide you with a tool to quickly generate custom and optimized DTOs for your special use cases.

This branch is for use with **CakePHP 4.0+**.
This branch is for use with **PHP 7.2+**.

## Examples

Expand All @@ -44,15 +44,9 @@ You can install this plugin into your CakePHP application using [Composer](https
The recommended way to install is:

```
composer require dereuromark/cakephp-dto
composer require dereuromark/dto
```

Then load the plugin with the following command:
```
bin/cake plugin load CakeDto -b
```
The bootstrap is needed for the TwigView events to be set up. If you already included TwigView, you might not need the bootstrap.


## Usage

Expand Down
27 changes: 13 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "dereuromark/cakephp-dto",
"description": "CakePHP DTO Plugin",
"type": "cakephp-plugin",
"keywords": ["cakephp", "dto", "plugin"],
"homepage": "https://github.com/dereuromark/cakephp-dto/",
"description": "DTO Generator for PHP",
"type": "library",
"keywords": ["php", "dto", "generator"],
"homepage": "https://github.com/dereuromark/dto/",
"license": "MIT",
"authors": [
{
Expand All @@ -18,40 +18,39 @@
},
{
"name": "Other contributors",
"homepage": "https://github.com/dereuromark/cakephp-dto/graphs/contributors",
"homepage": "https://github.com/dereuromark/dto/graphs/contributors",
"role": "Developer"
}
],
"support": {
"issues": "https://github.com/dereuromark/cakephp-dto/issues",
"source": "https://github.com/dereuromark/cakephp-dto/"
"issues": "https://github.com/dereuromark/dto/issues",
"source": "https://github.com/dereuromark/dto/"
},
"require": {
"ext-json": "*",
"php": ">=7.2",
"cakephp/cakephp": "4.x-dev as 4.0.0",
"wyrihaximus/twig-view": "dev-master",
"twig/twig": "^2.10",
"sebastian/diff": "^3.0"
},
"require-dev": {
"ext-dom": "*",
"ext-libxml": "*",
"nette/neon": "^2.4",
"cakephp/collection": "4.x-dev as 4.0.0",
"fig-r/psr2r-sniffer": "dev-master"
},
"suggest": {
"nette/neon": "^2.4 if you want to add a NEON file engine instead of XML."
},
"autoload": {
"psr-4": {
"CakeDto\\": "src/"
"Dto\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"CakeDto\\Test\\": "tests/",
"Cake\\Test\\": "vendor/cakephp/cakephp/tests/",
"TestApp\\": "tests/test_app/src/",
"Sandbox\\": "tests/test_app/plugins/Sandbox/src/"
"Dto\\Test\\": "tests/",
"TestApp\\": "tests/test_app/src/"
}
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
use WyriHaximus\TwigView\Event\ExtensionsListener;
use WyriHaximus\TwigView\Event\TokenParsersListener;

EventManager::instance()->on(new ExtensionsListener());
EventManager::instance()->on(new TokenParsersListener());
//EventManager::instance()->on(new ExtensionsListener());
//EventManager::instance()->on(new TokenParsersListener());
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ Objects, which are not DTOs or Collections, can get lost here.
If you have value objects (especially immutable ones), implement the `FromArrayToArrayInterface` here:

```php
use CakeDto\Dto\FromArrayToArrayInterface;
use Dto\Dto\FromArrayToArrayInterface;

final class Paint implements FromArrayToArrayInterface {}
```
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<!-- Add any additional test suites you want to run here -->
<testsuites>
<testsuite name="cake-dto">
<testsuite name="dto">
<directory>tests/TestCase/</directory>
</testsuite>
</testsuites>
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Io.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace CakeDto\Console;
namespace Dto\Console;

use Cake\Console\ConsoleIo;
use Cake\Console\Exception\StopException;
Expand Down
4 changes: 2 additions & 2 deletions src/Dto/AbstractDto.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace CakeDto\Dto;
namespace Dto\Dto;

use CakeDto\View\Json;
use Dto\View\Json;
use RuntimeException;

abstract class AbstractDto extends Dto {
Expand Down
4 changes: 2 additions & 2 deletions src/Dto/AbstractImmutableDto.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace CakeDto\Dto;
namespace Dto\Dto;

use CakeDto\View\Json;
use Dto\View\Json;
use RuntimeException;

abstract class AbstractImmutableDto extends Dto {
Expand Down
28 changes: 14 additions & 14 deletions src/Dto/Dto.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace CakeDto\Dto;
namespace Dto\Dto;

use ArrayAccess;
use CakeDto\View\Json;
use Dto\View\Json;
use Cake\Collection\Collection;
use Countable;
use InvalidArgumentException;
Expand Down Expand Up @@ -137,11 +137,11 @@ public function toArray($type = self::TYPE_DEFAULT, array $fields = null, $touch
} elseif ($value instanceof Countable && $value->count()) {
$values = $this->transformCollectiontoArray($value, $values, $key, $touched ? 'touchedToArray' : 'toArray', $type);
} elseif ($this->_metadata[$field]['serializable']) {
/** @var \CakeDto\Dto\FromArrayToArrayInterface $value */
/** @var \Dto\Dto\FromArrayToArrayInterface $value */
$values[$key] = $value->toArray();
} elseif ($this->_metadata[$field]['toArray']) {
// This will not be transformable in the other direction
/** @var \CakeDto\Dto\FromArrayToArrayInterface $value */
/** @var \Dto\Dto\FromArrayToArrayInterface $value */
$values[$key] = $value->toArray();
} else {
$values[$key] = $value;
Expand Down Expand Up @@ -278,15 +278,15 @@ protected function createCakeCollection($elementType, $arrayObject, $ignoreMissi
}

if (array_values($arrayElement) !== $arrayElement) {
/** @var \CakeDto\Dto\Dto $dto */
/** @var \Dto\Dto\Dto $dto */
$dto = new $elementType($arrayElement, $ignoreMissing, $type);
$collection = $collection->appendItem($dto);

continue;
}

foreach ($arrayElement as $arrayElementItem) {
/** @var \CakeDto\Dto\Dto $dto */
/** @var \Dto\Dto\Dto $dto */
$dto = new $elementType($arrayElementItem, $ignoreMissing, $type);
$collection = $collection->appendItem($dto);
}
Expand All @@ -301,10 +301,10 @@ protected function createCakeCollection($elementType, $arrayObject, $ignoreMissi
* @param bool $ignoreMissing
* @param string $type
*
* @return \CakeDto\Dto\Dto
* @return \Dto\Dto\Dto
*/
protected function createDto($field, $value, $ignoreMissing, $type) {
/** @var \CakeDto\Dto\AbstractDto $dto */
/** @var \Dto\Dto\AbstractDto $dto */
$className = $this->_metadata[$field]['type'];

if (is_array($value)) {
Expand All @@ -318,10 +318,10 @@ protected function createDto($field, $value, $ignoreMissing, $type) {
* @param string $field
* @param mixed $value
*
* @return \CakeDto\Dto\Dto
* @return \Dto\Dto\Dto
*/
protected function createObject($field, $value) {
/** @var \CakeDto\Dto\FromArrayToArrayInterface $className */
/** @var \Dto\Dto\FromArrayToArrayInterface $className */
$className = $this->_metadata[$field]['type'];

if (is_array($value)) {
Expand Down Expand Up @@ -350,15 +350,15 @@ protected function createCollection($collectionType, $elementType, $arrayObject,
}

if (array_values($arrayElement) !== $arrayElement) {
/** @var \CakeDto\Dto\Dto $dto */
/** @var \Dto\Dto\Dto $dto */
$dto = new $elementType($arrayElement, $ignoreMissing, $type);
$collection->append($dto);

continue;
}

foreach ($arrayElement as $arrayElementItem) {
/** @var \CakeDto\Dto\Dto $dto */
/** @var \Dto\Dto\Dto $dto */
$dto = new $elementType($arrayElementItem, $ignoreMissing, $type);
$collection->append($dto);
}
Expand All @@ -385,15 +385,15 @@ protected function createArrayCollection($elementType, $arrayObject, $ignoreMiss
}

if (array_values($arrayElement) !== $arrayElement) {
/** @var \CakeDto\Dto\Dto $dto */
/** @var \Dto\Dto\Dto $dto */
$dto = new $elementType($arrayElement, $ignoreMissing, $type);
$collection = $this->addValueToArrayCollection($collection, $dto, $arrayElement, $index, $key);

continue;
}

foreach ($arrayElement as $arrayElementItem) {
/** @var \CakeDto\Dto\Dto $dto */
/** @var \Dto\Dto\Dto $dto */
$dto = new $elementType($arrayElementItem, $ignoreMissing, $type);
$collection = $this->addValueToArrayCollection($collection, $dto, $arrayElement, $index, $key);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Dto/FromArrayToArrayInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace CakeDto\Dto;
namespace Dto\Dto;

/**
* Implement this interface for your VOs that should be fromArray()/toArray() safe.
Expand Down
2 changes: 1 addition & 1 deletion src/Engine/EngineInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace CakeDto\Engine;
namespace Dto\Engine;

interface EngineInterface {

Expand Down
2 changes: 1 addition & 1 deletion src/Engine/NeonEngine.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace CakeDto\Engine;
namespace Dto\Engine;

use InvalidArgumentException;
use Nette\Neon\Exception;
Expand Down
2 changes: 1 addition & 1 deletion src/Engine/XmlEngine.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace CakeDto\Engine;
namespace Dto\Engine;

use Cake\Utility\Xml;

Expand Down
2 changes: 1 addition & 1 deletion src/Engine/XmlValidator.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace CakeDto\Engine;
namespace Dto\Engine;

use Cake\Core\Plugin;
use DOMDocument;
Expand Down
2 changes: 1 addition & 1 deletion src/Engine/YamlEngine.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace CakeDto\Engine;
namespace Dto\Engine;

use InvalidArgumentException;

Expand Down
6 changes: 3 additions & 3 deletions src/Generator/Builder.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace CakeDto\Generator;
namespace Dto\Generator;

use CakeDto\Dto\FromArrayToArrayInterface;
use CakeDto\Engine\EngineInterface;
use Dto\Dto\FromArrayToArrayInterface;
use Dto\Engine\EngineInterface;
use Cake\Core\Configure;
use Cake\Core\InstanceConfigTrait;
use Cake\Utility\Inflector;
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/DiffHelperTrait.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace CakeDto\Generator;
namespace Dto\Generator;

use Cake\Console\Shell;
Copy link
Contributor

@saeideng saeideng Nov 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shells should move to use cake's command

use SebastianBergmann\Diff\Differ;
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/Finder.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace CakeDto\Generator;
namespace Dto\Generator;

use DirectoryIterator;
use InvalidArgumentException;
Expand Down
6 changes: 3 additions & 3 deletions src/Generator/Generator.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace CakeDto\Generator;
namespace Dto\Generator;

use CakeDto\Console\Io;
use CakeDto\View\Renderer;
use Dto\Console\Io;
use Dto\View\Renderer;
use Cake\Console\Shell;
use Exception;
use RecursiveDirectoryIterator;
Expand Down
11 changes: 0 additions & 11 deletions src/Plugin.php

This file was deleted.

16 changes: 8 additions & 8 deletions src/Shell/DtoShell.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
namespace CakeDto\Shell;

use CakeDto\Console\Io;
use CakeDto\Engine\EngineInterface;
use CakeDto\Engine\XmlEngine;
use CakeDto\Generator\Builder;
use CakeDto\Generator\Generator;
use CakeDto\View\Renderer;
namespace Dto\Shell;

use Dto\Console\Io;
use Dto\Engine\EngineInterface;
use Dto\Engine\XmlEngine;
use Dto\Generator\Builder;
use Dto\Generator\Generator;
use Dto\View\Renderer;
use Cake\Console\ConsoleOptionParser;
use Cake\Console\Shell;
use Cake\Core\Configure;
Expand Down
2 changes: 1 addition & 1 deletion src/TestSuite/DebugMemory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @since DebugKit 2.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace CakeDto\TestSuite;
namespace Dto\TestSuite;

use Cake\Error\Debugger;

Expand Down
Loading