Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove annotations #181

Merged
merged 4 commits into from
Jan 29, 2024
Merged
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
22 changes: 9 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ An OEM *(Object Excel Manager)*, if you will.

## Example usage

### Without annotations
### Without attributes

```php
class Product
Expand Down Expand Up @@ -54,19 +54,16 @@ $iterator = $iteratorFactory->fromFile(
);
```

### With annotations
### With attributes

```php
use Xezilaires\Annotation as XLS;
use Xezilaires\Attribute as XLS;

/**
* @XLS\Options(header=1, start=2)
*/

#[XLS\Options(header=1, start=2)]
class Product
{
/**
* @XLS\HeaderReference(header="Name")
*/
#[@XLS\HeaderReference(header="Name")]
private $name;
}

Expand All @@ -77,12 +74,12 @@ $normalizer = new \Xezilaires\Bridge\Symfony\Serializer\ObjectSerializer($symfon
$iteratorFactory = new \Xezilaires\SpreadsheetIteratorFactory($normalizer, [
\Xezilaires\Bridge\PhpSpreadsheet\Spreadsheet::class,
]);
$annotationDriver = new \Xezilaires\Metadata\Annotation\AnnotationDriver();
$attributeDriver = new \Xezilaires\Metadata\Attribute\AttributeDriver();

$iterator = $iteratorFactory->fromFile(
// https://github.com/sigwinhq/xezilaires-dev/raw/master/src/Xezilaires/Test/resources/fixtures/products.xlsx
new \SplFileObject(__DIR__.'/../../src/Xezilaires/Test/resources/fixtures/products.xlsx'),
$annotationDriver->getMetadataMapping(Product::class, ['reverse' => true])
$attributeDriver->getMetadataMapping(Product::class, ['reverse' => true])
);
```

