Skip to content

Commit

Permalink
closes #354
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Terentev committed Jan 26, 2016
1 parent 084992b commit 07c5af2
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 148 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
@@ -1,8 +1,9 @@
Yii Starter Kit Change Log
==========================

2.1.0 under development
2.1.0
-----------------------
- Enh #354: Command Bus implemented with yii2-command-bus extension
- Enh #321: editOwnModel permission
- Fixed #326
- API Fixes
Expand Down
7 changes: 5 additions & 2 deletions README.md
Expand Up @@ -74,6 +74,7 @@ Password: user
- Ready-to-go RESTful API module
- [File storage component + file upload widget](https://github.com/trntv/yii2-file-kit)
- On-demand thumbnail creation [trntv/yii2-glide](https://github.com/trntv/yii2-glide)
- Command Bus with queued and async tasks support [trntv/yii2-command-bus](https://github.com/trntv/yii2-command-bus)
- Useful behaviors (GlobalAccessBehavior, CacheInvalidateBehavior, MaintenanceBehavior)
- Yii2 log web interface
- Application timeline component
Expand All @@ -90,8 +91,7 @@ Password: user
- Extended IDE autocompletion
- Nginx config example
- Test-ready
- Docker support
- Vagrant support
- Docker support and Vagrant support
- Assets compression and concatenation
- [Some useful shortcuts](https://github.com/trntv/yii2-starter-kit/blob/master/common/shortcuts.php)
- many other features i'm lazy to write about :-)
Expand Down Expand Up @@ -220,6 +220,9 @@ Add in your application config:
```
It will allow access to you application only for authentificated users.

### Command Bus
Read more about command bus on in [official repository](https://github.com/trntv/yii2-command-bus#yii2-command-bus)

### Widgets configurable from backend
#### Carousel
1. Create carousel in backend
Expand Down
2 changes: 1 addition & 1 deletion autocompletion.php
Expand Up @@ -23,7 +23,7 @@ class Yii extends \yii\BaseYii
* @property yii\web\UrlManager $urlManagerBackend UrlManager for backend application.
* @property yii\web\UrlManager $urlManagerStorage UrlManager for storage application.
* @property trntv\glide\components\Glide $glide
* @property trntv\tactician\Tactician $commandBus
* @property trntv\bus\CommandBus $commandBus
*/
abstract class BaseApplication extends yii\base\Application
{
Expand Down
@@ -1,17 +1,30 @@
<?php

namespace common\commands\handler;
namespace common\commands;

use common\commands\command\AddToTimelineCommand;
use common\models\TimelineEvent;
use trntv\tactician\base\BaseHandler;
use Yii;
use yii\base\Object;
use common\models\TimelineEvent;
use trntv\bus\interfaces\SelfHandlingCommand;

/**
* @author Eugene Terentev <eugene@terentev.net>
*/
class AddToTimelineHandler extends BaseHandler
class AddToTimelineCommand extends Object implements SelfHandlingCommand
{
/**
* @var string
*/
public $category;
/**
* @var string
*/
public $event;
/**
* @var mixed
*/
public $data;

/**
* @param AddToTimelineCommand $command
* @return bool
Expand Down
80 changes: 80 additions & 0 deletions common/commands/SendEmailCommand.php
@@ -0,0 +1,80 @@
<?php

namespace common\commands;

use yii\base\Object;
use yii\swiftmailer\Message;
use trntv\bus\interfaces\SelfHandlingCommand;

/**
* @author Eugene Terentev <eugene@terentev.net>
*/
class SendEmailCommand extends Object implements SelfHandlingCommand
{
/**
* @var mixed
*/
public $from;
/**
* @var mixed
*/
public $to;
/**
* @var string
*/
public $subject;
/**
* @var string
*/
public $view;
/**
* @var array
*/
public $params;
/**
* @var string
*/
public $body;
/**
* @var bool
*/
public $html = true;

/**
* Command init
*/
public function init()
{
$this->from = $this->from ?: \Yii::$app->params['robotEmail'];
}

/**
* @return bool
*/
public function isHtml()
{
return (bool) $this->html;
}

/**
* @param \common\commands\SendEmailCommand $command
* @return bool
*/
public function handle($command)
{
if (!$command->body) {
$message = \Yii::$app->mailer->compose($command->view, $command->params);
} else {
$message = new Message();
if ($command->isHtml()) {
$message->setHtmlBody($command->body);
} else {
$message->setTextBody($command->body);
}
}
$message->setFrom($command->from);
$message->setTo($command->to ?: \Yii::$app->params['robotEmail']);
$message->setSubject($command->subject);
return $message->send();
}
}
24 changes: 0 additions & 24 deletions common/commands/command/AddToTimelineCommand.php

This file was deleted.

56 changes: 0 additions & 56 deletions common/commands/command/SendEmailCommand.php

This file was deleted.

34 changes: 0 additions & 34 deletions common/commands/handler/SendEmailHandler.php

This file was deleted.

13 changes: 7 additions & 6 deletions common/config/base.php
Expand Up @@ -22,12 +22,13 @@
],

'commandBus' => [
'class' => '\trntv\tactician\Tactician',
'commandNameExtractor' => '\League\Tactician\Handler\CommandNameExtractor\ClassNameExtractor',
'methodNameInflector' => '\League\Tactician\Handler\MethodNameInflector\HandleInflector',
'commandToHandlerMap' => [
'common\commands\command\SendEmailCommand' => '\common\commands\handler\SendEmailHandler',
'common\commands\command\AddToTimelineCommand' => '\common\commands\handler\AddToTimelineHandler',
'class' => 'trntv\bus\CommandBus',
'middlewares' => [
[
'class' => '\trntv\bus\middlewares\BackgroundCommandMiddleware',
'backgroundHandlerPath' => '@console/yii',
'backgroundHandlerRoute' => 'command-bus/handle',
]
]
],

Expand Down
4 changes: 2 additions & 2 deletions common/config/web.php
Expand Up @@ -17,13 +17,13 @@
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
'allowedIPs' => ['127.0.0.1', '::1', '192.168.33.1', '172.17.42.1'],
'allowedIPs' => ['127.0.0.1', '::1', '192.168.33.1', '172.17.42.1', '172.17.0.1'],
];
}

if (YII_ENV_DEV) {
$config['modules']['gii'] = [
'allowedIPs' => ['127.0.0.1', '::1', '192.168.33.1', '172.17.42.1'],
'allowedIPs' => ['127.0.0.1', '::1', '192.168.33.1', '172.17.42.1', '172.17.0.1'],
];
}

Expand Down
2 changes: 1 addition & 1 deletion common/models/User.php
Expand Up @@ -2,7 +2,7 @@
namespace common\models;

use cheatsheet\Time;
use common\commands\command\AddToTimelineCommand;
use common\commands\AddToTimelineCommand;
use Yii;
use yii\behaviors\AttributeBehavior;
use yii\behaviors\TimestampBehavior;
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Expand Up @@ -38,16 +38,17 @@
"trntv/yii2-file-kit": "^1.0.0",
"trntv/yii2-glide": "^1.0.0",
"trntv/yii2-datetime-widget": "^1.0.0",
"trntv/yii2-tactician": "^0.1.0",
"trntv/cheatsheet": "^0.1@dev",
"trntv/yii2-command-bus": "^1.0",
"intervention/image": "^2.1",
"vlucas/phpdotenv": "^2.0",
"league/glide": "^0.3",
"bower-asset/admin-lte": "^2.0",
"bower-asset/font-awesome": "^4.0",
"bower-asset/html5shiv": "^3.0",
"bower-asset/jquery-slimscroll": "^1.3",
"bower-asset/flot": "^0.8"
"bower-asset/flot": "^0.8",
"symfony/process": "^3.0"
},
"require-dev": {
"yiisoft/yii2-debug": "^2.0.0",
Expand All @@ -57,7 +58,6 @@
"codeception/codeception": "^2.0"
},
"suggest": {
"trntv/yii2-deploy": "dev-master@dev",
"trntv/yii2-debug-xhprof": "dev-master@dev"
},
"config": {
Expand Down
25 changes: 14 additions & 11 deletions console/config/console.php
Expand Up @@ -3,19 +3,22 @@
'id' => 'console',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'console\controllers',
'controllerMap'=>[
'message'=>[
'class'=>'console\controllers\ExtendedMessageController'
'controllerMap' => [
'command-bus' => [
'class' => 'trnv\bus\console\BackgroundBusController',
],
'migrate'=>[
'class'=>'yii\console\controllers\MigrateController',
'migrationPath'=>'@common/migrations/db',
'migrationTable'=>'{{%system_db_migration}}'
'message' => [
'class' => 'console\controllers\ExtendedMessageController'
],
'rbac-migrate'=>[
'class'=>'console\controllers\RbacMigrateController',
'migrationPath'=>'@common/migrations/rbac/',
'migrationTable'=>'{{%system_rbac_migration}}',
'migrate' => [
'class' => 'yii\console\controllers\MigrateController',
'migrationPath' => '@common/migrations/db',
'migrationTable' => '{{%system_db_migration}}'
],
'rbac-migrate' => [
'class' => 'console\controllers\RbacMigrateController',
'migrationPath' => '@common/migrations/rbac/',
'migrationTable' => '{{%system_rbac_migration}}',
'templateFile' => '@common/rbac/views/migration.php'
],
],
Expand Down
2 changes: 1 addition & 1 deletion frontend/modules/user/controllers/SignInController.php
Expand Up @@ -2,7 +2,7 @@

namespace frontend\modules\user\controllers;

use common\commands\command\SendEmailCommand;
use common\commands\SendEmailCommand;
use common\models\User;
use frontend\modules\user\models\LoginForm;
use frontend\modules\user\models\PasswordResetRequestForm;
Expand Down

0 comments on commit 07c5af2

Please sign in to comment.