I am writing some PHP that takes some paths to different content directories and uses them to include different parts of the pages later. I am trying to ensure that the paths are as they appear, and none of them violates the rules of the application. What is,
PRIVATEDIR(defined relatively DOCUMENT_ROOT) should be higher DOCUMENT_ROOT.CONTENTDIR(defined relatively PRIVATEDIR) should lie below PRIVATEDIRand should not return to DOCUMENT_ROOT.- The rest
*DIRS(relative to CONTENTDIR) should be belowCONTENTDIR
I set some default values ββin one controller of the singleton class, and then the user passes an array of paths that they want to override to this class constructor. Then I want sanity to test them, to comply with the above rules. This is how I started doing this ...
EDIT: Pay attention to my use error_reportingin the code below, and then don't do it yourself! I misunderstood how this command works. If you're wondering why, see comments by stealthyninja and Col. Shrapnel in the comments (and thank them for pointing this out to me).
private $opts = array(
'PRIVATEDIR' => '..',
'CONTENTDIR' => 'content',
...
...
);
private function __construct($options) {
error_reporting(0);
if(is_array($options)) {
$this->opts = array_merge($this->opts, $options);
}
if($this->opts['STATUS']==='debug') {
error_reporting(E_ALL | E_NOTICE | E_STRICT);
}
$this->opts['PUBLICDIR'] = realpath($_SERVER['DOCUMENT_ROOT'])
.DIRECTORY_SEPARATOR;
$this->opts['PRIVATEDIR'] = realpath($this->opts['PUBLICDIR']
.$this->opts['PRIVATEDIR'])
.DIRECTORY_SEPARATOR;
$this->opts['CONTENTDIR'] = realpath($this->opts['PRIVATEDIR']
.$this->opts['CONTENTDIR'])
.DIRECTORY_SEPARATOR;
$this->opts['CACHEDIR'] = realpath($this->opts['CONTENTDIR']
.$this->opts['CACHEDIR'])
.DIRECTORY_SEPARATOR;
$this->opts['ERRORDIR'] = realpath($this->opts['CONTENTDIR']
.$this->opts['ERRORDIR'])
.DIRECTORY_SEPARATOR;
$this->opts['TEMPLATEDIR' = realpath($this->opts['CONTENTDIR']
.$this->opts['TEMPLATEDIR'])
.DIRECTORY_SEPARATOR;
...
...
...
}
, , , , - (, , ), .
, ( ) , , , . ( ) , , , , (, // ...) , , .
, , , , ? . ? , , - ? ( , ).
.