src/Charcoal/App/Script/PathScriptTrait.php
public function filterWritablePath($path, $name = null)
    {
        if ($name === null && defined(get_called_class().'::DEFAULT_BASENAME')) {
            $name = static::DEFAULT_BASENAME;
        }

        if (!is_string($name)) {
            throw new InvalidArgumentException(
                'The target file name must be a string or use static::DEFAULT_BASENAME.'
            );
        }

        $path = $this->filterPath($path);
        $test = $this->basePath().'/'.$path;

        if (is_dir($test)) {
            if (is_writable($test)) {
                $path .= '/'.$name;
            } else {
                throw new InvalidArgumentException('The target path is not writeable.');
            }
        } elseif (is_file($test)) {
            if (!is_writable($test)) {
                throw new InvalidArgumentException('The target file is not writeable.');
            }
        } else {
            $info = pathinfo($path);
            $path = $this->filterWritablePath($info['dirname'], $info['basename']);
        }

        return $path;
    }
public function filterWritablePath($path, $name = null)
    {
        if ($name === null && defined(get_called_class().'::DEFAULT_BASENAME')) {
            $name = static::DEFAULT_BASENAME;
        }

        if (!is_string($name)) {
            throw new InvalidArgumentException(
                'The target file name must be a string or use static::DEFAULT_BASENAME.'
            );
        }

        $path = $this->filterPath($path);
        $test = $this->basePath().'/'.$path;

        if (is_dir($test)) {
            if (is_writable($test)) {
                $path .= '/'.$name;
            } else {
                throw new InvalidArgumentException('The target path is not writeable.');
            }
        } elseif (is_file($test)) {
            if (!is_writable($test)) {
                throw new InvalidArgumentException('The target file is not writeable.');
            }
        } else {
            $info = pathinfo($path);
            $path = $this->filterWritablePath($info['dirname'], $info['basename']);
        }

        return $path;
    }
public function filterWritablePath ( $ path , $ name = null ) { if ( $ name === null && defined ( get_called_class ( ) . '::DEFAULT_BASENAME' ) ) { $ name = static :: DEFAULT_BASENAME ; } if ( ! is_string ( $ name ) ) { throw new InvalidArgumentException ( 'The target file name must be a string or use static::DEFAULT_BASENAME.' ) ; } $ path = $ this -> filterPath ( $ path ) ; $ test = $ this -> basePath ( ) . '/' . $ path ; if ( is_dir ( $ test ) ) { if ( is_writable ( $ test ) ) { $ path .= '/' . $ name ; } else { throw new InvalidArgumentException ( 'The target path is not writeable.' ) ; } } elseif ( is_file ( $ test ) ) { if ( ! is_writable ( $ test ) ) { throw new InvalidArgumentException ( 'The target file is not writeable.' ) ; } } else { $ info = pathinfo ( $ path ) ; $ path = $ this -> filterWritablePath ( $ info [ 'dirname' ] , $ info [ 'basename' ] ) ; } return $ path ; }
Filter the given path to be writable.

@param  string      $path A writable path to a file or directory.
@param  string|null $name The target file name.
@throws InvalidArgumentException If the path is invalid.
@return string Returns the filtered path.
Filter the given path to be writable .