Expand All @@ -107,8 +104,7 @@ Features included:
*(using either `phpoffice/PhpSpreadsheet` or `openspout/openspout`)*
- **Denormalization / normalization** support
*(using `symfony/serializer`, from / to all supported formats)*
- **Annotations** support
*(using `doctrine/annotations`)*
- Attributes support
- mapping via **column names** or **header labels**
*(saying "Map header label `PrdctEN` to property `product`")*
- **A Symfony bundle**
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"symfony/serializer": "^6.4 || ^7.0"
},
"require-dev": {
"doctrine/annotations": "^1.12",
"matthiasnoback/symfony-dependency-injection-test": "^4.0",
"nyholm/nsa": "^1.1",
"nyholm/symfony-bundle-test": "dev-master",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
$iteratorFactory = new \Xezilaires\SpreadsheetIteratorFactory($normalizer, [
\Xezilaires\Bridge\PhpSpreadsheet\Spreadsheet::class,
]);
$annotationDriver = new \Xezilaires\Metadata\Annotation\AnnotationDriver();
$attributeDriver = new \Xezilaires\Metadata\Attribute\AttributeDriver();
// </demo>

$iterator = $iteratorFactory->fromFile(
// https://github.com/sigwinhq/xezilaires/raw/master/resources/fixtures/products.xlsx
new \SplFileObject(__DIR__.'/../../src/Xezilaires/Test/resources/fixtures/products.xlsx'),
$annotationDriver->getMetadataMapping(Product::class)
$attributeDriver->getMetadataMapping(Product::class)
);

$out = iterator_to_array($iterator);
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/reverse.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
$iteratorFactory = new \Xezilaires\SpreadsheetIteratorFactory($normalizer, [
\Xezilaires\Bridge\PhpSpreadsheet\Spreadsheet::class,
]);
$annotationDriver = new \Xezilaires\Metadata\Annotation\AnnotationDriver();
$attributeDriver = new \Xezilaires\Metadata\Attribute\AttributeDriver();
// </demo>

$iterator = $iteratorFactory->fromFile(
// https://github.com/sigwinhq/xezilaires/raw/master/resources/fixtures/products.xlsx
new \SplFileObject(__DIR__.'/../../src/Xezilaires/Test/resources/fixtures/products.xlsx'),
$annotationDriver->getMetadataMapping(Product::class, ['reverse' => true])
$attributeDriver->getMetadataMapping(Product::class, ['reverse' => true])
);

$out = iterator_to_array($iterator);
Expand Down
4 changes: 2 additions & 2 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</InternalMethod>
<MissingConstructor>
<errorLevel type="info">
<directory name="src/Xezilaires/Annotation/"/>
<directory name="src/Xezilaires/Attribute/"/>
<directory name="src/Xezilaires/Test/Model/"/>
</errorLevel>
</MissingConstructor>
Expand All @@ -46,7 +46,7 @@
</MissingTemplateParam>
<RedundantCondition>
<errorLevel type="info">
<file name="src/Xezilaires/Metadata/Annotation/AnnotationDriver.php"/>
<file name="src/Xezilaires/Metadata/Attribute/AttributeDriver.php"/>
</errorLevel>
</RedundantCondition>
<PropertyNotSetInConstructor>
Expand Down
3 changes: 1 addition & 2 deletions src/Bridge/PhpSpreadsheet/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
"require": {
"php": "^8.2",
"phpoffice/phpspreadsheet": "^1.29",
"sigwin/xezilaires": "^0.6"
"sigwin/xezilaires": "^1.0"
},
"require-dev": {
"doctrine/annotations": "^1.11",
"phpunit/phpunit": "^9.6",
"symfony/phpunit-bridge": "^6.4 || ^7.0",
"symfony/property-access": "^6.4 || ^7.0",
Expand Down
3 changes: 1 addition & 2 deletions src/Bridge/Spout/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
"require": {
"php": "^8.2",
"openspout/openspout": "^4.0",
"sigwin/xezilaires": "^0.6"
"sigwin/xezilaires": "^1.0"
},
"require-dev": {
"doctrine/annotations": "^1.11",
"nyholm/nsa": "^1.1",
"phpunit/phpunit": "^9.6",
"symfony/phpunit-bridge": "^6.4 || ^7.0",
Expand Down
4 changes: 2 additions & 2 deletions src/Bridge/Symfony/Command/SerializeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Serializer\Encoder\CsvEncoder;
use Xezilaires\IteratorFactory;
use Xezilaires\Metadata\Annotation\AnnotationDriver;
use Xezilaires\Metadata\Attribute\AttributeDriver;
use Xezilaires\Serializer;

#[AsCommand(
Expand Down Expand Up @@ -122,7 +122,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
break;
}

$driver = new AnnotationDriver();
$driver = new AttributeDriver();
$iterator = $this->iteratorFactory->fromFile(
new \SplFileObject($path),
$driver->getMetadataMapping($class, ['reverse' => $reverse, 'sequential' => true])
Expand Down
4 changes: 2 additions & 2 deletions src/Bridge/Symfony/Command/ValidateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Validator\ConstraintViolationInterface;
use Xezilaires\IteratorFactory;
use Xezilaires\Metadata\Annotation\AnnotationDriver;
use Xezilaires\Metadata\Attribute\AttributeDriver;
use Xezilaires\Validator;

#[AsCommand(
Expand Down Expand Up @@ -79,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$style = new SymfonyStyle($input, $output);
$style->title('Xezilaires validate');

$driver = new AnnotationDriver();
$driver = new AttributeDriver();

$totalCount = 0;
$totalInvalid = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/Bridge/Symfony/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"require": {
"php": "^8.2",
"sigwin/xezilaires": "^0.6",
"sigwin/xezilaires": "^1.0",
"symfony/console": "^6.4 || ^7.0",
"symfony/framework-bundle": "^6.4 || ^7.0",
"symfony/property-access": "^6.4 || ^7.0",
Expand All @@ -22,8 +22,8 @@
"matthiasnoback/symfony-dependency-injection-test": "^4.0",
"nyholm/symfony-bundle-test": "dev-master",
"phpunit/phpunit": "^9.6",
"sigwin/xezilaires-phpspreadsheet": "^0.6",
"sigwin/xezilaires-spout": "^0.6",
"sigwin/xezilaires-phpspreadsheet": "^1.0",
"sigwin/xezilaires-spout": "^1.0",
"symfony/phpunit-bridge": "^6.4 || ^7.0"
},
"conflict": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@
* with this source code in the file LICENSE.
*/

namespace Xezilaires\Annotation;
namespace Xezilaires\Attribute;

/**
* @Annotation
* @Target({"PROPERTY"})
*/
#[\Attribute(\Attribute::TARGET_PROPERTY)]
final class ArrayReference
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@
* with this source code in the file LICENSE.
*/

namespace Xezilaires\Annotation;
namespace Xezilaires\Attribute;

/**
* @Annotation
* @Target({"ANNOTATION", "PROPERTY"})
* @NamedArgumentConstructor
*/
#[\Attribute(\Attribute::TARGET_PROPERTY)]
final class ColumnReference implements Reference
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@
* with this source code in the file LICENSE.
*/

namespace Xezilaires\Annotation;
namespace Xezilaires\Attribute;

/**
* @Annotation
* @Target({"ANNOTATION", "PROPERTY"})
* @NamedArgumentConstructor
*/
#[\Attribute(\Attribute::TARGET_PROPERTY)]
final class HeaderReference implements Reference
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@
* with this source code in the file LICENSE.
*/

namespace Xezilaires\Annotation;
namespace Xezilaires\Attribute;

/**
* @Annotation
* @Target({"CLASS"})
* @NamedArgumentConstructor
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
final class Options
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* with this source code in the file LICENSE.
*/

namespace Xezilaires\Annotation;
namespace Xezilaires\Attribute;

/**
* Marker interface Reference.
Expand Down
38 changes: 0 additions & 38 deletions src/Xezilaires/Exception/AnnotationException.php

This file was deleted.

32 changes: 32 additions & 0 deletions src/Xezilaires/Exception/AttributeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

/*
* This file is part of the xezilaires project.
*
* (c) sigwin.hr
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Xezilaires\Exception;

use Xezilaires\Exception;

final class AttributeException extends \InvalidArgumentException implements Exception
{
public static function unsupportedAttribute(): self
{
return new self('Unsupported attribute');
}

/**
* @param array<int, null|\Xezilaires\Attribute\ArrayReference|\Xezilaires\Attribute\Reference> $references
*/
public static function tooManyReferencesDefined(\ReflectionProperty $property, array $references): self
{
return new self('Too many references defined for '.$property->getName());
}
}
Loading
Loading