Compare commits

...

2 Commits

Author SHA1 Message Date
gamonoid
9cee4e91df Upgrades from IceHrm Pro v24 2018-07-03 03:10:32 +02:00
gamonoid
8b276d54e6 Release notes v23.0.1.OS 2018-06-14 04:39:45 +02:00
8253 changed files with 659240 additions and 47489 deletions

View File

@@ -16,8 +16,7 @@ $customFields = \Classes\BaseService::getInstance()->getCustomFields("Employee")
<li class="active"><a id="tabEmployee" href="#tabPageEmployee"><?=t('Employees')?></a></li>
<?php }?>
<?php if($user->user_level == "Admin"){
?>
<?php if ($user->user_level == "Admin") { ?>
<li><a id="tabEmployeeSkill" href="#tabPageEmployeeSkill"><?=t('Skills')?></a></li>
<li><a id="tabEmployeeEducation" href="#tabPageEmployeeEducation"><?=t('Education')?></a></li>
<li><a id="tabEmployeeCertification" href="#tabPageEmployeeCertification"><?=t('Certifications')?></a></li>
@@ -28,8 +27,7 @@ $customFields = \Classes\BaseService::getInstance()->getCustomFields("Employee")
<li><a id="tabEmployeeDocument" href="#tabPageEmployeeDocument"><?=t('Documents')?></a></li>
<?php } ?>
<?php }?>
<?php if($user->user_level == "Admin"){
?>
<?php if ($user->user_level == "Admin"){ ?>
<li class="dropdown">
<a href="#" id="terminatedEmployeeMenu" class="dropdown-toggle" data-toggle="dropdown" aria-controls="terminatedEmployeeMenu-contents"><?=t('Deactivated Employees')?> <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu" aria-labelledby="terminatedEmployeeMenu" id="terminatedEmployeeMenu-contents">
@@ -37,7 +35,7 @@ $customFields = \Classes\BaseService::getInstance()->getCustomFields("Employee")
<li><a id="tabArchivedEmployee" href="#tabPageArchivedEmployee"><?=t('Terminated Employee Data')?></a></li>
</ul>
</li>
<?php }?>
<?php } ?>
</ul>
@@ -131,17 +129,13 @@ $customFields = \Classes\BaseService::getInstance()->getCustomFields("Employee")
</div>
<script>
var modJsList = new Array();
<?php if($user->user_level != "Admin"){
?>
<?php if($user->user_level != "Admin"){ ?>
modJsList['tabEmployee'] = new EmployeeAdapter('Employee','Employee',{"status":"Active"});
modJsList['tabEmployee'].setShowAddNew(false);
<?php
}else{
?>
modJsList['tabEmployee'].setShowDelete(false);
<?php }else{ ?>
modJsList['tabEmployee'] = new EmployeeAdapter('Employee','Employee',{"status":"Active"});
<?php
}
?>
<?php } ?>
modJsList['tabEmployee'].setRemoteTable(true);
modJsList['tabEmployee'].setFieldNameMap(<?=json_encode($fieldNameMap)?>);

View File

@@ -25,9 +25,8 @@ $moduleName = 'users';
define('MODULE_PATH',dirname(__FILE__));
include APP_BASE_PATH.'header.php';
include APP_BASE_PATH.'modulejslibs.inc.php';
$csrf = \Classes\BaseService::getInstance()->generateCsrf('User');
?><div class="span9">
<ul class="nav nav-tabs" id="modTab" style="margin-bottom:0px;margin-left:5px;border-bottom: none;">
<li class="active"><a id="tabUser" href="#tabPageUser"><?=t('Users')?></a></li>
<li class=""><a id="tabUserRole" href="#tabPageUserRole"><?=t('User Roles')?></a></li>
@@ -38,7 +37,7 @@ include APP_BASE_PATH.'modulejslibs.inc.php';
<div id="User" class="reviewBlock" data-content="List" style="padding-left:5px;">
</div>
<div id="UserForm" class="reviewBlock" data-content="Form" style="padding-left:5px;display:none;">
<div id="UserForm" class="reviewBlock" data-content="Form" data-csrf="<?=$csrf?>" style="padding-left:5px;display:none;">
</div>
</div>
@@ -56,8 +55,9 @@ include APP_BASE_PATH.'modulejslibs.inc.php';
<script>
var modJsList = new Array();
modJsList['tabUser'] = new UserAdapter('User');
<?php if(isset($_REQUEST['action']) && $_REQUEST['action'] == "new" && isset($_REQUEST['object'])){?>
modJsList['tabUser'].newInitObject = JSON.parse(Base64.decode('<?=$_REQUEST['object']?>'));
modJsList['tabUser'].setCSRFRequired(true);
<?php if(isset($_GET['action']) && $_GET['action'] == "new" && isset($_GET['object'])){?>
modJsList['tabUser'].newInitObject = JSON.parse(Base64.decode('<?=$_GET['object']?>'));
<?php }?>
modJsList['tabUserRole'] = new UserRoleAdapter('UserRole');
var modJs = modJsList['tabUser'];

View File

@@ -13,10 +13,10 @@ if(!defined('HOME_LINK_OTHERS')){
}
//Version
define('VERSION', '23.0.1.OS');
define('CACHE_VALUE', '23.0.1.OS');
define('VERSION_NUMBER', '2301');
define('VERSION_DATE', '14/06/2018');
define('VERSION', '24.0.0.OS');
define('CACHE_VALUE', '24.0.0.OS');
define('VERSION_NUMBER', '2400');
define('VERSION_DATE', '26/06/2018');
if(!defined('CONTACT_EMAIL')){define('CONTACT_EMAIL','icehrm@gamonoid.com');}
if(!defined('KEY_PREFIX')){define('KEY_PREFIX','IceHrm');}

View File

@@ -16,7 +16,6 @@ foreach($crons as $cron){
if($iceCron->isRunNow()){
\Utils\LogManager::getInstance()->info(CLIENT_NAME." execute cron :".$cron->name);
$iceCron->execute();
sleep(1);
}
}

View File

@@ -80,8 +80,6 @@ if (!isset($_REQUEST['objects'])) {
}
}
\Utils\LogManager::getInstance()->debug("Row Count Filter Query:" . $countFilterQuery);
\Utils\LogManager::getInstance()->debug("Row Count Filter Query Data:" . json_encode($countFilterQueryData));
if (in_array($table, \Classes\BaseService::getInstance()->userTables)
&& !$skipProfileRestriction && !$isSubOrdinates) {
@@ -89,8 +87,6 @@ if (!isset($_REQUEST['objects'])) {
$sql = "Select count(id) as count from "
. $obj->_table . " where " . SIGN_IN_ELEMENT_MAPPING_FIELD_NAME . " = ? " . $countFilterQuery;
array_unshift($countFilterQueryData, $cemp);
\Utils\LogManager::getInstance()->debug("Count Filter Query 1:" . $sql);
\Utils\LogManager::getInstance()->debug("Count Filter Query Data 1:" . json_encode($countFilterQueryData));
$rowCount = $obj->DB()->Execute($sql, $countFilterQueryData);
} else {
@@ -166,20 +162,12 @@ if (!isset($_REQUEST['objects'])) {
$sql = "Select count(id) as count from " . $obj->_table .
" where " . $obj->getUserOnlyMeAccessField() . " in (" . $subordinatesIds . ") "
. $countFilterQuery;
\Utils\LogManager::getInstance()->debug("Count Filter Query 2:" . $sql);
\Utils\LogManager::getInstance()->debug(
"Count Filter Query Data 2:" . json_encode($countFilterQueryData)
);
$rowCount = $obj->DB()->Execute($sql, $countFilterQueryData);
} else {
$sql = "Select count(id) as count from " . $obj->_table;
if (!empty($countFilterQuery)) {
$sql .= " where 1=1 " . $countFilterQuery;
}
\Utils\LogManager::getInstance()->debug("Count Filter Query 3:" . $sql);
\Utils\LogManager::getInstance()->debug(
"Count Filter Query Data 3:" . json_encode($countFilterQueryData)
);
$rowCount = $obj->DB()->Execute($sql, $countFilterQueryData);
}
}
@@ -214,12 +202,23 @@ if (!isset($_REQUEST['objects'])) {
$row["_org"] = \Classes\BaseService::getInstance()->cleanUpAdoDB($item);
$output['aaData'][] = $row;
}
echo json_encode($output);
try {
echo \Classes\BaseService::getInstance()->safeJsonEncode($output);
} catch (Exception $e) {
\Utils\LogManager::getInstance()->error($e->getMessage());
echo json_encode(['status' => 'Error']);
}
} else {
$output = array();
foreach ($data as $item) {
unset($item->keysToIgnore);
$output[] = \Classes\BaseService::getInstance()->cleanUpAdoDB($item);
}
echo json_encode($output);
try {
echo \Classes\BaseService::getInstance()->safeJsonEncode($output);
} catch (Exception $e) {
\Utils\LogManager::getInstance()->error($e->getMessage());
echo json_encode(['status' => 'Error']);
}
}

View File

@@ -15,7 +15,6 @@
modJsList[prop].setEmailTemplates(<?=json_encode($emailTemplates)?>);
<?php } ?>
modJsList[prop].setUser(<?=json_encode($user)?>);
//Test
<?php if(isset($_REQUEST['action']) && $_REQUEST['action'] == "new"){?>
if(modJsList[prop].newInitObject == undefined || modJsList[prop].newInitObject == null){
modJsList[prop].initFieldMasterData(null,modJsList[prop].renderForm);
@@ -29,14 +28,8 @@
modJsList[prop].setCurrentProfile(<?=json_encode($activeProfile)?>);
modJsList[prop].setInstanceId('<?=$baseService->getInstanceId()?>');
modJsList[prop].setNoJSONRequests('<?=$noJSONRequests?>');
}
}
//Other static js objects
var timeUtils = new TimeUtils();
timeUtils.setServerGMToffset('<?=$diffHoursBetweenServerTimezoneWithGMT?>');
@@ -44,6 +37,6 @@
</script>
<?php include 'popups.php';?>
<?php include APP_BASE_PATH.'js/bootstrapDataTable.php';?>
<script src="<?=BASE_URL?>js/bootstrap-datatable.js"></script>
</body>
</html>

View File

