Browse Source

消息分支

lbk 6 years ago
parent
commit
54bb7ddab8

+ 1 - 1
api/config/.gitignore

@@ -1,3 +1,3 @@
 main-local.php
 params-local.php
-test-local.php
+test-local.php

+ 27 - 25
api/config/main.php

@@ -13,7 +13,10 @@ return [
     'modules' => [
         'v1' => [
             'class' => 'api\modules\v1\Module'
-        ]
+        ],
+		'v2' => [
+			'class' => 'api\modules\v2\Module'
+		],
     ],
     'controllerNamespace' => 'api\controllers',
     'components' => [
@@ -32,38 +35,37 @@ return [
                 ],
             ],
         ],
-        'request' => [
+        /*'request' => [
             'class' => '\yii\web\Request',
             'enableCookieValidation' => false,
             'parsers' => [
                 'application/json' => 'yii\web\JsonParser',
             ],
             'cookieValidationKey' => 'O1d232trde1xww-M97_7QvwPo-5QGdkLMp#@#@',
-        ],
-        'errorHandler' => [
+        ],*/
+        /*'errorHandler' => [
             'errorAction' => 'site/error',
-        ],
+        ],*/
 
-        'urlManager' =>  [
-            'class' => 'yii\web\UrlManager',
-            'enablePrettyUrl' => true,
-            'enableStrictParsing' => true,
-            'showScriptName' => false,
-            'rules' => [
-                '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
-                '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
-                '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
-//                '' => 'site/index',
-//                ['class' => 'yii\rest\UrlRule', 'controller' => 'customer/api',
-//                    'pluralize' => false,
-//                ],
-//                #  定义方法: public function actionSearch($id);   <id> 就是search方法传入的参数
-//                #  http://10.10.10.252:599/v1/wishorder/2015-08-11+12:12:12/2015-09-11+12:12:12?access-token=pBJi3hyFsLsTuvUM9paFpWjYRatn3qwS
-//                #  分页:http://10.10.10.252:599/v1/wishorder/2015-08-11+12:12:12/2015-09-11+12:12:12?page=2&access-token=pBJi3hyFsLsTuvUM9paFpWjYRatn3qwS
-//                'GET v1/wishorder/<begin_datetime>/<end_datetime>' => 'v1/wishorder/viewbydate',
-//                'GET v1/ebayorder/<begin_datetime>/<end_datetime>' => 'v1/ebayorder/viewbydate',
-            ]
-        ],
+		'urlManager' => [
+			'enablePrettyUrl' => true,
+			'enableStrictParsing' => true,
+			'showScriptName' => false,
+			'rules' => [
+                [
+                     'class' => 'yii\rest\UrlRule',
+                     'controller' => [
+                         'v1/site'
+                     ]
+                 ],
+                 [
+                     'class' => 'yii\rest\UrlRule',
+                     'controller' => [
+                         'v2/site'
+                     ]
+                 ]
+			],
+		],
 
         'db' =>   require __DIR__ . '/../../common/config/db.php'
     ],

+ 0 - 205
api/controllers/UserController.php

