-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
1,319 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Cube package. | ||
* | ||
* (c) Slince <taosikai@yeah.net> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Jade; | ||
|
||
interface ContainerAwareInterface | ||
{ | ||
/** | ||
* Sets the container. | ||
* | ||
* @param ContainerInterface $container | ||
*/ | ||
public function setContainer(ContainerInterface $container); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the jade/jade package. | ||
* | ||
* (c) Slince <taosikai@yeah.net> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Jade; | ||
|
||
trait ContainerAwareTrait | ||
{ | ||
/** | ||
* @var ContainerInterface | ||
*/ | ||
protected $container; | ||
|
||
public function setContainer(ContainerInterface $container) | ||
{ | ||
$this->container = $container; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Cube package. | ||
* | ||
* (c) Slince <taosikai@yeah.net> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Jade; | ||
|
||
use Psr\Container\ContainerInterface as PsrContainerInterface; | ||
|
||
interface ContainerInterface extends PsrContainerInterface | ||
{ | ||
/** | ||
* 批量添加服务/参数 | ||
* | ||
* @param array $values | ||
*/ | ||
public function add(array $values); | ||
|
||
/** | ||
* 批量合并参数 | ||
* | ||
* @param array $values | ||
*/ | ||
public function merge(array $values); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the jade/jade package. | ||
* | ||
* (c) Slince <taosikai@yeah.net> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Jade\Controller; | ||
|
||
use Jade\ContainerAwareInterface; | ||
use Jade\ContainerAwareTrait; | ||
use Zend\Diactoros\Response; | ||
|
||
class Controller implements ContainerAwareInterface | ||
{ | ||
use ContainerAwareTrait; | ||
|
||
/** | ||
* 渲染模板 | ||
* @param string $view | ||
* @param array $parameters | ||
* @return string | ||
*/ | ||
protected function renderView($view, array $parameters = []) | ||
{ | ||
return $this->container->get('twig')->render($view, $parameters); | ||
} | ||
|
||
/** | ||
* 渲染模板 | ||
* | ||
* @param string $view | ||
* @param array $parameters | ||
* @return Response\HtmlResponse | ||
*/ | ||
protected function render($view, array $parameters = []) | ||
{ | ||
$content = $this->renderView($view, $parameters); | ||
return new Response\HtmlResponse($content); | ||
} | ||
|
||
/** | ||
* @param string $id | ||
* @return mixed | ||
*/ | ||
protected function get($id) | ||
{ | ||
return $this->container->get($id); | ||
} | ||
|
||
/** | ||
* Returns a JsonResponse that uses the serializer component if enabled, or json_encode. | ||
* | ||
* @final | ||
*/ | ||
protected function json($data, int $status = 200, array $headers = [], array $context = []) | ||
{ | ||
if ($this->container->has('serializer')) { | ||
$json = $this->container->get('serializer')->serialize($data, 'json', array_merge([ | ||
'json_encode_options' => Response\JsonResponse::DEFAULT_JSON_FLAGS, | ||
], $context)); | ||
} | ||
return new Response\JsonResponse($data, $status, $headers); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.