@@ -85,7 +85,7 @@
if(tabName!= undefined && tabName != "" && modJsList[tabName] != undefined && modJsList[tabName] != null){
$("#"+tabName).click();
}else{
<?php if(!isset($_REQUEST['action']) && $_REQUEST['action'] != "new"){?>
<?php if(!isset($_REQUEST['action'])){?>
modJs.get([]);
<?php } ?>
}
@@ -143,6 +143,7 @@
</script>
<?php include 'popups.php';?>
<?php include APP_BASE_PATH.'js/bootstrapDataTable.php';?>
<script src="<?=BASE_URL?>js/bootstrap-datatable.js"></script>
</body>
</html>

View File

@@ -89,6 +89,8 @@ $meta = json_decode(file_get_contents(MODULE_PATH."/meta.json"),true);
include('configureUIManager.php');
$chatUserProfile = \Classes\UIManager::getInstance()->getCurrentProfile();
?><!DOCTYPE html>
<html>
<head>
@@ -187,8 +189,6 @@ include('configureUIManager.php');
</script>
<script type="text/javascript" src="<?=BASE_URL?>js/app-global.js"></script>
</head>
<body class="skin-blue" data-turbolinks="false">
<header id="delegationDiv" class="header">

View File

@@ -1,6 +1,6 @@
{
"require": {
"monolog/monolog": "1.13.1",
"monolog/monolog": "^1.23",
"twig/twig": "1.23.*",
"gettext/gettext": "4.0.0",
"consolidation/robo": "~1",
@@ -10,7 +10,8 @@
"pear/mail": "^1.4",
"spomky-labs/base64url": "^1.0",
"cebe/markdown": "^1.2",
"neitanod/forceutf8": "^2.0"
"neitanod/forceutf8": "^2.0",
"google/apiclient": "^2.2"
},
"require-dev": {
"phpunit/phpunit": "~6"

View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "45cdd8adec569a3ef6dfed9c8b1fab41",
"content-hash": "bea0e0b37a382bfad7a07c0466ef70bb",
"packages": [
{
"name": "cebe/markdown",
@@ -607,6 +607,52 @@
],
"time": "2017-11-23T18:22:44+00:00"
},
{
"name": "firebase/php-jwt",
"version": "v5.0.0",
"source": {
"type": "git",
"url": "https://github.com/firebase/php-jwt.git",
"reference": "9984a4d3a32ae7673d6971ea00bae9d0a1abba0e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/firebase/php-jwt/zipball/9984a4d3a32ae7673d6971ea00bae9d0a1abba0e",
"reference": "9984a4d3a32ae7673d6971ea00bae9d0a1abba0e",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": " 4.8.35"
},
"type": "library",
"autoload": {
"psr-4": {
"Firebase\\JWT\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Neuman Vong",
"email": "neuman+pear@twilio.com",
"role": "Developer"
},
{
"name": "Anant Narayanan",
"email": "anant@php.net",
"role": "Developer"
}
],
"description": "A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.",
"homepage": "https://github.com/firebase/php-jwt",
"time": "2017-06-27T22:17:23+00:00"
},
{
"name": "gettext/gettext",
"version": "v4.0.0",
@@ -728,6 +774,149 @@
],
"time": "2017-03-23T17:02:28+00:00"
},
{
"name": "google/apiclient",
"version": "v2.2.1",
"source": {
"type": "git",
"url": "https://github.com/google/google-api-php-client.git",
"reference": "b69b8ac4bf6501793c389d4e013a79d09c85c5f2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/google/google-api-php-client/zipball/b69b8ac4bf6501793c389d4e013a79d09c85c5f2",
"reference": "b69b8ac4bf6501793c389d4e013a79d09c85c5f2",
"shasum": ""
},
"require": {
"firebase/php-jwt": "~2.0|~3.0|~4.0|~5.0",
"google/apiclient-services": "~0.13",
"google/auth": "^1.0",
"guzzlehttp/guzzle": "~5.3.1|~6.0",
"guzzlehttp/psr7": "^1.2",
"monolog/monolog": "^1.17",
"php": ">=5.4",
"phpseclib/phpseclib": "~0.3.10|~2.0"
},
"require-dev": {
"cache/filesystem-adapter": "^0.3.2",
"phpunit/phpunit": "~4",
"squizlabs/php_codesniffer": "~2.3",
"symfony/css-selector": "~2.1",
"symfony/dom-crawler": "~2.1"
},
"suggest": {
"cache/filesystem-adapter": "For caching certs and tokens (using Google_Client::setCache)"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.x-dev"
}
},
"autoload": {
"psr-0": {
"Google_": "src/"
},
"classmap": [
"src/Google/Service/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"description": "Client library for Google APIs",
"homepage": "http://developers.google.com/api-client-library/php",
"keywords": [
"google"
],
"time": "2017-11-03T01:19:53+00:00"
},
{
"name": "google/apiclient-services",
"version": "v0.61",
"source": {
"type": "git",
"url": "https://github.com/google/google-api-php-client-services.git",
"reference": "f7221039fda179b3f5096a6272b38706f2a6fcd0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/google/google-api-php-client-services/zipball/f7221039fda179b3f5096a6272b38706f2a6fcd0",
"reference": "f7221039fda179b3f5096a6272b38706f2a6fcd0",
"shasum": ""
},
"require": {
"php": ">=5.4"
},
"require-dev": {
"phpunit/phpunit": "~4.8"
},
"type": "library",
"autoload": {
"psr-0": {
"Google_Service_": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"description": "Client library for Google APIs",
"homepage": "http://developers.google.com/api-client-library/php",
"keywords": [
"google"
],
"time": "2018-05-26T00:23:39+00:00"
},
{
"name": "google/auth",
"version": "v1.3.0",
"source": {
"type": "git",
"url": "https://github.com/google/google-auth-library-php.git",
"reference": "8f7c96146b2c62d3f4c6bbc4b5bb8a8e396b0b71"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/google/google-auth-library-php/zipball/8f7c96146b2c62d3f4c6bbc4b5bb8a8e396b0b71",
"reference": "8f7c96146b2c62d3f4c6bbc4b5bb8a8e396b0b71",
"shasum": ""
},
"require": {
"firebase/php-jwt": "~2.0|~3.0|~4.0|~5.0",
"guzzlehttp/guzzle": "~5.3.1|~6.0",
"guzzlehttp/psr7": "^1.2",
"php": ">=5.4",
"psr/cache": "^1.0",
"psr/http-message": "^1.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^1.11",
"guzzlehttp/promises": "0.1.1|^1.3",
"phpunit/phpunit": "^4.8.36|^5.7",
"sebastian/comparator": ">=1.2.3"
},
"type": "library",
"autoload": {
"psr-4": {
"Google\\Auth\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"description": "Google Auth Library for PHP",
"homepage": "http://github.com/google/google-auth-library-php",
"keywords": [
"Authentication",
"google",
"oauth2"
],
"time": "2018-04-06T19:26:30+00:00"
},
{
"name": "grasmash/expander",
"version": "1.0.0",
@@ -823,6 +1012,187 @@
"description": "Expands internal property references in a yaml file.",
"time": "2017-12-16T16:06:03+00:00"
},
{
"name": "guzzlehttp/guzzle",
"version": "6.3.3",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/407b0cb880ace85c9b63c5f9551db498cb2d50ba",
"reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba",
"shasum": ""
},
"require": {
"guzzlehttp/promises": "^1.0",
"guzzlehttp/psr7": "^1.4",
"php": ">=5.5"
},
"require-dev": {
"ext-curl": "*",
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0",
"psr/log": "^1.0"
},
"suggest": {
"psr/log": "Required for using the Log middleware"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "6.3-dev"
}
},
"autoload": {
"files": [
"src/functions_include.php"
],
"psr-4": {
"GuzzleHttp\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle is a PHP HTTP client library",
"homepage": "http://guzzlephp.org/",
"keywords": [
"client",
"curl",
"framework",
"http",
"http client",
"rest",
"web service"
],
"time": "2018-04-22T15:46:56+00:00"
},
{
"name": "guzzlehttp/promises",
"version": "v1.3.1",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
"reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646",
"reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646",
"shasum": ""
},
"require": {
"php": ">=5.5.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Promise\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle promises library",
"keywords": [
"promise"
],
"time": "2016-12-20T10:07:11+00:00"
},
{
"name": "guzzlehttp/psr7",
"version": "1.4.2",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
"reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
"shasum": ""
},
"require": {
"php": ">=5.4.0",
"psr/http-message": "~1.0"
},
"provide": {
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Tobias Schultze",
"homepage": "https://github.com/Tobion"
}
],
"description": "PSR-7 message implementation that also provides common utility methods",
"keywords": [
"http",
"message",
"request",
"response",
"stream",
"uri",
"url"
],
"time": "2017-03-20T17:10:46+00:00"
},
{
"name": "league/container",
"version": "2.4.1",
@@ -890,16 +1260,16 @@
},
{
"name": "monolog/monolog",
"version": "1.13.1",
"version": "1.23.0",
"source": {
"type": "git",
"url": "https://github.com/Seldaek/monolog.git",
"reference": "c31a2c4e8db5da8b46c74cf275d7f109c0f249ac"
"reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Seldaek/monolog/zipball/c31a2c4e8db5da8b46c74cf275d7f109c0f249ac",
"reference": "c31a2c4e8db5da8b46c74cf275d7f109c0f249ac",
"url": "https://api.github.com/repos/Seldaek/monolog/zipball/fd8c787753b3a2ad11bc60c063cff1358a32a3b4",
"reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4",
"shasum": ""
},
"require": {
@@ -910,14 +1280,17 @@
"psr/log-implementation": "1.0.0"
},
"require-dev": {
"aws/aws-sdk-php": "~2.4, >2.4.8",
"aws/aws-sdk-php": "^2.4.9 || ^3.0",
"doctrine/couchdb": "~1.0@dev",
"graylog2/gelf-php": "~1.0",
"phpunit/phpunit": "~4.0",
"raven/raven": "~0.5",
"ruflin/elastica": "0.90.*",
"swiftmailer/swiftmailer": "~5.3",
"videlalvaro/php-amqplib": "~2.4"
"jakub-onderka/php-parallel-lint": "0.9",
"php-amqplib/php-amqplib": "~2.4",
"php-console/php-console": "^3.1.3",
"phpunit/phpunit": "~4.5",
"phpunit/phpunit-mock-objects": "2.3.0",
"ruflin/elastica": ">=0.90 <3.0",
"sentry/sentry": "^0.13",
"swiftmailer/swiftmailer": "^5.3|^6.0"
},
"suggest": {
"aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB",
@@ -925,15 +1298,17 @@
"ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)",
"ext-mongo": "Allow sending log messages to a MongoDB server",
"graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server",
"raven/raven": "Allow sending log messages to a Sentry server",
"mongodb/mongodb": "Allow sending log messages to a MongoDB server via PHP Driver",
"php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib",
"php-console/php-console": "Allow sending log messages to Google Chrome",
"rollbar/rollbar": "Allow sending log messages to Rollbar",
"ruflin/elastica": "Allow sending log messages to an Elastic Search server",
"videlalvaro/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib"
"sentry/sentry": "Allow sending log messages to a Sentry server"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.13.x-dev"
"dev-master": "2.0.x-dev"
}
},
"autoload": {
@@ -959,7 +1334,7 @@
"logging",
"psr-3"
],
"time": "2015-03-09T09:58:04+00:00"
"time": "2017-06-19T01:22:40+00:00"
},
{
"name": "neitanod/forceutf8",
@@ -1313,6 +1688,144 @@
],
"time": "2015-02-10T20:07:52+00:00"
},
{
"name": "phpseclib/phpseclib",
"version": "2.0.11",
"source": {
"type": "git",
"url": "https://github.com/phpseclib/phpseclib.git",
"reference": "7053f06f91b3de78e143d430e55a8f7889efc08b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/7053f06f91b3de78e143d430e55a8f7889efc08b",
"reference": "7053f06f91b3de78e143d430e55a8f7889efc08b",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"phing/phing": "~2.7",
"phpunit/phpunit": "^4.8.35|^5.7|^6.0",
"sami/sami": "~2.0",
"squizlabs/php_codesniffer": "~2.0"
},
"suggest": {
"ext-gmp": "Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.",
"ext-libsodium": "SSH2/SFTP can make use of some algorithms provided by the libsodium-php extension.",
"ext-mcrypt": "Install the Mcrypt extension in order to speed up a few other cryptographic operations.",
"ext-openssl": "Install the OpenSSL extension in order to speed up a wide variety of cryptographic operations."
},
"type": "library",
"autoload": {
"files": [
"phpseclib/bootstrap.php"
],
"psr-4": {
"phpseclib\\": "phpseclib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jim Wigginton",
"email": "terrafrost@php.net",
"role": "Lead Developer"
},
{
"name": "Patrick Monnerat",
"email": "pm@datasphere.ch",
"role": "Developer"
},
{
"name": "Andreas Fischer",
"email": "bantu@phpbb.com",
"role": "Developer"
},
{
"name": "Hans-Jürgen Petrich",
"email": "petrich@tronic-media.com",
"role": "Developer"
},
{
"name": "Graham Campbell",
"email": "graham@alt-three.com",
"role": "Developer"
}
],
"description": "PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.",
"homepage": "http://phpseclib.sourceforge.net",
"keywords": [
"BigInteger",
"aes",
"asn.1",
"asn1",
"blowfish",
"crypto",
"cryptography",
"encryption",
"rsa",
"security",
"sftp",
"signature",
"signing",
"ssh",
"twofish",
"x.509",
"x509"
],
"time": "2018-04-15T16:55:05+00:00"
},
{
"name": "psr/cache",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/php-fig/cache.git",
"reference": "d11b50ad223250cf17b86e38383413f5a6764bf8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8",
"reference": "d11b50ad223250cf17b86e38383413f5a6764bf8",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Cache\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for caching libraries",
"keywords": [
"cache",
"psr",
"psr-6"
],
"time": "2016-08-06T20:24:11+00:00"
},
{
"name": "psr/container",
"version": "1.0.0",
@@ -1362,6 +1875,56 @@
],
"time": "2017-02-14T16:28:37+00:00"
},
{
"name": "psr/http-message",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-message.git",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for HTTP messages",
"homepage": "https://github.com/php-fig/http-message",
"keywords": [
"http",
"http-message",
"psr",
"psr-7",
"request",
"response"
],
"time": "2016-08-06T14:39:51+00:00"
},
{
"name": "psr/log",
"version": "1.0.2",

View File

@@ -1,4 +0,0 @@
#!/usr/bin/env php
<?php
include 'export-plural-rules.php';

View File

@@ -0,0 +1 @@
../gettext/languages/bin/export-plural-rules

View File

@@ -1,234 +0,0 @@
<?php
use Gettext\Languages\Exporter\Exporter;
use Gettext\Languages\Language;
// Let's start by imposing that we don't accept any error or warning.
// This is a really life-saving approach.
error_reporting(E_ALL);
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
Enviro::echoErr("$errstr\nFile: $errfile\nLine: $errline\nCode: $errno\n");
die(5);
});
require_once dirname(__DIR__).'/src/autoloader.php';
// Parse the command line options
Enviro::initialize();
try {
if (isset(Enviro::$languages)) {
$languages = array();
foreach (Enviro::$languages as $languageId) {
$language = Language::getById($languageId);
if (!isset($language)) {
throw new Exception("Unable to find the language with id '$languageId'");
}
$languages[] = $language;
}
} else {
$languages = Language::getAll();
}
if (Enviro::$reduce) {
$languages = Enviro::reduce($languages);
}
if (isset(Enviro::$outputFilename)) {
echo call_user_func(array(Exporter::getExporterClassName(Enviro::$outputFormat), 'toFile'), $languages, Enviro::$outputFilename, array('us-ascii' => Enviro::$outputUSAscii));
} else {
echo call_user_func(array(Exporter::getExporterClassName(Enviro::$outputFormat), 'toString'), $languages, array('us-ascii' => Enviro::$outputUSAscii));
}
} catch (Exception $x) {
Enviro::echoErr($x->getMessage()."\n");
Enviro::echoErr("Trace:\n");
Enviro::echoErr($x->getTraceAsString()."\n");
die(4);
}
die(0);
/**
* Helper class to handle command line options.
*/
class Enviro
{
/**
* Shall the output contain only US-ASCII characters?
* @var bool
*/
public static $outputUSAscii;
/**
* The output format.
* @var string
*/
public static $outputFormat;
/**
* Output file name.
* @var string
*/
public static $outputFilename;
/**
* List of wanted language IDs; it not set: all languages will be returned.
* @var array|null
*/
public static $languages;
/**
* Reduce the language list to the minimum common denominator.
* @var bool
*/
public static $reduce;
/**
* Parse the command line options.
*/
public static function initialize()
{
global $argv;
self::$outputUSAscii = false;
self::$outputFormat = null;
self::$outputFilename = null;
self::$languages = null;
self::$reduce = null;
$exporters = Exporter::getExporters();
if (isset($argv) && is_array($argv)) {
foreach ($argv as $argi => $arg) {
if ($argi === 0) {
continue;
}
if (is_string($arg)) {
$argLC = trim(strtolower($arg));
switch ($argLC) {
case '--us-ascii':
self::$outputUSAscii = true;
break;
case '--reduce=yes':
self::$reduce = true;
break;
case '--reduce=no':
self::$reduce = false;
break;
default:
if (preg_match('/^--output=.+$/', $argLC)) {
if (isset(self::$outputFilename)) {
self::echoErr("The output file name has been specified more than once!\n");
self::showSyntax();
die(3);
}
list(, self::$outputFilename) = explode('=', $arg, 2);
self::$outputFilename = trim(self::$outputFilename);
} elseif (preg_match('/^--languages?=.+$/', $argLC)) {
list(, $s) = explode('=', $arg, 2);
$list = explode(',', $s);
if (is_array(self::$languages)) {
self::$languages = array_merge(self::$languages, $list);
} else {
self::$languages = $list;
}
} elseif (isset($exporters[$argLC])) {
if (isset(self::$outputFormat)) {
self::echoErr("The output format has been specified more than once!\n");
self::showSyntax();
die(3);
}
self::$outputFormat = $argLC;
} else {
self::echoErr("Unknown option: $arg\n");
self::showSyntax();
die(2);
}
break;
}
}
}
}
if (!isset(self::$outputFormat)) {
self::showSyntax();
die(1);
}
if (isset(self::$languages)) {
self::$languages = array_values(array_unique(self::$languages));
}
if (!isset(self::$reduce)) {
self::$reduce = isset(self::$languages) ? false : true;
}
}
/**
* Write out the syntax.
*/
public static function showSyntax()
{
$exporters = array_keys(Exporter::getExporters(true));
self::echoErr("Syntax: php ".basename(__FILE__)." [--us-ascii] [--languages=<LanguageId>[,<LanguageId>,...]] [--reduce=yes|no] [--output=<file name>] <".implode('|', $exporters).">\n");
self::echoErr("Where:\n");
self::echoErr("--us-ascii : if specified, the output will contain only US-ASCII characters.\n");
self::echoErr("--languages: (or --language) export only the specified language codes.\n");
self::echoErr(" Separate languages with commas; you can also use this argument\n");
self::echoErr(" more than once; it's case insensitive and accepts both '_' and\n");
self::echoErr(" '-' as locale chunks separator (eg we accept 'it_IT' as well as\n");
self::echoErr(" 'it-it').\n");
self::echoErr("--reduce : if set to yes the output won't contain languages with the same\n");
self::echoErr(" base language and rules.\n For instance nl_BE ('Flemish') will be\n");
self::echoErr(" omitted because it's the same as nl ('Dutch').\n");
self::echoErr(" Defaults to 'no' --languages is specified, to 'yes' otherwise.\n");
self::echoErr("--output : if specified, the output will be saved to <file name>. If not\n");
self::echoErr(" specified we'll output to standard output.\n");
self::echoErr("Output formats\n");
$len = max(array_map('strlen', $exporters));
foreach ($exporters as $exporter) {
self::echoErr(str_pad($exporter, $len).": ".Exporter::getExporterDescription($exporter)."\n");
}
}
/**
* Print a string to stderr.
* @param string $str The string to be printed out.
*/
public static function echoErr($str)
{
$hStdErr = @fopen('php://stderr', 'a');
if ($hStdErr === false) {
echo $str;
} else {
fwrite($hStdErr, $str);
fclose($hStdErr);
}
}
/**
* Reduce a language list to the minimum common denominator.
* @param Language[] $languages
* @return Language[]
*/
public static function reduce($languages)
{
for ($numChunks = 3; $numChunks >= 2; $numChunks--) {
$filtered = array();
foreach ($languages as $language) {
$chunks = explode('_', $language->id);
$compatibleFound = false;
if (count($chunks) === $numChunks) {
$categoriesHash = serialize($language->categories);
$otherIds = array();
$otherIds[] = $chunks[0];
for ($k = 2; $k < $numChunks; $k++) {
$otherIds[] = $chunks[0].'_'.$chunks[$numChunks - 1];
}
foreach ($languages as $check) {
foreach ($otherIds as $otherId) {
if (($check->id === $otherId) && ($check->formula === $language->formula) && (serialize($check->categories) === $categoriesHash)) {
$compatibleFound = true;
break;
}
}
if ($compatibleFound === true) {
break;
}
}
}
if (!$compatibleFound) {
$filtered[] = $language;
}
}
$languages = $filtered;
}
return $languages;
}
}

View File

@@ -0,0 +1 @@
../gettext/languages/bin/export-plural-rules.php

View File

@@ -1,170 +0,0 @@
#!/usr/bin/env php
<?php
/**
* @copyright Copyright (c) 2014 Carsten Brandt
* @license https://github.com/cebe/markdown/blob/master/LICENSE
* @link https://github.com/cebe/markdown#readme
*/
$composerAutoload = [
__DIR__ . '/../vendor/autoload.php', // standalone with "composer install" run
__DIR__ . '/../../../autoload.php', // script is installed as a composer binary
];
foreach ($composerAutoload as $autoload) {
if (file_exists($autoload)) {
require($autoload);
break;
}
}
// Send all errors to stderr
ini_set('display_errors', 'stderr');
$flavor = 'cebe\\markdown\\Markdown';
$flavors = [
'gfm' => ['cebe\\markdown\\GithubMarkdown', __DIR__ . '/../GithubMarkdown.php'],
'extra' => ['cebe\\markdown\\MarkdownExtra', __DIR__ . '/../MarkdownExtra.php'],
];
$full = false;
$src = [];
foreach($argv as $k => $arg) {
if ($k == 0) {
continue;
}
if ($arg[0] == '-') {
$arg = explode('=', $arg);
switch($arg[0]) {
case '--flavor':
if (isset($arg[1])) {
if (isset($flavors[$arg[1]])) {
require($flavors[$arg[1]][1]);
$flavor = $flavors[$arg[1]][0];
} else {
error("Unknown flavor: " . $arg[1], "usage");
}
} else {
error("Incomplete argument --flavor!", "usage");
}
break;
case '--full':
$full = true;
break;
case '-h':
case '--help':
echo "PHP Markdown to HTML converter\n";
echo "------------------------------\n\n";
echo "by Carsten Brandt <mail@cebe.cc>\n\n";
usage();
break;
default:
error("Unknown argument " . $arg[0], "usage");
}
} else {
$src[] = $arg;
}
}
if (empty($src)) {
$markdown = file_get_contents("php://stdin");
} elseif (count($src) == 1) {
$file = reset($src);
if (!file_exists($file)) {
error("File does not exist:" . $file);
}
$markdown = file_get_contents($file);
} else {
error("Converting multiple files is not yet supported.", "usage");
}
/** @var cebe\markdown\Parser $md */
$md = new $flavor();
$markup = $md->parse($markdown);
if ($full) {
echo <<<HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<style>
body { font-family: Arial, sans-serif; }
code { background: #eeeeff; padding: 2px; }
li { margin-bottom: 5px; }
img { max-width: 1200px; }
table, td, th { border: solid 1px #ccc; border-collapse: collapse; }
</style>
</head>
<body>
$markup
</body>
</html>
HTML;
} else {
echo $markup;
}
// functions
/**
* Display usage information
*/
function usage() {
global $argv;
$cmd = $argv[0];
echo <<<EOF
Usage:
$cmd [--flavor=<flavor>] [--full] [file.md]
--flavor specifies the markdown flavor to use. If omitted the original markdown by John Gruber [1] will be used.
Available flavors:
gfm - Github flavored markdown [2]
extra - Markdown Extra [3]
--full ouput a full HTML page with head and body. If not given, only the parsed markdown will be output.
--help shows this usage information.
If no file is specified input will be read from STDIN.
Examples:
Render a file with original markdown:
$cmd README.md > README.html
Render a file using gihtub flavored markdown:
$cmd --flavor=gfm README.md > README.html
Convert the original markdown description to html using STDIN:
curl http://daringfireball.net/projects/markdown/syntax.text | $cmd > md.html
[1] http://daringfireball.net/projects/markdown/syntax
[2] https://help.github.com/articles/github-flavored-markdown
[3] http://michelf.ca/projects/php-markdown/extra/
EOF;
exit(1);
}
/**
* Send custom error message to stderr
* @param $message string
* @param $callback mixed called before script exit
* @return void
*/
function error($message, $callback = null) {
$fe = fopen("php://stderr", "w");
fwrite($fe, "Error: " . $message . "\n");
if (is_callable($callback)) {
call_user_func($callback);
}
exit(1);
}

1
core/lib/composer/vendor/bin/markdown vendored Symbolic link
View File

@@ -0,0 +1 @@
../cebe/markdown/bin/markdown

View File

@@ -1,53 +0,0 @@
#!/usr/bin/env php
<?php
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
if (version_compare('7.0.0', PHP_VERSION, '>')) {
fwrite(
STDERR,
sprintf(
'This version of PHPUnit is supported on PHP 7.0 and PHP 7.1.' . PHP_EOL .
'You are using PHP %s (%s).' . PHP_EOL,
PHP_VERSION,
PHP_BINARY
)
);
die(1);
}
if (!ini_get('date.timezone')) {
ini_set('date.timezone', 'UTC');
}
foreach (array(__DIR__ . '/../../autoload.php', __DIR__ . '/../vendor/autoload.php', __DIR__ . '/vendor/autoload.php') as $file) {
if (file_exists($file)) {
define('PHPUNIT_COMPOSER_INSTALL', $file);
break;
}
}
unset($file);
if (!defined('PHPUNIT_COMPOSER_INSTALL')) {
fwrite(
STDERR,
'You need to set up the project dependencies using Composer:' . PHP_EOL . PHP_EOL .
' composer install' . PHP_EOL . PHP_EOL .
'You can learn all about Composer on https://getcomposer.org/.' . PHP_EOL
);
die(1);
}
require PHPUNIT_COMPOSER_INSTALL;
PHPUnit\TextUI\Command::main();

1
core/lib/composer/vendor/bin/phpunit vendored Symbolic link
View File

@@ -0,0 +1 @@
../phpunit/phpunit/phpunit

View File

@@ -1,22 +0,0 @@
#!/usr/bin/env php
<?php
/**
* if we're running from phar load the phar autoload,
* else let the script 'robo' search for the autoloader
*/
if (strpos(basename(__FILE__), 'phar')) {
require_once 'phar://robo.phar/vendor/autoload.php';
} else {
if (file_exists(__DIR__.'/vendor/autoload.php')) {
require_once __DIR__.'/vendor/autoload.php';
} elseif (file_exists(__DIR__.'/../../autoload.php')) {
require_once __DIR__ . '/../../autoload.php';
} else {
require_once 'phar://robo.phar/vendor/autoload.php';
}
}
$runner = new \Robo\Runner();
$runner->setSelfUpdateRepository('consolidation/robo');
$statusCode = $runner->execute($_SERVER['argv']);
exit($statusCode);

1
core/lib/composer/vendor/bin/robo vendored Symbolic link
View File

@@ -0,0 +1 @@
../consolidation/robo/robo

View File

@@ -9,6 +9,8 @@ return array(
'File_Iterator' => $vendorDir . '/phpunit/php-file-iterator/src/Iterator.php',
'File_Iterator_Facade' => $vendorDir . '/phpunit/php-file-iterator/src/Facade.php',
'File_Iterator_Factory' => $vendorDir . '/phpunit/php-file-iterator/src/Factory.php',
'Google_Service_Exception' => $vendorDir . '/google/apiclient/src/Google/Service/Exception.php',
'Google_Service_Resource' => $vendorDir . '/google/apiclient/src/Google/Service/Resource.php',
'PHPUnit\\Exception' => $vendorDir . '/phpunit/phpunit/src/Exception.php',
'PHPUnit\\Framework\\Assert' => $vendorDir . '/phpunit/phpunit/src/Framework/Assert.php',
'PHPUnit\\Framework\\AssertionFailedError' => $vendorDir . '/phpunit/phpunit/src/Framework/AssertionFailedError.php',

View File

@@ -7,6 +7,10 @@ $baseDir = dirname($vendorDir);
return array(
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php',
'6124b4c8570aa390c21fafd04a26c69f' => $vendorDir . '/myclabs/deep-copy/src/DeepCopy/deep_copy.php',
'a0edc8309cc5e1d60e3047b5df6b7052' => $vendorDir . '/guzzlehttp/psr7/src/functions_include.php',
'c964ee0ededf28c96ebd9db5099ef910' => $vendorDir . '/guzzlehttp/promises/src/functions_include.php',
'37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php',
'2c102faa651ef8ea5874edb585946bce' => $vendorDir . '/swiftmailer/swiftmailer/lib/swift_required.php',
'6124b4c8570aa390c21fafd04a26c69f' => $vendorDir . '/myclabs/deep-copy/src/DeepCopy/deep_copy.php',
'decc78cc4436b1292c6c0d151b19445c' => $vendorDir . '/phpseclib/phpseclib/phpseclib/bootstrap.php',
);

View File

@@ -11,6 +11,8 @@ return array(
'PEAR' => array($vendorDir . '/pear/pear_exception'),
'Net' => array($vendorDir . '/pear/net_smtp', $vendorDir . '/pear/net_socket'),
'Mail' => array($vendorDir . '/pear/mail'),
'Google_Service_' => array($vendorDir . '/google/apiclient-services/src'),
'Google_' => array($vendorDir . '/google/apiclient/src'),
'ForceUTF8\\' => array($vendorDir . '/neitanod/forceutf8/src'),
'Doctrine\\Common\\Lexer\\' => array($vendorDir . '/doctrine/lexer/lib'),
'Dflydev\\DotAccessData' => array($vendorDir . '/dflydev/dot-access-data/src'),

View File

@@ -6,6 +6,7 @@ $vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'phpseclib\\' => array($vendorDir . '/phpseclib/phpseclib/phpseclib'),
'phpDocumentor\\Reflection\\' => array($vendorDir . '/phpdocumentor/reflection-common/src', $vendorDir . '/phpdocumentor/reflection-docblock/src', $vendorDir . '/phpdocumentor/type-resolver/src'),
'cebe\\markdown\\' => array($vendorDir . '/cebe/markdown'),
'Whoops\\' => array($vendorDir . '/filp/whoops/src/Whoops'),
@@ -20,14 +21,21 @@ return array(
'Symfony\\Component\\Console\\' => array($vendorDir . '/symfony/console'),
'Robo\\' => array($vendorDir . '/consolidation/robo/src'),
'Psr\\Log\\' => array($vendorDir . '/psr/log/Psr/Log'),
'Psr\\Http\\Message\\' => array($vendorDir . '/psr/http-message/src'),
'Psr\\Container\\' => array($vendorDir . '/psr/container/src'),
'Psr\\Cache\\' => array($vendorDir . '/psr/cache/src'),
'Monolog\\' => array($vendorDir . '/monolog/monolog/src/Monolog'),
'League\\Container\\' => array($vendorDir . '/league/container/src'),
'Interop\\Container\\' => array($vendorDir . '/container-interop/container-interop/src/Interop/Container'),
'GuzzleHttp\\Psr7\\' => array($vendorDir . '/guzzlehttp/psr7/src'),
'GuzzleHttp\\Promise\\' => array($vendorDir . '/guzzlehttp/promises/src'),
'GuzzleHttp\\' => array($vendorDir . '/guzzlehttp/guzzle/src'),
'Grasmash\\YamlExpander\\' => array($vendorDir . '/grasmash/yaml-expander/src'),
'Grasmash\\Expander\\' => array($vendorDir . '/grasmash/expander/src'),
'Google\\Auth\\' => array($vendorDir . '/google/auth/src'),
'Gettext\\Languages\\' => array($vendorDir . '/gettext/languages/src'),
'Gettext\\' => array($vendorDir . '/gettext/gettext/src'),
'Firebase\\JWT\\' => array($vendorDir . '/firebase/php-jwt/src'),
'Egulias\\EmailValidator\\' => array($vendorDir . '/egulias/email-validator/EmailValidator'),
'Doctrine\\Instantiator\\' => array($vendorDir . '/doctrine/instantiator/src/Doctrine/Instantiator'),
'DeepCopy\\' => array($vendorDir . '/myclabs/deep-copy/src/DeepCopy'),

View File

@@ -8,13 +8,18 @@ class ComposerStaticInit6d4a28cd96a5bc5d5b97781c062572d9
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
'6124b4c8570aa390c21fafd04a26c69f' => __DIR__ . '/..' . '/myclabs/deep-copy/src/DeepCopy/deep_copy.php',
'a0edc8309cc5e1d60e3047b5df6b7052' => __DIR__ . '/..' . '/guzzlehttp/psr7/src/functions_include.php',
'c964ee0ededf28c96ebd9db5099ef910' => __DIR__ . '/..' . '/guzzlehttp/promises/src/functions_include.php',
'37a3dc5111fe8f707ab4c132ef1dbc62' => __DIR__ . '/..' . '/guzzlehttp/guzzle/src/functions_include.php',
'2c102faa651ef8ea5874edb585946bce' => __DIR__ . '/..' . '/swiftmailer/swiftmailer/lib/swift_required.php',
'6124b4c8570aa390c21fafd04a26c69f' => __DIR__ . '/..' . '/myclabs/deep-copy/src/DeepCopy/deep_copy.php',
'decc78cc4436b1292c6c0d151b19445c' => __DIR__ . '/..' . '/phpseclib/phpseclib/phpseclib/bootstrap.php',
);
public static $prefixLengthsPsr4 = array (
'p' =>
array (
'phpseclib\\' => 10,
'phpDocumentor\\Reflection\\' => 25,
),
'c' =>
@@ -44,7 +49,9 @@ class ComposerStaticInit6d4a28cd96a5bc5d5b97781c062572d9
'P' =>
array (
'Psr\\Log\\' => 8,
'Psr\\Http\\Message\\' => 17,
'Psr\\Container\\' => 14,
'Psr\\Cache\\' => 10,
),
'M' =>
array (
@@ -60,11 +67,19 @@ class ComposerStaticInit6d4a28cd96a5bc5d5b97781c062572d9
),
'G' =>
array (
'GuzzleHttp\\Psr7\\' => 16,
'GuzzleHttp\\Promise\\' => 19,
'GuzzleHttp\\' => 11,
'Grasmash\\YamlExpander\\' => 22,
'Grasmash\\Expander\\' => 18,
'Google\\Auth\\' => 12,
'Gettext\\Languages\\' => 18,
'Gettext\\' => 8,
),
'F' =>
array (
'Firebase\\JWT\\' => 13,
),
'E' =>
array (
'Egulias\\EmailValidator\\' => 23,
@@ -88,6 +103,10 @@ class ComposerStaticInit6d4a28cd96a5bc5d5b97781c062572d9
);
public static $prefixDirsPsr4 = array (
'phpseclib\\' =>
array (
0 => __DIR__ . '/..' . '/phpseclib/phpseclib/phpseclib',
),
'phpDocumentor\\Reflection\\' =>
array (
0 => __DIR__ . '/..' . '/phpdocumentor/reflection-common/src',
@@ -146,10 +165,18 @@ class ComposerStaticInit6d4a28cd96a5bc5d5b97781c062572d9
array (
0 => __DIR__ . '/..' . '/psr/log/Psr/Log',
),
'Psr\\Http\\Message\\' =>
array (
0 => __DIR__ . '/..' . '/psr/http-message/src',
),
'Psr\\Container\\' =>
array (
0 => __DIR__ . '/..' . '/psr/container/src',
),
'Psr\\Cache\\' =>
array (
0 => __DIR__ . '/..' . '/psr/cache/src',
),
'Monolog\\' =>
array (
0 => __DIR__ . '/..' . '/monolog/monolog/src/Monolog',
@@ -162,6 +189,18 @@ class ComposerStaticInit6d4a28cd96a5bc5d5b97781c062572d9
array (
0 => __DIR__ . '/..' . '/container-interop/container-interop/src/Interop/Container',
),
'GuzzleHttp\\Psr7\\' =>
array (
0 => __DIR__ . '/..' . '/guzzlehttp/psr7/src',
),
'GuzzleHttp\\Promise\\' =>
array (
0 => __DIR__ . '/..' . '/guzzlehttp/promises/src',
),
'GuzzleHttp\\' =>
array (
0 => __DIR__ . '/..' . '/guzzlehttp/guzzle/src',
),
'Grasmash\\YamlExpander\\' =>
array (
0 => __DIR__ . '/..' . '/grasmash/yaml-expander/src',
@@ -170,6 +209,10 @@ class ComposerStaticInit6d4a28cd96a5bc5d5b97781c062572d9
array (
0 => __DIR__ . '/..' . '/grasmash/expander/src',
),
'Google\\Auth\\' =>
array (
0 => __DIR__ . '/..' . '/google/auth/src',
),
'Gettext\\Languages\\' =>
array (
0 => __DIR__ . '/..' . '/gettext/languages/src',
@@ -178,6 +221,10 @@ class ComposerStaticInit6d4a28cd96a5bc5d5b97781c062572d9
array (
0 => __DIR__ . '/..' . '/gettext/gettext/src',
),
'Firebase\\JWT\\' =>
array (
0 => __DIR__ . '/..' . '/firebase/php-jwt/src',
),
'Egulias\\EmailValidator\\' =>
array (
0 => __DIR__ . '/..' . '/egulias/email-validator/EmailValidator',
@@ -250,6 +297,17 @@ class ComposerStaticInit6d4a28cd96a5bc5d5b97781c062572d9
0 => __DIR__ . '/..' . '/pear/mail',
),
),
'G' =>
array (
'Google_Service_' =>
array (
0 => __DIR__ . '/..' . '/google/apiclient-services/src',
),
'Google_' =>
array (
0 => __DIR__ . '/..' . '/google/apiclient/src',
),
),
'F' =>
array (
'ForceUTF8\\' =>
@@ -285,6 +343,8 @@ class ComposerStaticInit6d4a28cd96a5bc5d5b97781c062572d9
'File_Iterator' => __DIR__ . '/..' . '/phpunit/php-file-iterator/src/Iterator.php',
'File_Iterator_Facade' => __DIR__ . '/..' . '/phpunit/php-file-iterator/src/Facade.php',
'File_Iterator_Factory' => __DIR__ . '/..' . '/phpunit/php-file-iterator/src/Factory.php',
'Google_Service_Exception' => __DIR__ . '/..' . '/google/apiclient/src/Google/Service/Exception.php',
'Google_Service_Resource' => __DIR__ . '/..' . '/google/apiclient/src/Google/Service/Resource.php',
'PHPUnit\\Exception' => __DIR__ . '/..' . '/phpunit/phpunit/src/Exception.php',
'PHPUnit\\Framework\\Assert' => __DIR__ . '/..' . '/phpunit/phpunit/src/Framework/Assert.php',
'PHPUnit\\Framework\\AssertionFailedError' => __DIR__ . '/..' . '/phpunit/phpunit/src/Framework/AssertionFailedError.php',

View File

@@ -678,6 +678,54 @@
"whoops"
]
},
{
"name": "firebase/php-jwt",
"version": "v5.0.0",
"version_normalized": "5.0.0.0",
"source": {
"type": "git",
"url": "https://github.com/firebase/php-jwt.git",
"reference": "9984a4d3a32ae7673d6971ea00bae9d0a1abba0e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/firebase/php-jwt/zipball/9984a4d3a32ae7673d6971ea00bae9d0a1abba0e",
"reference": "9984a4d3a32ae7673d6971ea00bae9d0a1abba0e",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": " 4.8.35"
},
"time": "2017-06-27T22:17:23+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-4": {
"Firebase\\JWT\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Neuman Vong",
"email": "neuman+pear@twilio.com",
"role": "Developer"
},
{
"name": "Anant Narayanan",
"email": "anant@php.net",
"role": "Developer"
}
],
"description": "A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.",
"homepage": "https://github.com/firebase/php-jwt"
},
{
"name": "gettext/gettext",
"version": "v4.0.0",
@@ -803,6 +851,155 @@
"unicode"
]
},
{
"name": "google/apiclient",
"version": "v2.2.1",
"version_normalized": "2.2.1.0",
"source": {
"type": "git",
"url": "https://github.com/google/google-api-php-client.git",
"reference": "b69b8ac4bf6501793c389d4e013a79d09c85c5f2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/google/google-api-php-client/zipball/b69b8ac4bf6501793c389d4e013a79d09c85c5f2",
"reference": "b69b8ac4bf6501793c389d4e013a79d09c85c5f2",
"shasum": ""
},
"require": {
"firebase/php-jwt": "~2.0|~3.0|~4.0|~5.0",
"google/apiclient-services": "~0.13",
"google/auth": "^1.0",
"guzzlehttp/guzzle": "~5.3.1|~6.0",
"guzzlehttp/psr7": "^1.2",
"monolog/monolog": "^1.17",
"php": ">=5.4",
"phpseclib/phpseclib": "~0.3.10|~2.0"
},
"require-dev": {
"cache/filesystem-adapter": "^0.3.2",
"phpunit/phpunit": "~4",
"squizlabs/php_codesniffer": "~2.3",
"symfony/css-selector": "~2.1",
"symfony/dom-crawler": "~2.1"
},
"suggest": {
"cache/filesystem-adapter": "For caching certs and tokens (using Google_Client::setCache)"
},
"time": "2017-11-03T01:19:53+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.x-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-0": {
"Google_": "src/"
},
"classmap": [
"src/Google/Service/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"description": "Client library for Google APIs",
"homepage": "http://developers.google.com/api-client-library/php",
"keywords": [
"google"
]
},
{
"name": "google/apiclient-services",
"version": "v0.61",
"version_normalized": "0.61.0.0",
"source": {
"type": "git",
"url": "https://github.com/google/google-api-php-client-services.git",
"reference": "f7221039fda179b3f5096a6272b38706f2a6fcd0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/google/google-api-php-client-services/zipball/f7221039fda179b3f5096a6272b38706f2a6fcd0",
"reference": "f7221039fda179b3f5096a6272b38706f2a6fcd0",
"shasum": ""
},
"require": {
"php": ">=5.4"
},
"require-dev": {
"phpunit/phpunit": "~4.8"
},
"time": "2018-05-26T00:23:39+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"Google_Service_": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"description": "Client library for Google APIs",
"homepage": "http://developers.google.com/api-client-library/php",
"keywords": [
"google"
]
},
{
"name": "google/auth",
"version": "v1.3.0",
"version_normalized": "1.3.0.0",
"source": {
"type": "git",
"url": "https://github.com/google/google-auth-library-php.git",
"reference": "8f7c96146b2c62d3f4c6bbc4b5bb8a8e396b0b71"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/google/google-auth-library-php/zipball/8f7c96146b2c62d3f4c6bbc4b5bb8a8e396b0b71",
"reference": "8f7c96146b2c62d3f4c6bbc4b5bb8a8e396b0b71",
"shasum": ""
},
"require": {
"firebase/php-jwt": "~2.0|~3.0|~4.0|~5.0",
"guzzlehttp/guzzle": "~5.3.1|~6.0",
"guzzlehttp/psr7": "^1.2",
"php": ">=5.4",
"psr/cache": "^1.0",
"psr/http-message": "^1.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^1.11",
"guzzlehttp/promises": "0.1.1|^1.3",
"phpunit/phpunit": "^4.8.36|^5.7",
"sebastian/comparator": ">=1.2.3"
},
"time": "2018-04-06T19:26:30+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-4": {
"Google\\Auth\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"description": "Google Auth Library for PHP",
"homepage": "http://github.com/google/google-auth-library-php",
"keywords": [
"Authentication",
"google",
"oauth2"
]
},
{
"name": "grasmash/expander",
"version": "1.0.0",
@@ -902,6 +1099,193 @@
],
"description": "Expands internal property references in a yaml file."
},
{
"name": "guzzlehttp/guzzle",
"version": "6.3.3",
"version_normalized": "6.3.3.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/407b0cb880ace85c9b63c5f9551db498cb2d50ba",
"reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba",
"shasum": ""
},
"require": {
"guzzlehttp/promises": "^1.0",
"guzzlehttp/psr7": "^1.4",
"php": ">=5.5"
},
"require-dev": {
"ext-curl": "*",
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0",
"psr/log": "^1.0"
},
"suggest": {
"psr/log": "Required for using the Log middleware"
},
"time": "2018-04-22T15:46:56+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "6.3-dev"
}
},
"installation-source": "dist",
"autoload": {
"files": [
"src/functions_include.php"
],
"psr-4": {
"GuzzleHttp\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle is a PHP HTTP client library",
"homepage": "http://guzzlephp.org/",
"keywords": [
"client",
"curl",
"framework",
"http",
"http client",
"rest",
"web service"
]
},
{
"name": "guzzlehttp/promises",
"version": "v1.3.1",
"version_normalized": "1.3.1.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
"reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646",
"reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646",
"shasum": ""
},
"require": {
"php": ">=5.5.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0"
},
"time": "2016-12-20T10:07:11+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"GuzzleHttp\\Promise\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle promises library",
"keywords": [
"promise"
]
},
{
"name": "guzzlehttp/psr7",
"version": "1.4.2",
"version_normalized": "1.4.2.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
"reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
"shasum": ""
},
"require": {
"php": ">=5.4.0",
"psr/http-message": "~1.0"
},
"provide": {
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"time": "2017-03-20T17:10:46+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Tobias Schultze",
"homepage": "https://github.com/Tobion"
}
],
"description": "PSR-7 message implementation that also provides common utility methods",
"keywords": [
"http",
"message",
"request",
"response",
"stream",
"uri",
"url"
]
},
{
"name": "league/container",
"version": "2.4.1",
@@ -971,17 +1355,17 @@
},
{
"name": "monolog/monolog",
"version": "1.13.1",
"version_normalized": "1.13.1.0",
"version": "1.23.0",
"version_normalized": "1.23.0.0",
"source": {
"type": "git",
"url": "https://github.com/Seldaek/monolog.git",
"reference": "c31a2c4e8db5da8b46c74cf275d7f109c0f249ac"
"reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Seldaek/monolog/zipball/c31a2c4e8db5da8b46c74cf275d7f109c0f249ac",
"reference": "c31a2c4e8db5da8b46c74cf275d7f109c0f249ac",
"url": "https://api.github.com/repos/Seldaek/monolog/zipball/fd8c787753b3a2ad11bc60c063cff1358a32a3b4",
"reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4",
"shasum": ""
},
"require": {
@@ -992,14 +1376,17 @@
"psr/log-implementation": "1.0.0"
},
"require-dev": {
"aws/aws-sdk-php": "~2.4, >2.4.8",
"aws/aws-sdk-php": "^2.4.9 || ^3.0",
"doctrine/couchdb": "~1.0@dev",
"graylog2/gelf-php": "~1.0",
"phpunit/phpunit": "~4.0",
"raven/raven": "~0.5",
"ruflin/elastica": "0.90.*",
"swiftmailer/swiftmailer": "~5.3",
"videlalvaro/php-amqplib": "~2.4"
"jakub-onderka/php-parallel-lint": "0.9",
"php-amqplib/php-amqplib": "~2.4",
"php-console/php-console": "^3.1.3",
"phpunit/phpunit": "~4.5",
"phpunit/phpunit-mock-objects": "2.3.0",
"ruflin/elastica": ">=0.90 <3.0",
"sentry/sentry": "^0.13",
"swiftmailer/swiftmailer": "^5.3|^6.0"
},
"suggest": {
"aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB",
@@ -1007,16 +1394,18 @@
"ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)",
"ext-mongo": "Allow sending log messages to a MongoDB server",
"graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server",
"raven/raven": "Allow sending log messages to a Sentry server",
"mongodb/mongodb": "Allow sending log messages to a MongoDB server via PHP Driver",
"php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib",
"php-console/php-console": "Allow sending log messages to Google Chrome",
"rollbar/rollbar": "Allow sending log messages to Rollbar",
"ruflin/elastica": "Allow sending log messages to an Elastic Search server",
"videlalvaro/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib"
"sentry/sentry": "Allow sending log messages to a Sentry server"
},
"time": "2015-03-09T09:58:04+00:00",
"time": "2017-06-19T01:22:40+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.13.x-dev"
"dev-master": "2.0.x-dev"
}
},
"installation-source": "dist",
@@ -1721,6 +2110,100 @@
}
]
},
{
"name": "phpseclib/phpseclib",
"version": "2.0.11",
"version_normalized": "2.0.11.0",
"source": {
"type": "git",
"url": "https://github.com/phpseclib/phpseclib.git",
"reference": "7053f06f91b3de78e143d430e55a8f7889efc08b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/7053f06f91b3de78e143d430e55a8f7889efc08b",
"reference": "7053f06f91b3de78e143d430e55a8f7889efc08b",
"shasum": ""
},
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"phing/phing": "~2.7",
"phpunit/phpunit": "^4.8.35|^5.7|^6.0",
"sami/sami": "~2.0",
"squizlabs/php_codesniffer": "~2.0"
},
"suggest": {
"ext-gmp": "Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.",
"ext-libsodium": "SSH2/SFTP can make use of some algorithms provided by the libsodium-php extension.",
"ext-mcrypt": "Install the Mcrypt extension in order to speed up a few other cryptographic operations.",
"ext-openssl": "Install the OpenSSL extension in order to speed up a wide variety of cryptographic operations."
},
"time": "2018-04-15T16:55:05+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"files": [
"phpseclib/bootstrap.php"
],
"psr-4": {
"phpseclib\\": "phpseclib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jim Wigginton",
"email": "terrafrost@php.net",
"role": "Lead Developer"
},
{
"name": "Patrick Monnerat",
"email": "pm@datasphere.ch",
"role": "Developer"
},
{
"name": "Andreas Fischer",
"email": "bantu@phpbb.com",
"role": "Developer"
},
{
"name": "Hans-Jürgen Petrich",
"email": "petrich@tronic-media.com",
"role": "Developer"
},
{
"name": "Graham Campbell",
"email": "graham@alt-three.com",
"role": "Developer"
}
],
"description": "PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.",
"homepage": "http://phpseclib.sourceforge.net",
"keywords": [
"BigInteger",
"aes",
"asn.1",
"asn1",
"blowfish",
"crypto",
"cryptography",
"encryption",
"rsa",
"security",
"sftp",
"signature",
"signing",
"ssh",
"twofish",
"x.509",
"x509"
]
},
{
"name": "phpspec/prophecy",
"version": "1.7.3",
@@ -2192,6 +2675,54 @@
"xunit"
]
},
{
"name": "psr/cache",
"version": "1.0.1",
"version_normalized": "1.0.1.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/cache.git",
"reference": "d11b50ad223250cf17b86e38383413f5a6764bf8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8",
"reference": "d11b50ad223250cf17b86e38383413f5a6764bf8",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"time": "2016-08-06T20:24:11+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"Psr\\Cache\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for caching libraries",
"keywords": [
"cache",
"psr",
"psr-6"
]
},
{
"name": "psr/container",
"version": "1.0.0",
@@ -2243,6 +2774,58 @@
"psr"
]
},
{
"name": "psr/http-message",
"version": "1.0.1",
"version_normalized": "1.0.1.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-message.git",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"time": "2016-08-06T14:39:51+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"Psr\\Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common interface for HTTP messages",
"homepage": "https://github.com/php-fig/http-message",
"keywords": [
"http",
"http-message",
"psr",
"psr-7",
"request",
"response"
]
},
{
"name": "psr/log",
"version": "1.0.2",

View File

@@ -0,0 +1 @@
../../src

View File

@@ -1,157 +0,0 @@
<?php
namespace Consolidation\Config;
use Dflydev\DotAccessData\Data;
class Config implements ConfigInterface
{
/**
* @var Data
*/
protected $config;
/**
* TODO: make this private in 2.0 to prevent being saved as an array
* Making private now breaks backward compatibility
*
* @var Data
*/
protected $defaults;
/**
* Create a new configuration object, and initialize it with
* the provided nested array containing configuration data.
*
* @param array $data - Config data to store
*/
public function __construct(array $data = null)
{
$this->config = new Data($data);
$this->setDefaults(new Data());
}
/**
* {@inheritdoc}
*/
public function has($key)
{
return ($this->config->has($key));
}
/**
* {@inheritdoc}
*/
public function get($key, $defaultFallback = null)
{
if ($this->has($key)) {
return $this->config->get($key);
}
return $this->getDefault($key, $defaultFallback);
}
/**
* {@inheritdoc}
*/
public function set($key, $value)
{
$this->config->set($key, $value);
return $this;
}
/**
* {@inheritdoc}
*/
public function import($data)
{
return $this->replace($data);
}
/**
* {@inheritdoc}
*/
public function replace($data)
{
$this->config = new Data($data);
return $this;
}
/**
* {@inheritdoc}
*/
public function combine($data)
{
if (!empty($data)) {
$this->config->import($data, true);
}
return $this;
}
/**
* {@inheritdoc}
*/
public function export()
{
return $this->config->export();
}
/**
* {@inheritdoc}
*/
public function hasDefault($key)
{
return $this->getDefaults()->has($key);
}
/**
* {@inheritdoc}
*/
public function getDefault($key, $defaultFallback = null)
{
return $this->hasDefault($key) ? $this->getDefaults()->get($key) : $defaultFallback;
}
/**
* {@inheritdoc}
*/
public function setDefault($key, $value)
{
$this->getDefaults()->set($key, $value);
return $this;
}
/**
* Return the class $defaults property and ensure it's a Data object
* TODO: remove Data object validation in 2.0
*
* @return Data
*/
protected function getDefaults()
{
// Ensure $this->defaults is a Data object (not an array)
if (!$this->defaults instanceof Data) {
$this->setDefaults($this->defaults);
}
return $this->defaults;
}
/**
* Sets the $defaults class parameter
* TODO: remove support for array in 2.0 as this would currently break backward compatibility
*
* @param Data|array $defaults
*
* @throws \Exception
*/
protected function setDefaults($defaults)
{
if (is_array($defaults)) {
$this->defaults = new Data($defaults);
} elseif ($defaults instanceof Data) {
$this->defaults = $defaults;
} else {
throw new \Exception("Unknown type provided for \$defaults");
}
}
}

View File

@@ -1,105 +0,0 @@
<?php
namespace Consolidation\Config;
interface ConfigInterface
{
/**
* Determine if a non-default config value exists.
*/
public function has($key);
/**
* Fetch a configuration value
*
* @param string $key Which config item to look up
* @param string|null $defaultFallback Fallback default value to use when
* configuration object has neither a value nor a default. Use is
* discouraged; use default context in ConfigOverlay, or provide defaults
* using a config processor.
*
* @return mixed
*/
public function get($key, $defaultFallback = null);
/**
* Set a config value
*
* @param string $key
* @param mixed $value
*
* @return $this
*/
public function set($key, $value);
/**
* Import configuration from the provided nexted array, replacing whatever
* was here previously. No processing is done on the provided data.
*
* @deprecated Use 'replace'. Dflydev\DotAccessData\Data::import() merges, which is confusing, since this method replaces.
*
* @param array $data
* @return Config
*/
public function import($data);
/**
* Load configuration from the provided nexted array, replacing whatever
* was here previously. No processing is done on the provided data.
*
* TODO: This will become a required method in version 2.0. Adding now
* would break clients that implement ConfigInterface.
*
* @param array $data
* @return Config
*/
// public function replace($data);
/**
* Import configuration from the provided nexted array, merging with whatever
* was here previously. No processing is done on the provided data.
* Any data provided to the combine() method will overwrite existing data
* with the same key.
*
* TODO: This will become a required method in version 2.0. Adding now
* would break clients that implement ConfigInterface.
*
* @param array $data
* @return Config
*/
// public function combine($data);
/**
* Export all configuration as a nested array.
*/
public function export();
/**
* Return the default value for a given configuration item.
*
* @param string $key
*
* @return mixed
*/
public function hasDefault($key);
/**
* Return the default value for a given configuration item.
*
* @param string $key
* @param mixed $defaultFallback
*
* @return mixed
*/
public function getDefault($key, $defaultFallback = null);
/**
* Set the default value for a configuration setting. This allows us to
* set defaults either before or after more specific configuration values
* are loaded. Keeping defaults separate from current settings also
* allows us to determine when a setting has been overridden.
*
* @param string $key
* @param string $value
*/
public function setDefault($key, $value);
}

View File

@@ -1,10 +0,0 @@
<?php
namespace Consolidation\Config;
interface GlobalOptionDefaultValuesInterface
{
/**
* Return an associative array of option-key => default-value
*/
public function getGlobalOptionDefaultValues();
}

View File

@@ -1,127 +0,0 @@
<?php
namespace Consolidation\Config\Inject;
use Consolidation\Config\ConfigInterface;
use Consolidation\Config\Util\ConfigFallback;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputOption;
class ConfigForCommand implements EventSubscriberInterface
{
protected $config;
protected $application;
public function __construct(ConfigInterface $config)
{
$this->config = $config;
}
public function setApplication(Application $application)
{
$this->application = $application;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return [ConsoleEvents::COMMAND => 'injectConfiguration'];
}
/**
* Before a Console command runs, inject configuration settings
* for this command into the default value of the options of
* this command.
*
* @param \Symfony\Component\Console\Event\ConsoleCommandEvent $event
*/
public function injectConfiguration(ConsoleCommandEvent $event)
{
$command = $event->getCommand();
$this->injectConfigurationForGlobalOptions($event->getInput());
$this->injectConfigurationForCommand($command, $event->getInput());
$targetOfHelpCommand = $this->getHelpCommandTarget($command, $event->getInput());
if ($targetOfHelpCommand) {
$this->injectConfigurationForCommand($targetOfHelpCommand, $event->getInput());
}
}
protected function injectConfigurationForGlobalOptions($input)
{
if (!$this->application) {
return;
}
$configGroup = new ConfigFallback($this->config, 'options');
$definition = $this->application->getDefinition();
$options = $definition->getOptions();
return $this->injectConfigGroupIntoOptions($configGroup, $options, $input);
}
protected function injectConfigurationForCommand($command, $input)
{
$commandName = $command->getName();
$commandName = str_replace(':', '.', $commandName);
$configGroup = new ConfigFallback($this->config, $commandName, 'command.', '.options.');
$definition = $command->getDefinition();
$options = $definition->getOptions();
return $this->injectConfigGroupIntoOptions($configGroup, $options, $input);
}
protected function injectConfigGroupIntoOptions($configGroup, $options, $input)
{
foreach ($options as $option => $inputOption) {
$key = str_replace('.', '-', $option);
$value = $configGroup->get($key);
if ($value !== null) {
if (is_bool($value) && ($value == true)) {
$input->setOption($key, $value);
} elseif ($inputOption->acceptValue()) {
$inputOption->setDefault($value);
}
}
}
}
protected function getHelpCommandTarget($command, $input)
{
if (($command->getName() != 'help') || (!isset($this->application))) {
return false;
}
$this->fixInputForSymfony2($command, $input);
// Symfony Console helpfully swaps 'command_name' and 'command'
// depending on whether the user entered `help foo` or `--help foo`.
// One of these is always `help`, and the other is the command we
// are actually interested in.
$nameOfCommandToDescribe = $input->getArgument('command_name');
if ($nameOfCommandToDescribe == 'help') {
$nameOfCommandToDescribe = $input->getArgument('command');
}
return $this->application->find($nameOfCommandToDescribe);
}
protected function fixInputForSymfony2($command, $input)
{
// Symfony 3.x prepares $input for us; Symfony 2.x, on the other
// hand, passes it in prior to binding with the command definition,
// so we have to go to a little extra work. It may be inadvisable
// to do these steps for commands other than 'help'.
if (!$input->hasArgument('command_name')) {
$command->ignoreValidationErrors();
$command->mergeApplicationDefinition();
$input->bind($command->getDefinition());
}
}
}

View File

@@ -1,47 +0,0 @@
<?php
namespace Consolidation\Config\Inject;
use Consolidation\Config\Util\ConfigMerge;
/**
* Given an object that contains configuration methods, inject any
* configuration found in the configuration file.
*
* The proper use for this method is to call setter methods of the
* provided object. Using configuration to call methods that do work
* is an abuse of this mechanism.
*/
class ConfigForSetters
{
protected $config;
public function __construct($config, $group, $prefix = '', $postfix = '')
{
if (!empty($group) && empty($postfix)) {
$postfix = '.';
}
$this->config = new ConfigMerge($config, $group, $prefix, $postfix);
}
public function apply($object, $configurationKey)
{
$settings = $this->config->get($configurationKey);
foreach ($settings as $setterMethod => $args) {
$fn = [$object, $setterMethod];
if (is_callable($fn)) {
$result = call_user_func_array($fn, (array)$args);
// We require that $fn must only be used with setter methods.
// Setter methods are required to always return $this so that
// they may be chained. We will therefore throw an exception
// for any setter that returns something else.
if ($result != $object) {
$methodDescription = get_class($object) . "::$setterMethod";
$propertyDescription = $this->config->describe($configurationKey);
throw new \Exception("$methodDescription did not return '\$this' when processing $propertyDescription.");
}
}
}
}
}

View File

@@ -1,35 +0,0 @@
<?php
namespace Consolidation\Config\Loader;
/**
* Load configuration files.
*/
abstract class ConfigLoader implements ConfigLoaderInterface
{
protected $config = [];
protected $source = '';
public function getSourceName()
{
return $this->source;
}
protected function setSourceName($source)
{
$this->source = $source;
return $this;
}
public function export()
{
return $this->config;
}
public function keys()
{
return array_keys($this->config);
}
abstract public function load($path);
}

View File

@@ -1,29 +0,0 @@
<?php
namespace Consolidation\Config\Loader;
/**
* Load configuration files, and fill in any property values that
* need to be expanded.
*/
interface ConfigLoaderInterface
{
/**
* Convert loaded configuration into a simple php nested array.
*
* @return array
*/
public function export();
/**
* Return the top-level keys in the exported data.
*
* @return array
*/
public function keys();
/**
* Return a symbolic name for this configuration loader instance.
*/
public function getSourceName();
}

View File

@@ -1,167 +0,0 @@
<?php
namespace Consolidation\Config\Loader;
use Grasmash\Expander\Expander;
use Consolidation\Config\Util\ArrayUtil;
/**
* The config processor combines multiple configuration
* files together, and processes them as necessary.
*/
class ConfigProcessor
{
protected $processedConfig = [];
protected $unprocessedConfig = [];
protected $expander;
public function __construct($expander = null)
{
$this->expander = $expander ?: new Expander();
}
/**
* Extend the configuration to be processed with the
* configuration provided by the specified loader.
*
* @param ConfigLoaderInterface $loader
*/
public function extend(ConfigLoaderInterface $loader)
{
return $this->addFromSource($loader->export(), $loader->getSourceName());
}
/**
* Extend the configuration to be processed with
* the provided nested array.
*
* @param array $data
*/
public function add($data)
{
$this->unprocessedConfig[] = $data;
return $this;
}
/**
* Extend the configuration to be processed with
* the provided nested array. Also record the name
* of the data source, if applicable.
*
* @param array $data
* @param string $source
*/
protected function addFromSource($data, $source = '')
{
if (empty($source)) {
return $this->add($data);
}
$this->unprocessedConfig[$source] = $data;
return $this;
}
/**
* Process all of the configuration that has been collected,
* and return a nested array.
*
* @return array
*/
public function export($referenceArray = [])
{
if (!empty($this->unprocessedConfig)) {
$this->processedConfig = $this->process(
$this->processedConfig,
$this->fetchUnprocessed(),
$referenceArray
);
}
return $this->processedConfig;
}
/**
* To aid in debugging: return the source of each configuration item.
* n.b. Must call this function *before* export and save the result
* if persistence is desired.
*/
public function sources()
{
$sources = [];
foreach ($this->unprocessedConfig as $sourceName => $config) {
if (!empty($sourceName)) {
$configSources = ArrayUtil::fillRecursive($config, $sourceName);
$sources = ArrayUtil::mergeRecursiveDistinct($sources, $configSources);
}
}
return $sources;
}
/**
* Get the configuration to be processed, and clear out the
* 'unprocessed' list.
*
* @return array
*/
protected function fetchUnprocessed()
{
$toBeProcessed = $this->unprocessedConfig;
$this->unprocessedConfig = [];
return $toBeProcessed;
}
/**
* Use a map-reduce to evaluate the items to be processed,
* and merge them into the processed array.
*
* @param array $processed
* @param array $toBeProcessed
* @return array
*/
protected function process(array $processed, array $toBeProcessed, $referenceArray = [])
{
$toBeReduced = array_map([$this, 'preprocess'], $toBeProcessed);
$reduced = array_reduce($toBeReduced, [$this, 'reduceOne'], $processed);
return $this->evaluate($reduced, $referenceArray);
}
/**
* Process a single configuration file from the 'to be processed'
* list. By default this is a no-op. Override this method to
* provide any desired configuration preprocessing, e.g. dot-notation
* expansion of the configuration keys, etc.
*
* @param array $config
* @return array
*/
protected function preprocess(array $config)
{
return $config;
}
/**
* Evaluate one item in the 'to be evaluated' list, and then
* merge it into the processed configuration (the 'carry').
*
* @param array $processed
* @param array $config
* @return array
*/
protected function reduceOne(array $processed, array $config)
{
return ArrayUtil::mergeRecursiveDistinct($processed, $config);
}
/**
* Evaluate one configuration item.
*
* @param array $processed
* @param array $config
* @return array
*/
protected function evaluate(array $config, $referenceArray = [])
{
return $this->expander->expandArrayProperties(
$config,
$referenceArray
);
}
}

View File

@@ -1,26 +0,0 @@
<?php
namespace Consolidation\Config\Loader;
use Symfony\Component\Yaml\Yaml;
/**
* Load configuration files, and fill in any property values that
* need to be expanded.
*/
class YamlConfigLoader extends ConfigLoader
{
public function load($path)
{
$this->setSourceName($path);
// We silently skip any nonexistent config files, so that
// clients may simply `load` all of their candidates.
if (!file_exists($path)) {
$this->config = [];
return $this;
}
$this->config = (array) Yaml::parse(file_get_contents($path));
return $this;
}
}

View File

@@ -1,75 +0,0 @@
<?php
namespace Consolidation\Config\Util;
/**
* Useful array utilities.
*/
class ArrayUtil
{
/**
* Merges arrays recursively while preserving.
*
* @param array $array1
* @param array $array2
*
* @return array
*
* @see http://php.net/manual/en/function.array-merge-recursive.php#92195
* @see https://github.com/grasmash/bolt/blob/robo-rebase/src/Robo/Common/ArrayManipulator.php#L22
*/
public static function mergeRecursiveDistinct(
array &$array1,
array &$array2
) {
$merged = $array1;
foreach ($array2 as $key => &$value) {
$merged[$key] = self::mergeRecursiveValue($merged, $key, $value);
}
return $merged;
}
/**
* Process the value in an mergeRecursiveDistinct - make a recursive
* call if needed.
*/
protected static function mergeRecursiveValue(&$merged, $key, $value)
{
if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
return self::mergeRecursiveDistinct($merged[$key], $value);
}
return $value;
}
/**
* Fills all of the leaf-node values of a nested array with the
* provided replacement value.
*/
public static function fillRecursive(array $data, $fill)
{
$result = [];
foreach ($data as $key => $value) {
$result[$key] = $fill;
if (self::isAssociative($value)) {
$result[$key] = self::fillRecursive($value, $fill);
}
}
return $result;
}
/**
* Return true if the provided parameter is an array, and at least
* one key is non-numeric.
*/
public static function isAssociative($testArray)
{
if (!is_array($testArray)) {
return false;
}
foreach (array_keys($testArray) as $key) {
if (!is_numeric($key)) {
return true;
}
}
return false;
}
}

