Subir todo el proyecto incluyendo vendor y dependencias

This commit is contained in:
Admin
2026-01-16 20:33:13 -06:00
parent cf8ecfcf64
commit 0b3d76822d
2394 changed files with 2382358 additions and 40 deletions

4
vendor/trafficcophp/bytebuffer/.gitignore vendored Executable file
View File

@@ -0,0 +1,4 @@
/vendor/.composer/
vendor/
/phpunit.xml
.idea/

12
vendor/trafficcophp/bytebuffer/.travis.yml vendored Executable file
View File

@@ -0,0 +1,12 @@
language: php
sudo: false
php:
- 5.3
- 5.4
- 5.5
before_script:
- composer --prefer-source --dev install

57
vendor/trafficcophp/bytebuffer/README.md vendored Executable file
View File

@@ -0,0 +1,57 @@
# PHP Library for reading and writing binary data
[![Build Status](https://secure.travis-ci.org/nesQuick/ByteBuffer.png?branch=master)](http://travis-ci.org/nesQuick/ByteBuffer) [![No Maintenance Intended](http://unmaintained.tech/badge.svg)](http://unmaintained.tech/)
I intentionally needed that for writing a PHP Client for [TrafficCop](https://github.com/santosh79/traffic_cop/).
But the source grows so I decided to move it into an own package.
You can also call this a [pack()](http://www.php.net/manual/en/function.pack.php) wrapper.
## Install
Installation should be done via [composer](http://packagist.org/).
```
{
"require": {
"TrafficCophp/ByteBuffer": "dev-master"
}
}
```
## Example
A simple usage example could look like this
```php
<?php
require __DIR__ . '/vendor/.composer/autoload.php';
use TrafficCophp\ByteBuffer\ByteBuffer;
$channel = 'channel_one';
$message = 'php';
$buffer = new ByteBuffer(4 + 1 + 4 + strlen($channel) + strlen($message));
$buffer->writeInt32BE($buffer->length(), 0);
$buffer->writeInt8(0x1, 4);
$buffer->writeInt32BE(strlen($channel), 5);
$buffer->write($channel, 9);
$buffer->write($message, 9 + strlen($channel));
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$result = socket_connect($socket, '127.0.0.1', 3542);
socket_write($socket, (string) $buffer, $buffer->length());
```
## ToDo's
* Write Documentation
* Improve examples
* Allow Buffer as constructor
* Write test for concatinating buffers
## License
Licensed under the MIT license.

20
vendor/trafficcophp/bytebuffer/composer.json vendored Executable file
View File

@@ -0,0 +1,20 @@
{
"name": "TrafficCophp/ByteBuffer",
"type": "library",
"description": "Node.js inspired byte stream buffer for PHP.",
"keywords": ["Buffer", "Stream", "Socket", "Library", "Bytehandling", "pack", "wrapper", "binary data"],
"license": "MIT",
"authors": [
{
"name": "Ole 'nesQuick' Michaelis",
"email": "ole.michaelis@googlemail.com",
"homepage": "http://www.codestars.eu"
}
],
"autoload": {
"psr-0": {
"TrafficCophp": "src/"
}
},
"require": {}
}

5
vendor/trafficcophp/bytebuffer/composer.lock generated vendored Executable file
View File

@@ -0,0 +1,5 @@
{
"hash": "6cf3d618c76525d67fe4ca75786c4440",
"packages": [],
"aliases": []
}

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://gooh.github.com/phpunit-schema/3.7/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="TrafficCophp Bytebuffer Test Suite">
<directory suffix="Test.php">tests/TrafficCophp/ByteBuffer</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>

View File

@@ -0,0 +1,9 @@
<?php
namespace TrafficCophp\ByteBuffer;
abstract class AbstractBuffer implements ReadableBuffer, WriteableBuffer {
abstract public function __construct($length);
abstract public function __toString();
abstract public function length();
}

View File

@@ -0,0 +1,147 @@
<?php
namespace TrafficCophp\ByteBuffer;
/**
* ByteBuffer
*/
class Buffer extends AbstractBuffer {
const DEFAULT_FORMAT = 'x';
/**
* @var \SplFixedArray
*/
protected $buffer;
/**
* @var LengthMap
*/
protected $lengthMap;
public function __construct($argument) {
$this->lengthMap = new LengthMap();
if (is_string($argument)) {
$this->initializeStructs(strlen($argument), $argument);
} else if (is_int($argument)) {
$this->initializeStructs($argument, pack(self::DEFAULT_FORMAT.$argument));
} else {
throw new \InvalidArgumentException('Constructor argument must be an binary string or integer');
}
}
protected function initializeStructs($length, $content) {
$this->buffer = new \SplFixedArray($length);
for ($i = 0; $i < $length; $i++) {
$this->buffer[$i] = $content[$i];
}
}
protected function insert($format, $value, $offset, $length) {
$bytes = pack($format, $value);
for ($i = 0; $i < strlen($bytes); $i++) {
$this->buffer[$offset++] = $bytes[$i];
}
}
protected function extract($format, $offset, $length) {
$encoded = '';
for ($i = 0; $i < $length; $i++) {
$encoded .= $this->buffer->offsetGet($offset + $i);
}
if ($format == 'N'&& PHP_INT_SIZE <= 4) {
list(, $h, $l) = unpack('n*', $encoded);
$result = ($l + ($h * 0x010000));
} else if ($format == 'V' && PHP_INT_SIZE <= 4) {
list(, $h, $l) = unpack('v*', $encoded);
$result = ($h + ($l * 0x010000));
} else {
list(, $result) = unpack($format, $encoded);
}
return $result;
}
protected function checkForOverSize($excpected_max, $actual) {
if ($actual > $excpected_max) {
throw new \InvalidArgumentException(sprintf('%d exceeded limit of %d', $actual, $excpected_max));
}
}
public function __toString() {
$buf = '';
foreach ($this->buffer as $bytes) {
$buf .= $bytes;
}
return $buf;
}
public function length() {
return $this->buffer->getSize();
}
public function write($string, $offset) {
$length = strlen($string);
$this->insert('a' . $length, $string, $offset, $length);
}
public function writeInt8($value, $offset) {
$format = 'C';
$this->checkForOverSize(0xff, $value);
$this->insert($format, $value, $offset, $this->lengthMap->getLengthFor($format));
}
public function writeInt16BE($value, $offset) {
$format = 'n';
$this->checkForOverSize(0xffff, $value);
$this->insert($format, $value, $offset, $this->lengthMap->getLengthFor($format));
}
public function writeInt16LE($value, $offset) {
$format = 'v';
$this->checkForOverSize(0xffff, $value);
$this->insert($format, $value, $offset, $this->lengthMap->getLengthFor($format));
}
public function writeInt32BE($value, $offset) {
$format = 'N';
$this->checkForOverSize(0xffffffff, $value);
$this->insert($format, $value, $offset, $this->lengthMap->getLengthFor($format));
}
public function writeInt32LE($value, $offset) {
$format = 'V';
$this->checkForOverSize(0xffffffff, $value);
$this->insert($format, $value, $offset, $this->lengthMap->getLengthFor($format));
}
public function read($offset, $length) {
$format = 'a' . $length;
return $this->extract($format, $offset, $length);
}
public function readInt8($offset) {
$format = 'C';
return $this->extract($format, $offset, $this->lengthMap->getLengthFor($format));
}
public function readInt16BE($offset) {
$format = 'n';
return $this->extract($format, $offset, $this->lengthMap->getLengthFor($format));
}
public function readInt16LE($offset) {
$format = 'v';
return $this->extract($format, $offset, $this->lengthMap->getLengthFor($format));
}
public function readInt32BE($offset) {
$format = 'N';
return $this->extract($format, $offset, $this->lengthMap->getLengthFor($format));
}
public function readInt32LE($offset) {
$format = 'V';
return $this->extract($format, $offset, $this->lengthMap->getLengthFor($format));
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace TrafficCophp\ByteBuffer;
/**
* LengthMap
*/
class LengthMap {
protected $map;
public function __construct() {
$this->map = array(
'n' => 2,
'N' => 4,
'v' => 2,
'V' => 4,
'c' => 1,
'C' => 1
);
}
public function getLengthFor($format) {
return $this->map[$format];
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace TrafficCophp\ByteBuffer;
interface ReadableBuffer {
public function read($start, $end);
public function readInt8($offset);
public function readInt16BE($offset);
public function readInt16LE($offset);
public function readInt32BE($offset);
public function readInt32LE($offset);
}

View File

@@ -0,0 +1,12 @@
<?php
namespace TrafficCophp\ByteBuffer;
interface WriteableBuffer {
public function write($string, $offset);
public function writeInt8($value, $offset);
public function writeInt16BE($value, $offset);
public function writeInt16LE($value, $offset);
public function writeInt32BE($value, $offset);
public function writeInt32LE($value, $offset);
}

View File

@@ -0,0 +1,146 @@
<?php
use TrafficCophp\ByteBuffer\Buffer;
/**
* Buffer testsuite
*/
class BufferTest extends PHPUnit_Framework_TestCase {
public function testTrailingEmptyByte() {
$buffer = new Buffer(5);
$buffer->writeInt32LE(0xfeedface, 0);
$this->assertSame(pack('Vx', 0xfeedface), (string) $buffer);
}
public function testSurroundedEmptyByte() {
$buffer = new Buffer(9);
$buffer->writeInt32BE(0xfeedface, 0);
$buffer->writeInt32BE(0xcafebabe, 5);
$this->assertSame(pack('NxN', 0xfeedface, 0xcafebabe), (string) $buffer);
}
public function testTooSmallBuffer() {
$buffer = new Buffer(4);
$buffer->writeInt32BE(0xfeedface, 0);
$this->setExpectedException('RuntimeException');
$buffer->writeInt32LE(0xfeedface, 4);
}
public function testTwo4ByteIntegers() {
$buffer = new Buffer(8);
$buffer->writeInt32BE(0xfeedface, 0);
$buffer->writeInt32LE(0xfeedface, 4);
$this->assertSame(pack('NV', 0xfeedface, 0xfeedface), (string) $buffer);
}
public function testWritingString() {
$buffer = new Buffer(10);
$buffer->writeInt32BE(0xcafebabe, 0);
$buffer->write('please', 4);
$this->assertSame(pack('Na6', 0xcafebabe, 'please'), (string) $buffer);
}
public function testTooLongIntegers() {
$buffer = new Buffer(12);
$this->setExpectedException('InvalidArgumentException');
$buffer->writeInt32BE(0xfeedfacefeed, 0);
}
public function testLength() {
$buffer = new Buffer(8);
$this->assertEquals(8, $buffer->length());
}
public function testWriteInt8() {
$buffer = new Buffer(1);
$buffer->writeInt8(0xfe, 0);
$this->assertSame(pack('C', 0xfe), (string) $buffer);
}
public function testWriteInt16BE() {
$buffer = new Buffer(2);
$buffer->writeInt16BE(0xbabe, 0);
$this->assertSame(pack('n', 0xbabe), (string) $buffer);
}
public function testWriteInt16LE() {
$buffer = new Buffer(2);
$buffer->writeInt16LE(0xabeb, 0);
$this->assertSame(pack('v', 0xabeb), (string) $buffer);
}
public function testWriteInt32BE() {
$buffer = new Buffer(4);
$buffer->writeInt32BE(0xfeedface, 0);
$this->assertSame(pack('N', 0xfeedface), (string) $buffer);
}
public function testWriteInt32LE() {
$buffer = new Buffer(4);
$buffer->writeInt32LE(0xfeedface, 0);
$this->assertSame(pack('V', 0xfeedface), (string) $buffer);
}
public function testReaderBufferInitializeLenght() {
$buffer = new Buffer(pack('V', 0xfeedface));
$this->assertEquals(4, $buffer->length());
}
public function testReadInt8() {
$buffer = new Buffer(pack('C', 0xfe));
$this->assertSame(0xfe, $buffer->readInt8(0));
}
public function testReadInt16BE() {
$buffer = new Buffer(pack('n', 0xbabe));
$this->assertSame(0xbabe, $buffer->readInt16BE(0));
}
public function testReadInt16LE() {
$buffer = new Buffer(pack('v', 0xabeb));
$this->assertSame(0xabeb, $buffer->readInt16LE(0));
}
public function testReadInt32BE() {
$buffer = new Buffer(pack('N', 0xfeedface));
$this->assertSame(0xfeedface, $buffer->readInt32BE(0));
}
public function testReadInt32LE() {
$buffer = new Buffer(pack('V', 0xfeedface));
$this->assertSame(0xfeedface, $buffer->readInt32LE(0));
}
public function testRead() {
$buffer = new Buffer(pack('a7', 'message'));
$this->assertSame('message', $buffer->read(0, 7));
}
public function testComplexRead() {
$buffer = new Buffer(pack('Na7', 0xfeedface, 'message'));
$this->assertSame(0xfeedface, $buffer->readInt32BE(0));
$this->assertSame('message', $buffer->read(4, 7));
}
public function testWritingAndReadingOnTheSameBuffer() {
$buffer = new Buffer(10);
$int32be = 0xfeedface;
$string = 'hello!';
$buffer->writeInt32BE($int32be, 0);
$buffer->write($string, 4);
$this->assertSame($string, $buffer->read(4, 6));
$this->assertSame($int32be, $buffer->readInt32BE(0));
}
public function testInvalidConstructorWithArray() {
$this->setExpectedException('\InvalidArgumentException');
$buffer = new Buffer(array('asdf'));
}
public function testInvalidConstructorWithFloat() {
$this->setExpectedException('\InvalidArgumentException');
$buffer = new Buffer(324.23);
}
}