Skip to content

Commit 499a32e

Browse files
committed
cleanup codes
1 parent a5964a9 commit 499a32e

File tree

15 files changed

+312
-94
lines changed

15 files changed

+312
-94
lines changed

src/Containers/Modules.php

+5-9
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515

1616
// ------------------------------------------------------------------------
1717

18-
use O2System\Cache\Item;
1918
use O2System\Framework\Containers\Modules\DataStructures;
2019
use O2System\Framework\Services\Hooks;
21-
use O2System\Kernel\Cli\Writers\Format;
2220
use O2System\Kernel\Http\Message\Uri\Segments;
2321
use O2System\Kernel\Http\Router\Addresses;
2422
use O2System\Spl\DataStructures\SplArrayStack;
23+
use O2System\Spl\Exceptions\RuntimeException;
2524
use O2System\Spl\Info\SplNamespaceInfo;
26-
use Psr\Cache\CacheItemPoolInterface;
2725

2826
/**
2927
* Class Modules
@@ -90,8 +88,8 @@ private function autoload(DataStructures\Module $module)
9088

9189
// Add View Resource Directory
9290
if(services()->has('view')) {
93-
//view()->addFilePath($module->getResourcesDir());
94-
presenter()->assets->pushFilePath($module->getResourcesDir());
91+
view()->addFilePath($module->getResourcesDir());
92+
presenter()->assets->addFilePath($module->getResourcesDir());
9593

9694
// Initialize Presenter
9795
if($module->getType() === 'APP') {
@@ -489,6 +487,7 @@ public function find($segments, $register = false)
489487
*
490488
* @param $packageJsonFile
491489
* @return DataStructures\Module|bool Returns FALSE if failed.
490+
* @throws RuntimeException
492491
*/
493492
private function getPackageRegistry($packageJsonFile)
494493
{
@@ -497,12 +496,9 @@ private function getPackageRegistry($packageJsonFile)
497496
$packageJsonMetadata = json_decode(file_get_contents($packageJsonFile), true);
498497

499498
if (!is_array($packageJsonMetadata)) {
500-
return false;
499+
throw new RuntimeException('E_INVALID_JSON_MANIFEST');
501500
}
502501

503-
$modularType = strtoupper($packageJsonFileInfo['filename']);
504-
505-
506502
$moduleSegments = explode(
507503
DIRECTORY_SEPARATOR,
508504
trim(

src/Containers/Modules/DataStructures/Module.php

+22-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ public function __construct($dir)
7878
{
7979
parent::__construct($dir);
8080
$this->namespace = prepare_namespace(str_replace(PATH_ROOT, '', $dir), false);
81+
82+
if(is_file($moduleManifestFilePath = $dir . strtolower($this->getType()) . '.json')) {
83+
$moduleManifest = file_get_contents($moduleManifestFilePath);
84+
$this->properties = json_decode($moduleManifest, true);
85+
}
8186
}
8287

8388
// ------------------------------------------------------------------------
@@ -486,6 +491,13 @@ public function loadModel()
486491
}
487492
}
488493

494+
// ------------------------------------------------------------------------
495+
496+
/**
497+
* Module::getControllers
498+
*
499+
* @return array
500+
*/
489501
public function getControllers()
490502
{
491503
$controllers = [];
@@ -498,6 +510,12 @@ public function getControllers()
498510
);
499511

500512
foreach ($iterator as $file) {
513+
$fileDir = pathinfo($file->getRealPath(), PATHINFO_DIRNAME);
514+
$fileDir = str_replace(rtrim($directory, DIRECTORY_SEPARATOR), '', $fileDir);
515+
$fileDir = ltrim($fileDir, DIRECTORY_SEPARATOR);
516+
$fileDirParts = explode(DIRECTORY_SEPARATOR, $fileDir);
517+
$fileDirParts = array_filter($fileDirParts);
518+
501519
if (pathinfo($file, PATHINFO_EXTENSION) == "php") {
502520
$controllerClassName = str_replace([
503521
$directory,
@@ -512,15 +530,18 @@ public function getControllers()
512530
], $file->getRealPath());
513531

514532
$controller = new Module\Controller($namespace . $controllerClassName);
533+
$controller->depth = count($fileDirParts);
515534

516535
if ( ! empty($controller->name) and ! in_array($controller->getParameter(),
517536
['login', 'pages', 'setup', 'license'])) {
518-
$controllers[ $controller->getParameter() ] = $controller;
537+
$controllers[ $controller->getClass() ] = $controller;
519538
}
520539
}
521540
}
522541
}
523542

543+
ksort($controllers);
544+
524545
return $controllers;
525546
}
526547
}