View File

@@ -1,51 +0,0 @@
<?php
namespace Consolidation\Config\Util;
/**
* Fetch a configuration value from a configuration group. If the
* desired configuration value is not found in the most specific
* group named, keep stepping up to the next parent group until a
* value is located.
*
* Given the following constructor inputs:
* - $prefix = "command."
* - $group = "foo.bar.baz"
* - $postfix = ".options."
* Then the `get` method will then consider, in order:
* - command.foo.bar.baz.options
* - command.foo.bar.options
* - command.foo.options
* If any of these contain an option for "$key", then return its value.
*/
class ConfigFallback extends ConfigGroup
{
/**
* @inheritdoc
*/
public function get($key)
{
return $this->getWithFallback($key, $this->group, $this->prefix, $this->postfix);
}
/**
* Fetch an option value from a given key, or, if that specific key does
* not contain a value, then consult various fallback options until a
* value is found.
*
*/
protected function getWithFallback($key, $group, $prefix = '', $postfix = '.')
{
$configKey = "{$prefix}{$group}${postfix}{$key}";
if ($this->config->has($configKey)) {
return $this->config->get($configKey);
}
if ($this->config->hasDefault($configKey)) {
return $this->config->getDefault($configKey);
}
$moreGeneralGroupname = $this->moreGeneralGroupName($group);
if ($moreGeneralGroupname) {
return $this->getWithFallback($key, $moreGeneralGroupname, $prefix, $postfix);
}
return null;
}
}

View File

