Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
50a8e73
Update version
davidnurdin May 7, 2024
81af062
Update version
davidnurdin May 7, 2024
bac7282
Update version
davidnurdin May 7, 2024
8874436
Update version
davidnurdin May 7, 2024
f3420c2
Update version
davidnurdin May 7, 2024
89c68b1
Update version
davidnurdin May 7, 2024
1160949
Update version
davidnurdin May 7, 2024
f9a28a8
Update version
davidnurdin May 7, 2024
41a0187
Update version
davidnurdin May 7, 2024
9f1a7c6
Update version
davidnurdin May 7, 2024
fc85059
Update version
davidnurdin May 7, 2024
ed85cec
Update version
davidnurdin May 7, 2024
c4835a3
Update missing interface
davidnurdin May 7, 2024
c49c83b
Update missing interface
davidnurdin May 7, 2024
1fc6917
Update missing interface
davidnurdin May 7, 2024
51ca36a
Update missing interface
davidnurdin May 7, 2024
3ea0632
Update missing interface
davidnurdin May 7, 2024
2259f53
Update missing interface
davidnurdin May 7, 2024
7dfc4ee
Update missing interface
davidnurdin May 7, 2024
d20a0d9
add compatibility
davidnurdin May 13, 2024
faf2bcd
add compatibility
davidnurdin May 13, 2024
24a5f05
add compatibility
davidnurdin May 13, 2024
8dd2a2e
add compatibility
davidnurdin May 13, 2024
1020762
tests
davidnurdin May 13, 2024
358f58a
tests+kernels
davidnurdin May 13, 2024
c0295a7
tests ok!
davidnurdin May 14, 2024
329d059
tests ok!
davidnurdin May 14, 2024
cd29dec
warnings+depreciations
davidnurdin May 14, 2024
dd64611
warnings+depreciations
davidnurdin May 14, 2024
e80d317
depreciations
davidnurdin May 14, 2024
5589ba5
depreciations
davidnurdin May 14, 2024
2b91117
depreciations
davidnurdin May 15, 2024
3d4014a
depreciations
davidnurdin May 15, 2024
f88c733
Code coverrage update + test
davidnurdin May 15, 2024
01d044a
update composer.json
davidnurdin May 15, 2024
ee133a6
update composer.json
davidnurdin May 15, 2024
44632a1
Add transformers (missing coverage+test)
davidnurdin May 16, 2024
e1ec30e
Add additionalUriArgs to have more parameters in Uri
davidnurdin May 16, 2024
8273603
Add api products
davidnurdin May 16, 2024
8273df5
update
davidnurdin May 16, 2024
22783c7
update
davidnurdin May 16, 2024
5a68151
update
davidnurdin May 17, 2024
bde00ad
update
davidnurdin May 17, 2024
2d54bd4
composer ok
davidnurdin May 28, 2024
3aa7368
Deperecated schemamanager factory !
davidnurdin May 30, 2024
e60123d
additional params post+delet+put
davidnurdin May 31, 2024
3686f48
Add annotation bug (serverVersion+bad use ObjectManager)
davidnurdin Jun 7, 2024
c49d456
Add annotation bug (serverVersion+bad use ObjectManager)
davidnurdin Jun 7, 2024
36d8b88
Absolute uri
davidnurdin Jun 7, 2024
33a5ed0
Add annotations
davidnurdin Jun 7, 2024
ccf8616
add disableIdInUrl options
davidnurdin Jun 13, 2024
4ff0409
bug in InsertChangeSet.php with JSON
davidnurdin Jun 25, 2024
26cf71c
bug Driver (Meta) not loading
davidnurdin Jun 26, 2024
2d737d1
update
davidnurdin Jul 3, 2024
17f9604
add inherited class
davidnurdin Jul 11, 2024
a0e09b1
Fix bug with quotes
davidnurdin Jul 19, 2024
5825f61
Fix warning
davidnurdin Jul 24, 2024
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
4 changes: 2 additions & 2 deletions Annotations/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
*
* @Annotation
*/
class Delete implements DataSource{
#[\Attribute] class Delete implements DataSource{
use Route;
}
}
4 changes: 2 additions & 2 deletions Annotations/Fetch.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
*
* @Annotation
*/
class Fetch implements DataSource {
#[\Attribute] class Fetch implements DataSource {
use Route;
}
}
4 changes: 2 additions & 2 deletions Annotations/Insert.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
*
* @Annotation
*/
class Insert implements DataSource {
#[\Attribute] class Insert implements DataSource {
use Route;
}
}
82 changes: 78 additions & 4 deletions Annotations/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
namespace Circle\DoctrineRestDriver\Annotations;

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\ORM\Mapping\Driver\AttributeReader;
use Doctrine\ORM\Mapping\Driver\RepeatableAttributeCollection;
use Doctrine\ORM\Mapping\MappingAttribute;
use ReflectionAttribute;
use ReflectionClass;

/**
* Reads annotations
Expand All @@ -32,12 +37,15 @@ class Reader {
* @var AnnotationReader
*/
private $annotationReader;
private $attributeReader ;


/**
* Reader constructor.
*/
public function __construct() {
$this->annotationReader = new AnnotationReader();
// $this->annotationReader = new AnnotationReader();
$this->attributeReader = new AttributeReader() ;
}