@@ -1,205 +0,0 @@
-<?php
-namespace common\models;
-
-use Yii;
-use yii\base\NotSupportedException;
-use yii\behaviors\TimestampBehavior;
-use yii\db\ActiveRecord;
-use yii\web\IdentityInterface;
-
-/**
- * User model
- *
- * @property integer $id
- * @property string $username
- * @property string $password_hash
- * @property string $password_reset_token
- * @property string $email
- * @property string $auth_key
- * @property integer $status
- * @property integer $created_at
- * @property integer $updated_at
- * @property integer  $curr_login_ip
- * @property integer $curr_login_at
- * @property string $password write-only password
- */
-
-
-
-class User extends ActiveRecord implements IdentityInterface
-{
-
-    public $curr_login_at;
-    const STATUS_DELETED = 0;
-    const STATUS_ACTIVE = 10;
-
-
-    /**
-     * @inheritdoc
-     */
-    public static function tableName()
-    {
-        return '{{%user}}';
-    }
-
-    /**
-     * @inheritdoc
-     */
-    public function behaviors()
-    {
-        return [
-            TimestampBehavior::className(),
-        ];
-    }
-
-    # 生成access_token
-    public function generateAccessToken()
-    {
-        $this->access_token = Yii::$app->security->generateRandomString();
-    }
-
-    /**
-     * @inheritdoc
-     */
-    public function rules()
-    {
-        return [
-            ['status', 'default', 'value' => self::STATUS_ACTIVE],
-            ['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_DELETED]],
-        ];
-    }
-
-    /**
-     * @inheritdoc
-     */
-    public static function findIdentity($id)
-    {
-        return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]);
-    }
-
-
-
-
-    public static function findIdentityByAccessToken($token, $type = null)
-    {
-
-        return static::findOne(['access_token' => $token]);
-    }
-
-    /**
-     * Finds user by username
-     *
-     * @param string $username
-     * @return static|null
-     */
-    public static function findByUsername($username)
-    {
-        return static::findOne(['username' => $username, 'status' => self::STATUS_ACTIVE]);
-    }
-
-    /**
-     * Finds user by password reset token
-     *
-     * @param string $token password reset token
-     * @return static|null
-     */
-    public static function findByPasswordResetToken($token)
-    {
-        if (!static::isPasswordResetTokenValid($token)) {
-            return null;
-        }
-
-        return static::findOne([
-            'password_reset_token' => $token,
-            'status' => self::STATUS_ACTIVE,
-        ]);
-    }
-
-    /**
-     * Finds out if password reset token is valid
-     *
-     * @param string $token password reset token
-     * @return bool
-     */
-    public static function isPasswordResetTokenValid($token)
-    {
-        if (empty($token)) {
-            return false;
-        }
-
-        $timestamp = (int) substr($token, strrpos($token, '_') + 1);
-        $expire = Yii::$app->params['user.passwordResetTokenExpire'];
-        return $timestamp + $expire >= time();
-    }
-
-    /**
-     * @inheritdoc
-     */
-    public function getId()
-    {
-        return $this->getPrimaryKey();
-    }
-
-    /**
-     * @inheritdoc
-     */
-    public function getAuthKey()
-    {
-        return $this->auth_key;
-    }
-
-    /**
-     * @inheritdoc
-     */
-    public function validateAuthKey($authKey)
-    {
-        return $this->getAuthKey() === $authKey;
-    }
-
-    /**
-     * Validates password
-     *
-     * @param string $password password to validate
-     * @return bool if password provided is valid for current user
-     */
-    public function validatePassword($password)
-    {
-
-
-        return Yii::$app->security->validatePassword($password, $this->password_hash);
-    }
-
-    /**
-     * Generates password hash from password and sets it to the model
-     *
-     * @param string $password
-     */
-    public function setPassword($password)
-    {
-        $this->password_hash = Yii::$app->security->generatePasswordHash($password);
-    }
-
-    /**
-     * Generates "remember me" authentication key
-     */
-    public function generateAuthKey()
-    {
-        $this->auth_key = Yii::$app->security->generateRandomString();
-    }
-
-    /**
-     * Generates new password reset token
-     */
-    public function generatePasswordResetToken()
-    {
-        $this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time();
-    }
-
-    /**
-     * Removes password reset token
-     */
-    public function removePasswordResetToken()
-    {
-        $this->password_reset_token = null;
-    }
-}

+ 0 - 43
api/models/Goods.php

@@ -1,43 +0,0 @@
-<?php
-
-namespace api\models;
-
-use Yii;
-
-/**
- * This is the model class for table "goods".
- *
- * @property int $id
- * @property string $name
- */
-class Goods extends \yii\db\ActiveRecord
-{
-    /**
-     * @inheritdoc
-     */
-    public static function tableName()
-    {
-        return 'goods';
-    }
-
-    /**
-     * @inheritdoc
-     */
-    public function rules()
-    {
-        return [
-            [['name'], 'string', 'max' => 100],
-        ];
-    }
-
-    /**
-     * @inheritdoc
-     */
-    public function attributeLabels()
-    {
-        return [
-            'id' => 'ID',
-            'name' => 'Name',
-        ];
-    }
-}