@@ -1,61 +0,0 @@
<?php
namespace Consolidation\Config\Util;
/**
* Fetch a configuration value from a configuration group. If the
* desired configuration value is not found in the most specific
* group named, keep stepping up to the next parent group until a
* value is located.
*
* Given the following constructor inputs:
* - $prefix = "command."
* - $group = "foo.bar.baz"
* - $postfix = ".options."
* Then the `get` method will then consider, in order:
* - command.foo.bar.baz.options
* - command.foo.bar.options
* - command.foo.options
* If any of these contain an option for "$key", then return its value.
*/
abstract class ConfigGroup
{
protected $config;
protected $group;
protected $prefix;
protected $postfix;
public function __construct($config, $group, $prefix = '', $postfix = '.')
{
$this->config = $config;
$this->group = $group;
$this->prefix = $prefix;
$this->postfix = $postfix;
}
/**
* Return a description of the configuration group (with prefix and postfix).
*/
public function describe($property)
{
return $this->prefix . $this->group . $this->postfix . $property;
}
/**
* Get the requested configuration key from the most specific configuration
* group that contains it.
*/
abstract public function get($key);
/**
* Given a group name, such as "foo.bar.baz", return the next configuration
* group in the fallback hierarchy, e.g. "foo.bar".
*/
protected function moreGeneralGroupName($group)
{
$result = preg_replace('#\.[^.]*$#', '', $group);
if ($result != $group) {
return $result;
}
return false;
}
}

View File

@@ -1,34 +0,0 @@
<?php
namespace Consolidation\Config\Util;
/**
* Works like 'getWithFallback', but merges results from all applicable
* groups. Settings from most specific group take precedence.
*/
class ConfigMerge extends ConfigGroup
{
/**
* @inheritdoc
*/
public function get($key)
{
return $this->getWithMerge($key, $this->group, $this->prefix, $this->postfix);
}
/**
* Merge available configuration from each configuration group.
*/
public function getWithMerge($key, $group, $prefix = '', $postfix = '.')
{
$configKey = "{$prefix}{$group}${postfix}{$key}";
$result = $this->config->get($configKey, []);
if (!is_array($result)) {
throw new \UnexpectedValueException($configKey . ' must be a list of settings to apply.');
}
$moreGeneralGroupname = $this->moreGeneralGroupName($group);
if ($moreGeneralGroupname) {
$result += $this->getWithMerge($key, $moreGeneralGroupname, $prefix, $postfix);
}
return $result;
}
}

View File

@@ -1,203 +0,0 @@
<?php
namespace Consolidation\Config\Util;
use Consolidation\Config\Config;
use Consolidation\Config\ConfigInterface;
/**
* Overlay different configuration objects that implement ConfigInterface
* to make a priority-based, merged configuration object.
*
* Note that using a ConfigOverlay hides the defaults stored in each
* individual configuration context. When using overlays, always call
* getDefault / setDefault on the ConfigOverlay object itself.
*/
class ConfigOverlay implements ConfigInterface
{
protected $contexts = [];
const DEFAULT_CONTEXT = 'default';
const PROCESS_CONTEXT = 'process';
public function __construct()
{
$this->contexts[self::DEFAULT_CONTEXT] = new Config();
$this->contexts[self::PROCESS_CONTEXT] = new Config();
}
/**
* Add a named configuration object to the configuration overlay.
* Configuration objects added LAST have HIGHEST priority, with the
* exception of the fact that the process context always has the
* highest priority.
*
* If a context has already been added, its priority will not change.
*/
public function addContext($name, ConfigInterface $config)
{
$process = $this->contexts[self::PROCESS_CONTEXT];
unset($this->contexts[self::PROCESS_CONTEXT]);
$this->contexts[$name] = $config;
$this->contexts[self::PROCESS_CONTEXT] = $process;
return $this;
}
/**
* Add a placeholder context that will be prioritized higher than
* existing contexts. This is done to ensure that contexts added
* later will maintain a higher priority if the placeholder context
* is later relaced with a different configuration set via addContext().
*
* @param string $name
* @return $this
*/
public function addPlaceholder($name)
{
return $this->addContext($name, new Config());
}
/**
* Increase the priority of the named context such that it is higher
* in priority than any existing context except for the 'process'
* context.
*
* @param string $name
* @return $this
*/
public function increasePriority($name)
{
$config = $this->getContext($name);
unset($this->contexts[$name]);
return $this->addContext($name, $config);
}
public function hasContext($name)
{
return isset($this->contexts[$name]);
}
public function getContext($name)
{
if ($this->hasContext($name)) {
return $this->contexts[$name];
}
return new Config();
}
public function removeContext($name)
{
unset($this->contexts[$name]);
}
/**
* Determine if a non-default config value exists.
*/
public function findContext($key)
{
foreach (array_reverse($this->contexts) as $name => $config) {
if ($config->has($key)) {
return $config;
}
}
return false;
}
/**
* @inheritdoc
*/
public function has($key)
{
return $this->findContext($key) != false;
}
/**
* @inheritdoc
*/
public function get($key, $default = null)
{
$context = $this->findContext($key);
if ($context) {
return $context->get($key, $default);
}
return $default;
}
/**
* @inheritdoc
*/
public function set($key, $value)
{
$this->contexts[self::PROCESS_CONTEXT]->set($key, $value);
return $this;
}
/**
* @inheritdoc
*/
public function import($data)
{
$this->unsupported(__FUNCTION__);
}
/**
* @inheritdoc
*/
public function replace($data)
{
$this->unsupported(__FUNCTION__);
}
/**
* @inheritdoc
*/
public function combine($data)
{
$this->unsupported(__FUNCTION__);
}
/**
* @inheritdoc
*/
protected function unsupported($fn)
{
throw new \Exception("The method '$fn' is not supported for the ConfigOverlay class.");
}
/**
* @inheritdoc
*/
public function export()
{
$export = [];
foreach ($this->contexts as $name => $config) {
$export = array_merge_recursive($export, $config->export());
}
return $export;
}
/**
* @inheritdoc
*/
public function hasDefault($key)
{
return $this->contexts[self::DEFAULT_CONTEXT]->has($key);
}
/**
* @inheritdoc
*/
public function getDefault($key, $default = null)
{
return $this->contexts[self::DEFAULT_CONTEXT]->get($key, $default);
}
/**
* @inheritdoc
*/
public function setDefault($key, $value)
{
$this->contexts[self::DEFAULT_CONTEXT]->set($key, $value);
return $this;
}
}

View File

@@ -1,96 +0,0 @@
<?php
namespace Consolidation\Config\Util;
use Consolidation\Config\Config;
use Consolidation\Config\ConfigInterface;
/**
* Provide a configuration object that fetches values from environment
* variables.
*/
class EnvConfig implements ConfigInterface
{
/** @var string */
protected $prefix;
/**
* EnvConfig constructor
*
* @param $prefix The string to appear before every environment
* variable key. For example, if the prefix is 'MYAPP_', then
* the key 'foo.bar' will be fetched from the environment variable
* MYAPP_FOO_BAR.
*/
public function __construct($prefix)
{
// Ensure that the prefix is always uppercase, and always
// ends with a '_', regardless of the form the caller provided.
$this->prefix = strtoupper(rtrim($prefix, '_')) . '_';
}
/**
* @inheritdoc
*/
public function has($key)
{
return $this->get($key) !== null;
}
/**
* @inheritdoc
*/
public function get($key, $defaultFallback = null)
{
$envKey = $this->prefix . strtoupper(strtr($key, '.-', '__'));
$envKey = str_replace($this->prefix . $this->prefix, $this->prefix, $envKey);
return getenv($envKey) ?: $defaultFallback;
}
/**
* @inheritdoc
*/
public function set($key, $value)
{
throw new \Exception('Cannot call "set" on environmental configuration.');
}
/**
* @inheritdoc
*/
public function import($data)
{
// no-op
}
/**
* @inheritdoc
*/
public function export()
{
return [];
}
/**
* @inheritdoc
*/
public function hasDefault($key)
{
return false;
}
/**
* @inheritdoc
*/
public function getDefault($key, $defaultFallback = null)
{
return $defaultFallback;
}
/**
* @inheritdoc
*/
public function setDefault($key, $value)
{
throw new \Exception('Cannot call "setDefault" on environmental configuration.');
}
}

View File

@@ -0,0 +1 @@
../../tests

View File

@@ -1,130 +0,0 @@
<?php
namespace Consolidation\Config\Inject;
use Consolidation\Config\Config;
use Consolidation\TestUtils\MyFooCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\OutputInterface;
class ConfigForCommandTest extends \PHPUnit_Framework_TestCase
{
protected $config;
protected function setUp()
{
$data = [
// Global options
'options' => [
'global' => 'from-config',
],
// Define some configuration settings for the options for
// the commands my:foo and my:bar.
'command' => [
'my' => [
// commands.my.options.* apply to all my:* commands.
'options' => [
'dir' => '/etc/common',
'priority' => 'normal',
],
'foo' => [
// commands.my.foo.options.* apply only to the my:foo command.
'options' => [
'name' => 'baz',
],
],
],
],
];
$this->config = new Config($data);
}
public function testInjection()
{
$command = new MyFooCommand();
$input = new StringInput('my:foo');
list($status, $output) = $this->runCommandViaApplication($command, $input);
$expectedOutput = <<< EOT
Enter my:foo
dir: /etc/common
name: baz
other: fish
EOT;
$this->assertEquals(0, $status);
$this->assertEquals($expectedOutput, $output);
}
public function testInjectionWithOverride()
{
$command = new MyFooCommand();
$input = new StringInput('my:foo --name=Fred');
list($status, $output) = $this->runCommandViaApplication($command, $input);
$expectedOutput = <<< EOT
Enter my:foo
dir: /etc/common
name: Fred
other: fish
EOT;
$this->assertEquals(0, $status);
$this->assertEquals($expectedOutput, $output);
}
public function testHelpDefaultInjection()
{
$command = new MyFooCommand();
$input = new StringInput('help my:foo');
list($status, $output) = $this->runCommandViaApplication($command, $input);
$expectedOutput = <<< EOT
What is the name of the thing we are naming [default: "baz"]
EOT;
$this->assertEquals(0, $status);
$this->assertContains($expectedOutput, $output);
$expectedOutput = <<< EOT
A certain global option. [default: "from-config"]
EOT;
$this->assertContains($expectedOutput, $output);
}
protected function runCommandViaApplication($command, $input)
{
$application = new Application('TestApplication', '0.0.0');
$application->getDefinition()
->addOption(
new InputOption('--global', null, InputOption::VALUE_REQUIRED, 'A certain global option.', 'hardcoded')
);
$output = new BufferedOutput();
$configInjector = new ConfigForCommand($this->config);
$configInjector->setApplication($application);
$eventDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
$eventDispatcher->addSubscriber($configInjector);
$application->setDispatcher($eventDispatcher);
$application->setAutoExit(false);
$application->add($command);
$statusCode = $application->run($input, $output);
$commandOutput = trim($output->fetch());
return [$statusCode, $commandOutput];
}
}

View File

@@ -1,87 +0,0 @@
<?php
namespace Consolidation\Config\Inject;
use Consolidation\Config\Config;
use Consolidation\TestUtils\ApplyConfigTestTarget;
class ConfigForSettersTest extends \PHPUnit_Framework_TestCase
{
public function testApplyConfig()
{
$data = [
// Define some configuration settings for the configuration
// of some task \My\Tasks\Operations\Frobulate.
'task' => [
'Operations' => [
// task.Operations.settings apply to all tasks in
// any *.Tass.Operations namespace.
'settings' => [
'dir' => '/base/dir',
],
'Frobulate' => [
// task.Operations.Frobulate.settings applies only
// the Frobulate task.
'settings' => [
'dir' => '/override/dir',
],
],
],
],
];
$config = new Config($data);
$applicator = new ConfigForSetters($config, 'Operations.Frobulate', 'task.');
$testTarget = new ApplyConfigTestTarget();
$applicator->apply($testTarget, 'settings');
$this->assertEquals('/override/dir', $testTarget->getDir());
$this->assertEquals(null, $testTarget->getBad());
}
public function testApplyBadConfig()
{
$data = [
// Define some configuration settings for the configuration
// of some task \My\Tasks\Operations\Frobulate.
'task' => [
'Operations' => [
// task.Operations.settings apply to all tasks in
// any *.Tass.Operations namespace.
'settings' => [
'dir' => '/base/dir',
],
'Frobulate' => [
// task.Operations.Frobulate.settings applies only
// the Frobulate task.
'settings' => [
'bad' => 'fire truck',
],
],
],
],
];
$config = new Config($data);
$applicator = new ConfigForSetters($config, 'Operations.Frobulate', 'task.');
$testTarget = new ApplyConfigTestTarget();
$exceptionMessage = '';
try
{
$applicator->apply($testTarget, 'settings');
}
catch (\Exception $e)
{
$exceptionMessage = $e->getMessage();
}
// We would prefer it if bad methods were never called; unfortunately,
// declaring the return type of a method cannot be done in a reliable
// way (via reflection) until php 7, so we allow these methods to be
// called for now.
$this->assertEquals('fire truck', $testTarget->getBad());
$this->assertEquals('Consolidation\\TestUtils\\ApplyConfigTestTarget::bad did not return \'$this\' when processing task.Operations.Frobulate.settings.', $exceptionMessage);
}
}

View File

@@ -1,91 +0,0 @@
<?php
namespace Consolidation\Config\Util;
use Consolidation\Config\Config;
class ConfigGroupTest extends \PHPUnit_Framework_TestCase
{
protected $config;
protected function setUp()
{
$data = [
// Define some configuration settings for the options for
// the commands my:foo and my:bar.
'command' => [
'my' => [
// commands.my.options.* apply to all my:* commands.
'options' => [
'path' => '/etc/common',
'priority' => 'normal',
],
'foo' => [
// commands.my.foo.options.* apply only to the my:foo command.
'options' => [
'name' => 'baz',
],
],
'bar' => [
// Similarly, commands.my.bar.options is for the my:bar command.
'options' => [
'priority' => 'high',
],
],
],
],
// Define some configuration settings for the configuration
// of some task \My\Tasks\Operations\Frobulate.
'task' => [
'Operations' => [
// task.Operations.settings apply to all tasks in
// any *.Tass.Operations namespace.
'settings' => [
'dir' => '/base/dir',
],
'Frobulate' => [
// task.Operations.Frobulate.settings applies only
// the Frobulate task.
'settings' => [
'object' => 'fire truck',
],
],
],
],
];
$this->config = new Config($data);
}
public function testDotNotation()
{
// Test the test
$this->assertEquals('baz', $this->config->get('command.my.foo.options.name'));
}
public function testFallback()
{
$fooFallback = new ConfigFallback($this->config, 'my.foo', 'command.', '.options.');
$barFallback = new ConfigFallback($this->config, 'my.bar', 'command.', '.options.');
$this->assertEquals(null, $barFallback->get('name'));
$this->assertEquals('baz', $fooFallback->get('name'));
$this->assertEquals('high', $barFallback->get('priority'));
$this->assertEquals('normal', $fooFallback->get('priority'));
$this->assertEquals('/etc/common', $barFallback->get('path'));
$this->assertEquals('/etc/common', $fooFallback->get('path'));
}
public function testMerge()
{
$frobulateMerge = new ConfigMerge($this->config, 'Operations.Frobulate', 'task.');
$settings = $frobulateMerge->get('settings');
$this->assertEquals('fire truck', $settings['object']);
$this->assertEquals('/base/dir', $settings['dir']);
$keys = array_keys($settings);
sort($keys);
$this->assertEquals('dir,object', implode(',', $keys));
}
}

View File

@@ -1,29 +0,0 @@
<?php
namespace Consolidation\Config\Loader;
class ConfigLoaderTest extends \PHPUnit_Framework_TestCase
{
public function testConfigLoader()
{
$loader = new YamlConfigLoader();
// Assert that our test data exists (test the test)
$path = __DIR__ . '/data/config-1.yml';
$this->assertTrue(file_exists($path));
$loader->load($path);
$configFile = basename($loader->getSourceName());
$this->assertEquals('config-1.yml', $configFile);
// Make sure that the data we loaded contained the expected keys
$keys = $loader->keys();
sort($keys);
$keysString = implode(',', $keys);
$this->assertEquals('c,m', $keysString);
$configData = $loader->export();
$this->assertEquals('foo', $configData['c']);
$this->assertEquals('1', $configData['m'][0]);
}
}

View File

@@ -1,168 +0,0 @@
<?php
namespace Consolidation\Config\Util;
use Consolidation\Config\Config;
use Consolidation\Config\Loader\ConfigProcessor;
use Consolidation\Config\Loader\YamlConfigLoader;
class ConfigOverlayTest extends \PHPUnit_Framework_TestCase
{
protected $overlay;
protected function setUp()
{
$aliasContext = new Config();
$aliasContext->import([
'hidden-by-a' => 'alias hidden-by-a',
'hidden-by-process' => 'alias hidden-by-process',
'options' =>[
'a-a' => 'alias-a',
],
'command' => [
'foo' => [
'bar' => [
'command' => [
'options' => [
'a-b' => 'alias-b',
],
],
],
],
],
]);
$configFileContext = new Config();
$configFileContext->import([
'hidden-by-cf' => 'config-file hidden-by-cf',
'hidden-by-a' => 'config-file hidden-by-a',
'hidden-by-process' => 'config-file hidden-by-process',
'options' =>[
'cf-a' => 'config-file-a',
],
'command' => [
'foo' => [
'bar' => [
'command' => [
'options' => [
'cf-b' => 'config-file-b',
],
],
],
],
],
]);
$this->overlay = new ConfigOverlay();
$this->overlay->set('hidden-by-process', 'process-h');
$this->overlay->addContext('cf', $configFileContext);
$this->overlay->addContext('a', $aliasContext);
$this->overlay->setDefault('df-a', 'default');
$this->overlay->setDefault('hidden-by-a', 'default hidden-by-a');
$this->overlay->setDefault('hidden-by-cf', 'default hidden-by-cf');
$this->overlay->setDefault('hidden-by-process', 'default hidden-by-process');
}
public function testGetPriority()
{
$this->assertEquals('process-h', $this->overlay->get('hidden-by-process'));
$this->assertEquals('config-file hidden-by-cf', $this->overlay->get('hidden-by-cf'));
$this->assertEquals('alias hidden-by-a', $this->overlay->get('hidden-by-a'));
}
public function testDefault()
{
$this->assertEquals('alias-a', $this->overlay->get('options.a-a'));
$this->assertEquals('alias-a', $this->overlay->get('options.a-a', 'ignored'));
$this->assertEquals('default', $this->overlay->getDefault('df-a', 'ignored'));
$this->assertEquals('nsv', $this->overlay->getDefault('a-a', 'nsv'));
$this->overlay->setDefault('df-a', 'new value');
$this->assertEquals('new value', $this->overlay->getDefault('df-a', 'ignored'));
}
public function testExport()
{
$data = $this->overlay->export();
$this->assertEquals('config-file-a', $data['options']['cf-a']);
$this->assertEquals('alias-a', $data['options']['a-a']);
}
/**
* @expectedException Exception
*/
public function testImport()
{
$data = $this->overlay->import(['a' => 'value']);
}
public function testMaintainPriority()
{
// Get and re-add the 'cf' context. Its priority should not change.
$configFileContext = $this->overlay->getContext('cf');
$this->overlay->addContext('cf', $configFileContext);
// These asserts are the same as in testGetPriority
$this->assertEquals('process-h', $this->overlay->get('hidden-by-process'));
$this->assertEquals('config-file hidden-by-cf', $this->overlay->get('hidden-by-cf'));
$this->assertEquals('alias hidden-by-a', $this->overlay->get('hidden-by-a'));
}
public function testChangePriority()
{
// Increase the priority of the 'cf' context. Now, it should have a higher
// priority than the 'alias' context, but should still have a lower
// priority than the 'process' context.
$this->overlay->increasePriority('cf');
// These asserts are the same as in testGetPriority
$this->assertEquals('process-h', $this->overlay->get('hidden-by-process'));
$this->assertEquals('config-file hidden-by-cf', $this->overlay->get('hidden-by-cf'));
// This one has changed: the config-file value is now found instead
// of the alias value.
$this->assertEquals('config-file hidden-by-a', $this->overlay->get('hidden-by-a'));
}
public function testPlaceholder()
{
$this->overlay->addPlaceholder('lower');
$higherContext = new Config();
$higherContext->import(['priority-test' => 'higher']);
$lowerContext = new Config();
$lowerContext->import(['priority-test' => 'lower']);
// Usually 'lower' would have the highest priority, since it is
// added last. However, our earlier call to 'addPlaceholder' reserves
// a spot for it, so the 'higher' context will end up with a higher
// priority.
$this->overlay->addContext('higher', $higherContext);
$this->overlay->addContext('lower', $lowerContext);
$this->assertEquals('higher', $this->overlay->get('priority-test', 'neither'));
// Test to see that we can change the value of the 'higher' context,
// and the change will be reflected in the overlay.
$higherContext->set('priority-test', 'changed');
$this->assertEquals('changed', $this->overlay->get('priority-test', 'neither'));
// Test to see that the 'process' context still has the highest priority.
$this->overlay->set('priority-test', 'process');
$higherContext->set('priority-test', 'ignored');
$this->assertEquals('process', $this->overlay->get('priority-test', 'neither'));
}
public function testDoesNotHave()
{
$context = $this->overlay->getContext('no-such-context');
$data = $context->export();
$this->assertEquals('[]', json_encode($data));
$this->assertTrue(!$this->overlay->has('no-such-key'));
$this->assertTrue(!$this->overlay->hasDefault('no-such-default'));
$this->assertEquals('no-such-value', $this->overlay->get('no-such-key', 'no-such-value'));
}
}

View File

@@ -1,152 +0,0 @@
<?php
namespace Consolidation\Config\Loader;
use Consolidation\TestUtils\TestLoader;
class ConfigProcessorTest extends \PHPUnit_Framework_TestCase
{
public function testConfigProcessorAdd()
{
$config1 = [
'c' => 'foo',
'm' => [1],
];
$config2 = [
'b' => '${c}bar',
'm' => [2],
];
$config3 = [
'a' => '${b}baz',
'm' => [3],
];
$processor = new ConfigProcessor();
$processor->add($config1);
$processor->add($config2);
$processor->add($config3);
$data = $processor->export();
$this->assertEquals('foo', $data['c']);
$this->assertEquals('foobar', $data['b']);
$this->assertEquals('foobarbaz', $data['a']);
}
public function processorForConfigMergeTest($provideSourceNames)
{
$config1 = [
'm' => [
'x' => 'x-1',
'y' => [
'r' => 'r-1',
's' => 's-1',
't' => 't-1',
],
'z' => 'z-1',
],
];
$config2 = [
'm' => [
'w' => 'w-2',
'y' => [
'q' => 'q-2',
's' => 's-2',
],
'z' => 'z-2',
],
];
$config3 = [
'm' => [
'v' => 'v-3',
'y' => [
't' => 't-3',
'u' => 'u-3',
],
'z' => 'z-3',
],
];
$processor = new ConfigProcessor();
$testLoader = new TestLoader();
$testLoader->set($config1);
$testLoader->setSourceName($provideSourceNames ? 'c-1' : '');
$processor->extend($testLoader);
$testLoader->set($config2);
$testLoader->setSourceName($provideSourceNames ? 'c-2' : '');
$processor->extend($testLoader);
$testLoader->set($config3);
$testLoader->setSourceName($provideSourceNames ? 'c-3' : '');
$processor->extend($testLoader);
return $processor;
}
public function testConfigProcessorMergeAssociative()
{
$processor = $this->processorForConfigMergeTest(false);
$data = $processor->export();
$this->assertEquals('{"m":{"x":"x-1","y":{"r":"r-1","s":"s-2","t":"t-3","q":"q-2","u":"u-3"},"z":"z-3","w":"w-2","v":"v-3"}}', json_encode($data));
}
public function testConfigProcessorMergeAssociativeWithSourceNames()
{
$processor = $this->processorForConfigMergeTest(true);
$sources = $processor->sources();
$data = $processor->export();
$this->assertEquals('{"m":{"x":"x-1","y":{"r":"r-1","s":"s-2","t":"t-3","q":"q-2","u":"u-3"},"z":"z-3","w":"w-2","v":"v-3"}}', json_encode($data));
$this->assertEquals('c-1', $sources['m']['x']);
$this->assertEquals('c-1', $sources['m']['y']['r']);
$this->assertEquals('c-2', $sources['m']['w']);
$this->assertEquals('c-2', $sources['m']['y']['s']);
$this->assertEquals('c-3', $sources['m']['z']);
$this->assertEquals('c-3', $sources['m']['y']['u']);
}
public function testConfiProcessorSources()
{
$processor = new ConfigProcessor();
$loader = new YamlConfigLoader();
$processor->extend($loader->load(__DIR__ . '/data/config-1.yml'));
$processor->extend($loader->load(__DIR__ . '/data/config-2.yml'));
$processor->extend($loader->load(__DIR__ . '/data/config-3.yml'));
$sources = $processor->sources();
$data = $processor->export();
$this->assertEquals('foo', $data['c']);
$this->assertEquals('foobar', $data['b']);
$this->assertEquals('foobarbaz', $data['a']);
$this->assertEquals('3', $data['m'][0]);
$this->assertEquals( __DIR__ . '/data/config-3.yml', $sources['a']);
$this->assertEquals( __DIR__ . '/data/config-2.yml', $sources['b']);
$this->assertEquals( __DIR__ . '/data/config-1.yml', $sources['c']);
$this->assertEquals( __DIR__ . '/data/config-3.yml', $sources['m']);
}
public function testConfiProcessorSourcesLoadInReverseOrder()
{
$processor = new ConfigProcessor();
$loader = new YamlConfigLoader();
$processor->extend($loader->load(__DIR__ . '/data/config-3.yml'));
$processor->extend($loader->load(__DIR__ . '/data/config-2.yml'));
$processor->extend($loader->load(__DIR__ . '/data/config-1.yml'));
$sources = $processor->sources();
$data = $processor->export();
$this->assertEquals('foo', $data['c']);
$this->assertEquals('foobar', $data['b']);
$this->assertEquals('foobarbaz', $data['a']);
$this->assertEquals('1', $data['m'][0]);
$this->assertEquals( __DIR__ . '/data/config-3.yml', $sources['a']);
$this->assertEquals( __DIR__ . '/data/config-2.yml', $sources['b']);
$this->assertEquals( __DIR__ . '/data/config-1.yml', $sources['c']);
$this->assertEquals( __DIR__ . '/data/config-1.yml', $sources['m']);
}
}

View File

