Initial commit

This commit is contained in:
2021-01-19 18:19:37 +01:00
commit 6524a071df
14506 changed files with 1808535 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
vendor/
composer.lock

View File

@@ -0,0 +1,14 @@
language: php
php:
- 5.4
- 5.5
- 5.6
- hhvm
install:
- composer self-update
- composer install
script:
- ./vendor/bin/phpunit -c ./phpunit.xml --coverage-text --strict

21
core/vendor/commerceguys/enum/LICENSE vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2015 Commerce Guys
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

50
core/vendor/commerceguys/enum/README.md vendored Normal file
View File

@@ -0,0 +1,50 @@
enum
=====
[![Build Status](https://travis-ci.org/commerceguys/enum.svg?branch=master)](https://travis-ci.org/commerceguys/enum)
A PHP 5.4+ enumeration library.
Class constants are frequently used to denote sets of allowed values.
By grouping them in an enumeration class, we gain the ability to add helper methods,
list all possible values and validate values against them.
A [commerceguys/addressing](https://github.com/commerceguys/addressing) example:
```php
namespace CommerceGuys\Addressing\Enum;
use CommerceGuys\Enum\AbstractEnum;
/**
* Enumerates available locality types.
*/
final class LocalityType extends AbstractEnum
{
const CITY = 'city';
const DISTRICT = 'district';
// We can provide a getDefault() method here, or anything else.
}
LocalityType::getAll(); // ['CITY' => 'city', 'DISTRICT' => 'district']
LocalityType::getKey('city'); // 'CITY'
LocalityType::exists('city'); // true
LocalityType::assertExists('invalid value'); // InvalidArgumentException
LocalityType::assertAllExist(['district', 'invalid value']); // InvalidArgumentException
```
Meanwhile, on the AddressFormat:
```php
// The AddressFormatInterface is now free of LOCALITY_TYPE_ constants.
class AdressFormat implements AddressFormatInterface
{
public function setLocalityType($localityType)
{
LocalityType::assertExists($localityType);
$this->localityType = $localityType;
}
}
```
The reason why this library was made instead of reusing [myclabs/php-enum](https://github.com/myclabs/php-enum)
was that we didn't want to allow enumerations to be instantiated.

View File

@@ -0,0 +1,26 @@
{
"name": "commerceguys/enum",
"description": "A PHP 5.4+ enumeration library.",
"license": "MIT",
"require": {
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"autoload": {
"psr-4": {
"CommerceGuys\\Enum\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"CommerceGuys\\Enum\\Tests\\": "tests"
}
},
"authors": [
{
"name": "Bojan Zivanovic"
}
]
}

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="CommerceGuys Enum Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
</phpunit>

View File

@@ -0,0 +1,88 @@
<?php
namespace CommerceGuys\Enum;
/**
* Base class for enumerations.
*/
abstract class AbstractEnum
{
/**
* Static cache of available values, shared with all subclasses.
*
* @var array
*/
protected static $values = [];
private function __construct()
{
}
/**
* Gets all available values.
*
* @return array The available values, keyed by constant.
*/
public static function getAll()
{
$class = get_called_class();
if (!isset(static::$values[$class])) {
$reflection = new \ReflectionClass($class);
static::$values[$class] = $reflection->getConstants();
}
return static::$values[$class];
}
/**
* Gets the key of the provided value.
*
* @param string $value The value.
*
* @return boolean The key if found, false otherwise.
*/
public static function getKey($value)
{
return array_search($value, static::getAll(), true);
}
/**
* Checks whether the provided value is defined.
*
* @param string $value The value.
*
* @return boolean True if the value is defined, false otherwise.
*/
public static function exists($value)
{
return in_array($value, static::getAll(), true);
}
/**
* Asserts that the provided value is defined.
*
* @param string $value The value.
*
* @throws \InvalidArgumentException
*/
public static function assertExists($value)
{
if (static::exists($value) == false) {
$class = substr(strrchr(get_called_class(), '\\'), 1);
throw new \InvalidArgumentException(sprintf('"%s" is not a valid %s value.', $value, $class));
}
}
/**
* Asserts that all provided valus are defined.
*
* @param array $values The values.
*/
public static function assertAllExist(array $values)
{
foreach ($values as $value) {
static::assertExists($value);
}
}
}

View File

@@ -0,0 +1,71 @@
<?php
namespace CommerceGuys\Enum\Tests;
/**
* @coversDefaultClass \CommerceGuys\Enum\AbstractEnum
*/
class AbstractEnumTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers ::getAll
*/
public function testGetAll()
{
$expectedValues = ['FIRST' => 'first', 'SECOND' => 'second'];
$values = DummyEnum::getAll();
$this->assertEquals($expectedValues, $values);
}
/**
* @covers ::getKey
* @uses \CommerceGuys\Enum\AbstractEnum::getAll
*/
public function testGetKey()
{
$key = DummyEnum::getKey('first');
$this->assertEquals('FIRST', $key);
$key = DummyEnum::getKey('invalid');
$this->assertEquals(false, $key);
}
/**
* @covers ::exists
* @uses \CommerceGuys\Enum\AbstractEnum::getAll
*/
public function testExists()
{
$result = DummyEnum::exists('second');
$this->assertEquals(true, $result);
$result = DummyEnum::exists('invalid');
$this->assertEquals(false, $result);
}
/**
* @covers ::assertExists
* @uses \CommerceGuys\Enum\AbstractEnum::getAll
* @uses \CommerceGuys\Enum\AbstractEnum::exists
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage "invalid" is not a valid DummyEnum value.
*/
public function testAssertExists()
{
$result = DummyEnum::assertExists('invalid');
}
/**
* @covers ::assertAllExist
* @uses \CommerceGuys\Enum\AbstractEnum::getAll
* @uses \CommerceGuys\Enum\AbstractEnum::exists
* @uses \CommerceGuys\Enum\AbstractEnum::assertExists
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage "invalid" is not a valid DummyEnum value.
*/
public function testAssertAllExist()
{
$result = DummyEnum::assertAllExist(['second', 'invalid']);
}
}

View File

@@ -0,0 +1,14 @@
<?php
namespace CommerceGuys\Enum\Tests;
use CommerceGuys\Enum\AbstractEnum;
/**
* Dummy enumeration used for testing the AbstractEnum class.
*/
class DummyEnum extends AbstractEnum
{
const FIRST = 'first';
const SECOND = 'second';
}