+ 26 - 0
api/models/User.php

@@ -0,0 +1,26 @@
+<?php
+
+namespace api\models;
+
+use Yii;
+
+class User extends \yii\db\ActiveRecord
+{
+    /**
+     * @inheritdoc
+     */
+    public static function tableName()
+    {
+        return 'user';
+    }
+
+    /**
+     * @inheritdoc
+     */
+    public function rules()
+    {
+        return [
+            [['name'], 'string', 'max' => 100],
+        ];
+    }
+}

+ 1 - 1
api/modules/v1/controllers/GoodsController.php

@@ -6,7 +6,7 @@ use yii\rest\ActiveController;
 
 class GoodsController extends ActiveController
 {
-    public $modelClass = 'api\models\Goods';
+    public $modelClass = 'api\models\User';
 
 
     public function actionIndex()

+ 2 - 0
api/modules/v1/controllers/SiteController.php

@@ -8,6 +8,8 @@ use yii\rest\Controller;
  */
 class SiteController extends ActiveController
 {
+	public $modelClass = 'api\models\user';
+
     public function actionIndex()
     {
         \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;

+ 4 - 0
api/web/.htaccess

@@ -0,0 +1,4 @@
+RewriteEngine On
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteCond %{REQUEST_FILENAME} !-d
+RewriteRule . index.php

+ 27 - 0
backend/controllers/BaseController.php

@@ -0,0 +1,27 @@
+<?php
+namespace backend\controllers;
+
+use yii\web\Controller;
+
+/**
+ * Class BaseController
+ * @package backend\controllers
+ */
+class BaseController extends Controller
+{
+	public function init()
+	{
+		\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
+		parent::init();
+	}
+
+
+	public function beforeAction($action)
+	{
+		//todo
+		/*if (Yii::$app->user->isGuest) {
+
+		}*/
+		return true;
+	}
+}

+ 131 - 0
backend/controllers/MessageController.php

@@ -0,0 +1,131 @@
+<?php
+namespace backend\controllers;
+
+use common\logic\MQMessage\Message;
+use Yii;
+
+class MessageController extends BaseController
+{
+	/**
+	 * 发送消息 (接受多条)
+	 * @author: libingke
+	 */
+	public function actionSend()
+	{
+		//oauth 验证 todo
+
+		//获取接收参数  利用model验证或者判断
+		$params = Yii::$app->request->post();
+		$post = [
+			'message' => 'message 1',
+			'queue' => 'task_queue',
+		];
+
+		try {
+			$model = new Message();
+			$data = $model->send($post['message'], $post['queue']);
+
+			$result = ['code' => 200, 'message' => Yii::t('common', 'OK'), 'data' => $data];
+
+		} catch (\common\logic\MQMessage\Exception $e) {
+			$result = ['code' => $e->getCode(), 'message' => $e->getMessage(), 'data' => []];
+		}
+
+		return $result;
+	}
+
+	/**
+	 * 发送消息 (接受多条)
+	 * @author: libingke
+	 */
+	public function actionBatchSend()
+	{
+		//$params = Yii::$app->request->post();
+		$post = [
+			'messages' => ['message 1', 'message 2'],
+			'queue' => 'task_queue',
+		];
+
+		try {
+			$model = new Message();
+			$data = $model->batchSend($post['messages'], $post['queue']);
+
+			$result = ['code' => 200, 'message' => Yii::t('common', 'OK'), 'data' => $data];
+
+		} catch (\common\logic\MQMessage\Exception $e) {
+			$result = ['code' => $e->getCode(), 'message' => $e->getMessage(), 'data' => []];
+		}
+
+		return $result;
+	}
+
+	/**
+	 * 消费消息
+	 * @author: libingke
+	 */
+	public function actionReceive()
+	{
+		//$params = Yii::$app->request->post();
+		$post = [
+			'message' => 'message 1',
+			'queue' => 'task_queue',
+		];
+
+		try {
+			$model = new Message();
+			$data = $model->receive($post['queue'], $post['message']);
+
+			$result = ['code' => 200, 'message' => Yii::t('common', 'OK'), 'data' => $data];
+
+		} catch (\common\logic\MQMessage\Exception $e) {
+			$result = ['code' => $e->getCode(), 'message' => $e->getMessage(), 'data' => []];
+		}
+
+		return $result;
+
+	}
+
+	/**
+	 * 批量消费消息
+	 * @author: libingke
+	 */
+	public function actionBatchReceive()
+	{
+		//$params = Yii::$app->request->post();
+		$post = [
+			'messages' => ['message 1', 'message 2'],
+			'queue' => 'task_queue',
+		];
+
+		try {
+			$model = new Message();
+			$data = $model->batchReceive($post['queue'], $post['messages']);
+
+			$result = ['code' => 200, 'message' => Yii::t('common', 'OK'), 'data' => $data];
+
+		} catch (\common\logic\MQMessage\Exception $e) {
+			$result = ['code' => $e->getCode(), 'message' => $e->getMessage(), 'data' => []];
+		}
+
+		return $result;
+
+	}
+
+	/**
+	 * 删除消息
+	 * @author: libingke
+	 */
+    public function actionDelete()
+    {
+
+    }
+
+	/**
+	 * 批量删除消息
+	 * @author: libingke
+	 */
+	public function actionBatchDelete()
+	{
+
+	}
+}

+ 4 - 0
backend/web/.htaccess

@@ -0,0 +1,4 @@
+RewriteEngine On
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteCond %{REQUEST_FILENAME} !-d
+RewriteRule . index.php

+ 1 - 0
common/config/.gitignore

@@ -1,3 +1,4 @@
 main-local.php
 params-local.php
 test-local.php
+db-local.php

+ 2 - 2
common/config/db-local.php

@@ -2,8 +2,8 @@
 
 return [
     'class' => 'yii\db\Connection',
-    'dsn' => 'mysql:host=localhost;dbname=advance',
+    'dsn' => 'mysql:host=121.196.226.188;dbname=log_system',
     'username' => 'root',
-    'password' => 'root',
+    'password' => 'bty8QFR29',
     'charset' => 'utf8',
 ];

+ 13 - 0
common/config/main.php

@@ -19,5 +19,18 @@ return [
 
 
         ],
+
+		'i18n' => [
+			'translations' => [
+				'*' => [
+					'class' => 'yii\i18n\PhpMessageSource',
+					'basePath'=>'@common/messages',
+					'fileMap' => [
+						'common' => 'common.php',
+						'error'	 => 'errorCode.php',
+					],
+				],
+			],
+		],
     ],
 ];

+ 18 - 0
common/logic/MQMessage/Config.php

@@ -0,0 +1,18 @@
+<?php
+namespace common\logic\MQMessage;
+
+/**
+ * 连接配置
+ * Class Config
+ * @package common\logic\message
+ */
+class Config
+{
+	CONST HOST = "121.196.226.188";
+
+	CONST PORT = 5672;
+
+	CONST USER = "lbk";
+
+	CONST PASS = "123456";
+}

+ 12 - 0
common/logic/MQMessage/Exception.php

@@ -0,0 +1,12 @@
+<?php
+namespace common\logic\MQMessage;
+
+use PhpAmqpLib\Exception\AMQPProtocolChannelException as BaseException;
+
+/**
+ * Class Exception
+ * @package common\logic\message
+ */
+class Exception extends BaseException
+{
+}

+ 207 - 0
common/logic/MQMessage/Message.php

@@ -0,0 +1,207 @@
+<?php
+
+namespace common\logic\MQMessage;
+
+use PhpAmqpLib\Message\AMQPMessage;
+use PhpAmqpLib\Connection\AMQPStreamConnection;
+
+/**
+ * 处理消息体逻辑
+ * Class Message
+ * @package common\logic\MQMessage
+ */
+class Message extends Config
+{
+    private $connection;
+
+    private $channel;
+
+    private $callback_queue;
+
+    private $response = null;
+
+    private $corr_id;
+
+    private $result = '';
+
+    public function __construct()
+	{
+        $this->connection = new AMQPStreamConnection(
+        	self::HOST,
+			self::PORT,
+			self::USER,
+			self::PASS
+		);
+
+		$this->channel = $this->connection->channel();
+		list($this->callback_queue, ,) = $this->channel->queue_declare(
+			'', false, false, true, false
+		);
+
+		$this->channel->basic_consume(
+			$this->callback_queue, '', false, false, false, false,
+			array($this, 'on_response')
+		);
+    }
+
+	/**
+	 * [发送信息]
+	 * @author: libingke
+	 * @param string $body 消息主体
+	 * @param string $routing_key
+	 * @return array 返回数据
+	 */
+	public function send($body, $routing_key = 'task_queue')
+	{
+		$properties = [
+			'correlation_id' => uniqid(),
+			'reply_to' => $this->callback_queue
+		];
+
+		if (is_string($body)) {
+			$msg = new AMQPMessage( (string) $body,$properties);
+			$this->result = $this->channel->basic_publish($msg, '', $routing_key);
+		}
+
+		$this->channel->close();
+		$this->connection->close();
+
+		return $this->result;
+	}
+
+
+	/**
+	 * [批量发送信息]
+	 * @author: libingke
+	 * @param string $body 消息主体
+	 * @param string $routing_key
+	 * @return array 返回数据
+	 */
+	public function batchSend($body, $routing_key = '')
+	{
+		$properties = [
+			'correlation_id' => uniqid(),
+			'reply_to' => $this->callback_queue
+		];
+
+		if (is_array($body)) {
+			$msg = new AMQPMessage((string) $body, $properties);
+			$this->result = $this->channel->batch_basic_publish($msg, '', $routing_key);
+		}
+
+		$this->channel->close();
+		$this->connection->close();
+
+		return $this->result;
+	}
+
+	/**
+	 * [消费信息]
+	 * @author: libingke
+	 * @param string $queue 队列名称
+	 * @param string $str
+	 * @return array 返回数据
+	 */
+	public function receive($queue, $str)
+	{
+		$callback = function($msg) {
+			echo " [x] Received ", $msg->body, "\n";
+		};
+
+		$this->result = $this->channel->basic_consume($queue, '', false, true, false, false, $callback);
+
+		while(count($this->channel->callbacks)) {
+			$this->channel->wait();
+		}
+
+		return $this->result;
+	}
+
+	/**
+	 * [批量消费信息]
+	 * @author: libingke
+	 * @param string $queue 队列名称
+	 * @param string $arr
+	 * @return array 返回数据
+	 */
+	public function batchReceive($queue, $arr)
+	{
+		$callback = function($msg) {
+			echo " [x] Received ", $msg->body, "\n";
+		};
+
+		$this->result = $this->channel->basic_consume($queue, '', false, true, false, false, $callback);
+
+		while(count($this->channel->callbacks)) {
+			$this->channel->wait();
+		}
+
+		return $this->result;
+	}
+
+	/**
+	 * [删除信息]
+	 * @author: libingke
+	 */
+	public function delete()
+	{
+
+	}
+
+	public function on_response($rep)
+	{
+		if($rep->get('correlation_id') == $this->corr_id) {
+			$this->result .= $rep->body;
+			$this->response = $rep->body;
+		}
+	}
+
+    public static function CallMq($n)
+	{
+
+        $connection =   new AMQPStreamConnection(
+            self::HOST, self::PORT, self::USER, self::PASS
+		);
+        $channel = $connection->channel();
+
+        $channel->queue_declare('task_queue', false, true, false, false);
+
+        $data=empty($n)?"Hello World!":$n;
+
+        $msg = new AMQPMessage($data,
+            array('delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT)
+        );
+
+        $channel->basic_publish($msg, '', 'task_queue');
+
+        $channel->close();
+        $connection->close();
+
+        return true;
+    }
+
+
+    public static function CallUserMq($n)
+	{
+
+        $connection =   new AMQPStreamConnection(
+            self::HOST, self::PORT, self::USER, self::PASS
+		);
+        $channel = $connection->channel();
+
+        $channel->queue_declare('login', false, true, false, false);
+
+        $data=empty($n)?"Hello World!":$n;
+
+        $msg = new AMQPMessage($data,
+            array('delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT)
+        );
+
+        $channel->basic_publish($msg, '', 'login');
+
+        $channel->close();
+        $connection->close();
+
+        return true;
+    }
+}

+ 3 - 0
common/messages/common.php

@@ -0,0 +1,3 @@
+<?php
+
+return [];

+ 108 - 0
components/RabbitMQ/PhpClient.php

@@ -0,0 +1,108 @@
+<?php
+
+namespace components\RabbitMQ;
+
+use PhpAmqpLib\Message\AMQPMessage;
+use PhpAmqpLib\Connection\AMQPStreamConnection;
+
+class PhpClient
+{
+    private $connection;
+    private $channel;
+    private $callback_queue;
+    private $response;
+    private $corr_id;
+    private $result = '';
+
+	CONST HOST = "121.196.226.188";
+
+    CONST PORT = 5672;
+    CONST USER = "lbk";
+    CONST PASS = "123456";
+
+    public function __construct()
+	{
+        $this->connection = new AMQPStreamConnection(
+            self::HOST, self::PORT, self::USER, self::PASS); //建立连接
+
+        $this->channel = $this->connection->channel();
+        list($this->callback_queue, ,) = $this->channel->queue_declare(
+            "", false, false, true, false);
+
+        $this->channel->basic_consume(
+            $this->callback_queue, '', false, false, false, false,
+            array($this, 'on_response'));
+    }
+
+    public function on_response($rep) {
+        if($rep->get('correlation_id') == $this->corr_id) {
+            $this->result .= $rep->body;
+            $this->response = $rep->body;
+        }
+    }
+
+    public function call($n) {
+        $this->response = null;
+        $this->corr_id = uniqid();
+
+        $msg = new AMQPMessage(
+            (string) $n,
+            array('correlation_id' => $this->corr_id,
+                'reply_to' => $this->callback_queue)
+        );
+        $this->channel->basic_publish($msg, '', 'test'); //这里的queue是消息名称
+
+		var_dump($this->response, $this->result);die;
+
+        while($this->response != "end") {
+            $this->channel->wait();
+        }
+        return $this->result;
+    }
+
+
+    public static function CallMq($n){
+
+        $connection =   new AMQPStreamConnection(
+            self::HOST, self::PORT, self::USER, self::PASS); //建立连接
+        $channel = $connection->channel();
+
+        $channel->queue_declare('task_queue', false, true, false, false);
+
+        $data=empty($n)?"Hello World!":$n;
+
+        $msg = new AMQPMessage($data,
+            array('delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT)
+        );
+
+        $channel->basic_publish($msg, '', 'task_queue');
+
+        $channel->close();
+        $connection->close();
+
+        return true;
+    }
+
+
+    public static function CallUserMq($n){
+
+        $connection =   new AMQPStreamConnection(
+            self::HOST, self::PORT, self::USER, self::PASS); //建立连接
+        $channel = $connection->channel();
+
+        $channel->queue_declare('login', false, true, false, false);
+
+        $data=empty($n)?"Hello World!":$n;
+
+        $msg = new AMQPMessage($data,
+            array('delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT)
+        );
+
+        $channel->basic_publish($msg, '', 'login');
+
+        $channel->close();
+        $connection->close();
+
+        return true;
+    }
+}

+ 13 - 0
environments/dev/api/config/main-local.php

@@ -0,0 +1,13 @@
+<?php
+
+$config = [
+	'components' => [
+		'db' =>   require __DIR__ . '/../../common/config/db-local.php',
+		'request' => [
+			// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
+			'cookieValidationKey' => '',
+		],
+	]
+];
+
+return $config;

+ 3 - 0
environments/dev/api/config/params-local.php

@@ -0,0 +1,3 @@
+<?php
+return [
+];

+ 18 - 0
environments/dev/api/web/index-test.php

@@ -0,0 +1,18 @@
+<?php
+
+// NOTE: Make sure this file is not accessible when deployed to production
+if (!in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'])) {
+    die('You are not allowed to access this file.');
+}
+
+defined('YII_DEBUG') or define('YII_DEBUG', true);
+defined('YII_ENV') or define('YII_ENV', 'test');
+
+require __DIR__ . '/../../vendor/autoload.php';
+require __DIR__ . '/../../vendor/yiisoft/yii2/Yii.php';
+require __DIR__ . '/../../common/config/bootstrap.php';
+require __DIR__ . '/../config/bootstrap.php';
+
+$config = require __DIR__ . '/../config/test-local.php';
+
+(new yii\web\Application($config))->run();

+ 17 - 0
environments/dev/api/web/index.php

@@ -0,0 +1,17 @@
+<?php
+defined('YII_DEBUG') or define('YII_DEBUG', true);
+defined('YII_ENV') or define('YII_ENV', 'dev');
+
+require __DIR__ . '/../../vendor/autoload.php';
+require __DIR__ . '/../../vendor/yiisoft/yii2/Yii.php';
+require __DIR__ . '/../../common/config/bootstrap.php';
+require __DIR__ . '/../config/bootstrap.php';
+
+$config = yii\helpers\ArrayHelper::merge(
+    require __DIR__ . '/../../common/config/main.php',
+    require __DIR__ . '/../../common/config/main-local.php',
+    require __DIR__ . '/../config/main.php',
+    require __DIR__ . '/../config/main-local.php'
+);
+
+(new yii\web\Application($config))->run();

+ 2 - 0
environments/dev/api/web/robots.txt

@@ -0,0 +1,2 @@
+User-agent: *
+Disallow: /

+ 6 - 0
environments/index.php

@@ -36,6 +36,8 @@ return [
             'backend/web/assets',
             'frontend/runtime',
             'frontend/web/assets',
+			'api/runtime',
+			'api/web/assets',
         ],
         'setExecutable' => [
             'yii',
@@ -44,6 +46,7 @@ return [
         'setCookieValidationKey' => [
             'backend/config/main-local.php',
             'frontend/config/main-local.php',
+			'api/config/main-local.php',
         ],
     ],
     'Production' => [
@@ -53,6 +56,8 @@ return [
             'backend/web/assets',
             'frontend/runtime',
             'frontend/web/assets',
+			'api/runtime',
+			'api/web/assets',
         ],
         'setExecutable' => [
             'yii',
@@ -60,6 +65,7 @@ return [
         'setCookieValidationKey' => [
             'backend/config/main-local.php',
             'frontend/config/main-local.php',
+			'api/config/main-local.php',
         ],
     ],
 ];

+ 9 - 0
environments/prod/api/config/main-local.php

@@ -0,0 +1,9 @@
+<?php
+return [
+    'components' => [
+        'request' => [
+            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
+            'cookieValidationKey' => '',
+        ],
+    ],
+];

+ 3 - 0
environments/prod/api/config/params-local.php

@@ -0,0 +1,3 @@
+<?php
+return [
+];

+ 17 - 0
environments/prod/api/web/index.php

@@ -0,0 +1,17 @@
+<?php
+defined('YII_DEBUG') or define('YII_DEBUG', false);
+defined('YII_ENV') or define('YII_ENV', 'prod');
+
+require __DIR__ . '/../../vendor/autoload.php';
+require __DIR__ . '/../../vendor/yiisoft/yii2/Yii.php';
+require __DIR__ . '/../../common/config/bootstrap.php';
+require __DIR__ . '/../config/bootstrap.php';
+
+$config = yii\helpers\ArrayHelper::merge(
+    require __DIR__ . '/../../common/config/main.php',
+    require __DIR__ . '/../../common/config/main-local.php',
+    require __DIR__ . '/../config/main.php',
+    require __DIR__ . '/../config/main-local.php'
+);
+
+(new yii\web\Application($config))->run();

+ 2 - 0
environments/prod/api/web/robots.txt

@@ -0,0 +1,2 @@
+User-agent: *
+Disallow: /

+ 4 - 0
frontend/web/.htaccess

@@ -0,0 +1,4 @@
+RewriteEngine On
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteCond %{REQUEST_FILENAME} !-d
+RewriteRule . index.php