Skip to content

Commit cc8dcf7

Browse files
committed
changed a little templates hierarchy
1 parent 38503d6 commit cc8dcf7

File tree

10 files changed

+89
-43
lines changed

10 files changed

+89
-43
lines changed

app/base/abstracts/Commands/BaseCommand.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace App\Base\Abstracts\Commands;
1414

15+
use Degami\Basics\Exceptions\BasicException;
1516
use \Symfony\Component\Console\Command\Command as SymfonyCommand;
1617
use \Psr\Container\ContainerInterface;
1718
use \Dotenv\Dotenv;
@@ -45,6 +46,7 @@ class BaseCommand extends SymfonyCommand
4546
*
4647
* @param null $name
4748
* @param ContainerInterface|null $container
49+
* @throws BasicException
4850
*/
4951
public function __construct($name = null, ContainerInterface $container = null)
5052
{
@@ -57,6 +59,7 @@ public function __construct($name = null, ContainerInterface $container = null)
5759
* boostrap command
5860
*
5961
* @return void
62+
* @throws BasicException
6063
*/
6164
protected function bootstrap()
6265
{
@@ -111,18 +114,34 @@ protected function getQuestionHelper(): QuestionHelper
111114
/**
112115
* @param string $option_name
113116
* @param string $question_message
117+
* @param array|null $choices
114118
* @return bool|mixed|string|string[]|null
115119
*/
116-
protected function keepAskingForOption(string $option_name, string $question_message)
120+
protected function keepAskingForOption(string $option_name, string $question_message, array $choices = null)
117121
{
118122
if ($this->input == null || $this->output == null) {
119123
return null;
120124
}
121125

126+
if (is_array($choices)) {
127+
$choices = array_filter($choices, function ($el) {
128+
return stripos(",", $el) === false;
129+
});
130+
131+
if (empty($choices)) {
132+
$choices = null;
133+
}
134+
}
135+
122136
$value = $this->input->getOption($option_name);
123137
while (trim($value) == '') {
124138
$question = new Question($question_message);
125139
$value = $this->getQuestionHelper()->ask($this->input, $this->output, $question);
140+
141+
if (is_array($choices) && !in_array($value, $choices)) {
142+
$this->getIo()->error("Can be one of: ".implode(",", $choices));
143+
$value = '';
144+
}
126145
}
127146

128147
return $value;

app/base/tools/Plates/SiteBase.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,19 @@ public function getCurrentWebsite(): Website
8888
return $this->getSiteData()->getCurrentWebsite();
8989
}
9090

91+
/**
92+
* gets current website name
93+
*
94+
* @return string
95+
* @throws BasicException
96+
* @throws DependencyException
97+
* @throws NotFoundException
98+
*/
99+
public function getCurrentWebsiteName(): string
100+
{
101+
return $this->getCurrentWebsite()->getSiteName();
102+
}
103+
91104
/**
92105
* gets current locale
93106
*

app/site/commands/Mail/Test.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ protected function configure()
6767
* @throws DependencyException
6868
* @throws NotFoundException
6969
* @throws PhpfastcacheSimpleCacheException
70+
* @throws \Throwable
7071
*/
7172
protected function execute(InputInterface $input, OutputInterface $output)
7273
{
@@ -76,7 +77,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
7677
$this->getSiteData()->getSiteEmail(),
7778
$to,
7879
'Test Email from '.$this->getSiteData()->getCurrentWebsite()->getDomain(),
79-
'This is a test email to check functionality'
80+
'This is a test email to check functionality',
81+
'plain/text'
8082
);
8183

8284
$output->writeln("Mail sent. result:".var_export($out, true));

templates/admin/layout.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @var $current_user \App\Base\Abstracts\Models\AccountModel
55
* @var $controller \App\Base\Abstracts\Controllers\BaseHtmlPage
66
*/
7-
$this->layout('base::html', ['title' => $title] + get_defined_vars());?>
7+
$this->layout('base::page', ['title' => $title] + get_defined_vars());?>
88

99
<?php $this->start('head') ?>
1010
<link rel="stylesheet" type="text/css" href="<?php echo $this->sitebase()->assetUrl('/css/admin.css');?>">

templates/frontend/layout.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @var $title string
44
* @var $controller \App\Base\Abstracts\Controllers\BaseHtmlPage
55
*/
6-
$this->layout('base::html', ['title' => $title] + get_defined_vars()) ?>
6+
$this->layout('base::page', ['title' => $title] + get_defined_vars()) ?>
77

88
<?php $this->start('head') ?>
99
<link rel="stylesheet" type="text/css" href="<?php echo $this->sitebase()->assetUrl('/css/site.css');?>">

templates/html.php

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,18 @@
11
<?php
22
/**
3-
* @var $controller \App\Base\Abstracts\Controllers\BaseHtmlPage
43
* @var $title string
4+
* @var $lang string
5+
* @var $body_class string
56
*/
6-
/** @var \DebugBar\StandardDebugBar $debugbar */
7-
$debugbar = $this->sitebase()->getDebugbar();
8-
$debugbarRenderer = $debugbar->getJavascriptRenderer($this->sitebase()->getUrl('frontend.root').'debugbar');
9-
if (!isset($body_class)) {
10-
$body_class = "";
11-
}
7+
128
?><!doctype html>
13-
<html lang="<?= $this->sitebase()->getCurrentLocale() ?>">
9+
<html<?php if (!empty($lang)):?> lang="<?= $lang; ?>"<?php endif;?>>
1410
<head>
15-
<title><?= $this->sitebase()->translate($title)?></title>
1611
<meta charset="utf-8">
17-
<link rel="stylesheet" type="text/css" href="<?php echo $this->sitebase()->assetUrl('/bootstrap/css/bootstrap.min.css');?>" />
18-
<link rel="stylesheet" type="text/css" href="<?php echo $this->sitebase()->assetUrl('/jqueryui/themes/base/all.css');?>">
19-
<script type="text/javascript" src="<?php echo $this->sitebase()->assetUrl('/jquery/jquery.min.js');?>"></script>
20-
<meta name="viewport" content="minimum-scale=1.0, maximum-scale=1.0, width=device-width">
21-
<?= getenv('DEBUG') ? $debugbarRenderer->renderHead() : ''; ?>
12+
<title><?= $title ?></title>
2213
<?= $this->section('head'); ?>
23-
<?= $this->section('head_scripts'); ?>
2414
</head>
25-
<body class="<?= $body_class;?>">
26-
<?= $this->sitebase()->renderBlocks('after_body_open', $controller); ?>
15+
<body<?php if (!empty($body_class)):?> class="<?= $body_class;?>"<?php endif;?>>
2716
<?= $this->section('content'); ?>
28-
<script type="text/javascript" src="<?php echo $this->sitebase()->assetUrl('/jqueryui/jquery-ui.min.js');?>"></script>
29-
<script type="text/javascript" src="<?php echo $this->sitebase()->assetUrl('/bootstrap/js/bootstrap.min.js');?>"></script>
30-
<?= $this->section('scripts'); ?>
31-
<?= $this->section('styles'); ?>
32-
<?= getenv('DEBUG') ? $debugbarRenderer->render() : '' ?>
33-
<?= $this->sitebase()->renderBlocks('before_body_close', $controller); ?>
3417
</body>
3518
</html>

templates/mail.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
/**
3+
* @var $subject string
4+
*/
5+
6+
$lang = $lang ?? $this->sitebase()->getCurrentLocale();
7+
$title = $subject ?? $this->sitebase()->getCurrentWebsiteName();
8+
$this->layout('base::html', get_defined_vars()) ?>
9+
10+
<?= $this->section('content'); ?>

templates/mails/generic.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @var string $subject
44
* @var string $body
55
*/
6-
$this->layout('mails::mail_html', get_defined_vars()) ?>
6+
$this->layout('base::mail', get_defined_vars()) ?>
77

88
<?php $this->start('head') ?>
99
<link rel="stylesheet" type="text/css" href="<?php echo $this->sitebase()->assetUrl('/css/site.css');?>">

templates/mails/mail_html.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

templates/page.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* @var $controller \App\Base\Abstracts\Controllers\BaseHtmlPage
4+
* @var $title string
5+
*/
6+
/** @var \DebugBar\StandardDebugBar $debugbar */
7+
$debugbar = $this->sitebase()->getDebugbar();
8+
$debugbarRenderer = $debugbar->getJavascriptRenderer($this->sitebase()->getUrl('frontend.root').'debugbar');
9+
10+
$lang = $lang ?? $this->sitebase()->getCurrentLocale();
11+
$title = $this->sitebase()->translate($title);
12+
13+
$this->layout('base::html', get_defined_vars()) ?>
14+
15+
16+
<?php $this->start('head') ?>
17+
<link rel="stylesheet" type="text/css" href="<?php echo $this->sitebase()->assetUrl('/bootstrap/css/bootstrap.min.css');?>" />
18+
<link rel="stylesheet" type="text/css" href="<?php echo $this->sitebase()->assetUrl('/jqueryui/themes/base/all.css');?>">
19+
<script type="text/javascript" src="<?php echo $this->sitebase()->assetUrl('/jquery/jquery.min.js');?>"></script>
20+
<meta name="viewport" content="minimum-scale=1.0, maximum-scale=1.0, width=device-width">
21+
<?= getenv('DEBUG') ? $debugbarRenderer->renderHead() : ''; ?>
22+
<?= $this->section('head'); ?>
23+
<?= $this->section('head_scripts'); ?>
24+
<?php $this->stop() ?>
25+
26+
27+
<?= $this->sitebase()->renderBlocks('after_body_open', $controller); ?>
28+
<?= $this->section('content'); ?>
29+
<script type="text/javascript" src="<?php echo $this->sitebase()->assetUrl('/jqueryui/jquery-ui.min.js');?>"></script>
30+
<script type="text/javascript" src="<?php echo $this->sitebase()->assetUrl('/bootstrap/js/bootstrap.min.js');?>"></script>
31+
<?= $this->section('scripts'); ?>
32+
<?= $this->section('styles'); ?>
33+
<?= getenv('DEBUG') ? $debugbarRenderer->render() : '' ?>
34+
<?= $this->sitebase()->renderBlocks('before_body_close', $controller); ?>

0 commit comments

Comments
 (0)