mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-22 19:44:02 +08:00
request->getPost()兼容form和json格式
This commit is contained in:
parent
160700728e
commit
a231f63010
23
app/Library/Http/Request.php
Normal file
23
app/Library/Http/Request.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Library\Http;
|
||||
|
||||
use App\Exceptions\BadRequest;
|
||||
|
||||
class Request extends \Phalcon\Http\Request
|
||||
{
|
||||
|
||||
public function getPost($name = null, $filters = null, $defaultValue = null, $notAllowEmpty = false, $noRecursive = false)
|
||||
{
|
||||
$contentType = $this->getContentType();
|
||||
|
||||
if (stripos($contentType, 'form')) {
|
||||
return parent::getPost($name, $filters, $defaultValue, $notAllowEmpty, $noRecursive);
|
||||
} elseif (stripos($contentType, 'json')) {
|
||||
return $this->getPut($name, $filters, $defaultValue, $notAllowEmpty, $noRecursive);
|
||||
} else {
|
||||
throw new BadRequest('sys.invalid_content_type');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
19
app/Providers/Request.php
Normal file
19
app/Providers/Request.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Library\Http\Request as MyRequest;
|
||||
|
||||
class Request extends Provider
|
||||
{
|
||||
|
||||
protected $serviceName = 'request';
|
||||
|
||||
public function register()
|
||||
{
|
||||
$this->di->setShared($this->serviceName, function () {
|
||||
return new MyRequest();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -4,33 +4,43 @@ namespace App\Services\Frontend\Chapter;
|
||||
|
||||
use App\Models\Chapter as ChapterModel;
|
||||
use App\Models\User as UserModel;
|
||||
use Phalcon\Di as Di;
|
||||
use Phalcon\Events\Manager as EventsManager;
|
||||
|
||||
trait VoteTrait
|
||||
{
|
||||
|
||||
protected function incrAgreeCount(ChapterModel $chapter)
|
||||
{
|
||||
$this->getEventsManager->fire('chapterCounter:incrAgreeCount', $this, $chapter);
|
||||
$this->getPhEventsManager()->fire('chapterCounter:incrAgreeCount', $this, $chapter);
|
||||
}
|
||||
|
||||
protected function decrAgreeCount(ChapterModel $chapter)
|
||||
{
|
||||
$this->getEventsManager->fire('chapterCounter:decrAgreeCount', $this, $chapter);
|
||||
$this->getPhEventsManager()->fire('chapterCounter:decrAgreeCount', $this, $chapter);
|
||||
}
|
||||
|
||||
protected function incrOpposeCount(ChapterModel $chapter)
|
||||
{
|
||||
$this->getEventsManager->fire('chapterCounter:incrOpposeCount', $this, $chapter);
|
||||
$this->getPhEventsManager()->fire('chapterCounter:incrOpposeCount', $this, $chapter);
|
||||
}
|
||||
|
||||
protected function decrOpposeCount(ChapterModel $chapter)
|
||||
{
|
||||
$this->getEventsManager->fire('chapterCounter:decrOpposeCount', $this, $chapter);
|
||||
$this->getPhEventsManager()->fire('chapterCounter:decrOpposeCount', $this, $chapter);
|
||||
}
|
||||
|
||||
protected function incrUserDailyChapterVoteCount(UserModel $user)
|
||||
{
|
||||
$this->getEventsManager->fire('userDailyCounter:incrChapterVoteCount', $this, $user);
|
||||
$this->getPhEventsManager()->fire('userDailyCounter:incrChapterVoteCount', $this, $user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EventsManager
|
||||
*/
|
||||
protected function getPhEventsManager()
|
||||
{
|
||||
return Di::getDefault()->get('eventsManager');
|
||||
}
|
||||
|
||||
}
|
@ -4,33 +4,43 @@ namespace App\Services\Frontend\Comment;
|
||||
|
||||
use App\Models\Comment as CommentModel;
|
||||
use App\Models\User as UserModel;
|
||||
use Phalcon\Di as Di;
|
||||
use Phalcon\Events\Manager as EventsManager;
|
||||
|
||||
trait VoteTrait
|
||||
{
|
||||
|
||||
protected function incrAgreeCount(CommentModel $comment)
|
||||
{
|
||||
$this->getEventsManager->fire('commentCounter:incrAgreeCount', $this, $comment);
|
||||
$this->getPhEventsManager()->fire('commentCounter:incrAgreeCount', $this, $comment);
|
||||
}
|
||||
|
||||
protected function decrAgreeCount(CommentModel $comment)
|
||||
{
|
||||
$this->getEventsManager->fire('commentCounter:decrAgreeCount', $this, $comment);
|
||||
$this->getPhEventsManager()->fire('commentCounter:decrAgreeCount', $this, $comment);
|
||||
}
|
||||
|
||||
protected function incrOpposeCount(CommentModel $comment)
|
||||
{
|
||||
$this->getEventsManager->fire('commentCounter:incrOpposeCount', $this, $comment);
|
||||
$this->getPhEventsManager()->fire('commentCounter:incrOpposeCount', $this, $comment);
|
||||
}
|
||||
|
||||
protected function decrOpposeCount(CommentModel $comment)
|
||||
{
|
||||
$this->getEventsManager->fire('commentCounter:decrOpposeCount', $this, $comment);
|
||||
$this->getPhEventsManager()->fire('commentCounter:decrOpposeCount', $this, $comment);
|
||||
}
|
||||
|
||||
protected function incrUserDailyCommentVoteCount(UserModel $user)
|
||||
{
|
||||
$this->getEventsManager->fire('userDailyCounter:incrCommentVoteCount', $this, $user);
|
||||
$this->getPhEventsManager()->fire('userDailyCounter:incrCommentVoteCount', $this, $user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EventsManager
|
||||
*/
|
||||
protected function getPhEventsManager()
|
||||
{
|
||||
return Di::getDefault()->get('eventsManager');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,33 +4,43 @@ namespace App\Services\Frontend\Consult;
|
||||
|
||||
use App\Models\Consult as ConsultModel;
|
||||
use App\Models\User as UserModel;
|
||||
use Phalcon\Di as Di;
|
||||
use Phalcon\Events\Manager as EventsManager;
|
||||
|
||||
trait VoteTrait
|
||||
{
|
||||
|
||||
protected function incrAgreeCount(ConsultModel $consult)
|
||||
{
|
||||
$this->getEventsManager->fire('consultCounter:incrAgreeCount', $this, $consult);
|
||||
$this->getPhEventsManager()->fire('consultCounter:incrAgreeCount', $this, $consult);
|
||||
}
|
||||
|
||||
protected function decrAgreeCount(ConsultModel $consult)
|
||||
{
|
||||
$this->getEventsManager->fire('consultCounter:decrAgreeCount', $this, $consult);
|
||||
$this->getPhEventsManager()->fire('consultCounter:decrAgreeCount', $this, $consult);
|
||||
}
|
||||
|
||||
protected function incrOpposeCount(ConsultModel $consult)
|
||||
{
|
||||
$this->getEventsManager->fire('consultCounter:incrOpposeCount', $this, $consult);
|
||||
$this->getPhEventsManager()->fire('consultCounter:incrOpposeCount', $this, $consult);
|
||||
}
|
||||
|
||||
protected function decrOpposeCount(ConsultModel $consult)
|
||||
{
|
||||
$this->getEventsManager->fire('consultCounter:decrOpposeCount', $this, $consult);
|
||||
$this->getPhEventsManager()->fire('consultCounter:decrOpposeCount', $this, $consult);
|
||||
}
|
||||
|
||||
protected function incrUserDailyConsultVoteCount(UserModel $user)
|
||||
{
|
||||
$this->getEventsManager->fire('userDailyCounter:incrConsultVoteCount', $this, $user);
|
||||
$this->getPhEventsManager()->fire('userDailyCounter:incrConsultVoteCount', $this, $user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EventsManager
|
||||
*/
|
||||
protected function getPhEventsManager()
|
||||
{
|
||||
return Di::getDefault()->get('eventsManager');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,33 +4,43 @@ namespace App\Services\Frontend\Review;
|
||||
|
||||
use App\Models\Review as ReviewModel;
|
||||
use App\Models\User as UserModel;
|
||||
use Phalcon\Di as Di;
|
||||
use Phalcon\Events\Manager as EventsManager;
|
||||
|
||||
trait VoteTrait
|
||||
{
|
||||
|
||||
protected function incrAgreeCount(ReviewModel $review)
|
||||
{
|
||||
$this->getEventsManager->fire('reviewCounter:incrAgreeCount', $this, $review);
|
||||
$this->getPhEventsManager()->fire('reviewCounter:incrAgreeCount', $this, $review);
|
||||
}
|
||||
|
||||
protected function decrAgreeCount(ReviewModel $review)
|
||||
{
|
||||
$this->getEventsManager->fire('reviewCounter:decrAgreeCount', $this, $review);
|
||||
$this->getPhEventsManager()->fire('reviewCounter:decrAgreeCount', $this, $review);
|
||||
}
|
||||
|
||||
protected function incrOpposeCount(ReviewModel $review)
|
||||
{
|
||||
$this->getEventsManager->fire('reviewCounter:incrOpposeCount', $this, $review);
|
||||
$this->getPhEventsManager()->fire('reviewCounter:incrOpposeCount', $this, $review);
|
||||
}
|
||||
|
||||
protected function decrOpposeCount(ReviewModel $review)
|
||||
{
|
||||
$this->getEventsManager->fire('reviewCounter:decrOpposeCount', $this, $review);
|
||||
$this->getPhEventsManager()->fire('reviewCounter:decrOpposeCount', $this, $review);
|
||||
}
|
||||
|
||||
protected function incrUserDailyReviewVoteCount(UserModel $user)
|
||||
{
|
||||
$this->getEventsManager->fire('userDailyCounter:incrReviewVoteCount', $this, $user);
|
||||
$this->getPhEventsManager()->fire('userDailyCounter:incrReviewVoteCount', $this, $user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return EventsManager
|
||||
*/
|
||||
protected function getPhEventsManager()
|
||||
{
|
||||
return Di::getDefault()->get('eventsManager');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ use App\Providers\EventsManager as EventsManagerProvider;
|
||||
use App\Providers\Logger as LoggerProvider;
|
||||
use App\Providers\MetaData as MetaDataProvider;
|
||||
use App\Providers\Provider as AppProvider;
|
||||
use App\Providers\Request as RequestProvider;
|
||||
use App\Providers\Response as ResponseProvider;
|
||||
use App\Providers\Router as RouterProvider;
|
||||
use App\Providers\Security as SecurityProvider;
|
||||
@ -74,6 +75,7 @@ class HttpKernel extends Kernel
|
||||
EventsManagerProvider::class,
|
||||
LoggerProvider::class,
|
||||
MetaDataProvider::class,
|
||||
RequestProvider::class,
|
||||
ResponseProvider::class,
|
||||
RouterProvider::class,
|
||||
SecurityProvider::class,
|
||||
|
Loading…
x
Reference in New Issue
Block a user