@@ -1,140 +0,0 @@
<?php
namespace Consolidation\Config;
use Consolidation\Config\Loader\ConfigProcessor;
use Consolidation\Config\Loader\YamlConfigLoader;
class ConfigTest extends \PHPUnit_Framework_TestCase
{
public function testSetters()
{
// Pointless tests just to ensure everything is covered.
$config = new Config();
$config->set('foo', 'bar');
$data = $config->export();
$this->assertEquals('{"foo":"bar"}', json_encode($data));
}
public function testCombine()
{
// Pointless tests just to ensure everything is covered.
$config = new Config();
$config->set('foo', 'bar');
$config->set('baz', 'boz');
$config2 = new Config();
$config2->set('foo', 'fu');
$config2->set('new', 'blue');
$config->combine($config2->export());
$this->assertEquals('fu', $config->get('foo'));
$this->assertEquals('boz', $config->get('baz'));
$this->assertEquals('blue', $config->get('new'));
}
public function testDefault()
{
$data = [
'a' => 'foo',
'b' => 'bar',
'c' => 'boz',
];
$foo = ["foo" => "bar"];
$config = new Config($data);
$config->setDefault('c', 'other');
$config->setDefault('d', 'other');
$config->setDefault('f', $foo);
$this->assertEquals('foo', $config->get('a'));
$this->assertEquals('boz', $config->get('c'));
$this->assertEquals('other', $config->get('d'));
$this->assertEquals('other', $config->getDefault('c'));
$this->assertEquals('', $config->get('e'));
$this->assertEquals('bar', $config->get('f.foo'));
$this->assertEquals('{"foo":"bar"}', json_encode($config->get('f')));
}
public function testDefaultsArray()
{
$data = ['a' => 'foo', 'b' => 'bar', 'c' => 'boz',];
$defaults = ['d' => 'foo', 'e' => 'bar', 'f' => 'boz',];
// Create reflection class to test private methods
$configClass = new \ReflectionClass("Consolidation\Config\Config");
// $defaults
$defaultsProperty = $configClass->getProperty("defaults");
$defaultsProperty->setAccessible(true);
// $getDefaults
$getDefaultsMethod = $configClass->getMethod("getDefaults");
$getDefaultsMethod->setAccessible(true);
// Test the config class
$config = new Config($data);
// Set $config::defaults to an array to test getter and setter
$defaultsProperty->setValue($config, $defaults);
$this->assertTrue(is_array($defaultsProperty->getValue($config)));
$this->assertInstanceOf('Dflydev\DotAccessData\Data',
$getDefaultsMethod->invoke($config));
// Set $config::defaults to a string to test exception
$defaultsProperty->setValue($config, "foo.bar");
$this->setExpectedException("Exception");
$getDefaultsMethod->invoke($config);
}
public function testConfigurationWithCrossFileReferences()
{
$config = new Config();
$processor = new ConfigProcessor();
$loader = new YamlConfigLoader();
$processor->extend($loader->load(__DIR__ . '/data/config-1.yml'));
$processor->extend($loader->load(__DIR__ . '/data/config-2.yml'));
$processor->extend($loader->load(__DIR__ . '/data/config-3.yml'));
// Does not fail if configuration file cannot be found
$processor->extend($loader->load(__DIR__ . '/data/no-such-file.yml'));
// We must capture the sources before exporting, as export
// dumps this information.
$sources = $processor->sources();
$config->import($processor->export());
$this->assertEquals(implode(',', $config->get('m')), '3');
$this->assertEquals($config->get('a'), 'foobarbaz');
$this->assertEquals($sources['a'], __DIR__ . '/data/config-3.yml');
$this->assertEquals($sources['b'], __DIR__ . '/data/config-2.yml');
$this->assertEquals($sources['c'], __DIR__ . '/data/config-1.yml');
}
public function testConfigurationWithReverseOrderCrossFileReferences()
{
$config = new Config();
$processor = new ConfigProcessor();
$loader = new YamlConfigLoader();
$processor->extend($loader->load(__DIR__ . '/data/config-3.yml'));
$processor->extend($loader->load(__DIR__ . '/data/config-2.yml'));
$processor->extend($loader->load(__DIR__ . '/data/config-1.yml'));
$sources = $processor->sources();
$config->import($processor->export());
$this->assertEquals(implode(',', $config->get('m')), '1');
if (strpos($config->get('a'), '$') !== false) {
throw new \PHPUnit_Framework_SkippedTestError(
'Evaluation of cross-file references in reverse order not supported.'
);
}
$this->assertEquals($config->get('a'), 'foobarbaz');
$this->assertEquals($sources['a'], __DIR__ . '/data/config-3.yml');
$this->assertEquals($sources['b'], __DIR__ . '/data/config-2.yml');
$this->assertEquals($sources['c'], __DIR__ . '/data/config-1.yml');
}
}

View File

@@ -1,23 +0,0 @@
#!/bin/bash
SCENARIO=$1
ACTION=${2-install}
dir=dependencies/${SCENARIO}
if [ -z "$SCENARIO" ] ; then
SCENARIO=default
dir=.
fi
if [ ! -d "$dir" ] ; then
echo "Requested scenario '${SCENARIO}' does not exist."
exit 1
fi
echo "Switch to ${SCENARIO} scenario"
set -ex
composer -n --working-dir=$dir ${ACTION} --prefer-dist --no-scripts
composer -n --working-dir=$dir info

View File

@@ -1,66 +0,0 @@
#!/bin/bash
#
# This script is called automatically on every `composer update`.
# See "post-update-cmd" in the "scripts" section of composer.json.
#
# This script will create a derived composer.json / composer.lock
# pair for every test scenario. Test scenarios are defined in the
# "scenarios" file, which should be customized to suit the needs
# of the project.
#
SELF_DIRNAME="`dirname -- "$0"`"
source ${SELF_DIRNAME}/scenarios
echo
echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo "::"
echo ":: Update dependencies for the following scenarios:"
echo "::"
echo ":: ${SCENARIOS}"
echo "::"
echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo
set -ex
for SCENARIO in ${SCENARIOS} ; do
dir=dependencies/${SCENARIO}
# Define indirect variable names
stability_variable="stability_${SCENARIO}"
requirement_variable="requirement_${SCENARIO}"
platform_php_variable="platform_php_${SCENARIO}"
echo "### Create $dir/composer.json for ${SCENARIO} scenario"
mkdir -p $dir
cp composer.json $dir
# Then set our own platform php version if applicable (otherwise unset it)
composer -n --working-dir=$dir config platform.php "${!platform_php_variable---unset}"
# Temporarily set our vendor directory to 'vendor'
composer -n --working-dir=$dir config vendor-dir vendor
# Set an appropriate minimum stability for this version of Symfony
composer -n --working-dir=$dir config minimum-stability "${!stability_variable-stable}"
# Add a constraint to limit the Symfony version
composer -n --working-dir=$dir require --dev --no-update "${!requirement_variable}"
# Create the composer.lock file. Ignore the vendor directory created.
composer -n --working-dir=$dir update --no-scripts
# Set the vendor directory to its final desired location.
composer -n --working-dir=$dir config vendor-dir '../../vendor'
# The 'autoload' section specifies directory paths that are relative
# to the composer.json file. We will drop in some symlinks so that
# these paths will resolve as if the composer.json were in the root.
for target in $AUTOLOAD_DIRECTORIES ; do
ln -s -f ../../$target $dir
done
done

View File

@@ -1,12 +0,0 @@
#!/bin/bash
SCENARIOS="symfony2 symfony3 symfony4"
AUTOLOAD_DIRECTORIES='src tests'
platform_php_symfony2='5.4'
platform_php_symfony3='5.6'
requirement_symfony2='symfony/console:^2.8'
requirement_symfony3='symfony/console:^3'
requirement_symfony4='symfony/console:^4'

View File

@@ -1,43 +0,0 @@
<?php
namespace Consolidation\TestUtils;
class ApplyConfigTestTarget
{
protected $dir;
protected $value;
/**
* A proper setter for the 'dir' property
*/
public function dir($dir)
{
$this->dir = $dir;
return $this;
}
/**
* A getter for the 'dir' property that we will use to
* determine if the setter was called.
*/
public function getDir()
{
return $this->dir;
}
/**
* A bad setter that does not return $this.
*/
public function bad($value)
{
$this->value = $value;
}
/**
* A getter for the bad setter.
*/
public function getBad()
{
return $this->value;
}
}

View File

@@ -1,47 +0,0 @@
<?php
namespace Consolidation\TestUtils;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
class MyFooCommand extends Command
{
protected function configure()
{
$this
->setName('my:foo')
->setDescription('My foo command.')
->setHelp('This command tests command option injection by echoing its options')
->addOption(
'other',
null,
InputOption::VALUE_REQUIRED,
'Some other option',
'fish'
)
->addOption(
'name',
null,
InputOption::VALUE_REQUIRED,
'What is the name of the thing we are naming',
'George'
)
->addOption(
'dir',
null,
InputOption::VALUE_REQUIRED,
'What is the base directory to use for this command',
'/default/path'
);
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Enter my:foo');
$output->writeln('dir: ' . $input->getOption('dir'));
$output->writeln('name: ' . $input->getOption('name'));
$output->writeln('other: ' . $input->getOption('other'));
}
}

View File

@@ -1,36 +0,0 @@
<?php
namespace Consolidation\TestUtils;
use Consolidation\Config\Loader\ConfigLoaderInterface;
class TestLoader implements ConfigLoaderInterface
{
protected $data;
protected $sourceName;
public function set($data)
{
$this->data = $data;
}
public function setSourceName($name)
{
$this->sourceName = $name;
}
public function export()
{
return $this->data;
}
public function keys()
{
return array_keys($this->data);
}
public function getSourceName()
{
return $this->sourceName;
}
}

View File

@@ -0,0 +1 @@
../../src

View File

@@ -1,157 +0,0 @@
<?php
namespace Consolidation\Config;
use Dflydev\DotAccessData\Data;
class Config implements ConfigInterface
{
/**
* @var Data
*/
protected $config;
/**
* TODO: make this private in 2.0 to prevent being saved as an array
* Making private now breaks backward compatibility
*
* @var Data
*/
protected $defaults;
/**
* Create a new configuration object, and initialize it with
* the provided nested array containing configuration data.
*
* @param array $data - Config data to store
*/
public function __construct(array $data = null)
{
$this->config = new Data($data);
$this->setDefaults(new Data());
}
/**
* {@inheritdoc}
*/
public function has($key)
{
return ($this->config->has($key));
}
/**
* {@inheritdoc}
*/
public function get($key, $defaultFallback = null)
{
if ($this->has($key)) {
return $this->config->get($key);
}
return $this->getDefault($key, $defaultFallback);
}
/**
* {@inheritdoc}
*/
public function set($key, $value)
{
$this->config->set($key, $value);
return $this;
}
/**
* {@inheritdoc}
*/
public function import($data)
{
return $this->replace($data);
}
/**
* {@inheritdoc}
*/
public function replace($data)
{
$this->config = new Data($data);
return $this;
}
/**
* {@inheritdoc}
*/
public function combine($data)
{
if (!empty($data)) {
$this->config->import($data, true);
}
return $this;
}
/**
* {@inheritdoc}
*/
public function export()
{
return $this->config->export();
}
/**
* {@inheritdoc}
*/
public function hasDefault($key)
{
return $this->getDefaults()->has($key);
}
/**
* {@inheritdoc}
*/
public function getDefault($key, $defaultFallback = null)
{
return $this->hasDefault($key) ? $this->getDefaults()->get($key) : $defaultFallback;
}
/**
* {@inheritdoc}
*/
public function setDefault($key, $value)
{
$this->getDefaults()->set($key, $value);
return $this;
}
/**
* Return the class $defaults property and ensure it's a Data object
* TODO: remove Data object validation in 2.0
*
* @return Data
*/
protected function getDefaults()
{
// Ensure $this->defaults is a Data object (not an array)
if (!$this->defaults instanceof Data) {
$this->setDefaults($this->defaults);
}
return $this->defaults;
}
/**
* Sets the $defaults class parameter
* TODO: remove support for array in 2.0 as this would currently break backward compatibility
*
* @param Data|array $defaults
*
* @throws \Exception
*/
protected function setDefaults($defaults)
{
if (is_array($defaults)) {
$this->defaults = new Data($defaults);
} elseif ($defaults instanceof Data) {
$this->defaults = $defaults;
} else {
throw new \Exception("Unknown type provided for \$defaults");
}
}
}

View File

@@ -1,105 +0,0 @@
<?php
namespace Consolidation\Config;
interface ConfigInterface
{
/**
* Determine if a non-default config value exists.
*/
public function has($key);
/**
* Fetch a configuration value
*
* @param string $key Which config item to look up
* @param string|null $defaultFallback Fallback default value to use when
* configuration object has neither a value nor a default. Use is
* discouraged; use default context in ConfigOverlay, or provide defaults
* using a config processor.
*
* @return mixed
*/
public function get($key, $defaultFallback = null);
/**
* Set a config value
*
* @param string $key
* @param mixed $value
*
* @return $this
*/
public function set($key, $value);
/**
* Import configuration from the provided nexted array, replacing whatever
* was here previously. No processing is done on the provided data.
*
* @deprecated Use 'replace'. Dflydev\DotAccessData\Data::import() merges, which is confusing, since this method replaces.
*
* @param array $data
* @return Config
*/
public function import($data);
/**
* Load configuration from the provided nexted array, replacing whatever
* was here previously. No processing is done on the provided data.
*
* TODO: This will become a required method in version 2.0. Adding now
* would break clients that implement ConfigInterface.
*
* @param array $data
* @return Config
*/
// public function replace($data);
/**
* Import configuration from the provided nexted array, merging with whatever
* was here previously. No processing is done on the provided data.
* Any data provided to the combine() method will overwrite existing data
* with the same key.
*
* TODO: This will become a required method in version 2.0. Adding now
* would break clients that implement ConfigInterface.
*
* @param array $data
* @return Config
*/
// public function combine($data);
/**
* Export all configuration as a nested array.
*/
public function export();
/**
* Return the default value for a given configuration item.
*
* @param string $key
*
* @return mixed
*/
public function hasDefault($key);
/**
* Return the default value for a given configuration item.
*
* @param string $key
* @param mixed $defaultFallback
*
* @return mixed
*/
public function getDefault($key, $defaultFallback = null);
/**
* Set the default value for a configuration setting. This allows us to
* set defaults either before or after more specific configuration values
* are loaded. Keeping defaults separate from current settings also
* allows us to determine when a setting has been overridden.
*
* @param string $key
* @param string $value
*/
public function setDefault($key, $value);
}

View File

@@ -1,10 +0,0 @@
<?php
namespace Consolidation\Config;
interface GlobalOptionDefaultValuesInterface
{
/**
* Return an associative array of option-key => default-value
*/
public function getGlobalOptionDefaultValues();
}

View File

@@ -1,127 +0,0 @@
<?php
namespace Consolidation\Config\Inject;
use Consolidation\Config\ConfigInterface;
use Consolidation\Config\Util\ConfigFallback;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputOption;
class ConfigForCommand implements EventSubscriberInterface
{
protected $config;
protected $application;
public function __construct(ConfigInterface $config)
{
$this->config = $config;
}
public function setApplication(Application $application)
{
$this->application = $application;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return [ConsoleEvents::COMMAND => 'injectConfiguration'];
}
/**
* Before a Console command runs, inject configuration settings
* for this command into the default value of the options of
* this command.
*
* @param \Symfony\Component\Console\Event\ConsoleCommandEvent $event
*/
public function injectConfiguration(ConsoleCommandEvent $event)
{
$command = $event->getCommand();
$this->injectConfigurationForGlobalOptions($event->getInput());
$this->injectConfigurationForCommand($command, $event->getInput());
$targetOfHelpCommand = $this->getHelpCommandTarget($command, $event->getInput());
if ($targetOfHelpCommand) {
$this->injectConfigurationForCommand($targetOfHelpCommand, $event->getInput());
}
}
protected function injectConfigurationForGlobalOptions($input)
{
if (!$this->application) {
return;
}
$configGroup = new ConfigFallback($this->config, 'options');
$definition = $this->application->getDefinition();
$options = $definition->getOptions();
return $this->injectConfigGroupIntoOptions($configGroup, $options, $input);
}
protected function injectConfigurationForCommand($command, $input)
{
$commandName = $command->getName();
$commandName = str_replace(':', '.', $commandName);
$configGroup = new ConfigFallback($this->config, $commandName, 'command.', '.options.');
$definition = $command->getDefinition();
$options = $definition->getOptions();
return $this->injectConfigGroupIntoOptions($configGroup, $options, $input);
}
protected function injectConfigGroupIntoOptions($configGroup, $options, $input)
{
foreach ($options as $option => $inputOption) {
$key = str_replace('.', '-', $option);
$value = $configGroup->get($key);
if ($value !== null) {
if (is_bool($value) && ($value == true)) {
$input->setOption($key, $value);
} elseif ($inputOption->acceptValue()) {
$inputOption->setDefault($value);
}
}
}
}
protected function getHelpCommandTarget($command, $input)
{
if (($command->getName() != 'help') || (!isset($this->application))) {
return false;
}
$this->fixInputForSymfony2($command, $input);
// Symfony Console helpfully swaps 'command_name' and 'command'
// depending on whether the user entered `help foo` or `--help foo`.
// One of these is always `help`, and the other is the command we
// are actually interested in.
$nameOfCommandToDescribe = $input->getArgument('command_name');
if ($nameOfCommandToDescribe == 'help') {
$nameOfCommandToDescribe = $input->getArgument('command');
}
return $this->application->find($nameOfCommandToDescribe);
}
protected function fixInputForSymfony2($command, $input)
{
// Symfony 3.x prepares $input for us; Symfony 2.x, on the other
// hand, passes it in prior to binding with the command definition,
// so we have to go to a little extra work. It may be inadvisable
// to do these steps for commands other than 'help'.
if (!$input->hasArgument('command_name')) {
$command->ignoreValidationErrors();
$command->mergeApplicationDefinition();
$input->bind($command->getDefinition());
}
}
}

View File

@@ -1,47 +0,0 @@
<?php
namespace Consolidation\Config\Inject;
use Consolidation\Config\Util\ConfigMerge;
/**
* Given an object that contains configuration methods, inject any
* configuration found in the configuration file.
*
* The proper use for this method is to call setter methods of the
* provided object. Using configuration to call methods that do work
* is an abuse of this mechanism.
*/
class ConfigForSetters
{
protected $config;
public function __construct($config, $group, $prefix = '', $postfix = '')
{
if (!empty($group) && empty($postfix)) {
$postfix = '.';
}
$this->config = new ConfigMerge($config, $group, $prefix, $postfix);
}
public function apply($object, $configurationKey)
{
$settings = $this->config->get($configurationKey);
foreach ($settings as $setterMethod => $args) {
$fn = [$object, $setterMethod];
if (is_callable($fn)) {
$result = call_user_func_array($fn, (array)$args);
// We require that $fn must only be used with setter methods.
// Setter methods are required to always return $this so that
// they may be chained. We will therefore throw an exception
// for any setter that returns something else.
if ($result != $object) {
$methodDescription = get_class($object) . "::$setterMethod";
$propertyDescription = $this->config->describe($configurationKey);
throw new \Exception("$methodDescription did not return '\$this' when processing $propertyDescription.");
}
}
}
}
}

View File

@@ -1,35 +0,0 @@
<?php
namespace Consolidation\Config\Loader;
/**
* Load configuration files.
*/
abstract class ConfigLoader implements ConfigLoaderInterface
{
protected $config = [];
protected $source = '';
public function getSourceName()
{
return $this->source;
}
protected function setSourceName($source)
{
$this->source = $source;
return $this;
}
public function export()
{
return $this->config;
}
public function keys()
{
return array_keys($this->config);
}
abstract public function load($path);
}

View File

@@ -1,29 +0,0 @@
<?php
namespace Consolidation\Config\Loader;
/**
* Load configuration files, and fill in any property values that
* need to be expanded.
*/
interface ConfigLoaderInterface
{
/**
* Convert loaded configuration into a simple php nested array.
*
* @return array
*/
public function export();
/**
* Return the top-level keys in the exported data.
*
* @return array
*/
public function keys();
/**
* Return a symbolic name for this configuration loader instance.
*/
public function getSourceName();
}

View File

@@ -1,167 +0,0 @@
<?php
namespace Consolidation\Config\Loader;
use Grasmash\Expander\Expander;
use Consolidation\Config\Util\ArrayUtil;
/**
* The config processor combines multiple configuration
* files together, and processes them as necessary.
*/
class ConfigProcessor
{
protected $processedConfig = [];
protected $unprocessedConfig = [];
protected $expander;
public function __construct($expander = null)
{
$this->expander = $expander ?: new Expander();
}
/**
* Extend the configuration to be processed with the
* configuration provided by the specified loader.
*
* @param ConfigLoaderInterface $loader
*/
public function extend(ConfigLoaderInterface $loader)
{
return $this->addFromSource($loader->export(), $loader->getSourceName());
}
/**
* Extend the configuration to be processed with
* the provided nested array.
*
* @param array $data
*/
public function add($data)
{
$this->unprocessedConfig[] = $data;
return $this;
}
/**
* Extend the configuration to be processed with
* the provided nested array. Also record the name
* of the data source, if applicable.
*
* @param array $data
* @param string $source
*/
protected function addFromSource($data, $source = '')
{
if (empty($source)) {
return $this->add($data);
}
$this->unprocessedConfig[$source] = $data;
return $this;
}
/**
* Process all of the configuration that has been collected,
* and return a nested array.
*
* @return array
*/
public function export($referenceArray = [])
{
if (!empty($this->unprocessedConfig)) {
$this->processedConfig = $this->process(
$this->processedConfig,
$this->fetchUnprocessed(),
$referenceArray
);
}
return $this->processedConfig;
}
/**
* To aid in debugging: return the source of each configuration item.
* n.b. Must call this function *before* export and save the result
* if persistence is desired.
*/
public function sources()
{
$sources = [];
foreach ($this->unprocessedConfig as $sourceName => $config) {
if (!empty($sourceName)) {
$configSources = ArrayUtil::fillRecursive($config, $sourceName);
$sources = ArrayUtil::mergeRecursiveDistinct($sources, $configSources);
}
}
return $sources;
}
/**
* Get the configuration to be processed, and clear out the
* 'unprocessed' list.
*
* @return array
*/
protected function fetchUnprocessed()
{
$toBeProcessed = $this->unprocessedConfig;
$this->unprocessedConfig = [];
return $toBeProcessed;
}
/**
* Use a map-reduce to evaluate the items to be processed,
* and merge them into the processed array.
*
* @param array $processed
* @param array $toBeProcessed
* @return array
*/
protected function process(array $processed, array $toBeProcessed, $referenceArray = [])
{
$toBeReduced = array_map([$this, 'preprocess'], $toBeProcessed);
$reduced = array_reduce($toBeReduced, [$this, 'reduceOne'], $processed);
return $this->evaluate($reduced, $referenceArray);
}
/**
* Process a single configuration file from the 'to be processed'
* list. By default this is a no-op. Override this method to
* provide any desired configuration preprocessing, e.g. dot-notation
* expansion of the configuration keys, etc.
*
* @param array $config
* @return array
*/
protected function preprocess(array $config)
{
return $config;
}
/**
* Evaluate one item in the 'to be evaluated' list, and then
* merge it into the processed configuration (the 'carry').
*
* @param array $processed
* @param array $config
* @return array
*/
protected function reduceOne(array $processed, array $config)
{
return ArrayUtil::mergeRecursiveDistinct($processed, $config);
}
/**
* Evaluate one configuration item.
*
* @param array $processed
* @param array $config
* @return array
*/
protected function evaluate(array $config, $referenceArray = [])
{
return $this->expander->expandArrayProperties(
$config,
$referenceArray
);
}
}

View File

@@ -1,26 +0,0 @@
<?php
namespace Consolidation\Config\Loader;
use Symfony\Component\Yaml\Yaml;
/**
* Load configuration files, and fill in any property values that
* need to be expanded.
*/
class YamlConfigLoader extends ConfigLoader
{
public function load($path)
{
$this->setSourceName($path);
// We silently skip any nonexistent config files, so that
// clients may simply `load` all of their candidates.
if (!file_exists($path)) {
$this->config = [];
return $this;
}
$this->config = (array) Yaml::parse(file_get_contents($path));
return $this;
}
}

View File

@@ -1,75 +0,0 @@
<?php
namespace Consolidation\Config\Util;
/**
* Useful array utilities.
*/
class ArrayUtil
{
/**
* Merges arrays recursively while preserving.
*
* @param array $array1
* @param array $array2
*
* @return array
*
* @see http://php.net/manual/en/function.array-merge-recursive.php#92195
* @see https://github.com/grasmash/bolt/blob/robo-rebase/src/Robo/Common/ArrayManipulator.php#L22
*/
public static function mergeRecursiveDistinct(
array &$array1,
array &$array2
) {
$merged = $array1;
foreach ($array2 as $key => &$value) {
$merged[$key] = self::mergeRecursiveValue($merged, $key, $value);
}
return $merged;
}
/**
* Process the value in an mergeRecursiveDistinct - make a recursive
* call if needed.
*/
protected static function mergeRecursiveValue(&$merged, $key, $value)
{
if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
return self::mergeRecursiveDistinct($merged[$key], $value);
}
return $value;
}
/**
* Fills all of the leaf-node values of a nested array with the
* provided replacement value.
*/
public static function fillRecursive(array $data, $fill)
{
$result = [];
foreach ($data as $key => $value) {
$result[$key] = $fill;
if (self::isAssociative($value)) {
$result[$key] = self::fillRecursive($value, $fill);
}
}
return $result;
}
/**
* Return true if the provided parameter is an array, and at least
* one key is non-numeric.
*/
public static function isAssociative($testArray)
{
if (!is_array($testArray)) {
return false;
}
foreach (array_keys($testArray) as $key) {
if (!is_numeric($key)) {
return true;
}
}
return false;
}
}

View File

@@ -1,51 +0,0 @@
<?php
namespace Consolidation\Config\Util;
/**
* Fetch a configuration value from a configuration group. If the
* desired configuration value is not found in the most specific
* group named, keep stepping up to the next parent group until a
* value is located.
*
* Given the following constructor inputs:
* - $prefix = "command."
* - $group = "foo.bar.baz"
* - $postfix = ".options."
* Then the `get` method will then consider, in order:
* - command.foo.bar.baz.options
* - command.foo.bar.options
* - command.foo.options
* If any of these contain an option for "$key", then return its value.
*/
class ConfigFallback extends ConfigGroup
{
/**
* @inheritdoc
*/
public function get($key)
{
return $this->getWithFallback($key, $this->group, $this->prefix, $this->postfix);
}
/**
* Fetch an option value from a given key, or, if that specific key does
* not contain a value, then consult various fallback options until a
* value is found.
*
*/
protected function getWithFallback($key, $group, $prefix = '', $postfix = '.')
{
$configKey = "{$prefix}{$group}${postfix}{$key}";
if ($this->config->has($configKey)) {
return $this->config->get($configKey);
}
if ($this->config->hasDefault($configKey)) {
return $this->config->getDefault($configKey);
}
$moreGeneralGroupname = $this->moreGeneralGroupName($group);
if ($moreGeneralGroupname) {
return $this->getWithFallback($key, $moreGeneralGroupname, $prefix, $postfix);
}
return null;
}
}

View File

