Skip to content

Commit 3195185

Browse files
authored
Merge pull request #79 from phpMv/techempower-benchmarks
Update to 2.3.2
2 parents 3d04ccc + cfc65f7 commit 3195185

File tree

9 files changed

+78
-52
lines changed

9 files changed

+78
-52
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unrelease]
88
- Nothing
9+
## [2.3.2] 2019-10-28
10+
### Added
11+
- bulk queries in `DAO` class
12+
- `DAO::toAdd($instance)`
13+
- `DAO::toUpdate($instance)`
14+
- `DAO::toDelete($instance)`
15+
- `DAO::flush()`
16+
- Composer create-project
17+
```
18+
composer create-project phpmv/ubiquity-project {projectName}
19+
```
20+
### Changed
21+
- `MicroTemplateEngine` optimization (cache)
22+
### Added
923
## [2.3.1] 2019-09-25
1024
### Added
1125
- `workerman` server

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
- Scaffolding
2222
- Console Admin interface (Devtools)
2323
- Assets & themes management (since 2.1.0, on a [proposal](https://github.com/phpMv/ubiquity/issues/11) from [@Gildonei](https://github.com/gildonei))
24-
- Managed servers: fpm/fastcgi with Apache or nginX, Swoole, PHP-PM with ReactPHP (Dev only)
24+
- Managed servers: fpm/fastcgi with Apache or nginX, [Workerman](https://github.com/walkor/Workerman), [Swoole](https://github.com/swoole/swoole-src), [PHP-PM](https://github.com/php-pm/php-pm) with ReactPHP (Dev only)
2525

2626
# Upgrade
2727
If Ubiquity devtools are already globally installed, and you want to upgrade to the lastest stable version:

src/Ubiquity/core/Framework.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use Ubiquity\utils\http\USession;
2222

2323
class Framework {
24-
public const version = '2.3.1';
24+
public const version = '2.3.2';
2525

2626
public static function getVersion() {
2727
return self::version;

src/Ubiquity/orm/DAO.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public static function getOne($className, $condition, $included = true, $paramet
134134
* @return object the instance loaded or null if not found
135135
*/
136136
public static function getById($className, $keyValues, $included = true, $useCache = NULL) {
137-
return self::_getOne ( self::getDb ( $className ), $className, self::getConditionParser ( $className, $keyValues ), $included, $useCache );
137+
return self::_getOne ( self::getDatabase ( self::$modelsDatabase [$className] ?? 'default'), $className, self::getConditionParser ( $className, $keyValues ), $included, $useCache );
138138
}
139139

140140
protected static function getConditionParser($className, $keyValues): ConditionParser {

src/Ubiquity/orm/parser/ConditionParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function setKeyValues($values) {
5858
} else {
5959
$this->params = [ ];
6060
foreach ( $values as $val ) {
61-
$this->addParams ( $val );
61+
$this->params [$val] = true;
6262
}
6363
}
6464
}

src/Ubiquity/utils/base/UIntrospection.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* This class is part of Ubiquity
88
*
99
* @author jcheron <[email protected]>
10-
* @version 1.0.5
10+
* @version 1.0.6
1111
*
1212
*/
1313
class UIntrospection {
@@ -34,7 +34,7 @@ public static function getLoadedViews(\ReflectionMethod $r, $lines) {
3434
if (isset ( $matches [1] )) {
3535
$result = array_merge ( $result, $matches [1] );
3636
}
37-
if (strpos ( $code, '$this->loadDefaultView' ) !== false || strpos ( $code, '$this->jquery->renderDefaultView' ) !== false) {
37+
if (\strpos ( $code, '$this->loadDefaultView' ) !== false || strpos ( $code, '$this->jquery->renderDefaultView' ) !== false) {
3838
$result [] = $r->getDeclaringClass ()->getShortName () . '/' . $r->getName () . '.html';
3939
}
4040
return $result;
@@ -80,7 +80,8 @@ public static function closure_dump(\Closure $c) {
8080
$sLine = $r->getStartLine ();
8181
$eLine = $r->getEndLine ();
8282
if ($eLine === $sLine) {
83-
$str .= \strstr ( \strstr ( $lines [$sLine - 1], "{" ), "}", true ) . "}";
83+
$match = \strstr ( $lines [$sLine - 1], "function" );
84+
$str .= \strstr ( \strstr ( $match, "{" ), "}", true ) . "}";
8485
} else {
8586
$str .= \strrchr ( $lines [$sLine - 1], "{" );
8687
for($l = $sLine; $l < $eLine - 1; $l ++) {

src/Ubiquity/views/View.php

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,85 +2,88 @@
22

33
namespace Ubiquity\views;
44

5-
use Ubiquity\utils\base\UString;
65
use Ubiquity\views\engine\TemplateEngine;
76
use Ubiquity\controllers\Startup;
87

98
/**
10-
* Represents a view
9+
* Represents a view.
10+
* Ubiquity\views$View
11+
* This class is part of Ubiquity
12+
*
1113
* @author jcheron <[email protected]>
12-
* @version 1.0.2
14+
* @version 1.0.3
1315
*
1416
*/
1517
class View {
1618
private $vars;
1719

1820
public function __construct() {
19-
$this->vars=array ();
21+
$this->vars = array ();
2022
}
2123

2224
protected function includeFileAsString($filename) {
23-
\ob_start();
25+
\ob_start ();
2426
include ($filename);
25-
return \ob_get_clean();
27+
return \ob_get_clean ();
2628
}
2729

2830
public function setVar($name, $value) {
29-
$this->vars[$name]=$value;
31+
$this->vars [$name] = $value;
3032
return $this;
3133
}
3234

3335
public function setVars($vars) {
34-
if (\is_array($vars))
35-
$this->vars=\array_merge($this->vars, $vars);
36+
if (\is_array ( $vars ))
37+
$this->vars = \array_merge ( $this->vars, $vars );
3638
else
37-
$this->vars=$vars;
39+
$this->vars = $vars;
3840
return $this;
3941
}
4042

4143
public function getVar($name) {
42-
if (\array_key_exists($name, $this->vars)) {
43-
return $this->vars[$name];
44+
if (\array_key_exists ( $name, $this->vars )) {
45+
return $this->vars [$name];
4446
}
4547
}
4648

4749
/**
4850
* affiche la vue $viewName
51+
*
4952
* @param string $viewName nom de la vue à charger
5053
* @param boolean $asString Si vrai, la vue n'est pas affichée mais retournée sous forme de chaîne (utilisable dans une variable)
5154
* @throws \Exception
5255
* @return string
5356
*/
54-
public function render($viewName, $asString=false) {
55-
$templateEngine=Startup::$templateEngine;
56-
$ext=\pathinfo($viewName, PATHINFO_EXTENSION);
57+
public function render($viewName, $asString = false) {
58+
$templateEngine = Startup::$templateEngine;
59+
$ext = \pathinfo ( $viewName, PATHINFO_EXTENSION );
5760
if ($ext === null)
58-
$viewName=$viewName . ".php";
59-
$data=$this->vars;
60-
if (!UString::endswith($viewName, ".php") && $templateEngine instanceof TemplateEngine) {
61-
return $templateEngine->render($viewName, $data, $asString);
61+
$viewName = $viewName . '.php';
62+
$data = $this->vars;
63+
if (\substr ( $viewName, - strlen ( '.php' ) ) !== '.php' && $templateEngine instanceof TemplateEngine) {
64+
return $templateEngine->render ( $viewName, $data, $asString );
6265
}
6366

64-
if (is_array($data)) {
65-
extract($data);
67+
if (\is_array ( $data )) {
68+
\extract ( $data );
6669
}
67-
$fileName=\ROOT . \DS . "views".\DS . $viewName;
68-
if(file_exists($fileName)){
70+
$fileName = \ROOT . \DS . 'views' . \DS . $viewName;
71+
if (\file_exists ( $fileName )) {
6972
if ($asString) {
70-
return $this->includeFileAsString($fileName);
73+
return $this->includeFileAsString ( $fileName );
7174
} else {
7275
include ($fileName);
7376
}
74-
}else{
75-
throw new \Exception("View {$viewName} not found!");
77+
} else {
78+
throw new \Exception ( "View {$viewName} not found!" );
7679
}
7780
}
78-
79-
public function getBlockNames($templateName){
80-
return Startup::$templateEngine->getBlockNames($templateName);
81+
82+
public function getBlockNames($templateName) {
83+
return Startup::$templateEngine->getBlockNames ( $templateName );
8184
}
82-
83-
public function getCode($templateName){
84-
return Startup::$templateEngine->getCode($templateName);
85+
86+
public function getCode($templateName) {
87+
return Startup::$templateEngine->getCode ( $templateName );
8588
}
8689
}

src/Ubiquity/views/engine/micro/MicroTemplateEngine.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,32 @@
33
namespace Ubiquity\views\engine\micro;
44

55
use Ubiquity\views\engine\TemplateEngine;
6-
use Ubiquity\controllers\Startup;
76
use Ubiquity\utils\base\UFileSystem;
87

98
class MicroTemplateEngine extends TemplateEngine {
109
private $viewsFolder;
10+
private $parsers = [ ];
11+
12+
private function getTemplateParser(string $viewName): TemplateParser {
13+
if (! isset ( $this->parsers [$viewName] )) {
14+
$this->parsers [$viewName] = new TemplateParser ( $this->viewsFolder . $viewName );
15+
}
16+
return $this->parsers [$viewName];
17+
}
1118

1219
public function __construct() {
13-
$this->viewsFolder = \ROOT . \DS . "views" . \DS;
20+
$this->viewsFolder = \ROOT . \DS . 'views' . \DS;
1421
}
1522

1623
/*
1724
* (non-PHPdoc)
1825
* @see TemplateEngine::render()
1926
*/
2027
public function render($viewName, $pData, $asString) {
21-
$config = Startup::getConfig (); // eventually used in template code
22-
$fileName = $this->viewsFolder . $viewName;
2328
if (\is_array ( $pData )) {
2429
\extract ( $pData );
2530
}
26-
$tpl = new TemplateParser ( $fileName );
27-
$content = eval ( '?>' . $tpl->__toString () );
31+
$content = eval ( '?>' . $this->getTemplateParser ( $viewName )->__toString () );
2832
if ($asString)
2933
return $content;
3034
else

src/Ubiquity/views/engine/micro/TemplateParser.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,29 @@
33
namespace Ubiquity\views\engine\micro;
44

55
/**
6-
* Moteur de template pour les fichiers d'extension phtml
7-
* @author jc
6+
* Micro template engine parser
7+
* Ubiquity\views\engine\micro$TemplateParser
8+
* This class is part of Ubiquity
9+
*
10+
* @author jcheron <[email protected]>
11+
* @version 1.0.1
812
*
913
*/
1014
class TemplateParser {
1115
private $fileContent;
1216

1317
public function __construct($fileName) {
14-
$this->fileContent=file_get_contents($fileName);
18+
$this->fileContent = $this->parse ( \file_get_contents ( $fileName ) );
1519
}
1620

1721
private function parse($html) {
18-
$startPoint='{{';
19-
$endPoint='}}';
20-
$result=preg_replace('/(' . preg_quote($startPoint) . ')(.*?)(' . preg_quote($endPoint) . ')/sim', '<?php echo $2 ?>', $html);
22+
$startPoint = '{{';
23+
$endPoint = '}}';
24+
$result = \preg_replace ( '/(' . \preg_quote ( $startPoint ) . ')(.*?)(' . \preg_quote ( $endPoint ) . ')/sim', '<?php echo $2 ?>', $html );
2125
return $result;
2226
}
2327

2428
public function __toString() {
25-
return $this->parse($this->fileContent);
29+
return $this->fileContent;
2630
}
2731
}

0 commit comments

Comments
 (0)