Skip to content

Commit e57b838

Browse files
committed
Jet Core
------------------------- * MVC_Router: tryDirectFiles( array $allowed_files ) : bool method added Example app ------------------------- * MVC_Router->tryDirectFiles usage example (robots.txt, security.txt)
1 parent 10470a9 commit e57b838

File tree

8 files changed

+51
-2
lines changed

8 files changed

+51
-2
lines changed

application/Classes/Application/Web.php

+10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace JetApplication;
1010

11+
use Jet\IO_File;
1112
use Jet\Logger;
1213

1314
use Jet\MVC;
@@ -49,6 +50,7 @@ public static function init( MVC_Router $router ): void
4950
{
5051
SysConf_Jet_MVC::setUseModulePages( false );
5152

53+
5254
Logger::setLoggerProvider( function() : ?Application_Web_Services_Logger {
5355
return Application_Web_Services::Logger();
5456
} );
@@ -60,6 +62,14 @@ public static function init( MVC_Router $router ): void
6062
SysConf_Jet_UI::setViewsDir( $router->getBase()->getViewsPath() . 'ui/' );
6163
SysConf_Jet_Form::setDefaultViewsDir( $router->getBase()->getViewsPath() . 'form/' );
6264
SysConf_Jet_ErrorPages::setErrorPagesDir( $router->getBase()->getPagesDataPath( $router->getLocale() ) );
65+
66+
if($router->tryDirectFiles([
67+
'robots.txt',
68+
'security.txt'
69+
])) {
70+
return;
71+
}
72+
6373
}
6474

6575
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [cs] robots.txt example
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [CS] security.txt example
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* robots.txt example
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* security.txt example

application/config/Jet.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
SysConf_Jet_Mailing::setTemplatesDir( SysConf_Path::getApplication().'email-templates/' );
1818

19-
SysConf_Jet_Debug::setDevelMode( true );
19+
SysConf_Jet_Debug::setDevelMode( false );
2020

2121
if( SysConf_Jet_Debug::getDevelMode() ) {
2222
//Dev configuration

library/Jet/MVC/Router.php

+30-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
namespace Jet;
1010

11+
use JetApplication\Application;
12+
1113
require_once 'Router/Interface.php';
1214

1315
/**
@@ -175,6 +177,10 @@ public function resolve( string|null $request_URL = null ): void
175177
$this->request_URL = (string)$request_URL;
176178

177179
if( $this->resolve_seekBaseAndLocale() ) {
180+
if($this->getIs404()) {
181+
return;
182+
}
183+
178184
if($this->resolve_seekPage()) {
179185
if($this->resolve_authorizePage()) {
180186
if($this->resolve_pageResolve()) {
@@ -581,5 +587,28 @@ public function getValidUrl(): string
581587
{
582588
return $this->valid_url;
583589
}
584-
590+
591+
/**
592+
* @param array $allowed_files
593+
* @return bool
594+
*/
595+
public function tryDirectFiles( array $allowed_files ) : bool
596+
{
597+
if(
598+
in_array($this->getUrlPath(), $allowed_files)
599+
) {
600+
$path = $this->getBase()->getPagesDataPath($this->getLocale()).$this->getUrlPath();
601+
602+
if(IO_File::isReadable($path)) {
603+
echo IO_File::read( $path );
604+
Application::end();
605+
}
606+
607+
$this->setIs404();
608+
return true;
609+
}
610+
611+
return false;
612+
}
613+
585614
}

library/Jet/MVC/Router/Interface.php

+6
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,11 @@ public function getHasUnusedUrlPath(): bool;
145145
* @return string
146146
*/
147147
public function getValidUrl(): string;
148+
149+
/**
150+
* @param array $allowed_files
151+
* @return bool
152+
*/
153+
public function tryDirectFiles( array $allowed_files ) : bool;
148154

149155
}

0 commit comments

Comments
 (0)