Skip to content

Commit d6400e9

Browse files
committed
MvcCore 4+ implementation (namespaces)
'Default' controllers and actions renamed to 'Index'
1 parent 107cc6d commit d6400e9

32 files changed

+232
-230
lines changed

.packager/config-phar.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"^/vendor/tracy/.*", // - tracy library (https://tracy.nette.org/)
2020
"^/vendor/tracy/tracy/(.*)/assets/", // excluded everything except staticly
2121
"^/vendor/tracy/tracy/tools/", // loaded PHP scripts by composer - added later
22-
"^/vendor/mvccore/ext-tracy.*", // - mvccore tracy adapter and all tracy panel extensions
22+
"^/vendor/mvccore/ext-debug-tracy.*", // - mvccore tracy adapter and all tracy panel extensions
2323
"^/vendor/mrclay/.*", // HTML/JS/CSS minify library
2424

2525
// Exclude source css and js files, use only what is generated in '/Var/Tmp' dir

.packager/config-php-preserve-hdd.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"^/vendor/autoload\.php", // composer autoload file
2929
"^/vendor/mvccore/mvccore/src/startup\.php",// mvccore autoload file
3030
"^/vendor/tracy/.*", // tracy library (https://tracy.nette.org/)
31-
"^/vendor/mvccore/ext-tracy.*", // mvccore tracy adapter and all tracy panel extensions
31+
"^/vendor/mvccore/ext-debug-tracy.*", // mvccore tracy adapter and all tracy panel extensions
3232
"^/vendor/nette/safe-stream.*", // nette safe stream used to complete assets in cache
3333
"^/vendor/mrclay/.*", // HTML/JS/CSS minify library
3434

@@ -39,10 +39,6 @@
3939
// include all scripts or files, where it's relative path from sourceDir match any of these rules:
4040
// (include paterns always overides exclude patterns)
4141
'includePatterns' => array(
42-
// include previously excluded SimpleForm validators - but only realy used validators
43-
"^/vendor/mvccore/simpleform/src/SimpleForm/Validators/(Maxlength|SafeString|NumberField|Integer|Url)\.php$",
44-
// include previously excluded SimpleForm fields - but only realy used fields
45-
"^/vendor/mvccore/simpleform/src/SimpleForm/(Text|Password|Hidden|SubmitButton|SubmitInput|Button|Number)\.php$",
4642
),
4743
// process simple strings replacements on all readed PHP scripts before saving into result package:
4844
// (replacements are executed before configured minification in RAM, they don't affect anythin on hard drive)

.packager/config-php-preserve-package.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"^/vendor/autoload\.php", // composer autoload file
2929
"^/vendor/mvccore/mvccore/src/startup\.php",// mvccore autoload file
3030
"^/vendor/tracy/.*", // tracy library (https://tracy.nette.org/)
31-
"^/vendor/mvccore/ext-tracy.*", // mvccore tracy adapter and all tracy panel extensions
31+
"^/vendor/mvccore/ext-debug-tracy.*", // mvccore tracy adapter and all tracy panel extensions
3232
"^/vendor/nette/safe-stream.*", // nette safe stream used to complete assets in cache
3333
"^/vendor/mrclay/.*", // HTML/JS/CSS minify library
3434

.packager/config-php-strict-hdd.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"^/vendor/autoload\.php", // composer autoload file
3131
"^/vendor/mvccore/mvccore/src/startup\.php",// mvccore autoload file
3232
"^/vendor/tracy/.*", // tracy library (https://tracy.nette.org/)
33-
"^/vendor/mvccore/ext-tracy.*", // mvccore tracy adapter and all tracy panel extensions
33+
"^/vendor/mvccore/ext-debug-tracy.*", // mvccore tracy adapter and all tracy panel extensions
3434
"^/vendor/nette/safe-stream.*", // nette safe stream used to complete assets in cache
3535
"^/vendor/mrclay/.*", // HTML/JS/CSS minify library
3636

.packager/config-php-strict-package.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"^/vendor/autoload\.php", // composer autoload file
2222
"^/vendor/mvccore/mvccore/src/startup\.php",// mvccore autoload file
2323
"^/vendor/tracy/.*", // tracy library (https://tracy.nette.org/)
24-
"^/vendor/mvccore/ext-tracy.*", // mvccore tracy adapter and all tracy panel extensions
24+
"^/vendor/mvccore/ext-debug-tracy.*", // mvccore tracy adapter and all tracy panel extensions
2525
"^/vendor/nette/safe-stream.*", // nette safe stream used to complete assets in cache
2626
"^/vendor/mrclay/.*", // HTML/JS/CSS minify library
2727

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MvcCore - Application - XML Documents
22