@@ -1,61 +0,0 @@
<?php
namespace Consolidation\Config\Util;
/**
* Fetch a configuration value from a configuration group. If the
* desired configuration value is not found in the most specific
* group named, keep stepping up to the next parent group until a
* value is located.
*
* Given the following constructor inputs:
* - $prefix = "command."
* - $group = "foo.bar.baz"
* - $postfix = ".options."
* Then the `get` method will then consider, in order:
* - command.foo.bar.baz.options
* - command.foo.bar.options
* - command.foo.options
* If any of these contain an option for "$key", then return its value.
*/
abstract class ConfigGroup
{
protected $config;
protected $group;
protected $prefix;
protected $postfix;
public function __construct($config, $group, $prefix = '', $postfix = '.')
{
$this->config = $config;
$this->group = $group;
$this->prefix = $prefix;
$this->postfix = $postfix;
}
/**
* Return a description of the configuration group (with prefix and postfix).
*/
public function describe($property)
{
return $this->prefix . $this->group . $this->postfix . $property;
}
/**
* Get the requested configuration key from the most specific configuration
* group that contains it.
*/
abstract public function get($key);
/**
* Given a group name, such as "foo.bar.baz", return the next configuration
* group in the fallback hierarchy, e.g. "foo.bar".
*/
protected function moreGeneralGroupName($group)
{
$result = preg_replace('#\.[^.]*$#', '', $group);
if ($result != $group) {
return $result;
}
return false;
}
}

View File

@@ -1,34 +0,0 @@
<?php
namespace Consolidation\Config\Util;
/**
* Works like 'getWithFallback', but merges results from all applicable
* groups. Settings from most specific group take precedence.
*/
class ConfigMerge extends ConfigGroup
{
/**
* @inheritdoc
*/
public function get($key)
{
return $this->getWithMerge($key, $this->group, $this->prefix, $this->postfix);
}
/**
* Merge available configuration from each configuration group.
*/
public function getWithMerge($key, $group, $prefix = '', $postfix = '.')
{
$configKey = "{$prefix}{$group}${postfix}{$key}";
$result = $this->config->get($configKey, []);
if (!is_array($result)) {
throw new \UnexpectedValueException($configKey . ' must be a list of settings to apply.');
}
$moreGeneralGroupname = $this->moreGeneralGroupName($group);
if ($moreGeneralGroupname) {
$result += $this->getWithMerge($key, $moreGeneralGroupname, $prefix, $postfix);
}
return $result;
}
}

View File

@@ -1,203 +0,0 @@
<?php
namespace Consolidation\Config\Util;
use Consolidation\Config\Config;
use Consolidation\Config\ConfigInterface;
/**
* Overlay different configuration objects that implement ConfigInterface
* to make a priority-based, merged configuration object.
*
* Note that using a ConfigOverlay hides the defaults stored in each
* individual configuration context. When using overlays, always call
* getDefault / setDefault on the ConfigOverlay object itself.
*/
class ConfigOverlay implements ConfigInterface
{
protected $contexts = [];
const DEFAULT_CONTEXT = 'default';
const PROCESS_CONTEXT = 'process';
public function __construct()
{
$this->contexts[self::DEFAULT_CONTEXT] = new Config();
$this->contexts[self::PROCESS_CONTEXT] = new Config();
}
/**
* Add a named configuration object to the configuration overlay.
* Configuration objects added LAST have HIGHEST priority, with the
* exception of the fact that the process context always has the
* highest priority.
*
* If a context has already been added, its priority will not change.
*/
public function addContext($name, ConfigInterface $config)
{
$process = $this->contexts[self::PROCESS_CONTEXT];
unset($this->contexts[self::PROCESS_CONTEXT]);
$this->contexts[$name] = $config;
$this->contexts[self::PROCESS_CONTEXT] = $process;
return $this;
}
/**
* Add a placeholder context that will be prioritized higher than
* existing contexts. This is done to ensure that contexts added
* later will maintain a higher priority if the placeholder context
* is later relaced with a different configuration set via addContext().
*
* @param string $name
* @return $this
*/
public function addPlaceholder($name)
{
return $this->addContext($name, new Config());
}
/**
* Increase the priority of the named context such that it is higher
* in priority than any existing context except for the 'process'
* context.
*
* @param string $name
* @return $this
*/
public function increasePriority($name)
{
$config = $this->getContext($name);
unset($this->contexts[$name]);
return $this->addContext($name, $config);
}
public function hasContext($name)
{
return isset($this->contexts[$name]);
}
public function getContext($name)
{
if ($this->hasContext($name)) {
return $this->contexts[$name];
}
return new Config();
}
public function removeContext($name)
{
unset($this->contexts[$name]);
}
/**
* Determine if a non-default config value exists.
*/
public function findContext($key)
{
foreach (array_reverse($this->contexts) as $name => $config) {
if ($config->has($key)) {
return $config;
}
}
return false;
}
/**
* @inheritdoc
*/
public function has($key)
{
return $this->findContext($key) != false;
}
/**
* @inheritdoc
*/
public function get($key, $default = null)
{
$context = $this->findContext($key);
if ($context) {
return $context->get($key, $default);
}
return $default;
}
/**
* @inheritdoc
*/
public function set($key, $value)
{
$this->contexts[self::PROCESS_CONTEXT]->set($key, $value);
return $this;
}
/**
* @inheritdoc
*/
public function import($data)
{
$this->unsupported(__FUNCTION__);
}
/**
* @inheritdoc
*/
public function replace($data)
{
$this->unsupported(__FUNCTION__);
}
/**
* @inheritdoc
*/
public function combine($data)
{
$this->unsupported(__FUNCTION__);
}
/**
* @inheritdoc
*/
protected function unsupported($fn)
{
throw new \Exception("The method '$fn' is not supported for the ConfigOverlay class.");
}
/**
* @inheritdoc
*/
public function export()
{
$export = [];
foreach ($this->contexts as $name => $config) {
$export = array_merge_recursive($export, $config->export());
}
return $export;
}
/**
* @inheritdoc
*/
public function hasDefault($key)
{
return $this->contexts[self::DEFAULT_CONTEXT]->has($key);
}
/**
* @inheritdoc
*/
public function getDefault($key, $default = null)
{
return $this->contexts[self::DEFAULT_CONTEXT]->get($key, $default);
}
/**
* @inheritdoc
*/
public function setDefault($key, $value)
{
$this->contexts[self::DEFAULT_CONTEXT]->set($key, $value);
return $this;
}
}

View File

@@ -1,96 +0,0 @@
<?php
namespace Consolidation\Config\Util;
use Consolidation\Config\Config;
use Consolidation\Config\ConfigInterface;
/**
* Provide a configuration object that fetches values from environment
* variables.
*/
class EnvConfig implements ConfigInterface
{
/** @var string */
protected $prefix;
/**
* EnvConfig constructor
*
* @param $prefix The string to appear before every environment
* variable key. For example, if the prefix is 'MYAPP_', then
* the key 'foo.bar' will be fetched from the environment variable
* MYAPP_FOO_BAR.
*/
public function __construct($prefix)
{
// Ensure that the prefix is always uppercase, and always
// ends with a '_', regardless of the form the caller provided.
$this->prefix = strtoupper(rtrim($prefix, '_')) . '_';
}
/**
* @inheritdoc
*/
public function has($key)
{
return $this->get($key) !== null;
}
/**
* @inheritdoc
*/
public function get($key, $defaultFallback = null)
{
$envKey = $this->prefix . strtoupper(strtr($key, '.-', '__'));
$envKey = str_replace($this->prefix . $this->prefix, $this->prefix, $envKey);
return getenv($envKey) ?: $defaultFallback;
}
/**
* @inheritdoc
*/
public function set($key, $value)
{
throw new \Exception('Cannot call "set" on environmental configuration.');
}
/**
* @inheritdoc
*/
public function import($data)
{
// no-op
}
/**
* @inheritdoc
*/
public function export()
{
return [];
}
/**
* @inheritdoc
*/
public function hasDefault($key)
{
return false;
}
/**
* @inheritdoc
*/
public function getDefault($key, $defaultFallback = null)
{
return $defaultFallback;
}
/**
* @inheritdoc
*/
public function setDefault($key, $value)
{
throw new \Exception('Cannot call "setDefault" on environmental configuration.');
}
}

View File

@@ -0,0 +1 @@
../../tests

View File

@@ -1,130 +0,0 @@
<?php
namespace Consolidation\Config\Inject;
use Consolidation\Config\Config;
use Consolidation\TestUtils\MyFooCommand;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\OutputInterface;
class ConfigForCommandTest extends \PHPUnit_Framework_TestCase
{
protected $config;
protected function setUp()
{
$data = [
// Global options
'options' => [
'global' => 'from-config',
],
// Define some configuration settings for the options for
// the commands my:foo and my:bar.
'command' => [
'my' => [
// commands.my.options.* apply to all my:* commands.
'options' => [
'dir' => '/etc/common',
'priority' => 'normal',
],
'foo' => [
// commands.my.foo.options.* apply only to the my:foo command.
'options' => [
'name' => 'baz',
],
],
],
],
];
$this->config = new Config($data);
}
public function testInjection()
{
$command = new MyFooCommand();
$input = new StringInput('my:foo');
list($status, $output) = $this->runCommandViaApplication($command, $input);
$expectedOutput = <<< EOT
Enter my:foo
dir: /etc/common
name: baz
other: fish
EOT;
$this->assertEquals(0, $status);
$this->assertEquals($expectedOutput, $output);
}
public function testInjectionWithOverride()
{
$command = new MyFooCommand();
$input = new StringInput('my:foo --name=Fred');
list($status, $output) = $this->runCommandViaApplication($command, $input);
$expectedOutput = <<< EOT
Enter my:foo
dir: /etc/common
name: Fred
other: fish
EOT;
$this->assertEquals(0, $status);
$this->assertEquals($expectedOutput, $output);
}
public function testHelpDefaultInjection()
{
$command = new MyFooCommand();
$input = new StringInput('help my:foo');
list($status, $output) = $this->runCommandViaApplication($command, $input);
$expectedOutput = <<< EOT
What is the name of the thing we are naming [default: "baz"]
EOT;
$this->assertEquals(0, $status);
$this->assertContains($expectedOutput, $output);
$expectedOutput = <<< EOT
A certain global option. [default: "from-config"]
EOT;
$this->assertContains($expectedOutput, $output);
}
protected function runCommandViaApplication($command, $input)
{
$application = new Application('TestApplication', '0.0.0');
$application->getDefinition()
->addOption(
new InputOption('--global', null, InputOption::VALUE_REQUIRED, 'A certain global option.', 'hardcoded')
);
$output = new BufferedOutput();
$configInjector = new ConfigForCommand($this->config);
$configInjector->setApplication($application);
$eventDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
$eventDispatcher->addSubscriber($configInjector);
$application->setDispatcher($eventDispatcher);
$application->setAutoExit(false);
$application->add($command);
$statusCode = $application->run($input, $output);
$commandOutput = trim($output->fetch());
return [$statusCode, $commandOutput];
}
}

View File

@@ -1,87 +0,0 @@
<?php
namespace Consolidation\Config\Inject;
use Consolidation\Config\Config;
use Consolidation\TestUtils\ApplyConfigTestTarget;
class ConfigForSettersTest extends \PHPUnit_Framework_TestCase
{
public function testApplyConfig()
{
$data = [
// Define some configuration settings for the configuration
// of some task \My\Tasks\Operations\Frobulate.
'task' => [
'Operations' => [
// task.Operations.settings apply to all tasks in
// any *.Tass.Operations namespace.
'settings' => [
'dir' => '/base/dir',
],
'Frobulate' => [
// task.Operations.Frobulate.settings applies only
// the Frobulate task.
'settings' => [
'dir' => '/override/dir',
],
],
],
],
];
$config = new Config($data);
$applicator = new ConfigForSetters($config, 'Operations.Frobulate', 'task.');
$testTarget = new ApplyConfigTestTarget();
$applicator->apply($testTarget, 'settings');
$this->assertEquals('/override/dir', $testTarget->getDir());
$this->assertEquals(null, $testTarget->getBad());
}
public function testApplyBadConfig()
{
$data = [
// Define some configuration settings for the configuration
// of some task \My\Tasks\Operations\Frobulate.
'task' => [
'Operations' => [
// task.Operations.settings apply to all tasks in
// any *.Tass.Operations namespace.
'settings' => [
'dir' => '/base/dir',
],
'Frobulate' => [
// task.Operations.Frobulate.settings applies only
// the Frobulate task.
'settings' => [
'bad' => 'fire truck',
],
],
],
],
];
$config = new Config($data);
$applicator = new ConfigForSetters($config, 'Operations.Frobulate', 'task.');
$testTarget = new ApplyConfigTestTarget();
$exceptionMessage = '';
try
{
$applicator->apply($testTarget, 'settings');
}
catch (\Exception $e)
{
$exceptionMessage = $e->getMessage();
}
// We would prefer it if bad methods were never called; unfortunately,
// declaring the return type of a method cannot be done in a reliable
// way (via reflection) until php 7, so we allow these methods to be
// called for now.
$this->assertEquals('fire truck', $testTarget->getBad());
$this->assertEquals('Consolidation\\TestUtils\\ApplyConfigTestTarget::bad did not return \'$this\' when processing task.Operations.Frobulate.settings.', $exceptionMessage);
}
}

View File

@@ -1,91 +0,0 @@
<?php
namespace Consolidation\Config\Util;
use Consolidation\Config\Config;
class ConfigGroupTest extends \PHPUnit_Framework_TestCase
{
protected $config;
protected function setUp()
{
$data = [
// Define some configuration settings for the options for
// the commands my:foo and my:bar.
'command' => [
'my' => [
// commands.my.options.* apply to all my:* commands.
'options' => [
'path' => '/etc/common',
'priority' => 'normal',
],
'foo' => [
// commands.my.foo.options.* apply only to the my:foo command.
'options' => [
'name' => 'baz',
],
],
'bar' => [
// Similarly, commands.my.bar.options is for the my:bar command.
'options' => [
'priority' => 'high',
],
],
],
],
// Define some configuration settings for the configuration
// of some task \My\Tasks\Operations\Frobulate.
'task' => [
'Operations' => [
// task.Operations.settings apply to all tasks in
// any *.Tass.Operations namespace.
'settings' => [
'dir' => '/base/dir',
],
'Frobulate' => [
// task.Operations.Frobulate.settings applies only
// the Frobulate task.
'settings' => [
'object' => 'fire truck',
],
],
],
],
];
$this->config = new Config($data);
}
public function testDotNotation()
{
// Test the test
$this->assertEquals('baz', $this->config->get('command.my.foo.options.name'));
}
public function testFallback()
{
$fooFallback = new ConfigFallback($this->config, 'my.foo', 'command.', '.options.');
$barFallback = new ConfigFallback($this->config, 'my.bar', 'command.', '.options.');
$this->assertEquals(null, $barFallback->get('name'));
$this->assertEquals('baz', $fooFallback->get('name'));
$this->assertEquals('high', $barFallback->get('priority'));
$this->assertEquals('normal', $fooFallback->get('priority'));
$this->assertEquals('/etc/common', $barFallback->get('path'));
$this->assertEquals('/etc/common', $fooFallback->get('path'));
}
public function testMerge()
{
$frobulateMerge = new ConfigMerge($this->config, 'Operations.Frobulate', 'task.');
$settings = $frobulateMerge->get('settings');
$this->assertEquals('fire truck', $settings['object']);
$this->assertEquals('/base/dir', $settings['dir']);
$keys = array_keys($settings);
sort($keys);
$this->assertEquals('dir,object', implode(',', $keys));
}
}

View File

@@ -1,29 +0,0 @@
<?php
namespace Consolidation\Config\Loader;
class ConfigLoaderTest extends \PHPUnit_Framework_TestCase
{
public function testConfigLoader()
{
$loader = new YamlConfigLoader();
// Assert that our test data exists (test the test)
$path = __DIR__ . '/data/config-1.yml';
$this->assertTrue(file_exists($path));
$loader->load($path);
$configFile = basename($loader->getSourceName());
$this->assertEquals('config-1.yml', $configFile);
// Make sure that the data we loaded contained the expected keys
$keys = $loader->keys();
sort($keys);
$keysString = implode(',', $keys);
$this->assertEquals('c,m', $keysString);
$configData = $loader->export();
$this->assertEquals('foo', $configData['c']);
$this->assertEquals('1', $configData['m'][0]);
}
}

View File

@@ -1,168 +0,0 @@
<?php
namespace Consolidation\Config\Util;
use Consolidation\Config\Config;
use Consolidation\Config\Loader\ConfigProcessor;
use Consolidation\Config\Loader\YamlConfigLoader;
class ConfigOverlayTest extends \PHPUnit_Framework_TestCase
{
protected $overlay;
protected function setUp()
{
$aliasContext = new Config();
$aliasContext->import([
'hidden-by-a' => 'alias hidden-by-a',
'hidden-by-process' => 'alias hidden-by-process',
'options' =>[
'a-a' => 'alias-a',
],
'command' => [
'foo' => [
'bar' => [
'command' => [
'options' => [
'a-b' => 'alias-b',
],
],
],
],
],
]);
$configFileContext = new Config();
$configFileContext->import([
'hidden-by-cf' => 'config-file hidden-by-cf',
'hidden-by-a' => 'config-file hidden-by-a',
'hidden-by-process' => 'config-file hidden-by-process',
'options' =>[
'cf-a' => 'config-file-a',
],
'command' => [
'foo' => [
'bar' => [
'command' => [
'options' => [
'cf-b' => 'config-file-b',
],
],
],
],
],
]);
$this->overlay = new ConfigOverlay();
$this->overlay->set('hidden-by-process', 'process-h');
$this->overlay->addContext('cf', $configFileContext);
$this->overlay->addContext('a', $aliasContext);
$this->overlay->setDefault('df-a', 'default');
$this->overlay->setDefault('hidden-by-a', 'default hidden-by-a');
$this->overlay->setDefault('hidden-by-cf', 'default hidden-by-cf');
$this->overlay->setDefault('hidden-by-process', 'default hidden-by-process');
}
public function testGetPriority()
{
$this->assertEquals('process-h', $this->overlay->get('hidden-by-process'));
$this->assertEquals('config-file hidden-by-cf', $this->overlay->get('hidden-by-cf'));
$this->assertEquals('alias hidden-by-a', $this->overlay->get('hidden-by-a'));
}
public function testDefault()
{
$this->assertEquals('alias-a', $this->overlay->get('options.a-a'));
$this->assertEquals('alias-a', $this->overlay->get('options.a-a', 'ignored'));
$this->assertEquals('default', $this->overlay->getDefault('df-a', 'ignored'));
$this->assertEquals('nsv', $this->overlay->getDefault('a-a', 'nsv'));
$this->overlay->setDefault('df-a', 'new value');
$this->assertEquals('new value', $this->overlay->getDefault('df-a', 'ignored'));
}
public function testExport()
{
$data = $this->overlay->export();
$this->assertEquals('config-file-a', $data['options']['cf-a']);
$this->assertEquals('alias-a', $data['options']['a-a']);
}
/**
* @expectedException Exception
*/
public function testImport()
{
$data = $this->overlay->import(['a' => 'value']);
}
public function testMaintainPriority()
{
// Get and re-add the 'cf' context. Its priority should not change.
$configFileContext = $this->overlay->getContext('cf');
$this->overlay->addContext('cf', $configFileContext);
// These asserts are the same as in testGetPriority
$this->assertEquals('process-h', $this->overlay->get('hidden-by-process'));
$this->assertEquals('config-file hidden-by-cf', $this->overlay->get('hidden-by-cf'));
$this->assertEquals('alias hidden-by-a', $this->overlay->get('hidden-by-a'));
}
public function testChangePriority()
{
// Increase the priority of the 'cf' context. Now, it should have a higher
// priority than the 'alias' context, but should still have a lower
// priority than the 'process' context.
$this->overlay->increasePriority('cf');
// These asserts are the same as in testGetPriority
$this->assertEquals('process-h', $this->overlay->get('hidden-by-process'));
$this->assertEquals('config-file hidden-by-cf', $this->overlay->get('hidden-by-cf'));
// This one has changed: the config-file value is now found instead
// of the alias value.
$this->assertEquals('config-file hidden-by-a', $this->overlay->get('hidden-by-a'));
}
public function testPlaceholder()
{
$this->overlay->addPlaceholder('lower');
$higherContext = new Config();
$higherContext->import(['priority-test' => 'higher']);
$lowerContext = new Config();
$lowerContext->import(['priority-test' => 'lower']);
// Usually 'lower' would have the highest priority, since it is
// added last. However, our earlier call to 'addPlaceholder' reserves
// a spot for it, so the 'higher' context will end up with a higher
// priority.
$this->overlay->addContext('higher', $higherContext);
$this->overlay->addContext('lower', $lowerContext);
$this->assertEquals('higher', $this->overlay->get('priority-test', 'neither'));
// Test to see that we can change the value of the 'higher' context,
// and the change will be reflected in the overlay.
$higherContext->set('priority-test', 'changed');
$this->assertEquals('changed', $this->overlay->get('priority-test', 'neither'));
// Test to see that the 'process' context still has the highest priority.
$this->overlay->set('priority-test', 'process');
$higherContext->set('priority-test', 'ignored');
$this->assertEquals('process', $this->overlay->get('priority-test', 'neither'));
}
public function testDoesNotHave()
{
$context = $this->overlay->getContext('no-such-context');
$data = $context->export();
$this->assertEquals('[]', json_encode($data));
$this->assertTrue(!$this->overlay->has('no-such-key'));
$this->assertTrue(!$this->overlay->hasDefault('no-such-default'));
$this->assertEquals('no-such-value', $this->overlay->get('no-such-key', 'no-such-value'));
}
}

View File

@@ -1,152 +0,0 @@
<?php
namespace Consolidation\Config\Loader;
use Consolidation\TestUtils\TestLoader;
class ConfigProcessorTest extends \PHPUnit_Framework_TestCase
{
public function testConfigProcessorAdd()
{
$config1 = [
'c' => 'foo',
'm' => [1],
];
$config2 = [
'b' => '${c}bar',
'm' => [2],
];
$config3 = [
'a' => '${b}baz',
'm' => [3],
];
$processor = new ConfigProcessor();
$processor->add($config1);
$processor->add($config2);
$processor->add($config3);
$data = $processor->export();
$this->assertEquals('foo', $data['c']);
$this->assertEquals('foobar', $data['b']);
$this->assertEquals('foobarbaz', $data['a']);
}
public function processorForConfigMergeTest($provideSourceNames)
{
$config1 = [
'm' => [
'x' => 'x-1',
'y' => [
'r' => 'r-1',
's' => 's-1',
't' => 't-1',
],
'z' => 'z-1',
],
];
$config2 = [
'm' => [
'w' => 'w-2',
'y' => [
'q' => 'q-2',
's' => 's-2',
],
'z' => 'z-2',
],
];
$config3 = [
'm' => [
'v' => 'v-3',
'y' => [
't' => 't-3',
'u' => 'u-3',
],
'z' => 'z-3',
],
];
$processor = new ConfigProcessor();
$testLoader = new TestLoader();
$testLoader->set($config1);
$testLoader->setSourceName($provideSourceNames ? 'c-1' : '');
$processor->extend($testLoader);
$testLoader->set($config2);
$testLoader->setSourceName($provideSourceNames ? 'c-2' : '');
$processor->extend($testLoader);
$testLoader->set($config3);
$testLoader->setSourceName($provideSourceNames ? 'c-3' : '');
$processor->extend($testLoader);
return $processor;
}
public function testConfigProcessorMergeAssociative()
{
$processor = $this->processorForConfigMergeTest(false);
$data = $processor->export();
$this->assertEquals('{"m":{"x":"x-1","y":{"r":"r-1","s":"s-2","t":"t-3","q":"q-2","u":"u-3"},"z":"z-3","w":"w-2","v":"v-3"}}', json_encode($data));
}
public function testConfigProcessorMergeAssociativeWithSourceNames()
{
$processor = $this->processorForConfigMergeTest(true);
$sources = $processor->sources();
$data = $processor->export();
$this->assertEquals('{"m":{"x":"x-1","y":{"r":"r-1","s":"s-2","t":"t-3","q":"q-2","u":"u-3"},"z":"z-3","w":"w-2","v":"v-3"}}', json_encode($data));
$this->assertEquals('c-1', $sources['m']['x']);
$this->assertEquals('c-1', $sources['m']['y']['r']);
$this->assertEquals('c-2', $sources['m']['w']);
$this->assertEquals('c-2', $sources['m']['y']['s']);
$this->assertEquals('c-3', $sources['m']['z']);
$this->assertEquals('c-3', $sources['m']['y']['u']);
}
public function testConfiProcessorSources()
{
$processor = new ConfigProcessor();
$loader = new YamlConfigLoader();
$processor->extend($loader->load(__DIR__ . '/data/config-1.yml'));
$processor->extend($loader->load(__DIR__ . '/data/config-2.yml'));
$processor->extend($loader->load(__DIR__ . '/data/config-3.yml'));
$sources = $processor->sources();
$data = $processor->export();
$this->assertEquals('foo', $data['c']);
$this->assertEquals('foobar', $data['b']);
$this->assertEquals('foobarbaz', $data['a']);
$this->assertEquals('3', $data['m'][0]);
$this->assertEquals( __DIR__ . '/data/config-3.yml', $sources['a']);
$this->assertEquals( __DIR__ . '/data/config-2.yml', $sources['b']);
$this->assertEquals( __DIR__ . '/data/config-1.yml', $sources['c']);
$this->assertEquals( __DIR__ . '/data/config-3.yml', $sources['m']);
}
public function testConfiProcessorSourcesLoadInReverseOrder()
{
$processor = new ConfigProcessor();
$loader = new YamlConfigLoader();
$processor->extend($loader->load(__DIR__ . '/data/config-3.yml'));
$processor->extend($loader->load(__DIR__ . '/data/config-2.yml'));
$processor->extend($loader->load(__DIR__ . '/data/config-1.yml'));
$sources = $processor->sources();
$data = $processor->export();
$this->assertEquals('foo', $data['c']);
$this->assertEquals('foobar', $data['b']);
$this->assertEquals('foobarbaz', $data['a']);
$this->assertEquals('1', $data['m'][0]);
$this->assertEquals( __DIR__ . '/data/config-3.yml', $sources['a']);
$this->assertEquals( __DIR__ . '/data/config-2.yml', $sources['b']);
$this->assertEquals( __DIR__ . '/data/config-1.yml', $sources['c']);
$this->assertEquals( __DIR__ . '/data/config-1.yml', $sources['m']);
}
}

View File

