Skip to content

Commit

Permalink
Rename main class
Browse files Browse the repository at this point in the history
  • Loading branch information
uginroot committed Mar 3, 2020
1 parent 5ea1150 commit 022ae55
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 29 deletions.
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Install
```bash
composer require uginroot/doctrine-type-set:^2.1
composer require uginroot/doctrine-type-set:^2.2
```

# Using
Expand All @@ -11,7 +11,7 @@ namespace App\Type;

use Uginroot\PhpSet\SetAbstract;

class RoleSetType extends SetAbstract{
class Role extends SetAbstract{
public const ROLE_USER = 'user';
public const ROLE_AUTHOR = 'author';
public const ROLE_MODERATOR = 'moderator';
Expand All @@ -23,13 +23,13 @@ class RoleSetType extends SetAbstract{
```php
namespace App\DoctrineType;

use Uginroot\DoctrineTypeSet\AbstractDoctrineTypeSet;
use App\Type\RoleSetType;
use Uginroot\DoctrineTypeSet\SetDoctrineTypeAbstract;
use App\Type\Role;

class RoleSetDoctrineType extends AbstractDoctrineTypeSet{
class RoleDoctrineType extends SetDoctrineTypeAbstract{

public function getClass() : string{
return RoleSetType::class;
return Role::class;
}
}
```
Expand All @@ -39,15 +39,15 @@ class RoleSetDoctrineType extends AbstractDoctrineTypeSet{
doctrine:
dbal:
types:
RoleSetDoctrineType: App\DoctrineType\RoleSetDoctrineType
RoleDoctrineType: App\DoctrineType\RoleDoctrineType
```

#### Add mapping data to entity
```php
namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Uginroot\PhpSet\SetAbstract;
use App\Type\Role;

/**
* User
Expand All @@ -67,10 +67,10 @@ class User{
private ?int $id;

/**
* @var SetAbstract
* @ORM\Column(name="role", type="RoleSetDoctrineType", nullable=true)
* @var Role
* @ORM\Column(name="role", type="RoleDoctrineType", nullable=true)
*/
private ?SetAbstract $role;
private ?Role $role;

/**
* @return int
Expand All @@ -81,18 +81,18 @@ class User{
}

/**
* @return SetAbstract
* @return Role
*/
public function getRole(): ?SetAbstract
public function getRole(): ?Role
{
return $this->role;
}

/**
* @param SetAbstract $role
* @param Role $role
* @return $this
*/
public function setRole(SetAbstract $role):self
public function setRole(Role $role):self
{
$this->role = $role;
return $this;
Expand All @@ -105,7 +105,7 @@ class User{
public function getRoles():array
{
$role = $this->getRole();
return $role === null ? [] : $role->getNames();
return $role === null ? [] : $role->getChoice()->getNames();
}
}
```
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
],
"autoload": {
"psr-4": {
"Uginroot\\DoctrineTypeSet\\": "src/"
"Uginroot\\DoctrineTypeSet\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Uginroot\\DoctrineTypeSet\\Test\\": "test/"
"Uginroot\\DoctrineTypeSet\\Test\\": "test"
}
},
"require": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace Uginroot\DoctrineTypeSet;


use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Types\Type;
Expand All @@ -13,7 +12,7 @@
use Uginroot\DoctrineTypeSet\Exceptions\UnsupportedPlatformException;
use Uginroot\PhpSet\SetAbstract;

abstract class AbstractDoctrineTypeSet extends Type
abstract class SetDoctrineTypeAbstract extends Type
{
private ?string $setClass = null;

Expand Down
14 changes: 7 additions & 7 deletions test/DoctrineTypeSetTest.php → test/SetDoctrineTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@
use ReflectionClass;
use ReflectionException;
use stdClass;
use Uginroot\DoctrineTypeSet\AbstractDoctrineTypeSet;
use Uginroot\DoctrineTypeSet\SetDoctrineTypeAbstract;
use Uginroot\DoctrineTypeSet\Exceptions\UnexpectedExtendsException;
use Uginroot\DoctrineTypeSet\Exceptions\UnsupportedPlatformException;
use Uginroot\DoctrineTypeSet\Test\Sets\Animals;
use Uginroot\DoctrineTypeSet\Test\Types\AnimalsType;
use Uginroot\DoctrineTypeSet\Test\Types\AnimalsDoctrineType;
use Uginroot\PhpSet\SetAbstract;

class DoctrineTypeSetTest extends TestCase
class SetDoctrineTypeTest extends TestCase
{
private ?AbstractDoctrineTypeSet $type;
private ?SetDoctrineTypeAbstract $type;

/**
* @throws DBALException
* @throws ReflectionException
*/
public static function setUpBeforeClass():void
{
$class = new ReflectionClass(AnimalsType::class);
$class = new ReflectionClass(AnimalsDoctrineType::class);
Type::addType($class->getShortName(), $class->getName());
}

Expand All @@ -38,9 +38,9 @@ public static function setUpBeforeClass():void
*/
protected function setUp():void
{
$class = new ReflectionClass(AnimalsType::class);
$class = new ReflectionClass(AnimalsDoctrineType::class);
$type = Type::getType($class->getShortName());
if($type instanceof AbstractDoctrineTypeSet){
if($type instanceof SetDoctrineTypeAbstract){
$this->type = $type;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

namespace Uginroot\DoctrineTypeSet\Test\Types;

use Uginroot\DoctrineTypeSet\AbstractDoctrineTypeSet;
use Uginroot\DoctrineTypeSet\SetDoctrineTypeAbstract;
use Uginroot\DoctrineTypeSet\Test\Sets\Animals;

class AnimalsType extends AbstractDoctrineTypeSet
class AnimalsDoctrineType extends SetDoctrineTypeAbstract
{
public function getClass():string
{
Expand Down

0 comments on commit 022ae55

Please sign in to comment.