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

Added Cycle ORM support via yii-cycle package and configured; #26

Merged
merged 1 commit into from
Oct 23, 2019
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
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@
"yiisoft/mailer-swiftmailer": "^3.0@dev",
"yiisoft/html": "^3.0@dev",
"yiisoft/security": "^3.0@dev",
"cycle/orm": "^1.1",
"cycle/annotated": "^2.0"
"yiisoft/yii-cycle": "^3.0@dev"
},
"require-dev": {
"hiqdev/composer-config-plugin": "^1.0@dev"
Expand Down
11 changes: 2 additions & 9 deletions config/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@
'@src' => '@root/src',
'@runtime' => '@root/runtime',
],
CacheInterface::class => [
'__class' => Cache::class,
'handler' => [
'__class' => ArrayCache::class,
],
],
Psr\SimpleCache\CacheInterface::class => ArrayCache::class,
CacheInterface::class => Cache::class,
LoggerInterface::class => new LoggerFactory(),
FileRotatorInterface::class => [
'__class' => FileRotator::class,
Expand All @@ -48,7 +44,4 @@
'setPassword()' => [$params['mailer.password']],
],
MailerInterface::class => new MailerFactory(),

// Cycle ORM
ORMInterface::class => new CycleOrmFactory(),
];
30 changes: 30 additions & 0 deletions config/params.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,34 @@
'commands' => [
'user/create' => CreateUser::class,
],

// cycle DBAL config
'cycle.dbal' => [
'default' => 'default',
'aliases' => [],
'databases' => [
'default' => ['connection' => 'sqlite']
],
'connections' => [
'sqlite' => [
'driver' => \Spiral\Database\Driver\SQLite\SQLiteDriver::class,
'connection' => 'sqlite:@runtime/database.db',
'username' => '',
'password' => '',
]
],
],
// cycle common config
'cycle.common' => [
'entityPaths' => [
'@src/Entity'
],
],
// cycle migration config
'cycle.migrations' => [
'directory' => '@root/migrations',
'namespace' => 'App\\Migration',
'table' => 'migration',
'safe' => false,
],
];
2 changes: 1 addition & 1 deletion src/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private function findLayoutFile(?string $file): ?string
return $file;
}

return $file . '.' . $this->view->defaultExtension;
return $file . '.' . $this->view->getDefaultExtension();
}

abstract protected function getId(): string;
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Yiisoft\Yii\Web\User\IdentityInterface;

/**
* @Entity
* @Entity(repository="App\Repository\UserRepository")
*/
class User implements IdentityInterface
{
Expand Down
15 changes: 7 additions & 8 deletions src/Repository/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,33 @@

use App\Entity\User;
use Cycle\ORM\ORMInterface;
use Cycle\ORM\Select;
use Yiisoft\Yii\Web\User\IdentityInterface;
use Yiisoft\Yii\Web\User\IdentityRepositoryInterface;

class UserRepository implements IdentityRepositoryInterface
class UserRepository extends Select\Repository implements IdentityRepositoryInterface
{
private $orm;

public function __construct(ORMInterface $orm)
public function __construct(ORMInterface $orm, $role = User::class)
{
$this->orm = $orm;
parent::__construct(new Select($orm, $role));
}

private function findIdentityBy(string $field, string $value): ?IdentityInterface
{
return $this->orm->getRepository(User::class)->findOne([$field => $value]);
return $this->findOne([$field => $value]);
}

public function findIdentity(string $id): ?IdentityInterface
{
return $this->findIdentityBy('id', $id);
return $this->findByPK($id);
}

public function findIdentityByToken(string $token, string $type): ?IdentityInterface
{
return $this->findIdentityBy('token', $token);
}

public function findByLogin(string $login): ?User
public function findByLogin(string $login): ?IdentityInterface
{
return $this->findIdentityBy('login', $login);
}
Expand Down