Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
dxkite committed Jan 30, 2020
2 parents 15eb278 + bff4879 commit 9e1c42e
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 24 deletions.
12 changes: 0 additions & 12 deletions suda/src/application/debug/RequestDumper.php
Expand Up @@ -29,16 +29,4 @@ public function __construct(Application $application, Request $request, Response
parent::__construct($application, $context);
$this->response = $response;
}

/**
* @param Throwable $throwable
*/
public function dumpThrowable($throwable)
{
parent::dumpThrowable($throwable);
if ($this->response->isSend() === false) {
$this->response->sendContent($throwable);
$this->response->end();
}
}
}
7 changes: 3 additions & 4 deletions suda/src/application/template/ModuleTemplateBase.php
Expand Up @@ -210,10 +210,9 @@ protected function getModuleStaticAssetRoot(?string $module)
protected function prepareStaticModuleSource(?string $module, ?string $name = null)
{
$copySource = $this->application->conf('copy-static-source', SUDA_DEBUG);
if ($copySource) {
$static = $this->getModuleStaticPath($module, $name);
$staticCopyed = is_dir($static) && in_array($static, static::$copiedStaticPaths);
if ($staticCopyed === false) {
$static = $this->getModuleStaticPath($module, $name);
if ($copySource && is_dir($static)) {
if (in_array($static, static::$copiedStaticPaths) === false) {
$from = $static;
$to = $this->getModuleStaticOutputPath($module, $name);
$time = sprintf('copy template static source %s => %s ', $from, $to);
Expand Down
9 changes: 5 additions & 4 deletions suda/src/application/template/RawTemplate.php
Expand Up @@ -177,19 +177,20 @@ public function exec(string $name)
*/
public function getRenderedString()
{
if (file_exists($this->getPath())) {
$path = $this->getPath();
if (file_exists($path)) {
ob_start();
extract($this->value);
include $this->getPath();
include $path;
if ($this->extend) {
$this->include($this->extend);
}
return ob_get_clean() ?: '';
}
throw new NoTemplateFoundException(
'missing dest at ' . $this->getPath(),
'missing dest at ' . $path ,
E_USER_ERROR,
$this->getPath(),
$path ,
1
);
}
Expand Down
3 changes: 2 additions & 1 deletion suda/src/application/wrapper/TemplateWrapper.php
Expand Up @@ -20,6 +20,7 @@ class TemplateWrapper extends AbstractContentWrapper
public function getWrappedContent(Response $response):Stream
{
$content = $this->content;
return new StringStream($content->getRenderedString());
$text = $content->getRenderedString();
return new StringStream($text);
}
}
4 changes: 3 additions & 1 deletion suda/src/database/statement/QueryAccess.php
Expand Up @@ -134,7 +134,9 @@ protected function createPDOStatement(Connection $connection, Statement $stateme
$queryObj = $statement->getQuery();
$query = $connection->prefix($queryObj->getQuery());
if ($statement->isScroll()) {
$stmt = $connection->getPdo()->prepare($query, [PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL]);
$stmt = $connection->getPdo()->prepare($query, [
PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL
]);
} else {
$stmt = $connection->getPdo()->prepare($query);
}
Expand Down
4 changes: 3 additions & 1 deletion suda/src/database/struct/QueryStatement.php
Expand Up @@ -148,7 +148,9 @@ public function id():string
* @throws SQLException
*/
public function count() {
$totalQuery = new QueryStatement($this->getAccess(), sprintf("SELECT count(*) as count from (%s) as total", $this->getString()),
$query = $this->getString();
$query = preg_replace('/LIMIT\s+\d+(\s*,\s*\d+)?\s*$/ims', '', $query);
$totalQuery = new QueryStatement($this->getAccess(), sprintf("SELECT count(*) as count from (%s) as total", $query),
$this->getBinder());
$totalQuery->wantType(null);
$data = $totalQuery->one();
Expand Down
10 changes: 9 additions & 1 deletion suda/src/database/struct/ReadStatement.php
Expand Up @@ -120,7 +120,15 @@ public function fetchAll(?string $class = null, array $args = []): array
* @throws SQLException
*/
public function count() {
$totalQuery = new QueryStatement($this->getAccess(), sprintf("SELECT count(*) as count from (%s) as total", $this->getString()),
$query = clone $this;
$query->orderBy = '';
$query->limit = '';
$fields = $this->struct->all();
if (count($fields) > 0) {
$field = \array_shift($fields);
$query->read([$field->getName()]);
}
$totalQuery = new QueryStatement($this->getAccess(), sprintf("SELECT count(*) as count from (%s) as total", $query->getString()),
$this->getBinder());
$totalQuery->wantType(null);
$data = $totalQuery->one();
Expand Down
3 changes: 3 additions & 0 deletions suda/src/framework/loader/Path.php
Expand Up @@ -18,6 +18,9 @@ class Path
*/
public static function format(string $path):?string
{
if (strlen(trim($path)) === 0) {
return null;
}
return static::existCharset($path, ['GBK','GB2312','BIG5']);
}

Expand Down

0 comments on commit 9e1c42e

Please sign in to comment.