Skip to content

Commit

Permalink
Merge pull request #2 from tarikweiss/development
Browse files Browse the repository at this point in the history
Declared Tjson as new root namespace. Thanks for the hint @wolxXx :)
  • Loading branch information
tarikweiss authored Mar 16, 2022
2 parents fd677d3 + e9ac44e commit d2f1215
Show file tree
Hide file tree
Showing 21 changed files with 119 additions and 115 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
composer.phar
/vendor/
/.phpunit.result.cache

# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ It will map all properties (including private and protected), as long they are n
### Sample object class
The properties can be configured with doctrine annotations or the new PHP 8 attributes.
A full documentation of the annotations/attributes is following.

```php
class ClassToConvert
{
#[\Tarikweiss\Tjson\Attributes\MappedPropertyName(name: 'public_item')]
#[\Tjson\Attributes\MappedPropertyName(name: 'public_item')]
public $publicItem;

protected $protectedItem;

private $privateItem;

#[\Tarikweiss\Tjson\Attributes\MappedPropertyClass(class: ClassC::class)]
#[\Tjson\Attributes\MappedPropertyClass(class: ClassC::class)]
private ClassA|ClassB|ClassC $typedItems;

/**
* @\Tarikweiss\Tjson\Attributes\Required(required = true)
* @\Tjson\Attributes\Required(required = true)
*/
private $anotherProperty = 'withValue';

Expand All @@ -47,17 +48,19 @@ This json is assumed as value for `$jsonString` for the following samples:
````
#### Decoder
Decoding is done as follows:

```php
$jsonDecoder = new \Tarikweiss\Tjson\JsonDecoder();
$jsonDecoder = new \Tjson\JsonDecoder();

$yourClassInstance = $jsonDecoder->decodeByClassName($jsonString, \Your\Class::class)
echo $yourClassInstance->getProtectedItem() // 1337
```

#### Encoder
Encoding is done as follows:

```php
$jsonEncoder = new \Tarikweiss\Tjson\JsonEncoder();
$jsonEncoder = new \Tjson\JsonEncoder();

$jsonString = $jsonEncoder->encode($yourClassInstance);
```
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"autoload": {
"psr-4": {
"Tarikweiss\\Tjson\\": "src/"
"Tjson\\": "src/"
}
},
"require-dev": {
Expand Down
4 changes: 2 additions & 2 deletions src/Attributes/MappedPropertyClass.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace Tarikweiss\Tjson\Attributes;
namespace Tjson\Attributes;

/**
* Class MappedPropertyClass
* Use this attribute to specify, which class should be used for mapping. This is especially needed, when not specifying
* a type or specifying union type.<br>
* If only a single type is specified and class name does not match, an exception will be thrown.
* @package Tarikweiss\Tjson\Attributes
* @package Tjson\Attributes
* @Annotation
* @\Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Attributes/MappedPropertyName.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace Tarikweiss\Tjson\Attributes;
namespace Tjson\Attributes;

/**
* Class MappedPropertyName
*
* @package Tarikweiss\Tjson\Attributes
* @package Tjson\Attributes
* @Annotation
* @\Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor()
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Attributes/Omit.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace Tarikweiss\Tjson\Attributes;
namespace Tjson\Attributes;

/**
* Class Omit
*
* @package Tarikweiss\Tjson\Attributes
* @package Tjson\Attributes
* @Annotation
* @\Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor()
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Attributes/Required.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace Tarikweiss\Tjson\Attributes;
namespace Tjson\Attributes;

/**
* Class Required
*
* @package Tarikweiss\Tjson\Attributes
* @package Tjson\Attributes
* @Annotation
* @\Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor()
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Decoding/AbstractedType.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace Tarikweiss\Tjson\Decoding;
namespace Tjson\Decoding;

/**
* Class AbstractedType
*
* @package Tarikweiss\Tjson\Decoding
* @package Tjson\Decoding
*/
class AbstractedType
{
Expand Down
4 changes: 2 additions & 2 deletions src/Decoding/PropertyDecoder.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace Tarikweiss\Tjson\Decoding;
namespace Tjson\Decoding;

/**
* Class PropertyDecoder
*
* @package Tarikweiss\Tjson\Decoding
* @package Tjson\Decoding
*/
class PropertyDecoder
{
Expand Down
4 changes: 2 additions & 2 deletions src/Exception/AmbiguousNameDefinitionException.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace Tarikweiss\Tjson\Exception;
namespace Tjson\Exception;

/**
* Class AmbiguousNameDefinitionException
*
* @package Tarikweiss\Tjson\Exception
* @package Tjson\Exception
*/
class AmbiguousNameDefinitionException extends \Exception
{
Expand Down
4 changes: 2 additions & 2 deletions src/Exception/AmbiguousTypeDefinitionException.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace Tarikweiss\Tjson\Exception;
namespace Tjson\Exception;

/**
* Class AmbiguousTypeDefinitionException
*
* @package Tarikweiss\Tjson\Exception
* @package Tjson\Exception
*/
class AmbiguousTypeDefinitionException extends \Exception
{
Expand Down
4 changes: 2 additions & 2 deletions src/Exception/ClassNotFoundException.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace Tarikweiss\Tjson\Exception;
namespace Tjson\Exception;

/**
* Class ClassNotFoundException
*
* @package Tarikweiss\Tjson\Exception
* @package Tjson\Exception
*/
class ClassNotFoundException extends \Exception
{
Expand Down
4 changes: 2 additions & 2 deletions src/Exception/NoMatchingTypeDefinitionException.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace Tarikweiss\Tjson\Exception;
namespace Tjson\Exception;

/**
* Class NoMatchingTypeDefinitionException
*
* @package Tarikweiss\Tjson\Exception
* @package Tjson\Exception
*/
class NoMatchingTypeDefinitionException extends \Exception
{
Expand Down
4 changes: 2 additions & 2 deletions src/Exception/RequiredPropertyNotFoundException.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace Tarikweiss\Tjson\Exception;
namespace Tjson\Exception;

/**
* Class RequiredPropertyNotFoundException
*
* @package Tarikweiss\Tjson\Exception
* @package Tjson\Exception
*/
class RequiredPropertyNotFoundException extends \Exception
{
Expand Down
Loading

0 comments on commit d2f1215

Please sign in to comment.