3-
[![Latest Stable Version](https://img.shields.io/badge/Stable-v3.2.0-brightgreen.svg?style=plastic)](https://github.com/mvccore/app-xmldocs/releases)
3+
[![Latest Stable Version](https://img.shields.io/badge/Stable-v4.0.0-brightgreen.svg?style=plastic)](https://github.com/mvccore/app-xmldocs/releases)
44
[![License](https://img.shields.io/badge/Licence-BSD-brightgreen.svg?style=plastic)](https://github.com/mvccore/app-xmldocs/blob/master/LICENCE.md)
55
[![Packager Build](https://img.shields.io/badge/Packager%20Build-passing-brightgreen.svg?style=plastic)](https://github.com/mvccore/packager)
66
![PHP Version](https://img.shields.io/badge/PHP->=5.3-brightgreen.svg?style=plastic)

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"require": {
2727
"php": ">=5.3.0",
2828
"mrclay/minify": "^2.2",
29-
"mvccore/packager": ">=2.1.7"
29+
"mvccore/packager": ">=2.1.11"
3030
},
3131
"minimum-stability": "dev"
3232
}

development/App/Bootstrap.php

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
<?php
22

3-
class App_Bootstrap {
3+
namespace App;
4+
5+
class Bootstrap {
46
public static function Init () {
5-
$app = MvcCore::GetInstance();
7+
$app = \MvcCore::GetInstance();
68

79
// patch core to use extended debug class
8-
if (class_exists('MvcCoreExt_Tracy')) {
9-
MvcCoreExt_Tracy::$Editor = 'MSVS2015';
10-
$app->SetDebugClass('MvcCoreExt_Tracy');
10+
if (class_exists('\MvcCore\Ext\Debug\Tracy')) {
11+
\MvcCore\Ext\Debug\Tracy::$Editor = 'MSVS2015';
12+
$app->SetDebugClass(\MvcCore\Ext\Debug\Tracy::class);
1113
}
1214

1315
$app
14-
->SetRouterClass(MvcCoreExt_LangRouter::class)
15-
->SetDefaultControllerName('Front_Index');
16+
->SetRouterClass(\MvcCore\Ext\Router\Lang::class)
17+
->SetDefaultControllerName('Front\Index');
1618

1719
// use this line only if you want to pack application without JS/CSS/fonts/images
1820
// inside package and you want to have all those files placed on hard drive manualy
1921
// you can use this variant in modes PHP_PRESERVE_PACKAGE, PHP_PRESERVE_HDD and PHP_STRICT_HDD
2022
//MvcCoreExt_ViewHelpers_Assets::SetAssetUrlCompletion(FALSE);
2123

22-
// add another view helper namespace
23-
MvcCore_View::AddHelpersClassBases('MvcCoreExt_ViewHelpers');
24-
25-
/** @var $router MvcCoreExt_LangRouter */
26-
$router = & MvcCore_Router::GetInstance();
24+
/** @var $router \MvcCore\Ext\Router\Lang */
25+
$router = & \MvcCore\Router::GetInstance();
2726
$router
2827
->SetAllowedLangs('en', 'cs')
2928
->SetFirstRequestStrictlyByUserAgent()
3029
->SetRoutes(array(
31-
'Admin_Index:Index' => array(
30+
'Admin\Index:Index' => array(
3231
'pattern' => "#^/admin#",
3332
),
34-
'Front_Index:Index' => new MvcCoreExt_LangRouter_Route(array(
35-
'name' => 'Front_Index:Index',
33+
'Front\Index:Index' => new \MvcCore\Ext\Router\Lang\Route(array(
34+
'controller' => 'Front\Index',
35+
'action' => 'Index',
3636
'pattern' => "#^([a-zA-Z0-9/_\-]*)#",
3737
'reverse' => '{%path}',
3838
)),

development/App/Controllers/Admin.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3-
class App_Controllers_Admin extends App_Controllers_Base
3+
namespace App\Controllers;
4+
5+
class Admin extends Base
46
{
57
public function PreDispatch () {
68
parent::PreDispatch();
@@ -10,8 +12,8 @@ public function PreDispatch () {
1012
}
1113
}
1214
private function _preDispatchSetUpBundles () {
13-
MvcCoreExt_ViewHelpers_Assets::SetGlobalOptions(
14-
(array) MvcCore_Config::GetSystem()->assets
15+
\MvcCore\Ext\View\Helpers\Assets::SetGlobalOptions(
16+
(array) \MvcCore\Config::GetSystem()->assets
1517
);
1618
$static = self::$staticPath;
1719
/*$this->view->Css('fixedHead')

development/App/Controllers/Admin/Index.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?php
22

3-
class App_Controllers_Admin_Index extends App_Controllers_Admin
3+
namespace App\Controllers\Admin;
4+
5+
use App\Controllers;
6+
7+
class Index extends Controllers\Admin
48
{
59
public function IndexAction () {
610
$this->view->Title = 'Admin';

development/App/Controllers/Base.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
22

3-
class App_Controllers_Base extends MvcCore_Controller
3+
namespace App\Controllers;
4+
5+
class Base extends \MvcCore\Controller
46
{
5-
/** @var App_Models_Translator */
7+
/** @var \App\Models\Translator */
68
protected static $translator;
79

810
/** @var string */
@@ -11,6 +13,6 @@ class App_Controllers_Base extends MvcCore_Controller
1113
public function Init () {
1214
parent::Init();
1315
$this->lang = $this->request->Lang;
14-
self::$translator = App_Models_Translator::GetInstance();
16+
self::$translator = \App\Models\Translator::GetInstance();
1517
}
1618
}

development/App/Controllers/Front.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
22

3-
class App_Controllers_Front extends App_Controllers_Base
3+
namespace App\Controllers;
4+
5+
class Front extends Base
46
{
5-
/** @var App_Models_Document */
7+
/** @var \App\Models\Document */
68
protected $document;
79

810
public function PreDispatch () {
@@ -14,8 +16,8 @@ public function PreDispatch () {
1416
}
1517
}
1618
private function _preDispatchSetUpBundles () {
17-
MvcCoreExt_ViewHelpers_Assets::SetGlobalOptions(
18-
(array) MvcCore_Config::GetSystem()->assets
19+
\MvcCore\Ext\View\Helpers\Assets::SetGlobalOptions(
20+
(array) \MvcCore\Config::GetSystem()->assets
1921
);
2022
$static = self::$staticPath;
2123
$this->view->Css('fixedHead')

development/App/Controllers/Front/Index.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?php
22

3-
class App_Controllers_Front_Index extends App_Controllers_Front
3+
namespace App\Controllers\Front;
4+
5+
use App\Controllers;
6+
7+
class Index extends Controllers\Front
48
{
59
public function Init () {
610
parent::Init();
@@ -31,16 +35,16 @@ protected function setUpDocument () {
3135
);
3236
}
3337
$documentPath = '/' . $this->lang . $path;
34-
$matchedDocs = App_Models_Document::GetByPath($documentPath, TRUE);
38+
$matchedDocs = \App\Models\Document::GetByPath($documentPath, TRUE);
3539
if (!$matchedDocs) {
36-
throw new Exception(
40+
throw new \Exception(
3741
"No matched document found in path: '$documentPath'.", 404
3842
);
3943
} else {
4044
$this->document = $matchedDocs[0];
4145
}
4246
} else {
43-
$this->document = new App_Models_Document;
47+
$this->document = new \App\Models\Document;
4448
}
4549
}
4650
}

development/App/Controllers/System.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<?php
22

3-
class App_Controllers_System extends App_Controllers_Base
3+
namespace App\Controllers;
4+
5+
class System extends Base
46
{
57
public function JsErrorsLogAction () {
68
$this->DisableView();
7-
if (MvcCore_Config::IsProduction()) return;
9+
if (\MvcCore\Config::IsProduction()) return;
810
$keys = array(
911
'message'=>1,
1012
'uri' => 1,
@@ -23,7 +25,7 @@ public function JsErrorsLogAction () {
2325
$data[$key] = $param;
2426
}
2527
$msg = json_encode($data);
26-
MvcCore_Debug::Log($msg, MvcCore_Debug::JAVASCRIPT);
28+
\MvcCore\Debug::Log($msg, \MvcCore\Debug::JAVASCRIPT);
2729
}
2830
private static function _hexToStr ($hex) {
2931
$string='';

development/App/Models/Base.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3-
class App_Models_Base extends MvcCore_Model
3+
namespace App\Models;
4+
5+
class Base extends \MvcCore\Model
46
{
57
public static function GetAllDbTables () {
68
$dbName = self::GetCfg()->dbname;
@@ -14,8 +16,8 @@ public static function GetAllDbTables () {
1416
TABLE_SCHEMA = :dbName
1517
");
1618
$select->execute(array('dbName' => $dbName));
17-
18-
$rawResult = $select->fetchAll(PDO::FETCH_ASSOC);
19+
20+
$rawResult = $select->fetchAll(\PDO::FETCH_ASSOC);
1921

2022
$result = array();
2123
foreach ($rawResult as $item) $result[] = $item['TableName'];

development/App/Models/Document.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

3-
class App_Models_Document extends App_Models_XmlModel
3+
namespace App\Models;
4+
5+
class Document extends XmlModel
46
{
57
protected static $dataPath = '/Var/Documents';
68
/**
@@ -12,11 +14,11 @@ class App_Models_Document extends App_Models_XmlModel
1214
* matching ordering digits at target xml file beginning.
1315
* @param string $path
1416
* @param bool $firstMatchOnly
15-
* @return App_Models_Document[]
17+
* @return \App\Models\Document[]
1618
*/
1719
public static function GetByPath ($path = '', $firstMatchOnly = FALSE) {
1820
$result = array();
19-
$xmlFullPath = MvcCore::GetInstance()->GetRequest()->AppRoot . static::$dataPath;
21+
$xmlFullPath = \MvcCore::GetInstance()->GetRequest()->AppRoot . static::$dataPath;
2022
$path = rtrim($path);
2123
$correctedPath = is_dir($xmlFullPath . '/' . ltrim($path, '/')) ? rtrim($path, '/') . '/index' : $path;
2224
$lastSlashPos = strrpos($correctedPath, '/');
@@ -27,7 +29,7 @@ public static function GetByPath ($path = '', $firstMatchOnly = FALSE) {
2729
$pathToMatch = "([0-9]*)\-" . substr($correctedPath, $lastSlashPos + 1);
2830
}
2931
if (!file_exists($xmlFullPath) && !is_dir($xmlFullPath)) return array();
30-
$di = new DirectoryIterator($xmlFullPath);
32+
$di = new \DirectoryIterator($xmlFullPath);
3133
foreach ($di as $item) {
3234
if ($item->isDir()) continue;
3335
if ($item->getExtension() != 'xml') continue;

development/App/Models/Translator.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?php
22

3-
class App_Models_Translator extends App_Models_Base
3+
namespace App\Models;
4+
5+
class Translator extends Base
46
{
57
protected $stores = array();
68
protected $autoInit = FALSE;
79
protected static $dataDir = '/Var/Translations';
810
public function Translate ($key = '', $lang = '') {
911
$result = $key;
10-
if (!$lang) $lang = App_Controllers_Base::$Lang;
12+
if (!$lang) $lang = \App\Controllers\Base::$Lang;
1113
$store = & $this->_getStore($lang);
1214
if (isset($store[$key])) {
1315
$result = $store[$key];
@@ -17,15 +19,15 @@ public function Translate ($key = '', $lang = '') {
1719
private function & _getStore ($lang) {
1820
if (!isset($this->stores[$lang])) {
1921
$store = array();
20-
$fileFullPath = MvcCore::GetInstance()->GetRequest()->AppRoot . self::$dataDir . '/' . $lang . '.csv';
21-
if (!file_exists($fileFullPath)) throw new Exception("[".__CLASS__."] No translations defined. (path: '$fileFullPath')");
22+
$fileFullPath = \MvcCore::GetInstance()->GetRequest()->AppRoot . self::$dataDir . '/' . $lang . '.csv';
23+
if (!file_exists($fileFullPath)) throw new \Exception("[".__CLASS__."] No translations defined. (path: '$fileFullPath')");
2224
$rawCsv = file_get_contents($fileFullPath);
2325
$rawCsvRows = explode("\n", str_replace("\r\n", "\n", $rawCsv));
2426
foreach ($rawCsvRows as $rowKey => $rawCsvRow) {
2527
list($key, $value) = str_getcsv($rawCsvRow, ";", '');
2628
if (isset($store[$key])) {
2729
$rowKey += 1;
28-
throw new Exception("[".__CLASS__."] Translation key already defined. (path: '$fileFullPath', row: '$rowKey', key: '$key')");
30+
throw new \Exception("[".__CLASS__."] Translation key already defined. (path: '$fileFullPath', row: '$rowKey', key: '$key')");
2931
}
3032
$store[$key] = str_replace('\\n', "\n", $value);
3133
}

0 commit comments

Comments
 (0)