thrownew\InvalidArgumentException('A stream must either be a resource or a string.');
}
$this->filePermission=$filePermission;
$this->useLocking=$useLocking;
}
/**
* {@inheritDoc}
*/
publicfunctionclose():void
{
if($this->url&&is_resource($this->stream)){
fclose($this->stream);
}
$this->stream=null;
$this->dirCreated=null;
}
/**
* Return the currently active stream if it is open
*
* @return resource|null
*/
publicfunctiongetStream()
{
return$this->stream;
}
/**
* Return the stream URL if it was configured with a URL and not an active resource
*
* @return string|null
*/
publicfunctiongetUrl():?string
{
return$this->url;
}
/**
* @return int
*/
publicfunctiongetStreamChunkSize():int
{
return$this->streamChunkSize;
}
/**
* {@inheritDoc}
*/
protectedfunctionwrite(array$record):void
{
if(!is_resource($this->stream)){
$url=$this->url;
if(null===$url||''===$url){
thrownew\LogicException('Missing stream url, the stream can not be opened. This may be caused by a premature call to close().'.Utils::getRecordMessageForException($record));
}
$this->createDir($url);
$this->errorMessage=null;
set_error_handler([$this,'customErrorHandler']);
try{
$stream=fopen($url,'a');
if($this->filePermission!==null){
@chmod($url,$this->filePermission);
}
}finally{
restore_error_handler();
}
if(!is_resource($stream)){
$this->stream=null;
thrownew\UnexpectedValueException(sprintf('The stream or file "%s" could not be opened in append mode: '.$this->errorMessage,$url).Utils::getRecordMessageForException($record));