fisrt commit'

This commit is contained in:
2018-05-24 18:51:55 +02:00
commit 906f96a15e
3463 changed files with 425820 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
<?php
namespace League\CLImate\Util\Writer;
class Buffer implements WriterInterface
{
/**
* @var string $contents The buffered data.
*/
protected $contents = "";
/**
* Write the content to the buffer.
*
* @param string $content
*
* @return void
*/
public function write($content)
{
$this->contents .= $content;
}
/**
* Get the buffered data.
*
* @return string
*/
public function get()
{
return $this->contents;
}
/**
* Clean the buffer and throw away any data.
*
* @return void
*/
public function clean()
{
$this->contents = "";
}
}
+99
View File
@@ -0,0 +1,99 @@
<?php
namespace League\CLImate\Util\Writer;
class File implements WriterInterface
{
/** @var resource|string */
protected $resource;
/** @var boolean $close_locally */
protected $close_locally = false;
/** @var boolean $use_locking */
protected $use_locking = false;
/** @var boolean $gzip_file */
protected $gzip_file = false;
/**
* @param string|resource $resource
* @param bool $use_locking
* @param bool $gzip_file
*/
public function __construct($resource, $use_locking = false, $gzip_file = false)
{
$this->resource = $resource;
$this->use_locking = $use_locking;
$this->gzip_file = $gzip_file;
}
public function lock()
{
$this->use_locking = true;
return $this;
}
public function gzipped()
{
$this->gzip_file = true;
return $this;
}
/**
* Write the content to the stream
*
* @param string $content
*/
public function write($content)
{
$resource = $this->getResource();
if ($this->use_locking) {
flock($resource, LOCK_EX);
}
gzwrite($resource, $content);
if ($this->use_locking) {
flock($resource, LOCK_UN);
}
}
protected function getResource()
{
if (is_resource($this->resource)) {
return $this->resource;
}
$this->close_locally = true;
if (!is_writable($this->resource)) {
throw new \Exception("The resource [{$this->resource}] is not writable");
}
if (!($this->resource = $this->openResource())) {
throw new \Exception("The resource could not be opened");
}
return $this->resource;
}
protected function openResource()
{
if ($this->gzip_file) {
return gzopen($this->resource, 'a');
}
return fopen($this->resource, 'a');
}
public function _destruct()
{
if ($this->close_locally) {
gzclose($this->getResource());
}
}
}
+16
View File
@@ -0,0 +1,16 @@
<?php
namespace League\CLImate\Util\Writer;
class StdErr implements WriterInterface
{
/**
* Write the content to the stream
*
* @param string $content
*/
public function write($content)
{
fwrite(\STDERR, $content);
}
}
+16
View File
@@ -0,0 +1,16 @@
<?php
namespace League\CLImate\Util\Writer;
class StdOut implements WriterInterface
{
/**
* Write the content to the stream
*
* @param string $content
*/
public function write($content)
{
fwrite(\STDOUT, $content);
}
}
@@ -0,0 +1,13 @@
<?php
namespace League\CLImate\Util\Writer;
interface WriterInterface
{
/**
* @param string $content
*
* @return void
*/
public function write($content);
}