src/Containers/Modules/DataStructures/Module/Controller.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ public function __construct($className)
9393
'settings',
9494
'setting',
9595
'sendError',
96-
'sendPayload'
96+
'sendPayload',
97+
'process'
9798
])) {
9899
$methodSegments = $segments;
99100

src/Framework.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
* By default development will show errors but testing and live will hide them.
2525
*/
2626

27-
use O2System\Kernel\Http\Message\Uri;
28-
2927
switch (strtoupper(ENVIRONMENT)) {
3028
case 'DEVELOPMENT':
3129
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
@@ -445,9 +443,9 @@ private function httpHandler()
445443
->setType('APP')
446444
->setNamespace('App\\');
447445
$this->modules->register($app);
448-
446+
449447
if($this->config->get('app') !== null) {
450-
$app = (new Framework\Containers\Modules\DataStructures\Module(PATH_APP . $this->config->get('app') . DIRECTORY_SEPARATOR))
448+
$app = (new Framework\Containers\Modules\DataStructures\Module(PATH_APP . studlycase($this->config->get('app')) . DIRECTORY_SEPARATOR))
451449
->setType('APP')
452450
->setNamespace('App\\' . studlycase($this->config->get('app')) . '\\');
453451
$this->modules->register($app);
@@ -608,7 +606,9 @@ private function httpHandler()
608606
if(empty($requestControllerOutput) or $requestControllerOutput === '') {
609607
output()->sendError(204);
610608
} else {
611-
output()->sendPayload($requestControllerOutput);
609+
output()->sendPayload([
610+
'output' => $requestControllerOutput
611+
]);
612612
}
613613
} elseif ($this->services->has('view')) {
614614
if (empty($requestControllerOutput) or $requestControllerOutput === '') {
@@ -647,4 +647,4 @@ private function httpHandler()
647647
output()->sendError(404);
648648
}
649649
}
650-
}
650+
}

src/Http/Controller.php

-9
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@
2222
*/
2323
class Controller extends \O2System\Kernel\Http\Controller
2424
{
25-
/**
26-
* Controller::$inherited
27-
*
28-
* Controller inherited flag.
29-
*
30-
* @var bool
31-
*/
32-
static public $inherited = false;
33-
3425
/**
3526
* Controller::__get
3627
*

src/Http/Controllers/Pages.php

-11
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,6 @@
2525
*/
2626
class Pages extends Controller
2727
{
28-
/**
29-
* Controller::$inherited
30-
*
31-
* Controller inherited flag.
32-
*
33-
* @var bool
34-
*/
35-
static public $inherited = true;
36-
37-
// ------------------------------------------------------------------------
38-
3928
/**
4029
* Pages::index
4130
*

src/Http/Presenter.php

+7
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ class Presenter extends AbstractRepository
7878
*/
7979
public $theme = false;
8080

81+
/**
82+
* Presenter::$favicon
83+
*
84+
* @var string
85+
*/
86+
public $favicon = 'default/icons/favicon.jpg';
87+
8188
// ------------------------------------------------------------------------
8289

8390
/**

src/Http/Router.php

+4-17
Original file line numberDiff line numberDiff line change
@@ -166,22 +166,10 @@ public function handle(KernelMessageUri $uri = null)
166166
*/
167167
if (class_exists($controllerClassName = $controllerNamespace . implode('\\',
168168
array_map('studlycase', $uriRoutedSegments)))) {
169-
170-
if ($controllerClassName::$inherited) {
171-
$uriSegments = array_diff($uriSegments, $uriRoutedSegments);
172-
$this->setController(new KernelControllerDataStructure($controllerClassName),
173-
$uriSegments);
174-
return true;
175-
break; // break modular
176-
break; // break routed uri segments
177-
} else {
178-
$uriSegments = array_diff($uriSegments, $uriRoutedSegments);
179-
$this->setController(new KernelControllerDataStructure($controllerClassName),
180-
$uriSegments);
181-
return true;
182-
break; // break modular
183-
break; // break routed uri segments
184-
}
169+
$uriSegments = array_diff($uriSegments, $uriRoutedSegments);
170+
$this->setController(new KernelControllerDataStructure($controllerClassName),
171+
$uriSegments);
172+
return true;
185173
}
186174
}
187175
}
@@ -308,7 +296,6 @@ final protected function getControllerClassName($className)
308296

309297
if (class_exists($controllerClassName)) {
310298
return $controllerClassName;
311-
break;
312299
}
313300
}
314301

src/Http/View.php

+44-9
Original file line numberDiff line numberDiff line change
@@ -335,23 +335,15 @@ public function getPageFilePath($filename)
335335
// Find without controller parameter as sub directory
336336
if (is_file($filePath = $pageDirectory . $filename . '.mobile' . $pageExtension)) {
337337
return realpath($filePath);
338-
break; // break extension
339-
break; // break directory
340338
} elseif (is_file($filePath = $pageDirectory . $filename . DIRECTORY_SEPARATOR . 'index.mobile' . $pageExtension)) {
341339
return realpath($filePath);
342-
break; // break extension
343-
break; // break directory
344340
}
345341
}
346342