@@ -1,140 +0,0 @@
<?php
namespace Consolidation\Config;
use Consolidation\Config\Loader\ConfigProcessor;
use Consolidation\Config\Loader\YamlConfigLoader;
class ConfigTest extends \PHPUnit_Framework_TestCase
{
public function testSetters()
{
// Pointless tests just to ensure everything is covered.
$config = new Config();
$config->set('foo', 'bar');
$data = $config->export();
$this->assertEquals('{"foo":"bar"}', json_encode($data));
}
public function testCombine()
{
// Pointless tests just to ensure everything is covered.
$config = new Config();
$config->set('foo', 'bar');
$config->set('baz', 'boz');
$config2 = new Config();
$config2->set('foo', 'fu');
$config2->set('new', 'blue');
$config->combine($config2->export());
$this->assertEquals('fu', $config->get('foo'));
$this->assertEquals('boz', $config->get('baz'));
$this->assertEquals('blue', $config->get('new'));
}
public function testDefault()
{
$data = [
'a' => 'foo',
'b' => 'bar',
'c' => 'boz',
];
$foo = ["foo" => "bar"];
$config = new Config($data);
$config->setDefault('c', 'other');
$config->setDefault('d', 'other');
$config->setDefault('f', $foo);
$this->assertEquals('foo', $config->get('a'));
$this->assertEquals('boz', $config->get('c'));
$this->assertEquals('other', $config->get('d'));
$this->assertEquals('other', $config->getDefault('c'));
$this->assertEquals('', $config->get('e'));
$this->assertEquals('bar', $config->get('f.foo'));
$this->assertEquals('{"foo":"bar"}', json_encode($config->get('f')));
}
public function testDefaultsArray()
{
$data = ['a' => 'foo', 'b' => 'bar', 'c' => 'boz',];
$defaults = ['d' => 'foo', 'e' => 'bar', 'f' => 'boz',];
// Create reflection class to test private methods
$configClass = new \ReflectionClass("Consolidation\Config\Config");
// $defaults
$defaultsProperty = $configClass->getProperty("defaults");
$defaultsProperty->setAccessible(true);
// $getDefaults
$getDefaultsMethod = $configClass->getMethod("getDefaults");
$getDefaultsMethod->setAccessible(true);
// Test the config class
$config = new Config($data);
// Set $config::defaults to an array to test getter and setter
$defaultsProperty->setValue($config, $defaults);
$this->assertTrue(is_array($defaultsProperty->getValue($config)));
$this->assertInstanceOf('Dflydev\DotAccessData\Data',
$getDefaultsMethod->invoke($config));
// Set $config::defaults to a string to test exception
$defaultsProperty->setValue($config, "foo.bar");
$this->setExpectedException("Exception");
$getDefaultsMethod->invoke($config);
}
public function testConfigurationWithCrossFileReferences()
{
$config = new Config();
$processor = new ConfigProcessor();
$loader = new YamlConfigLoader();
$processor->extend($loader->load(__DIR__ . '/data/config-1.yml'));
$processor->extend($loader->load(__DIR__ . '/data/config-2.yml'));
$processor->extend($loader->load(__DIR__ . '/data/config-3.yml'));
// Does not fail if configuration file cannot be found
$processor->extend($loader->load(__DIR__ . '/data/no-such-file.yml'));
// We must capture the sources before exporting, as export
// dumps this information.
$sources = $processor->sources();
$config->import($processor->export());
$this->assertEquals(implode(',', $config->get('m')), '3');
$this->assertEquals($config->get('a'), 'foobarbaz');
$this->assertEquals($sources['a'], __DIR__ . '/data/config-3.yml');
$this->assertEquals($sources['b'], __DIR__ . '/data/config-2.yml');
$this->assertEquals($sources['c'], __DIR__ . '/data/config-1.yml');
}
public function testConfigurationWithReverseOrderCrossFileReferences()
{
$config = new Config();
$processor = new ConfigProcessor();
$loader = new YamlConfigLoader();
$processor->extend($loader->load(__DIR__ . '/data/config-3.yml'));
$processor->extend($loader->load(__DIR__ . '/data/config-2.yml'));
$processor->extend($loader->load(__DIR__ . '/data/config-1.yml'));
$sources = $processor->sources();
$config->import($processor->export());
$this->assertEquals(implode(',', $config->get('m')), '1');
if (strpos($config->get('a'), '$') !== false) {
throw new \PHPUnit_Framework_SkippedTestError(
'Evaluation of cross-file references in reverse order not supported.'
);
}
$this->assertEquals($config->get('a'), 'foobarbaz');
$this->assertEquals($sources['a'], __DIR__ . '/data/config-3.yml');
$this->assertEquals($sources['b'], __DIR__ . '/data/config-2.yml');
$this->assertEquals($sources['c'], __DIR__ . '/data/config-1.yml');
}
}

View File

@@ -1,23 +0,0 @@
#!/bin/bash
SCENARIO=$1
ACTION=${2-install}
dir=dependencies/${SCENARIO}
if [ -z "$SCENARIO" ] ; then
SCENARIO=default
dir=.
fi
if [ ! -d "$dir" ] ; then
echo "Requested scenario '${SCENARIO}' does not exist."
exit 1
fi
echo "Switch to ${SCENARIO} scenario"
set -ex
composer -n --working-dir=$dir ${ACTION} --prefer-dist --no-scripts
composer -n --working-dir=$dir info

View File

@@ -1,66 +0,0 @@
#!/bin/bash
#
# This script is called automatically on every `composer update`.
# See "post-update-cmd" in the "scripts" section of composer.json.
#
# This script will create a derived composer.json / composer.lock
# pair for every test scenario. Test scenarios are defined in the
# "scenarios" file, which should be customized to suit the needs
# of the project.
#
SELF_DIRNAME="`dirname -- "$0"`"
source ${SELF_DIRNAME}/scenarios
echo
echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo "::"
echo ":: Update dependencies for the following scenarios:"
echo "::"
echo ":: ${SCENARIOS}"
echo "::"
echo "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
echo
set -ex
for SCENARIO in ${SCENARIOS} ; do
dir=dependencies/${SCENARIO}
# Define indirect variable names
stability_variable="stability_${SCENARIO}"
requirement_variable="requirement_${SCENARIO}"
platform_php_variable="platform_php_${SCENARIO}"
echo "### Create $dir/composer.json for ${SCENARIO} scenario"
mkdir -p $dir
cp composer.json $dir
# Then set our own platform php version if applicable (otherwise unset it)
composer -n --working-dir=$dir config platform.php "${!platform_php_variable---unset}"
# Temporarily set our vendor directory to 'vendor'
composer -n --working-dir=$dir config vendor-dir vendor
# Set an appropriate minimum stability for this version of Symfony
composer -n --working-dir=$dir config minimum-stability "${!stability_variable-stable}"
# Add a constraint to limit the Symfony version
composer -n --working-dir=$dir require --dev --no-update "${!requirement_variable}"
# Create the composer.lock file. Ignore the vendor directory created.
composer -n --working-dir=$dir update --no-scripts
# Set the vendor directory to its final desired location.
composer -n --working-dir=$dir config vendor-dir '../../vendor'
# The 'autoload' section specifies directory paths that are relative
# to the composer.json file. We will drop in some symlinks so that
# these paths will resolve as if the composer.json were in the root.
for target in $AUTOLOAD_DIRECTORIES ; do
ln -s -f ../../$target $dir
done
done

View File

@@ -1,12 +0,0 @@
#!/bin/bash
SCENARIOS="symfony2 symfony3 symfony4"
AUTOLOAD_DIRECTORIES='src tests'
platform_php_symfony2='5.4'
platform_php_symfony3='5.6'
requirement_symfony2='symfony/console:^2.8'
requirement_symfony3='symfony/console:^3'
requirement_symfony4='symfony/console:^4'

View File

@@ -1,43 +0,0 @@
<?php
namespace Consolidation\TestUtils;
class ApplyConfigTestTarget
{
protected $dir;
protected $value;
/**
* A proper setter for the 'dir' property
*/
public function dir($dir)
{
$this->dir = $dir;
return $this;
}
/**
* A getter for the 'dir' property that we will use to
* determine if the setter was called.
*/
public function getDir()
{
return $this->dir;
}
/**
* A bad setter that does not return $this.
*/
public function bad($value)
{
$this->value = $value;
}
/**
* A getter for the bad setter.
*/
public function getBad()
{
return $this->value;
}
}

View File

@@ -1,47 +0,0 @@
<?php
namespace Consolidation\TestUtils;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
class MyFooCommand extends Command
{
protected function configure()
{
$this
->setName('my:foo')
->setDescription('My foo command.')
->setHelp('This command tests command option injection by echoing its options')
->addOption(
'other',
null,
InputOption::VALUE_REQUIRED,
'Some other option',
'fish'
)
->addOption(
'name',
null,
InputOption::VALUE_REQUIRED,
'What is the name of the thing we are naming',
'George'
)
->addOption(
'dir',
null,
InputOption::VALUE_REQUIRED,
'What is the base directory to use for this command',
'/default/path'
);
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Enter my:foo');
$output->writeln('dir: ' . $input->getOption('dir'));
$output->writeln('name: ' . $input->getOption('name'));
$output->writeln('other: ' . $input->getOption('other'));
}
}

View File

@@ -1,36 +0,0 @@
<?php
namespace Consolidation\TestUtils;
use Consolidation\Config\Loader\ConfigLoaderInterface;
class TestLoader implements ConfigLoaderInterface
{
protected $data;
protected $sourceName;
public function set($data)
{
$this->data = $data;
}
public function setSourceName($name)
{
$this->sourceName = $name;
}
public function export()
{
return $this->data;
}
public function keys()
{
return array_keys($this->data);
}
public function getSourceName()
{
return $this->sourceName;
}
}

View File

@@ -0,0 +1 @@
../../src

View File

