Bolt\Filesystem\FilePermissions::authorized PHP Method

authorized() public method

Check if you can do something with the given file or directory.
public authorized ( string $prefix, string $path ) : boolean
$prefix string
$path string
return boolean
    public function authorized($prefix, $path)
    {
        // Check blocked resources
        foreach ($this->blocked as $rule) {
            if (preg_match($rule, $path)) {
                return false;
            }
        }
        // Check allowed filesystems
        foreach ($this->allowedPrefixes as $allowedPrefix) {
            if ($allowedPrefix === $prefix) {
                return true;
            }
        }
        // Check allowed resources
        foreach ($this->allowed as $rule) {
            if (preg_match($rule, $path)) {
                return true;
            }
        }
        return false;
    }

Usage Example

Example #1
0
 public function testBasicAuth()
 {
     $app = $this->getApp();
     $fp = new FilePermissions($app);
     $this->assertTrue($fp->authorized('config', 'test.yml'));
     $this->assertFalse($fp->authorized('something', '/path/to/.htaccess'));
 }
All Usage Examples Of Bolt\Filesystem\FilePermissions::authorized