347343
if (is_file($filePath = $pageDirectory . $filename . $pageExtension)) {
348344
return realpath($filePath);
349-
break; // break extension
350-
break; // break directory
351345
} elseif(is_file($filePath = $pageDirectory . $filename . DIRECTORY_SEPARATOR . 'index' . $pageExtension)) {
352346
return realpath($filePath);
353-
break; // break extension
354-
break; // break directory
355347
}
356348
}
357349
}
@@ -804,6 +796,9 @@ public function render(array $options = [])
804796
}
805797
}
806798

799+
// Microsoft TileImage
800+
presenter()->meta->offsetSet('msapplication-TileImage', images_url(pathinfo(presenter()->favicon, PATHINFO_DIRNAME) . '/144x144/' . pathinfo(presenter()->favicon, PATHINFO_BASENAME)));
801+
807802
if (presenter()->meta->count()) {
808803
$meta = presenter()->meta->getArrayCopy();
809804

@@ -841,9 +836,49 @@ public function render(array $options = [])
841836
*/
842837
$this->document->linkNodes->createElement([
843838
'rel' => 'manifest',
844-
'href' => '/manifest.json',
839+
'href' => base_url() . '/manifest.json',
840+
]);
841+
842+
/**
843+
* Injecting Favicons
844+
*/
845+
$this->document->linkNodes->createElement([
846+
'rel' => 'icon',
847+
'type' => 'image/jpg',
848+
'href' => images_url(pathinfo(presenter()->favicon, PATHINFO_DIRNAME) . '/' . pathinfo(presenter()->favicon, PATHINFO_BASENAME)),
845849
]);
846850

851+
$appleFavicons = [
852+
'57x57',
853+
'60x60',
854+
'72x72',
855+
'76x76',
856+
'114x114',
857+
'120x120',
858+
'144x144',
859+
'152x152',
860+
'180x180'
861+
];
862+
foreach($appleFavicons as $appleFavicon) {
863+
$this->document->linkNodes->createElement([
864+
'rel' => 'apple-touch-icon',
865+
'href' => images_url(pathinfo(presenter()->favicon, PATHINFO_DIRNAME) . '/'. $appleFavicon . '/' . pathinfo(presenter()->favicon, PATHINFO_BASENAME)),
866+
]);
867+
}
868+
869+
$androidFavicons = [
870+
'192x192',
871+
'32x32',
872+
'96x96',
873+
'16x16'
874+
];
875+
foreach($androidFavicons as $andoidFavicon) {
876+
$this->document->linkNodes->createElement([
877+
'rel' => 'icon',
878+
'href' => images_url(pathinfo(presenter()->favicon, PATHINFO_DIRNAME) . '/'. $andoidFavicon . '/' . pathinfo(presenter()->favicon, PATHINFO_BASENAME)),
879+
]);
880+
}
881+
847882
if(controller()->getReflection()->hasMethod('output')) {
848883
controller()->getInstance()->output($this->document);
849884
}

src/Models/Sql/Model.php

+8-10
Original file line numberDiff line numberDiff line change
@@ -343,16 +343,14 @@ public function __get($property)
343343
}
344344
}
345345

346-
if (empty($get[ $property ])) {
347-
if (services()->has($property)) {
348-
return services()->get($property);
349-
} elseif ($this->hasSubModel($property)) {
350-
return $this->loadSubModel($property);
351-
} elseif (o2system()->__isset($property)) {
352-
return o2system()->__get($property);
353-
} elseif (models()->__isset($property)) {
354-
return models()->get($property);
355-
}
346+
if (services()->has($property)) {
347+
return services()->get($property);
348+
} elseif ($this->hasSubModel($property)) {
349+
return $this->loadSubModel($property);
350+
} elseif (o2system()->__isset($property)) {
351+
return o2system()->__get($property);
352+
} elseif (models()->__isset($property)) {
353+
return models()->get($property);
356354
}
357355

358356
return false;

src/Models/Sql/System/Modules/Authorities.php

+21-1
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,32 @@ public function module()
4646
// ------------------------------------------------------------------------
4747

4848
/**
49-
* Actions::ownership
49+
* Authorities::ownership
5050
*
5151
* @return array|bool|\O2System\Framework\Models\Sql\DataObjects\Result\Row
5252
*/
5353
public function ownership()
5454
{
5555
return $this->morphTo();
5656
}
57+
58+
/**
59+
* Authorities::isChecked
60+
*
61+
* @return array|bool|\O2System\Framework\Models\Sql\DataObjects\Result\Row
62+
*/
63+
public function isChecked($module, $endpoint, $role, $permission)
64+
{
65+
$result = $this->findWhere([
66+
'id_sys_module' => $module,
67+
'endpoint' => $endpoint,
68+
'ownership_id' => $role,
69+
'permission' => $permission
70+
]);
71+
72+
if ($result->count())
73+
return true;
74+
75+
return false;
76+
}
5777
}

0 commit comments

Comments
 (0)