barbushin / php-console

Handle PHP errors, dump variables, execute PHP code remotely in Google Chrome
https://chrome.google.com/webstore/detail/php-console/nfhmhhlpfleoednkpnnnkolmclajemef
MIT License
1.34k stars 283 forks source link

Won't work if app can't write to 'php-console.dat' #58

Closed younes0 closed 9 years ago

younes0 commented 10 years ago

This is a bug encountered in Laravel though I'm not sure if it's specific to Laravel. One workaround is to warn the user to make that file writable, by throwing an Exception or a warning in the Chrome console

barbushin commented 10 years ago

There is already https://github.com/barbushin/php-console/blob/master/src/PhpConsole/Storage/File.php#L28

younes0 commented 10 years ago

Well the file already exists but it's no writable

You could add the following lines

    public function __construct($filePath, $validatePathNotUnderDocRoot = true) {
        if(!file_exists($filePath)) {
            if(file_put_contents($filePath, '') === false) {
                throw new \Exception('Unable to write file ' . $filePath);
            }
        } else if (!is_writable($filePath)) {
            throw new \Exception('Unable to write file ' . $filePath);
        }
        $this->filePath = realpath($filePath);

        if($validatePathNotUnderDocRoot && $this->isPathUnderDocRoot()) {
            throw new \Exception('Path ' . $this->filePath . ' is under DOCUMENT_ROOT. It\'s insecure!');
        }
    }