/**
Expand All @@ -48,8 +56,74 @@ public function __construct() {
* @return null|string
*/
public function read(\ReflectionClass $class, $namespace) {
$annotation = $this->annotationReader->getClassAnnotation($class, $namespace);

return $annotation instanceof $namespace ? $annotation : null;
$attributes = $this->getClassAttributes($class);

foreach ($attributes as $attribute)
{
if ($attribute instanceof $namespace)
return $attribute ;
}

// get inherited annotations
$parent = $class->getParentClass();
if ($parent !== false) {
return $this->read($parent, $namespace);
}


return null ; // @codeCoverageIgnore

// $annotation = $this->annotationReader->getClassAnnotation($class, $namespace);
// return $attributes instanceof $namespace ? $attributes : null;
// return $annotation instanceof $namespace ? $annotation : null;
}

public function readAll(\ReflectionClass $class, $namespace) {

$attributes = $this->getClassAttributes($class);

$return = [] ;

foreach ($attributes as $attribute)
{
if ($attribute instanceof $namespace) {
if (!str_starts_with($attribute::class,__NAMESPACE__))
$return[$attribute::class] = $attribute;
}
}

return $return ;

}

/**
* @psalm-return class-string-map<T, T|RepeatableAttributeCollection<T>>
*
* @template T of MappingAttribute
*/
public function getClassAttributes(ReflectionClass $class): array
{
return $this->convertToAttributeInstances($class->getAttributes());
}

/**
* @param array<ReflectionAttribute> $attributes
*
* @return class-string-map<T, T|RepeatableAttributeCollection<T>>
*
* @template T of MappingAttribute
*/
private function convertToAttributeInstances(array $attributes): array
{
$instances = [];

foreach ($attributes as $attribute) {
$attributeName = $attribute->getName();
$instance = $attribute->newInstance();
$instances[$attributeName] = $instance;
}

return $instances;
}
}
}
36 changes: 29 additions & 7 deletions Annotations/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,35 @@ trait Route {
*
* @SuppressWarnings("PHPMD.StaticAccess")
*/
public function __construct(array $values) {
$settings = new ArrayCollection($values);
public function __construct($arrayOrUri,$statusCodes = null,$method = null,$options = [] ) {
$values = $arrayOrUri;

$this->route = Url::assert($settings->get('value'), 'value');
$this->statusCodes = MaybeList::assert($settings->get('statusCodes'), 'statusCodes');
$this->method = MaybeString::assert($settings->get('method'), 'method');
$this->options = MaybeList::assert($settings->get('options'), 'options');
if (is_array($values)) {
$settings = new ArrayCollection($values);
// $this->route = Url::assert($settings->get('value'), 'value');
if (substr($values,0,1) === "/")
$this->route = substr($settings->get('value'),1);
else
$this->route = Url::assert($settings->get('value'), 'value');
// permet absolute "/"
$this->statusCodes = MaybeList::assert($settings->get('statusCodes'), 'statusCodes');
$this->method = MaybeString::assert($settings->get('method'), 'method');
$this->options = MaybeList::assert($settings->get('options'), 'options');
if ($this->options === null)
$this->options = [] ;

}
elseif (is_string($values)) { // @codeCoverageIgnoreStart
if (substr($values,0,1) === "/")
$this->route = substr($values,1);
else
$this->route = Url::assert($values, 'value');
// permet absolute "/"
$this->statusCodes = $statusCodes;
$this->method = $method;
$this->options = $options;
// @codeCoverageIgnoreEnd
}
}

/**
Expand Down Expand Up @@ -104,4 +126,4 @@ public function getMethod() {
public function getOptions() {
return $this->options;
}
}
}
40 changes: 39 additions & 1 deletion Annotations/Routing.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class Routing {
*/
private $getAll;

private $customs ;

/**
* @var array
*/
Expand All @@ -77,9 +79,45 @@ public function __construct($namespace) {
$reader = new Reader();
$class = new \ReflectionClass($namespace);

// search all customs
$this->customs = $reader->readAll($class,DataSource::class);
foreach (self::$annotations as $alias => $annotation) $this->$alias = $reader->read($class, $annotation);

// create func
// foreach ($this->customs as $custom)
// {
//// $customName = $custom->getMethod();
//// if ($customName === null)
// $customName = $custom::class;
// $this->$customName = $custom ;
//
// }
}

public function customs()
{
return $this->customs;
}
public function __get($name)
{
if (isset($this->customs[$name]))
return $this->customs[$name] ;
}

public function __isset($name)
{
return isset($this->customs[$name]) ;
}

public function __call($name, $arguments)
{
if (isset($this->customs[$name]))
return $this->customs[$name] ;
}
public function getCustoms()
{
return $this->customs ;
}
/**
* returns the post route
*
Expand Down Expand Up @@ -133,4 +171,4 @@ public function delete() {
public function getAll() {
return $this->getAll;
}
}
}
4 changes: 2 additions & 2 deletions Annotations/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
*
* @Annotation
*/
class Select implements DataSource {
#[\Attribute] class Select implements DataSource {
use Route;
}
}
4 changes: 2 additions & 2 deletions Annotations/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
*
* @Annotation
*/
class Update implements DataSource {
#[\Attribute] class Update implements DataSource {
use Route;
}
}
Loading