@@ -1,73 +0,0 @@
<?php
namespace Robo;
use Symfony\Component\Console\Application as SymfonyApplication;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;
class Application extends SymfonyApplication
{
/**
* @param string $name
* @param string $version
*/
public function __construct($name, $version)
{
parent::__construct($name, $version);
$this->getDefinition()
->addOption(
new InputOption('--simulate', null, InputOption::VALUE_NONE, 'Run in simulated mode (show what would have happened).')
);
$this->getDefinition()
->addOption(
new InputOption('--progress-delay', null, InputOption::VALUE_REQUIRED, 'Number of seconds before progress bar is displayed in long-running task collections. Default: 2s.', Config::DEFAULT_PROGRESS_DELAY)
);
$this->getDefinition()
->addOption(
new InputOption('--define', '-D', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Define a configuration item value.', [])
);
}
/**
* @param string $roboFile
* @param string $roboClass
*/
public function addInitRoboFileCommand($roboFile, $roboClass)
{
$createRoboFile = new Command('init');
$createRoboFile->setDescription("Intitalizes basic RoboFile in current dir");
$createRoboFile->setCode(function () use ($roboClass, $roboFile) {
$output = Robo::output();
$output->writeln("<comment> ~~~ Welcome to Robo! ~~~~ </comment>");
$output->writeln("<comment> ". basename($roboFile) ." will be created in the current directory </comment>");
file_put_contents(
$roboFile,
'<?php'
. "\n/**"
. "\n * This is project's console commands configuration for Robo task runner."
. "\n *"
. "\n * @see http://robo.li/"
. "\n */"
. "\nclass " . $roboClass . " extends \\Robo\\Tasks\n{\n // define public methods as commands\n}"
);
$output->writeln("<comment> Edit this file to add your commands! </comment>");
});
$this->add($createRoboFile);
}
/**
* Add self update command, do nothing if null is provided
*
* @param string $repository GitHub Repository for self update
*/
public function addSelfUpdateCommand($repository = null)
{
if (!$repository) {
return;
}
$selfUpdateCommand = new SelfUpdateCommand($this->getName(), $this->getVersion(), $repository);
$this->add($selfUpdateCommand);
}
}

View File

@@ -1,62 +0,0 @@
<?php
namespace Robo\Collection;
use Robo\Result;
use Robo\Contract\TaskInterface;
use Robo\State\StateAwareInterface;
use Robo\State\Data;
/**
* Creates a task wrapper that converts any Callable into an
* object that can be used directly with a task collection.
*
* It is not necessary to use this class directly; Collection will
* automatically wrap Callables when they are added.
*/
class CallableTask implements TaskInterface
{
/**
* @var callable
*/
protected $fn;
/**
* @var \Robo\Contract\TaskInterface
*/
protected $reference;
public function __construct(callable $fn, TaskInterface $reference)
{
$this->fn = $fn;
$this->reference = $reference;
}
/**
* @return \Robo\Result
*/
public function run()
{
$result = call_user_func($this->fn, $this->getState());
// If the function returns no result, then count it
// as a success.
if (!isset($result)) {
$result = Result::success($this->reference);
}
// If the function returns a result, it must either return
// a \Robo\Result or an exit code. In the later case, we
// convert it to a \Robo\Result.
if (!$result instanceof Result) {
$result = new Result($this->reference, $result);
}
return $result;
}
public function getState()
{
if ($this->reference instanceof StateAwareInterface) {
return $this->reference->getState();
}
return new Data();
}
}

View File

@@ -1,769 +0,0 @@
<?php
namespace Robo\Collection;
use Robo\Result;
use Robo\State\Data;
use Psr\Log\LogLevel;
use Robo\Contract\TaskInterface;
use Robo\Task\StackBasedTask;
use Robo\Task\BaseTask;
use Robo\TaskInfo;
use Robo\Contract\WrappedTaskInterface;
use Robo\Exception\TaskException;
use Robo\Exception\TaskExitException;
use Robo\Contract\CommandInterface;
use Robo\Contract\InflectionInterface;
use Robo\State\StateAwareInterface;
use Robo\State\StateAwareTrait;
/**
* Group tasks into a collection that run together. Supports
* rollback operations for handling error conditions.
*
* This is an internal class. Clients should use a CollectionBuilder
* rather than direct use of the Collection class. @see CollectionBuilder.
*
* Below, the example FilesystemStack task is added to a collection,
* and associated with a rollback task. If any of the operations in
* the FilesystemStack, or if any of the other tasks also added to
* the task collection should fail, then the rollback function is
* called. Here, taskDeleteDir is used to remove partial results
* of an unfinished task.
*/
class Collection extends BaseTask implements CollectionInterface, CommandInterface, StateAwareInterface
{
use StateAwareTrait;
/**
* @var \Robo\Collection\Element[]
*/
protected $taskList = [];
/**
* @var TaskInterface[]
*/
protected $rollbackStack = [];
/**
* @var TaskInterface[]
*/
protected $completionStack = [];
/**
* @var CollectionInterface
*/
protected $parentCollection;
/**
* @var callable[]
*/
protected $deferredCallbacks = [];
/**
* @var string[]
*/
protected $messageStoreKeys = [];
/**
* Constructor.
*/
public function __construct()
{
$this->resetState();
}
public function setProgressBarAutoDisplayInterval($interval)
{
if (!$this->progressIndicator) {
return;
}
return $this->progressIndicator->setProgressBarAutoDisplayInterval($interval);
}
/**
* {@inheritdoc}
*/
public function add(TaskInterface $task, $name = self::UNNAMEDTASK)
{
$task = new CompletionWrapper($this, $task);
$this->addToTaskList($name, $task);
return $this;
}
/**
* {@inheritdoc}
*/
public function addCode(callable $code, $name = self::UNNAMEDTASK)
{
return $this->add(new CallableTask($code, $this), $name);
}
/**
* {@inheritdoc}
*/
public function addIterable($iterable, callable $code)
{
$callbackTask = (new IterationTask($iterable, $code, $this))->inflect($this);
return $this->add($callbackTask);
}
/**
* {@inheritdoc}
*/
public function rollback(TaskInterface $rollbackTask)
{
// Rollback tasks always try as hard as they can, and never report failures.
$rollbackTask = $this->ignoreErrorsTaskWrapper($rollbackTask);
return $this->wrapAndRegisterRollback($rollbackTask);
}
/**
* {@inheritdoc}
*/
public function rollbackCode(callable $rollbackCode)
{
// Rollback tasks always try as hard as they can, and never report failures.
$rollbackTask = $this->ignoreErrorsCodeWrapper($rollbackCode);
return $this->wrapAndRegisterRollback($rollbackTask);
}
/**
* {@inheritdoc}
*/
public function completion(TaskInterface $completionTask)
{
$collection = $this;
$completionRegistrationTask = new CallableTask(
function () use ($collection, $completionTask) {
$collection->registerCompletion($completionTask);
},
$this
);
$this->addToTaskList(self::UNNAMEDTASK, $completionRegistrationTask);
return $this;
}
/**
* {@inheritdoc}
*/
public function completionCode(callable $completionTask)
{
$completionTask = new CallableTask($completionTask, $this);
return $this->completion($completionTask);
}
/**
* {@inheritdoc}
*/
public function before($name, $task, $nameOfTaskToAdd = self::UNNAMEDTASK)
{
return $this->addBeforeOrAfter(__FUNCTION__, $name, $task, $nameOfTaskToAdd);
}
/**
* {@inheritdoc}
*/
public function after($name, $task, $nameOfTaskToAdd = self::UNNAMEDTASK)
{
return $this->addBeforeOrAfter(__FUNCTION__, $name, $task, $nameOfTaskToAdd);
}
/**
* {@inheritdoc}
*/
public function progressMessage($text, $context = [], $level = LogLevel::NOTICE)
{
$context += ['name' => 'Progress'];
$context += TaskInfo::getTaskContext($this);
return $this->addCode(
function () use ($level, $text, $context) {
$context += $this->getState()->getData();
$this->printTaskOutput($level, $text, $context);
}
);
}
/**
* @param \Robo\Contract\TaskInterface $rollbackTask
*
* @return $this
*/
protected function wrapAndRegisterRollback(TaskInterface $rollbackTask)
{
$collection = $this;
$rollbackRegistrationTask = new CallableTask(
function () use ($collection, $rollbackTask) {
$collection->registerRollback($rollbackTask);
},
$this
);
$this->addToTaskList(self::UNNAMEDTASK, $rollbackRegistrationTask);
return $this;
}
/**
* Add either a 'before' or 'after' function or task.
*
* @param string $method
* @param string $name
* @param callable|TaskInterface $task
* @param string $nameOfTaskToAdd
*
* @return $this
*/
protected function addBeforeOrAfter($method, $name, $task, $nameOfTaskToAdd)
{
if (is_callable($task)) {
$task = new CallableTask($task, $this);
}
$existingTask = $this->namedTask($name);
$fn = [$existingTask, $method];
call_user_func($fn, $task, $nameOfTaskToAdd);
return $this;
}
/**
* Wrap the provided task in a wrapper that will ignore
* any errors or exceptions that may be produced. This
* is useful, for example, in adding optional cleanup tasks
* at the beginning of a task collection, to remove previous
* results which may or may not exist.
*
* TODO: Provide some way to specify which sort of errors
* are ignored, so that 'file not found' may be ignored,
* but 'permission denied' reported?
*
* @param \Robo\Contract\TaskInterface $task
*
* @return \Robo\Collection\CallableTask
*/
public function ignoreErrorsTaskWrapper(TaskInterface $task)
{
// If the task is a stack-based task, then tell it
// to try to run all of its operations, even if some
// of them fail.
if ($task instanceof StackBasedTask) {
$task->stopOnFail(false);
}
$ignoreErrorsInTask = function () use ($task) {
$data = [];
try {
$result = $this->runSubtask($task);
$message = $result->getMessage();
$data = $result->getData();
$data['exitcode'] = $result->getExitCode();
} catch (\Exception $e) {
$message = $e->getMessage();
}
return Result::success($task, $message, $data);
};
// Wrap our ignore errors callable in a task.
return new CallableTask($ignoreErrorsInTask, $this);
}
/**
* @param callable $task
*
* @return \Robo\Collection\CallableTask
*/
public function ignoreErrorsCodeWrapper(callable $task)
{
return $this->ignoreErrorsTaskWrapper(new CallableTask($task, $this));
}
/**
* Return the list of task names added to this collection.
*
* @return array
*/
public function taskNames()
{
return array_keys($this->taskList);
}
/**
* Test to see if a specified task name exists.
* n.b. before() and after() require that the named
* task exist; use this function to test first, if
* unsure.
*
* @param string $name
*
* @return bool
*/
public function hasTask($name)
{
return array_key_exists($name, $this->taskList);
}
/**
* Find an existing named task.
*
* @param string $name
* The name of the task to insert before. The named task MUST exist.
*
* @return Element
* The task group for the named task. Generally this is only
* used to call 'before()' and 'after()'.
*/
protected function namedTask($name)
{
if (!$this->hasTask($name)) {
throw new \RuntimeException("Could not find task named $name");
}
return $this->taskList[$name];
}
/**
* Add a list of tasks to our task collection.
*
* @param TaskInterface[] $tasks
* An array of tasks to run with rollback protection
*
* @return $this
*/
public function addTaskList(array $tasks)
{
foreach ($tasks as $name => $task) {
$this->add($task, $name);
}
return $this;
}
/**
* Add the provided task to our task list.
*
* @param string $name
* @param \Robo\Contract\TaskInterface $task
*
* @return \Robo\Collection\Collection
*/
protected function addToTaskList($name, TaskInterface $task)
{
// All tasks are stored in a task group so that we have a place
// to hang 'before' and 'after' tasks.
$taskGroup = new Element($task);
return $this->addCollectionElementToTaskList($name, $taskGroup);
}
/**
* @param int|string $name
* @param \Robo\Collection\Element $taskGroup
*
* @return $this
*/
protected function addCollectionElementToTaskList($name, Element $taskGroup)
{
// If a task name is not provided, then we'll let php pick
// the array index.
if (Result::isUnnamed($name)) {
$this->taskList[] = $taskGroup;
return $this;
}
// If we are replacing an existing task with the
// same name, ensure that our new task is added to
// the end.
$this->taskList[$name] = $taskGroup;
return $this;
}
/**
* Set the parent collection. This is necessary so that nested
* collections' rollback and completion tasks can be added to the
* top-level collection, ensuring that the rollbacks for a collection
* will run if any later task fails.
*
* @param \Robo\Collection\NestedCollectionInterface $parentCollection
*
* @return $this
*/
public function setParentCollection(NestedCollectionInterface $parentCollection)
{
$this->parentCollection = $parentCollection;
return $this;
}
/**
* Get the appropriate parent collection to use
*
* @return CollectionInterface
*/
public function getParentCollection()
{
return $this->parentCollection ? $this->parentCollection : $this;
}
/**
* Register a rollback task to run if there is any failure.
*
* Clients are free to add tasks to the rollback stack as
* desired; however, usually it is preferable to call
* Collection::rollback() instead. With that function,
* the rollback function will only be called if all of the
* tasks added before it complete successfully, AND some later
* task fails.
*
* One example of a good use-case for registering a callback
* function directly is to add a task that sends notification
* when a task fails.
*
* @param TaskInterface $rollbackTask
* The rollback task to run on failure.
*/
public function registerRollback(TaskInterface $rollbackTask)
{
if ($this->parentCollection) {
return $this->parentCollection->registerRollback($rollbackTask);
}
if ($rollbackTask) {
$this->rollbackStack[] = $rollbackTask;
}
}
/**
* Register a completion task to run once all other tasks finish.
* Completion tasks run whether or not a rollback operation was
* triggered. They do not trigger rollbacks if they fail.
*
* The typical use-case for a completion function is to clean up
* temporary objects (e.g. temporary folders). The preferred
* way to do that, though, is to use Temporary::wrap().
*
* On failures, completion tasks will run after all rollback tasks.
* If one task collection is nested inside another task collection,
* then the nested collection's completion tasks will run as soon as
* the nested task completes; they are not deferred to the end of
* the containing collection's execution.
*
* @param TaskInterface $completionTask
* The completion task to run at the end of all other operations.
*/
public function registerCompletion(TaskInterface $completionTask)
{
if ($this->parentCollection) {
return $this->parentCollection->registerCompletion($completionTask);
}
if ($completionTask) {
// Completion tasks always try as hard as they can, and never report failures.
$completionTask = $this->ignoreErrorsTaskWrapper($completionTask);
$this->completionStack[] = $completionTask;
}
}
/**
* Return the count of steps in this collection
*
* @return int
*/
public function progressIndicatorSteps()
{
$steps = 0;
foreach ($this->taskList as $name => $taskGroup) {
$steps += $taskGroup->progressIndicatorSteps();
}
return $steps;
}
/**
* A Collection of tasks can provide a command via `getCommand()`
* if it contains a single task, and that task implements CommandInterface.
*
* @return string
*
* @throws \Robo\Exception\TaskException
*/
public function getCommand()
{
if (empty($this->taskList)) {
return '';
}
if (count($this->taskList) > 1) {
// TODO: We could potentially iterate over the items in the collection
// and concatenate the result of getCommand() from each one, and fail
// only if we encounter a command that is not a CommandInterface.
throw new TaskException($this, "getCommand() does not work on arbitrary collections of tasks.");
}
$taskElement = reset($this->taskList);
$task = $taskElement->getTask();
$task = ($task instanceof WrappedTaskInterface) ? $task->original() : $task;
if ($task instanceof CommandInterface) {
return $task->getCommand();
}
throw new TaskException($task, get_class($task) . " does not implement CommandInterface, so can't be used to provide a command");
}
/**
* Run our tasks, and roll back if necessary.
*
* @return \Robo\Result
*/
public function run()
{
$result = $this->runWithoutCompletion();
$this->complete();
return $result;
}
/**
* @return \Robo\Result
*/
private function runWithoutCompletion()
{
$result = Result::success($this);
if (empty($this->taskList)) {
return $result;
}
$this->startProgressIndicator();
if ($result->wasSuccessful()) {
foreach ($this->taskList as $name => $taskGroup) {
$taskList = $taskGroup->getTaskList();
$result = $this->runTaskList($name, $taskList, $result);
if (!$result->wasSuccessful()) {
$this->fail();
return $result;
}
}
$this->taskList = [];
}
$this->stopProgressIndicator();
$result['time'] = $this->getExecutionTime();
return $result;
}
/**
* Run every task in a list, but only up to the first failure.
* Return the failing result, or success if all tasks run.
*
* @param string $name
* @param TaskInterface[] $taskList
* @param \Robo\Result $result
*
* @return \Robo\Result
*
* @throws \Robo\Exception\TaskExitException
*/
private function runTaskList($name, array $taskList, Result $result)
{
try {
foreach ($taskList as $taskName => $task) {
$taskResult = $this->runSubtask($task);
$this->advanceProgressIndicator();
// If the current task returns an error code, then stop
// execution and signal a rollback.
if (!$taskResult->wasSuccessful()) {
return $taskResult;
}
// We accumulate our results into a field so that tasks that
// have a reference to the collection may examine and modify
// the incremental results, if they wish.
$key = Result::isUnnamed($taskName) ? $name : $taskName;
$result->accumulate($key, $taskResult);
// The result message will be the message of the last task executed.
$result->setMessage($taskResult->getMessage());
}
} catch (TaskExitException $exitException) {
$this->fail();
throw $exitException;
} catch (\Exception $e) {
// Tasks typically should not throw, but if one does, we will
// convert it into an error and roll back.
return Result::fromException($task, $e, $result->getData());
}
return $result;
}
/**
* Force the rollback functions to run
*
* @return $this
*/
public function fail()
{
$this->disableProgressIndicator();
$this->runRollbackTasks();
$this->complete();
return $this;
}
/**
* Force the completion functions to run
*
* @return $this
*/
public function complete()
{
$this->detatchProgressIndicator();
$this->runTaskListIgnoringFailures($this->completionStack);
$this->reset();
return $this;
}
/**
* Reset this collection, removing all tasks.
*
* @return $this
*/
public function reset()
{
$this->taskList = [];
$this->completionStack = [];
$this->rollbackStack = [];
return $this;
}
/**
* Run all of our rollback tasks.
*
* Note that Collection does not implement RollbackInterface, but
* it may still be used as a task inside another task collection
* (i.e. you can nest task collections, if desired).
*/
protected function runRollbackTasks()
{
$this->runTaskListIgnoringFailures($this->rollbackStack);
// Erase our rollback stack once we have finished rolling
// everything back. This will allow us to potentially use
// a command collection more than once (e.g. to retry a
// failed operation after doing some error recovery).
$this->rollbackStack = [];
}
/**
* @param TaskInterface|NestedCollectionInterface|WrappedTaskInterface $task
*
* @return \Robo\Result
*/
protected function runSubtask($task)
{
$original = ($task instanceof WrappedTaskInterface) ? $task->original() : $task;
$this->setParentCollectionForTask($original, $this->getParentCollection());
if ($original instanceof InflectionInterface) {
$original->inflect($this);
}
if ($original instanceof StateAwareInterface) {
$original->setState($this->getState());
}
$this->doDeferredInitialization($original);
$taskResult = $task->run();
$taskResult = Result::ensureResult($task, $taskResult);
$this->doStateUpdates($original, $taskResult);
return $taskResult;
}
protected function doStateUpdates($task, Data $taskResult)
{
$this->updateState($taskResult);
$key = spl_object_hash($task);
if (array_key_exists($key, $this->messageStoreKeys)) {
$state = $this->getState();
list($stateKey, $sourceKey) = $this->messageStoreKeys[$key];
$value = empty($sourceKey) ? $taskResult->getMessage() : $taskResult[$sourceKey];
$state[$stateKey] = $value;
}
}
public function storeState($task, $key, $source = '')
{
$this->messageStoreKeys[spl_object_hash($task)] = [$key, $source];
return $this;
}
public function deferTaskConfiguration($task, $functionName, $stateKey)
{
return $this->defer(
$task,
function ($task, $state) use ($functionName, $stateKey) {
$fn = [$task, $functionName];
$value = $state[$stateKey];
$fn($value);
}
);
}
/**
* Defer execution of a callback function until just before a task
* runs. Use this time to provide more settings for the task, e.g. from
* the collection's shared state, which is populated with the results
* of previous test runs.
*/
public function defer($task, $callback)
{
$this->deferredCallbacks[spl_object_hash($task)][] = $callback;
return $this;
}
protected function doDeferredInitialization($task)
{
// If the task is a state consumer, then call its receiveState method
if ($task instanceof \Robo\State\Consumer) {
$task->receiveState($this->getState());
}
// Check and see if there are any deferred callbacks for this task.
$key = spl_object_hash($task);
if (!array_key_exists($key, $this->deferredCallbacks)) {
return;
}
// Call all of the deferred callbacks
foreach ($this->deferredCallbacks[$key] as $fn) {
$fn($task, $this->getState());
}
}
/**
* @param TaskInterface|NestedCollectionInterface|WrappedTaskInterface $task
* @param $parentCollection
*/
protected function setParentCollectionForTask($task, $parentCollection)
{
if ($task instanceof NestedCollectionInterface) {
$task->setParentCollection($parentCollection);
}
}
/**
* Run all of the tasks in a provided list, ignoring failures.
* This is used to roll back or complete.
*
* @param TaskInterface[] $taskList
*/
protected function runTaskListIgnoringFailures(array $taskList)
{
foreach ($taskList as $task) {
try {
$this->runSubtask($task);
} catch (\Exception $e) {
// Ignore rollback failures.
}
}
}
/**
* Give all of our tasks to the provided collection builder.
*
* @param CollectionBuilder $builder
*/
public function transferTasks($builder)
{
foreach ($this->taskList as $name => $taskGroup) {
// TODO: We are abandoning all of our before and after tasks here.
// At the moment, transferTasks is only called under conditions where
// there will be none of these, but care should be taken if that changes.
$task = $taskGroup->getTask();
$builder->addTaskToCollection($task);
}
$this->reset();
}
}

View File

@@ -1,571 +0,0 @@
<?php
namespace Robo\Collection;
use Consolidation\Config\Inject\ConfigForSetters;
use Robo\Config\Config;
use Psr\Log\LogLevel;
use Robo\Contract\InflectionInterface;
use Robo\Contract\TaskInterface;
use Robo\Contract\CompletionInterface;
use Robo\Contract\WrappedTaskInterface;
use Robo\Task\Simulator;
use ReflectionClass;
use Robo\Task\BaseTask;
use Robo\Contract\BuilderAwareInterface;
use Robo\Contract\CommandInterface;
use Robo\Contract\VerbosityThresholdInterface;
use Robo\State\StateAwareInterface;
use Robo\State\StateAwareTrait;
use Robo\Result;
/**
* Creates a collection, and adds tasks to it. The collection builder
* offers a streamlined chained-initialization mechanism for easily
* creating task groups. Facilities for creating working and temporary
* directories are also provided.
*
* ``` php
* <?php
* $result = $this->collectionBuilder()
* ->taskFilesystemStack()
* ->mkdir('g')
* ->touch('g/g.txt')
* ->rollback(
* $this->taskDeleteDir('g')
* )
* ->taskFilesystemStack()
* ->mkdir('g/h')
* ->touch('g/h/h.txt')
* ->taskFilesystemStack()
* ->mkdir('g/h/i/c')
* ->touch('g/h/i/i.txt')
* ->run()
* ?>
*
* In the example above, the `taskDeleteDir` will be called if
* ```
*/
class CollectionBuilder extends BaseTask implements NestedCollectionInterface, WrappedTaskInterface, CommandInterface, StateAwareInterface
{
use StateAwareTrait;
/**
* @var \Robo\Tasks
*/
protected $commandFile;
/**
* @var CollectionInterface
*/
protected $collection;
/**
* @var TaskInterface
*/
protected $currentTask;
/**
* @var bool
*/
protected $simulated;
/**
* @param \Robo\Tasks $commandFile
*/
public function __construct($commandFile)
{
$this->commandFile = $commandFile;
$this->resetState();
}
public static function create($container, $commandFile)
{
$builder = new self($commandFile);
$builder->setLogger($container->get('logger'));
$builder->setProgressIndicator($container->get('progressIndicator'));
$builder->setConfig($container->get('config'));
$builder->setOutputAdapter($container->get('outputAdapter'));
return $builder;
}
/**
* @param bool $simulated
*
* @return $this
*/
public function simulated($simulated = true)
{
$this->simulated = $simulated;
return $this;
}
/**
* @return bool
*/
public function isSimulated()
{
if (!isset($this->simulated)) {
$this->simulated = $this->getConfig()->get(Config::SIMULATE);
}
return $this->simulated;
}
/**
* Create a temporary directory to work in. When the collection
* completes or rolls back, the temporary directory will be deleted.
* Returns the path to the location where the directory will be
* created.
*
* @param string $prefix
* @param string $base
* @param bool $includeRandomPart
*
* @return string
*/
public function tmpDir($prefix = 'tmp', $base = '', $includeRandomPart = true)
{
// n.b. Any task that the builder is asked to create is
// automatically added to the builder's collection, and
// wrapped in the builder object. Therefore, the result
// of any call to `taskFoo()` from within the builder will
// always be `$this`.
return $this->taskTmpDir($prefix, $base, $includeRandomPart)->getPath();
}
/**
* Create a working directory to hold results. A temporary directory
* is first created to hold the intermediate results. After the
* builder finishes, the work directory is moved into its final location;
* any results already in place will be moved out of the way and
* then deleted.
*
* @param string $finalDestination The path where the working directory
* will be moved once the task collection completes.
*
* @return string
*/
public function workDir($finalDestination)
{
// Creating the work dir task in this context adds it to our task collection.
return $this->taskWorkDir($finalDestination)->getPath();
}
public function addTask(TaskInterface $task)
{
$this->getCollection()->add($task);
return $this;
}
/**
* Add arbitrary code to execute as a task.
*
* @see \Robo\Collection\CollectionInterface::addCode
*
* @param callable $code
* @param int|string $name
* @return $this
*/
public function addCode(callable $code, $name = \Robo\Collection\CollectionInterface::UNNAMEDTASK)
{
$this->getCollection()->addCode($code, $name);
return $this;
}
/**
* Add a list of tasks to our task collection.
*
* @param TaskInterface[] $tasks
* An array of tasks to run with rollback protection
*
* @return $this
*/
public function addTaskList(array $tasks)
{
$this->getCollection()->addTaskList($tasks);
return $this;
}
public function rollback(TaskInterface $task)
{
// Ensure that we have a collection if we are going to add
// a rollback function.
$this->getCollection()->rollback($task);
return $this;
}
public function rollbackCode(callable $rollbackCode)
{
$this->getCollection()->rollbackCode($rollbackCode);
return $this;
}
public function completion(TaskInterface $task)
{
$this->getCollection()->completion($task);
return $this;
}
public function completionCode(callable $completionCode)
{
$this->getCollection()->completionCode($completionCode);
return $this;
}
/**
* @param string $text
* @param array $context
* @param string $level
*
* @return $this
*/
public function progressMessage($text, $context = [], $level = LogLevel::NOTICE)
{
$this->getCollection()->progressMessage($text, $context, $level);
return $this;
}
/**
* @param \Robo\Collection\NestedCollectionInterface $parentCollection
*
* @return $this
*/
public function setParentCollection(NestedCollectionInterface $parentCollection)
{
$this->getCollection()->setParentCollection($parentCollection);
return $this;
}
/**
* Called by the factory method of each task; adds the current
* task to the task builder.
*
* TODO: protected
*
* @param TaskInterface $task
*
* @return $this
*/
public function addTaskToCollection($task)
{
// Postpone creation of the collection until the second time
// we are called. At that time, $this->currentTask will already
// be populated. We call 'getCollection()' so that it will
// create the collection and add the current task to it.
// Note, however, that if our only tasks implements NestedCollectionInterface,
// then we should force this builder to use a collection.
if (!$this->collection && (isset($this->currentTask) || ($task instanceof NestedCollectionInterface))) {
$this->getCollection();
}
$this->currentTask = $task;
if ($this->collection) {
$this->collection->add($task);
}
return $this;
}
public function getState()
{
$collection = $this->getCollection();
return $collection->getState();
}
public function storeState($key, $source = '')
{
return $this->callCollectionStateFuntion(__FUNCTION__, func_get_args());
}
public function deferTaskConfiguration($functionName, $stateKey)
{
return $this->callCollectionStateFuntion(__FUNCTION__, func_get_args());
}
public function defer($callback)
{
return $this->callCollectionStateFuntion(__FUNCTION__, func_get_args());
}
protected function callCollectionStateFuntion($functionName, $args)
{
$currentTask = ($this->currentTask instanceof WrappedTaskInterface) ? $this->currentTask->original() : $this->currentTask;
array_unshift($args, $currentTask);
$collection = $this->getCollection();
$fn = [$collection, $functionName];
call_user_func_array($fn, $args);
return $this;
}
public function setVerbosityThreshold($verbosityThreshold)
{
$currentTask = ($this->currentTask instanceof WrappedTaskInterface) ? $this->currentTask->original() : $this->currentTask;
if ($currentTask) {
$currentTask->setVerbosityThreshold($verbosityThreshold);
return $this;
}
parent::setVerbosityThreshold($verbosityThreshold);
return $this;
}
/**
* Return the current task for this collection builder.
* TODO: Not needed?
*
* @return \Robo\Contract\TaskInterface
*/
public function getCollectionBuilderCurrentTask()
{
return $this->currentTask;
}
/**
* Create a new builder with its own task collection
*
* @return CollectionBuilder
*/
public function newBuilder()
{
$collectionBuilder = new self($this->commandFile);
$collectionBuilder->inflect($this);
$collectionBuilder->simulated($this->isSimulated());
$collectionBuilder->setVerbosityThreshold($this->verbosityThreshold());
$collectionBuilder->setState($this->getState());
return $collectionBuilder;
}
/**
* Calling the task builder with methods of the current
* task calls through to that method of the task.
*
* There is extra complexity in this function that could be
* simplified if we attached the 'LoadAllTasks' and custom tasks
* to the collection builder instead of the RoboFile. While that
* change would be a better design overall, it would require that
* the user do a lot more work to set up and use custom tasks.
* We therefore take on some additional complexity here in order
* to allow users to maintain their tasks in their RoboFile, which
* is much more convenient.
*
* Calls to $this->collectionBuilder()->taskFoo() cannot be made
* directly because all of the task methods are protected. These
* calls will therefore end up here. If the method name begins
* with 'task', then it is eligible to be used with the builder.
*
* When we call getBuiltTask, below, it will use the builder attached
* to the commandfile to build the task. However, this is not what we
* want: the task needs to be built from THIS collection builder, so that
* it will be affected by whatever state is active in this builder.
* To do this, we have two choices: 1) save and restore the builder
* in the commandfile, or 2) clone the commandfile and set this builder
* on the copy. 1) is vulnerable to failure in multithreaded environments
* (currently not supported), while 2) might cause confusion if there
* is shared state maintained in the commandfile, which is in the
* domain of the user.
*
* Note that even though we are setting up the commandFile to
* use this builder, getBuiltTask always creates a new builder
* (which is constructed using all of the settings from the
* commandFile's builder), and the new task is added to that.
* We therefore need to transfer the newly built task into this
* builder. The temporary builder is discarded.
*
* @param string $fn
* @param array $args
*
* @return $this|mixed
*/
public function __call($fn, $args)
{
if (preg_match('#^task[A-Z]#', $fn) && (method_exists($this->commandFile, 'getBuiltTask'))) {
$saveBuilder = $this->commandFile->getBuilder();
$this->commandFile->setBuilder($this);
$temporaryBuilder = $this->commandFile->getBuiltTask($fn, $args);
$this->commandFile->setBuilder($saveBuilder);
if (!$temporaryBuilder) {
throw new \BadMethodCallException("No such method $fn: task does not exist in " . get_class($this->commandFile));
}
$temporaryBuilder->getCollection()->transferTasks($this);
return $this;
}
if (!isset($this->currentTask)) {
throw new \BadMethodCallException("No such method $fn: current task undefined in collection builder.");
}
// If the method called is a method of the current task,
// then call through to the current task's setter method.
$result = call_user_func_array([$this->currentTask, $fn], $args);
// If something other than a setter method is called, then return its result.
$currentTask = ($this->currentTask instanceof WrappedTaskInterface) ? $this->currentTask->original() : $this->currentTask;
if (isset($result) && ($result !== $currentTask)) {
return $result;
}
return $this;
}
/**
* Construct the desired task and add it to this builder.
*
* @param string|object $name
* @param array $args
*
* @return \Robo\Collection\CollectionBuilder
*/
public function build($name, $args)
{
$reflection = new ReflectionClass($name);
$task = $reflection->newInstanceArgs($args);
if (!$task) {
throw new RuntimeException("Can not construct task $name");
}
$task = $this->fixTask($task, $args);
$this->configureTask($name, $task);
return $this->addTaskToCollection($task);
}
/**
* @param InflectionInterface $task
* @param array $args
*
* @return \Robo\Collection\CompletionWrapper|\Robo\Task\Simulator
*/
protected function fixTask($task, $args)
{
if ($task instanceof InflectionInterface) {
$task->inflect($this);
}
if ($task instanceof BuilderAwareInterface) {
$task->setBuilder($this);
}
if ($task instanceof VerbosityThresholdInterface) {
$task->setVerbosityThreshold($this->verbosityThreshold());
}
// Do not wrap our wrappers.
if ($task instanceof CompletionWrapper || $task instanceof Simulator) {
return $task;
}
// Remember whether or not this is a task before
// it gets wrapped in any decorator.
$isTask = $task instanceof TaskInterface;
$isCollection = $task instanceof NestedCollectionInterface;
// If the task implements CompletionInterface, ensure
// that its 'complete' method is called when the application
// terminates -- but only if its 'run' method is called
// first. If the task is added to a collection, then the
// task will be unwrapped via its `original` method, and
// it will be re-wrapped with a new completion wrapper for
// its new collection.
if ($task instanceof CompletionInterface) {
$task = new CompletionWrapper(Temporary::getCollection(), $task);
}
// If we are in simulated mode, then wrap any task in
// a TaskSimulator.
if ($isTask && !$isCollection && ($this->isSimulated())) {
$task = new \Robo\Task\Simulator($task, $args);
$task->inflect($this);
}
return $task;
}
/**
* Check to see if there are any setter methods defined in configuration
* for this task.
*/
protected function configureTask($taskClass, $task)
{
$taskClass = static::configClassIdentifier($taskClass);
$configurationApplier = new ConfigForSetters($this->getConfig(), $taskClass, 'task.');
$configurationApplier->apply($task, 'settings');
// TODO: If we counted each instance of $taskClass that was called from
// this builder, then we could also apply configuration from
// "task.{$taskClass}[$N].settings"
// TODO: If the builder knew what the current command name was,
// then we could also search for task configuration under
// command-specific keys such as "command.{$commandname}.task.{$taskClass}.settings".
}
/**
* When we run the collection builder, run everything in the collection.
*
* @return \Robo\Result
*/
public function run()
{
$this->startTimer();
$result = $this->runTasks();
$this->stopTimer();
$result['time'] = $this->getExecutionTime();
$result->mergeData($this->getState()->getData());
return $result;
}
/**
* If there is a single task, run it; if there is a collection, run
* all of its tasks.
*
* @return \Robo\Result
*/
protected function runTasks()
{
if (!$this->collection && $this->currentTask) {
$result = $this->currentTask->run();
return Result::ensureResult($this->currentTask, $result);
}
return $this->getCollection()->run();
}
/**
* @return string
*/
public function getCommand()
{
if (!$this->collection && $this->currentTask) {
$task = $this->currentTask;
$task = ($task instanceof WrappedTaskInterface) ? $task->original() : $task;
if ($task instanceof CommandInterface) {
return $task->getCommand();
}
}
return $this->getCollection()->getCommand();
}
/**
* @return \Robo\Collection\Collection
*/
public function original()
{
return $this->getCollection();
}
/**
* Return the collection of tasks associated with this builder.
*
* @return CollectionInterface
*/
public function getCollection()
{
if (!isset($this->collection)) {
$this->collection = new Collection();
$this->collection->inflect($this);
$this->collection->setState($this->getState());
$this->collection->setProgressBarAutoDisplayInterval($this->getConfig()->get(Config::PROGRESS_BAR_AUTO_DISPLAY_INTERVAL));
if (isset($this->currentTask)) {
$this->collection->add($this->currentTask);
}
}
return $this->collection;
}
}

View File

@@ -1,151 +0,0 @@
<?php
namespace Robo\Collection;
use Psr\Log\LogLevel;
use Robo\Contract\TaskInterface;
interface CollectionInterface extends NestedCollectionInterface
{
/**
* Unnamed tasks are assigned an arbitrary numeric index
* in the task list. Any numeric value may be used, but the
* UNNAMEDTASK constant is recommended for clarity.
*
* @var int
*/
const UNNAMEDTASK = 0;
/**
* Add a task or a list of tasks to our task collection. Each task
* will run via its 'run()' method once (and if) all of the tasks
* added before it complete successfully. If the task also implements
* RollbackInterface, then it will be rolled back via its 'rollback()'
* method ONLY if its 'run()' method completes successfully, and some
* task added after it fails.
*
* @param TaskInterface $task
* The task to add to our collection.
* @param int|string $name
* An optional name for the task -- missing or UNNAMEDTASK for unnamed tasks.
* Names are used for positioning before and after tasks.
*
* @return CollectionInterface
*/
public function add(TaskInterface $task, $name = self::UNNAMEDTASK);
/**
* Add arbitrary code to execute as a task.
*
* @param callable $code Code to execute as a task
* @param int|string $name
* An optional name for the task -- missing or UNNAMEDTASK for unnamed tasks.
* Names are used for positioning before and after tasks.
*
* @return $this
*/
public function addCode(callable $code, $name = self::UNNAMEDTASK);
/**
* Add arbitrary code that will be called once for every item in the
* provided array or iterable object. If the function result of the
* provided callback is a TaskInterface or Collection, then it will be
* executed.
*
* @param CollectionInterface|array $iterable A collection of things to iterate
* @param $code $code A callback function to call for each item in the collection.
*
* @return $this
*/
public function addIterable($iterable, callable $code);
/**
* Add a rollback task to our task collection. A rollback task
* will execute ONLY if all of the tasks added before it complete
* successfully, AND some task added after it fails.
*
* @param TaskInterface $rollbackTask
* The rollback task to add. Note that the 'run()' method of the
* task executes, not its 'rollback()' method. To use the 'rollback()'
* method, add the task via 'Collection::add()' instead.
*
* @return $this
*/
public function rollback(TaskInterface $rollbackTask);
/**
* Add arbitrary code to execute as a rollback.
*
* @param callable $rollbackTask Code to execute during rollback processing
*
* @return $this
*/
public function rollbackCode(callable $rollbackTask);
/**
* Add a completion task to our task collection. A completion task
* will execute EITHER after all tasks succeed, OR immediatley after
* any task fails. Completion tasks never cause errors to be returned
* from Collection::run(), even if they fail.
*
* @param TaskInterface $completionTask
* The completion task to add. Note that the 'run()' method of the
* task executes, just as if the task was added normally.
*
* @return $this
*/
public function completion(TaskInterface $completionTask);
/**
* Add arbitrary code to execute as a completion.
*
* @param callable $completionTask Code to execute after collection completes
*
* @return $this
*/
public function completionCode(callable $completionTask);
/**
* Add a task before an existing named task.
*
* @param string $name
* The name of the task to insert before. The named task MUST exist.
* @param callable|TaskInterface $task
* The task to add.
* @param int|string $nameOfTaskToAdd
* The name of the task to add. If not provided, will be associated
* with the named task it was added before.
*
* @return $this
*/
public function before($name, $task, $nameOfTaskToAdd = self::UNNAMEDTASK);
/**
* Add a task after an existing named task.
*
* @param string $name
* The name of the task to insert before. The named task MUST exist.
* @param callable|TaskInterface $task
* The task to add.
* @param int|string $nameOfTaskToAdd
* The name of the task to add. If not provided, will be associated
* with the named task it was added after.
*
* @return $this
*/
public function after($name, $task, $nameOfTaskToAdd = self::UNNAMEDTASK);
/**
* Print a progress message after Collection::run() has executed
* all of the tasks that were added prior to the point when this
* method was called. If one of the previous tasks fail, then this
* message will not be printed.
*
* @param string $text Message to print.
* @param array $context Extra context data for use by the logger. Note
* that the data from the collection state is merged with the provided context.
* @param \Psr\Log\LogLevel|string $level The log level to print the information at. Default is NOTICE.
*
* @return $this
*/
public function progressMessage($text, $context = [], $level = LogLevel::NOTICE);
}

View File

@@ -1,35 +0,0 @@
<?php
namespace Robo\Collection;
use Consolidation\AnnotatedCommand\Hooks\ProcessResultInterface;
use Consolidation\AnnotatedCommand\CommandData;
use Robo\Contract\TaskInterface;
use Robo\Result;
/**
* The collection process hook is added to the annotation command
* hook manager in Runner::configureContainer(). This hook will be
* called every time a command runs. If the command result is a
* \Robo\Contract\TaskInterface (in particular, \Robo\Collection\Collection),
* then we run the collection, and return the result. We ignore results
* of any other type.
*/
class CollectionProcessHook implements ProcessResultInterface
{
/**
* @param \Robo\Result|\Robo\Contract\TaskInterface $result
* @param \Consolidation\AnnotatedCommand\CommandData $commandData
*
* @return null|\Robo\Result
*/
public function process($result, CommandData $commandData)
{
if ($result instanceof TaskInterface) {
try {
return $result->run();
} catch (\Exception $e) {
return Result::fromException($result, $e);
}
}
}
}

View File

@@ -1,106 +0,0 @@
<?php
namespace Robo\Collection;
use Robo\Task\BaseTask;
use Robo\Contract\TaskInterface;
use Robo\Contract\RollbackInterface;
use Robo\Contract\CompletionInterface;
use Robo\Contract\WrappedTaskInterface;
/**
* Creates a task wrapper that will manage rollback and collection
* management to a task when it runs. Tasks are automatically
* wrapped in a CompletionWrapper when added to a task collection.
*
* Clients may need to wrap their task in a CompletionWrapper if it
* creates temporary objects.
*
* @see \Robo\Task\Filesystem\loadTasks::taskTmpDir
*/
class CompletionWrapper extends BaseTask implements WrappedTaskInterface
{
/**
* @var \Robo\Collection\Collection
*/
private $collection;
/**
* @var \Robo\Contract\TaskInterface
*/
private $task;
/**
* @var NULL|\Robo\Contract\TaskInterface
*/
private $rollbackTask;
/**
* Create a CompletionWrapper.
*
* Temporary tasks are always wrapped in a CompletionWrapper, as are
* any tasks that are added to a collection. If a temporary task
* is added to a collection, then it is first unwrapped from its
* CompletionWrapper (via its original() method), and then added to a
* new CompletionWrapper for the collection it is added to.
*
* In this way, when the CompletionWrapper is finally executed, the
* task's rollback and completion handlers will be registered on
* whichever collection it was registered on.
*
* @todo Why not CollectionInterface the type of the $collection argument?
*
* @param \Robo\Collection\Collection $collection
* @param \Robo\Contract\TaskInterface $task
* @param \Robo\Contract\TaskInterface|NULL $rollbackTask
*/
public function __construct(Collection $collection, TaskInterface $task, TaskInterface $rollbackTask = null)
{
$this->collection = $collection;
$this->task = ($task instanceof WrappedTaskInterface) ? $task->original() : $task;
$this->rollbackTask = $rollbackTask;
}
/**
* {@inheritdoc}
*/
public function original()
{
return $this->task;
}
/**
* Before running this task, register its rollback and completion
* handlers on its collection. The reason this class exists is to
* defer registration of rollback and completion tasks until 'run()' time.
*
* @return \Robo\Result
*/
public function run()
{
if ($this->rollbackTask) {
$this->collection->registerRollback($this->rollbackTask);
}
if ($this->task instanceof RollbackInterface) {
$this->collection->registerRollback(new CallableTask([$this->task, 'rollback'], $this->task));
}
if ($this->task instanceof CompletionInterface) {
$this->collection->registerCompletion(new CallableTask([$this->task, 'complete'], $this->task));
}
return $this->task->run();
}
/**
* Make this wrapper object act like the class it wraps.
*
* @param string $function
* @param array $args
*
* @return mixed
*/
public function __call($function, $args)
{
return call_user_func_array(array($this->task, $function), $args);
}
}

Some files were not shown because too many files have changed in this diff Show More