scrawl.phar

#!/usr/bin/env php
<?php
/**
 * Bundled by phar-composer with the help of php-box.
 *
 * @link https://github.com/clue/phar-composer
 */
define('BOX_EXTRACT_PATTERN_DEFAULT','__HALT'.'_COMPILER(); ?>');
define('BOX_EXTRACT_PATTERN_OPEN',"__HALT"."_COMPILER(); ?>\r\n");
if (class_exists('Phar')) {
Phar::mapPhar('');
require 'phar://' . __FILE__ . '/bin/scrawl';
} else {
$extract = new Extract(__FILE__, Extract::findStubLength(__FILE__));
$dir = $extract->go();
set_include_path($dir . PATH_SEPARATOR . get_include_path());
require "$dir/bin/scrawl";
}
class Extract
{
const PATTERN_DEFAULT=BOX_EXTRACT_PATTERN_DEFAULT;
const PATTERN_OPEN=BOX_EXTRACT_PATTERN_OPEN;
const GZ=4096;
const BZ2=8192;
const MASK=12288;
private$file;
private$handle;
private$stub;
function __construct($file,$stub){
if(!is_file($file)){
throw new InvalidArgumentException(sprintf('The path "%s" is not a file or does not exist.',$file
));
}
$this->file=$file;
$this->stub=$stub;
}
static function findStubLength($file,$pattern=self::PATTERN_OPEN
){
if(!($fp=fopen($file,'rb'))){
throw new RuntimeException(sprintf('The phar "%s" could not be opened for reading.',$file
));
}
$stub=null;
$offset=0;
$combo=str_split($pattern);
while(!feof($fp)){
if(fgetc($fp)===$combo[$offset]){
$offset++;
if(!isset($combo[$offset])){
$stub=ftell($fp);
break;
}
}else{
$offset=0;
}
}
fclose($fp);
if(null===$stub){
throw new InvalidArgumentException(sprintf('The pattern could not be found in "%s".',$file
));
}
return$stub;
}
function go($dir=null){
if(null===$dir){
$dir=rtrim(sys_get_temp_dir(),'\\/').DIRECTORY_SEPARATOR
.'pharextract'.DIRECTORY_SEPARATOR
.basename($this->file,'.phar');
}else{
$dir=realpath($dir);
}
$md5=$dir.DIRECTORY_SEPARATOR.md5_file($this->file);
if(file_exists($md5)){
return$dir;
}
if(!is_dir($dir)){
$this->createDir($dir);
}
$this->open();
if(-1===fseek($this->handle,$this->stub)){
throw new RuntimeException(sprintf('Could not seek to %d in the file "%s".',$this->stub,$this->file
));
}
$info=$this->readManifest();
if($info['flags']&self::GZ){
if(!function_exists('gzinflate')){
throw new RuntimeException('The zlib extension is (gzinflate()) is required for "%s.',$this->file
);
}
}
if($info['flags']&self::BZ2){
if(!function_exists('bzdecompress')){
throw new RuntimeException('The bzip2 extension (bzdecompress()) is required for "%s".',$this->file
);
}
}
self::purge($dir);
$this->createDir($dir);
$this->createFile($md5);
foreach($info['files']as$info){
$path=$dir.DIRECTORY_SEPARATOR.$info['path'];
$parent=dirname($path);
if(!is_dir($parent)){
$this->createDir($parent);
}
if(preg_match('{/$}',$info['path'])){
$this->createDir($path,511,false);
}else{
$this->createFile($path,$this->extractFile($info));
}
}
return$dir;
}
static function purge($path){
if(is_dir($path)){
foreach(scandir($path)as$item){
if(('.'===$item)||('..'===$item)){
continue;
}
self::purge($path.DIRECTORY_SEPARATOR.$item);
}
if(!rmdir($path)){
throw new RuntimeException(sprintf('The directory "%s" could not be deleted.',$path
));
}
}else{
if(!unlink($path)){
throw new RuntimeException(sprintf('The file "%s" could not be deleted.',$path
));
}
}
}
private function createDir($path,$chmod=511,$recursive=true){
if(!mkdir($path,$chmod,$recursive)){
throw new RuntimeException(sprintf('The directory path "%s" could not be created.',$path
));
}
}
private function createFile($path,$contents='',$mode=438){
if(false===file_put_contents($path,$contents)){
throw new RuntimeException(sprintf('The file "%s" could not be written.',$path
));
}
if(!chmod($path,$mode)){
throw new RuntimeException(sprintf('The file "%s" could not be chmodded to %o.',$path,$mode
));
}
}
private function extractFile($info){
if(0===$info['size']){
return'';
}
$data=$this->read($info['compressed_size']);
if($info['flags']&self::GZ){
if(false===($data=gzinflate($data))){
throw new RuntimeException(sprintf('The "%s" file could not be inflated (gzip) from "%s".',$info['path'],$this->file
));
}
}elseif($info['flags']&self::BZ2){
if(false===($data=bzdecompress($data))){
throw new RuntimeException(sprintf('The "%s" file could not be inflated (bzip2) from "%s".',$info['path'],$this->file
));
}
}
if(($actual=strlen($data))!==$info['size']){
throw new UnexpectedValueException(sprintf('The size of "%s" (%d) did not match what was expected (%d) in "%s".',$info['path'],$actual,$info['size'],$this->file
));
}
$crc32=sprintf('%u',crc32($data)&4294967295);
if($info['crc32']!=$crc32){
throw new UnexpectedValueException(sprintf('The crc32 checksum (%s) for "%s" did not match what was expected (%s) in "%s".',$crc32,$info['path'],$info['crc32'],$this->file
));
}
return$data;
}
private function open(){
if(null===($this->handle=fopen($this->file,'rb'))){
$this->handle=null;
throw new RuntimeException(sprintf('The file "%s" could not be opened for reading.',$this->file
));
}
}
private function read($bytes){
$read='';
$total=$bytes;
while(!feof($this->handle)&&$bytes){
if(false===($chunk=fread($this->handle,$bytes))){
throw new RuntimeException(sprintf('Could not read %d bytes from "%s".',$bytes,$this->file
));
}
$read.=$chunk;
$bytes-=strlen($chunk);
}
if(($actual=strlen($read))!==$total){
throw new RuntimeException(sprintf('Only read %d of %d in "%s".',$actual,$total,$this->file
));
}
return$read;
}
private function readManifest(){
$size=unpack('V',$this->read(4));
$size=$size[1];
$raw=$this->read($size);
$count=unpack('V',substr($raw,0,4));
$count=$count[1];
$aliasSize=unpack('V',substr($raw,10,4));
$aliasSize=$aliasSize[1];
$raw=substr($raw,14+$aliasSize);
$metaSize=unpack('V',substr($raw,0,4));
$metaSize=$metaSize[1];
$offset=0;
$start=4+$metaSize;
$manifest=array('files'=>array(),'flags'=>0,);
for($i=0;$i<$count;$i++){
$length=unpack('V',substr($raw,$start,4));
$length=$length[1];
$start+=4;
$path=substr($raw,$start,$length);
$start+=$length;
$file=unpack('Vsize/Vtimestamp/Vcompressed_size/Vcrc32/Vflags/Vmetadata_length',substr($raw,$start,24));
$file['path']=$path;
$file['crc32']=sprintf('%u',$file['crc32']&4294967295);
$file['offset']=$offset;
$offset+=$file['compressed_size'];
$start+=24+$file['metadata_length'];
$manifest['flags']|=$file['flags']&self::MASK;
$manifest['files'][]=$file;
}
return$manifest;
}
}

__HALT_COMPILER(); ?>
>�/
bin/scrawl���e�����bin/build-phar���e�cX�z�bin/tag-version��em��,�*test/input/api-full/Ext/ExportDocBlock.php
��e
�y�(�*test/input/api-full/Ext/ExportStartEnd.php��e�� test/input/api-full/Ext/Main.php{��e{˾�֤test/input/api-full/Ext/Php.php�
��e�
#O���&test/input/api-full/MdVerb/AstVerb.php7��e7�S�(test/input/api-full/MdVerb/MainVerbs.php��e���p�&test/input/api-full/MdVerb/MdVerbs.php6��e6�މ��*test/input/api-full/Template/ast/class.php���e�Q��s�5test/input/api-full/Template/ast/class_methods.md.php���e��'l�/test/input/api-full/Template/ast/default.md.phpB��eB{L!'�2test/input/api-full/Template/ast/function_list.php���e�I��.test/input/api-full/Template/ast/method.md.php���e�����0test/input/api-full/Template/bash/install.md.phpX��eX>��ɤ8test/input/api-full/Template/php/composer_install.md.php���e��,���,test/input/api-full/Template/all_classes.php��etd&C�(test/input/api-full/Utility/DocBlock.php���e�6���$test/input/api-full/Utility/Main.php��e~:��%test/input/api-full/Utility/Regex.php���e�8�	Ѥtest/input/api-full/Scrawl.phpm��emҨ�P�test/input/docs/class/Abc.mdX��eXۋcd� test/input/md-verbs/test.see.txt��e�="5�(test/input/md-verbs/test.template.md.php&��e&m��<�test/input/md-verbs/test.txt��e�Y�!test/input/project-root/README.md��e����#test/input/run-cli/code/abc/two.php���e��*P��test/input/run-cli/code/One.php���e��V�'�+test/input/run-cli/docsrc/AllClasses.src.md��e�TA��$test/input/run-cli/docsrc/One.src.md'��e'XT֤'test/input/run-cli/docsrc/README.src.md���e�y�v_�/test/input/run-cli/template/own_template.md.php��e]�^z�'test/input/run-cli/scrawl-bootstrap.php���e�G�ą�test/input/run-cli/scrawl.json���e���g��test/input/run-cli/README.md���e�
��$test/input/run-full/code/abc/two.php���e��*P�� test/input/run-full/code/One.php���e��V�'�,test/input/run-full/docsrc/AllClasses.src.md��e�TA��%test/input/run-full/docsrc/One.src.md'��e'XT֤(test/input/run-full/docsrc/README.src.md���e�y�v_�0test/input/run-full/template/own_template.md.php��e]�^z�test/input/run-full/README.md���e�
��&test/old/input/Project/code/AbcExt.php��e+֝��$test/old/input/Project/code/Bird.php���e�L�߮�#test/old/input/Project/code/Dog.php���e�ilS:�2test/old/input/Project/docs/api/code/AbcExt.php.md4��e4�u墴0test/old/input/Project/docs/api/code/Bird.php.md���e�#�W��/test/old/input/Project/docs/api/code/Dog.php.md���e��fe� test/old/input/Project/README.md��ec֟��test/old/GeneratedDocs.php|��e|IdQ&�test/old/Init.php=��e=XCK�2test/output/api-full/api/Ext/ExportDocBlock.php.mda��ea�B[��2test/output/api-full/api/Ext/ExportStartEnd.php.mdM��eM��츴(test/output/api-full/api/Ext/Main.php.md��e��H�'test/output/api-full/api/Ext/Php.php.md���e�VL	��.test/output/api-full/api/MdVerb/AstVerb.php.md���e��`��0test/output/api-full/api/MdVerb/MainVerbs.php.md���e�:����.test/output/api-full/api/MdVerb/MdVerbs.php.mdK��eK��_�0test/output/api-full/api/Utility/DocBlock.php.md���e���T�,test/output/api-full/api/Utility/Main.php.md���e���wf�-test/output/api-full/api/Utility/Regex.php.mdL��eLq�2��&test/output/api-full/api/Scrawl.php.md"��e"еsE�"test/output/api-full/api/README.md��e`>���test/output/api/test-gen_api.md���e��.��0test/output/run-cli/docs/api/code/abc/two.php.md=��e=�(��,test/output/run-cli/docs/api/code/One.php.md9��e9W��ܴ&test/output/run-cli/docs/api/README.md��e��T�&test/output/run-cli/docs/AllClasses.mdn��en4H\��test/output/run-cli/docs/One.md���e��K�"test/output/run-cli/docs/README.md���e�
��1test/output/run-full/docs/api/code/abc/two.php.md=��e=�(��-test/output/run-full/docs/api/code/One.php.md9��e9W��ܴ'test/output/run-full/docs/api/README.md��e��T�'test/output/run-full/docs/AllClasses.mdn��en4H\�� test/output/run-full/docs/One.md���e��K�#test/output/run-full/docs/README.md���e�
��test/run/Integrate.php�(��e�(�6�_�test/run/MdDocs.php���e�8<���test/run/MdTemplates.php���e�C�״test/run/SrcCode.php_��e_���test/config.jsonW��eW�ɣ�LICENSE,��e,8S�	README.md�'��e�'���	Status.md�.��e�.���c�
composer.json:��e:�60�
composer.lockL��eL��8\�src/Ext/ExportDocBlock.phpp��ep�>Wɴsrc/Ext/ExportStartEnd.php��e��src/Ext/Main.php{��e{˾�ִsrc/Ext/Php.php��e��e��src/Ext/TestExtension.php���e��q�u�src/Ext/DoNothingExtension.php���e�p�P�src/MdVerb/AstVerb.php%��e%	IM��src/MdVerb/MainVerbs.phpE��eEM�D��src/MdVerb/MdVerbs.php���e���4´src/Template/ast/class.php���e���ʹ%src/Template/ast/class_methods.md.phpk��ek�;�src/Template/ast/default.md.php���e�ψo�"src/Template/ast/function_list.php���e�I��src/Template/ast/method.md.php���e�����src/Template/ast/debug.php���e���`�!src/Template/ast/ApiReadme.md.php���e���֤ src/Template/bash/install.md.phpX��eX>��ɴ(src/Template/php/composer_install.md.phpk��ekg����,src/Template/php/composer_install_inline.php��e�8�src/Template/all_classes.php.��e.�
ee�!src/Template/git/ChangeLog.md.phpt��etW��� src/Template/git/CloneUrl.md.php��e���src/Utility/DocBlock.phpF��eFd9��src/Utility/Main.php���e�:�k��src/Utility/Regex.php���e�1�d�src/Old.phps��es���شsrc/defaults.json���e����*�src/Extension.php�
��e�
�$��src/defaults-1.0.json4��e4b�a�src/defaults-no-comments.json���e���!ۤsrc/Scrawl.phpHU��eHU�
�docsrc/ClassList.src.md��e�TA��docsrc/README.src.md���e�0j�{�docsrc/README.src.md.bak�
��e�
����docsrc/ChangeLog.src.md���e�i�7��!doctemplate/Scrawl/MdVerbs.md.phpl��elbXU=�#doctemplate/Scrawl/Templates.md.phpM��eM�x`��config/scrawl.json���e�x��build/phar-composer-1.4.0.phar�p��e�p<˿�build/cicd.yaml���e�a�a�&docs/api/src/Ext/ExportDocBlock.php.md���e�<�Q��&docs/api/src/Ext/ExportStartEnd.php.md���e���=��docs/api/src/Ext/Main.php.mdI��eIr�)�docs/api/src/Ext/Php.php.md��ew3>z�%docs/api/src/Ext/TestExtension.php.md���e�/Dn��*docs/api/src/Ext/DoNothingExtension.php.md3��e3��]l�"docs/api/src/MdVerb/AstVerb.php.mdD��eD��)��$docs/api/src/MdVerb/MainVerbs.php.md���e��q���"docs/api/src/MdVerb/MdVerbs.php.md���e�Z�ur�$docs/api/src/Utility/DocBlock.php.md_��e_a�� docs/api/src/Utility/Main.php.md���e��<���!docs/api/src/Utility/Regex.php.md���e�S�|�docs/api/src/Old.php.md���e�B�g��docs/api/src/Scrawl.php.md��e�%�-�"docs/api/test/run/Integrate.php.mdT��eTg�Z�docs/api/test/run/MdDocs.php.md���e��-�R�$docs/api/test/run/MdTemplates.php.md���e���s� docs/api/test/run/SrcCode.php.md���e����¤docs/api/README.mdr��er����docs/ClassList.mdS��eS��/ädocs/README.md�'��e�'���docs/README.src.md.bak���e��Pb�docs/ChangeLog.md�a��e�a�ϯ��vendor/autoload.php��e�Qh��vendor/composer/ClassLoader.php�?��e�?2@u�%vendor/composer/InstalledVersions.php]?��e]?�N�%vendor/composer/autoload_classmap.php��e���'vendor/composer/autoload_namespaces.php���e��/t�!vendor/composer/autoload_psr4.php���e��ݬ�!vendor/composer/autoload_real.php?��e?h��<�#vendor/composer/autoload_static.php��e�
曤vendor/composer/installed.json ��e �
l��vendor/composer/installed.php}
��e}
f�M�"vendor/taeluf/better-regex/LICENSE,��e,8S�$vendor/taeluf/better-regex/README.md���e��9랤$vendor/taeluf/better-regex/Status.md���e���O��(vendor/taeluf/better-regex/code/Breg.phpd��ed��SX�+vendor/taeluf/better-regex/code/Matcher.php���e����U�*vendor/taeluf/better-regex/code/Parser.php���e���a�(vendor/taeluf/better-regex/composer.json��e����(vendor/taeluf/better-regex/composer.lock��e'X΀�)vendor/taeluf/better-regex/docs/README.md���e��9랤4vendor/taeluf/better-regex/docs/api/code/Breg.php.md���e�eSe��6vendor/taeluf/better-regex/docs/api/code/Parser.php.mdS��eS���<vendor/taeluf/better-regex/docs/api/test/run/Cleaning.php.md���e��U��8vendor/taeluf/better-regex/docs/api/test/run/Main.php.md���e�z�w��/vendor/taeluf/better-regex/docs/exports/keys.md�	��e�	0�֟�0vendor/taeluf/better-regex/docs/exports/keys.phpQ
��eQ
� �y�+vendor/taeluf/better-regex/test/config.json���e���%=�6vendor/taeluf/better-regex/test/input/bug/whenever.regk��ek��q�:vendor/taeluf/better-regex/test/input/bug/whenever.reg.bakq��eqF��0vendor/taeluf/better-regex/test/run/Cleaning.php���e�\~^��,vendor/taeluf/better-regex/test/run/Main.phpW��eW�v@o�vendor/taeluf/cli/README.md�
��e�
���vendor/taeluf/cli/Status.md���e���̤vendor/taeluf/cli/bin/tlf-cliO��eOO[��vendor/taeluf/cli/composer.json.��e.}�G3�vendor/taeluf/cli/composer.lock���e�"��X�$vendor/taeluf/cli/config/scrawl.json���e�o����"vendor/taeluf/cli/doc/Changelog.mdv��ev-咳�vendor/taeluf/cli/doc/README.md�
��e�
���)vendor/taeluf/cli/doc/api/code/Cli.php.md���e�o!�)vendor/taeluf/cli/docsrc/Changelog.src.md4��e4�/nj�&vendor/taeluf/cli/docsrc/README.src.md���e�iᐿ�vendor/taeluf/cli/src/Cli.php(��e(:���vendor/taeluf/cli/src/Msgs.php���e��N{�'vendor/taeluf/cli/test/TestResults.html��e�$vendor/taeluf/cli/test/defaults.json���e�]���vendor/taeluf/cli/test/proto���e�#��<�vendor/taeluf/cli/test/test.phpB��eB��7�(vendor/taeluf/cli/test/user_configs.jsonw��ew]�15�vendor/taeluf/lexer/Devlog.md--��e--��j5�vendor/taeluf/lexer/Issues.md���e���3�vendor/taeluf/lexer/LICENSE-��e-��j�vendor/taeluf/lexer/README.mdj��ej2g�^�vendor/taeluf/lexer/README2.md���e�5~��vendor/taeluf/lexer/Status.md�+��e�+Mԟ�vendor/taeluf/lexer/bin/lex���e��_$�!vendor/taeluf/lexer/composer.json���e�8�ʤ!vendor/taeluf/lexer/composer.lock���e�$�2�'vendor/taeluf/lexer/config/phptest.json���e�Y�`�&vendor/taeluf/lexer/config/scrawl.json���e�s�Ǥ(vendor/taeluf/lexer/docs/Architecture.md�
��e�
��K�%vendor/taeluf/lexer/docs/Changelog.mdiR��eiR-��(vendor/taeluf/lexer/docs/CreateParser.md�/��e�/t*�s�2vendor/taeluf/lexer/docs/Development/PhpGrammar.md�
��e�
�F��-vendor/taeluf/lexer/docs/DirectiveCommands.md`��e`Mk��$vendor/taeluf/lexer/docs/Examples.md	��e	�����*vendor/taeluf/lexer/docs/GettingStarted.md���e��Q�*vendor/taeluf/lexer/docs/GrammarExample.mdx��ex;{$�&vendor/taeluf/lexer/docs/OldReadme1.md+��e+�E~~�%vendor/taeluf/lexer/docs/ParseCode.md���e�*�<��"vendor/taeluf/lexer/docs/README.mdj��ej2g�^�#vendor/taeluf/lexer/docs/Testing.md���e�z��v� vendor/taeluf/lexer/docs/Tips.md>��e>ph�]�"vendor/taeluf/lexer/docs/UseAST.md���e��crݤ+vendor/taeluf/lexer/docs/api/src/Ast.php.md���e�Wx�"�4vendor/taeluf/lexer/docs/api/src/Ast/ArrayAst.php.md[��e[Mjɤ3vendor/taeluf/lexer/docs/api/src/Ast/JsonAst.php.mdI��eI�c8�5vendor/taeluf/lexer/docs/api/src/Ast/StringAst.php.md_��e_2�_)�8vendor/taeluf/lexer/docs/api/src/Bash/BashGrammar.php.mdS��eSx�QU�Hvendor/taeluf/lexer/docs/api/src/Docblock/DocblockGrammar.defunct.php.md��e�Ap�@vendor/taeluf/lexer/docs/api/src/Docblock/DocblockGrammar.php.md���e��n�/vendor/taeluf/lexer/docs/api/src/Grammar.php.md���e�`1�.vendor/taeluf/lexer/docs/api/src/Helper.php.md���e��E��-vendor/taeluf/lexer/docs/api/src/Lexer.php.md8	��e8	\r�F�5vendor/taeluf/lexer/docs/api/src/Lexer/Utility.php.md��e_I�6vendor/taeluf/lexer/docs/api/src/Lexer/Versions.php.md`��e`�@=��7vendor/taeluf/lexer/docs/api/src/NewAst/ClassAst.php.md��e����:vendor/taeluf/lexer/docs/api/src/NewAst/DocblockAst.php.md��eMkۧ�:vendor/taeluf/lexer/docs/api/src/NewAst/PropertyAst.php.md��ee�]8�6vendor/taeluf/lexer/docs/api/src/Php/PhpGrammar.php.md���e�*ɚ��-vendor/taeluf/lexer/docs/api/src/Token.php.md���e�=�Y7�7vendor/taeluf/lexer/docs/api/src/old/JsonGrammar.php.mdz��ez���-�:vendor/taeluf/lexer/docs/api/src/old/OldBashGrammar.php.md(��e(lH��/vendor/taeluf/lexer/docs/api/test/Tester.php.md��ey1���Bvendor/taeluf/lexer/docs/api/test/input/old/all/BashGrammar.php.md���e� �U�Bvendor/taeluf/lexer/docs/api/test/input/old/all/JsonGrammar.php.mdN��eN'�t�Mvendor/taeluf/lexer/docs/api/test/input/old/php-new/PhpGrammar.16jul21.php.md���e�bn���Fvendor/taeluf/lexer/docs/api/test/input/old/php-new/SampleClass.php.md��e|��Qvendor/taeluf/lexer/docs/api/test/input/old/php-new/StarterGrammar.16jul21.php.md���e����Mvendor/taeluf/lexer/docs/api/test/input/old/php-old/PhpGrammar.16jul21.php.md���e��v��Fvendor/taeluf/lexer/docs/api/test/input/old/php-old/SampleClass.php.md��eVo��Qvendor/taeluf/lexer/docs/api/test/input/old/php-old/StarterGrammar.16jul21.php.md���e�w��Gvendor/taeluf/lexer/docs/api/test/input/php/DocumentationExample.php.mdg��eg7�Y�Hvendor/taeluf/lexer/docs/api/test/input/php/lex/MethodParseErrors.php.md8��e8w�Bvendor/taeluf/lexer/docs/api/test/input/php/lex/SampleClass.php.md
��e
!�U�Rvendor/taeluf/lexer/docs/api/test/input/php/lex/code-scrawl/IntegrationTest.php.md���e��LäLvendor/taeluf/lexer/docs/api/test/input/php/lex/code-scrawl/MainVerbs.php.md���e���l��Rvendor/taeluf/lexer/docs/api/test/input/php/lex/code-scrawl/Scrawl2-partial.php.mdq��eq]k�Y�Jvendor/taeluf/lexer/docs/api/test/input/php/lex/code-scrawl/Scrawl2.php.mdA��eA3(ɤWvendor/taeluf/lexer/docs/api/test/input/php/lex/code-scrawl/functionListTemplate.php.mdE��eE� A�Bvendor/taeluf/lexer/docs/api/test/input/php/lex/lildb/LilDb.php.mdu��euB��Jvendor/taeluf/lexer/docs/api/test/input/php/lex/lildb/LilMigrations.php.md���e�����Mvendor/taeluf/lexer/docs/api/test/input/php/lex/lildb/LilMigrationsBug.php.md���e�4(ȤEvendor/taeluf/lexer/docs/api/test/input/php/lex/phad/FormsTest.php.md#��e#��S��Evendor/taeluf/lexer/docs/api/test/input/php/lex/phtml/Compiler.php.md
��e
�.�Avendor/taeluf/lexer/docs/api/test/input/php/lex/phtml/Node.php.md�	��e�	�TQߤFvendor/taeluf/lexer/docs/api/test/input/php/lex/phtml/PHPParser.php.md���e���g(�Bvendor/taeluf/lexer/docs/api/test/input/php/lex/phtml/Phtml.php.md4	��e4	�f���Evendor/taeluf/lexer/docs/api/test/input/php/lex/phtml/TextNode.php.mdC��eCų��=vendor/taeluf/lexer/docs/api/test/output/PhpExampleAst.php.md���e���gӤ9vendor/taeluf/lexer/docs/api/test/run/DefunctTests.php.md���e����
�Avendor/taeluf/lexer/docs/api/test/run/Grammars/BashGrammar.php.md���e��R��Evendor/taeluf/lexer/docs/api/test/run/Grammars/DocblockGrammar.php.md���e�:�b�@vendor/taeluf/lexer/docs/api/test/run/Grammars/PhpGrammar.php.md	��e	M턼�=vendor/taeluf/lexer/docs/api/test/run/debug/PhpGrammar.php.md���e���9vendor/taeluf/lexer/docs/api/test/run/document/Idk.php.md���e������@vendor/taeluf/lexer/docs/api/test/run/document/PhpGrammar.php.md���e�xC^Ĥ5vendor/taeluf/lexer/docs/api/test/run/main/Api.php.md^��e^�(�-�9vendor/taeluf/lexer/docs/api/test/run/main/Grammar.php.mdB��eB�O`�6vendor/taeluf/lexer/docs/api/test/run/main/Main.php.md3��e30�@vendor/taeluf/lexer/docs/api/test/run/main/StarterGrammar.php.mdq��eq�m��@vendor/taeluf/lexer/docs/api/test/run/translate/Translate.php.mdt��et�.T�Cvendor/taeluf/lexer/docs/api/test/src/Starter/StarterGrammar.php.md���e��B�`�3vendor/taeluf/lexer/docs/old-dev/DocblockGrammar.md+%��e+%����+vendor/taeluf/lexer/docs/old-dev/History.mdS��eS6��4�:vendor/taeluf/lexer/docs/old-dev/PhpGrammarArchitecture.md�
��e�
�k(��7vendor/taeluf/lexer/docs/old-dev/PhpLanguageFeatures.md���e�mVdؤ1vendor/taeluf/lexer/docs/old-dev/UnsortedNotes.md�
��e�
{z�}�.vendor/taeluf/lexer/docsrc/Architecture.src.md0
��e0
k>ܤ+vendor/taeluf/lexer/docsrc/Changelog.src.md1��e1��QP�.vendor/taeluf/lexer/docsrc/CreateParser.src.md9.��e9.%K?�8vendor/taeluf/lexer/docsrc/Development/PhpGrammar.src.mdY
��eY
���`�3vendor/taeluf/lexer/docsrc/DirectiveCommands.src.md��eP<v��*vendor/taeluf/lexer/docsrc/Examples.src.mdT��eTgu���0vendor/taeluf/lexer/docsrc/GettingStarted.src.md���e��@�0vendor/taeluf/lexer/docsrc/GrammarExample.src.mdY��eY����,vendor/taeluf/lexer/docsrc/OldReadme1.src.mdP��eP���+vendor/taeluf/lexer/docsrc/ParseCode.src.md,��e,
��(vendor/taeluf/lexer/docsrc/README.src.md���e�M;R�)vendor/taeluf/lexer/docsrc/Testing.src.md���e�K�ܤ&vendor/taeluf/lexer/docsrc/Tips.src.md.��e.�Q���(vendor/taeluf/lexer/docsrc/UseAST.src.md*��e*.���5vendor/taeluf/lexer/docsrc/old-dev/DocblockGrammar.md�"��e�"O/�^�-vendor/taeluf/lexer/docsrc/old-dev/History.md���e�4��<�<vendor/taeluf/lexer/docsrc/old-dev/PhpGrammarArchitecture.md*
��e*
�;Д�9vendor/taeluf/lexer/docsrc/old-dev/PhpLanguageFeatures.md���e��k'¤3vendor/taeluf/lexer/docsrc/old-dev/UnsortedNotes.md�	��e�	��tY�*vendor/taeluf/lexer/old/PhpGrammarTest.php�8��e�8
�>�1vendor/taeluf/lexer/old/PhpOld/BodyDirectives.php���e����#�2vendor/taeluf/lexer/old/PhpOld/ClassDirectives.php���e��yGŤ6vendor/taeluf/lexer/old/PhpOld/ClassDirectives.php.bakq��eq��p�6vendor/taeluf/lexer/old/PhpOld/ClassDirectives.php.old"��e"��L�8vendor/taeluf/lexer/old/PhpOld/ClassMemberDirectives.php)*��e)*����5vendor/taeluf/lexer/old/PhpOld/LanguageDirectives.phpz��ez��0P�2vendor/taeluf/lexer/old/PhpOld/OtherDirectives.phpL��eL^f.�-vendor/taeluf/lexer/old/PhpOld/PhpGrammar.php��e�����vendor/taeluf/lexer/src/Ast.php���e�E˵��(vendor/taeluf/lexer/src/Ast/ArrayAst.php8��e82W���'vendor/taeluf/lexer/src/Ast/JsonAst.phpU��eU(>=5�)vendor/taeluf/lexer/src/Ast/StringAst.php���e��o;�,vendor/taeluf/lexer/src/Bash/BashGrammar.php�
��e�
F;t�0vendor/taeluf/lexer/src/Bash/BashGrammar.php.bak���e�����0vendor/taeluf/lexer/src/Bash/OtherDirectives.phpy
��ey
��[��<vendor/taeluf/lexer/src/Docblock/DocblockGrammar.defunct.php���e� �`�4vendor/taeluf/lexer/src/Docblock/DocblockGrammar.php[��e[�_�x�#vendor/taeluf/lexer/src/Grammar.php
)��e
)owT�"vendor/taeluf/lexer/src/Helper.php���e�i싘�!vendor/taeluf/lexer/src/Lexer.php���e���'�'vendor/taeluf/lexer/src/Lexer/Cache.php��e)�g�,vendor/taeluf/lexer/src/Lexer/Directives.php�	��e�	����6vendor/taeluf/lexer/src/Lexer/InstructionProcessor.php���e��&=%�.vendor/taeluf/lexer/src/Lexer/Instructions.php� ��e� �`�+vendor/taeluf/lexer/src/Lexer/Internals.php��e��gW�/vendor/taeluf/lexer/src/Lexer/MappedMethods.php���e�g�+Τ)vendor/taeluf/lexer/src/Lexer/Utility.php��e���*vendor/taeluf/lexer/src/Lexer/Versions.php��e�M�+vendor/taeluf/lexer/src/NewAst/ClassAst.php-��e-0w�8�.vendor/taeluf/lexer/src/NewAst/DocblockAst.php���e��K��.vendor/taeluf/lexer/src/NewAst/PropertyAst.php�
��e�
O�֭�.vendor/taeluf/lexer/src/Php/CoreDirectives.php�
��e�
ab3T�(vendor/taeluf/lexer/src/Php/Handlers.php���e��}ݤ*vendor/taeluf/lexer/src/Php/Operations.php?5��e?5Q*%�*vendor/taeluf/lexer/src/Php/PhpGrammar.php�	��e�	�}�Ĥ%vendor/taeluf/lexer/src/Php/README.md"
��e"
���0vendor/taeluf/lexer/src/Php/StringDirectives.phpG
��eG
�56�%vendor/taeluf/lexer/src/Php/Words.php,!��e,!���X�!vendor/taeluf/lexer/src/Token.phpd��ed�S�E�+vendor/taeluf/lexer/src/old/JsonGrammar.php� ��e� ��.m�.vendor/taeluf/lexer/src/old/OldBashGrammar.php���e��S�
�#vendor/taeluf/lexer/test/Tester.php���e���x�Ivendor/taeluf/lexer/test/input/bash/comments_docblocks_functions.bash.bak���e���~%�;vendor/taeluf/lexer/test/input/bash/comments_functions.bash���e�
�
1�Evendor/taeluf/lexer/test/input/bash/whitespace_docblock_function.bashU��eU���<vendor/taeluf/lexer/test/input/bash/ws_dblock_func_cmnt.bash���e�
8A�6vendor/taeluf/lexer/test/input/old/all/BashGrammar.php���e����U�<vendor/taeluf/lexer/test/input/old/all/Documentation.php.old���e���䵤6vendor/taeluf/lexer/test/input/old/all/JsonGrammar.php���e�PK�B�4vendor/taeluf/lexer/test/input/old/extra/Sample.bash���e��1���5vendor/taeluf/lexer/test/input/old/extra/Sample2.bash���e�7�Ф5vendor/taeluf/lexer/test/input/old/extra/Sample3.bash}��e}�D��5vendor/taeluf/lexer/test/input/old/extra/Sample4.bash-
��e-
�$*t�5vendor/taeluf/lexer/test/input/old/extra/Sample5.bash%
��e%
�ep��Avendor/taeluf/lexer/test/input/old/php-new/Convoluted.old.php.oldz��ez��c�Avendor/taeluf/lexer/test/input/old/php-new/PhpGrammar.16jul21.php'��e'�D��Fvendor/taeluf/lexer/test/input/old/php-new/PhpGrammar.16jul21.tree.phpQ#��eQ#��>]�Gvendor/taeluf/lexer/test/input/old/php-new/PhpGrammar.16jul21.tree2.php?#��e?#}���:vendor/taeluf/lexer/test/input/old/php-new/SampleClass.php��e���z�?vendor/taeluf/lexer/test/input/old/php-new/SampleClass.tree.php�	��e�	��Z�@vendor/taeluf/lexer/test/input/old/php-new/SampleClass.tree2.php�
��e�
�*�Evendor/taeluf/lexer/test/input/old/php-new/StarterGrammar.16jul21.phpy��ey�0b�Jvendor/taeluf/lexer/test/input/old/php-new/StarterGrammar.16jul21.tree.php��e��R�Kvendor/taeluf/lexer/test/input/old/php-new/StarterGrammar.16jul21.tree2.php���e���-�Avendor/taeluf/lexer/test/input/old/php-old/Convoluted.old.php.oldz��ez��c�Avendor/taeluf/lexer/test/input/old/php-old/PhpGrammar.16jul21.php'��e'�D��Fvendor/taeluf/lexer/test/input/old/php-old/PhpGrammar.16jul21.tree.phpQ#��eQ#��>]�Gvendor/taeluf/lexer/test/input/old/php-old/PhpGrammar.16jul21.tree2.phpN#��eN#R�	{�:vendor/taeluf/lexer/test/input/old/php-old/SampleClass.php��e���z�?vendor/taeluf/lexer/test/input/old/php-old/SampleClass.tree.php�	��e�	�Hw��@vendor/taeluf/lexer/test/input/old/php-old/SampleClass.tree2.php�	��e�	ż��Evendor/taeluf/lexer/test/input/old/php-old/StarterGrammar.16jul21.phpy��ey�0b�Jvendor/taeluf/lexer/test/input/old/php-old/StarterGrammar.16jul21.tree.php��e��R�Kvendor/taeluf/lexer/test/input/old/php-old/StarterGrammar.16jul21.tree2.php��e"t�[�;vendor/taeluf/lexer/test/input/php/DocumentationExample.php���e�l�?o�?vendor/taeluf/lexer/test/input/php/DocumentationExampleTree.php���e�;�{��@vendor/taeluf/lexer/test/input/php/counts/MethodParseErrors.json���e�J-�ؤ:vendor/taeluf/lexer/test/input/php/counts/SampleClass.jsona��ea
����Ovendor/taeluf/lexer/test/input/php/counts/code-scrawl/functionListTemplate.json���e�4�d�:vendor/taeluf/lexer/test/input/php/counts/lildb/LilDb.json_��e_]w�Bvendor/taeluf/lexer/test/input/php/counts/lildb/LilMigrations.jsonK��eK�z�x�Evendor/taeluf/lexer/test/input/php/counts/lildb/LilMigrationsBug.json^��e^{��z�=vendor/taeluf/lexer/test/input/php/counts/phad/FormsTest.json_��e_����=vendor/taeluf/lexer/test/input/php/counts/phtml/Compiler.json���e��E"��9vendor/taeluf/lexer/test/input/php/counts/phtml/Node.json���e�瓐�>vendor/taeluf/lexer/test/input/php/counts/phtml/PHPParser.json���e���u�:vendor/taeluf/lexer/test/input/php/counts/phtml/Phtml.json���e�^dKC�=vendor/taeluf/lexer/test/input/php/counts/phtml/TextNode.json=��e=���g�<vendor/taeluf/lexer/test/input/php/lex/MethodParseErrors.php���e���Ѵ�6vendor/taeluf/lexer/test/input/php/lex/SampleClass.php��e���z�Fvendor/taeluf/lexer/test/input/php/lex/code-scrawl/IntegrationTest.phpm��em}���@vendor/taeluf/lexer/test/input/php/lex/code-scrawl/MainVerbs.php��e2�`V�Fvendor/taeluf/lexer/test/input/php/lex/code-scrawl/Scrawl2-partial.php���e��P`.�>vendor/taeluf/lexer/test/input/php/lex/code-scrawl/Scrawl2.phpn��en�'Y�Kvendor/taeluf/lexer/test/input/php/lex/code-scrawl/functionListTemplate.php���e���R�6vendor/taeluf/lexer/test/input/php/lex/lildb/LilDb.php�"��e�"�4�>vendor/taeluf/lexer/test/input/php/lex/lildb/LilMigrations.php��evQ٤Avendor/taeluf/lexer/test/input/php/lex/lildb/LilMigrationsBug.php��e��R�9vendor/taeluf/lexer/test/input/php/lex/phad/FormsTest.php$>��e$>BF��9vendor/taeluf/lexer/test/input/php/lex/phtml/Compiler.phpH��eHb��5vendor/taeluf/lexer/test/input/php/lex/phtml/Node.php���e�X�
!�:vendor/taeluf/lexer/test/input/php/lex/phtml/PHPParser.phpf��ef�>��6vendor/taeluf/lexer/test/input/php/lex/phtml/Phtml.phpm#��em#�,��9vendor/taeluf/lexer/test/input/php/lex/phtml/TextNode.php��e}�5��2vendor/taeluf/lexer/test/output/PhpExampleAst.json���e��$�1vendor/taeluf/lexer/test/output/PhpExampleAst.php���e��د��.vendor/taeluf/lexer/test/output/PhpFeatures.mdS��eS�Ø��Dvendor/taeluf/lexer/test/output/php/tree/Lexer/GrammarTestMinimal.js5
��e5
���3�Kvendor/taeluf/lexer/test/output/php/tree/Lexer/GrammarTestMinimal.printr.js���e�)�e�=vendor/taeluf/lexer/test/output/php/tree/MethodParseErrors.js�?��e�?�њ�Dvendor/taeluf/lexer/test/output/php/tree/MethodParseErrors.printr.js�n��e�n���7vendor/taeluf/lexer/test/output/php/tree/SampleClass.js���e�폒-�>vendor/taeluf/lexer/test/output/php/tree/SampleClass.printr.js���e�k��Lvendor/taeluf/lexer/test/output/php/tree/code-scrawl/functionListTemplate.js_��e_���Svendor/taeluf/lexer/test/output/php/tree/code-scrawl/functionListTemplate.printr.jsQ��eQ!M�7vendor/taeluf/lexer/test/output/php/tree/lildb/LilDb.js����e����삤>vendor/taeluf/lexer/test/output/php/tree/lildb/LilDb.printr.js����e�����?vendor/taeluf/lexer/test/output/php/tree/lildb/LilMigrations.js)��e)�-��Fvendor/taeluf/lexer/test/output/php/tree/lildb/LilMigrations.printr.js�E��e�E��[��Bvendor/taeluf/lexer/test/output/php/tree/lildb/LilMigrationsBug.js���e�Ky��Ivendor/taeluf/lexer/test/output/php/tree/lildb/LilMigrationsBug.printr.js/
��e/
MX���:vendor/taeluf/lexer/test/output/php/tree/phad/FormsTest.js�P��e�PI�ޗ�Avendor/taeluf/lexer/test/output/php/tree/phad/FormsTest.printr.js%n��e%nw��K�:vendor/taeluf/lexer/test/output/php/tree/phtml/Compiler.js�d��e�dY�az�Avendor/taeluf/lexer/test/output/php/tree/phtml/Compiler.printr.jsѲ��eѲ��O�6vendor/taeluf/lexer/test/output/php/tree/phtml/Node.jsN��eN�!�(�=vendor/taeluf/lexer/test/output/php/tree/phtml/Node.printr.js���e�^_�'�;vendor/taeluf/lexer/test/output/php/tree/phtml/PHPParser.jsX1��eX1�|0�Bvendor/taeluf/lexer/test/output/php/tree/phtml/PHPParser.printr.js,U��e,U����7vendor/taeluf/lexer/test/output/php/tree/phtml/Phtml.js�h��e�hJ$��>vendor/taeluf/lexer/test/output/php/tree/phtml/Phtml.printr.js2���e2��{�:vendor/taeluf/lexer/test/output/php/tree/phtml/TextNode.js���e�a�x��Avendor/taeluf/lexer/test/output/php/tree/phtml/TextNode.printr.js���e�L���-vendor/taeluf/lexer/test/run/DefunctTests.phpu��eu��Τ5vendor/taeluf/lexer/test/run/Grammars/BashGrammar.php!��e!@tsϤ9vendor/taeluf/lexer/test/run/Grammars/DocblockGrammar.php� ��e� F�Ǥ4vendor/taeluf/lexer/test/run/Grammars/PhpGrammar.phpN1��eN1�I�j�1vendor/taeluf/lexer/test/run/debug/PhpGrammar.phpl��el�M�!�-vendor/taeluf/lexer/test/run/document/Idk.php��e`�m6�4vendor/taeluf/lexer/test/run/document/PhpGrammar.php��e�_y�)vendor/taeluf/lexer/test/run/main/Api.php���e�y�$�-vendor/taeluf/lexer/test/run/main/Grammar.php�5��e�5��Q�*vendor/taeluf/lexer/test/run/main/Main.phpc��ecU��Τ4vendor/taeluf/lexer/test/run/main/StarterGrammar.php���e�Fޣ��4vendor/taeluf/lexer/test/run/translate/Translate.php-��e-*�g�)vendor/taeluf/lexer/test/src/Php/Args.phpD��eDTvK�5vendor/taeluf/lexer/test/src/Php/ClassIntegration.php�'��e�'�>2#�,vendor/taeluf/lexer/test/src/Php/Classes.phpl��el���P�+vendor/taeluf/lexer/test/src/Php/Consts.php���e��n�,vendor/taeluf/lexer/test/src/Php/Methods.php�&��e�&3���/vendor/taeluf/lexer/test/src/Php/Namespaces.phpq��eqb�ۤ*vendor/taeluf/lexer/test/src/Php/Other.phpN��eN��]פ0vendor/taeluf/lexer/test/src/Php/PhpOpenTags.php���e��A.3�*vendor/taeluf/lexer/test/src/Php/Props.php���e��5�+vendor/taeluf/lexer/test/src/Php/Traits.php"	��e"	���-vendor/taeluf/lexer/test/src/Php/UseTrait.php-��e-�?�"�+vendor/taeluf/lexer/test/src/Php/Values.php^��e^qP�^�)vendor/taeluf/lexer/test/src/Php/Vars.phpm��em\�w��8vendor/taeluf/lexer/test/src/Starter/OtherDirectives.php���e��� �7vendor/taeluf/lexer/test/src/Starter/StarterGrammar.php���e�B���vendor/taeluf/tester/Docs.md���e�-�y�vendor/taeluf/tester/LICENSE'��e'�:[�vendor/taeluf/tester/README.md���e�*i���vendor/taeluf/tester/Status.mdo��eo6�� vendor/taeluf/tester/bin/phptest���e�ޏ��"vendor/taeluf/tester/composer.json���e��yg��"vendor/taeluf/tester/composer.lockp��epHCm�'vendor/taeluf/tester/config/scrawl.json���e�b�!�#vendor/taeluf/tester/doc/History.md��e�Y樤"vendor/taeluf/tester/doc/README.md���e�*i���&vendor/taeluf/tester/doc/api/README.md���e�����<vendor/taeluf/tester/doc/api/src/BackwardCompatTester.php.md��eFz�3vendor/taeluf/tester/doc/api/src/CurlBrowser.php.mdT��eTȍ��8vendor/taeluf/tester/doc/api/src/ExceptionCatcher.php.md
��e
�~,�2vendor/taeluf/tester/doc/api/src/FakeServer.php.md��eI^�.vendor/taeluf/tester/doc/api/src/Runner.php.md���e��ʶ�.vendor/taeluf/tester/doc/api/src/Tester.php.md���e�0����/vendor/taeluf/tester/doc/api/src/Utility.php.mdo��eo~s��/vendor/taeluf/tester/doc/api/test/Tester.php.md��eL�-�>vendor/taeluf/tester/doc/api/test/input/Runner/run/Test.php.md���e��~�;�4vendor/taeluf/tester/doc/api/test/run/Browser.php.md���e�%�!�4vendor/taeluf/tester/doc/api/test/run/Compare.php.mdK��eK�����7vendor/taeluf/tester/doc/api/test/run/Exceptions.php.mdE��eE�$�3vendor/taeluf/tester/doc/api/test/run/Runner.php.md��enk:Z�3vendor/taeluf/tester/doc/api/test/run/Server.php.md���e���^�*vendor/taeluf/tester/docsrc/History.src.mdp��ep�D�ؤ)vendor/taeluf/tester/docsrc/README.src.mdu��eu�;a�1vendor/taeluf/tester/src/BackwardCompatTester.php���e�bq��(vendor/taeluf/tester/src/CurlBrowser.php0��e0,�I�-vendor/taeluf/tester/src/ExceptionCatcher.php���e�B�V��'vendor/taeluf/tester/src/FakeServer.phpB��eB�?Aa�#vendor/taeluf/tester/src/Runner.phpQ4��eQ4+N��#vendor/taeluf/tester/src/Tester.phpi$��ei$Ո��.vendor/taeluf/tester/src/Tester/Assertions.php�1��e�1��!�.vendor/taeluf/tester/src/Tester/Databasing.php���e���,¤.vendor/taeluf/tester/src/Tester/Exceptions.php���e�q����)vendor/taeluf/tester/src/Tester/Other.phpb
��eb
��*vendor/taeluf/tester/src/Tester/Server.php~#��e~#�8�a�-vendor/taeluf/tester/src/Tester/Utilities.php���e����$vendor/taeluf/tester/src/Utility.phpq
��eq
�K��&vendor/taeluf/tester/src/defaults.jsonr��er�L���*vendor/taeluf/tester/src/mime_type_map.php�X��e�Xez
��,vendor/taeluf/tester/test/Server/deliver.php��e��Y�-vendor/taeluf/tester/test/Server1/deliver.php ��e ��e��-vendor/taeluf/tester/test/Server2/deliver.php ��e gjо�*vendor/taeluf/tester/test/TestResults.htmlo��eo�٨�$vendor/taeluf/tester/test/Tester.phpw��ewu4%�'vendor/taeluf/tester/test/bootstrap.php<��e<giA�%vendor/taeluf/tester/test/config.jsonM��eM�Wڃ�0vendor/taeluf/tester/test/input/Browser/file.txt
��e
�7�3vendor/taeluf/tester/test/input/Compare/Compare.php ��e =���3vendor/taeluf/tester/test/input/Compare/Compare.txt-��e-�p$�7vendor/taeluf/tester/test/input/Runner/TestResults.html���e���N�2vendor/taeluf/tester/test/input/Runner/config.json6��e69�1#�3vendor/taeluf/tester/test/input/Runner/run/Test.php��e�wfg�/vendor/taeluf/tester/test/input/test-upload.txt!��e!�o�)vendor/taeluf/tester/test/run/Browser.php��e�wbϤ)vendor/taeluf/tester/test/run/Compare.php5	��e5	�v�,vendor/taeluf/tester/test/run/Exceptions.phpM��eM��M��(vendor/taeluf/tester/test/run/Runner.php��eZ��Ȥ(vendor/taeluf/tester/test/run/Server.php(��e(�6c�$vendor/taeluf/util/code/FormSpam.php���e�����%vendor/taeluf/util/code/HoneyForm.phpa��eah���� vendor/taeluf/util/code/Util.php:��e:$7p�� vendor/taeluf/util/composer.jsonl��el��:� vendor/taeluf/util/composer.lock���e�^6pD�*vendor/taeluf/util/test/Server/deliver.php
��e
O��H�8vendor/taeluf/util/test/Server/public/csrf-test-post.php���e�J~UD�3vendor/taeluf/util/test/Server/public/csrf-test.php���e���?��4vendor/taeluf/util/test/Server/public/honey-form.php���e�5���4vendor/taeluf/util/test/Server/public/honey-post.php���e�+1侤3vendor/taeluf/util/test/Server/public/spam-form.php-��e-�ᚤ3vendor/taeluf/util/test/Server/public/spam-post.php���e���U �)vendor/taeluf/util/test/bin/get_class.php���e��7,��%vendor/taeluf/util/test/bootstrap.php<��e<giA�#vendor/taeluf/util/test/config.json
��e
�5�u�.vendor/taeluf/util/test/input/ClassExtends.phps��es���y�;vendor/taeluf/util/test/input/ClassExtendsAndImplements.php���e�A��*�Fvendor/taeluf/util/test/input/ClassExtendsAndImplementsNoNamespace.php���e��h�ؤ1vendor/taeluf/util/test/input/ClassImplements.php���e��첤:vendor/taeluf/util/test/input/ClassImplementsInterface.phpI��eI,Dn�/vendor/taeluf/util/test/input/ClassOnlyTest.phpC��eCvjG�9vendor/taeluf/util/test/input/ClassWithFunctionBefore.php��e�p٧�4vendor/taeluf/util/test/input/ClassWithNamespace.phpb��eb�Sk��.vendor/taeluf/util/test/input/ClassWithUse.php���e���!פ1vendor/taeluf/util/test/input/FailingClassOne.php
��e
���Z�0vendor/taeluf/util/test/input/VeryLargeClass.phpaC��eaC���X�+vendor/taeluf/util/test/run/ClassFinder.phpV��eV�1d��$vendor/taeluf/util/test/run/Csrf.phpl��el��<�(vendor/taeluf/util/test/run/FormSpam.phpH	��eH	٪6w�(vendor/taeluf/util/test/run/Honeypot.php���e�
�;Ҥ&vendor/taeluf/util/test/src/Tester.php���e�n�/-�<?php

if (Phar::running()==''){

// if global phptest is called & phptest is also installed to the current package via composer
// then only run the package-level install
$vendor_install = getcwd().'/vendor/bin/scrawl';
//vendor_install_2 accounts for the composer update that stopped symlinking & started include-ing the target bin script
$vendor_install2 = getcwd().'/vendor/taeluf/code-scrawl/bin/scrawl';
if (file_exists($vendor_install)
    &&realpath(__FILE__)!=realpath($vendor_install)
    &&realpath(__FILE__)!=realpath($vendor_install2)
){
    $args = array_slice($argv,1);
    $args = array_filter($args, function($v){
        return '"'.addslashes($v).'"';
    });
    $cmd = "$vendor_install ". implode(' ',$args);
    // because composer started using an include() instead of symlink, the #!/shebang line was occuring before `namespace Composer` & causing errors
    // so now we use `passthru` here to execute the vendor script rather than include it
    passthru("$vendor_install ". implode(' ',$args));
    return;
}

// require() the current package's autoloader
$cwd_autoload = getcwd().'/vendor/autoload.php';
if (!is_file($cwd_autoload)){
    echo "\n\nAutoloader file '$cwd_autoload' not found. ";
} else {
    require($cwd_autoload);
}

//require own global autoloader
$own_global_autoload = dirname(__DIR__).'/vendor/autoload.php';
if (is_file($own_global_autoload)&&realpath($cwd_autoload)!=realpath($own_global_autoload)){
    require($own_global_autoload);
}

} else {
    require(__DIR__.'/../vendor/autoload.php');
}

$dir = getcwd();


$cli = new \Tlf\Cli();
$cli->load_inputs(json_decode(file_get_contents(dirname(__DIR__).'/src/defaults.json'),true));

if (is_file($config=$dir.'/.config/scrawl.json')
    ||is_file($config=$dir.'/scrawl.json')
){
    $cli->load_inputs(json_decode(file_get_contents($config),true));
} else if (is_file($config=$dir.'/.docsrc/config.json')){
    $cli->load_inputs(json_decode(file_get_contents($config),true));
} else if (is_file($config=$dir.'/config/scrawl.json')){
    $cli->load_inputs(json_decode(file_get_contents($config),true));
}

$cli->load_stdin();

if (!isset($cli->args['dir.root']))$cli->args['dir.root'] = getcwd();



/////////
// backward compatability config changes
/////////
# old_config_name becomes new_config_name
# dir.code becomes dir.scan
if (isset($cli->args['dir.code']) && !isset($cli->args['dir.scan'])){
    $cli->args['dir.scan'] = $cli->args['dir.code'];
}
unset($cli->args['dir.code']);
# dir.template becomes dir.src
if (isset($cli->args['dir.template']) && !isset($cli->args['dir.src'])){
    $cli->args['dir.src'] = $cli->args['dir.template'];
}
unset($cli->args['dir.template']);
# dir.template_files becomes template.dirs 
if (isset($cli->args['dir.template_files']) && !isset($cli->args['template.dirs'])){
    $cli->args['template.dirs'] = $cli->args['dir.template_files'];
}
unset($cli->args['dir.template_files']);

# convert template.dirs from string to array
if (isset($cli->args['template.dirs'])&&is_string($cli->args['template.dirs'])){
    $cli->args['template.dirs'] = [$cli->args['template.dirs']];
}

/////////
// prepend `dir.root` to these path configs
/////////
$root_prefix = ['dir.src', 'dir.docs', 'template.dirs', 'file.bootstrap'];
foreach ($root_prefix as $key){
    $arg = $cli->args[$key] ?? null;
    if ($arg==null)continue;
    if (is_array($arg)){
        $cli->args[$key] = array_map(function($path) use ($cli){
            return $cli->args['dir.root'].'/'.$path;
        },$cli->args[$key]);
    } else {
        $cli->args[$key] = $cli->args['dir.root'].'/'.$arg;
    }
}


////////
// init scrawl & run it
////////
$scrawl = new \Tlf\Scrawl($cli->args);


$cli->load_command('main', [$scrawl, 'run'], "Generate Documentation");

/**
 * Get absolute path to the generated documentation file of a code file.
 *
 * @usage `scrawl get_doc_path "/absolute/path.php"
 * @arg absolute path to document
 */
$cli->load_command('get_doc_path', [$scrawl, 'get_doc_path'], "Get absolute path to the generated documentation file of a code file.");
$cli->load_command('get_doc_src_path', [$scrawl, 'get_doc_source_path'], "Get absolute path to the Editable .src.md file of a .md file.");
// $cli->load_command('init', [$scrawl, 'run_init']);

// $runner->backward_compatability();
return $cli->execute();#!/usr/bin/env bash
# MUST BE RUN FROM PROJECT ROOT
#


if [[ ! -d build ]];then
    mkdir build
fi

if [[ ! -f "build/phar-composer-1.4.0.phar" ]]; then
    phar_composer_url="https://github.com/clue/phar-composer/releases/download/v1.4.0/phar-composer-1.4.0.phar"
    if [[ "$1" == "--build-phar" ]];then 
        answer="y";
    else
        read -p \
        "
        phar-composer is not installed. 
        Download from $phar_composer_url? 
        (y/n)" \
        answer
    fi

    if [[ "$answer" == "y" || "$answer" == "Y" ]];then
        cd build;
        curl -JOL $phar_composer_url 
        cd ..;
    else
        echo "Can't create phar without installing phar-composer. Try again."
        exit
    fi

fi

if [[ -f build/scrawl.phar ]];then
    rm build/scrawl.phar
fi
php -d phar.readonly=0 build/phar-composer-1.4.0.phar build "$(pwd)/"
git_hash="git rev-parse --short HEAD"
mv code-scrawl.phar "build/scrawl.phar"

echo "

    bin/scrawl.phar created

"
#!/usr/bin/env bash

read -p "Be sure all changes are stashed or committed before building [enter] tocontinue, [ctrl+c] to exit."

cur_branch="$(git rev-parse --abbrev-ref HEAD)"

feature_version="0.8"
full_version="0.8.2"

new_branch="build-$full_version"
git branch --delete --force $new_branch
git checkout -B $new_branch

rm -rf .cache/
mkdir .cache

composer install
bin/build-phar

mv build/scrawl.phar bin/scrawl.phar
if [[ ! -f bin/scrawl.phar ]];then
    echo "Failed to create bin/scrawl.phar"
    exit 2;
fi

git add bin/scrawl.phar
git commit -m "build scrawl.phar & git tag it"
git tag -a "$full_version"
git push origin "$full_version"

git checkout "$cur_branch"
git branch --delete --force "$new_branch"

# An increase in each section of the version means the following:
# (Idk if this is true, just an idea, probably not the best place to leave this note. but here it is)
# BackwardCompatibilityBreaks.FeatureAdded.BugFixed.OtherChange
# BackwCompat.Feature.Bug.Other
# Except 0.X.X is 0.BackwardCompatibilityBreaks.AnyCommit
<?php

namespace Tlf\Scrawl\FileExt;

/**
 * Export docblock content above `@export(key)`
 * @featured
 */
class ExportDocBlock {

    protected $regs = [
        'export.key' => '/\@export\(([^\)]*)\)/',
        'Exports' => '/((?:.|\n)*) *(\@export.*)/',
    ];

    /**
     * get an array of docblocks
     * @return array of docblocks, like `[0=>['raw'=>'/*...', 'clean'=>'...'], 1=>...]`
     */
    public function get_docblocks(string $str): array{
        $blocks = \Tlf\Scrawl\Utility\DocBlock::extractBlocks($str);
        return $blocks;
    }

    /**
     * get an array of exported text
     * @param $docblocks Array of docblocks. @see(get_docblocks())
     */
    public function get_exports(array $docblocks){
        $exports = [];
        foreach ($docblocks as $db){
            
            $comment = \Tlf\Scrawl\Utility\Main::trimTextBlock($db->clean);
            $reg = $this->regs['Exports'];
            preg_match($reg, $comment, $matches);

            $exported = \Tlf\Scrawl\Utility\Main::trimTextBlock($matches[1]);

            $key_portion = $matches[2];
            preg_match($this->regs['export.key'], $key_portion, $key_matches);
            $key = $key_matches[1];
            $exports[$key] = $exported;
        }

        return $exports;
    }

}
<?php

namespace Tlf\Scrawl\FileExt;

/**
 * Export code between `// @export_start(key)` and `// @export_end(key)`
 * @featured
 */
class ExportStartEnd {


    protected $regs = [
        'exports'=> 
            //For this regex: $1 is the key, $2 is the code, $3 is the @export_end line
            '/\ *(?:\/\/|\#)\ *@export_start\(([^\)]*)\)((?:.|\r|\n)+)\ *(?:\/\/|\#)\ *(@export_end\(\1\))/',
    ];

    public function __construct(){}

    public function get_exports($str){
        
        preg_match_all($this->regs['exports'], $str, $matches, PREG_SET_ORDER);
        // print_r($matches);

        $exports = [];
        foreach ($matches as $index=>$m){
            $exports[$m[1]] = \Tlf\Scrawl\Utility\Main::trimTextBlock($m[2]);
        }

        return $exports;
    }

}
<?php

namespace Tlf\Scrawl\Ext;

class Main {

    public function copy_readme($scrawl){
        $content = $scrawl->read_file('README.md');
        $scrawl->write_doc('README.md', $content);
    }

    // public function write_exports_list(){
    //     // I'm not planning to re-implement this ... though i am leaving around the old code in case i change my mind
    // }

}

<?php

namespace Tlf\Scrawl\FileExt;

/**
 * Integrate the lexer for PHP files
 */
class Php {

    public \Tlf\Scrawl $scrawl;

    public function __construct(\Tlf\Scrawl $scrawl){
        $this->scrawl = $scrawl;
    }


    public function get_all_classes(){
        $asts = $this->scrawl->get_group('ast');
        $classes = [];
        foreach ($asts as $k=>$a){
            var_dump($k);
            if (substr($k,0,6)!='class.')continue;
            $classes[$a['fqn']] = $a;
        }

        return $classes;
    }

    public function set_ast(array $ast){
        // set class asts
        $classes = array_merge($ast['class']??[], $ast['namespace']['class']??[]);
        foreach ($classes as $c){
            $this->scrawl->set('ast','class.'.$c['name'], $c);
        }

        // set file asts
        foreach ($ast as $a){
            // if ($a['type']=='file')
        }

    }

    /**
     * Parsed `$str` into an ast (using the Lexer)
     * @param $str a string to parse
     * @return array ast
     */
    public function parse_str(string $str): array{

        $lexer = new \Tlf\Lexer();
        // $lexer->addGrammar(new \Tlf\Lexer\PhpGrammar());
        
        $ast = new \Tlf\Lexer\Ast('file');
        $phpGram = new \Tlf\Lexer\PhpGrammar();
        $lexer = new \Tlf\Lexer();
        $lexer->debug = false;
        $lexer->addGrammar($phpGram);

        // the first directive we're listening for
        $lexer->addDirective($phpGram->getDirectives(':php_open')['php_open']);

        ob_start();
        // runs the lexer with $ast as the head
        $ast = $lexer->lex($str, $ast);
        ob_end_clean();

        return $ast->getTree();
    }

    /**
     * Parsed `$str` into an ast (using the Lexer)
     *
     * @param $file_path a relative file path to parse (relative to dir.root)
     * @return array ast
     */
    public function parse_file(string $file_path): array {

        $lexer = new \Tlf\Lexer();
        // $lexer->addGrammar(new \Tlf\Lexer\PhpGrammar());

        $abs_path = $this->scrawl->dir_root.'/'.$file_path;
        
        $phpGram = new \Tlf\Lexer\PhpGrammar();
        $lexer = new \Tlf\Lexer();
        $lexer->debug = false;
        $lexer->addGrammar($phpGram);

        // the first directive we're listening for
        $lexer->addDirective($phpGram->getDirectives(':php_open')['php_open']);

        ob_start();
        // runs the lexer with $ast as the head
        $ast = $lexer->lexFile($abs_path);
        ob_end_clean();

        return $ast->getTree();
    }


    /**
     * use the ast to create docs using the classList template
     *
     * @return array of files like `['rel/path'=>'file content']`
     */
    public function make_docs(array $ast){
        $files = [];

        $classes = $ast['class'] ?? $ast['namespace']['class'] ?? [];;
        foreach ($classes as $class){
            $out = $this->scrawl->get_template('ast/class', [null, $class, null]);
            $path = $class['fqn'];
            $path = str_replace('\\','/', $path).'.md';
            $files['class/'.$path] = $out;
        }

        $traits = $ast['trait'] ?? $ast['namespace']['trait'] ?? [];;
        foreach ($traits as $trait){
            $out = $this->scrawl->get_template('ast/class', [null, $trait, null]);
            $path = $trait['fqn'];
            $path = str_replace('\\','/', $path).'.md';
            $files['trait/'.$path] = $out;
        }

        return $files;
    }
}
<?php

namespace Tlf\Scrawl\Ext\MdVerb;

class Ast {

    public \Tlf\Scrawl $scrawl;

    public function __construct($scrawl){
        $this->scrawl = $scrawl;
    }

    public function get_markdown($key, $template='ast/default'){
        $value = $this->get_ast($key);
        $template = $this->scrawl->get_template($template, [$key, $value, $this]);
        return $template;
    }

    /**
     * @param $key a dotproperty like `class.ClassName.methods.MethodName.docblock.description`
     * @param $length the number of dots in the dotproperty to traverse. -1 means all
     */
    public function get_ast(string $key, int $length=-1){
        $parts = explode('.',$key);
        if ($length!=-1){
            $parts = array_slice($parts, 0,$length);
        }
        $group = array_shift($parts);
        $class = array_shift($parts);
        $ast = $this->scrawl->get('ast', $group.'.'.$class);

        $stack = $group.'.'.$class;
        $next = $ast;
        foreach ($parts as $p){
            $current = $next;
            $stack .= '.'.$p;

            // echo "\n\n$stack";
            if (!isset($current[$p])&&is_array($current)){
                foreach ($current as $i=>$item){
                    if (!is_numeric($i))continue;
                    // echo "\n\n".$p."::";
                    // echo $item['name']."\n\n";
                    if ($item['name']==$p){
                        $next = $item;
                        continue 2;
                    }
                }
                print_r($current);
                echo "\n\nFailed at ".$stack;
                echo "\n\nsomething went wrong\n\n";
                exit;
            } else if (!isset($current[$p])){
                echo "\n\ncan't get next item\n\n";
                exit;
            }

            $next = $current[$p];
        }

        // exit;
        return $next;
    }

    public function getVerbs(): array{
        return [
            'ast'=>'verbAst', //alias for @ast_class()
            'classMethods'=>'getClassMethodsTemplate',
            'ast_class'=> 'getAstClassInfo',
        ];
    }

    /**
     *
     * @param $fqn The fully qualified name, like a class name or function with its namespace
     * @param $dotProperty For class, something like 'methods.methodName.docblock' to get a docblock for the given class. 
     *
     * @example @ast(\Tlf\Scrawl\Ext\MdVerb\Ast, methods.getAstClassInfo.docblock)
     * @mdverb ast
     *
     */
    public function getAstClassInfo(array $info, string $fqn, string $dotProperty){
        // @ast(class,Phad\Test\Documentation,methods.testWriteAView.docblock)
        
        $class = $this->scrawl->getOutput('astClass', $fqn);

        // var_dump(array_keys($this->scrawl->getOutputs('astClass')));

        if ($class == 'null') return "class '$fqn' not found in ast.";
    


        $propStack = explode('.', $dotProperty);

        $head = $class;
        if (!is_array($head)){
            $file = $info['file']->path;
            // $this->scrawl->error('@ast or @ast_class in '.$file,'requires "astClass" output for fqn "'.$fqn.'" to be an array, but a '. gettype($class).' was returned.');
            $this->scrawl->error("@ast($fqn, $dotProperty) failed", 'in '.$file);
            return "@ast($fqn) failed";
        }
        foreach ($propStack as $prop){
            if ($prop=='*'){
                return print_r($head,true);
            }
            
            if (!isset($head[$prop])){
                $options =  [];
                foreach ($head as $key=>$value){
                    if (is_numeric($key) && ($value['name']??null)==$prop){
                        $head = $head[$key];
                        continue 2;
                    } else if (is_numeric($key) && isset($value['name'])){
                        $options[] = $value['name'];
                    }
                }
                $options = array_merge($options, array_keys($head));
                $msg = "Cannot find '$prop' part of '$dotProperty' on '$fqn'. You may try one of: ". implode(", ", $options);
                $this->scrawl->error('@ast or @ast_class', $msg);
                return $msg;
            }
            $head = $head[$prop];
        }

        if (is_array($head)){
            if (isset($head['body']))return $head['body'];
            else if (isset($head['description']))return $head['description'];
            else if (isset($head['src']))return $head['src'];
            $msg="Found an array for '$dotProperty' on '$fqn' with keys: ".implode(", ", array_keys($head));
            $this->scrawl->error('@ast or @ast_class', $msg);
            return $msg;
        }

        return $head;
    }

    /**
     *
     * @return string replacement
     */
    public function verbAst($info, $className, $dotProperty){

        //
        // This method not currently functional. Ugggh!!!
        //

        // $parts = explode('.', $classDotThing);
        // $class = array_shift($parts);
        // return $this->getAstClassInfo($info, $class, 'method.'.implode('.',$parts));
        return $this->getAstClassInfo($info, $className, $dotProperty);
        // $key = $class;
        // var_dump($key);
        // $output = $this->scrawl->getOutput('api',$key);
//
        // if (trim($output)=='')return "--ast '${class}' not found--";
//
        // return $output;
    }

    public function getClassMethodsTemplate($verb, $argListStr, $line){
        if ($verb!='classMethods')return;

        $args = explode(',', $argListStr);

        $className = $args[0];
        $visibility = '*';
        if (isset($args[1])){
            $visibility = trim($args[1]);
        }
        
        $class = $this->scrawl->getOutput('astClass', $className);

        $template = dirname(__DIR__,2).'/Template/classMethods.md.php';
        ob_start();
        require($template);
        $final = ob_get_clean();
        return $final;
    }

}
<?php

namespace Tlf\Scrawl\Ext\MdVerb;

class MainVerbs {

    /**
     * a scrawl instance
     */
    public \Tlf\Scrawl $scrawl;

    public function __construct(\Tlf\Scrawl $scrawl){
        $this->scrawl = $scrawl;
    }

    /**
     * add callbacks to `$md_ext->handlers`
     */
    public function setup_handlers(\Tlf\Scrawl\Ext\MdVerbs $md_ext){
        $handlers = [
            'import'=>'at_import',
            'file' => 'at_file',
            'template'=> 'at_template',
            'easy_link'=> 'at_easy_link',
            'hard_link'=> 'at_hard_link',
            'see_file'=> 'at_see_file',
        ];
        foreach ($handlers as $verb=>$func_name){
            $md_ext->handlers[$verb] = [$this, $func_name];
        }
    }


    public function at_template(string $templateName, ...$templateArgs){
        return $this->scrawl->get_template($templateName, $templateArgs);
    }

    /**
     * Import something previously exported with @export or @export_start/@export_end
     * @usage @import(Namespace.Key)
     * @output whatever was exported by @export or @export_start/_end
     */
    public function at_import(string $key){
        $output = $this->scrawl->get('export',$key);

        if ($output===null){
            $this->scrawl->warn('@import', '@import('.$key.') failed');
            $replacement = '# Import key "'.$key.'" not found.';
        } else {
            $replacement = $output;
        }
        return $replacement;
    }

    /**
     *
     * @usage @file(rel/path/to/file.ext)
     * @output the file's content, `trim`med.
     */
    public function at_file(string $relFilePath){
        $file = $this->scrawl->dir_root.'/'.$relFilePath;

        if (!is_file($file)){
            $this->scrawl->warn('@file', "@file($relFilePath) failed. File does not exist.");
            return "'$file' is not a file.";
        }

        return trim(file_get_contents($file));
    }

    /**
     *
     * @usage @see_file(relative/file/path)
     * @output `[relative/file/path](urlPath)`
     */
    public function at_see_file(string $relFilePath){
        $path = $this->scrawl->dir_root.'/'.$relFilePath;
        if (!is_file($path) && !is_dir($path)){
            $this->scrawl->warn("@see_file","@see_file($relFilePath): File does not exist");
        }
        $urlPath = $relFilePath;
        if ($urlPath[0]!='/')$urlPath = '/'.$urlPath;
        $link = '['.$relFilePath.']('.$urlPath.')';
        return $link;
    }


    /** just returns a regular markdown link. In future, may check validity of link or do some kind of logging 
     *
     * @usage @hard_link(https://url.com, LinkName)
     * @output [LinkName](https://url.com)
     */
    public function at_hard_link(string $url, string $name=null){
        if ($name==null) $name = $url;
        return '['.$name.']('.$url.')';
    }

    /**
     *
     *
     * @usage @easy_link(twitter, TaelufDev)
     * @output [TaelufDef](https://twitter.com/TaelufDev)
     * @todo support a third param 'LinkName' so the target and link name need not be identical
     */ 
    public function at_easy_link(string $service, string $target){
        $sites = [
            'twitter'=>'https://twitter.com/',
            'gitlab'=>'https://gitlab.com/',
            'github'=>'https://github.com/',
            'facebook'=>'https://facebook.com/',
            'tlf'=>'https://tluf.me/',
        ];

        $host = $sites[strtolower($service)] ?? null;
        if ($host==null){
            $this->scrawl->warn('@easy_link', "@easy_link($service,$target): Service '$service' is not valid. Options are "
                .implode(', ', array_keys($sites))
            );
            return "--service '$service' not found--";
        }
        $url = $host.$target;
        $linkName = $target;
        $mdLink = "[$linkName]($url)";
        return $mdLink;
    }

}
<?php

namespace Tlf\Scrawl\Ext;

/**
 * Runs `@mdverb` extensions, enabling special callbacks for `@verb()`s in `.src.md` files
 */
class MdVerbs { 

    protected $regs = [
        'verb' =>'/(?<!\\\\)\@([a-zA-Z_]+)\(([^\)]*)\)/m',
    ];

    /** `key=>value` array of verb handlers. value should be callable. key is the verb. */
    public $handlers = [];

    /**
     * Get all `@verbs(arg1, arg2)` 
     * @return array of verb arrays ... the verb array contains `string src`, `string verb`, and `array args`
     */
    public function get_verbs(string $str): array {
        $reg = $this->regs['verb'];
        preg_match_all($reg, $str, $matches, PREG_SET_ORDER);

        $verbs = [];
        foreach ($matches as $m){
            $verb = [];
            $verb['src'] = $m[0];
            $verb['verb'] = $m[1];
            // `$m[2]` is like `arg1, arg2, arg3`, so i expode on `,` & `trim` with array_map
            $verb['args'] = 
                array_map('trim',
                    explode(',',$m[2])
                );
            $verbs[] = $verb;
        }
        return $verbs;
    }

    /**
     * Get all verbs, execute them, and replace them within the doc
     * @param $doc a documentation file's content
     */
    public function replace_all_verbs(string $doc): string{
        $verbs = $this->get_verbs($doc);

        $out = $doc;
        foreach ($verbs as $v){
            $replacement = $this->run_verb($v['src'], $v['verb'], $v['args']);
            $out = str_replace($v['src'], $replacement, $out);
        }
        return $out;
    }

    /**
     * execute a verb and get its output 
     * @return string that should replace the `@verb()` call
     */
    public function run_verb(string $src, string $verb, array $args): string {
        if (!isset($this->handlers[$verb])){
            //@todo scrawl->warn()
            return '--Verb `@'.$verb.'()` has no handler--';
        }
        $handler = $this->handlers[$verb];
        try {
            $ret = $handler(...$args);
        } catch (\ArgumentCountError $e){
            // @TODO need to use scrawl->warn()
            //
            echo "\n\nARGUMENT COUNT ERROR ... error reporting incomplete ... see code/Ext/MdVerbs.php";
            echo "\n\n";
            throw $e;

//
            // return '';
            // $class = get_class($callable[0]);
            // $method = $callable[1];
            // echo "\n\n";
            // echo "\nCannot call $class->$method() becuase of an argument count error.";
//
            // echo "\n\n";
            // echo "Error caused by: \n";
            // $info = (array)$info;
            // $info['file'] = (array)$info['file'];
            // $info['file']['content'] = '--content is removed from var dump for readability--';
            // print_r($info);
//
            // echo "\n\n";
            // throw $e;
        }

        if (!is_string($ret)){

            $args_str = implode(', ', $args);
            $type = gettype($ret);
            throw new \TypeError("Verbs must return strings. @$verb($args_str) returned $type");
        }
        return $ret;
    }

}
<?php
/**
 * @param $args[0] the key pointing to the ast, must begin with `class.ClassName`
 * @param $args[1] array class ast
 * @param $args[2] is the AstVerb class instance
 */
$Class = $class = $args[1];


// echo "\n\n\n-----------\n\n";
// var_dump($Class);
// exit;

if ($Class['type']=='class')$type = 'class';
else $type = 'trait';

$class_name = $class['fqn'] ?? $class['name'];
?>
# <?= $type .' '. $class_name ?>
<?="\n".($Class['docblock']['description']??'')?>



## Constants
<?php
foreach ($Class['const']??[] as $constant){
    $def = $constant['declaration'];
    $descript = $constant['docblock']['description']??'';
    echo "- `${def}` ${descript}\n";
}

?>

## Properties
<?php
foreach ($Class['properties']??[] as $prop){
    $def = $prop['declaration'];
    $descript = $prop['docblock']['description']??'';
    echo "- `${def}` ${descript}\n";
}

?>

## Methods 
<?php
foreach ($Class['methods']??[] as $method){
    // var_dump($method);
    // exit;
    $def = $method['declaration'];
    // $descript = $method['description'];
    $descript = $method['docblock']['description']??'';
    // var_dump($method['docblock']);
    // if (is_array($method['docblock']));
    // exit;
    echo "- `${def}` ${descript}\n";
}

?>

<?php
// static props/functions are not yet separated out by the lexer
return;

?>

## Static Properties 
<?php
foreach ($Class['staticProps']??[] as $prop){
    $def = $prop['definition'];
    $descript = $prop['description'];
    echo "- `${def}` ${descript}\n";
}

?>

## Static functions
<?php
foreach ($Class['staticFunctions']??[] as $func){
    $def = $func['definition'];
    $descript = $func['description'];
    echo "- `${def}` ${descript}\n";
}

<?php
/**
 * @param $args[0] the key pointing to the ast, must begin with `class.ClassName`
 * @param $args[1] array class ast
 * @param $args[2] is the AstVerb class instance
 */
$class = $args[1];

$instanceArg = '$'.lcfirst($class['name']);
$visibility = '*';

foreach ($class['methods'] as $m):

    // print_r($m);
// exit;
    $declare = substr($m['declaration'], 0, strpos($m['declaration'], '('));
    $declareParts = explode(' ', $declare);
    if ($visibility!=='*'){
        if (!in_array($visibility, $declareParts))continue;
    }
    $isStatic = false;
    if (in_array('static',$declareParts))$isStatic = true;


    $pos = strpos($m['declaration'],$m['name']);
    $cleanDefinition = substr($m['declaration'],$pos);
    // $pos = strpos($cleanDefinition, '{');
    // $cleanDefinition = trim(substr($cleanDefinition,0,$pos));

    //special declaration conversions:
    // static should be ClassName::method(...)
    // __construct should be new ClassName(...)
    // other should be $className->method(...)

    if ($m['name']=='__construct'){
        $cleanDefinition = $instanceArg.' = new '.$class['name'].substr($cleanDefinition,strlen('__construct'));
    } else if ($isStatic){
        $cleanDefinition = $class['name'].'::'.$cleanDefinition;
    } else {
        $cleanDefinition = $instanceArg.'->'.$cleanDefinition;
    }


    $description = $m['dockblock']['tip']??$m['docblock']['description']??'';
    $description = str_replace("\n", "\n    ", $description);
?>
- `<?=$cleanDefinition?>`: <?=$description?>

<?php
    foreach ($m['docblock']??[] as $verb=>$text){
        if ($verb=='src'||$verb=='description'||$verb=='type'||$verb=='tip')continue;
        echo "    - `@$verb`: $text\n";
    }
endforeach;

// print_r($class);
<?php
/**
 * @param $args[0] the key pointing to the ast, must begin with `class.ClassName`
 * @param $args[1] string or array ... whatever the key pointed at 
 * @param $args[2] is the AstVerb class instance
 */
$key = $args[0];

if (is_array($args[1])){
    echo "@ast($key) is an array";
} else {
    echo $args[1];
}

<?php
/**
 * @param $args[0] the key pointing to the ast, must begin with `class.ClassName`
 * @param $args[1] array file ast
 * @param $args[2] the AstVerb class instance
 */
$File = $args[1];

?>
# File <?=$File['relPath']?>

## Functions
<?php
foreach ($File['functions'] ??[] as $function){
    $descript = $function['docblock']['tip'] ?? $function['docblock']['description'] ?? '';
    $name = $function['name'];
    echo "- `$name`: $descript\n";
}
<?php
/**
 * @param $args[0] the key pointing to the ast, must begin with `class.ClassName`
 * @param $args[1] a method ast array
 * @param $args[2] is the AstVerb class instance
 */
$key = $args[0];
$method = $args[1];
$ext = $args[2];

$method_name = $method['name'];
$class = $ext->get_ast($key, 2);
$class_name=$class['name'];
?>
# <?=$class_name?>::<?=$method_name?>  
<?=$method['docblock']['description']??'no description';?>

<?php
/**
 * @param $args[0] the name of the executable command
 * @param $args[1] relative path to executable file within the repo
 */
$command=$args[0];
$execFile=$args[1];
$git_clone_url = \Tlf\Scrawl\Utility\Main::getGitCloneUrl();

?>
```bash
pwd="$(pwd)";
command="<?=$command?>"
downloadDir=~/.gitclone
mkdir -p "$downloadDir"
cd "$downloadDir"
git clone <?=$git_clone_url?> ${command} 
echo "alias ${command}=\"${downloadDir}/${command}/<?=$execFile?>\"" >> ~/.bashrc
chmod ug+x "${downloadDir}/${command}/<?=$execFile?>"
cd "$pwd";
source ~/.bashrc
echo "You can now run \`${command}\`"
```
<?php
/**
 * Display composer install instructions for your library
 *
 * @usage `@template(composer_install, vendor/package, ?version)`
 *
 * @param $args[0] package name like `taeluf/code-scrawl`
 * @param $args[1] (optional) branch name ... defaults to current branch
 */


if (!isset($args[0])){
    $this->scrawl->warn("package name was not passed to @template(composer_install, vendor/package)");
    echo "--cannot print composer install instructions because package name was not passed--";
    return;
}
$package = $args[0];
$version = $args[1] ?? $ext->getCurrentBranchForComposer();

?>
```bash
composer require <?=$package.' '.$version?> 
```
or in your `composer.json`
```json
{"require":{ "<?=$package?>": "<?=$version?>"}}
```
<?php

if (!function_exists('get_objects')){

/**
 * Get classes, traits
 * @todo add of interfaces ... anything else?
 * @return `['classes'=>[...$files],'traits'=>[...$asts]]`
 */
function get_objects(\Tlf\Scrawl $scrawl) {
    $objects = [];
    $apis = $scrawl->getOutputs('api');
    // print_r(array_keys($apis));
    // exit;
    foreach ($apis as $key => $file){
        if ($file['type']!='file')continue;
        // ob_start();

        // unset($file['class']);

        // var_dump($scrawl->file);
        // exit;
        $path = substr($file['path'], strlen($scrawl->dir));
        if ($path[0]!='/')$path = '/'.$path;
        foreach ($file['class']??$file['namespace']['class']??[] as $index=>$classAst){
            $classAst['file'] = $path;
            $objects['classes'][$classAst['fqn']??$classAst['name']] = $classAst;
        }
        foreach ($file['trait']??[] as $index=>$traitAst){
            $traitAst['file'] = $path;
            $objects['traits'][$traitAst['fqn']??$traitAst['name']] = $traitAst;
        }
    }

    return $objects;
}
}

$objects = get_objects($this);
?>
# All Classes
Documentation generated by @easy_link(tlf, php/code-scrawl)

<?php
// print_r(array_keys($objects));
foreach ($objects['classes'] as $class):

    // print_r($class);
    $name_path = str_replace('\\','/', $class['fqn']);
?>
## <?=$class['fqn']??$class['name']?>  
<?=$class['docblock']['description'] ?? 'no docblock'?>  
See [<?=$class['name']?>.php](/docs/api<?=$class['file']?>) for more.


<?php
endforeach;

<?php

namespace Tlf\Scrawl\Utility;

/**
 *
 * @featured
 */
class DocBlock {


    public function __construct($rawBlock, $cleanBlock){
        $this->raw = $rawBlock;
        $this->clean = $cleanBlock;
    }

    static protected $regex = [
        // @TODO Make a less strict regex
        'DocBlock./**' => ['/((\/\*\*.*\n)( *\*.*\n)* *\*\/)/'],
        'DocBlock./**.removeBlockOpen' => '/(^\/\*\*)/',
        'DocBlock./**.removeLineOpenAndBlockClose' => '/(\n\s*\* ?\/?)/',
    ];


    static public function DocBlock($name, $match, $nullFile, $info){
        $clean = static::cleanBlock($match[0], null);
        $docBlock = new static($match[0], $clean);


        return $docBlock;
    }

    static public function extractBlocks($fileContent){
        $blocks = \Tlf\Scrawl\Utility\Regex::matchRegexes(static::class, 
                    ['DocBlock'=>static::$regex['DocBlock./**']]
                    , null, $fileContent);

        return $blocks;
    }

    static public function cleanBlock($rawBlock){
        $docBlock = 
            preg_replace(
                [   static::$regex['DocBlock./**.removeBlockOpen'], 
                    static::$regex['DocBlock./**.removeLineOpenAndBlockClose']
                ],
                ["", "\n"],
                $rawBlock
            );
        $docBlock = trim($docBlock);

        $docBlock = Main::trimTextBlock($docBlock);
        
        return $docBlock;

    }

}
<?php

namespace Tlf\Scrawl\Utility;

class Main {

    static protected $classMap=[];

    static protected $isRegistered=false;

    static public function spl_autoload($class){
        $class = '\\'.$class;
        if (!isset(static::$classMap[$class]))return;
        $file = static::$classMap[$class];
        unset(static::$classMap[$class]);
        require($file);
    }
    static public function autoload($dir){
        if (!static::$isRegistered){
            static::$isRegistered = true;
            spl_autoload_register([get_class(), 'spl_autoload']);
            require_once(__DIR__.'/Php.php');
        }
        $files = static::allFilesFromDir($dir, '', ['.php']);
        
        foreach ($files as $f){
            $class = Utility\Php::getClassFromFile($f->path);
            if (trim($class)=='')continue;
            // require_once($f->path);
            static::$classMap[$class] = $f->path;
        }

        // print_r(static::$classMap);
    }
    /** trim a block of text
     */
    static public function trimTextBlock($textBlock){
        $textBlock = static::removeLeftHandPad($textBlock);
        //remove blank lines at beginning
        $textBlock = preg_replace('/^(\s*\n)+/','',$textBlock);
        //remove blank lines at end
        $textBlock = preg_replace('/(\n\s*)+$/','',$textBlock);
        return $textBlock;
    }

    /**
     *  Trim the leading spaces from a block of text
     */
    static public function removeLeftHandPad($textBlock){
        $leftPadList = [];
        $leftPadReg = '/^(\ *)[^\s\n\r]/m';
        preg_match_all($leftPadReg,$textBlock,$leftPadList);

        $shortest = null;
        foreach ($leftPadList[1] as $pad){
            if ($shortest===null
                ||strlen($pad)<strlen($shortest)
            ){
                $shortest = $pad;
            }
        }
        $textUnpadded = preg_replace("/^{$shortest}/m",'',$textBlock);
        return $textUnpadded;
    }

    static public function allFilesFromDir(string $rootDir, string $relDir, array $forExt=[]){
        $dir = $rootDir.'/'.$relDir;
        if (!is_dir($dir)){
            return [];
        }
        $dh = opendir($dir);
        $allFiles = [];
        while ($file=readdir($dh)){
            if ($file=='.'||$file=='..')continue;
            if (is_dir($dir.'/'.$file)){
                $subFiles = self::allFilesFromDir($rootDir, $relDir.'/'.$file,$forExt);
                $allFiles = array_merge($allFiles,$subFiles);
                continue;
            }  
            $include = false;
            if ($forExt===[]||in_array('*', $forExt)){
                $include = true;
            } else {
                foreach ($forExt as $ext){
                    $len = strlen($ext);
                    if (strtolower(substr($file, -$len))===strtolower($ext)){
                        $include = true;
                        break;
                    }
                }
            }
            // $allFiles[] = str_replace('//','/',$dir.'/'.$file);
            if ($include){
                $allFiles[] = new File($rootDir, $relDir.'/'.$file);
            }
        }
        return $allFiles;
    }

    static public function DANGEROUS_removeNonEmptyDirectory($directory){
        $src = $directory;
        $dir = opendir($src);
        while(false !== ( $file = readdir($dir)) ) {
            if (( $file != '.' ) && ( $file != '..' )) {
                $full = $src . '/' . $file;
                if ( is_dir($full) ) {
                    static::DANGEROUS_removeNonEmptyDirectory($full);
                }
                else {
                    unlink($full);
                }
            }
        }
        closedir($dir);
        rmdir($src);
    }



    static public function getCurrentBranchForComposer(){
        $branch = exec("git branch --show-current");
        return $branch.'.x-dev';
    }

    static public function getGitCloneUrl(){
        $url = exec("git config --get remote.origin.url | sed -r 's/.*(\\@|\\/\\/)([^:\\/]*)(\\:|\\/)(.*)\\.git/https:\\/\\/\\2\\/\\4/'");
        $url .= '.git';
        return $url;
    }
}
<?php

namespace Tlf\Scrawl\Utility;

class Regex {


    /**
     *
     */
    static public function matchRegexes($targetObject, $regexArray, File $file=null, $text=null){
        if ($file === null && $text === null)throw new \Exception("Either \$file or \$text must be set");
        if ($text === null)$text = $file->content();

        $ret = [];
        foreach ($regexArray as $name => $regs){
            // echo "\nName:$name\n\n";
            $func = $regs['function'] ?? str_replace(['-','.'], '_', $name);
            unset($regs['function']);
            foreach ($regs as $i => $regex){
                $didMatch = preg_match_all($regex, $text, $matches, PREG_SET_ORDER);
                if ($didMatch){
                    //@export_start(Regex.infoArray)
                    $info = [
                        'matchList'=>$matches, // Array of all matches
                        'lineStart' => -1, // (not implemented, @TODO) Line in file/text that your match starts on
                        'lineEnd' => -1,   // (not implemented, @TODO) Line in file/text that your match ends on
                        'text' => $text,   //
                        'regIndex' => null,
                    ];
                    //@export_end(Regex.infoArray))
                    foreach ($matches as $key => $match){
                        $info['regIndex']=$key;
                        $lineStart = 0;
                        $lineEnd = 0;
                        $info['lineStart'] = $lineStart;
                        $info['lineEnd'] = $lineEnd;
                        $ret[] = call_user_func([$targetObject, $func], $name, $match, $file, $info);
                    }
                }
            }
        }
        return $ret;
    }
}
<?php

namespace Tlf;

class Scrawl {



    /** array for get/set */
    public array $stuff = [];

    public array $extensions = [
        'code'=>[],
    ];

    /** absolute path to your documentation dir */
    public ?string $dir_docs = null;

    /** absolute path to the root of your project */
    public ?string $dir_root = null;

    public array $template_dirs = [

    ];

    /** if true, append two spaces to every line so all new lines are parsed as new lines */
    public bool $markdown_preserveNewLines = true;

    /** if true, add an html comment to md docs saying not to edit directly */
    public bool $markdown_prependGenNotice = true;

    /**
     * @parma $options `key=>value` array to set properties
     */
    public function __construct(array $options=[]){
        $this->template_dirs[] = __DIR__.'/Template/';
        $this->options = $options;
        foreach ($this->options as $k=>$o){
            $k = str_replace('.','_',$k);
            $this->$k = $o;
        }

    }

    public function get_template(string $name, array $args){

        foreach ($this->template_dirs as $path){
            if (file_exists($file = $path.'/'.$name.'.md.php')){}
            else if (file_exists($file=$path.'/'.$name.'.php')){}
            else continue;
            $out = (function(array $args, string $file) {
                ob_start();
                require($file);
                $out = ob_get_clean();
                return $out;
            })($args, $file);
            return $out;
        }
        
        $this->warn("@template", $msg="Template '$name' does not exist.");
        return $msg;
    }

    /**
     * @param $string a string to parse ... template source or file source, idk
     * @param $file_ext a file extension like 'php' or 'md' (to indicate type)
     */
    public function process_str(string $string, string $file_ext){

        $extensions = $this->extensions['file'][$file_ext];

        foreach ($extensions as $ext){
            /**
             * I'm over designing
             * what am i over designing for?
             * i'm trying to make it so extensions are highly customizable
             * like i want to be able to make multiple extensions that handle php files
             * like maybe i want a php file extension that just ... finds all occurences of some particular string ...
             * So i think that's a reasonable goal
             * but then how do i integrate that all together?
             *
             * This one just needs to return an ast ...
             * so then maybe i need an additional extension that handles ASTs ...
             * or i could make the php extension do all the ast processing (getting docblock attributes)
             * which makes sense bc the php extension will produce different ast than any other language-based extension ... or even a diff php extension using a different lexer & ast generator
             *
             * so i probably should just make this do all the things (this being the php extension)
             * 
             * yeah, cuz right now i'm using onSourceFilesDone() to loop over ALL api outputs (which are ast outputs)
             * and generate some docs
             * which like ... yeah ... there's a point for that
             *
             * I think I could just have the extension do it's thing all at once
             * 
             * add a second function that takes in an ast and generates a file?
             *
             * Yeah ... bc that looping code doesn't have any more context
             *
             * I'm just looking for the simplest & most testable implementation
             *
             */
        }

    } 

    public function addExtension(object $ext){
        //something
    }

    public function get(string $group, string $key){
        if (!isset($this->stuff[$group])){
            $this->warn("Group not set", $group);
            return null;
        } else if (!isset($this->stuff[$group][$key])){
            $this->warn("Group.Key not set", "$group.$key");
            return null;
        }
        return $this->stuff[$group][$key];
    }
    public function get_group(string $group){
        if (!isset($this->stuff[$group])){
            $this->warn("Group not set", $group);
            return null;
        }
        return $this->stuff[$group];
    }


    public function set(string $group, string $key, $value){
        $this->stuff[$group][$key] = $value;
    }

    public function parse_str($str, $ext){
        $out = [];
        foreach ($this->extensions['code'][$ext] as $ext){
            $out = $ext->parse_str($str); 
        }
        return $out;
    }

    /**
     * save a file to disk in the documents directory
     */
    public function write_doc(string $rel_path, string $content){
        $content = $this->prepare_md_content($content);
        $rel_path = str_replace('../','/', $rel_path);
        $path = $this->dir_docs.'/'.$rel_path;
        $dir = dirname($path);
        if (!is_dir($dir))mkdir($dir,0755,true);
        if (is_file($path)){
            $this->warn('Overwrite',$rel_path);
        } else {
            $this->good('Write',$rel_path);
        }
        file_put_contents($path, $content);
    }

    /**
     * Read a file from disk, from the project root
     */
    public function read_file(string $rel_path){
        return file_get_contents($this->dir_root.'/'.$rel_path);
    }


    /**
     * Output a message to cli (may do logging later, idk)
     */
    public function report(string $msg){
        echo "\n$msg";
    }

    /**
     * Output a message to cli, header highlighted in red
     */
    public function warn($header, $message){
        echo "\033[0;31m$header:\033[0m $message\033[0;31m\033[0m\n";
    }

    /**
     * Output a message to cli, header highlighted in red
     */
    public function good($header, $message){
        echo "\033[0;32m$header:\033[0m $message\033[0;31m\033[0m\n";
    }

    /** apply small fixes to markdown */
    public function prepare_md_content(string $markdown){

        if ($this->markdown_preserveNewLines){
            $markdown  = str_replace("\n","  \n",$markdown);
        }

        if ($this->markdown_prependGenNotice){
            // @TODO give relative path to source file
            $markdown = "<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  \n".$markdown;
        }
        
        return $markdown;
    }
}
# class Abc
Does nothing

## Constants

## Properties

## Methods 
- `function ghi()` 

test @see_file()
<?php
echo $args[0].'-'.$args[1];

?>
test.txt file
# Readme file, heck
Intro!
<?php

class two {

    /** test docblock for go_2() */
    public function go_2(){
    }

    /** test docblock for test() */
    public function test(){
        //@export_start(Two.test)
        echo "two test";
        //@export_end(Two.test)
    }
}
<?php

class One {

    /** test docblock for go() 
     *
     * @export(One.go)
     */
    public function go(){
    }

    /** test docblock for test_2() */
    public function test_2(){
    }
}
@template(all_classes)
@ast(class.One.methods.go.declaration)
## Readme file
This should copy automatically

@template(php/composer_install, taeluf/code-scrawl)

```php
@file(code/One.php)
```

@template(own_template)

@own_verb(test arg, second arg)

@non_existent_verb(okay)
this is a test template
<?php
/**
 * @param $scrawl instance of `\Tlf\Scrawl`
 */

$scrawl->verb_handlers['own_verb'] = 
    function($arg1, $arg2){
        return $arg1.'--'.$arg2;

    };
{
    "dir.scan": ["code", "test"],
    "template.dirs": ["template"],
    "dir.docs": "../../output/run-cli/docs/",
    "dir.src": "docsrc",
    "file.bootstrap":"scrawl-bootstrap.php",
    "deleteExistingDocs": true,
    "readme.copyFromDocs": true
}
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
## Readme file  
This should copy automatically  
  
```bash  
composer require taeluf/code-scrawl v0.8.x-dev   
```  
or in your `composer.json`  
```json  
{"require":{ "taeluf/code-scrawl": "v0.8.x-dev"}}  
```  
  
  
```php  
<?php  
  
class One {  
  
    /** test docblock for go()   
     *  
     * @export(One.go)  
     */  
    public function go(){  
    }  
  
    /** test docblock for test_2() */  
    public function test_2(){  
    }  
}  
```  
  
this is a test template  
  
  
@own_verb(test arg, second arg)  
  
@non_existent_verb(okay)  
<?php

class two {

    /** test docblock for go_2() */
    public function go_2(){
    }

    /** test docblock for test() */
    public function test(){
        //@export_start(Two.test)
        echo "two test";
        //@export_end(Two.test)
    }
}
<?php

class One {

    /** test docblock for go() 
     *
     * @export(One.go)
     */
    public function go(){
    }

    /** test docblock for test_2() */
    public function test_2(){
    }
}
@template(all_classes)
@ast(class.One.methods.go.declaration)
## Readme file
This should copy automatically

@template(php/composer_install, taeluf/code-scrawl)

```php
@file(code/One.php)
```

@template(own_template)

@own_verb(test arg, second arg)

@non_existent_verb(okay)
this is a test template
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
## Readme file  
This should copy automatically  
  
```bash  
composer require taeluf/code-scrawl v0.8.x-dev   
```  
or in your `composer.json`  
```json  
{"require":{ "taeluf/code-scrawl": "v0.8.x-dev"}}  
```  
  
  
```php  
<?php  
  
class One {  
  
    /** test docblock for go()   
     *  
     * @export(One.go)  
     */  
    public function go(){  
    }  
  
    /** test docblock for test_2() */  
    public function test_2(){  
    }  
}  
```  
  
this is a test template  
  
  
@own_verb(test arg, second arg)  
  
@non_existent_verb(okay)  
<?php

namespace Tlf\Scrawl\Test\Ext;

/**
 * Test regex matching ... Not a great implementation
 */
class AbcExt extends \Tlf\Scrawl\ExtensionType\DefaultExt {

    
    ///////
    // define your regexes
    ///////
    public $regData = [
        'Abc' => 
            //For this regex: $1 is the key, $2 is the code, $3 is the @export_end line
            '/abc/',
    ];

    ///////
    // define a function to handle regex matches
    ///////
    /**
     *
     * @param $info a special info array generated by BetterRegex
     * @param $file a file object. @see onTemplateFileFound()
     */
    public function matchAbc($info, $file){
        //replace the match with '000' because ... examples
        $fixed = str_replace('abc', '000', $info['string']);
        $file->content = str_replace($info['string'], $fixed, $file->content);
    }
    //////
    // Use a hook to invoke regex matching
    // Probably onTemplateFileFound or onSourceFileFound
    //////
    public function onTemplateFileFound($file){
        // in case you only want to run on one file
        if (basename($file->path)!='RegexTest.src.md')return;
        $this->match('Abc',$file, $file);
        $out_file = substr($file->relPath,0,-7).'.md';
        $this->scrawl->setOutput('file', $out_file, $file);
    }

}
<?php

/**
 * A class for doing bird stuff, like flying ...
 */
class Bird {

    public function fly(){
        echo "good";
    }

    public function die(){
        echo "not so good";
    }
}
<?php

/**
 * A class for doing dog stuff, like walking...
 */
class Dog {

    public function fly(){
        echo "can't";
    }

    public function walk(){
        echo "goodboi";
    }
}
# class Tlf\Scrawl\Test\Ext\AbcExt
Test regex matching ... Not a great implementation


## Constants

## Properties
- `public $regData = [
        'Abc' => 
                        '/abc/',
    ];` 

## Methods 
- `public function matchAbc($info, $file)` 
- `public function onTemplateFileFound($file)` 




# class Bird
A class for doing bird stuff, like flying ...


## Constants

## Properties

## Methods 
- `public function fly()` 
- `public function die()` 




# class Dog
A class for doing dog stuff, like walking...


## Constants

## Properties

## Methods 
- `public function fly()` 
- `public function walk()` 




# Readme  
test  
<?php

namespace Tlf\Scrawl\Test;


/**
 * Generates documentation & tests the output
 *
 */
class GeneratedDocs extends \Tlf\Tester {

    public $dir;

    public function prepare(){
        $this->dir = $root = dirname(__DIR__).'/input/Project';
        $readme_file = dirname($root).'/README.md';
        $this->empty_dir($root.'/docs/', true);
        if (is_file($readme_file))unlink($readme_file);

        $args = json_decode(file_get_contents($root.'/.config/scrawl.json'),true);
        $args['noprompt'] = true;
        $scrawl = new \Tlf\Scrawl($root, $args);
        $scrawl->generate_docs(null, $args);

    }

    public function testTemplate(){
        $file = $this->dir.'/docs/Template.md';
        $content = file_get_contents($file);

        $this->compare(
            // 2 spaces added for 'markdown.preserveNewLines' feature
            "## Template Test  "
            ."\none",
            $content
        );
    }

    public function testRegexMatching(){
        $file = $this->dir.'/docs/RegexTest.md';
        $content = file_get_contents($file);
        $this->compare(
            // needs 2 spaces after first line because of "markdown.preserveNewLines" setting
            "000defghijkl  "
            ."\njklghidef000",
            trim($content),
        );
    }

    public function testFilesPresent(){
        $files = [
            'README.md',
            'docs/exports/keys.md',
            'docs/exports/keys.php',
            'docs/README.md',
            'docs/Test.md',
            'docs/RegexTest.md',
        ];

        foreach ($files as $f){
            $this->is_file($this->dir.'/'.$f);
        }
    }

}
<?php

namespace Tlf\Scrawl\Test;


/**
 *
 */
class Main extends \Tlf\Tester {

    /**
     *
     * @test that sample files get copied from test/input/Project/* to test/input/Init/*
     */
    public function testInit(){
        $dir = dirname(__DIR__).'/input/Init/';
        $this->empty_dir($dir, true);

        $args = json_decode(file_get_contents($dir.'/../Project/.config/scrawl.json'),true);
        $cli = new \Tlf\Cli();
        $cli->pwd = $dir;
        $args['noprompt'] = true;
        $scrawl = new \Tlf\Scrawl($dir, $args);
        $scrawl->run_init($cli, $args);


        $target_files = \Tlf\Tester\Utility::getAllFiles(dirname($dir).'/Project/', dirname($dir).'/Project/');

        $target_files = array_filter($target_files, function($f){return substr($f,0,6)!='/docs/';});

        $actual_files = \Tlf\Tester\Utility::getAllFiles($dir, $dir);


        sort($target_files);
        sort($actual_files);

        // $actual_files= array_map(function($f){return $f->relPath;}, $actual_files);
        $this->compare($target_files, $actual_files);



    }

}
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File ./Ext/ExportDocBlock.php  
  
# class Tlf\Scrawl\FileExt\ExportDocBlock  
Export docblock content above `@export(key)`  
@featured  
  
## Constants  
  
## Properties  
- `protected $regs = [  
        'export.key' => '/\@export\(([^\)]*)\)/',  
        'Exports' => '/((?:.|\n)*) *(\@export.*)/',  
    ];`   
  
## Methods   
- `public function get_docblocks(string $str): array` get an array of docblocks  
- `public function get_exports(array $docblocks)` get an array of exported text  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File ./Ext/ExportStartEnd.php  
  
# class Tlf\Scrawl\FileExt\ExportStartEnd  
Export code between `// @export_start(key)` and `// @export_end(key)`  
@featured  
  
## Constants  
  
## Properties  
- `protected $regs = [  
        'exports'=>   
                        '/\ *(?:\/\/|\#)\ *@export_start\(([^\)]*)\)((?:.|\r|\n)+)\ *(?:\/\/|\#)\ *(@export_end\(\1\))/',  
    ];`   
  
## Methods   
- `public function __construct()`   
- `public function get_exports($str)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File ./Ext/Main.php  
  
# class Tlf\Scrawl\Ext\Main  
  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function copy_readme($scrawl)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File ./Ext/Php.php  
  
# class Tlf\Scrawl\FileExt\Php  
Integrate the lexer for PHP files  
  
## Constants  
  
## Properties  
- `public \Tlf\Scrawl $scrawl;`   
  
## Methods   
- `public function __construct(\Tlf\Scrawl $scrawl)`   
- `public function get_all_classes()`   
- `public function set_ast(array $ast)`   
- `public function parse_str(string $str): array` Parsed `$str` into an ast (using the Lexer)  
- `public function parse_file(string $file_path): array` Parsed `$str` into an ast (using the Lexer)  
  
- `public function make_docs(array $ast)` use the ast to create docs using the classList template  
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File ./MdVerb/AstVerb.php  
  
# class Tlf\Scrawl\Ext\MdVerb\Ast  
  
  
## Constants  
  
## Properties  
- `public \Tlf\Scrawl $scrawl;`   
  
## Methods   
- `public function __construct($scrawl)`   
- `public function get_markdown($key, $template='ast/default')`   
- `public function get_ast(string $key, int $length=-1)`   
- `public function getVerbs(): array`   
- `public function getAstClassInfo(array $info, string $fqn, string $dotProperty)`   
- `public function verbAst($info, $className, $dotProperty)`   
- `public function getClassMethodsTemplate($verb, $argListStr, $line)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File ./MdVerb/MainVerbs.php  
  
# class Tlf\Scrawl\Ext\MdVerb\MainVerbs  
  
  
## Constants  
  
## Properties  
- `public \Tlf\Scrawl $scrawl;` a scrawl instance  
  
## Methods   
- `public function __construct(\Tlf\Scrawl $scrawl)`   
- `public function setup_handlers(\Tlf\Scrawl\Ext\MdVerbs $md_ext)` add callbacks to `$md_ext->handlers`  
- `public function at_template(string $templateName, ...$templateArgs)`   
- `public function at_import(string $key)` Import something previously exported with @export or @export_start/@export_end  
- `public function at_file(string $relFilePath)`   
- `public function at_see_file(string $relFilePath)`   
- `public function at_hard_link(string $url, string $name=null)` just returns a regular markdown link. In future, may check validity of link or do some kind of logging  
- `public function at_easy_link(string $service, string $target)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File ./MdVerb/MdVerbs.php  
  
# class Tlf\Scrawl\Ext\MdVerbs  
Runs `@mdverb` extensions, enabling special callbacks for `@verb()`s in `.src.md` files  
  
## Constants  
  
## Properties  
- `protected $regs = [  
        'verb' =>'/(?<!\\\\)\@([a-zA-Z_]+)\(([^\)]*)\)/m',  
    ];`   
- `public $handlers = [];` `key=>value` array of verb handlers. value should be callable. key is the verb.  
  
## Methods   
- `public function get_verbs(string $str): array` Get all `@verbs(arg1, arg2)`   
- `public function replace_all_verbs(string $doc): string` Get all verbs, execute them, and replace them within the doc  
- `public function run_verb(string $src, string $verb, array $args): string` execute a verb and get its output   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File ./Utility/DocBlock.php  
  
# class Tlf\Scrawl\Utility\DocBlock  
@featured  
  
## Constants  
  
## Properties  
- `static protected $regex = [  
                'DocBlock./**' => ['/((\/\*\*.*\n)( *\*.*\n)* *\*\/)/'],  
        'DocBlock./**.removeBlockOpen' => '/(^\/\*\*)/',  
        'DocBlock./**.removeLineOpenAndBlockClose' => '/(\n\s*\* ?\/?)/',  
    ];`   
  
## Methods   
- `public function __construct($rawBlock, $cleanBlock)`   
- `static public function DocBlock($name, $match, $nullFile, $info)`   
- `static public function extractBlocks($fileContent)`   
- `static public function cleanBlock($rawBlock)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File ./Utility/Main.php  
  
# class Tlf\Scrawl\Utility\Main  
  
  
## Constants  
  
## Properties  
- `static protected $classMap=[];`   
- `static protected $isRegistered=false;`   
  
## Methods   
- `static public function removeLeftHandPad($textBlock)`   
- `static public function allFilesFromDir(string $rootDir, string $relDir, array $forExt=[])`   
- `static public function DANGEROUS_removeNonEmptyDirectory($directory)`   
- `static public function getCurrentBranchForComposer()`   
- `static public function getGitCloneUrl()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File ./Utility/Regex.php  
  
# class Tlf\Scrawl\Utility\Regex  
  
  
## Constants  
  
## Properties  
  
## Methods   
- `static public function matchRegexes($targetObject, $regexArray, File $file=null, $textnull)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File ./Scrawl.php  
  
# class Tlf\Scrawl  
  
  
## Constants  
  
## Properties  
- `public array $stuff = [];` array for get/set  
- `public array $extensions = [  
        'code'=>[],  
    ];`   
- `public string $dir_docs = null;` absolute path to your documentation dir  
- `public string $dir_root = null;` absolute path to the root of your project  
- `public array $template_dirs = [  
  
    ];`   
- `public bool $markdown_preserveNewLines = true;` if true, append two spaces to every line so all new lines are parsed as new lines  
- `public bool $markdown_prependGenNotice = true;` if true, add an html comment to md docs saying not to edit directly  
  
## Methods   
- `public function __construct(array $options=[])`   
- `public function get_template(string $name, array $args)`   
- `public function process_str(string $string, string $file_ext)`   
- `public function addExtension(object $ext)`   
- `public function get(string $group, string $key)`   
- `public function get_group(string $group)`   
- `public function set(string $group, string $key, $value)`   
- `public function parse_str($str, $ext)`   
- `public function write_doc(string $rel_path, string $content)` save a file to disk in the documents directory  
- `public function read_file(string $rel_path)` Read a file from disk, from the project root  
- `public function report(string $msg)` Output a message to cli (may do logging later, idk)  
- `public function warn($header, $message)` Output a message to cli, header highlighted in red  
- `public function good($header, $message)` Output a message to cli, header highlighted in red  
- `public function prepare_md_content(string $markdown)` apply small fixes to markdown  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
<!-- Project Classlist generated by ast/ApiReadme template. -->  
<!-- To Disable: Set api.generate_readme = false in your config.json -->  
# All Classes  
Browse 11 classes in this project. There are 0 test classes and 11 non-test classes.  
  
## Source Classes (not tests)  
- [`Scrawl`](./Scrawl.php.md): No description...    
- [`Regex`](./Utility/Regex.php.md): No description...    
- [`Main`](./Utility/Main.php.md): No description...    
- [`DocBlock`](./Utility/DocBlock.php.md): @featured    
- [`MdVerbs`](./MdVerb/MdVerbs.php.md): Runs `@mdverb` extensions, enabling special callbacks for `@verb()`s in `.src.md` files    
- [`MainVerbs`](./MdVerb/MainVerbs.php.md): No description...    
- [`Ast`](./MdVerb/AstVerb.php.md): No description...    
- [`Php`](./Ext/Php.php.md): Integrate the lexer for PHP files    
- [`Main`](./Ext/Main.php.md): No description...    
- [`ExportStartEnd`](./Ext/ExportStartEnd.php.md): Export code between `// @export_start(key)` and `// @export_end(key)`  
    @featured    
- [`ExportDocBlock`](./Ext/ExportDocBlock.php.md): Export docblock content above `@export(key)`  
    @featured    
  
  
## Traits  
  
  
  
## Test Classes   
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File /test/run/Integrate.php  
  
# class Tlf\Scrawl\Test\Integrate  
  
See source code at [/test/run/Integrate.php](/test/run/Integrate.php)  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function check_full_test(string $which)`   
- `public function testRunCli()`   
- `public function testRunFull()`   
- `public function testAllClasses()`   
- `public function testGenerateApiDir()` @test  
- `public function testGenerateApiDirPrototype()`   
- `public function testGetAllClasses()`   
- `public function testPhpExtWithScrawl()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File code/abc/two.php  
  
# class two  
  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function go_2()` test docblock for go_2()  
- `public function test()` test docblock for test()  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File code/One.php  
  
# class One  
  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function go()` test docblock for go()  
- `public function test_2()` test docblock for test_2()  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
<!-- Project Classlist generated by ast/ApiReadme template. -->  
<!-- To Disable: Set api.generate_readme = false in your config.json -->  
# All Classes  
Browse 2 classes in this project. There are 0 test classes and 2 non-test classes.  
  
## Source Classes (not tests)  
- [`One`](code/One.php.md): No description...    
- [`two`](code/abc/two.php.md): No description...    
  
  
## Traits  
  
  
  
## Test Classes   
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# All Classes  
Documentation generated by @easy_link(tlf, php/code-scrawl)  
  
## two    
no docblock    
See [two.php](/docs/api/code/abc/two.php.md) for more.  
  
  
## One    
no docblock    
See [One.php](/docs/api/code/One.php.md) for more.  
  
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
public function go()  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
## Readme file  
This should copy automatically  
  
```bash  
composer require taeluf/code-scrawl v0.8.x-dev   
```  
or in your `composer.json`  
```json  
{"require":{ "taeluf/code-scrawl": "v0.8.x-dev"}}  
```  
  
  
```php  
<?php  
  
class One {  
  
    /** test docblock for go()   
     *  
     * @export(One.go)  
     */  
    public function go(){  
    }  
  
    /** test docblock for test_2() */  
    public function test_2(){  
    }  
}  
```  
  
this is a test template  
  
  
@own_verb(test arg, second arg)  
  
@non_existent_verb(okay)  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File code/abc/two.php  
  
# class two  
  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function go_2()` test docblock for go_2()  
- `public function test()` test docblock for test()  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File code/One.php  
  
# class One  
  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function go()` test docblock for go()  
- `public function test_2()` test docblock for test_2()  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
<!-- Project Classlist generated by ast/ApiReadme template. -->  
<!-- To Disable: Set api.generate_readme = false in your config.json -->  
# All Classes  
Browse 2 classes in this project. There are 0 test classes and 2 non-test classes.  
  
## Source Classes (not tests)  
- [`One`](code/One.php.md): No description...    
- [`two`](code/abc/two.php.md): No description...    
  
  
## Traits  
  
  
  
## Test Classes   
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# All Classes  
Documentation generated by @easy_link(tlf, php/code-scrawl)  
  
## two    
no docblock    
See [two.php](/docs/api/code/abc/two.php.md) for more.  
  
  
## One    
no docblock    
See [One.php](/docs/api/code/One.php.md) for more.  
  
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
public function go()  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
## Readme file  
This should copy automatically  
  
```bash  
composer require taeluf/code-scrawl v0.8.x-dev   
```  
or in your `composer.json`  
```json  
{"require":{ "taeluf/code-scrawl": "v0.8.x-dev"}}  
```  
  
  
```php  
<?php  
  
class One {  
  
    /** test docblock for go()   
     *  
     * @export(One.go)  
     */  
    public function go(){  
    }  
  
    /** test docblock for test_2() */  
    public function test_2(){  
    }  
}  
```  
  
this is a test template  
  
  
@own_verb(test arg, second arg)  
  
@non_existent_verb(okay)  
<?php

namespace Tlf\Scrawl\Test;

class Integrate extends \Tlf\Tester {

    /**
     * @param $which `run-full` or `run-cli` jsut to pick the right dirs
     */
    public function check_full_test(string $which){
        $dir_docs = $this->file('test/output/'.$which.'/docs/');
        $dir_root = $this->file('test/input/'.$which.'/');
        $files = \Tlf\Scrawl\Utility\Main::allFilesFromDir($dir_docs,'');
        // print_r($files);
        $this->compare_arrays(
            [
            '/api/code/abc/two.php.md',
            '/api/code/One.php.md',
            '/AllClasses.md',
            '/README.md',
            '/One.md',
            ],
            $files
        );

        $this->test('readme file output');
        $this->str_contains(
            file_get_contents($dir_docs.'/README.md'),
            'composer require taeluf/code-scrawl v0.8.x-dev',
            'class One {',
            'this is a test template',
            'test arg--second arg',
            '<!-- MdVerb `@non_existent_verb()` has no handler -->'
        );

        $this->test('copy readme file from docs to root');
        $this->compare(
            file_get_contents($dir_docs.'/README.md'),
            file_get_contents($dir_root.'/README.md')
        );

        $this->test('@ast verb');
        $this->str_contains(
            file_get_contents($dir_docs.'/One.md'),
            'public function go()',
        );

        $this->test('all classes template');
        $this->str_contains(
            file_get_contents($dir_docs.'/AllClasses.md'),
            '## two',
            '## One',
        );

        $this->test('Api output');
        $this->str_contains(
            file_get_contents($dir_docs.'/api/code/One.php.md'),
            '# File code/One.php',
            '- `public function go()` test docblock for go()',
            '- `public function test_2()` test docblock for test_2()',
        );

    }

    public function testRunCli(){
        $this->empty_dir($this->file('test/output/run-cli/docs/'), true);
        $readme_file = $this->file('test/input/run-cli/README.md');
        if (file_exists($readme_file))unlink($readme_file);

        $file = $this->file('test/input/run-cli/');
        $cli = $this->file('bin/scrawl');
        $cmd = "cd '$file'; '$cli';";
        $out = system($cmd);

        echo $out;

        $this->check_full_test('run-cli');
    }

    /**
     *
     * @test md verbs
     * @test @ast mdverb
     * @test all classes template
     * @test copy readme
     * @test custom mdverb handler
     * @test custom template
     * @test custom mdverb handler NOT FOUND
     */
    public function testRunFull(){
        $this->empty_dir($this->file('test/output/run-full/docs/'), true);
        $readme_file = $this->file('test/input/run-full/README.md');
        if (file_exists($readme_file))unlink($readme_file);

        $scrawl = new \Tlf\Scrawl(
            ['dir.root'=>$this->file('test/input/run-full/'),
            'dir.docs'=>$this->file('test/output/run-full/docs/'),
            'dir.src'=>$this->file('test/input/run-full/docsrc/'),
            'dir.scan'=>['code'],
            'template.dirs'=>[$this->file('test/input/run-full/template/')],
            ]
        );

        $scrawl->verb_handlers['own_verb'] = 
            function($arg1, $arg2){
                return $arg1.'--'.$arg2;

            };

        $scrawl->run();
        
        $this->check_full_test('run-full');
    }

    /**
     * @test Scrawl->get_all_classes()
     * @test all_classes template
     */
    public function testAllClasses(){
        $scrawl = new \Tlf\Scrawl();
        $scrawl->dir_root = $this->file('test/input/api-full/');
        $scrawl->dir_docs = $this->file('test/output/api-full/');
        $scrawl->dir_scan = [
            '.',
        ];
        $classes = $scrawl->get_all_classes();

        $class_names = [
            'Tlf\Scrawl\Utility\DocBlock',
            'Tlf\Scrawl\Utility\Main',
            'Tlf\Scrawl\Utility\Regex',
            'Tlf\Scrawl\FileExt\ExportDocBlock',
            'Tlf\Scrawl\FileExt\ExportStartEnd',
            'Tlf\Scrawl\Ext\Main',
            'Tlf\Scrawl\FileExt\Php',
            'Tlf\Scrawl\Ext\MdVerb\Ast',
            'Tlf\Scrawl\Ext\MdVerb\MainVerbs',
            'Tlf\Scrawl\Ext\MdVerbs',
            'Tlf\Scrawl'
            ];
        sort($class_names);
        $actual_class_names = array_keys($classes);
        sort($actual_class_names);
        $this->compare_arrays($class_names, $actual_class_names);


        $template = $scrawl->get_template('all_classes', [$classes]);
        $template2 = $scrawl->get_template('all_classes', []);

        $this->test('all_classes template ... classes passed in vs not');
        $this->is_true($template==$template2);

        $this->str_contains($template,
            ...$class_names
        );
    }

    /**
     * @test
     */
    public function testGenerateApiDir(){

        $scrawl = new \Tlf\Scrawl();
        $scrawl->dir_root = $this->file('test/input/api-full/');
        $scrawl->dir_docs = $this->file('test/output/api-full/');
        $scrawl->dir_scan = [
            '.',
        ];

        $this->empty_dir($scrawl->dir_docs, true);


        $scrawl->generate_apis();

        $files = \Tlf\Scrawl\Utility\Main::allFilesFromDir($scrawl->dir_docs, '');

        // print_r($files);

        $target = [
                '/api/Utility/DocBlock.php.md',
                '/api/Utility/Main.php.md',
                '/api/Utility/Regex.php.md',
                '/api/Ext/ExportDocBlock.php.md',
                '/api/Ext/ExportStartEnd.php.md',
                '/api/Ext/Main.php.md',
                '/api/Ext/Php.php.md',
                '/api/MdVerb/AstVerb.php.md',
                '/api/MdVerb/MainVerbs.php.md',
                '/api/MdVerb/MdVerbs.php.md',
                '/api/Scrawl.php.md',
            ];
        sort($target);
        sort($files);
        $this->compare_arrays($target,$files);

        $this->str_contains(
            file_get_contents($this->file('test/output/api-full/api/Scrawl.php.md')),
'- `public function report(string $msg)` Output a message to cli (may do logging later, idk)',
'- `public function warn($header, $message)` Output a message to cli, header highlighted in red',
'- `public function good($header, $message)` Output a message to cli, header highlighted in red',
'- `public function prepare_md_content(string $markdown)` apply small fixes to markdown  '
        );
    }

    /**
     * @test prototype of generating api docs
     */
    public function testGenerateApiDirPrototype(){

        $scrawl = new \Tlf\Scrawl();
        $scrawl->dir_root = $this->file('');
        $scrawl->dir_docs = $this->file('test/output/api/');
        $this->empty_dir($scrawl->dir_docs);
        $php_ext = new \Tlf\Scrawl\FileExt\Php($scrawl);
        $ast = $php_ext->parse_file('test/run/Integrate.php');



        $path = $ast['path'];
        $rel_path = substr($path, strlen($scrawl->dir_root));
        $ast['path'] = $rel_path;

        // $scrawl->set('ast','file.'.$rel_path, $ast);

        $classes = array_merge($ast['class'] ?? [], $ast['namespace']['class'] ?? []);

        $doc = "# File ".$rel_path."\n";
        foreach ($classes as $c){
            $markdown = $scrawl->get_template('ast/class', [null,$c,null]);

            $doc .="\n".$markdown;
        }

        // echo $doc;

        $scrawl->write_doc('test-gen_api.md', $doc);

        $this->str_contains(
            file_get_contents($this->file('test/output/api/test-gen_api.md')),
            '- `public function testGenerateApiDirPrototype()`',
            '- `public function testGetAllClasses()`',
            '- `public function testPhpExtWithScrawl()`',
        );
    }


    public function testGetAllClasses(){

        $class1 = <<<PHP
            <?php
            class Abc {
                function def(){}
            }
        PHP;
        $class2 = <<<PHP
            <?php
            class Ghi {
                function jkl(){}
            }
        PHP;
        $class3 = <<<PHP
            <?php
            class Mno{
                function pqr(){}
            }
        PHP;

        $scrawl = new \Tlf\Scrawl();
        $php_ext = new \Tlf\Scrawl\FileExt\Php($scrawl);
        $ast1 = $php_ext->parse_str($class1);
        $ast2 = $php_ext->parse_str($class2);
        $ast3 = $php_ext->parse_str($class3);

        $php_ext->set_ast($ast1);
        $php_ext->set_ast($ast2);
        $php_ext->set_ast($ast3);

        $classes = $php_ext->get_all_classes();

        $this->compare(
            'Abc',
            $classes['Abc']['fqn'],
        );
        $this->compare(
            'Ghi',
            $classes['Ghi']['fqn'],
        );
        $this->compare(
            'Mno',
            $classes['Mno']['fqn'],
        );

    }







    public function testPhpExtWithScrawl(){
        echo "this is an old test from the beginning of the rewrite ... probably don't need it anymore. I don't think it was ever passing";
        $this->disable();
        return;
        $str = $this->php_code;
        $scrawl = new \Tlf\Scrawl();

        $scrawl->extensions['code']['php'][] = new \Tlf\Scrawl\FileExt\Php();

        $res = $scrawl->parse_str($str, 'php');
        print_r($res);
        exit;

        print_r($scrawl->get('ast'));


        return;

        $scrawl->extensions['file']['php'];
        $scrawl->addExtension('file');

        $outputs = $scrawl->process_str($str, '.php');

        // this should have
        // ast = ... the ast ...
        // tags = 
        print_r($outputs);

        // i should use the lexer to build the ast explicitly
        $class_ast = null; 
        $method_ast = null;
        $this->compare(
            [
                'ast'=>[
                    'class'=>['Abc'=>$class_ast] // ast as from lexer
                ],
                'tags'=>[
                    'feature'=>['name'=>'no feature', 'target'=>'ast.class.Abc']
                ],
                'flat'=>[
                    'ast.class.Abc'=>$class_ast,
                    'ast.class.Abc.method.ghi'=>$method_ast,
                ],
            ],
            $outputs
        );

        return;
        // this shouldn't do anything bc i haven't added any extensions
        print_r($scrawl->getOutputs());
    }

}
<?php

namespace Tlf\Scrawl\Test;

/**
 * For testing all things `.md` file
 */
class MdDocs extends \Tlf\Tester {




    /**
     * @test getting an ast from a dot-property like `class.Abc.methods.go`
     * @test getting markdown from a dot-property & template name
     * @test parsing a doc with MdVerbs ext & auto-filling in the @ast verb
     * @test template ast/method
     * @test template ast/default
     */
    public function testAstVerb(){
        $doc = <<<MARKDOWN
            @ast(class.Abc.methods.go.docblock.description)
        MARKDOWN;
        $code = <<<PHP
            <?php
            class Abc {
                /**
                 * Test Description
                 *
                 * @param \$oh nothing
                 * @return void
                 */
                public function go(\$oh){}
            }
        PHP;


        $scrawl = new \Tlf\Scrawl();

        $php_ext = new \Tlf\Scrawl\FileExt\Php($scrawl);
        $ast = $php_ext->parse_str($code);

        $scrawl->set('ast','class.Abc', $ast['class'][0]);

        $ast_ext = new \Tlf\Scrawl\Ext\MdVerb\Ast($scrawl);

        $method_ast = $ast_ext->get_ast('class.Abc.methods.go');
        $this->compare(
            'method',
            $method_ast['type'],
        );
        $this->compare(
            'go',
            $method_ast['name'],
        );

       $this->compare(
            'Test Description',
            $ast_ext->get_ast('class.Abc.methods.go.docblock.description')
        );
        $this->compare_lines(
            '# Abc::go'
            ."\nTest Description",
            $ast_ext->get_markdown('class.Abc.methods.go', 'ast/method')
        );

        $this->test('main verbs integration');

        $verb_handler = new \Tlf\Scrawl\Ext\MdVerbs($scrawl);
        $verb_handler->handlers['ast'] = [$ast_ext, 'get_markdown'];

        $this->compare_lines(
            "Test Description",
            $verb_handler->replace_all_verbs($doc)  
        );

    }


    /** @test built-in md verb handlers */
    public function testMdVerbsMain(){
        $doc = <<<MARKDOWN
        @import(test)
        @file(test.txt)
        @template(test.template, one, two)
        @easy_link(tlf,php/code-scrawl)
        @hard_link(https://taeluf.com, Taeluf.com)
        @see_file(test.see.txt)
        MARKDOWN;
        $scrawl = new \Tlf\Scrawl();
        $scrawl->dir_root = $this->file('test/input/md-verbs/');
        $scrawl->template_dirs[] = $this->file('test/input/md-verbs/');
        $scrawl->set('export', 'test', 'test export');
        $ext = new \Tlf\Scrawl\Ext\MdVerbs();
        $verb_handler = new \Tlf\Scrawl\Ext\MdVerb\MainVerbs($scrawl);
        $verb_handler->setup_handlers($ext);
        ob_start();
        $output = $ext->replace_all_verbs($doc);
        $errors = ob_get_clean();

        $this->test('no error output');
        $this->compare('', $errors);

        $this->test('filled-in documentation');
        $this->compare_lines(
        <<<MARKDOWN
            test export
            test.txt file
            one-two
            [php/code-scrawl](https://tluf.me/php/code-scrawl)
            [Taeluf.com](https://taeluf.com)
            [test.see.txt](/test.see.txt)
        MARKDOWN,
            $output
        );
    }

    /** @test that \@verbs() work */
    public function testMdVerbsParsing(){
        $doc = <<<MARKDOWN
        # Whatever
        @test(one) with @test(two, three, four)
        @test(three)
        MARKDOWN;
        $ext = new \Tlf\Scrawl\Ext\MdVerbs();
        $verbs = $ext->get_verbs($doc);

        $this->compare(
            [
                ['src'=>'@test(one)',
                'verb'=>'test',
                'args'=>['one'],
                ],
                ['src'=>'@test(two, three, four)',
                'verb'=>'test',
                'args'=>['two', 'three', 'four'],
                ],
                ['src'=>'@test(three)',
                'verb'=>'test',
                'args'=>['three'],
                ],

            ],
            $verbs
        );

        $ext->handlers['test'] = function(...$strings){
            return implode(':',$strings);
        };

        $replacement = $ext->run_verb($verbs[1]['src'], $verbs[1]['verb'], $verbs[1]['args']);
        $this->compare('two:three:four', $replacement);
    }

    /** @test copying readme to PROJECT_ROOT/README.md */
    public function testCopyReadme(){
        $scrawl = new \Tlf\Scrawl(
            ['dir.docs'=> $this->file('test/input/docs/'),
            'dir.root'=>$this->file('test/input/project-root/')
            ]
        );
        $main_ext = new \Tlf\Scrawl\Ext\Main();
        $main_ext->copy_readme($scrawl);

        $this->file_exists($this->file('test/input/docs/README.md'));
    }

}
<?php

namespace Tlf\Scrawl\Test;

/**
 * For testing all things `.md` file
 *
 */
class MdTemplates extends \Tlf\Tester {


    /** @test template bash/install */
    public function testBashInstall(){
        $scrawl = new \Tlf\Scrawl();
        $template = $scrawl->get_template('bash/install', ['scrawl-test', 'bin/scrawl-test']);

        $this->str_contains(
            $template,
            'command="scrawl-test"',
            'git clone https://gitlab.com/taeluf/php/CodeScrawl.git ${command}',
            'chmod ug+x "${downloadDir}/${command}/bin/scrawl-test"',

        );
        // echo $template;
    }

    /** @test template php/composer_install */
    public function testComposerInstall(){
        $scrawl = new \Tlf\Scrawl();
        $template = $scrawl->get_template('php/composer_install', ['taeluf/code-scrawl', 'v0.7.x-dev']);

        $this->str_contains(
            $template,
            'composer require taeluf/code-scrawl v0.7.x-dev',
            '"taeluf/code-scrawl": "v0.7.x-dev"',
        );
    }

    /** 
     *
     * These tests are pretty straightforward & do NOT use the ast verb or verb class at all (except passing it to the the templates) ... those more involved tests are integration tests & not every template needs to be tested that way ... just one or two
     *
     * @test ast/method template
     * @test ast/default template
     * @test ast/function_list template
     */
    public function testAstTemplates(){
        $this->test('ast/method & ast/default templates');
        // because testAstVerb() properly tests those templates ...
        $this->method_exists('Tlf\\Scrawl\\Test\\MdDocs', 'testAstVerb');


        $this->test('ast/function_list template');
        $scrawl = new \Tlf\Scrawl();
        $php_ext = new \Tlf\Scrawl\FileExt\Php($scrawl);
        $ast_ext = new \Tlf\Scrawl\Ext\MdVerb\Ast($scrawl);
        $ast = $php_ext->parse_str(<<<PHP
            <?php
            /** abc test description */
            function abc(){}
            /** def test description */
            function def(){}
        PHP);
        $ast['relPath'] = ':memory:';
        $md = $scrawl->get_template('ast/function_list', ['file.memory', $ast, $ast_ext]);

        $this->compare_lines(
            '# File :memory:
            ## Functions
            - `abc`: abc test description
            - `def`: def test description',
            $md
        );


        $this->test('ast/class template');
        $scrawl = new \Tlf\Scrawl();
        $php_ext = new \Tlf\Scrawl\FileExt\Php($scrawl);
        $ast_ext = new \Tlf\Scrawl\Ext\MdVerb\Ast($scrawl);
        $ast = $php_ext->parse_str(<<<PHP
            <?php
            class One {
                /** sure const */
                const sure = "sure";
                /** abc var */
                public \$abc = "okay";
                /** def test description */
                function def(){}
            }
        PHP);
        $md = $scrawl->get_template('ast/class', ['class.One', $ast['class'][0], $ast_ext]);

        $this->compare_lines(
            '# class One

            ## Constants
            - `const sure = "sure";` 

            ## Properties
            - `public $abc = "okay";` abc var

            ## Methods 
            - `function def()` def test description',
            $md
        );

        $this->test('ast/class_methods');
        $scrawl = new \Tlf\Scrawl();
        $php_ext = new \Tlf\Scrawl\FileExt\Php($scrawl);
        $ast_ext = new \Tlf\Scrawl\Ext\MdVerb\Ast($scrawl);
        $ast = $php_ext->parse_str(<<<PHP
            <?php
            class One {
                /** def test description */
                function def(){}
                function xyz(){}
            }
        PHP);
        $md = $scrawl->get_template('ast/class_methods', ['class.One', $ast['class'][0], $ast_ext]);


        $this->compare_lines(
            '- `$one->def()`: def test description'
            ."\n".'- `$one->xyz()`:',
            $md
        );
    }

}
<?php

namespace Tlf\Scrawl\Test;

/**
 * For testing all things related to source code
 */
class SrcCode extends \Tlf\Tester {

    public $php_code = 
        <<<PHP
            <?php 

            /**
             * Does nothing
             * @feature(no feature)
             * @deprecated because it does nothing
             * @todo delete this useless class
             */
            class Abc extends Def {
                function ghi(){}
            } 
        PHP;



    /**
     * @test export_start() code export_end()
     */
    public function testExportStartEnd(){
        $str = <<<BASH
            // @export_start(change_git_origin)
            old_remote="$(git config --get remote.origin.url)"
            git remote remove origin
            git remote add origin "\${new_url}"
            # push all
            git push --mirror origin
            git remote add "$(date +%d_%m_%y_old)" "\${old_remote}"
            // @export_end(change_git_origin)
            // @export_start(nothing)
            var="some value"
            // @export_end(nothing)
        BASH;

        $start_end_ext = new \Tlf\Scrawl\FileExt\ExportStartEnd();
        $exports = $start_end_ext->get_exports($str);

        $this->compare(
            [
            'change_git_origin'=>
                'old_remote="$(git config --get remote.origin.url)"'."\n"
                ."git remote remove origin\n"
                .'git remote add origin "${new_url}"'."\n"
                ."# push all\n"
                ."git push --mirror origin\n"
                .'git remote add "$(date +%d_%m_%y_old)" "${old_remote}"',

            'nothing'=>'var="some value"',
            ],
            $exports
        );
    }


    /**
     * @test export a docblock (everything above the \@export() line)
     */
    public function testDocblockExport(){
        $str = <<<PHP
            /**
             * use the ast to create docs using the classList template
             *
             * @export(no_return) and some text?
             * @return array of files like `['rel/path'=>'file content']`
             */
            function who_cares(){}
            /**
             * Parsed `\$str` into an ast (using the Lexer)
             * @param \$str a string to parse
             * @return array ast
             * @export(with_return)
             */
            public \$it_doesnt_matter = null;
        PHP;
        $docblock_ext = new \Tlf\Scrawl\FileExt\ExportDocBlock();
        
        $blocks = $docblock_ext->get_docblocks($str);
        $exports = $docblock_ext->get_exports($blocks);

        $this->compare(
            [
                'no_return'=>'use the ast to create docs using the classList template',
                'with_return'=>"Parsed `\$str` into an ast (using the Lexer)\n@param \$str a string to parse\n@return array ast"
            ],
            $exports,
        );
        // print_r($exports);
    }

    /** 
     * @test php ast 
     * @test php make_docs()
     * @test scrawl write_doc()
     */
    public function testPhpExt(){
        $this->empty_dir($this->file('test/input/docs/'));
        $str = $this->php_code;



        $scrawl = new \Tlf\Scrawl(
            [
                'dir.docs'=>$this->file('test/input/docs/'),
                'markdown.preserveNewLines' => false,
                'markdown.prependGenNotice' => false,
            ],
        );
        $php_ext = new \Tlf\Scrawl\FileExt\Php($scrawl);

        $ast = $php_ext->parse_str($str);
        $files = $php_ext->make_docs($ast);

        foreach ($files as $rel_path=>$src){
            $scrawl->write_doc($rel_path, $src);
        }

        $this->str_contains($files['class/Abc.md'],
            '# class Abc',
            '- `function ghi()` ',
        );

        $this->compare(
            $files['class/Abc.md'],
            'file://'.$this->file('test/input/docs/class/Abc.md')
        );

    }

}
{
    "dir.test": ["test/run"],
    "results.writeHtml":false,
    "file.require":[]
}
MIT License

Copyright (c) 2020 Reed Sutman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# Code Scrawl  
Code Scrawl is a documentation generator. You write `.src.md` files and call buit-in functions with `@‌verbs()` within, including `@‌template(template_name)` to load several built-in templates. You can create custom extensions and templates for your own projects, or to generate documentation for using a library you made.   
  
Also generate full API documentation of PHP classes. AST Generation uses `taeluf/lexer`, which can be extended to support other languages, but as of May 2023, there are no clear plans to do this.  
  
## Features  
- Integrated AST generation to automatically copy+paste specific parts of source code, thanks to [php/lexer](https://tluf.me/php/lexer)  
- Several builtin verbs and templates  
- Extend with custom verbs and templates.  
  
## Deprecation Warning:  
- v1.0 will stop using hidden directories like `.docsrc/` and instead use `docsrc/`. The defaults.json file will be changed to accomodate in v1.0  
- v1.0 will use dir `src/` instead of `code/` as a default directory to scan. (currently also scans `test/`, which will not change)  
  
### Install  
```bash  
composer require taeluf/code-scrawl v0.8.x-dev   
```  
or in your `composer.json`  
```json  
{"require":{ "taeluf/code-scrawl": "v0.8.x-dev"}}  
```  
  
  
### Configure  
Create a file `.config/scrawl.json` or `scrawl.json` in your project root. Defaults:  
```json  
{  
    "--NOTICE":"v1.0 will introduce updated defaults.",  
  
    "template.dirs": [".doctemplate"],  
  
    "dir.docs": "docs",  
    "dir.src": ".docsrc",  
    "dir.scan": ["code", "test"],  
    "ScrawlExtensions":[],  
  
    "file.bootstrap":"scrawl-bootstrap.php",  
  
    "api.output_dir": "api/",  
    "api.generate_readme": true,  
  
    "deleteExistingDocs": false,  
    "readme.copyFromDocs": false,  
  
    "markdown.preserveNewLines": true,  
    "markdown.prependGenNotice": true  
}  
```  
  
### Default Configs / File Structre  
**Note:** Instructions updated to use non-hidden directories, but the default.json file still uses hidden directories. This inconsistency will be fixed in v1.0  
- `config/scrawl.json`: configuration file  
- `docsrc/*.src.md`: documentation source files (from which your documentation is generated)  
- `docs/`: generated documentation output  
- `src/*`, and `test/*`: Code files to scan  
- `doctemplate/*.md.php` and `CodeScrawl/src/Template/*.md.php`: re-usable templates   
- `scrawl-bootstrap.php`: Runs at start of `$scrawl->run()` and `$this` is the `$scrawl` instance.  
  
## Usage  
Overview:  
- Execute with `vendor/bin/scrawl` from your project root.  
- Write files like `docsrc/README.src.md`  
- Use Markdown Verbs (mdverb) to load documentation and code into your `.src.md` files: `@‌file(src/defaults.json)` would print the content of `src/defaults.json`  
- Use the `@‌template` mdverb to load a template: `@‌template(php/compose_install, taeluf/code-scrawl)` to print composer install instructions   
- Use the `@‌ast` mdverb to load code from the AST (Asymmetric Syntax Tree): `@‌ast(class.\Tlf\Scrawl.docblock.description)` to print directly or `@‌ast(class.\Tlf\Scrawl, ast/class)` to use an ast template.  
- Write special `@‌codeverbs` in comments in code source files to export docblocks and code.   
- Extend it! Write custom templates and `@‌mdverb` handlers  
- Write custom md verb handlers (see 'Extension' section below)  
- Write custom templates (see 'Extension' section below)  
- Use an `ASCII Non-Joiner` character after an `@` sign, to write a literal `@‌at_sign_with_text` and not execute the verb handler.  
  
### Write Documents: Example  
Write files in your `docsrc` folder with the extension `.src.md`.  
Example, from [docsrc/README.src.md](/docsrc/README.src.md)  
  
This would display the `## Install` instructions and `## Configure` instructions as above  
```md  
# Code Scrawl  
Intro text  
  
## Setup   
### Install  
@‌template(php/compose_install, taeluf/code-scrawl)  
  
### Configure  
Create a file `.config/scrawl.json` or `scrawl.json` in your project root. Defaults:  
‌```json  
@‌file(src/defaults.json)  
‌```  
```  
  
### `@‌MdVerbs` List  
Write these in your markdown source files for special functionality    
- `@import()`: Import something previously exported with `@export` or `@export_start/@export_end`. Usage: `@import(Namespace.Key)`    
- `@file()`: Copy a file's content into your markdown.. Usage: `@file(rel/path/to/file.ext)`    
- `@template()`: Load a template. Usage: `@template(template_name, arg1, arg2)`    
- `@link()`: Output links configured in your config json file.  
Config format is `{..., "links": { "link_name": "https://example.org"} }`. Usage: `@link(phpunit)`    
- `@easy_link()`: Get a link to common services (twitter, gitlab, github, facebook). Usage: `@easy_link(twitter, TaelufDev)`    
- `@hard_link()`: just returns a regular markdown link. In future, may check validity of link or do some kind of logging. Usage: `@hard_link(https://url.com, LinkName)`    
- `@see_file()`: Get a link to a file in your repo. Usage: `@see_file(relative/file/path)`    
- `@see()`: Get a link to a file in your repo. Usage: `@see_file(relative/file/path)`    
- `@system()`: Run a command on the computer's operating system.  
  
Supported options: `trim`, `trim_empty_lines`, `last_x_lines, int`    
- `@ast()`: Get an ast & optionally load a custom template for it. Usage: `@ast(class.ClassName.methods.docblock.description, ast/default)`    
  
  
### Template List  
Templates can be loaded with `@‌template(template_name, arg1, arg2)`, except `ast/*` templates (see below for those).  
  
Each template contains documentation for how to use it & what args it requres.  
  
  
### `@‌ast()` Templates (Asymmetric Syntax Tree)  
Example: `@‌ast(class.\Tlf\Scrawl.docblock.description)` to print directly or `@‌ast(class.\Tlf\Scrawl, ast/class)` to use an ast template.  
  
### `@‌CodeVerbs` Exports (from code in scan dirs)  
In a docblock, write `@‌export(Some.Key)` to export everything above it.  
  
In a block of code (or literally anywhere), write `// @‌export_start(Some.Key)` then `// @‌export_end(Some.Key)` to export everything in between.  
  
See [test/run/SrcCode.php](/test/run/SrcCode.php) for examples  
  
## Extensions  
  
### Templates: Write a custom template  
Look at existing templates in [doctemplate/](/doctemplate/) or [src/Template](/src/Template) for examples.  
  
### Verb Handlers: Write a custom verb handler  
In your `scrawl-bootstrap.php` file, do something like:  
```php  
<?php  
/**  
 * @param $scrawl instance of `\Tlf\Scrawl`  
 */  
  
$scrawl->verb_handlers['own_verb'] =   
    function($arg1, $arg2){  
        return $arg1.'--'.$arg2;  
  
    };  
```  
  
### PHP Extensions  
Create a class that `implements \Tlf\Scrawl\Extension`. See file [src/Extension.php](/src/Extension.php). You can `class YourExt extends \Tlf\Scrawl\DoNothingExtension` as a base class and then only override the methods you need.  
  
In your `config.json`, set `"ScrawlExtensions": ["Your\\Fully\\Qualified\\ClassName"]`, with as many extension classes as you like.  
  
## Architecture  
- `Tlf\Scrawl`: Primary class that `run()`s everything.  
- `\Tlf\Scrawl->run()`: generate `api/*` files. Load all php classes. scan code files. Scan `.src.md` files & output `.md` files.  
    - file set as `file.bootstrap` is `require()`d at start of `run()` to setup additional mdverb handlers and (eventually) other extensions. Default is `scrawl-bootstrap.php`  
- `Tlf\Scrawl\Ext\MdVerbs`: Instantiated during `run()` prior to scanning documentation source files. When an `@‌mdverb(arg1,arg2)` is encounter in documentation source file, a handler (`$mdverbs->handlers['mdverb']`) is called with string arguments like `$handler('arg1', 'arg2')`. Extend it by adding a callable to `$scrawl->mdverb_ext->handlers`.  
    - `Tlf\Scrawl\Ext\MdVerb\MainVerbs`: Has functions for simple verb handlers like `@‌file`, `@‌template`. Adds each function as a handler to the `MdVerbs` class.  
    - `\Tlf\Scrawl\Ext\MdVerb\Ast`: A special mdverb handler that loads ASTs from the lexer and passes it to a named (or default) template.  
- `Tlf\Scrawl\FileExt\Php`: The only AST extension currently active. It is a convenience class that wraps the Lexer so it is easily called by `Scrawl`. It is called to setup ASTs by `class.ClassName...` on `$scrawl`. Call `$scrawl->get('ast', 'class.ClassName...')`. It is called to generate the `api/*` documentation files.  
- INACTIVE CLASS `Tlf\Scrawl\Ext\Main` simply copies the `project_root/.docrsc/README.src.md` to `project_root/README.md`  
- `Tlf\Scrawl\FileExt\ExportDocBlock` and `ExportStartEnd` handle the `@‌export()` tag in docblocks and the `@‌export_start()/@‌export_end()` tags.  
- `\Tlf\Scrawl\Utility\DocBlock`: Convenience class for extracting docblocks from files.  
- `\Tlf\Scrawl\Utility\Main`: Class with some convenience functions  
- `\Tlf\Scrawl\Utility\Regex`: Class to make regex matching within a file more abstract & object oriented. (it's not particularly good)  
  
## More Info  
- Run withOUT the cli: Some of the configs require absolute paths when running through php, rather than from the cli. An example is in [test/run/Integrate.php](/test/run/Integrate.php) under method `testRunFull()`  
- `@‌literal`: Displaying a literal `@‌literal` in an md source file can be done by putting a [Zero Width Non-Joiner](https://unicode-explorer.com/c/200C) after the arroba (`@`). You can also use a backslash like so: `@\literal`, but then the backslash prints  
- All classes in this repo: [docs/ClassList.md](/docs/ClassList.md)  
- `$scrawl` has a `get/set` feature. In a template, you can get an ast like `$scrawl->get('ast.Fully\Qualified\ClassName')`. Outside a template, you can use the `Php` class ([src/Ext/Php.php](/src/Ext/Php.php)) to get an ast from a file or string.  
- the `deleteExistingDocs` config has a bit of a sanity check to make sure you don't accidentally delete your whole system or something ...  
# Code Scrawl Status

## Feb 3, 2024
I tried setting up cicd. its a mess. i don't understand. I'm stuck on the part of adding a .phar archive to my release (oh, maybe I should look at an existing project's cicd pipeline & copy what they're doing. What major projectsa re on gitlab?)



## Dec 23, 2023
This stuff:
* 7535260 - (HEAD -> v0.8, origin/v0.8) run scrawl (4 minutes ago) <Reed Sutman>
* c119802 - Fix url path for class documentation, so that any double forward-slashes are removed. (4 minutes ago) <Reed Sutman>
* ed30a63 - add git/ChangeLog template & a changelog documentation src file (template for everybody. src file for itself) (44 minutes ago) <Reed Sutman>
* 6c61bbe - Add api.generate_readme config (default TRUE). This is NEW Functionality that creates a README in the api/ dir. Created template for api readme generation & implemented it for Code Scrawl's docs (53 minutes ago) <Reed Sutman>
* de02bb5 - add api.output_dir configuration. Default avlue has same functionality as before (always output API to doc/api/ dir. Set null/false in your config to disable api output). (2 hours ago) <Reed Sutman>
* fd071e4 - other fixes. run scrawl. No errors any more! (2 hours ago) <Reed Sutman>
* 4bc75e1 - minor pathing fixes. run scrawl (2 hours ago) <Reed Sutman>
* 8a59b35 - move files. code/ -> src/, .docsrc / -> docsrc/, .config/ -> config/, .doctemplate -> doctemplate/ (2 hours ago) <Reed Sutman>

## Dec 20, 2022
- documented architecture
- made `$scrawl->mdverb_ext` accessible to bootstrap files
- `file.bootstrap` is now `require`d at start of `run()` so `$scrawl` can ALSO be accessed via `$this`.
- TODO: in scrawl->run(), add a simple hooks / extensions mechanism. Call hooked methods (or objects) on each source code file, and on each documentation source file, and at the end of run(). Possible other intermediate calls.
- TODO: Use `@‌template('all_classes')` or something similar to show the architecture. (need to write their docblocks and also change the template)
- TODO: In `.doctemplate/Scrawl/Templates.md.php`, add docblock descriptions, at least, to output

## Dec 18, 2022
- It doesn't look like I have a way to dynamically add php extension classes (such as the bash classes). See the Dec 10 notes for more information.
- Updated README to have a better flow & better detailed documentation
- TODO: Improve documentation of how to write extensions
- TODO: Setup dynamically adding php extension classes.
- TODO: Re-add `scrawl init` bin function

## Dec 10, 2022
- Extensions! I don't seem to have a way to set extensions in the config.json, since the only place extensions are dynamically checked for is in `parse_str()` & it expects an already instantiated object. in `Integrate.php::testPhpExtWithScrawl()`, extensions are dynamically added, but this isn't through configs or through the CLI. I'd like to fix this, so I can write extensions in other packages, then add them to the config, then have them run like they're supposed to. One solution is to add a simple callback function that can do things dynamically. So, when `Scrall->run()` is called, I could check the config for a `setup_file` or `setup_function`, then that file or function could setup scrawl however it needs to be setup. That allows more configurability, since it gives PHP access to scrawl when scrawl is run through CLI, and it is simpler because I don't have to come up with a new scheme for extension setup.

## TODO (apr 27, 2022)
- review old notes?? I think i already did the new structure? idk

## Goals
- rewrite scrawl to the new structure
- add an annotations feature that extracts all `@tags` from docblocks & comments throughout the code base & links them to asts (and/or files, maybe? idk)

## Versions
Lexing (ast generation) is not really ready
- v0.3 depends on lexer v0.6, which is abandoned but stable??
- v0.4 depends on lexer v0.2, which supports SIMPLE bash lexing & SIMPLE php lexing
- v0.5 depends on lexer v0.2, which is under development & has several failing tests
- v0.6 depends on lexer v0.7, the up & coming lexer
- v0.7 less extensible, much simpler codebase

## TODO
- IMPORTANT re-run `scrawl` on this repo & review it for errors & clean up the documentation
- IMPORTANT update default branch for code scrawl
- PLEASE write test for `scrawl init` (likely requires some internal changes)
- PLEASE make it so global `scrawl` command can successfully run `vendor/bin/scrawl`
- MAYBE add `@verb` escaping like `\@verb` or `@\verb` (probably `\@verb`)
- EH reorg some of the classes
- EH rework some of the naming
- EH rework some of the defaults
- MEH clean up the `bin/scrawl` script
- MEH review the `code/Old.php` file for ... stuff i might actually use
- MEH review the `old/GeneratedDocs.php` test class

## Latest
- Feb 15, 2022:
    - integration test for `scrawl->run()` (and write `run()`)
    - add integration test for running scrawl from cli (and modify `bin/scrawl`)
    - clean up the repo
- feb 14, 2022: 
    - api dir generation
    - all_classes template

## Feb 11, 2022 end of day
I was working on generating the `Api` folder ... prototyping it in a test `phptest -test generateApiDir`

i want to finish that prototype
then i want to make a more integrated test that basically puts that prototype into a more generic function on scrawl or the php ext ... idk

then i also want to do the `all_classes` template ... which would still require me to set the file ast on every class ... which would ... require additional processing, maybe setting file ast's to Scrawl or by pre-processing classes and adding file path to their asts before separating them FROM their file asts or by adding references back to their parent ast ... idk about that one

And once those "two" things are done, i'd like to write an integration test that ... runs code scrawl on a project directory (likely from the `test/input/` dir somewhere) ... 

THEN i can update to use the cli runner with that integrated code

THEN i can review old code & delete almost all of it

Woo heck hoo!

have a good time reed! Don't spend too much time on unimportant software. There are other priorities. This is important (to me), but far from crucial & probably not that important for the world ... but maybe the future will bear out something different & I'll find out that my awesomse software is awesome lol idk.

Love,
Reed <3


## Feb 11, 2022 (near end of day)
goals:
1. test all_classes template
2. write api docs to disk for every php file in the code dirs, matching the directory structure on disk

## Feb 10, 2022 end of day
TODO:
- NO write export list ext
- NO all docblocks ext? idk ... i might just skip it ...
- test all my templates

DONE:
- ast verb
- moved SimpleVerbs to new structure. Wrote tests for them
- cleaned up the repo (stuff i've covered already or that i don't need).
- 

Notes:
- code-old.bak is code-old before i started deleting things ... i really shouldn't need any of it
- test/old/ is ... old tests?? i think they might be useful. should review them


## Feb 10, 2022
I made the new branch ... and made notes on v0.6 ...
i want to just ... clean this up, i think ... remove all the old trash code so i can start centering around the new, good code ... then start rewriting and stuff

## Feb 8, 2022
- I've started a rewrite ... i'll need to make a new branch ... i'm still needing to finish `New/Ext/ExportStartEnd.php` and its tests ... Then I need to modify the existing rewrites & use the new version of BetterReg (Breg) ... just look at `code/New` & `test/run/Idk.php`

## Jan 28, 2022
I would really like to index all the `@whatevers` throughout comments & docblocks. Then be able to like, `$scrawl->get('feature', 'PhpFileHandler')` and have a reference to the docblock & property/method/class/etc on which `@feature(PhpFileHandler)` is declared

## Jan 25, 2022
- i updated the lexer integration code & the `classList` template so api docs are now being generated ... though still missing many important features

## Dec 6, 2021 (end of day):
TODO:
- after review, set this as default branch
- code/Scrawl.php needs major refactor (because it's just confusing)
- Extension stuff needs major refactor (because it's juts confusing)
- if config file does not exist, then prompt/ask if init is desired

NOTES:
- tests are passing
    - autoloading MIGHT not be working correctly ... I'm not sure
- cli implementation is totally based upon cli lib now
- composer.json is correct
- nothing lexer/ast related has been reviewed
- `scrawl` and `scrawl init` both work
- `.doctemplate` is implemented
- Docs are largely written

Extra TODO:
- test each template (mainly just to have example usage)


## v0.6: Up & coming scrawl
Just made new branch. TODO:
- general cleanup
- setup new cli lib
- fix all tests


---

## Copied from ... v0.4? Pretty sure
Basically, its in a very messy state and it needs some real time & attention to clean everything up.

- My lexer isn't properly parsing php. I need to fix this. Especially look at Grammar.php's ast. It IS getting `onLexerStart()` method, but its being recorded as a function in the file, not a method of the class.
- I just started updating the `verbAst` function (old implementation for `@ast()`), but didn't finish. Right now I just have it calling the method used for `@ast_class()`, but I haven't confirmed it due to the aforementioned lexer issues
- My templates verb function also needs updated to the latest version.

### Ideas
- shorthand extension declaration for built-in extensions.
    - `Lang\\*` to load all language extensions
    - `MdVerb\\Ast` for Ast extension (instead of `\Tlf\Scrawl\Ext\MdVerb\Ast`)
- Remove the `key=>value` pairing & switch to pure array of class names (and shorthands)
- a `disable` key to disable certain extensions that are automatically setup. 
- `@ast(type, key, astprop.whatever)`. Example: `@ast(class, \Tlf\Scrawl, methods.__construct.docblock)` will print a `trim`med docblock into the md file
- `@todo()` to print all TODOs found in the code base
    - `@TODO(*)` to output all TODOs (or something like it)
    - `@TODO(rel/file.ext)` to output all TODOs from `rel/file.ext`
- Configs for what generated output files should be written
- `@see_class(ClassName)` to output `[FqnClassName](LinkToClassFile)`
- `@see_function(FunctionName)` to output `[function_name()](LinkToFunctionFile)`
- `@see_file(Rel/FileName)` to output a link to the file (allows scrawl to report errors, so you know the link stays valid)
- `filename.src.md.php` to execute as php file, THEN run code scrawl
    - `filename.src.php.md` to run code scrawl THEN execute as php file
- `@see_dependencies()` to show links to all dependencies (as declared in composer.json)
- add optional link checking (`curl` every link to make sure they are valid)


### Latest (newest to oldest)
- changed `lex` setting to `lex.php` and `lex.bash` and now it defaults to `false`
- `@ast_class` works! `@ast` does too, but its currently just an alias for @ast_class
- add error reporting via `$scrawl->error('header', $msg)`
- Modify mdverb regex to allow `@verb()s` anywhere, not just at the start of a line. & remove requirement for rest of line to be whitespace.
- add `@easy_link(twitter, TaelufDev)` mdverb.
- Added `composer_install` template
- Added `@template(template_name, ...args)` as part of `Md/SimpleVerbs` extension
- Add `lex` config to conditionally disable the lexer.
- Md verb methods now receive a list of args instead of an argListString. The about the match is passed in an array as the first arg
- Vastly improved `@ast()`
- Refactored namespaces & other stuff. Much cleaned up! 
- Refactored to `interface`-driven extension system (rather than key-based)
- Clean up documentation files
- `@file(relative/path/to/file.whatever)` to include the trimmed contents of a file
- Cached lexer asts (in Lexer)
- Minor fixes
- new ApiLexer extension integrates with the PHPGrammar of my lexer library
{
    "name": "taeluf/code-scrawl",
    "type": "library",
    "description": "A documentation generation framework with some built-in extensions for exporting comments and code, and importing into markdown. ",
    "autoload": {
        "classmap":["src/"]
    },
    "license": "MIT",
    "require": {
        "taeluf/cli": "v0.1.x-dev",
        "taeluf/lexer": "v0.8.x-dev",
        "taeluf/better-regex": "v0.4.x-dev" 
    },
    "require-dev": {
        "taeluf/tester": "v0.3.x-dev"
    },
    "minimum-stability": "dev",
    "bin": [
        "bin/scrawl" 
    ]
}
{
    "_readme": [
        "This file locks the dependencies of your project to a known state",
        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
        "This file is @generated automatically"
    ],
    "content-hash": "ad297aaad40050f09f444c559e4b76fb",
    "packages": [
        {
            "name": "taeluf/better-regex",
            "version": "v0.4.x-dev",
            "source": {
                "type": "git",
                "url": "https://gitlab.com/taeluf/php/better-regex.git",
                "reference": "3ee2ff3482d8903d6977fa1fd97a227f4457dc54"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Fbetter-regex/repository/archive.zip?sha=3ee2ff3482d8903d6977fa1fd97a227f4457dc54",
                "reference": "3ee2ff3482d8903d6977fa1fd97a227f4457dc54",
                "shasum": ""
            },
            "require-dev": {
                "taeluf/code-scrawl": "v0.7.x-dev",
                "taeluf/tester": "v0.3.x-dev"
            },
            "default-branch": true,
            "type": "library",
            "autoload": {
                "classmap": [
                    "code"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "support": {
                "issues": "https://gitlab.com/taeluf/php/better-regex/-/issues",
                "source": "https://gitlab.com/taeluf/php/better-regex/-/tree/v0.4"
            },
            "time": "2022-03-28T20:55:32+00:00"
        },
        {
            "name": "taeluf/cli",
            "version": "v0.1.x-dev",
            "source": {
                "type": "git",
                "url": "https://gitlab.com/taeluf/php/cli.git",
                "reference": "12d7dd6b9a5a1fa0602405e579b807dd5b65a39d"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Fcli/repository/archive.zip?sha=12d7dd6b9a5a1fa0602405e579b807dd5b65a39d",
                "reference": "12d7dd6b9a5a1fa0602405e579b807dd5b65a39d",
                "shasum": ""
            },
            "require-dev": {
                "taeluf/code-scrawl": "v0.8.x-dev"
            },
            "default-branch": true,
            "bin": [
                "bin/tlf-cli"
            ],
            "type": "library",
            "autoload": {
                "files": [],
                "classmap": [
                    "src"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "support": {
                "issues": "https://gitlab.com/taeluf/php/cli/-/issues",
                "source": "https://gitlab.com/taeluf/php/cli/-/tree/v0.1"
            },
            "time": "2024-02-03T13:23:25+00:00"
        },
        {
            "name": "taeluf/lexer",
            "version": "v0.8.x-dev",
            "source": {
                "type": "git",
                "url": "https://gitlab.com/taeluf/php/lexer.git",
                "reference": "c019eb59d150f04ff8c16a19792b5d725046cd90"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Flexer/repository/archive.zip?sha=c019eb59d150f04ff8c16a19792b5d725046cd90",
                "reference": "c019eb59d150f04ff8c16a19792b5d725046cd90",
                "shasum": ""
            },
            "require": {
                "taeluf/util": "v0.1.x-dev"
            },
            "require-dev": {
                "taeluf/code-scrawl": "v0.8.x-dev",
                "taeluf/tester": "v0.3.x-dev"
            },
            "default-branch": true,
            "bin": [
                "bin/lex"
            ],
            "type": "library",
            "autoload": {
                "classmap": [
                    "src"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "description": "A declarative lexer seamlessly hooking into php functions, building ASTs for multiple languages.",
            "support": {
                "issues": "https://gitlab.com/taeluf/php/lexer/-/issues",
                "source": "https://gitlab.com/taeluf/php/lexer/-/tree/v0.8"
            },
            "time": "2024-02-03T15:33:41+00:00"
        },
        {
            "name": "taeluf/util",
            "version": "v0.1.x-dev",
            "source": {
                "type": "git",
                "url": "git@gitlab.com:taeluf/php/php-utilities.git",
                "reference": "95524064e9be1b587064c1661980fee20793a1a3"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Fphp-utilities/repository/archive.zip?sha=95524064e9be1b587064c1661980fee20793a1a3",
                "reference": "95524064e9be1b587064c1661980fee20793a1a3",
                "shasum": ""
            },
            "require-dev": {
                "taeluf/code-scrawl": "v0.8.x-dev",
                "taeluf/phtml": "v0.1.x-dev",
                "taeluf/tester": "v0.3.x-dev"
            },
            "default-branch": true,
            "type": "library",
            "autoload": {
                "classmap": [
                    "code"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "description": "Utility methods",
            "time": "2023-12-09T08:23:28+00:00"
        }
    ],
    "packages-dev": [
        {
            "name": "taeluf/tester",
            "version": "v0.3.x-dev",
            "source": {
                "type": "git",
                "url": "https://gitlab.com/taeluf/php/php-tests.git",
                "reference": "68b4623cd9c4ae8a7e7a6eaf0bacae6933cfa178"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Fphp-tests/repository/archive.zip?sha=68b4623cd9c4ae8a7e7a6eaf0bacae6933cfa178",
                "reference": "68b4623cd9c4ae8a7e7a6eaf0bacae6933cfa178",
                "shasum": ""
            },
            "require": {
                "taeluf/cli": "v0.1.x-dev",
                "taeluf/util": "v0.1.x-dev"
            },
            "require-dev": {
                "taeluf/code-scrawl": "v0.6.x-dev"
            },
            "default-branch": true,
            "bin": [
                "bin/phptest"
            ],
            "type": "library",
            "autoload": {
                "classmap": [
                    "src/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "description": "A unit testing library for Php.",
            "support": {
                "issues": "https://gitlab.com/taeluf/php/php-tests/-/issues",
                "source": "https://gitlab.com/taeluf/php/php-tests/-/tree/v0.3"
            },
            "time": "2024-01-10T13:40:51+00:00"
        }
    ],
    "aliases": [],
    "minimum-stability": "dev",
    "stability-flags": {
        "taeluf/cli": 20,
        "taeluf/lexer": 20,
        "taeluf/better-regex": 20,
        "taeluf/tester": 20
    },
    "prefer-stable": false,
    "prefer-lowest": false,
    "platform": [],
    "platform-dev": [],
    "plugin-api-version": "2.6.0"
}
<?php

namespace Tlf\Scrawl\FileExt;

/**
 * Export docblock content above `@export(key)`
 * @featured
 */
class ExportDocBlock {

    protected $regs = [
        'export.key' => '/\@export\(([^\)]*)\)/',
        'Exports' => '/((?:.|\n)*) *(\@export.*)/',
    ];

    /**
     * get an array of docblocks
     * @return array of docblocks, like `[0=>['raw'=>'/*...', 'clean'=>'...'], 1=>...]`
     */
    public function get_docblocks(string $str): array{
        $blocks = \Tlf\Scrawl\Utility\DocBlock::extractBlocks($str);
        return $blocks;
    }

    /**
     * get an array of exported text
     * @param $docblocks Array of docblocks. @see(get_docblocks())
     */
    public function get_exports(array $docblocks){
        $exports = [];
        foreach ($docblocks as $db){
            
            $comment = \Tlf\Scrawl\Utility\Main::trimTextBlock($db->clean);
            $reg = $this->regs['Exports'];
            $did_match = preg_match($reg, $comment, $matches);
            if (!$did_match)continue;

            $exported = \Tlf\Scrawl\Utility\Main::trimTextBlock($matches[1]);

            $key_portion = $matches[2];
            $did_match = preg_match($this->regs['export.key'], $key_portion, $key_matches);
            if (!$did_match)continue;
            $key = $key_matches[1];
            $exports[$key] = $exported;
        }

        return $exports;
    }

}
<?php

namespace Tlf\Scrawl\FileExt;

/**
 * Export code between `// @export_start(key)` and `// @export_end(key)`
 * @featured
 */
class ExportStartEnd {


    protected $regs = [
        'exports'=> 
            //For this regex: $1 is the key, $2 is the code, $3 is the @export_end line
            '/\ *(?:\/\/|\#)\ *@export_start\(([^\)]*)\)((?:.|\r|\n)+)\ *(?:\/\/|\#)\ *(@export_end\(\1\))/',
    ];

    public function __construct(){}

    public function get_exports($str){
        
        preg_match_all($this->regs['exports'], $str, $matches, PREG_SET_ORDER);
        // print_r($matches);

        $exports = [];
        foreach ($matches as $index=>$m){
            $exports[$m[1]] = \Tlf\Scrawl\Utility\Main::trimTextBlock($m[2]);
        }

        return $exports;
    }

}
<?php

namespace Tlf\Scrawl\Ext;

class Main {

    public function copy_readme($scrawl){
        $content = $scrawl->read_file('README.md');
        $scrawl->write_doc('README.md', $content);
    }

    // public function write_exports_list(){
    //     // I'm not planning to re-implement this ... though i am leaving around the old code in case i change my mind
    // }

}

<?php

namespace Tlf\Scrawl\FileExt;

/**
 * Integrate the lexer for PHP files
 */
class Php {

    public \Tlf\Scrawl $scrawl;

    public function __construct(\Tlf\Scrawl $scrawl){
        $this->scrawl = $scrawl;
    }


    public function get_all_classes(){
        $asts = $this->scrawl->get_group('ast');
        $classes = [];
        foreach ($asts as $k=>$a){
            var_dump($k);
            if (substr($k,0,6)!='class.')continue;
            $classes[$a['fqn']] = $a;
        }

        return $classes;
    }

    public function set_ast(array $ast){
        // set class asts
        $classes = array_merge($ast['class']??[], $ast['namespace']['class']??[]);
        foreach ($classes as $c){
            $this->scrawl->set('ast','class.'.$c['name'], $c);
        }

        // set file asts
        // foreach ($ast as $a){
            // if ($a['type']=='file')
        // }

    }

    /**
     * Parsed `$str` into an ast (using the Lexer)
     * @param $str a string to parse
     * @return array ast
     */
    public function parse_str(string $str): array{

        $lexer = new \Tlf\Lexer();
        // $lexer->addGrammar(new \Tlf\Lexer\PhpGrammar());
        
        $ast = new \Tlf\Lexer\Ast('file');
        $phpGram = new \Tlf\Lexer\PhpGrammar();
        $lexer = new \Tlf\Lexer();
        $lexer->debug = false;
        $lexer->addGrammar($phpGram);

        // the first directive we're listening for
        $lexer->addDirective($phpGram->getDirectives(':php_open')['php_open']);

        ob_start();
        // runs the lexer with $ast as the head
        $ast = $lexer->lex($str, $ast);
        ob_end_clean();

        return $ast->getTree();
    }

    /**
     * Parsed `$str` into an ast (using the Lexer)
     *
     * @param $file_path a relative file path to parse (relative to dir.root). MAY be an absolute path...
     * @return array ast
     */
    public function parse_file(string $file_path): array {

        // $lexer->addGrammar(new \Tlf\Lexer\PhpGrammar());

        $abs_path = $this->scrawl->dir_root.'/'.$file_path;
        if (!file_exists($abs_path)){
            $abs_path = $file_path;
        }
        
        $phpGram = new \Tlf\Lexer\PhpGrammar();
        $phpGram->directives = array_merge(
            $phpGram->_string_directives,
            $phpGram->_core_directives,
        );
        $lexer = new \Tlf\Lexer();
        $lexer->useCache = true;
        $lexer->debug = false;
        $lexer->addGrammar($phpGram, null, false);

        // the first directive we're listening for
        $lexer->addDirective($phpGram->getDirectives(':php_open')['php_open']);

        ob_start();
        // runs the lexer with $ast as the head
        $ast = $lexer->lexFile($abs_path);
        // $ast = new \Tlf\Lexer\Ast('file');
        // $ast = $lexer->lex(file_get_contents($abs_path), $ast);
        ob_end_clean();

        return $ast->getTree();
    }


    /**
     * use the ast to create docs using the classList template
     *
     * @return array of files like `['rel/path'=>'file content']`
     */
    public function make_docs(array $ast){
        $files = [];

        $classes = $ast['class'] ?? $ast['namespace']['class'] ?? [];;
        foreach ($classes as $class){
            $out = $this->scrawl->get_template('ast/class', [null, $class, null]);
            $path = $class['fqn'];
            $path = str_replace('\\','/', $path).'.md';
            $files['class/'.$path] = $out;
        }

        $traits = $ast['trait'] ?? $ast['namespace']['trait'] ?? [];;
        foreach ($traits as $trait){
            $out = $this->scrawl->get_template('ast/class', [null, $trait, null]);
            $path = $trait['fqn'];
            $path = str_replace('\\','/', $path).'.md';
            $files['trait/'.$path] = $out;
        }

        return $files;
    }
}
<?php

namespace Tlf\Scrawl;

/**
 * Class purely exists to test that extensions work
 */
class TestExtension implements \Tlf\Scrawl\Extension {


    /**
     * a scrawl instance
     */
    protected \Tlf\Scrawl $scrawl;

    public function __construct(\Tlf\Scrawl $scrawl){
        $this->scrawl = $scrawl;
        $this->scrawl->good("TestExtension::__construct", "good");
    }

    public function bootstrap(){
        $this->scrawl->good("TestExtension::bootstrap()","good");
    }


    public function ast_generated(string $className, array $ast){
        $this->scrawl->good("TestExtension::ast_generated()","good");
    }

    public function astlist_generated(array $asts) {
        $this->scrawl->good("TestExtension::astlist_generated()","good");
    }

    public function scan_filelist_loaded(array $code_files){ 
        $this->scrawl->good("TestExtension::scan_filelist_loaded()","good");

    }

    public function scan_file_processed(string $path, string $relPath, string $file_content, array $file_exports){ 
        $this->scrawl->good("TestExtension::scan_file_processed()","good");
    }

    public function scan_filelist_processed(array $code_files, array $all_exports){ 
        $this->scrawl->good("TestExtension::scan_filelist_processed()","good");

    }

    public function doc_filelist_loaded(array $doc_files, \Tlf\Scrawl\Ext\MdVerbs $mdverb_ext){ 
        $this->scrawl->good("TestExtension::doc_filelist_loaded()","good");

    }

    public function doc_file_loaded($path,$relPath,$file_content){ 
        $this->scrawl->good("TestExtension::doc_file_loaded()","good");

    }

    public function doc_file_processed($path,$relPath,$file_content){ 
        $this->scrawl->good("TestExtension::doc_file_processed()","good");

    }

    public function doc_filelist_processed($doc_files){ 
        $this->scrawl->good("TestExtension::doc_filelist_processed()","good");

    }

    public function scrawl_finished(){ 
        $this->scrawl->good("TestExtension::scrawl_finished()","good");

    }


}
<?php

namespace Tlf\Scrawl;

/**
 * Literally does nothing except the constructor and $scrawl property. Just a base class to save boilerplate on the interface
 */
class DoNothingExtension implements \Tlf\Scrawl\Extension {


    /**
     * a scrawl instance
     */
    protected \Tlf\Scrawl $scrawl;

    public function __construct(\Tlf\Scrawl $scrawl){
        $this->scrawl = $scrawl;
        $this->scrawl->good("TestExtension::__construct", "good");
    }

    public function bootstrap(){}

    public function ast_generated(string $className, array $ast){}

    public function astlist_generated(array $asts) {}

    public function scan_filelist_loaded(array $code_files){ }

    public function scan_file_processed(string $path, string $relPath, string $file_content, array $file_exports){ }

    public function scan_filelist_processed(array $code_files, array $all_exports){ }

    public function doc_filelist_loaded(array $doc_files, \Tlf\Scrawl\Ext\MdVerbs $mdverb_ext){ }

    public function doc_file_loaded($path,$relPath,$file_content){ }

    public function doc_file_processed($path,$relPath,$file_content){ }

    public function doc_filelist_processed($doc_files){ }

    public function scrawl_finished(){ }


}
<?php

namespace Tlf\Scrawl\Ext\MdVerb;

class Ast {

    public \Tlf\Scrawl $scrawl;

    public function __construct($scrawl){
        $this->scrawl = $scrawl;
    }

    /**
     * Get an ast & optionally load a custom template for it
     *
     * @usage @ast(class.ClassName.methods.docblock.description, ast/default)
     */
    public function get_markdown($key, $template='ast/default'){
        $value = $this->get_ast($key);
        $template = $this->scrawl->get_template($template, [$key, $value, $this]);
        return $template;
    }

    /**
     * @param $key a dotproperty like `class.ClassName.methods.MethodName.docblock.description`
     * @param $length the number of dots in the dotproperty to traverse. -1 means all
     */
    public function get_ast(string $key, int $length=-1){
        $parts = explode('.',$key);
        if ($length!=-1){
            $parts = array_slice($parts, 0,$length);
        }
        $group = array_shift($parts);
        $class = array_shift($parts);
        $ast = $this->scrawl->get('ast', $group.'.'.$class);

        if ($ast==null){
            $this->scrawl->warn("Ast $group not found", "Can't load '$class'.");
            return;
        }

        // echo "\n\nAST:";
        // var_dump($ast);
        // var_dump($group);
        // var_dump($class);
        // echo "\n\n";

        $stack = $group.'.'.$class;
        $next = $ast;
        foreach ($parts as $p){
            $current = $next;
            $stack .= '.'.$p;

            // echo "\n\nStack: $stack";
            if (!isset($current[$p])&&is_array($current)){
                foreach ($current as $i=>$item){
                    if (!is_numeric($i))continue;
                    echo "\n\n".$p."::";
                    echo $item['name']."\n\n";
                    if ($item['name']==$p){
                        $next = $item;
                        continue 2;
                    }
                }
                // echo "Current: ";
                // print_r($current);
                $this->scrawl->warn("Ast Not Found", "Can't load '$key'. Failed at '$current.$p'");
                return null;
                break;
                echo "\n\nFailed at ".$stack;
                echo "\n\nsomething went wrong\n\n";
                exit;
            } else if (!isset($current[$p])){
                $this->scrawl->warn("Ast Not Found", "Can't load '$key'. Failed at '$p'");
                return null;
                echo "\n\ncan't get next item\n\n";
                exit;
            }

            $next = $current[$p];
        }

        // exit;
        return $next;
    }

    public function getVerbs(): array{
        return [
            'ast'=>'verbAst', //alias for @ast_class()
            'classMethods'=>'getClassMethodsTemplate',
            'ast_class'=> 'getAstClassInfo',
        ];
    }

    /**
     *
     * @param $fqn The fully qualified name, like a class name or function with its namespace
     * @param $dotProperty For class, something like 'methods.methodName.docblock' to get a docblock for the given class. 
     *
     * @example @ast(\Tlf\Scrawl\Ext\MdVerb\Ast, methods.getAstClassInfo.docblock)
     * @mdverb ast
     *
     */
    public function getAstClassInfo(array $info, string $fqn, string $dotProperty){
        // @ast(class,Phad\Test\Documentation,methods.testWriteAView.docblock)
        
        $class = $this->scrawl->getOutput('astClass', $fqn);

        // var_dump(array_keys($this->scrawl->getOutputs('astClass')));

        if ($class == 'null') return "class '$fqn' not found in ast.";
    


        $propStack = explode('.', $dotProperty);

        $head = $class;
        if (!is_array($head)){
            $file = $info['file']->path;
            // $this->scrawl->error('@ast or @ast_class in '.$file,'requires "astClass" output for fqn "'.$fqn.'" to be an array, but a '. gettype($class).' was returned.');
            $this->scrawl->error("@ast($fqn, $dotProperty) failed", 'in '.$file);
            return "@ast($fqn) failed";
        }
        foreach ($propStack as $prop){
            if ($prop=='*'){
                return print_r($head,true);
            }
            
            if (!isset($head[$prop])){
                $options =  [];
                foreach ($head as $key=>$value){
                    if (is_numeric($key) && ($value['name']??null)==$prop){
                        $head = $head[$key];
                        continue 2;
                    } else if (is_numeric($key) && isset($value['name'])){
                        $options[] = $value['name'];
                    }
                }
                $options = array_merge($options, array_keys($head));
                $msg = "Cannot find '$prop' part of '$dotProperty' on '$fqn'. You may try one of: ". implode(", ", $options);
                $this->scrawl->error('@ast or @ast_class', $msg);
                return $msg;
            }
            $head = $head[$prop];
        }

        if (is_array($head)){
            if (isset($head['body']))return $head['body'];
            else if (isset($head['description']))return $head['description'];
            else if (isset($head['src']))return $head['src'];
            $msg="Found an array for '$dotProperty' on '$fqn' with keys: ".implode(", ", array_keys($head));
            $this->scrawl->error('@ast or @ast_class', $msg);
            return $msg;
        }

        return $head;
    }

    /**
     *
     * @return string replacement
     */
    public function verbAst($info, $className, $dotProperty){

        //
        // This method not currently functional. Ugggh!!!
        //

        // $parts = explode('.', $classDotThing);
        // $class = array_shift($parts);
        // return $this->getAstClassInfo($info, $class, 'method.'.implode('.',$parts));
        return $this->getAstClassInfo($info, $className, $dotProperty);
        // $key = $class;
        // var_dump($key);
        // $output = $this->scrawl->getOutput('api',$key);
//
        // if (trim($output)=='')return "--ast '${class}' not found--";
//
        // return $output;
    }

    public function getClassMethodsTemplate($verb, $argListStr, $line){
        if ($verb!='classMethods')return;

        $args = explode(',', $argListStr);

        $className = $args[0];
        $visibility = '*';
        if (isset($args[1])){
            $visibility = trim($args[1]);
        }
        
        $class = $this->scrawl->getOutput('astClass', $className);

        $template = dirname(__DIR__,2).'/Template/classMethods.md.php';
        ob_start();
        require($template);
        $final = ob_get_clean();
        return $final;
    }

}
<?php

namespace Tlf\Scrawl\Ext\MdVerb;

class MainVerbs {

    /**
     * a scrawl instance
     */
    public \Tlf\Scrawl $scrawl;

    public function __construct(\Tlf\Scrawl $scrawl){
        $this->scrawl = $scrawl;
    }

    /**
     * add callbacks to `$md_ext->handlers`
     */
    public function setup_handlers(\Tlf\Scrawl\Ext\MdVerbs $md_ext){
        $handlers = [
            'import'=>'at_import',
            'file' => 'at_file',
            'template'=> 'at_template',
            'link'=> 'at_link',
            'easy_link'=> 'at_easy_link',
            'hard_link'=> 'at_hard_link',
            'see_file'=> 'at_see_file',
            'see'=> 'at_see_file',
            'system' => 'at_system',
        ];
        foreach ($handlers as $verb=>$func_name){
            $md_ext->handlers[$verb] = [$this, $func_name];
        }
    }

    // public function okay(){}

    /**
     * Run a command on the computer's operating system.
     *
     * Supported options: `trim`, `trim_empty_lines`, `last_x_lines, int`
     *
     * @param $system_command string command to run on the system, like `git log`
     * @param $options array of options. 
     *
     * @return whatever is output by the system command
     */
    public function at_system(string $system_command, ...$options){
        //if (substr($system_command,0,3) == 'git'){
            //echo "\n$system_command\n";
            //exit;
        //}

        $this->scrawl->good("@system()", $system_command);
        
        ob_start();
        system("$system_command");
        $output = ob_get_clean();

        if (in_array('trim', $options)){
            $output = trim($output);
        }

        if (in_array('trim_empty_lines', $options)){
            $parts = explode("\n", $output);
            while ($parts[0] == ''){
                array_shift($parts);
            }

            while ($parts[count($parts)-1] == ''){
                array_pop($parts);
            }

            $output = implode("\n", $parts);
        }

        if (in_array('last_x_lines', $options)){
            $index = array_search('last_x_lines', $options);
            $x = $options[$index+1];
            $lines = explode("\n", $output);
            $last_x_lines = array_slice($lines,-((int)$x));
            $output = implode("\n", $last_x_lines);
        }

        return $output;
    }

    /**
     * Load a template
     * @usage @template(template_name, arg1, arg2)
     */
    public function at_template(string $templateName, ...$templateArgs){
        return $this->scrawl->get_template($templateName, $templateArgs);
    }

    /**
     * Import something previously exported with `@export` or `@export_start/@export_end`
     *
     * @usage @import(Namespace.Key)
     * @output whatever was exported by @export or @export_start/_end
     */
    public function at_import(string $key){
        $output = $this->scrawl->get('export',$key);

        if ($output===null){
            $this->scrawl->warn('@import', '@import('.$key.') failed');
            $replacement = '# Import key "'.$key.'" not found.';
        } else {
            $replacement = $output;
        }
        return $replacement;
    }

    /**
     * Copy a file's content into your markdown.
     *
     * @usage @file(rel/path/to/file.ext)
     * @output the file's content, `trim`med.
     */
    public function at_file(string $relFilePath){
        $file = $this->scrawl->dir_root.'/'.$relFilePath;

        if (!is_file($file)){
            $this->scrawl->warn('@file', "@file($relFilePath) failed. File does not exist.");
            return "'$file' is not a file.";
        }

        return trim(file_get_contents($file));
    }

    /**
     * Get a link to a file in your repo
     *
     * @usage @see_file(relative/file/path)
     * @output `[relative/file/path](urlPath)`
     */
    public function at_see_file(string $relFilePath, ?string $link_name = null){
        $path = $this->scrawl->dir_root.'/'.$relFilePath;
        if (!is_file($path) && !is_dir($path)){
            $this->scrawl->warn("@see_file","@see_file($relFilePath): File does not exist");
        }
        $urlPath = $relFilePath;
        if ($urlPath[0]!='/')$urlPath = '/'.$urlPath;
        $link_name = $link_name ?? $relFilePath;
        $link = '['.$link_name.']('.$urlPath.')';
        return $link;
    }


    /** just returns a regular markdown link. In future, may check validity of link or do some kind of logging 
     *
     * @usage @hard_link(https://url.com, LinkName)
     * @output [LinkName](https://url.com)
     */
    public function at_hard_link(string $url, string $name=null){
        if ($name==null) $name = $url;
        return '['.$name.']('.$url.')';
    }

    /** 
     * Output links configured in your config json file.
     * Config format is `{..., "links": { "link_name": "https://example.org"} }`
     *
     * @usage @link(phpunit)
     * @output [LinkName](https://url.com)
     */
    public function at_link(string $link_name, ?string $alternative_text = null){
        $url = $this->scrawl->options['links'][$link_name] ?? null;
        if ($url == null){
            $this->scrawl->warn("Link not found", "Your config json does not include link \"$link_name\". Define like: `\"links\":{\"$link_name\": \"https://example.com\"}`");
            return '(*error: link "'.$link_name.'" not found*)';
        }

        $header = "Link printed ($link_name)";

        if ($alternative_text!=null)$link_name = $alternative_text;

        $mdlink = '['.$link_name.']('.$url.')';

        $this->scrawl->good($header, $mdlink);

        return $mdlink;
    }

    /**
     * Get a link to common services (twitter, gitlab, github, facebook)
     *
     * @usage @easy_link(twitter, TaelufDev)
     * @output [TaelufDef](https://twitter.com/TaelufDev)
     * @todo support a third param 'LinkName' so the target and link name need not be identical
     */ 
    public function at_easy_link(string $service, string $target){
        $sites = [
            'twitter'=>'https://twitter.com/',
            'gitlab'=>'https://gitlab.com/',
            'github'=>'https://github.com/',
            'facebook'=>'https://facebook.com/',
            'tlf'=>'https://tluf.me/',
        ];

        $host = $sites[strtolower($service)] ?? null;
        if ($host==null){
            $this->scrawl->warn('@easy_link', "@easy_link($service,$target): Service '$service' is not valid. Options are "
                .implode(', ', array_keys($sites))
            );
            return "--service '$service' not found--";
        }
        $url = $host.$target;
        $linkName = $target;
        $mdLink = "[$linkName]($url)";
        return $mdLink;
    }

}
<?php

namespace Tlf\Scrawl\Ext;

/**
 * Runs `@mdverb` extensions, enabling special callbacks for `@verb()`s in `.src.md` files
 */
class MdVerbs { 

    protected $regs = [
        /**
         * Separates an `@mdverb(arg1,arg2)` into $1=mdverb, $2=arg1,arg2
         */
        'verb' =>'/(?<!\\\\)\@([a-zA-Z_]+)\(([^\)]*)\)/m',
    ];

    /** 
     * array of verb handlers
     * 
     * @key the verb
     * @value a callable, where arg list is the arguments in the `@mdverb(arg1,arg2)` like `$handler('arg1', 'arg2')`
     *
     */
    public $handlers = [];

    public ?\Tlf\Scrawl $scrawl;

    public function __construct(?\Tlf\Scrawl $scrawl=null){
        $this->scrawl = $scrawl;
    }

    /**
     * Get all `@verbs(arg1, arg2)` 
     * @return array of verb arrays ... the verb array contains `string src`, `string verb`, and `array args`
     */
    public function get_verbs(string $str): array {
        $reg = $this->regs['verb'];
        preg_match_all($reg, $str, $matches, PREG_SET_ORDER);

        $verbs = [];
        foreach ($matches as $m){
            $verb = [];
            $verb['src'] = $m[0];
            $verb['verb'] = $m[1];
            // `$m[2]` is like `arg1, arg2, arg3`, so i expode on `,` & `trim` with array_map
            $verb['args'] = 
                array_map('trim',
                    explode(',',$m[2])
                );
            $verbs[] = $verb;
        }
        return $verbs;
    }

    /**
     * Get all verbs, execute them, and replace them within the doc
     * @param $doc a documentation file's content
     */
    public function replace_all_verbs(string $doc): string{
        $verbs = $this->get_verbs($doc);

        $out = $doc;
        foreach ($verbs as $v){
            $replacement = $this->run_verb($v['src'], $v['verb'], $v['args']);
            $out = str_replace($v['src'], $replacement, $out);
        }
        return $out;
    }

    /**
     * Execute a verb handler and get its output 
     *
     * @param $src the source code for the mdverb, like `@mdverb(arg1,arg)`
     * @param $verb the verb like `mdverb`
     * @param $args an array of the args like `['arg1', 'arg2']`
     *
     * @return string that should replace the `@verb()` call
     */
    public function run_verb(string $src, string $verb, array $args): string {
        if (!isset($this->handlers[$verb])){
            $this->scrawl->warn("MdVerb has no handler", "@$verb()");
            // return '<!-- MdVerb `@'.$verb.'()` has no handler -->';
            return $src;
        }
        $handler = $this->handlers[$verb];
        try {
            $ret = $handler(...$args);
        } catch (\ArgumentCountError $e){
            // @TODO need to use scrawl->warn()
            //
            echo "\n\nARGUMENT COUNT ERROR ... error reporting incomplete ... see code/Ext/MdVerbs.php";
            echo "\n\n";
            throw $e;

//
            // return '';
            // $class = get_class($callable[0]);
            // $method = $callable[1];
            // echo "\n\n";
            // echo "\nCannot call $class->$method() becuase of an argument count error.";
//
            // echo "\n\n";
            // echo "Error caused by: \n";
            // $info = (array)$info;
            // $info['file'] = (array)$info['file'];
            // $info['file']['content'] = '--content is removed from var dump for readability--';
            // print_r($info);
//
            // echo "\n\n";
            // throw $e;
        }

        if (!is_string($ret)){

            $args_str = implode(', ', $args);
            $type = gettype($ret);
            throw new \TypeError("Verbs must return strings. @$verb($args_str) returned $type");
        }
        return $ret;
    }

}
<?php
/**
 * @param $args[0] the key pointing to the ast, must begin with `class.ClassName`
 * @param $args[1] array class ast
 * @param $args[2] is the AstVerb class instance
 */
$Class = $class = $args[1];


// echo "\n\n\n-----------\n\n";
// var_dump($Class);
// exit;

if ($Class['type']=='class')$type = 'class';
else $type = 'trait';

$class_name = $class['fqn'] ?? $class['name'];
?>
# <?= $type .' '. $class_name ?>
<?="\n".($Class['docblock']['description']??'')?>

<?php
if (class_exists($class_name, true)){
    $refClass = new \ReflectionClass($class_name);
    $file = $refClass->getFileName();
    $rel = $this->parse_rel_path($this->dir_root, $file);

    if ($rel != null){
        echo "See source code at [$rel]($rel)\n";
    }
}

?>

## Constants
<?php
foreach ($Class['const']??[] as $constant){
    $def = $constant['declaration'] ?? '--declaration-missting--';
    $descript = $constant['docblock']['description']??'';
    echo "- `${def}` ${descript}\n";
}

?>

## Properties
<?php
foreach ($Class['properties']??[] as $prop){
    $def = $prop['declaration'] ?? '--declaration-missting--';
    $descript = $prop['docblock']['description']??'';
    echo "- `${def}` ${descript}\n";
}

?>

## Methods 
<?php
foreach ($Class['methods']??[] as $method){
    // var_dump($method);
    // exit;
    // if (isset($method['declaration']) && !is_null($method['declaration'])){
    $def = $method['declaration'] ?? '--declaration-missing--';
    // } else $this->warn("Method declaration missing:", "For class ".$Class['name']);
    // $descript = $method['description'];
    $descript = $method['docblock']['description']??'';
    // var_dump($method['docblock']);
    // if (is_array($method['docblock']));
    // exit;
    echo "- `${def}` ${descript}\n";
}

?>

<?php
// static props/functions are not yet separated out by the lexer
return;

?>

## Static Properties 
<?php
foreach ($Class['staticProps']??[] as $prop){
    $def = $prop['definition'];
    $descript = $prop['description'];
    echo "- `${def}` ${descript}\n";
}

?>

## Static functions
<?php
foreach ($Class['staticFunctions']??[] as $func){
    $def = $func['definition'];
    $descript = $func['description'];
    echo "- `${def}` ${descript}\n";
}

<?php
/**
 * @param $args[0] the key pointing to the ast, must begin with `class.ClassName`
 * @param $args[1] array class ast
 * @param $args[2] is the AstVerb class instance
 */
$class = $args[1];

$instanceArg = '$'.lcfirst($class['name']);
$visibility = '*';

foreach ($class['methods'] as $m):

    // print_r($m);
// exit;
    $declare = substr($m['declaration'], 0, strpos($m['declaration'], '('));
    $declareParts = explode(' ', $declare);
    if ($visibility!=='*'){
        if (!in_array($visibility, $declareParts))continue;
    }
    $isStatic = false;
    if (in_array('static',$declareParts))$isStatic = true;


    $pos = strpos($m['declaration'],$m['name']);
    $cleanDefinition = substr($m['declaration'],$pos);
    // $pos = strpos($cleanDefinition, '{');
    // $cleanDefinition = trim(substr($cleanDefinition,0,$pos));

    //special declaration conversions:
    // static should be ClassName::method(...)
    // __construct should be new ClassName(...)
    // other should be $className->method(...)

    if ($m['name']=='__construct'){
        $cleanDefinition = $instanceArg.' = new '.$class['name'].substr($cleanDefinition,strlen('__construct'));
    } else if ($isStatic){
        $cleanDefinition = $class['name'].'::'.$cleanDefinition;
    } else {
        $cleanDefinition = $instanceArg.'->'.$cleanDefinition;
    }


    $description = $m['dockblock']['tip']??$m['docblock']['description']??'';
    $description = str_replace("\n", "\n    ", $description);
    $description = trim($description);
?>
- `<?=$cleanDefinition?>`: <?=$description?>

<?php
    foreach ($m['docblock']??[] as $verb=>$text){
        if ($verb=='src'||$verb=='description'||$verb=='type'||$verb=='tip')continue;
        if (is_array($text))continue;
        if (is_array($text))$text = $text['description']??'';
        echo "    - `@$verb`: $text\n";
    }
endforeach;

// print_r($class);
<?php
/**
 * @param $args[0] the key pointing to the ast, must begin with `class.ClassName`
 * @param $args[1] string or array ... whatever the key pointed at 
 * @param $args[2] is the AstVerb class instance
 */
$key = $args[0];

if (is_array($args[1])){
    // $this->warn("Cannot show ast $key.", "it is an array");
    echo "@ast($key) is an array";
} else {
    echo $args[1];
}

<?php
/**
 * @param $args[0] the key pointing to the ast, must begin with `class.ClassName`
 * @param $args[1] array file ast
 * @param $args[2] the AstVerb class instance
 */
$File = $args[1];

?>
# File <?=$File['relPath']?>

## Functions
<?php
foreach ($File['functions'] ??[] as $function){
    $descript = $function['docblock']['tip'] ?? $function['docblock']['description'] ?? '';
    $name = $function['name'];
    echo "- `$name`: $descript\n";
}
<?php
/**
 * @param $args[0] the key pointing to the ast, must begin with `class.ClassName`
 * @param $args[1] a method ast array
 * @param $args[2] is the AstVerb class instance
 */
$key = $args[0];
$method = $args[1];
$ext = $args[2];

$method_name = $method['name'];
$class = $ext->get_ast($key, 2);
$class_name=$class['name'];
?>
# <?=$class_name?>::<?=$method_name?>  
<?=$method['docblock']['description']??'no description';?>

<?php
/**
 * This template is to debug your mdtemplate
 *
 * @param $args[0] the key pointing to the ast, must begin with `class.ClassName`
 * @param $args[1] string or array ... whatever the key pointed at 
 * @param $args[2] is the AstVerb class instance
 */
$key = $args[0];

echo "---DEBUG_SCRAWL_AST_VERB---"
    ."\nKey:$key"
    ."\nAST Value: \n".print_r($args[1],true)
    ."\nAST Verb class instances: \n".var_export($args[2], true);
<?php
/**
 * Template to show all classes & traits within a repo.
 *
 * Template to be used by PHP code, not to be included by a .src.md file.
 * TODO: Support interfaces
 *
 * @param $args[0] array<string fully_qualified_classname, array $ast> ASTs for each class scanned within the repo.
 * @param $args[1] array<string fully_qualified_traitname, array $ast> ASTs for each trait scanned within the repo.
 */

//print_r($args);
//exit;

$class_list = array_merge(
    // array shift to reduce memory footprint, i guess.
    array_shift($args),
    array_shift($args)
);


$test_classes = [];
$src_classes = [];
$traits = [];

$count = count($class_list);

while ($class = array_pop($class_list)){
    $file = str_replace('//','/',$class['file']);

    $class_basename = $class['name'];
    $class_docs = $file.'.md';
    $description = $class['docblock']['description'] ?? 'No description...';
    $description = str_replace("\n", "\n    ", trim($description));

    $class_markdown = "- [`$class_basename`]($class_docs): $description"."  ";


    if ($class['type'] == 'trait'){
        //print_r($class);
        //exit;
        $traits[] = $class_markdown;
    } else if (substr($file,0,5)=='test/'
        ||substr($file,0,6)=='tests/'){
        $test_classes[] = $class_markdown;
    } else {
        $src_classes[] = $class_markdown;
    }
}

?>
<!-- Project Classlist generated by ast/ApiReadme template. -->
<!-- To Disable: Set api.generate_readme = false in your config.json -->
# All Classes
Browse <?=$count?> classes &amp; traits in this project. There are <?=count($src_classes)?> source classes, <?=count($test_classes)?> test classes, and <?=count($traits)?> traits.

*Note: As of Dec 23, 2023, only classes &amp; traits are listed. interfaces &amp; enums are not supported.*

## Source Classes (not tests)
<?php
    echo implode("\n", $src_classes);
    echo "\n\n";
?>

## Traits
<?php
    echo implode("\n", $traits);
    echo "\n\n";
?>

## Test Classes 
<?php
    echo implode("\n", $test_classes);
    echo "\n\n";
?>
<?php
/**
 * @param $args[0] the name of the executable command
 * @param $args[1] relative path to executable file within the repo
 */
$command=$args[0];
$execFile=$args[1];
$git_clone_url = \Tlf\Scrawl\Utility\Main::getGitCloneUrl();

?>
```bash
pwd="$(pwd)";
command="<?=$command?>"
downloadDir=~/.gitclone
mkdir -p "$downloadDir"
cd "$downloadDir"
git clone <?=$git_clone_url?> ${command} 
echo "alias ${command}=\"${downloadDir}/${command}/<?=$execFile?>\"" >> ~/.bashrc
chmod ug+x "${downloadDir}/${command}/<?=$execFile?>"
cd "$pwd";
source ~/.bashrc
echo "You can now run \`${command}\`"
```
<?php
/**
 * Display composer install instructions for your library
 *
 * @usage `@template(composer_install, vendor/package, ?version)`
 *
 * @param $args[0] package name like `taeluf/code-scrawl`
 * @param $args[1] (optional) branch name ... defaults to current branch
 */


$package = $args[0] ?? \Tlf\Scrawl\Utility\Main::getComposerPackageName();
if ($package==null){
    $this->scrawl->warn("Cannot find composer.json file at ".getcwd().'/composer.json, nor was package name passed to @template(composer_install, vendor/package)');
    echo "--cannot print composer install instructions because package name was not passed--";
    return;
}
$version = $args[1] ?? \Tlf\Scrawl\Utility\Main::getCurrentBranchForComposer();

?>
```bash
composer require <?=$package.' '.$version?> 
```
or in your `composer.json`
```json
{"require":{ "<?=$package?>": "<?=$version?>"}}
```
<?php
/**
 * Display composer install instructions for your library
 *
 * @usage `@template(composer_install, vendor/package, ?version)`
 *
 * @param $args[0] package name like `taeluf/code-scrawl`
 * @param $args[1] (optional) branch name ... defaults to current branch
 */


$package = $args[0] ?? \Tlf\Scrawl\Utility\Main::getComposerPackageName();
if ($package==null){
    $this->scrawl->warn("Cannot find composer.json file at ".getcwd().'/composer.json, nor was package name passed to @template(composer_install, vendor/package)');
    echo "--cannot print composer install instructions because package name was not passed--";
    return;
}
$version = $args[1] ?? \Tlf\Scrawl\Utility\Main::getCurrentBranchForComposer();

echo "`composer require $package $version`";
<?php
/**
 * @param $args[0] array of classes
 */
ob_start();
$classes = $args[0] ?? $this->get_all_classes();
ob_end_clean();

?>
# All Classes
Documentation generated by @easy_link(tlf, php/code-scrawl)

<?php
// print_r(array_keys($objects));
foreach ($classes as $fqn=>$class):

    // print_r($class);
    $name_path = str_replace('\\','/', $class['fqn']);
?>
## <?=$class['fqn']??$class['name']?>  
<?=$class['docblock']['description'] ?? 'no docblock'?>  
See [<?=$class['name']?>.php](/docs/api/<?=$class['file']?>.md) for more.


<?php
endforeach;

<?php
echo "`git log` on ".date('r'). "  \n";
system("git log --pretty=format:'- %h %d %s [%cr]' --abbrev-commit");
<?php
<?php

namespace Tlf\Scrawl\Utility;

/**
 *
 * @featured
 */
class DocBlock {

    public $raw;
    public $clean;

    public function __construct($rawBlock, $cleanBlock){
        $this->raw = $rawBlock;
        $this->clean = $cleanBlock;
    }

    static protected $regex = [
        // @TODO Make a less strict regex
        'DocBlock./**' => ['/((\/\*\*.*\n)( *\*.*\n)* *\*\/)/'],
        'DocBlock./**.removeBlockOpen' => '/(^\/\*\*)/',
        'DocBlock./**.removeLineOpenAndBlockClose' => '/(\n\s*\* ?\/?)/',
    ];


    static public function DocBlock($name, $match, $nullFile, $info){
        $clean = static::cleanBlock($match[0], null);
        $docBlock = new static($match[0], $clean);


        return $docBlock;
    }

    static public function extractBlocks($fileContent){
        /**
         * when `static::$regex['DocBlock./**']` is matched, `static::DocBlock('DocBlock',...)` is called
         */
        $blocks = \Tlf\Scrawl\Utility\Regex::matchRegexes(static::class, 
                    ['DocBlock'=>static::$regex['DocBlock./**']]
                    , null, $fileContent);

        return $blocks;
    }

    static public function cleanBlock($rawBlock){
        $docBlock = 
            preg_replace(
                [   static::$regex['DocBlock./**.removeBlockOpen'], 
                    static::$regex['DocBlock./**.removeLineOpenAndBlockClose']
                ],
                ["", "\n"],
                $rawBlock
            );
        $docBlock = trim($docBlock);

        $docBlock = Main::trimTextBlock($docBlock);
        
        return $docBlock;

    }

}
<?php

namespace Tlf\Scrawl\Utility;

class Main {

    static protected $classMap=[];

    static protected $isRegistered=false;

    static public function spl_autoload($class){
        $class = '\\'.$class;
        if (!isset(static::$classMap[$class]))return;
        $file = static::$classMap[$class];
        unset(static::$classMap[$class]);
        require($file);
    }
    static public function autoload($dir){
        if (!static::$isRegistered){
            static::$isRegistered = true;
            spl_autoload_register([get_class(), 'spl_autoload']);
            require_once(__DIR__.'/Php.php');
        }
        $files = static::allFilesFromDir($dir, '', ['.php']);
        
        foreach ($files as $f){
            $class = Utility\Php::getClassFromFile($f->path);
            if (trim($class)=='')continue;
            // require_once($f->path);
            static::$classMap[$class] = $f->path;
        }

        // print_r(static::$classMap);
    }
    /** trim a block of text
     */
    static public function trimTextBlock($textBlock){
        $textBlock = static::removeLeftHandPad($textBlock);
        //remove blank lines at beginning
        $textBlock = preg_replace('/^(\s*\n)+/','',$textBlock);
        //remove blank lines at end
        $textBlock = preg_replace('/(\n\s*)+$/','',$textBlock);
        return $textBlock;
    }

    /**
     *  Trim the leading spaces from a block of text
     */
    static public function removeLeftHandPad($textBlock){
        $leftPadList = [];
        $leftPadReg = '/^(\ *)[^\s\n\r]/m';
        preg_match_all($leftPadReg,$textBlock,$leftPadList);

        $shortest = null;
        foreach ($leftPadList[1] as $pad){
            if ($shortest===null
                ||strlen($pad)<strlen($shortest)
            ){
                $shortest = $pad;
            }
        }
        $textUnpadded = preg_replace("/^{$shortest}/m",'',$textBlock);
        return $textUnpadded;
    }

    static public function allFilesFromDir(string $rootDir, string $relDir, array $forExt=[]){
        $dir = $rootDir.'/'.$relDir;
        if (!is_dir($dir)){
            return [];
        }
        $dh = opendir($dir);
        $allFiles = [];
        while ($file=readdir($dh)){
            if ($file=='.'||$file=='..')continue;
            if (is_dir($dir.'/'.$file)){
                $subFiles = self::allFilesFromDir($rootDir, $relDir.'/'.$file,$forExt);
                $allFiles = array_merge($allFiles,$subFiles);
                continue;
            }  
            $include = false;
            if ($forExt===[]||in_array('*', $forExt)){
                $include = true;
            } else {
                foreach ($forExt as $ext){
                    $len = strlen($ext);
                    if (strtolower(substr($file, -$len))===strtolower($ext)){
                        $include = true;
                        break;
                    }
                }
            }
            // $allFiles[] = str_replace('//','/',$dir.'/'.$file);
            if ($include){
                // $allFiles[] = new File($rootDir, $relDir.'/'.$file);
                $allFiles[] = $relDir.'/'.$file;
            }
        }
        return $allFiles;
    }

    static public function DANGEROUS_removeNonEmptyDirectory($directory){
        $src = $directory;
        $dir = opendir($src);
        while(false !== ( $file = readdir($dir)) ) {
            if (( $file != '.' ) && ( $file != '..' )) {
                $full = $src . '/' . $file;
                if ( is_dir($full) ) {
                    static::DANGEROUS_removeNonEmptyDirectory($full);
                }
                else {
                    unlink($full);
                }
            }
        }
        closedir($dir);
        rmdir($src);
    }


    /**
     * Check your composer.json in the current working directory for a `"name"`
     * @return a string like taeluf/code-scrawl or null
     */
    static public function getComposerPackageName(){
        $file = getcwd().'/composer.json';
        if (!file_exists($file))return null;
        $settings = json_decode(file_get_contents($file), true);
        return $settings['name'];
    }

    static public function getCurrentBranchForComposer(){
        $branch = exec("git branch --show-current");
        return $branch.'.x-dev';
    }


    /**
     * Return the git clone url, but always return the https version
     *
     * @return string https git url to git clone the current project
     */
    static public function getGitCloneUrl(): string {
        $url = exec("git config --get remote.origin.url | sed -r 's/.*(\\@|\\/\\/)([^:\\/]*)(\\:|\\/)(.*)\\.git/https:\\/\\/\\2\\/\\4/'");
        $url .= '.git';
        return $url;
    }
}
<?php

namespace Tlf\Scrawl\Utility;

class Regex {

    /**
     *
     */
    static public function matchRegexes($targetObject, $regexArray, File $file=null, $text=null){
        if ($file === null && $text === null)throw new \Exception("Either \$file or \$text must be set");
        if ($text === null)$text = $file->content();

        $ret = [];
        foreach ($regexArray as $name => $regs){
            // echo "\nName:$name\n\n";
            $func = $regs['function'] ?? str_replace(['-','.'], '_', $name);
            unset($regs['function']);
            foreach ($regs as $i => $regex){
                $didMatch = preg_match_all($regex, $text, $matches, PREG_SET_ORDER);
                if ($didMatch){
                    //@export_start(Regex.infoArray)
                    $info = [
                        'matchList'=>$matches, // Array of all matches
                        'lineStart' => -1, // (not implemented, @TODO) Line in file/text that your match starts on
                        'lineEnd' => -1,   // (not implemented, @TODO) Line in file/text that your match ends on
                        'text' => $text,   //
                        'regIndex' => null,
                    ];
                    //@export_end(Regex.infoArray))
                    foreach ($matches as $key => $match){
                        $info['regIndex']=$key;
                        $lineStart = 0;
                        $lineEnd = 0;
                        $info['lineStart'] = $lineStart;
                        $info['lineEnd'] = $lineEnd;
                        $ret[] = call_user_func([$targetObject, $func], $name, $match, $file, $info);
                    }
                }
            }
        }
        return $ret;
    }
}
<?php

namespace Tlf\Scrawl\OldStuffs;

/**
 * just old code that i don't wanna get rid of
 */
class ugh_old_things{

    public function run_init($cli, $args){
        if (
            $this->prompt("Create sample files for code scrawl in '".$cli->pwd."'? (y/n)", "y")
            !="y"
        ) {
            return false;
        } 

        $files = \Tlf\Scrawl\Utility::allFilesFromDir(dirname(__DIR__).'/test/input/Project/', '', []);
        foreach ($files as $f){
            if (substr($f->relPath,0,6)=='/docs/')continue;
            $file = $cli->pwd.'/'.$f->relPath;
            $dir = dirname($file);
            if (!is_dir($dir))mkdir($dir);
            if (!is_file($file)){
                file_put_contents($file, $f->content());
            }
        }

    }

    public function prompt($message, $default){
        if ($this->configs['noprompt'][0] === true) {
            return $default;
        }

        return readline($message);
    }


    public function pathToRootFrom($configuredDirectory){
        $relPath = $this->getConfig('dir.'.$configuredDirectory);
        if ($relPath===null) return null;
        $relPath = $relPath[0];
        $relPath = str_replace('\\','/',$relPath);
        $parts = explode('/', $relPath);
        $retRelPath = '';
        foreach ($parts as $p){
            $retRelPath .= '../';
        }
        return $retRelPath;
    }
}
{

    "--comments":{
        "Documentation": "Visit https://www.taeluf.com/docs/Code%20Scrawl or https://gitlab.com/taeluf/php/CodeScrawl",
        "Deprecation 1":"Version 1.0 will scan src/ & test/ ",
        "Deprecation 2":"Version 1.0 will default to non-hidden directories 'docsrc' and 'doctemplate'",
        "Deprecation 3":"Version 1.0 will fully-default to 'config/' dir rather than '.config/', though both will still work.",

        "Addition 1": "2023-12-23: Added 'api.output_dir = 'api/' config. If `null`, then do not write api output files. Previously, APIs were ALWAYS output to the api/ dir. Default config has the same behavior as before.",
        "Addition 2": "2023-12-23: Add api.generate_readme config (default TRUE). This is NEW Functionality that creates a README in the api/ dir."
    },

    "template.dirs": [".doctemplate"],

    "dir.docs": "docs",
    "dir.src": ".docsrc",
    "dir.scan": ["code", "test"],

    "api.output_dir": "api/",
    "api.generate_readme": true,


    "ScrawlExtensions":[],

    "file.bootstrap":"scrawl-bootstrap.php",

    "deleteExistingDocs": false,
    "readme.copyFromDocs": false,

    "markdown.preserveNewLines": true,
    "markdown.prependGenNotice": true
}
<?php

namespace Tlf\Scrawl;

/**
 * An extensions has multiple opportunities to interact in the documentation generation process
 */
interface Extension {
    
    /**
     * Initialize the extension
     * @param $scrawl a Scrawl instance
     */
    public function __construct(\Tlf\Scrawl $scrawl);

    /**
     * Any initial setup required. This is called AFTER `file.bootstrap` files are loaded, and before anything else.
     */
    public function bootstrap();


    /**
     * Called when an AST has been generated, after it has been set to scrawl.
     * To change the AST scrawl is using, call `$scrawl->set('ast', "class.{$className})"
     *
     * @param $className fully qualified class name
     * @param $ast an ast as an array
     */
    public function ast_generated(string $className, array $ast);

    /** 
     * ASTs have been generated and api documentation has been output
     * @param $asts the root array containing all the ASTs
     */
    public function astlist_generated(array $asts);

    /**
     * Called before any files are processed
     * @param $code_files array of all files to be scanned for code
     */
    public function scan_filelist_loaded(array $code_files);

    /**
     * Called when an individual file is finished being processed
     *
     * @param $path absolute path to the file
     * @param $relPath relative path to the file
     * @param $file_content the content of the file
     * @param $file_exports array of all items exported from just this file
     */
    public function scan_file_processed(string $path, string $relPath, string $file_content, array $file_exports);

    /**
     * Called when all files are finished being processed
     *
     * @param $code_files array of all files that were scanned and processed
     * @param $all_exports array of all exports found in the scanned files
     */
    public function scan_filelist_processed(array $code_files, array $all_exports);

    /**
     * Called when all documentations ource files have been loaded
     *
     * @param $doc_files array of all documentation source files, containing Code Scrawl code
     * @param $mdverb_ext \Tlf\Scrawl\Ext\MdVerbs instance
     */
    public function doc_filelist_loaded(array $doc_files, \Tlf\Scrawl\Ext\MdVerbs $mdverb_ext);

    /**
     * Called when an individual documentation source file has been loaded, before any processing
     *
     * @param $path absolute path to the file
     * @param $relPath relative path to the input file, relative within the documentation source dir
     * @param $file_content the content of the file
     */
    public function doc_file_loaded($path,$relPath,$file_content);

    /**
     * Called when an individual documentation source file has been processed and all `@mdverbs` have been replaced, and the file has been written to disk
     *
     * @param $path absolute path to the output file 
     * @param $relPath relative path to the output file, relative within the documentation dir
     * @param $file_content the content of the file
     */
    public function doc_file_processed($path,$relPath,$file_content);

    /**
     * Called when all documentation source files have been processed, before readme.md is copied over to root dir.
     *
     * @param $doc_files array of all documentation source files, containing Code Scrawl code
     */
    public function doc_filelist_processed($doc_files);

    /**
     * Called after all other scrawl operations are complete
     */
    public function scrawl_finished();
}
{

    "--comments":{
        "Documentation": "Visit https://www.taeluf.com/docs/Code%20Scrawl or https://gitlab.com/taeluf/php/CodeScrawl",
        "Change 1":"Version 0.8 scanned code/ & test/. Version 1.0 scans src/ & test/ ",
        "Change 2":"Now using non-hidden directories .doctemplate and .docsrc",
        "Change 3":"Version 1.0 defaults to non-hidden 'config/' dir. '.config/' still works."
    },

    "template.dirs": ["doctemplate"],

    "dir.docs": "docs",
    "dir.src": "docsrc",
    "dir.scan": ["src", "test"],
    "ScrawlExtensions":[],

    "api.output_dir": "api/",
    "api.generate_readme": true,

    "file.bootstrap":"scrawl-bootstrap.php",

    "deleteExistingDocs": false,
    "readme.copyFromDocs": false,

    "markdown.preserveNewLines": true,
    "markdown.prependGenNotice": true
}
{
    "--NOTICE":"v1.0 will introduce updated defaults.",

    "template.dirs": [".doctemplate"],

    "dir.docs": "docs",
    "dir.src": ".docsrc",
    "dir.scan": ["code", "test"],
    "ScrawlExtensions":[],

    "file.bootstrap":"scrawl-bootstrap.php",

    "api.output_dir": "api/",
    "api.generate_readme": true,

    "deleteExistingDocs": false,
    "readme.copyFromDocs": false,

    "markdown.preserveNewLines": true,
    "markdown.prependGenNotice": true
}
<?php

namespace Tlf;

/**
 * Central class for running scrawl.
 */
class Scrawl {



    /** array for get/set */
    public array $stuff = [];

    public array $extensions = [
        'code'=>[],
    ];
    /**
     * Array of \Tlf\Scrawl\Extension objects
     */
    public array $ScrawlExtensions = [];

    /**
     * \Tlf\Scrawl\Ext\MdVerbs
     */
    public \Tlf\Scrawl\Ext\MdVerbs $mdverb_ext;

    /** absolute path to php file to `require()` before scrawl runs */
    public ?string $file_bootstrap = null;

    /** absolute path to your documentation dir */
    public ?string $dir_docs = null;

    /** absolute path to the root of your project */
    public ?string $dir_root = null;

    /** absolute path to the documentation source dir */
    public ?string $dir_src = null;

    /** array of relative path to dirs to scan, within your dir_root */
    public ?array $dir_scan = [];

    /** array of handlers for the mdverb extension */
    public array $verb_handlers = [];

    /** absolute path to directories that contain md templates */
    public array $template_dirs = [];

    /** if true, append two spaces to every line so all new lines are parsed as new lines */
    public bool $markdown_preserveNewLines = true;

    /** if true, add an html comment to md docs saying not to edit directly */
    public bool $markdown_prependGenNotice = true;

    /** if true, copies `docs/README.md` to project root `README.md` */
    public bool $readme_copyFromDocs = true;

    /** If true will delete all files in your docs dir before running */
    public bool $deleteExistingDocs = false;

    /** Which directory to write Class/Method/Property info to */
    public ?string $api_output_dir = 'api/';
    /** True to generate a README listing all classes, inside the api_output_dir */
    public bool $api_generate_readme = true;

    /**
     * Array of values, typically passed in through cli
     */
    public array $options = [];

    /**
     * @parma $options `key=>value` array to set properties
     */
    public function __construct(array $options=[]){
        $this->options = $options;
        foreach ($this->options as $k=>$o){
            $k = str_replace('.','_',$k);
            if (property_exists($this,$k)){
                $this->$k = $o;
            }
        }

        $this->template_dirs[] = __DIR__.'/Template/';
        $this->mdverb_ext = $this->setup_mdverb_ext();
        $this->ScrawlExtensions = $this->setup_extensions($this->options['ScrawlExtensions']??[]);
    }

    /**
     * Get the relative path within target_path, if it starts with root_path
     *
     * @experimental has not been tested
     * @param $base_path the base path, to remove from target path
     * @param $target_path a path that starts with `$base_path` and contains a relative path you're parsing.
     * @return the relative path, or null if target path does not start with base path
     */
    public function parse_rel_path(string $base_path, string $target_path, bool $use_realpath = true): ?string {
        $abs_base = $use_realpath ? realpath($base_path) : $base_path;
        $abs_target = $use_realpath ? realpath($target_path) : $target_path;
        $len = strlen($abs_base);
        // var_dump($abs_base);
        // var_dump($abs_target);
        if (substr($abs_target, 0, $len) != $abs_base)return null;

        return substr($abs_target,$len);
    }

    /**
     *
     * Cli function to get the absolute path to a code file
     *
     * @param $args array of arguments
     * @key 1, code_file_path -  absolute path to documentation of a code file. Example "/absolute/path.php" might return "/absolute/docs/path.md"
     * @usage `$scrawl->get_doc_path(new \Tlf\Cli(), "/absolute/path");
     *
     * @return absolute path or an empty string
     */
    public function get_doc_path(\Tlf\Cli $cli, array $args): string {
        $code_file_path = $args['--'][0];
        // echo "\nPath: $code_file_path\n";
        // echo "\nRealPath: ".realpath($code_file_path)."\n";
        $code_file_path = realpath($code_file_path);
        // print_r($args);

        $cwd = getcwd();
        // echo "\nCurDir: ".$cwd."\n";
        if ($cwd!=substr($code_file_path,0,strlen($cwd))){
            
            return "";
        }
        $rel_path = substr($code_file_path,strlen($cwd));
        $rel_path = str_replace('../','/', $rel_path);


        $abs_path = $this->dir_docs.($this->api_output_dir??'api/').$rel_path.'.md';
        $abs_path = str_replace('//','/', $abs_path);
        echo "$abs_path";
        return $abs_path;
        // echo "AbsPath:".$abs_path;
//
        // echo "\nRelPath: $rel_path\n";
//
//
        // return "\nPath: $code_file_path\n";

    }

    /**
     *
     * Cli function to get the absolute path to a documentation source file for a .md file 
     *
     * @param $args array of arguments
     * @key 1, code_file_path -  absolute path to documentation of a code file. Example "/absolute/path.php" might return "/absolute/docs/path.md"
     * @usage `$scrawl->get_doc_path(new \Tlf\Cli(), "/absolute/path");
     *
     * @return absolute path or an empty string
     */
    public function get_doc_source_path(\Tlf\Cli $cli, array $args): string {
        $code_file_path = $args['--'][0];
        // echo "\nPath: $code_file_path\n";
        // echo "\nRealPath: ".realpath($code_file_path)."\n";
        $code_file_path = realpath($code_file_path);
        // print_r($args);

        $cwd = getcwd();
        // echo "\nCurDir: ".$cwd."\n";
        if ($cwd!=substr($code_file_path,0,strlen($cwd))){
            return "";
        }
        if ($code_file_path == realpath($this->dir_root.'/README.md')){
            $path = $this->dir_src.'/README.src.md';
            echo $path;
            return $path;
        }
        
        $rel_path = substr($code_file_path,strlen($this->dir_docs));
        $rel_path = str_replace('../','/', $rel_path);


        $abs_path = $this->dir_src.'/'.$rel_path;
        $abs_path = str_replace('//','/', $abs_path);
        // replace .md with .src.md
        $abs_path = substr($abs_path, 0,-3) . '.src.md';
        echo "$abs_path";
        return $abs_path;
        // echo "AbsPath:".$abs_path;
//
        // echo "\nRelPath: $rel_path\n";
//
//
        // return "\nPath: $code_file_path\n";

    }


    /**
     * Get a template stored on disk. `$name` should be relative path without extension. `$args` is passed to template code, but not `extract`ed. Template files must end with `.md.php` or just `.php`.
     *
     */
    public function get_template(string $name, array $args){

        foreach ($this->template_dirs as $path){
            if (file_exists($file = $path.'/'.$name.'.md.php')){}
            else if (file_exists($file=$path.'/'.$name.'.php')){}
            else continue;
            $out = (function(array $args, string $file) {
                ob_start();
                require($file);
                $out = ob_get_clean();
                return $out;
            })($args, $file);
            return $out;
        }
        
        $this->warn("@template", $msg="Template '$name' does not exist.");
        return $msg;
    }

    public function get(string $group, string $key){
        if (!isset($this->stuff[$group])){
            $this->warn("Group not set", $group);
            return null;
        } else if (!isset($this->stuff[$group][$key])){
            $this->warn("Group.Key not set", "$group.$key");
            return null;
        }
        return $this->stuff[$group][$key];
    }

    public function get_group(string $group){
        if (!isset($this->stuff[$group])){
            $this->warn("Group not set", $group);
            return null;
        }
        return $this->stuff[$group];
    }


    public function set(string $group, string $key, $value){
        $this->stuff[$group][$key] = $value;
    }

    public function parse_str($str, $ext){
        $out = [];
        foreach ($this->extensions['code'][$ext] as $ext){
            $out = $ext->parse_str($str); 
        }
        return $out;
    }

    /**
     * save a file to disk in the documents directory
     */
    public function write_doc(string $rel_path, string $content){
        $content = $this->prepare_md_content($content);
        $rel_path = str_replace('../','/', $rel_path);
        $path = $this->dir_docs.'/'.$rel_path;
        $dir = dirname($path);
        if (!is_dir($dir))mkdir($dir,0755,true);
        if (is_file($path)){
            $this->good('Overwrite',$rel_path);
        } else {
            $this->good('Write',$rel_path);
        }
        file_put_contents($path, $content);
    }

    /**
     * save a file to disk in the root directory
     */
    public function write_file(string $rel_path, string $content){
        $rel_path = str_replace('../','/', $rel_path);
        $path = $this->dir_root.'/'.$rel_path;
        $dir = dirname($path);
        if (!is_dir($dir))mkdir($dir,0755,true);
        if (is_file($path)){
            $this->good('Overwrite',$rel_path);
        } else {
            $this->good('Write',$rel_path);
        }
        file_put_contents($path, $content);
    }

    /**
     * Read a file from disk, from the project root
     */
    public function read_file(string $rel_path){
        return file_get_contents($this->dir_root.'/'.$rel_path);
    }
    /**
     * Read a file from disk, from the project docs dir
     */
    public function read_doc(string $rel_path){
        return file_get_contents($this->dir_docs.'/'.$rel_path);
    }

    /** get a path to a docs file */
    public function doc_path(string $rel_path){
        return $this->dir_docs.'/'.$rel_path;
    }


    /**
     * Output a message to cli (may do logging later, idk)
     */
    public function report(string $msg){
        echo "\n$msg";
    }

    /**
     * Output a message to cli, header highlighted in red
     */
    public function warn($header, $message){
        echo "\033[0;31m$header:\033[0m $message\033[0;31m\033[0m\n";
    }

    /**
     * Output a message to cli, header highlighted in red
     */
    public function good($header, $message){
        echo "\033[0;32m$header:\033[0m $message\033[0;31m\033[0m\n";
    }

    /** apply small fixes to markdown */
    public function prepare_md_content(string $markdown){

        if ($this->markdown_preserveNewLines){
            $markdown  = str_replace("\n","  \n",$markdown);
        }

        if ($this->markdown_prependGenNotice){
            // @TODO give relative path to source file
            $markdown = "<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  \n".$markdown;
        }
        
        return $markdown;
    }


    public function get_all_docsrc_files(){
        $files = \Tlf\Scrawl\Utility\Main::allFilesFromDir($this->dir_src, '');
        return $files;
    }

    /** 
     * get array of all files in `$scrawl->dir_scan` 
     * @return array or relative paths within `$scrawl->dir_scan` 
     */
    public function get_all_scan_files(): array{
        $all = [];
        foreach ($this->dir_scan as $f){
            $files = \Tlf\Scrawl\Utility\Main::allFilesFromDir($this->dir_root, $f);
            $all = array_merge($all, $files);
        }
        return $all;
    }

    /**
     * Generate api docs for all files
     * (currently only php files)
     */
    public function generate_apis() {

        if ($this->api_output_dir === null
            || $this->api_output_dir === false
        )return;

        foreach ($this->get_all_scan_files() as $file){
            $this->generate_api($file);
        }

        if ($this->api_generate_readme){
            $this->generate_apis_readme();
        }
    }

    /**
     * Create a README file that lists all of the classes in the API dir.
     */
    public function generate_apis_readme(){
        $this->report("Generate README for APIs");

        $markdown = $this->get_template('ast/ApiReadme', [$this->get_all_classes(), $this->get_all_traits()]);

        $this->write_doc($this->api_output_dir.'/README.md', $markdown);

    }

    /**
     * Generate api doc for a single file
     * (currently only php files)
     *
     * @param $rel_path relative path inside `$scrawl->dir_root` 
     */
    public function generate_api($rel_path){
        if (strtolower(pathinfo($rel_path,PATHINFO_EXTENSION))!=='php')return;
        $php_ext = new \Tlf\Scrawl\FileExt\Php($this);
        $ast = $php_ext->parse_file($rel_path);

        $path = $ast['path'];
        // $rel_path = substr($path, strlen($scrawl->dir_root));
        // $ast['path'] = $rel_path;

        // $scrawl->set('ast','file.'.$rel_path, $ast);

        $classes = array_merge($ast['class'] ?? [], $ast['namespace']['class'] ?? []);

        if (count($classes)==0)return;
        $doc = "# File ".$rel_path."\n";
        foreach ($classes as $c){
            $markdown = $this->get_template('ast/class', [null,$c,null]);

            $doc .="\n".$markdown;
        }
        $this->write_doc($this->api_output_dir.'/'.$rel_path.'.md', $doc);
    }

    /**
     * Get an array of all classes scanned within this repo. 
     *
     * @return array<string fully_qualified_classname, array $ast> ASTs for each class scanned within the repo.
     */
    public function get_all_classes(): array {
        $php_ext = new \Tlf\Scrawl\FileExt\Php($this);
        $files = $this->get_all_scan_files();
        $classes = [];
        $trait_count = 0;
        foreach ($files as $f){
            if (strtolower(pathinfo($f,PATHINFO_EXTENSION))!=='php')continue;
            $this->report("Generate Ast: ".$f);
            $ast = $php_ext->parse_file($f);

            $trait_count += count($ast['trait']??[]) + count($ast['namespace']['trait']??[]);
            $new_classes = array_merge($ast['class'] ?? [], $ast['namespace']['class'] ?? []);
            foreach ($new_classes as &$c){
                $c['file'] = $f;
                $classes[$c['fqn']] = $c;
            }
        }

        return $classes;
    }

    /**
     * Get an array of all classes scanned within this repo. 
     *
     * @return array<string fully_qualified_classname, array $ast> ASTs for each class scanned within the repo.
     */
    public function get_all_traits(): array {
        $php_ext = new \Tlf\Scrawl\FileExt\Php($this);
        $files = $this->get_all_scan_files();
        $traits = [];
        $trait_count = 0;
        foreach ($files as $f){
            if (strtolower(pathinfo($f,PATHINFO_EXTENSION))!=='php')continue;
            $this->report("Generate Ast: ".$f);
            $ast = $php_ext->parse_file($f);

            $new_traits = array_merge($ast['trait'] ?? [], $ast['namespace']['trait'] ?? []);
            foreach ($new_traits as &$c){
                $c['file'] = $f;
                $traits[$c['fqn']] = $c;
            }
        }

        return $traits;
    }

    /**
     * Array of \Tlf\Scrawl\Extension objects
     * @param $extensions_classes an array of class names implementing `\Tlf\Scrawl\Extension`
     * @return array of instantiated objects
     */
    public function setup_extensions(array $extension_classes){

        $extensions = [];
        foreach ($extension_classes as $ec){
            if (!class_exists($ec, true)){
                $this->report("Extension class '$ec' does not exist.");
                continue;
            }
            /* if (substr($ec,0,1)=='\\')$ec = substr($ec,1); */
            if (!in_array('Tlf\\Scrawl\\Extension',class_implements($ec,true))){
                $this->report("Extension class '$ec' does not exist.");
                continue;
            }
            $extensions[] = new $ec($this);

        }

        return $extensions;
    }

    /**
     * Execute scrawl in its entirety
     */
    public function run(){

        // bootstrap via file
        $scrawl = null;
        if ($this->file_bootstrap!=null&&file_exists($this->file_bootstrap)){
            $scrawl = $this;
            require_once($this->file_bootstrap);
        }
        unset($scrawl);

        // bootstrap extensions
        foreach ($this->ScrawlExtensions as $se){
            $se->bootstrap();
        }

        // delete existing documentation
        if ($this->deleteExistingDocs){
            $del_dir = realpath($this->dir_docs);
            $cwd = realpath(getcwd());
            $len = strlen($cwd);
            if (substr($del_dir,0,$len)===$cwd
                && strlen($cwd)>6
                &&count(explode('/',$cwd))>=4
            ){
                $this->warn("Delete Dir", $del_dir);
                \Tlf\Scrawl\Utility\Main::DANGEROUS_removeNonEmptyDirectory($del_dir);
            }
        }
        $this->report("Generate Asts");
        //////////
        // process php files into 'ast'
        //////////
        $classes = $this->get_all_classes();
        foreach ($classes as $c){
            $this->set('ast', 'class.'.$c['fqn'], $c);
            foreach ($this->ScrawlExtensions as $se){
                $se->ast_generated($c['fqn'], $c);
            }
        }
        $this->report("### Generate APIs ###\n");
        $this->generate_apis();


        // call extensions for ast generated
        foreach ($this->ScrawlExtensions as $se){
            $se->astlist_generated($this->get_group('ast')??[]);
        }


        //////////
        // process all code files using code extensions
        //////////
        $export_docblock = new \Tlf\Scrawl\FileExt\ExportDocBlock();
        $export_startend = new \Tlf\Scrawl\FileExt\ExportStartEnd();
        // $php_ext = new \Tlf\Scrawl\FileExt\Php();

        $code_files = $this->get_all_scan_files();

        // call extensions for all files
        foreach ($this->ScrawlExtensions as $se){
            $se->scan_filelist_loaded($code_files);
        }

        // var_dump($code_files);
        // exit;
        foreach ($code_files as $f){
            $path = $this->dir_root.'/'.$f;
            $file_content = file_get_contents($path);
            $file_exports = [];
            // docblock @export()s
            $docblocks = $export_docblock->get_docblocks($file_content);
            $exports = $export_docblock->get_exports($docblocks);
            foreach ($exports as $k=>$e)$this->set('export',$k, $e);
            $file_exports = $exports;
            // @export_start/@export_end()
            $exports = $export_startend->get_exports($file_content);
            $file_exports = array_merge($file_exports, $exports);
            foreach ($exports as $k=>$e)$this->set('export',$k, $e);


            foreach ($this->ScrawlExtensions as $se){
                $se->scan_file_processed($path, $f, $file_content, $file_exports??[]);
            }
        }

        foreach ($this->ScrawlExtensions as $se){
            $se->scan_filelist_processed($code_files, $this->get_group('export') ?? []);
        }

        //////////
        // process all documentation source files
        //////////
        $src_files = $this->get_all_docsrc_files();

        $mdverb_ext = $this->mdverb_ext;

        foreach ($this->ScrawlExtensions as $se){
            $se->doc_filelist_loaded($src_files, $mdverb_ext);
        }

        foreach ($src_files as $sf){
            $path = $this->dir_src.'/'.$sf;
            // $sf contains a leading slash, i guess?
            if ($path==$this->dir_src.'//config.json'){
                continue;
            }
            $content = file_get_contents($path);
            // process mdverbs

            foreach ($this->ScrawlExtensions as $se){
                $se->doc_file_loaded($path,$sf,$content);
            }

            $content = $mdverb_ext->replace_all_verbs($content);
            if (substr($sf,-7)=='.src.md')$sf = substr($sf,0,-7).'.md';

            $this->write_doc($sf, $content);

            foreach ($this->ScrawlExtensions as $se){
                $se->doc_file_processed($this->dir_docs.'/'.$sf,$sf,$content);
            }
        }


        foreach ($this->ScrawlExtensions as $se){
            $se->doc_filelist_processed($src_files);
        }


        $readme_path = $this->doc_path('README.md');
        if ($this->readme_copyFromDocs && file_exists($readme_path)){
            $this->write_file('README.md', $this->read_doc('README.md'));
        }

        $this->good("Finished",'Code Scrawl Ran');


        foreach ($this->ScrawlExtensions as $se){
            $se->scrawl_finished();
        }
    }

    /**
     * get an array ast from a file
     * Currently only supports php files
     * Also sets the ast to scrawl
     */
    public function get_ast(string $file): ?array {
        $ext = pathinfo($file, PATHINFO_EXTENSION);
        if ($ext!='php'){
            $this->report("File '$file' not .php. Skip ast parse.");
            return null;
        }
        $php_ext = new \Tlf\Scrawl\FileExt\Php($this);
        $ast = $php_ext->parse_file($file);
        // $php_ext->set_ast($ast);
        return $ast;
    }


    /** get the class ast
     * @param $class fully qualified class name
     */
    public function get_class_ast(string $class): ?array{
       $ast = $this->get('ast','class.'.$class); 
       return $ast;
    }


    public function setup_mdverb_ext(){
        $mdverb_ext = new \Tlf\Scrawl\Ext\MdVerbs($this);
        $main_verbs_ext = new \Tlf\Scrawl\Ext\MdVerb\MainVerbs($this);
        $main_verbs_ext->setup_handlers($mdverb_ext);

        $ast_ext = new \Tlf\Scrawl\Ext\MdVerb\Ast($this);
        $mdverb_ext->handlers['ast'] = [$ast_ext, 'get_markdown'];
        foreach ($this->verb_handlers as $k=>$v){
            $mdverb_ext->handlers[$k] = $v;
        }
        return $mdverb_ext;
    }

    // public function call_extensions($hook){
//
    // }

}
@template(all_classes)
# Code Scrawl
Code Scrawl is a documentation generator. You write `.src.md` files and call buit-in functions with `@‌verbs()` within, including `@‌template(template_name)` to load several built-in templates. You can create custom extensions and templates for your own projects, or to generate documentation for using a library you made. 

Also generate full API documentation of PHP classes. AST Generation uses `taeluf/lexer`, which can be extended to support other languages, but as of May 2023, there are no clear plans to do this.

## Features
- Integrated AST generation to automatically copy+paste specific parts of source code, thanks to @easy_link(tlf, php/lexer)
- Several builtin verbs and templates
- Extend with custom verbs and templates.

## Deprecation Warning:
- v1.0 will stop using hidden directories like `.docsrc/` and instead use `docsrc/`. The defaults.json file will be changed to accomodate in v1.0
- v1.0 will use dir `src/` instead of `code/` as a default directory to scan. (currently also scans `test/`, which will not change)

### Install
@template(php/composer_install, taeluf/code-scrawl)

### Configure
Create a file `.config/scrawl.json` or `scrawl.json` in your project root. Defaults:
```json
@file(src/defaults-no-comments.json)
```

### Default Configs / File Structre
**Note:** Instructions updated to use non-hidden directories, but the default.json file still uses hidden directories. This inconsistency will be fixed in v1.0
- `config/scrawl.json`: configuration file
- `docsrc/*.src.md`: documentation source files (from which your documentation is generated)
- `docs/`: generated documentation output
- `src/*`, and `test/*`: Code files to scan
- `doctemplate/*.md.php` and `CodeScrawl/src/Template/*.md.php`: re-usable templates 
- `scrawl-bootstrap.php`: Runs at start of `$scrawl->run()` and `$this` is the `$scrawl` instance.

## Usage
Overview:
- Execute with `vendor/bin/scrawl` from your project root.
- Write files like `docsrc/README.src.md`
- Use Markdown Verbs (mdverb) to load documentation and code into your `.src.md` files: `@‌file(src/defaults.json)` would print the content of `src/defaults.json`
- Use the `@‌template` mdverb to load a template: `@‌template(php/compose_install, taeluf/code-scrawl)` to print composer install instructions 
- Use the `@‌ast` mdverb to load code from the AST (Asymmetric Syntax Tree): `@‌ast(class.\Tlf\Scrawl.docblock.description)` to print directly or `@‌ast(class.\Tlf\Scrawl, ast/class)` to use an ast template.
- Write special `@‌codeverbs` in comments in code source files to export docblocks and code. 
- Extend it! Write custom templates and `@‌mdverb` handlers
- Write custom md verb handlers (see 'Extension' section below)
- Write custom templates (see 'Extension' section below)
- Use an `ASCII Non-Joiner` character after an `@` sign, to write a literal `@‌at_sign_with_text` and not execute the verb handler.

### Write Documents: Example
Write files in your `docsrc` folder with the extension `.src.md`.
Example, from @see_file(docsrc/README.src.md)

This would display the `## Install` instructions and `## Configure` instructions as above
```md
# Code Scrawl
Intro text

## Setup 
### Install
@‌template(php/compose_install, taeluf/code-scrawl)

### Configure
Create a file `.config/scrawl.json` or `scrawl.json` in your project root. Defaults:
‌```json
@‌file(src/defaults.json)
‌```
```

### `@‌MdVerbs` List
Write these in your markdown source files for special functionality  
@template(Scrawl/MdVerbs)

### Template List
Templates can be loaded with `@‌template(template_name, arg1, arg2)`, except `ast/*` templates (see below for those).

Each template contains documentation for how to use it & what args it requres.
@template(Scrawl/Templates)

### `@‌ast()` Templates (Asymmetric Syntax Tree)
Example: `@‌ast(class.\Tlf\Scrawl.docblock.description)` to print directly or `@‌ast(class.\Tlf\Scrawl, ast/class)` to use an ast template.

### `@‌CodeVerbs` Exports (from code in scan dirs)
In a docblock, write `@‌export(Some.Key)` to export everything above it.

In a block of code (or literally anywhere), write `// @‌export_start(Some.Key)` then `// @‌export_end(Some.Key)` to export everything in between.

See @see_file(test/run/SrcCode.php) for examples

## Extensions

### Templates: Write a custom template
Look at existing templates in @see_file(doctemplate/) or @see_file(src/Template) for examples.

### Verb Handlers: Write a custom verb handler
In your `scrawl-bootstrap.php` file, do something like:
```php
@file(test/input/run-cli/scrawl-bootstrap.php)
```

### PHP Extensions
Create a class that `implements \Tlf\Scrawl\Extension`. See file @see_file(src/Extension.php). You can `class YourExt extends \Tlf\Scrawl\DoNothingExtension` as a base class and then only override the methods you need.

In your `config.json`, set `"ScrawlExtensions": ["Your\\Fully\\Qualified\\ClassName"]`, with as many extension classes as you like.

## Architecture
- `Tlf\Scrawl`: Primary class that `run()`s everything.
- `\Tlf\Scrawl->run()`: generate `api/*` files. Load all php classes. scan code files. Scan `.src.md` files & output `.md` files.
    - file set as `file.bootstrap` is `require()`d at start of `run()` to setup additional mdverb handlers and (eventually) other extensions. Default is `scrawl-bootstrap.php`
- `Tlf\Scrawl\Ext\MdVerbs`: Instantiated during `run()` prior to scanning documentation source files. When an `@‌mdverb(arg1,arg2)` is encounter in documentation source file, a handler (`$mdverbs->handlers['mdverb']`) is called with string arguments like `$handler('arg1', 'arg2')`. Extend it by adding a callable to `$scrawl->mdverb_ext->handlers`.
    - `Tlf\Scrawl\Ext\MdVerb\MainVerbs`: Has functions for simple verb handlers like `@‌file`, `@‌template`. Adds each function as a handler to the `MdVerbs` class.
    - `\Tlf\Scrawl\Ext\MdVerb\Ast`: A special mdverb handler that loads ASTs from the lexer and passes it to a named (or default) template.
- `Tlf\Scrawl\FileExt\Php`: The only AST extension currently active. It is a convenience class that wraps the Lexer so it is easily called by `Scrawl`. It is called to setup ASTs by `class.ClassName...` on `$scrawl`. Call `$scrawl->get('ast', 'class.ClassName...')`. It is called to generate the `api/*` documentation files.
- INACTIVE CLASS `Tlf\Scrawl\Ext\Main` simply copies the `project_root/.docrsc/README.src.md` to `project_root/README.md`
- `Tlf\Scrawl\FileExt\ExportDocBlock` and `ExportStartEnd` handle the `@‌export()` tag in docblocks and the `@‌export_start()/@‌export_end()` tags.
- `\Tlf\Scrawl\Utility\DocBlock`: Convenience class for extracting docblocks from files.
- `\Tlf\Scrawl\Utility\Main`: Class with some convenience functions
- `\Tlf\Scrawl\Utility\Regex`: Class to make regex matching within a file more abstract & object oriented. (it's not particularly good)

## More Info
- Run withOUT the cli: Some of the configs require absolute paths when running through php, rather than from the cli. An example is in @see_file(test/run/Integrate.php) under method `testRunFull()`
- `@‌literal`: Displaying a literal `@‌literal` in an md source file can be done by putting a @hard_link(https://unicode-explorer.com/c/200C, Zero Width Non-Joiner) after the arroba (`@`). You can also use a backslash like so: `@\literal`, but then the backslash prints
- All classes in this repo: @see_file(docs/ClassList.md)
- `$scrawl` has a `get/set` feature. In a template, you can get an ast like `$scrawl->get('ast.Fully\Qualified\ClassName')`. Outside a template, you can use the `Php` class (@see_file(src/Ext/Php.php)) to get an ast from a file or string.
- the `deleteExistingDocs` config has a bit of a sanity check to make sure you don't accidentally delete your whole system or something ...
# Code Scrawl
Documentation Generation with `@‌verbs()` in markdown for special functionality and templates for common documentation needs. Define your own verbs & templates. 

Integrated with @easy_link(tlf, php/lexer) for ASTs of PHP classes (there may be bugs & it's tested only with php 7.4).

Run scrawl with `vendor/bin/scrawl` from your project root.

## Example `.docsrc/README.src.md`
See below for a list of templates & `@‌verbs` available to use.

This would display the `## Install` instructions and `## Configure` instructions as below
```md
# Code Scrawl
Intro text

## Install
@‌template(php/compose_install, taeluf/code-scrawl)

## Configure
Create a file `.config/scrawl.json` or `scrawl.json` in your project root. Defaults:
‌```
@‌file(src/defaults.json)
‌```
```

## Install
@template(php/composer_install, taeluf/code-scrawl)

## Configure
Create a file `.config/scrawl.json` or `scrawl.json` in your project root. Defaults:
```php
@file(src/defaults.json)
```

## Define your own verbs 
In your `scrawl-bootstrap.php` file, do something like:
```php
@file(test/input/run-cli/scrawl-bootstrap.php)
```

## Write your own templates
Look at existing templates in @see_file(doctemplate/) or @see_file(src/Template) for examples.

## Run Scrawl
`cd` into your project root
```bash
# run documentation on the current dir
vendor/bin/scrawl 
```

## File Structure (defaults)
- `.config/scrawl.json`: configuration file
- `.docsrc/*.src.md`: documentation source files (from which your documentation is generated)
- `docs/`: generated documentation output
- `code/*`, and `test/*`: Code files to scan
- `doctemplate/*.md.php` and `CodeScrawl/src/Template/*.md.php`: re-usable templates 
- `scrawl-bootstrap.php`: Runs before `$scrawl->run()` and has access to `$scrawl` instance

## `@‌Verbs`
Write these in your markdown source files for special functionality  
@template(Scrawl/MdVerbs)

## Templates
Templates can be loaded with `@‌template(template_name, arg1, arg2)`, though ast templates should be loaded with `@‌ast(class.ClassName.ast_path, ast/template_name)` where the template name is optional.

Click the link to view the template file to see the documentation on how to use it & what args it requires
@template(Scrawl/Templates)

## Exports (from code in scan dirs)
In a docblock, write `@‌export(Some.Key)` to export everything above it.

In a block of code (or literally anywhere), write `// @‌export_start(Some.Key)` then `// @‌export_end(Some.key)` to export everything in between.

See @see_file(test/run/SrcCode.php) for examples

## More Info
- Run withOUT the cli: Some of the configs require absolute paths when running through php, rather than from the cli. An example is in @see_file(test/run/Integrate.php) under method `testRunFull()`
- `@‌literal`: Displaying a literal `@‌literal` in an md source file can be done by putting a @hard_link(https://unicode-explorer.com/c/200C, Zero Width Non-Joiner) after the arroba (`@`). You can also use a backslash like so: `@\literal`, but then the backslash prints
- All classes in this repo: @see_file(docs/ClassList.md)
- `$scrawl` has a `get/set` feature. In a template, you can get an ast like `$scrawl->get('ast.Fully\Qualified\ClassName')`. Outside a template, you can use the `Php` class (@see_file(src/Ext/Php.php)) to get an ast from a file or string.
- the `deleteExistingDocs` config has a bit of a sanity check to make sure you don't accidentally delete your whole system or something ...
# ChangeLog

## Noted Changes
- 2023-12-23: Repo cleanup (use non-hidden dirs, etc). Add API readme generation. Add git Changelog template

## Git Log
@template(git/ChangeLog)
<?php
/**
 * No params... uses $this to access scrawl
 */

ob_start();
$ext = $this->mdverb_ext;
$ast_verbs = new Tlf\Scrawl\Ext\MdVerb\Ast($this);

$verbs = [];
foreach ($ext->handlers as $verb=>$callable){
    $object = $callable[0];
    $method_name = $callable[1];
    $class = get_class($object);
    $ast = $this->get_class_ast($class);

    $method_ast = $ast_verbs->get_ast('class.'.$class.'.methods.'.$method_name);

    if (!isset($method_ast['docblock'])){
        $verbs[$verb] = "No description Found--".$method_name;
        continue;
    }

    $attributes = $method_ast['docblock']['attribute'];
    $usage = array_filter($attributes,
        function($v){if ($v['name']=='usage')return true; return false;}
    )[0]['description']??null;
    if ($usage!=null)$usage = ". Usage: `".$usage.'`';

    $output = array_filter($attributes,
        function($v){if ($v['name']=='output')return true; return false;}
    )[0]['description']??null;
    if ($output != null)$output = ". Output: `".$output."`";

    $description = trim($method_ast['docblock']['description'])
        .$usage
        .$output
        ;
    $verbs[$verb] = $description;
}
ob_get_clean();
// print_r($ext);
// exit;
// echo "\n\n\n-----------\n\n";
// print_r($verbs);
// echo "\n\n\n-----------\n\n";
// exit;
//
foreach ($verbs as $verb=>$description){
    echo "- `@$verb()`: $description  \n";
}
<?php

$scandir = dirname(__DIR__, 2).'/code/Template/';

$files = \Tlf\Scrawl\Utility\Main::allFilesFromDir($scandir,'',[]);
// $files = array_map(
    // function($dir){
        // return '/'.$dir;
    // }
    // ,scandir($scandir),
// );

$dir = $scandir;
foreach ($files as $file){
    $f = $file;
    $path = $dir.'/'.$file;
    if (!is_file($path))continue;

    if ($f[0]=='/')$f = substr($f,1);
    $parts = explode('.', $f);
    // array_pop($parts);
    // array_pop($parts);
    // $f = implode('.', $parts);
    $f = $parts[0];

    echo "- [`$f`](/code/Template/$file)\n";
}
{

    "template.dirs": ["doctemplate"],

    "dir.docs": "docs",
    "dir.src": "docsrc",
    "dir.scan": ["src", "test/run/"],

    "ScrawlExtensions": [
        "Tlf\\Scrawl\\TestExtension"
    ],

    "api.output_dir": "api/",
    "api.generate_readme": true,

    "deleteExistingDocs": true,
    "readme.copyFromDocs": true,

    "markdown.preserveNewLines": true,
    "markdown.prependGenNotice": true
}
#!/usr/bin/env php
<?php
/**
 * Bundled by phar-composer with the help of php-box.
 *
 * @link https://github.com/clue/phar-composer
 */
define('BOX_EXTRACT_PATTERN_DEFAULT','__HALT'.'_COMPILER(); ?>');
define('BOX_EXTRACT_PATTERN_OPEN',"__HALT"."_COMPILER(); ?>\r\n");
if (class_exists('Phar')) {
Phar::mapPhar('');
require 'phar://' . __FILE__ . '/bin/phar-composer';
} else {
$extract = new Extract(__FILE__, Extract::findStubLength(__FILE__));
$dir = $extract->go();
set_include_path($dir . PATH_SEPARATOR . get_include_path());
require "$dir/bin/phar-composer";
}
class Extract
{
const PATTERN_DEFAULT=BOX_EXTRACT_PATTERN_DEFAULT;
const PATTERN_OPEN=BOX_EXTRACT_PATTERN_OPEN;
const GZ=4096;
const BZ2=8192;
const MASK=12288;
private$file;
private$handle;
private$stub;
function __construct($file,$stub){
if(!is_file($file)){
throw new InvalidArgumentException(sprintf('The path "%s" is not a file or does not exist.',$file
));
}
$this->file=$file;
$this->stub=$stub;
}
static function findStubLength($file,$pattern=self::PATTERN_OPEN
){
if(!($fp=fopen($file,'rb'))){
throw new RuntimeException(sprintf('The phar "%s" could not be opened for reading.',$file
));
}
$stub=null;
$offset=0;
$combo=str_split($pattern);
while(!feof($fp)){
if(fgetc($fp)===$combo[$offset]){
$offset++;
if(!isset($combo[$offset])){
$stub=ftell($fp);
break;
}
}else{
$offset=0;
}
}
fclose($fp);
if(null===$stub){
throw new InvalidArgumentException(sprintf('The pattern could not be found in "%s".',$file
));
}
return$stub;
}
function go($dir=null){
if(null===$dir){
$dir=rtrim(sys_get_temp_dir(),'\\/').DIRECTORY_SEPARATOR
.'pharextract'.DIRECTORY_SEPARATOR
.basename($this->file,'.phar');
}else{
$dir=realpath($dir);
}
$md5=$dir.DIRECTORY_SEPARATOR.md5_file($this->file);
if(file_exists($md5)){
return$dir;
}
if(!is_dir($dir)){
$this->createDir($dir);
}
$this->open();
if(-1===fseek($this->handle,$this->stub)){
throw new RuntimeException(sprintf('Could not seek to %d in the file "%s".',$this->stub,$this->file
));
}
$info=$this->readManifest();
if($info['flags']&self::GZ){
if(!function_exists('gzinflate')){
throw new RuntimeException('The zlib extension is (gzinflate()) is required for "%s.',$this->file
);
}
}
if($info['flags']&self::BZ2){
if(!function_exists('bzdecompress')){
throw new RuntimeException('The bzip2 extension (bzdecompress()) is required for "%s".',$this->file
);
}
}
self::purge($dir);
$this->createDir($dir);
$this->createFile($md5);
foreach($info['files']as$info){
$path=$dir.DIRECTORY_SEPARATOR.$info['path'];
$parent=dirname($path);
if(!is_dir($parent)){
$this->createDir($parent);
}
if(preg_match('{/$}',$info['path'])){
$this->createDir($path,511,false);
}else{
$this->createFile($path,$this->extractFile($info));
}
}
return$dir;
}
static function purge($path){
if(is_dir($path)){
foreach(scandir($path)as$item){
if(('.'===$item)||('..'===$item)){
continue;
}
self::purge($path.DIRECTORY_SEPARATOR.$item);
}
if(!rmdir($path)){
throw new RuntimeException(sprintf('The directory "%s" could not be deleted.',$path
));
}
}else{
if(!unlink($path)){
throw new RuntimeException(sprintf('The file "%s" could not be deleted.',$path
));
}
}
}
private function createDir($path,$chmod=511,$recursive=true){
if(!mkdir($path,$chmod,$recursive)){
throw new RuntimeException(sprintf('The directory path "%s" could not be created.',$path
));
}
}
private function createFile($path,$contents='',$mode=438){
if(false===file_put_contents($path,$contents)){
throw new RuntimeException(sprintf('The file "%s" could not be written.',$path
));
}
if(!chmod($path,$mode)){
throw new RuntimeException(sprintf('The file "%s" could not be chmodded to %o.',$path,$mode
));
}
}
private function extractFile($info){
if(0===$info['size']){
return'';
}
$data=$this->read($info['compressed_size']);
if($info['flags']&self::GZ){
if(false===($data=gzinflate($data))){
throw new RuntimeException(sprintf('The "%s" file could not be inflated (gzip) from "%s".',$info['path'],$this->file
));
}
}elseif($info['flags']&self::BZ2){
if(false===($data=bzdecompress($data))){
throw new RuntimeException(sprintf('The "%s" file could not be inflated (bzip2) from "%s".',$info['path'],$this->file
));
}
}
if(($actual=strlen($data))!==$info['size']){
throw new UnexpectedValueException(sprintf('The size of "%s" (%d) did not match what was expected (%d) in "%s".',$info['path'],$actual,$info['size'],$this->file
));
}
$crc32=sprintf('%u',crc32($data)&4294967295);
if($info['crc32']!=$crc32){
throw new UnexpectedValueException(sprintf('The crc32 checksum (%s) for "%s" did not match what was expected (%s) in "%s".',$crc32,$info['path'],$info['crc32'],$this->file
));
}
return$data;
}
private function open(){
if(null===($this->handle=fopen($this->file,'rb'))){
$this->handle=null;
throw new RuntimeException(sprintf('The file "%s" could not be opened for reading.',$this->file
));
}
}
private function read($bytes){
$read='';
$total=$bytes;
while(!feof($this->handle)&&$bytes){
if(false===($chunk=fread($this->handle,$bytes))){
throw new RuntimeException(sprintf('Could not read %d bytes from "%s".',$bytes,$this->file
));
}
$read.=$chunk;
$bytes-=strlen($chunk);
}
if(($actual=strlen($read))!==$total){
throw new RuntimeException(sprintf('Only read %d of %d in "%s".',$actual,$total,$this->file
));
}
return$read;
}
private function readManifest(){
$size=unpack('V',$this->read(4));
$size=$size[1];
$raw=$this->read($size);
$count=unpack('V',substr($raw,0,4));
$count=$count[1];
$aliasSize=unpack('V',substr($raw,10,4));
$aliasSize=$aliasSize[1];
$raw=substr($raw,14+$aliasSize);
$metaSize=unpack('V',substr($raw,0,4));
$metaSize=$metaSize[1];
$offset=0;
$start=4+$metaSize;
$manifest=array('files'=>array(),'flags'=>0,);
for($i=0;$i<$count;$i++){
$length=unpack('V',substr($raw,$start,4));
$length=$length[1];
$start+=4;
$path=substr($raw,$start,$length);
$start+=$length;
$file=unpack('Vsize/Vtimestamp/Vcompressed_size/Vcrc32/Vflags/Vmetadata_length',substr($raw,$start,24));
$file['path']=$path;
$file['crc32']=sprintf('%u',$file['crc32']&4294967295);
$file['offset']=$offset;
$offset+=$file['compressed_size'];
$start+=24+$file['metadata_length'];
$manifest['flags']|=$file['flags']&self::MASK;
$manifest['files'][]=$file;
}
return$manifest;
}
}

__HALT_COMPILER(); ?>
0��LICENSE:�<
b:�TiE�
composer.json�<
b�-N3�
composer.lock���<
b�����src/Box/Extract.min.php�<
b����src/Box/StubGenerator.php,�<
b,t��src/Package/Bundle.php�<
bN��۴src/Package/Package.php�
�<
b�
��-�src/Logger.phpG�<
bG���src/App.php��<
b�y�Z9�src/Command/Build.php��<
b��F��src/Command/Search.php��<
b��*:4�src/Command/Install.php_	�<
b_	2�$+�src/Phar/PharComposer.php�#�<
b�#��>�src/Phar/TargetPhar.php��<
b�'Bٴsrc/Phar/Packager.phpf*�<
bf*"6մbin/phar-composer��<
b����vendor/autoload.php��<
b���I?�vendor/composer/ClassLoader.php�>�<
b�>�5Ky�%vendor/composer/InstalledVersions.php�:�<
b�:T��"�%vendor/composer/autoload_classmap.php��<
b���@�'vendor/composer/autoload_namespaces.php��<
b�V�/ٴ!vendor/composer/autoload_psr4.php��<
b�5��C�!vendor/composer/autoload_real.phpi�<
bi�p�#vendor/composer/autoload_static.php�	�<
b�	��Ҵvendor/composer/installed.json#E�<
b#E����vendor/composer/installed.php��<
b�j�ˢ�"vendor/composer/platform_check.php��<
b�q����!vendor/doctrine/inflector/LICENSE)�<
b)�9޴Evendor/doctrine/inflector/lib/Doctrine/Common/Inflector/Inflector.php�B�<
b�BF:.�vendor/guzzle/guzzle/LICENSEW�<
bW�[��>vendor/guzzle/guzzle/src/Guzzle/Cache/AbstractCacheAdapter.phpG�<
bG!��=vendor/guzzle/guzzle/src/Guzzle/Cache/CacheAdapterFactory.php��<
b�:��ô3vendor/guzzle/guzzle/src/Guzzle/Cache/composer.json��<
b�I�0e�9vendor/guzzle/guzzle/src/Guzzle/Cache/Zf2CacheAdapter.php��<
b��I�̴>vendor/guzzle/guzzle/src/Guzzle/Cache/DoctrineCacheAdapter.phpe�<
be�S�޴?vendor/guzzle/guzzle/src/Guzzle/Cache/CacheAdapterInterface.php��<
b����=vendor/guzzle/guzzle/src/Guzzle/Cache/ClosureCacheAdapter.php^�<
b^���δ9vendor/guzzle/guzzle/src/Guzzle/Cache/Zf1CacheAdapter.php��<
b�Z㍼�:vendor/guzzle/guzzle/src/Guzzle/Cache/NullCacheAdapter.php�<
b���;vendor/guzzle/guzzle/src/Guzzle/Service/ClientInterface.php�
�<
b�
���?vendor/guzzle/guzzle/src/Guzzle/Service/CachingConfigLoader.php��<
b��Bvendor/guzzle/guzzle/src/Guzzle/Service/Builder/ServiceBuilder.php�<
b����Kvendor/guzzle/guzzle/src/Guzzle/Service/Builder/ServiceBuilderInterface.php��<
b��S�)�Hvendor/guzzle/guzzle/src/Guzzle/Service/Builder/ServiceBuilderLoader.phpD
�<
bD
��_�Nvendor/guzzle/guzzle/src/Guzzle/Service/Exception/ServiceNotFoundException.phpn�<
bn�S�h�Fvendor/guzzle/guzzle/src/Guzzle/Service/Exception/CommandException.php��<
b���կ�Lvendor/guzzle/guzzle/src/Guzzle/Service/Exception/ResponseClassException.php��<
b�#��N�Qvendor/guzzle/guzzle/src/Guzzle/Service/Exception/DescriptionBuilderException.php��<
b�ƣ��Nvendor/guzzle/guzzle/src/Guzzle/Service/Exception/CommandTransferException.php��<
b�V��ϴYvendor/guzzle/guzzle/src/Guzzle/Service/Exception/InconsistentClientTransferException.php��<
b�y���Mvendor/guzzle/guzzle/src/Guzzle/Service/Exception/ServiceBuilderException.php��<
b���NδIvendor/guzzle/guzzle/src/Guzzle/Service/Exception/ValidationException.php�<
bb�d�5vendor/guzzle/guzzle/src/Guzzle/Service/composer.json�<
b<��x�2vendor/guzzle/guzzle/src/Guzzle/Service/Client.php%�<
b%�
�W�@vendor/guzzle/guzzle/src/Guzzle/Service/AbstractConfigLoader.phpq�<
bq��7�Uvendor/guzzle/guzzle/src/Guzzle/Service/Resource/ResourceIteratorFactoryInterface.php�<
b癤ѴUvendor/guzzle/guzzle/src/Guzzle/Service/Resource/CompositeResourceIteratorFactory.php��<
b��쾒�Ovendor/guzzle/guzzle/src/Guzzle/Service/Resource/MapResourceIteratorFactory.php��<
b������Nvendor/guzzle/guzzle/src/Guzzle/Service/Resource/ResourceIteratorInterface.php�<
b�2�P�Qvendor/guzzle/guzzle/src/Guzzle/Service/Resource/ResourceIteratorClassFactory.php��<
b�q���Tvendor/guzzle/guzzle/src/Guzzle/Service/Resource/AbstractResourceIteratorFactory.php�<
b`�:vendor/guzzle/guzzle/src/Guzzle/Service/Resource/Model.php�<
bBpQ��Evendor/guzzle/guzzle/src/Guzzle/Service/Resource/ResourceIterator.php\�<
b\K�˴Qvendor/guzzle/guzzle/src/Guzzle/Service/Resource/ResourceIteratorApplyBatched.phpS
�<
bS

֜��Svendor/guzzle/guzzle/src/Guzzle/Service/Description/ServiceDescriptionInterface.php��<
b�/S��Avendor/guzzle/guzzle/src/Guzzle/Service/Description/Parameter.php�a�<
b�a[���Pvendor/guzzle/guzzle/src/Guzzle/Service/Description/ServiceDescriptionLoader.php�	�<
b�	%��@�Jvendor/guzzle/guzzle/src/Guzzle/Service/Description/ValidatorInterface.php��<
b��b��Gvendor/guzzle/guzzle/src/Guzzle/Service/Description/SchemaFormatter.php��<
b��/lF�Gvendor/guzzle/guzzle/src/Guzzle/Service/Description/SchemaValidator.phpj.�<
bj.Cc�޴Jvendor/guzzle/guzzle/src/Guzzle/Service/Description/ServiceDescription.php��<
b���#ŴAvendor/guzzle/guzzle/src/Guzzle/Service/Description/Operation.phpv=�<
bv=���Jvendor/guzzle/guzzle/src/Guzzle/Service/Description/OperationInterface.php��<
b�e� �Ivendor/guzzle/guzzle/src/Guzzle/Service/Command/DefaultResponseParser.php��<
b��.'|�Hvendor/guzzle/guzzle/src/Guzzle/Service/Command/Factory/AliasFactory.php`�<
b`d���Pvendor/guzzle/guzzle/src/Guzzle/Service/Command/Factory/ConcreteClassFactory.phpE�<
bE��=�Lvendor/guzzle/guzzle/src/Guzzle/Service/Command/Factory/CompositeFactory.php�<
bj1̴Lvendor/guzzle/guzzle/src/Guzzle/Service/Command/Factory/FactoryInterface.php��<
b�ϠYc�Uvendor/guzzle/guzzle/src/Guzzle/Service/Command/Factory/ServiceDescriptionFactory.phpm�<
bm����Fvendor/guzzle/guzzle/src/Guzzle/Service/Command/Factory/MapFactory.php�<
b�	���Lvendor/guzzle/guzzle/src/Guzzle/Service/Command/CreateResponseClassEvent.php<�<
b< 8+�Kvendor/guzzle/guzzle/src/Guzzle/Service/Command/OperationResponseParser.php��<
b�R��Jvendor/guzzle/guzzle/src/Guzzle/Service/Command/ResponseClassInterface.php��<
b�s�o�Bvendor/guzzle/guzzle/src/Guzzle/Service/Command/ClosureCommand.php�<
b���.�Kvendor/guzzle/guzzle/src/Guzzle/Service/Command/ResponseParserInterface.php��<
b�w��{�Nvendor/guzzle/guzzle/src/Guzzle/Service/Command/RequestSerializerInterface.php��<
b�ÖEk�Cvendor/guzzle/guzzle/src/Guzzle/Service/Command/AbstractCommand.php40�<
b40Qb���Dvendor/guzzle/guzzle/src/Guzzle/Service/Command/CommandInterface.php�
�<
b�
%����Dvendor/guzzle/guzzle/src/Guzzle/Service/Command/OperationCommand.php�	�<
b�	�Y���[vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/PostFileVisitor.php��<
b���$p�Wvendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/JsonVisitor.php��<
b���a
�Xvendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/QueryVisitor.php�<
b=����_vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/ResponseBodyVisitor.php��<
b�V����\vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/PostFieldVisitor.php
�<
b
˱�ԴYvendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/HeaderVisitor.php��<
b� ϶q�Wvendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/BodyVisitor.php�	�<
b�	Y4��cvendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/RequestVisitorInterface.php7�<
b7{�HƴVvendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/XmlVisitor.php��<
b����bvendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Request/AbstractRequestVisitor.php��<
b���Zv�`vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/ReasonPhraseVisitor.phpH�<
bH��1�Xvendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/JsonVisitor.php�
�<
b�
�貴Zvendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/HeaderVisitor.php�<
b�տ�evendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/ResponseVisitorInterface.php2�<
b2��[�^vendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/StatusCodeVisitor.phpB�<
bB�x�@�Xvendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/BodyVisitor.php3�<
b3����dvendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/AbstractResponseVisitor.phpf�<
bf}��M�Wvendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/Response/XmlVisitor.php��<
b�
�i��Tvendor/guzzle/guzzle/src/Guzzle/Service/Command/LocationVisitor/VisitorFlyweight.php��<
b���Q�Lvendor/guzzle/guzzle/src/Guzzle/Service/Command/DefaultRequestSerializer.php��<
b��9�[�Avendor/guzzle/guzzle/src/Guzzle/Service/ConfigLoaderInterface.php��<
b�VQ�h�Ivendor/guzzle/guzzle/src/Guzzle/Plugin/Cache/CallbackCanCacheStrategy.php��<
b�,\�p�Hvendor/guzzle/guzzle/src/Guzzle/Plugin/Cache/DefaultCacheKeyProvider.php��<
b���V��Avendor/guzzle/guzzle/src/Guzzle/Plugin/Cache/SkipRevalidation.php��<
b�Nt�Jvendor/guzzle/guzzle/src/Guzzle/Plugin/Cache/CanCacheStrategyInterface.php��<
b���[�:vendor/guzzle/guzzle/src/Guzzle/Plugin/Cache/composer.json��<
b��ôFvendor/guzzle/guzzle/src/Guzzle/Plugin/Cache/CacheStorageInterface.php��<
b�]�9�Hvendor/guzzle/guzzle/src/Guzzle/Plugin/Cache/DefaultCanCacheStrategy.php��<
b������Avendor/guzzle/guzzle/src/Guzzle/Plugin/Cache/DenyRevalidation.php��<
b���<vendor/guzzle/guzzle/src/Guzzle/Plugin/Cache/CachePlugin.php:3�<
b:3P��Fvendor/guzzle/guzzle/src/Guzzle/Plugin/Cache/RevalidationInterface.phpN�<
bN��D��Dvendor/guzzle/guzzle/src/Guzzle/Plugin/Cache/DefaultCacheStorage.php� �<
b� �ڴJvendor/guzzle/guzzle/src/Guzzle/Plugin/Cache/CacheKeyProviderInterface.php��<
b��k�˴Dvendor/guzzle/guzzle/src/Guzzle/Plugin/Cache/DefaultRevalidation.php��<
b����ܴ4vendor/guzzle/guzzle/src/Guzzle/Plugin/composer.jsonT�<
bTo&��<vendor/guzzle/guzzle/src/Guzzle/Plugin/History/composer.json��<
b��:��@vendor/guzzle/guzzle/src/Guzzle/Plugin/History/HistoryPlugin.phpQ�<
bQDS�+�:vendor/guzzle/guzzle/src/Guzzle/Plugin/Mock/MockPlugin.phpN�<
bNp��9vendor/guzzle/guzzle/src/Guzzle/Plugin/Mock/composer.json��<
b�~=�x�:vendor/guzzle/guzzle/src/Guzzle/Plugin/Oauth/composer.json��<
b�>7��<vendor/guzzle/guzzle/src/Guzzle/Plugin/Oauth/OauthPlugin.php((�<
b((=,���8vendor/guzzle/guzzle/src/Guzzle/Plugin/Log/composer.json��<
b�<�i�8vendor/guzzle/guzzle/src/Guzzle/Plugin/Log/LogPlugin.php��<
b��A"ڴ>vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/CookiePlugin.php��<
b�L"]��Rvendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/Exception/InvalidCookieException.php��<
b�!m|��Ivendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/CookieJar/FileCookieJar.php��<
b�t2L�Jvendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/CookieJar/ArrayCookieJar.php@�<
b@�6.~�Nvendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/CookieJar/CookieJarInterface.phpj�<
bj4`۴;vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/composer.json��<
b���R�8vendor/guzzle/guzzle/src/Guzzle/Plugin/Cookie/Cookie.php21�<
b21��8vendor/guzzle/guzzle/src/Guzzle/Plugin/Md5/composer.json��<
b��m���Fvendor/guzzle/guzzle/src/Guzzle/Plugin/Md5/CommandContentMd5Plugin.php��<
b��'f��Avendor/guzzle/guzzle/src/Guzzle/Plugin/Md5/Md5ValidatorPlugin.phpu
�<
bu
�Nm��:vendor/guzzle/guzzle/src/Guzzle/Plugin/Async/composer.json��<
b���E �<vendor/guzzle/guzzle/src/Guzzle/Plugin/Async/AsyncPlugin.php��<
b���`��Xvendor/guzzle/guzzle/src/Guzzle/Plugin/ErrorResponse/ErrorResponseExceptionInterface.phpV�<
bV|�F��Lvendor/guzzle/guzzle/src/Guzzle/Plugin/ErrorResponse/ErrorResponsePlugin.php�<
bd�'��Yvendor/guzzle/guzzle/src/Guzzle/Plugin/ErrorResponse/Exception/ErrorResponseException.php��<
b���ҙ�Bvendor/guzzle/guzzle/src/Guzzle/Plugin/ErrorResponse/composer.json��<
b�[y��=vendor/guzzle/guzzle/src/Guzzle/Plugin/CurlAuth/composer.json��<
b��6�Bvendor/guzzle/guzzle/src/Guzzle/Plugin/CurlAuth/CurlAuthPlugin.phpl�<
bl˞��@vendor/guzzle/guzzle/src/Guzzle/Plugin/Backoff/BackoffPlugin.php=�<
b=Z�m�<vendor/guzzle/guzzle/src/Guzzle/Plugin/Backoff/composer.json��<
b�"��Svendor/guzzle/guzzle/src/Guzzle/Plugin/Backoff/AbstractErrorCodeBackoffStrategy.php�<
b�|�Kvendor/guzzle/guzzle/src/Guzzle/Plugin/Backoff/TruncatedBackoffStrategy.php��<
b��AQp�Jvendor/guzzle/guzzle/src/Guzzle/Plugin/Backoff/ConstantBackoffStrategy.php��<
b�
j�v�Kvendor/guzzle/guzzle/src/Guzzle/Plugin/Backoff/BackoffStrategyInterface.php��<
b�X�|�Nvendor/guzzle/guzzle/src/Guzzle/Plugin/Backoff/ReasonPhraseBackoffStrategy.php��<
b�� sW�Fvendor/guzzle/guzzle/src/Guzzle/Plugin/Backoff/HttpBackoffStrategy.php��<
b�#Ǧ�Mvendor/guzzle/guzzle/src/Guzzle/Plugin/Backoff/ExponentialBackoffStrategy.php��<
b�m�hS�Hvendor/guzzle/guzzle/src/Guzzle/Plugin/Backoff/LinearBackoffStrategy.php��<
b�T�#�@vendor/guzzle/guzzle/src/Guzzle/Plugin/Backoff/BackoffLogger.php	�<
b	(�*��Jvendor/guzzle/guzzle/src/Guzzle/Plugin/Backoff/CallbackBackoffStrategy.php��<
b��>��Jvendor/guzzle/guzzle/src/Guzzle/Plugin/Backoff/AbstractBackoffStrategy.phpI�<
bI��Z4�Fvendor/guzzle/guzzle/src/Guzzle/Plugin/Backoff/CurlBackoffStrategy.php��<
b�%+��5vendor/guzzle/guzzle/src/Guzzle/Common/Collection.php-�<
b-��E�Avendor/guzzle/guzzle/src/Guzzle/Common/HasDispatcherInterface.phpN�<
bN�3��Evendor/guzzle/guzzle/src/Guzzle/Common/Exception/RuntimeException.phpz�<
bzh^�w�Mvendor/guzzle/guzzle/src/Guzzle/Common/Exception/UnexpectedValueException.php��<
b��e���Kvendor/guzzle/guzzle/src/Guzzle/Common/Exception/BadMethodCallException.php��<
b��qS��Dvendor/guzzle/guzzle/src/Guzzle/Common/Exception/GuzzleException.phpd�<
bd�شMvendor/guzzle/guzzle/src/Guzzle/Common/Exception/InvalidArgumentException.php��<
b��VǴHvendor/guzzle/guzzle/src/Guzzle/Common/Exception/ExceptionCollection.php�<
b�A˲�4vendor/guzzle/guzzle/src/Guzzle/Common/composer.json��<
b��>x��2vendor/guzzle/guzzle/src/Guzzle/Common/Version.php��<
b����0vendor/guzzle/guzzle/src/Guzzle/Common/Event.php(�<
b(��k۴@vendor/guzzle/guzzle/src/Guzzle/Common/AbstractHasDispatcher.php��<
b�%�;��;vendor/guzzle/guzzle/src/Guzzle/Common/ToArrayInterface.php��<
b���N�>vendor/guzzle/guzzle/src/Guzzle/Common/FromConfigInterface.php��<
b���1r�1vendor/guzzle/guzzle/src/Guzzle/Stream/Stream.php�<
b���|�4vendor/guzzle/guzzle/src/Guzzle/Stream/composer.json��<
b���"U�Bvendor/guzzle/guzzle/src/Guzzle/Stream/PhpStreamRequestFactory.php%�<
b%-��Hvendor/guzzle/guzzle/src/Guzzle/Stream/StreamRequestFactoryInterface.php[�<
b[4�:vendor/guzzle/guzzle/src/Guzzle/Stream/StreamInterface.php8�<
b81���7vendor/guzzle/guzzle/src/Guzzle/Log/ArrayLogAdapter.phpg�<
bgx�c�1vendor/guzzle/guzzle/src/Guzzle/Log/composer.json��<
b�<��:�:vendor/guzzle/guzzle/src/Guzzle/Log/AbstractLogAdapter.php �<
b p��-�5vendor/guzzle/guzzle/src/Guzzle/Log/Zf1LogAdapter.php��<
b���Yڴ5vendor/guzzle/guzzle/src/Guzzle/Log/PsrLogAdapter.php^�<
b^�����9vendor/guzzle/guzzle/src/Guzzle/Log/ClosureLogAdapter.phpG�<
bG��#p�;vendor/guzzle/guzzle/src/Guzzle/Log/LogAdapterInterface.php��<
b��\:�5vendor/guzzle/guzzle/src/Guzzle/Log/Zf2LogAdapter.php��<
b�>'���9vendor/guzzle/guzzle/src/Guzzle/Log/MonologLogAdapter.php��<
b�+$�Y�8vendor/guzzle/guzzle/src/Guzzle/Log/MessageFormatter.php��<
b��B�8vendor/guzzle/guzzle/src/Guzzle/Http/ClientInterface.php�&�<
b�&Pg5�<vendor/guzzle/guzzle/src/Guzzle/Http/ReadLimitEntityBody.php#
�<
b#
`.��Bvendor/guzzle/guzzle/src/Guzzle/Http/Message/PostFileInterface.php��<
b�Ӑ´9vendor/guzzle/guzzle/src/Guzzle/Http/Message/Response.php�f�<
b�f��礴Avendor/guzzle/guzzle/src/Guzzle/Http/Message/MessageInterface.php	�<
b	ۓ`��@vendor/guzzle/guzzle/src/Guzzle/Http/Message/AbstractMessage.php#�<
b#�C}#�Avendor/guzzle/guzzle/src/Guzzle/Http/Message/RequestInterface.php7!�<
b7!��Օ�?vendor/guzzle/guzzle/src/Guzzle/Http/Message/RequestFactory.php�2�<
b�2�h�7vendor/guzzle/guzzle/src/Guzzle/Http/Message/Header.php��<
b��S�Pvendor/guzzle/guzzle/src/Guzzle/Http/Message/EntityEnclosingRequestInterface.php��<
b��9vendor/guzzle/guzzle/src/Guzzle/Http/Message/PostFile.php��<
b�M.>�Gvendor/guzzle/guzzle/src/Guzzle/Http/Message/EntityEnclosingRequest.php��<
b��'DU�Hvendor/guzzle/guzzle/src/Guzzle/Http/Message/Header/HeaderCollection.php �<
b ��hɴEvendor/guzzle/guzzle/src/Guzzle/Http/Message/Header/HeaderFactory.php��<
b��┴Gvendor/guzzle/guzzle/src/Guzzle/Http/Message/Header/HeaderInterface.phpP�<
bP�(��<vendor/guzzle/guzzle/src/Guzzle/Http/Message/Header/Link.php��<
b������Nvendor/guzzle/guzzle/src/Guzzle/Http/Message/Header/HeaderFactoryInterface.php��<
b������Dvendor/guzzle/guzzle/src/Guzzle/Http/Message/Header/CacheControl.php�
�<
b�
��O�8vendor/guzzle/guzzle/src/Guzzle/Http/Message/Request.php�K�<
b�K1�WߴHvendor/guzzle/guzzle/src/Guzzle/Http/Message/RequestFactoryInterface.phpx�<
bx�&۴9vendor/guzzle/guzzle/src/Guzzle/Http/Resources/cacert.pem��<
b�c�Hvendor/guzzle/guzzle/src/Guzzle/Http/QueryAggregator/CommaAggregator.php�<
b�^<ʹQvendor/guzzle/guzzle/src/Guzzle/Http/QueryAggregator/QueryAggregatorInterface.php��<
b�)��Fvendor/guzzle/guzzle/src/Guzzle/Http/QueryAggregator/PhpAggregator.phpt�<
bt�$��Lvendor/guzzle/guzzle/src/Guzzle/Http/QueryAggregator/DuplicateAggregator.php<�<
b<9�|\�@vendor/guzzle/guzzle/src/Guzzle/Http/Exception/CurlException.phpC�<
bC&Y��Gvendor/guzzle/guzzle/src/Guzzle/Http/Exception/BadResponseException.php4�<
b4��=�@vendor/guzzle/guzzle/src/Guzzle/Http/Exception/HttpException.php��<
b���Ovendor/guzzle/guzzle/src/Guzzle/Http/Exception/ServerErrorResponseException.php��<
b�Wp�Ivendor/guzzle/guzzle/src/Guzzle/Http/Exception/MultiTransferException.php�
�<
b�
[ڒ��Cvendor/guzzle/guzzle/src/Guzzle/Http/Exception/RequestException.php�<
b�o~�Lvendor/guzzle/guzzle/src/Guzzle/Http/Exception/TooManyRedirectsException.phpi�<
biǸ��Ovendor/guzzle/guzzle/src/Guzzle/Http/Exception/ClientErrorResponseException.php��<
b�5"�ڴPvendor/guzzle/guzzle/src/Guzzle/Http/Exception/CouldNotRewindStreamException.php��<
b��n��2vendor/guzzle/guzzle/src/Guzzle/Http/composer.json(�<
b(W�M�/vendor/guzzle/guzzle/src/Guzzle/Http/Client.php�A�<
b�AF����=vendor/guzzle/guzzle/src/Guzzle/Http/IoEmittingEntityBody.php��<
b��c�"�<vendor/guzzle/guzzle/src/Guzzle/Http/EntityBodyInterface.phps	�<
bs	����2vendor/guzzle/guzzle/src/Guzzle/Http/Mimetypes.php���<
b����Dvendor/guzzle/guzzle/src/Guzzle/Http/AbstractEntityBodyDecorator.php��<
b��a��5vendor/guzzle/guzzle/src/Guzzle/Http/StaticClient.php'�<
b'�Z�!�4vendor/guzzle/guzzle/src/Guzzle/Http/QueryString.php*"�<
b*"���ô8vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlHandle.phps=�<
bs=X/�޴@vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMultiInterface.php=�<
b=�њO�7vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMulti.php�8�<
b�8��{@�<vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlMultiProxy.php�<
b���D�9vendor/guzzle/guzzle/src/Guzzle/Http/Curl/CurlVersion.php��<
b���\�=vendor/guzzle/guzzle/src/Guzzle/Http/Curl/RequestMediator.php]�<
b]T�š�:vendor/guzzle/guzzle/src/Guzzle/Http/CachingEntityBody.phpz�<
bz��b�,vendor/guzzle/guzzle/src/Guzzle/Http/Url.php"9�<
b"9+a�_�7vendor/guzzle/guzzle/src/Guzzle/Http/RedirectPlugin.php{'�<
b{'s�;��3vendor/guzzle/guzzle/src/Guzzle/Http/EntityBody.php��<
b��á�8vendor/guzzle/guzzle/src/Guzzle/Batch/BatchInterface.phpM�<
bMƿs|�:vendor/guzzle/guzzle/src/Guzzle/Batch/BatchSizeDivisor.phpk�<
bkd�j��Jvendor/guzzle/guzzle/src/Guzzle/Batch/Exception/BatchTransferException.php�
�<
b�
&���3vendor/guzzle/guzzle/src/Guzzle/Batch/composer.json/�<
b/V�y�6vendor/guzzle/guzzle/src/Guzzle/Batch/HistoryBatch.php��<
b�`B2�>vendor/guzzle/guzzle/src/Guzzle/Batch/BatchCommandTransfer.php��<
b���2�=vendor/guzzle/guzzle/src/Guzzle/Batch/BatchClosureDivisor.phpt�<
btzHF�Avendor/guzzle/guzzle/src/Guzzle/Batch/ExceptionBufferingBatch.php��<
b��E$��/vendor/guzzle/guzzle/src/Guzzle/Batch/Batch.php��<
b��s��6vendor/guzzle/guzzle/src/Guzzle/Batch/BatchBuilder.php��<
b��;ʹ?vendor/guzzle/guzzle/src/Guzzle/Batch/BatchDivisorInterface.php��<
b���~��8vendor/guzzle/guzzle/src/Guzzle/Batch/NotifyingBatch.php��<
b��j��@vendor/guzzle/guzzle/src/Guzzle/Batch/BatchTransferInterface.php�<
b��#T�>vendor/guzzle/guzzle/src/Guzzle/Batch/BatchClosureTransfer.php��<
b���ִ7vendor/guzzle/guzzle/src/Guzzle/Batch/FlushingBatch.php��<
b�ۆ�P�@vendor/guzzle/guzzle/src/Guzzle/Batch/AbstractBatchDecorator.php��<
b��?��>vendor/guzzle/guzzle/src/Guzzle/Batch/BatchRequestTransfer.php��<
b��q;�6vendor/guzzle/guzzle/src/Guzzle/Iterator/composer.json��<
b�s�@�;vendor/guzzle/guzzle/src/Guzzle/Iterator/AppendIterator.php��<
b�����;vendor/guzzle/guzzle/src/Guzzle/Iterator/FilterIterator.php��<
b�ڬ���8vendor/guzzle/guzzle/src/Guzzle/Iterator/MapIterator.phpT�<
bTR`1q�@vendor/guzzle/guzzle/src/Guzzle/Iterator/MethodProxyIterator.phpb�<
bb]���2vendor/guzzle/guzzle/src/Guzzle/Iterator/README.md��<
b��ɧQ�<vendor/guzzle/guzzle/src/Guzzle/Iterator/ChunkedIterator.php�<
bGZ���Avendor/guzzle/guzzle/src/Guzzle/Inflection/MemoizingInflector.php��<
b�l�_t�8vendor/guzzle/guzzle/src/Guzzle/Inflection/composer.jsonr�<
broR��Cvendor/guzzle/guzzle/src/Guzzle/Inflection/PreComputedInflector.php��<
b�\:��8vendor/guzzle/guzzle/src/Guzzle/Inflection/Inflector.phpS�<
bSB#c��Avendor/guzzle/guzzle/src/Guzzle/Inflection/InflectorInterface.php>�<
b>ָ�k�8vendor/guzzle/guzzle/src/Guzzle/Parser/Url/UrlParser.php��<
b�loV2�Avendor/guzzle/guzzle/src/Guzzle/Parser/Url/UrlParserInterface.php�<
b�"��@vendor/guzzle/guzzle/src/Guzzle/Parser/Message/MessageParser.php+
�<
b+
�d��Ivendor/guzzle/guzzle/src/Guzzle/Parser/Message/MessageParserInterface.php��<
b�(5�;�Hvendor/guzzle/guzzle/src/Guzzle/Parser/Message/PeclHttpMessageParser.php��<
b����Hvendor/guzzle/guzzle/src/Guzzle/Parser/Message/AbstractMessageParser.php��<
b��J2�4vendor/guzzle/guzzle/src/Guzzle/Parser/composer.json��<
b�;�`��Kvendor/guzzle/guzzle/src/Guzzle/Parser/UriTemplate/UriTemplateInterface.php��<
b�[��Fvendor/guzzle/guzzle/src/Guzzle/Parser/UriTemplate/PeclUriTemplate.php��<
b���QѴBvendor/guzzle/guzzle/src/Guzzle/Parser/UriTemplate/UriTemplate.php �<
b Y���9vendor/guzzle/guzzle/src/Guzzle/Parser/ParserRegistry.php��<
b����>vendor/guzzle/guzzle/src/Guzzle/Parser/Cookie/CookieParser.phpz�<
bz�����Gvendor/guzzle/guzzle/src/Guzzle/Parser/Cookie/CookieParserInterface.php��<
b��=�$vendor/knplabs/packagist-api/LICENSE!�<
b!F��N�Hvendor/knplabs/packagist-api/src/Packagist/Api/Result/AbstractResult.phpe�<
be�.��Fvendor/knplabs/packagist-api/src/Packagist/Api/Result/Package/Dist.php��<
b�=��Hvendor/knplabs/packagist-api/src/Packagist/Api/Result/Package/Author.php��<
b���I+�Hvendor/knplabs/packagist-api/src/Packagist/Api/Result/Package/Source.php�<
b�����Ivendor/knplabs/packagist-api/src/Packagist/Api/Result/Package/Version.php��<
b�@(���Kvendor/knplabs/packagist-api/src/Packagist/Api/Result/Package/Downloads.php�<
b����Lvendor/knplabs/packagist-api/src/Packagist/Api/Result/Package/Maintainer.php��<
b���R��Avendor/knplabs/packagist-api/src/Packagist/Api/Result/Package.php��<
b��D��@vendor/knplabs/packagist-api/src/Packagist/Api/Result/Result.phpl�<
bl�l^�Avendor/knplabs/packagist-api/src/Packagist/Api/Result/Factory.php��<
b�&����9vendor/knplabs/packagist-api/src/Packagist/Api/Client.php��<
b�3%
��Gvendor/symfony/console/Symfony/Component/Console/Helper/TableHelper.php�<
b��Fvendor/symfony/console/Symfony/Component/Console/Helper/TableStyle.phpO�<
bO�^xҴBvendor/symfony/console/Symfony/Component/Console/Helper/Helper.phpL�<
bLduZ�Ivendor/symfony/console/Symfony/Component/Console/Helper/ProcessHelper.php��<
b��*E0�Jvendor/symfony/console/Symfony/Component/Console/Helper/ProgressHelper.php//�<
b//
�r�Hvendor/symfony/console/Symfony/Component/Console/Helper/DialogHelper.php�@�<
b�@�I��Avendor/symfony/console/Symfony/Component/Console/Helper/Table.phpm(�<
bm(��'��Evendor/symfony/console/Symfony/Component/Console/Helper/HelperSet.php�	�<
b�	ݖ��Jvendor/symfony/console/Symfony/Component/Console/Helper/TableSeparator.php��<
b��n	�Jvendor/symfony/console/Symfony/Component/Console/Helper/QuestionHelper.php@1�<
b@1�;��Kvendor/symfony/console/Symfony/Component/Console/Helper/FormatterHelper.php	�<
b	"�*��Kvendor/symfony/console/Symfony/Component/Console/Helper/HelperInterface.php��<
b��z�״Lvendor/symfony/console/Symfony/Component/Console/Helper/InputAwareHelper.php��<
b���˴Gvendor/symfony/console/Symfony/Component/Console/Helper/ProgressBar.php�B�<
b�Bz�=ߴPvendor/symfony/console/Symfony/Component/Console/Helper/DebugFormatterHelper.phpS�<
bS=�ƴLvendor/symfony/console/Symfony/Component/Console/Helper/DescriptorHelper.php 
�<
b 
9u�:�Nvendor/symfony/console/Symfony/Component/Console/Descriptor/TextDescriptor.php�#�<
b�#!��ϴRvendor/symfony/console/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php/�<
b/�+�Jvendor/symfony/console/Symfony/Component/Console/Descriptor/Descriptor.php�
�<
b�
8{"$�Nvendor/symfony/console/Symfony/Component/Console/Descriptor/JsonDescriptor.php-�<
b-�T�Mvendor/symfony/console/Symfony/Component/Console/Descriptor/XmlDescriptor.php&�<
b&M1�Q�Svendor/symfony/console/Symfony/Component/Console/Descriptor/DescriptorInterface.php��<
b�JZ0<�Vvendor/symfony/console/Symfony/Component/Console/Descriptor/ApplicationDescription.php�<
b�)ŴNvendor/symfony/console/Symfony/Component/Console/Resources/bin/hiddeninput.exe$�<
b$���v�8vendor/symfony/console/Symfony/Component/Console/LICENSE)�<
b)�&��Rvendor/symfony/console/Symfony/Component/Console/Output/ConsoleOutputInterface.phpK�<
bK��0��Hvendor/symfony/console/Symfony/Component/Console/Output/StreamOutput.php��<
b��M�H�Kvendor/symfony/console/Symfony/Component/Console/Output/OutputInterface.php!�<
b!G-g�Bvendor/symfony/console/Symfony/Component/Console/Output/Output.php9�<
b9����Ivendor/symfony/console/Symfony/Component/Console/Output/ConsoleOutput.php^�<
b^�@RC�Fvendor/symfony/console/Symfony/Component/Console/Output/NullOutput.php��<
b�8��Jvendor/symfony/console/Symfony/Component/Console/Output/BufferedOutput.phph�<
bht|X4�Bvendor/symfony/console/Symfony/Component/Console/ConsoleEvents.php7�<
b7E����@vendor/symfony/console/Symfony/Component/Console/Application.php���<
b��Q��ӴMvendor/symfony/console/Symfony/Component/Console/Tester/ApplicationTester.php[
�<
b[
/�I�Ivendor/symfony/console/Symfony/Component/Console/Tester/CommandTester.phpK�<
bKt�I��:vendor/symfony/console/Symfony/Component/Console/Shell.php��<
b�ք��Fvendor/symfony/console/Symfony/Component/Console/Question/Question.phpl�<
bl�A<�Lvendor/symfony/console/Symfony/Component/Console/Question/ChoiceQuestion.php$�<
b$�Ͱ�Rvendor/symfony/console/Symfony/Component/Console/Question/ConfirmationQuestion.php$�<
b$弸!�Evendor/symfony/console/Symfony/Component/Console/Input/ArrayInput.phpK�<
bK����Hvendor/symfony/console/Symfony/Component/Console/Input/InputArgument.php��<
b���w�Fvendor/symfony/console/Symfony/Component/Console/Input/InputOption.php:�<
b:{P�Jvendor/symfony/console/Symfony/Component/Console/Input/InputDefinition.phpu/�<
bu/#x��Ivendor/symfony/console/Symfony/Component/Console/Input/InputInterface.php�<
b�)���Nvendor/symfony/console/Symfony/Component/Console/Input/InputAwareInterface.php^�<
b^9K�h�Fvendor/symfony/console/Symfony/Component/Console/Input/StringInput.php�
�<
b�
II�@vendor/symfony/console/Symfony/Component/Console/Input/Input.php��<
b�����Dvendor/symfony/console/Symfony/Component/Console/Input/ArgvInput.php�)�<
b�)�_U��Ivendor/symfony/console/Symfony/Component/Console/Logger/ConsoleLogger.php��<
b��C%6�Nvendor/symfony/console/Symfony/Component/Console/Formatter/OutputFormatter.php9�<
b9���Svendor/symfony/console/Symfony/Component/Console/Formatter/OutputFormatterStyle.php��<
b��ÒN�Xvendor/symfony/console/Symfony/Component/Console/Formatter/OutputFormatterStyleStack.php�
�<
b�
9�B۴\vendor/symfony/console/Symfony/Component/Console/Formatter/OutputFormatterStyleInterface.php��<
b�5���Wvendor/symfony/console/Symfony/Component/Console/Formatter/OutputFormatterInterface.php��<
b�z���Dvendor/symfony/console/Symfony/Component/Console/Command/Command.php�E�<
b�E�D�@�Hvendor/symfony/console/Symfony/Component/Console/Command/HelpCommand.phpb
�<
bb
"�$�Hvendor/symfony/console/Symfony/Component/Console/Command/ListCommand.php�
�<
b�
[�"�Nvendor/symfony/console/Symfony/Component/Console/Event/ConsoleCommandEvent.php8�<
b8j�"�Gvendor/symfony/console/Symfony/Component/Console/Event/ConsoleEvent.php��<
b���
��Pvendor/symfony/console/Symfony/Component/Console/Event/ConsoleTerminateEvent.php�<
b{e��Pvendor/symfony/console/Symfony/Component/Console/Event/ConsoleExceptionEvent.php=�<
b=��ŴUvendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php��<
b���R�Ivendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/LICENSE)�<
b)�&��^vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventSubscriberInterface.php-�<
b-���/�Kvendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/Event.php��<
b��fm�ovendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/DependencyInjection/RegisterListenersPass.php��<
b��� Ǵ^vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcherInterface.php��<
b���"�cvendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php��<
b�56��[vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/Debug/WrappedListener.php��<
b��M}�dvendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php!(�<
b!(PX�̴mvendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcherInterface.php#�<
b#�Ӗc�^vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/ImmutableEventDispatcher.php��<
b�Oh�Rvendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/GenericEvent.php?�<
b?�m|�6vendor/symfony/finder/Symfony/Component/Finder/LICENSE)�<
b)�&��Rvendor/symfony/finder/Symfony/Component/Finder/Exception/AccessDeniedException.php��<
b��cW޴Ovendor/symfony/finder/Symfony/Component/Finder/Exception/ExceptionInterface.php��<
b��7�Zvendor/symfony/finder/Symfony/Component/Finder/Exception/OperationNotPermitedException.php��<
b�P����Yvendor/symfony/finder/Symfony/Component/Finder/Exception/ShellCommandFailureException.php9�<
b9���Tvendor/symfony/finder/Symfony/Component/Finder/Exception/AdapterFailureException.php��<
b�>�@�7vendor/symfony/finder/Symfony/Component/Finder/Glob.php_�<
b_��j�Cvendor/symfony/finder/Symfony/Component/Finder/Expression/Regex.php��<
b��;A�Hvendor/symfony/finder/Symfony/Component/Finder/Expression/Expression.php%
�<
b%
KL��Bvendor/symfony/finder/Symfony/Component/Finder/Expression/Glob.php�<
bZ~���Lvendor/symfony/finder/Symfony/Component/Finder/Expression/ValueInterface.phpH�<
bH�"�Evendor/symfony/finder/Symfony/Component/Finder/Adapter/PhpAdapter.php{
�<
b{
9!�2�Nvendor/symfony/finder/Symfony/Component/Finder/Adapter/AbstractFindAdapter.php�)�<
b�)�C��Jvendor/symfony/finder/Symfony/Component/Finder/Adapter/AbstractAdapter.php��<
b��=�ĴIvendor/symfony/finder/Symfony/Component/Finder/Adapter/BsdFindAdapter.php�
�<
b�
��kA�Ivendor/symfony/finder/Symfony/Component/Finder/Adapter/GnuFindAdapter.php�
�<
b�
��Kvendor/symfony/finder/Symfony/Component/Finder/Adapter/AdapterInterface.php��<
b�j���Lvendor/symfony/finder/Symfony/Component/Finder/Comparator/DateComparator.php��<
b�
�'e�Nvendor/symfony/finder/Symfony/Component/Finder/Comparator/NumberComparator.php
�<
b
l�dJ�Hvendor/symfony/finder/Symfony/Component/Finder/Comparator/Comparator.php�<
b���@vendor/symfony/finder/Symfony/Component/Finder/Shell/Command.php��<
b�_LF�>vendor/symfony/finder/Symfony/Component/Finder/Shell/Shell.php��<
b��q��9vendor/symfony/finder/Symfony/Component/Finder/Finder.php�U�<
b�U6i�v�>vendor/symfony/finder/Symfony/Component/Finder/SplFileInfo.php
�<
b
s1�Nvendor/symfony/finder/Symfony/Component/Finder/Iterator/PathFilterIterator.php��<
b�We�,�Rvendor/symfony/finder/Symfony/Component/Finder/Iterator/FilenameFilterIterator.php��<
b��Jc�Mvendor/symfony/finder/Symfony/Component/Finder/Iterator/FilePathsIterator.php�
�<
b�
׷�]�Vvendor/symfony/finder/Symfony/Component/Finder/Iterator/MultiplePcreFilterIterator.php��<
b��W)<�Svendor/symfony/finder/Symfony/Component/Finder/Iterator/DateRangeFilterIterator.php��<
b��'�Q�Lvendor/symfony/finder/Symfony/Component/Finder/Iterator/SortableIterator.php�	�<
b�	p��e�Jvendor/symfony/finder/Symfony/Component/Finder/Iterator/FilterIterator.php��<
b��,G�Rvendor/symfony/finder/Symfony/Component/Finder/Iterator/FileTypeFilterIterator.phpY�<
bY�]�%�Vvendor/symfony/finder/Symfony/Component/Finder/Iterator/RecursiveDirectoryIterator.php
�<
b
'_Svendor/symfony/finder/Symfony/Component/Finder/Iterator/SizeRangeFilterIterator.php��<
b�����Tvendor/symfony/finder/Symfony/Component/Finder/Iterator/DepthRangeFilterIterator.php��<
b�-,��Zvendor/symfony/finder/Symfony/Component/Finder/Iterator/ExcludeDirectoryFilterIterator.php��<
b��J�Uvendor/symfony/finder/Symfony/Component/Finder/Iterator/FilecontentFilterIterator.php��<
b�$l��Pvendor/symfony/finder/Symfony/Component/Finder/Iterator/CustomFilterIterator.php�<
b���Avendor/symfony/process/Symfony/Component/Process/ProcessUtils.php<
�<
b<
H�f��Hvendor/symfony/process/Symfony/Component/Process/PhpExecutableFinder.phpk�<
bk�
��<vendor/symfony/process/Symfony/Component/Process/Process.phpb��<
bb�K}��8vendor/symfony/process/Symfony/Component/Process/LICENSE)�<
b)�&��Cvendor/symfony/process/Symfony/Component/Process/ProcessBuilder.php��<
b�4�Y�Ovendor/symfony/process/Symfony/Component/Process/Exception/RuntimeException.php��<
b�>H���Uvendor/symfony/process/Symfony/Component/Process/Exception/ProcessFailedException.phpE�<
bEkҐ��Qvendor/symfony/process/Symfony/Component/Process/Exception/ExceptionInterface.php��<
b��<��Wvendor/symfony/process/Symfony/Component/Process/Exception/ProcessTimedOutException.php{�<
b{��2��Wvendor/symfony/process/Symfony/Component/Process/Exception/InvalidArgumentException.php��<
b�˅��Mvendor/symfony/process/Symfony/Component/Process/Exception/LogicException.php��<
b���W�Evendor/symfony/process/Symfony/Component/Process/ExecutableFinder.php�	�<
b�	�u�f�?vendor/symfony/process/Symfony/Component/Process/PhpProcess.php��<
b��d�X�Gvendor/symfony/process/Symfony/Component/Process/Pipes/WindowsPipes.php6�<
b6CfTC�Hvendor/symfony/process/Symfony/Component/Process/Pipes/AbstractPipes.phpN�<
bN6r�y�Dvendor/symfony/process/Symfony/Component/Process/Pipes/UnixPipes.php��<
b���z�Ivendor/symfony/process/Symfony/Component/Process/Pipes/PipesInterface.phpw�<
bw�X]�The MIT License (MIT)

Copyright (c) 2013 Christian Lück

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
{
    "name": "clue/phar-composer",
    "description": "Simple phar creation for any project managed via Composer",
    "keywords": ["executable phar", "build process", "bundle dependencies", "phar", "composer"],
    "homepage": "https://github.com/clue/phar-composer",
    "license": "MIT",
    "authors": [
        {
            "name": "Christian Lück",
            "email": "christian@clue.engineering"
        }
    ],
    "require": {
        "php": ">=5.3.6",
        "knplabs/packagist-api": "^1.0",
        "symfony/console": "^6.0 || ^5.0 || ^4.0 || ^3.0 || ^2.5",
        "symfony/finder": "^6.0 || ^5.0 || ^4.0 || ^3.0 || ^2.5",
        "symfony/process": "^6.0 || ^5.0 || ^4.0 || ^3.0 || ^2.5"
    },
    "require-dev": {
        "phpunit/phpunit": "^9.5 || ^5.7 || ^4.8.36"
    },
    "autoload": {
        "psr-4": {"Clue\\PharComposer\\": "src/"}
    },
    "bin": ["bin/phar-composer"],
    "scripts": {
        "build": "@php bin/build.php"
    },
    "config": {
        "platform": {
            "php": "5.3.6"
        }
    }
}
{
    "_readme": [
        "This file locks the dependencies of your project to a known state",
        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
        "This file is @generated automatically"
    ],
    "content-hash": "678a26d2bd4ee3e1e52298dd0354f69b",
    "packages": [
        {
            "name": "doctrine/inflector",
            "version": "v1.1.0",
            "source": {
                "type": "git",
                "url": "https://github.com/doctrine/inflector.git",
                "reference": "90b2128806bfde671b6952ab8bea493942c1fdae"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/doctrine/inflector/zipball/90b2128806bfde671b6952ab8bea493942c1fdae",
                "reference": "90b2128806bfde671b6952ab8bea493942c1fdae",
                "shasum": ""
            },
            "require": {
                "php": ">=5.3.2"
            },
            "require-dev": {
                "phpunit/phpunit": "4.*"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "1.1.x-dev"
                }
            },
            "autoload": {
                "psr-0": {
                    "Doctrine\\Common\\Inflector\\": "lib/"
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Roman Borschel",
                    "email": "roman@code-factory.org"
                },
                {
                    "name": "Benjamin Eberlei",
                    "email": "kontakt@beberlei.de"
                },
                {
                    "name": "Guilherme Blanco",
                    "email": "guilhermeblanco@gmail.com"
                },
                {
                    "name": "Jonathan Wage",
                    "email": "jonwage@gmail.com"
                },
                {
                    "name": "Johannes Schmitt",
                    "email": "schmittjoh@gmail.com"
                }
            ],
            "description": "Common String Manipulations with regard to casing and singular/plural rules.",
            "homepage": "http://www.doctrine-project.org",
            "keywords": [
                "inflection",
                "pluralize",
                "singularize",
                "string"
            ],
            "support": {
                "source": "https://github.com/doctrine/inflector/tree/master"
            },
            "time": "2015-11-06T14:35:42+00:00"
        },
        {
            "name": "guzzle/guzzle",
            "version": "v3.9.3",
            "source": {
                "type": "git",
                "url": "https://github.com/guzzle/guzzle3.git",
                "reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/guzzle/guzzle3/zipball/0645b70d953bc1c067bbc8d5bc53194706b628d9",
                "reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9",
                "shasum": ""
            },
            "require": {
                "ext-curl": "*",
                "php": ">=5.3.3",
                "symfony/event-dispatcher": "~2.1"
            },
            "replace": {
                "guzzle/batch": "self.version",
                "guzzle/cache": "self.version",
                "guzzle/common": "self.version",
                "guzzle/http": "self.version",
                "guzzle/inflection": "self.version",
                "guzzle/iterator": "self.version",
                "guzzle/log": "self.version",
                "guzzle/parser": "self.version",
                "guzzle/plugin": "self.version",
                "guzzle/plugin-async": "self.version",
                "guzzle/plugin-backoff": "self.version",
                "guzzle/plugin-cache": "self.version",
                "guzzle/plugin-cookie": "self.version",
                "guzzle/plugin-curlauth": "self.version",
                "guzzle/plugin-error-response": "self.version",
                "guzzle/plugin-history": "self.version",
                "guzzle/plugin-log": "self.version",
                "guzzle/plugin-md5": "self.version",
                "guzzle/plugin-mock": "self.version",
                "guzzle/plugin-oauth": "self.version",
                "guzzle/service": "self.version",
                "guzzle/stream": "self.version"
            },
            "require-dev": {
                "doctrine/cache": "~1.3",
                "monolog/monolog": "~1.0",
                "phpunit/phpunit": "3.7.*",
                "psr/log": "~1.0",
                "symfony/class-loader": "~2.1",
                "zendframework/zend-cache": "2.*,<2.3",
                "zendframework/zend-log": "2.*,<2.3"
            },
            "suggest": {
                "guzzlehttp/guzzle": "Guzzle 5 has moved to a new package name. The package you have installed, Guzzle 3, is deprecated."
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "3.9-dev"
                }
            },
            "autoload": {
                "psr-0": {
                    "Guzzle": "src/",
                    "Guzzle\\Tests": "tests/"
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Michael Dowling",
                    "email": "mtdowling@gmail.com",
                    "homepage": "https://github.com/mtdowling"
                },
                {
                    "name": "Guzzle Community",
                    "homepage": "https://github.com/guzzle/guzzle/contributors"
                }
            ],
            "description": "PHP HTTP client. This library is deprecated in favor of https://packagist.org/packages/guzzlehttp/guzzle",
            "homepage": "http://guzzlephp.org/",
            "keywords": [
                "client",
                "curl",
                "framework",
                "http",
                "http client",
                "rest",
                "web service"
            ],
            "support": {
                "issues": "https://github.com/guzzle/guzzle3/issues",
                "source": "https://github.com/guzzle/guzzle3/tree/master"
            },
            "abandoned": "guzzlehttp/guzzle",
            "time": "2015-03-18T18:23:50+00:00"
        },
        {
            "name": "knplabs/packagist-api",
            "version": "1.3.0",
            "source": {
                "type": "git",
                "url": "https://github.com/KnpLabs/packagist-api.git",
                "reference": "9aebf8238943289d3bc3ab51e0014ed94a7a266a"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/KnpLabs/packagist-api/zipball/9aebf8238943289d3bc3ab51e0014ed94a7a266a",
                "reference": "9aebf8238943289d3bc3ab51e0014ed94a7a266a",
                "shasum": ""
            },
            "require": {
                "doctrine/inflector": "~1.0",
                "guzzle/guzzle": "~3.0",
                "php": ">=5.3.2"
            },
            "require-dev": {
                "phpspec/php-diff": "*@dev",
                "phpspec/phpspec": "~2.0"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "1.x-dev"
                }
            },
            "autoload": {
                "psr-0": {
                    "Packagist\\Api\\": "src/"
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "KnpLabs Team",
                    "homepage": "http://knplabs.com"
                }
            ],
            "description": "Packagist API client.",
            "homepage": "http://knplabs.com",
            "keywords": [
                "api",
                "composer",
                "packagist"
            ],
            "support": {
                "issues": "https://github.com/KnpLabs/packagist-api/issues",
                "source": "https://github.com/KnpLabs/packagist-api/tree/master"
            },
            "time": "2015-09-07T14:25:16+00:00"
        },
        {
            "name": "symfony/console",
            "version": "v2.6.13",
            "target-dir": "Symfony/Component/Console",
            "source": {
                "type": "git",
                "url": "https://github.com/symfony/console.git",
                "reference": "0e5e18ae09d3f5c06367759be940e9ed3f568359"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/symfony/console/zipball/0e5e18ae09d3f5c06367759be940e9ed3f568359",
                "reference": "0e5e18ae09d3f5c06367759be940e9ed3f568359",
                "shasum": ""
            },
            "require": {
                "php": ">=5.3.3"
            },
            "require-dev": {
                "psr/log": "~1.0",
                "symfony/event-dispatcher": "~2.1",
                "symfony/phpunit-bridge": "~2.7",
                "symfony/process": "~2.1"
            },
            "suggest": {
                "psr/log": "For using the console logger",
                "symfony/event-dispatcher": "",
                "symfony/process": ""
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "2.6-dev"
                }
            },
            "autoload": {
                "psr-0": {
                    "Symfony\\Component\\Console\\": ""
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Fabien Potencier",
                    "email": "fabien@symfony.com"
                },
                {
                    "name": "Symfony Community",
                    "homepage": "https://symfony.com/contributors"
                }
            ],
            "description": "Symfony Console Component",
            "homepage": "https://symfony.com",
            "support": {
                "source": "https://github.com/symfony/console/tree/v2.6.11"
            },
            "time": "2015-07-26T09:08:40+00:00"
        },
        {
            "name": "symfony/event-dispatcher",
            "version": "v2.6.13",
            "target-dir": "Symfony/Component/EventDispatcher",
            "source": {
                "type": "git",
                "url": "https://github.com/symfony/event-dispatcher.git",
                "reference": "672593bc4b0043a0acf91903bb75a1c82d8f2e02"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/672593bc4b0043a0acf91903bb75a1c82d8f2e02",
                "reference": "672593bc4b0043a0acf91903bb75a1c82d8f2e02",
                "shasum": ""
            },
            "require": {
                "php": ">=5.3.3"
            },
            "require-dev": {
                "psr/log": "~1.0",
                "symfony/config": "~2.0,>=2.0.5",
                "symfony/dependency-injection": "~2.6",
                "symfony/expression-language": "~2.6",
                "symfony/phpunit-bridge": "~2.7",
                "symfony/stopwatch": "~2.3"
            },
            "suggest": {
                "symfony/dependency-injection": "",
                "symfony/http-kernel": ""
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "2.6-dev"
                }
            },
            "autoload": {
                "psr-0": {
                    "Symfony\\Component\\EventDispatcher\\": ""
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Fabien Potencier",
                    "email": "fabien@symfony.com"
                },
                {
                    "name": "Symfony Community",
                    "homepage": "https://symfony.com/contributors"
                }
            ],
            "description": "Symfony EventDispatcher Component",
            "homepage": "https://symfony.com",
            "support": {
                "source": "https://github.com/symfony/event-dispatcher/tree/v2.6.11"
            },
            "time": "2015-05-02T15:18:45+00:00"
        },
        {
            "name": "symfony/finder",
            "version": "v2.6.13",
            "target-dir": "Symfony/Component/Finder",
            "source": {
                "type": "git",
                "url": "https://github.com/symfony/finder.git",
                "reference": "203a10f928ae30176deeba33512999233181dd28"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/symfony/finder/zipball/203a10f928ae30176deeba33512999233181dd28",
                "reference": "203a10f928ae30176deeba33512999233181dd28",
                "shasum": ""
            },
            "require": {
                "php": ">=5.3.3"
            },
            "require-dev": {
                "symfony/phpunit-bridge": "~2.7"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "2.6-dev"
                }
            },
            "autoload": {
                "psr-0": {
                    "Symfony\\Component\\Finder\\": ""
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Fabien Potencier",
                    "email": "fabien@symfony.com"
                },
                {
                    "name": "Symfony Community",
                    "homepage": "https://symfony.com/contributors"
                }
            ],
            "description": "Symfony Finder Component",
            "homepage": "https://symfony.com",
            "support": {
                "source": "https://github.com/symfony/finder/tree/v2.6.11"
            },
            "time": "2015-07-09T16:02:48+00:00"
        },
        {
            "name": "symfony/process",
            "version": "v2.6.13",
            "target-dir": "Symfony/Component/Process",
            "source": {
                "type": "git",
                "url": "https://github.com/symfony/process.git",
                "reference": "57f1e88bb5dafa449b83f9f265b11d52d517b3e9"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/symfony/process/zipball/57f1e88bb5dafa449b83f9f265b11d52d517b3e9",
                "reference": "57f1e88bb5dafa449b83f9f265b11d52d517b3e9",
                "shasum": ""
            },
            "require": {
                "php": ">=5.3.3"
            },
            "require-dev": {
                "symfony/phpunit-bridge": "~2.7"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "2.6-dev"
                }
            },
            "autoload": {
                "psr-0": {
                    "Symfony\\Component\\Process\\": ""
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Fabien Potencier",
                    "email": "fabien@symfony.com"
                },
                {
                    "name": "Symfony Community",
                    "homepage": "https://symfony.com/contributors"
                }
            ],
            "description": "Symfony Process Component",
            "homepage": "https://symfony.com",
            "support": {
                "source": "https://github.com/symfony/process/tree/v2.6.11"
            },
            "time": "2015-06-30T16:10:16+00:00"
        }
    ],
    "packages-dev": [
        {
            "name": "doctrine/instantiator",
            "version": "1.0.5",
            "source": {
                "type": "git",
                "url": "https://github.com/doctrine/instantiator.git",
                "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d",
                "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d",
                "shasum": ""
            },
            "require": {
                "php": ">=5.3,<8.0-DEV"
            },
            "require-dev": {
                "athletic/athletic": "~0.1.8",
                "ext-pdo": "*",
                "ext-phar": "*",
                "phpunit/phpunit": "~4.0",
                "squizlabs/php_codesniffer": "~2.0"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "1.0.x-dev"
                }
            },
            "autoload": {
                "psr-4": {
                    "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/"
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Marco Pivetta",
                    "email": "ocramius@gmail.com",
                    "homepage": "http://ocramius.github.com/"
                }
            ],
            "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors",
            "homepage": "https://github.com/doctrine/instantiator",
            "keywords": [
                "constructor",
                "instantiate"
            ],
            "support": {
                "issues": "https://github.com/doctrine/instantiator/issues",
                "source": "https://github.com/doctrine/instantiator/tree/master"
            },
            "time": "2015-06-14T21:17:01+00:00"
        },
        {
            "name": "phpdocumentor/reflection-docblock",
            "version": "2.0.5",
            "source": {
                "type": "git",
                "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git",
                "reference": "e6a969a640b00d8daa3c66518b0405fb41ae0c4b"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/e6a969a640b00d8daa3c66518b0405fb41ae0c4b",
                "reference": "e6a969a640b00d8daa3c66518b0405fb41ae0c4b",
                "shasum": ""
            },
            "require": {
                "php": ">=5.3.3"
            },
            "require-dev": {
                "phpunit/phpunit": "~4.0"
            },
            "suggest": {
                "dflydev/markdown": "~1.0",
                "erusev/parsedown": "~1.0"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "2.0.x-dev"
                }
            },
            "autoload": {
                "psr-0": {
                    "phpDocumentor": [
                        "src/"
                    ]
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Mike van Riel",
                    "email": "mike.vanriel@naenius.com"
                }
            ],
            "support": {
                "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues",
                "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/release/2.x"
            },
            "time": "2016-01-25T08:17:30+00:00"
        },
        {
            "name": "phpspec/prophecy",
            "version": "v1.10.3",
            "source": {
                "type": "git",
                "url": "https://github.com/phpspec/prophecy.git",
                "reference": "451c3cd1418cf640de218914901e51b064abb093"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/phpspec/prophecy/zipball/451c3cd1418cf640de218914901e51b064abb093",
                "reference": "451c3cd1418cf640de218914901e51b064abb093",
                "shasum": ""
            },
            "require": {
                "doctrine/instantiator": "^1.0.2",
                "php": "^5.3|^7.0",
                "phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0|^5.0",
                "sebastian/comparator": "^1.2.3|^2.0|^3.0|^4.0",
                "sebastian/recursion-context": "^1.0|^2.0|^3.0|^4.0"
            },
            "require-dev": {
                "phpspec/phpspec": "^2.5 || ^3.2",
                "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "1.10.x-dev"
                }
            },
            "autoload": {
                "psr-4": {
                    "Prophecy\\": "src/Prophecy"
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Konstantin Kudryashov",
                    "email": "ever.zet@gmail.com",
                    "homepage": "http://everzet.com"
                },
                {
                    "name": "Marcello Duarte",
                    "email": "marcello.duarte@gmail.com"
                }
            ],
            "description": "Highly opinionated mocking framework for PHP 5.3+",
            "homepage": "https://github.com/phpspec/prophecy",
            "keywords": [
                "Double",
                "Dummy",
                "fake",
                "mock",
                "spy",
                "stub"
            ],
            "support": {
                "issues": "https://github.com/phpspec/prophecy/issues",
                "source": "https://github.com/phpspec/prophecy/tree/v1.10.3"
            },
            "time": "2020-03-05T15:02:03+00:00"
        },
        {
            "name": "phpunit/php-code-coverage",
            "version": "2.2.4",
            "source": {
                "type": "git",
                "url": "https://github.com/sebastianbergmann/php-code-coverage.git",
                "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/eabf68b476ac7d0f73793aada060f1c1a9bf8979",
                "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979",
                "shasum": ""
            },
            "require": {
                "php": ">=5.3.3",
                "phpunit/php-file-iterator": "~1.3",
                "phpunit/php-text-template": "~1.2",
                "phpunit/php-token-stream": "~1.3",
                "sebastian/environment": "^1.3.2",
                "sebastian/version": "~1.0"
            },
            "require-dev": {
                "ext-xdebug": ">=2.1.4",
                "phpunit/phpunit": "~4"
            },
            "suggest": {
                "ext-dom": "*",
                "ext-xdebug": ">=2.2.1",
                "ext-xmlwriter": "*"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "2.2.x-dev"
                }
            },
            "autoload": {
                "classmap": [
                    "src/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "BSD-3-Clause"
            ],
            "authors": [
                {
                    "name": "Sebastian Bergmann",
                    "email": "sb@sebastian-bergmann.de",
                    "role": "lead"
                }
            ],
            "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.",
            "homepage": "https://github.com/sebastianbergmann/php-code-coverage",
            "keywords": [
                "coverage",
                "testing",
                "xunit"
            ],
            "support": {
                "irc": "irc://irc.freenode.net/phpunit",
                "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
                "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/2.2"
            },
            "time": "2015-10-06T15:47:00+00:00"
        },
        {
            "name": "phpunit/php-file-iterator",
            "version": "1.4.5",
            "source": {
                "type": "git",
                "url": "https://github.com/sebastianbergmann/php-file-iterator.git",
                "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/730b01bc3e867237eaac355e06a36b85dd93a8b4",
                "reference": "730b01bc3e867237eaac355e06a36b85dd93a8b4",
                "shasum": ""
            },
            "require": {
                "php": ">=5.3.3"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "1.4.x-dev"
                }
            },
            "autoload": {
                "classmap": [
                    "src/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "BSD-3-Clause"
            ],
            "authors": [
                {
                    "name": "Sebastian Bergmann",
                    "email": "sb@sebastian-bergmann.de",
                    "role": "lead"
                }
            ],
            "description": "FilterIterator implementation that filters files based on a list of suffixes.",
            "homepage": "https://github.com/sebastianbergmann/php-file-iterator/",
            "keywords": [
                "filesystem",
                "iterator"
            ],
            "support": {
                "irc": "irc://irc.freenode.net/phpunit",
                "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues",
                "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/1.4.5"
            },
            "time": "2017-11-27T13:52:08+00:00"
        },
        {
            "name": "phpunit/php-text-template",
            "version": "1.2.1",
            "source": {
                "type": "git",
                "url": "https://github.com/sebastianbergmann/php-text-template.git",
                "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686",
                "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686",
                "shasum": ""
            },
            "require": {
                "php": ">=5.3.3"
            },
            "type": "library",
            "autoload": {
                "classmap": [
                    "src/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "BSD-3-Clause"
            ],
            "authors": [
                {
                    "name": "Sebastian Bergmann",
                    "email": "sebastian@phpunit.de",
                    "role": "lead"
                }
            ],
            "description": "Simple template engine.",
            "homepage": "https://github.com/sebastianbergmann/php-text-template/",
            "keywords": [
                "template"
            ],
            "support": {
                "issues": "https://github.com/sebastianbergmann/php-text-template/issues",
                "source": "https://github.com/sebastianbergmann/php-text-template/tree/1.2.1"
            },
            "time": "2015-06-21T13:50:34+00:00"
        },
        {
            "name": "phpunit/php-timer",
            "version": "1.0.9",
            "source": {
                "type": "git",
                "url": "https://github.com/sebastianbergmann/php-timer.git",
                "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3dcf38ca72b158baf0bc245e9184d3fdffa9c46f",
                "reference": "3dcf38ca72b158baf0bc245e9184d3fdffa9c46f",
                "shasum": ""
            },
            "require": {
                "php": "^5.3.3 || ^7.0"
            },
            "require-dev": {
                "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "1.0-dev"
                }
            },
            "autoload": {
                "classmap": [
                    "src/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "BSD-3-Clause"
            ],
            "authors": [
                {
                    "name": "Sebastian Bergmann",
                    "email": "sb@sebastian-bergmann.de",
                    "role": "lead"
                }
            ],
            "description": "Utility class for timing",
            "homepage": "https://github.com/sebastianbergmann/php-timer/",
            "keywords": [
                "timer"
            ],
            "support": {
                "issues": "https://github.com/sebastianbergmann/php-timer/issues",
                "source": "https://github.com/sebastianbergmann/php-timer/tree/master"
            },
            "time": "2017-02-26T11:10:40+00:00"
        },
        {
            "name": "phpunit/php-token-stream",
            "version": "1.4.12",
            "source": {
                "type": "git",
                "url": "https://github.com/sebastianbergmann/php-token-stream.git",
                "reference": "1ce90ba27c42e4e44e6d8458241466380b51fa16"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/1ce90ba27c42e4e44e6d8458241466380b51fa16",
                "reference": "1ce90ba27c42e4e44e6d8458241466380b51fa16",
                "shasum": ""
            },
            "require": {
                "ext-tokenizer": "*",
                "php": ">=5.3.3"
            },
            "require-dev": {
                "phpunit/phpunit": "~4.2"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "1.4-dev"
                }
            },
            "autoload": {
                "classmap": [
                    "src/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "BSD-3-Clause"
            ],
            "authors": [
                {
                    "name": "Sebastian Bergmann",
                    "email": "sebastian@phpunit.de"
                }
            ],
            "description": "Wrapper around PHP's tokenizer extension.",
            "homepage": "https://github.com/sebastianbergmann/php-token-stream/",
            "keywords": [
                "tokenizer"
            ],
            "support": {
                "issues": "https://github.com/sebastianbergmann/php-token-stream/issues",
                "source": "https://github.com/sebastianbergmann/php-token-stream/tree/1.4"
            },
            "abandoned": true,
            "time": "2017-12-04T08:55:13+00:00"
        },
        {
            "name": "phpunit/phpunit",
            "version": "4.8.36",
            "source": {
                "type": "git",
                "url": "https://github.com/sebastianbergmann/phpunit.git",
                "reference": "46023de9a91eec7dfb06cc56cb4e260017298517"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/46023de9a91eec7dfb06cc56cb4e260017298517",
                "reference": "46023de9a91eec7dfb06cc56cb4e260017298517",
                "shasum": ""
            },
            "require": {
                "ext-dom": "*",
                "ext-json": "*",
                "ext-pcre": "*",
                "ext-reflection": "*",
                "ext-spl": "*",
                "php": ">=5.3.3",
                "phpspec/prophecy": "^1.3.1",
                "phpunit/php-code-coverage": "~2.1",
                "phpunit/php-file-iterator": "~1.4",
                "phpunit/php-text-template": "~1.2",
                "phpunit/php-timer": "^1.0.6",
                "phpunit/phpunit-mock-objects": "~2.3",
                "sebastian/comparator": "~1.2.2",
                "sebastian/diff": "~1.2",
                "sebastian/environment": "~1.3",
                "sebastian/exporter": "~1.2",
                "sebastian/global-state": "~1.0",
                "sebastian/version": "~1.0",
                "symfony/yaml": "~2.1|~3.0"
            },
            "suggest": {
                "phpunit/php-invoker": "~1.1"
            },
            "bin": [
                "phpunit"
            ],
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "4.8.x-dev"
                }
            },
            "autoload": {
                "classmap": [
                    "src/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "BSD-3-Clause"
            ],
            "authors": [
                {
                    "name": "Sebastian Bergmann",
                    "email": "sebastian@phpunit.de",
                    "role": "lead"
                }
            ],
            "description": "The PHP Unit Testing framework.",
            "homepage": "https://phpunit.de/",
            "keywords": [
                "phpunit",
                "testing",
                "xunit"
            ],
            "support": {
                "issues": "https://github.com/sebastianbergmann/phpunit/issues",
                "source": "https://github.com/sebastianbergmann/phpunit/tree/4.8.36"
            },
            "time": "2017-06-21T08:07:12+00:00"
        },
        {
            "name": "phpunit/phpunit-mock-objects",
            "version": "2.3.8",
            "source": {
                "type": "git",
                "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git",
                "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/ac8e7a3db35738d56ee9a76e78a4e03d97628983",
                "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983",
                "shasum": ""
            },
            "require": {
                "doctrine/instantiator": "^1.0.2",
                "php": ">=5.3.3",
                "phpunit/php-text-template": "~1.2",
                "sebastian/exporter": "~1.2"
            },
            "require-dev": {
                "phpunit/phpunit": "~4.4"
            },
            "suggest": {
                "ext-soap": "*"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "2.3.x-dev"
                }
            },
            "autoload": {
                "classmap": [
                    "src/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "BSD-3-Clause"
            ],
            "authors": [
                {
                    "name": "Sebastian Bergmann",
                    "email": "sb@sebastian-bergmann.de",
                    "role": "lead"
                }
            ],
            "description": "Mock Object library for PHPUnit",
            "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/",
            "keywords": [
                "mock",
                "xunit"
            ],
            "support": {
                "irc": "irc://irc.freenode.net/phpunit",
                "issues": "https://github.com/sebastianbergmann/phpunit-mock-objects/issues",
                "source": "https://github.com/sebastianbergmann/phpunit-mock-objects/tree/2.3"
            },
            "abandoned": true,
            "time": "2015-10-02T06:51:40+00:00"
        },
        {
            "name": "sebastian/comparator",
            "version": "1.2.4",
            "source": {
                "type": "git",
                "url": "https://github.com/sebastianbergmann/comparator.git",
                "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2b7424b55f5047b47ac6e5ccb20b2aea4011d9be",
                "reference": "2b7424b55f5047b47ac6e5ccb20b2aea4011d9be",
                "shasum": ""
            },
            "require": {
                "php": ">=5.3.3",
                "sebastian/diff": "~1.2",
                "sebastian/exporter": "~1.2 || ~2.0"
            },
            "require-dev": {
                "phpunit/phpunit": "~4.4"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "1.2.x-dev"
                }
            },
            "autoload": {
                "classmap": [
                    "src/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "BSD-3-Clause"
            ],
            "authors": [
                {
                    "name": "Jeff Welch",
                    "email": "whatthejeff@gmail.com"
                },
                {
                    "name": "Volker Dusch",
                    "email": "github@wallbash.com"
                },
                {
                    "name": "Bernhard Schussek",
                    "email": "bschussek@2bepublished.at"
                },
                {
                    "name": "Sebastian Bergmann",
                    "email": "sebastian@phpunit.de"
                }
            ],
            "description": "Provides the functionality to compare PHP values for equality",
            "homepage": "http://www.github.com/sebastianbergmann/comparator",
            "keywords": [
                "comparator",
                "compare",
                "equality"
            ],
            "support": {
                "issues": "https://github.com/sebastianbergmann/comparator/issues",
                "source": "https://github.com/sebastianbergmann/comparator/tree/1.2"
            },
            "time": "2017-01-29T09:50:25+00:00"
        },
        {
            "name": "sebastian/diff",
            "version": "1.4.3",
            "source": {
                "type": "git",
                "url": "https://github.com/sebastianbergmann/diff.git",
                "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/7f066a26a962dbe58ddea9f72a4e82874a3975a4",
                "reference": "7f066a26a962dbe58ddea9f72a4e82874a3975a4",
                "shasum": ""
            },
            "require": {
                "php": "^5.3.3 || ^7.0"
            },
            "require-dev": {
                "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "1.4-dev"
                }
            },
            "autoload": {
                "classmap": [
                    "src/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "BSD-3-Clause"
            ],
            "authors": [
                {
                    "name": "Kore Nordmann",
                    "email": "mail@kore-nordmann.de"
                },
                {
                    "name": "Sebastian Bergmann",
                    "email": "sebastian@phpunit.de"
                }
            ],
            "description": "Diff implementation",
            "homepage": "https://github.com/sebastianbergmann/diff",
            "keywords": [
                "diff"
            ],
            "support": {
                "issues": "https://github.com/sebastianbergmann/diff/issues",
                "source": "https://github.com/sebastianbergmann/diff/tree/1.4"
            },
            "time": "2017-05-22T07:24:03+00:00"
        },
        {
            "name": "sebastian/environment",
            "version": "1.3.8",
            "source": {
                "type": "git",
                "url": "https://github.com/sebastianbergmann/environment.git",
                "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/be2c607e43ce4c89ecd60e75c6a85c126e754aea",
                "reference": "be2c607e43ce4c89ecd60e75c6a85c126e754aea",
                "shasum": ""
            },
            "require": {
                "php": "^5.3.3 || ^7.0"
            },
            "require-dev": {
                "phpunit/phpunit": "^4.8 || ^5.0"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "1.3.x-dev"
                }
            },
            "autoload": {
                "classmap": [
                    "src/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "BSD-3-Clause"
            ],
            "authors": [
                {
                    "name": "Sebastian Bergmann",
                    "email": "sebastian@phpunit.de"
                }
            ],
            "description": "Provides functionality to handle HHVM/PHP environments",
            "homepage": "http://www.github.com/sebastianbergmann/environment",
            "keywords": [
                "Xdebug",
                "environment",
                "hhvm"
            ],
            "support": {
                "issues": "https://github.com/sebastianbergmann/environment/issues",
                "source": "https://github.com/sebastianbergmann/environment/tree/1.3"
            },
            "time": "2016-08-18T05:49:44+00:00"
        },
        {
            "name": "sebastian/exporter",
            "version": "1.2.2",
            "source": {
                "type": "git",
                "url": "https://github.com/sebastianbergmann/exporter.git",
                "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/42c4c2eec485ee3e159ec9884f95b431287edde4",
                "reference": "42c4c2eec485ee3e159ec9884f95b431287edde4",
                "shasum": ""
            },
            "require": {
                "php": ">=5.3.3",
                "sebastian/recursion-context": "~1.0"
            },
            "require-dev": {
                "ext-mbstring": "*",
                "phpunit/phpunit": "~4.4"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "1.3.x-dev"
                }
            },
            "autoload": {
                "classmap": [
                    "src/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "BSD-3-Clause"
            ],
            "authors": [
                {
                    "name": "Jeff Welch",
                    "email": "whatthejeff@gmail.com"
                },
                {
                    "name": "Volker Dusch",
                    "email": "github@wallbash.com"
                },
                {
                    "name": "Bernhard Schussek",
                    "email": "bschussek@2bepublished.at"
                },
                {
                    "name": "Sebastian Bergmann",
                    "email": "sebastian@phpunit.de"
                },
                {
                    "name": "Adam Harvey",
                    "email": "aharvey@php.net"
                }
            ],
            "description": "Provides the functionality to export PHP variables for visualization",
            "homepage": "http://www.github.com/sebastianbergmann/exporter",
            "keywords": [
                "export",
                "exporter"
            ],
            "support": {
                "issues": "https://github.com/sebastianbergmann/exporter/issues",
                "source": "https://github.com/sebastianbergmann/exporter/tree/master"
            },
            "time": "2016-06-17T09:04:28+00:00"
        },
        {
            "name": "sebastian/global-state",
            "version": "1.1.1",
            "source": {
                "type": "git",
                "url": "https://github.com/sebastianbergmann/global-state.git",
                "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bc37d50fea7d017d3d340f230811c9f1d7280af4",
                "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4",
                "shasum": ""
            },
            "require": {
                "php": ">=5.3.3"
            },
            "require-dev": {
                "phpunit/phpunit": "~4.2"
            },
            "suggest": {
                "ext-uopz": "*"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "1.0-dev"
                }
            },
            "autoload": {
                "classmap": [
                    "src/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "BSD-3-Clause"
            ],
            "authors": [
                {
                    "name": "Sebastian Bergmann",
                    "email": "sebastian@phpunit.de"
                }
            ],
            "description": "Snapshotting of global state",
            "homepage": "http://www.github.com/sebastianbergmann/global-state",
            "keywords": [
                "global state"
            ],
            "support": {
                "issues": "https://github.com/sebastianbergmann/global-state/issues",
                "source": "https://github.com/sebastianbergmann/global-state/tree/1.1.1"
            },
            "time": "2015-10-12T03:26:01+00:00"
        },
        {
            "name": "sebastian/recursion-context",
            "version": "1.0.5",
            "source": {
                "type": "git",
                "url": "https://github.com/sebastianbergmann/recursion-context.git",
                "reference": "b19cc3298482a335a95f3016d2f8a6950f0fbcd7"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/b19cc3298482a335a95f3016d2f8a6950f0fbcd7",
                "reference": "b19cc3298482a335a95f3016d2f8a6950f0fbcd7",
                "shasum": ""
            },
            "require": {
                "php": ">=5.3.3"
            },
            "require-dev": {
                "phpunit/phpunit": "~4.4"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "1.0.x-dev"
                }
            },
            "autoload": {
                "classmap": [
                    "src/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "BSD-3-Clause"
            ],
            "authors": [
                {
                    "name": "Jeff Welch",
                    "email": "whatthejeff@gmail.com"
                },
                {
                    "name": "Sebastian Bergmann",
                    "email": "sebastian@phpunit.de"
                },
                {
                    "name": "Adam Harvey",
                    "email": "aharvey@php.net"
                }
            ],
            "description": "Provides functionality to recursively process PHP variables",
            "homepage": "http://www.github.com/sebastianbergmann/recursion-context",
            "support": {
                "issues": "https://github.com/sebastianbergmann/recursion-context/issues",
                "source": "https://github.com/sebastianbergmann/recursion-context/tree/master"
            },
            "time": "2016-10-03T07:41:43+00:00"
        },
        {
            "name": "sebastian/version",
            "version": "1.0.6",
            "source": {
                "type": "git",
                "url": "https://github.com/sebastianbergmann/version.git",
                "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6",
                "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6",
                "shasum": ""
            },
            "type": "library",
            "autoload": {
                "classmap": [
                    "src/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "BSD-3-Clause"
            ],
            "authors": [
                {
                    "name": "Sebastian Bergmann",
                    "email": "sebastian@phpunit.de",
                    "role": "lead"
                }
            ],
            "description": "Library that helps with managing the version number of Git-hosted PHP projects",
            "homepage": "https://github.com/sebastianbergmann/version",
            "support": {
                "issues": "https://github.com/sebastianbergmann/version/issues",
                "source": "https://github.com/sebastianbergmann/version/tree/1.0.6"
            },
            "time": "2015-06-21T13:59:46+00:00"
        },
        {
            "name": "symfony/yaml",
            "version": "v2.6.13",
            "target-dir": "Symfony/Component/Yaml",
            "source": {
                "type": "git",
                "url": "https://github.com/symfony/yaml.git",
                "reference": "c044d1744b8e91aaaa0d9bac683ab87ec7cbf359"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/symfony/yaml/zipball/c044d1744b8e91aaaa0d9bac683ab87ec7cbf359",
                "reference": "c044d1744b8e91aaaa0d9bac683ab87ec7cbf359",
                "shasum": ""
            },
            "require": {
                "php": ">=5.3.3"
            },
            "require-dev": {
                "symfony/phpunit-bridge": "~2.7"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "2.6-dev"
                }
            },
            "autoload": {
                "psr-0": {
                    "Symfony\\Component\\Yaml\\": ""
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Fabien Potencier",
                    "email": "fabien@symfony.com"
                },
                {
                    "name": "Symfony Community",
                    "homepage": "https://symfony.com/contributors"
                }
            ],
            "description": "Symfony Yaml Component",
            "homepage": "https://symfony.com",
            "support": {
                "source": "https://github.com/symfony/yaml/tree/v2.6.11"
            },
            "time": "2015-07-26T08:59:42+00:00"
        }
    ],
    "aliases": [],
    "minimum-stability": "stable",
    "stability-flags": [],
    "prefer-stable": false,
    "prefer-lowest": false,
    "platform": {
        "php": ">=5.3.6"
    },
    "platform-dev": [],
    "platform-overrides": {
        "php": "5.3.6"
    },
    "plugin-api-version": "2.2.0"
}
<?php
namespace Herrera\Box;
use InvalidArgumentException;
use LengthException;
use RuntimeException;
use UnexpectedValueException;
define('BOX_EXTRACT_PATTERN_DEFAULT','__HALT'.'_COMPILER(); ?>');
define('BOX_EXTRACT_PATTERN_OPEN',"__HALT"."_COMPILER(); ?>\r\n");
class Extract
{
const PATTERN_DEFAULT=BOX_EXTRACT_PATTERN_DEFAULT;
const PATTERN_OPEN=BOX_EXTRACT_PATTERN_OPEN;
const GZ=4096;
const BZ2=8192;
const MASK=12288;
private$file;
private$handle;
private$stub;
function __construct($file,$stub){
if(!is_file($file)){
throw new InvalidArgumentException(sprintf('The path "%s" is not a file or does not exist.',$file
));
}
$this->file=$file;
$this->stub=$stub;
}
static function findStubLength($file,$pattern=self::PATTERN_OPEN
){
if(!($fp=fopen($file,'rb'))){
throw new RuntimeException(sprintf('The phar "%s" could not be opened for reading.',$file
));
}
$stub=null;
$offset=0;
$combo=str_split($pattern);
while(!feof($fp)){
if(fgetc($fp)===$combo[$offset]){
$offset++;
if(!isset($combo[$offset])){
$stub=ftell($fp);
break;
}
}else{
$offset=0;
}
}
fclose($fp);
if(null===$stub){
throw new InvalidArgumentException(sprintf('The pattern could not be found in "%s".',$file
));
}
return$stub;
}
function go($dir=null){
if(null===$dir){
$dir=rtrim(sys_get_temp_dir(),'\\/').DIRECTORY_SEPARATOR
.'pharextract'.DIRECTORY_SEPARATOR
.basename($this->file,'.phar');
}else{
$dir=realpath($dir);
}
$md5=$dir.DIRECTORY_SEPARATOR.md5_file($this->file);
if(file_exists($md5)){
return$dir;
}
if(!is_dir($dir)){
$this->createDir($dir);
}
$this->open();
if(-1===fseek($this->handle,$this->stub)){
throw new RuntimeException(sprintf('Could not seek to %d in the file "%s".',$this->stub,$this->file
));
}
$info=$this->readManifest();
if($info['flags']&self::GZ){
if(!function_exists('gzinflate')){
throw new RuntimeException('The zlib extension is (gzinflate()) is required for "%s.',$this->file
);
}
}
if($info['flags']&self::BZ2){
if(!function_exists('bzdecompress')){
throw new RuntimeException('The bzip2 extension (bzdecompress()) is required for "%s".',$this->file
);
}
}
self::purge($dir);
$this->createDir($dir);
$this->createFile($md5);
foreach($info['files']as$info){
$path=$dir.DIRECTORY_SEPARATOR.$info['path'];
$parent=dirname($path);
if(!is_dir($parent)){
$this->createDir($parent);
}
if(preg_match('{/$}',$info['path'])){
$this->createDir($path,511,false);
}else{
$this->createFile($path,$this->extractFile($info));
}
}
return$dir;
}
static function purge($path){
if(is_dir($path)){
foreach(scandir($path)as$item){
if(('.'===$item)||('..'===$item)){
continue;
}
self::purge($path.DIRECTORY_SEPARATOR.$item);
}
if(!rmdir($path)){
throw new RuntimeException(sprintf('The directory "%s" could not be deleted.',$path
));
}
}else{
if(!unlink($path)){
throw new RuntimeException(sprintf('The file "%s" could not be deleted.',$path
));
}
}
}
private function createDir($path,$chmod=511,$recursive=true){
if(!mkdir($path,$chmod,$recursive)){
throw new RuntimeException(sprintf('The directory path "%s" could not be created.',$path
));
}
}
private function createFile($path,$contents='',$mode=438){
if(false===file_put_contents($path,$contents)){
throw new RuntimeException(sprintf('The file "%s" could not be written.',$path
));
}
if(!chmod($path,$mode)){
throw new RuntimeException(sprintf('The file "%s" could not be chmodded to %o.',$path,$mode
));
}
}
private function extractFile($info){
if(0===$info['size']){
return'';
}
$data=$this->read($info['compressed_size']);
if($info['flags']&self::GZ){
if(false===($data=gzinflate($data))){
throw new RuntimeException(sprintf('The "%s" file could not be inflated (gzip) from "%s".',$info['path'],$this->file
));
}
}elseif($info['flags']&self::BZ2){
if(false===($data=bzdecompress($data))){
throw new RuntimeException(sprintf('The "%s" file could not be inflated (bzip2) from "%s".',$info['path'],$this->file
));
}
}
if(($actual=strlen($data))!==$info['size']){
throw new UnexpectedValueException(sprintf('The size of "%s" (%d) did not match what was expected (%d) in "%s".',$info['path'],$actual,$info['size'],$this->file
));
}
$crc32=sprintf('%u',crc32($data)&4294967295);
if($info['crc32']!=$crc32){
throw new UnexpectedValueException(sprintf('The crc32 checksum (%s) for "%s" did not match what was expected (%s) in "%s".',$crc32,$info['path'],$info['crc32'],$this->file
));
}
return$data;
}
private function open(){
if(null===($this->handle=fopen($this->file,'rb'))){
$this->handle=null;
throw new RuntimeException(sprintf('The file "%s" could not be opened for reading.',$this->file
));
}
}
private function read($bytes){
$read='';
$total=$bytes;
while(!feof($this->handle)&&$bytes){
if(false===($chunk=fread($this->handle,$bytes))){
throw new RuntimeException(sprintf('Could not read %d bytes from "%s".',$bytes,$this->file
));
}
$read.=$chunk;
$bytes-=strlen($chunk);
}
if(($actual=strlen($read))!==$total){
throw new RuntimeException(sprintf('Only read %d of %d in "%s".',$actual,$total,$this->file
));
}
return$read;
}
private function readManifest(){
$size=unpack('V',$this->read(4));
$size=$size[1];
$raw=$this->read($size);
$count=unpack('V',substr($raw,0,4));
$count=$count[1];
$aliasSize=unpack('V',substr($raw,10,4));
$aliasSize=$aliasSize[1];
$raw=substr($raw,14+$aliasSize);
$metaSize=unpack('V',substr($raw,0,4));
$metaSize=$metaSize[1];
$offset=0;
$start=4+$metaSize;
$manifest=array('files'=>array(),'flags'=>0,);
for($i=0;$i<$count;$i++){
$length=unpack('V',substr($raw,$start,4));
$length=$length[1];
$start+=4;
$path=substr($raw,$start,$length);
$start+=$length;
$file=unpack('Vsize/Vtimestamp/Vcompressed_size/Vcrc32/Vflags/Vmetadata_length',substr($raw,$start,24));
$file['path']=$path;
$file['crc32']=sprintf('%u',$file['crc32']&4294967295);
$file['offset']=$offset;
$offset+=$file['compressed_size'];
$start+=24+$file['metadata_length'];
$manifest['flags']|=$file['flags']&self::MASK;
$manifest['files'][]=$file;
}
return$manifest;
}
}
<?php

namespace Clue\PharComposer\Box;

/**
 * Generates a new PHP bootstrap loader stub for a Phar.
 *
 * This has been copied from herrera-io/box v1.6.1 as is with only the
 * following minor adjustments:
 * - adjusted namespace
 * - use global `InvalidArgumentException` instead of namespaced variant
 * - use minified Extract.min.php instead of running Compactor on Extract.php (original)
 *
 * @author Kevin Herrera <kevin@herrera.io>
 */
class StubGenerator
{
    /**
     * The list of server variables that are allowed to be modified.
     *
     * @var array
     */
    private static $allowedMung = array(
        'PHP_SELF',
        'REQUEST_URI',
        'SCRIPT_FILENAME',
        'SCRIPT_NAME'
    );

    /**
     * The alias to be used in "phar://" URLs.
     *
     * @var string
     */
    private $alias;

    /**
     * The top header comment banner text.
     *
     * @var string.
     */
    private $banner = 'Generated by Box.

@link https://github.com/herrera-io/php-box/';

    /**
     * Embed the Extract class in the stub?
     *
     * @var boolean
     */
    private $extract = false;

    /**
     * The processed extract code.
     *
     * @var array
     */
    private $extractCode = array();

    /**
     * Force the use of the Extract class?
     *
     * @var boolean
     */
    private $extractForce = false;

    /**
     * The location within the Phar of index script.
     *
     * @var string
     */
    private $index;

    /**
     * Use the Phar::interceptFileFuncs() method?
     *
     * @var boolean
     */
    private $intercept = false;

    /**
     * The map for file extensions and their mimetypes.
     *
     * @var array
     */
    private $mimetypes = array();

    /**
     * The list of server variables to modify.
     *
     * @var array
     */
    private $mung = array();

    /**
     * The location of the script to run when a file is not found.
     *
     * @var string
     */
    private $notFound;

    /**
     * The rewrite function.
     *
     * @var string
     */
    private $rewrite;

    /**
     * The shebang line.
     *
     * @var string
     */
    private $shebang = '#!/usr/bin/env php';

    /**
     * Use Phar::webPhar() instead of Phar::mapPhar()?
     *
     * @var boolean
     */
    private $web = false;

    /**
     * Sets the alias to be used in "phar://" URLs.
     *
     * @param string $alias The alias.
     *
     * @return StubGenerator The stub generator.
     */
    public function alias($alias)
    {
        $this->alias = $alias;

        return $this;
    }

    /**
     * Sets the top header comment banner text.
     *
     * @param string $banner The banner text.
     *
     * @return StubGenerator The stub generator.
     */
    public function banner($banner)
    {
        $this->banner = $banner;

        return $this;
    }

    /**
     * Creates a new instance of the stub generator.
     *
     * @return StubGenerator The stub generator.
     */
    public static function create()
    {
        return new static();
    }

    /**
     * Embed the Extract class in the stub?
     *
     * @param boolean $extract Embed the class?
     * @param boolean $force   Force the use of the class?
     *
     * @return StubGenerator The stub generator.
     */
    public function extract($extract, $force = false)
    {
        $this->extract = $extract;
        $this->extractForce = $force;

        if ($extract) {
            $this->extractCode = array(
                'constants' => array(),
                'class' => array(),
            );

            $code = file_get_contents(__DIR__ . '/Extract.min.php');
            $code = preg_replace('/\n+/', "\n", $code);
            $code = explode("\n", $code);
            $code = array_slice($code, 2);

            foreach ($code as $i => $line) {
                if ((0 === strpos($line, 'use'))
                    && (false === strpos($line, '\\'))
                ) {
                    unset($code[$i]);
                } elseif (0 === strpos($line, 'define')) {
                    $this->extractCode['constants'][] = $line;
                } else {
                    $this->extractCode['class'][] = $line;
                }
            }
        }

        return $this;
    }

    /**
     * Sets location within the Phar of index script.
     *
     * @param string $index The index file.
     *
     * @return StubGenerator The stub generator.
     */
    public function index($index)
    {
        $this->index = $index;

        return $this;
    }

    /**
     * Use the Phar::interceptFileFuncs() method in the stub?
     *
     * @param boolean $intercept Use interceptFileFuncs()?
     *
     * @return StubGenerator The stub generator.
     */
    public function intercept($intercept)
    {
        $this->intercept = $intercept;

        return $this;
    }

    /**
     * Generates the stub.
     *
     * @return string The stub.
     */
    public function generate()
    {
        $stub = array();

        if ('' !== $this->shebang) {
            $stub[] = $this->shebang;
        }

        $stub[] = '<?php';

        if (null !== $this->banner) {
            $stub[] = $this->getBanner();
        }

        if ($this->extract) {
            $stub[] = join("\n", $this->extractCode['constants']);

            if ($this->extractForce) {
                $stub = array_merge($stub, $this->getExtractSections());
            }
        }

        $stub = array_merge($stub, $this->getPharSections());

        if ($this->extract) {
            if ($this->extractForce) {
                if ($this->index && !$this->web) {
                    $stub[] = "require \"\$dir/{$this->index}\";";
                }
            } else {
                end($stub);

                $stub[key($stub)] .= ' else {';

                $stub = array_merge($stub, $this->getExtractSections());

                if ($this->index) {
                    $stub[] = "require \"\$dir/{$this->index}\";";
                }

                $stub[] = '}';
            }

            $stub[] = join("\n", $this->extractCode['class']);
        }

        $stub[] = "__HALT_COMPILER();";

        return join("\n", $stub);
    }

    /**
     * Sets the map for file extensions and their mimetypes.
     *
     * @param array $mimetypes The map.
     *
     * @return StubGenerator The stub generator.
     */
    public function mimetypes(array $mimetypes)
    {
        $this->mimetypes = $mimetypes;

        return $this;
    }

    /**
     * Sets the list of server variables to modify.
     *
     * @param array $list The list.
     *
     * @return StubGenerator The stub generator.
     *
     * @throws \InvalidArgumentException If the list contains an invalid value.
     */
    public function mung(array $list)
    {
        foreach ($list as $value) {
            if (false === in_array($value, self::$allowedMung)) {
                throw new \InvalidArgumentException(sprintf(
                    'The $_SERVER variable "%s" is not allowed.',
                    $value
                ));
            }
        }

        $this->mung = $list;

        return $this;
    }

    /**
     * Sets the location of the script to run when a file is not found.
     *
     * @param string $script The script.
     *
     * @return StubGenerator The stub generator.
     */
    public function notFound($script)
    {
        $this->notFound = $script;

        return $this;
    }

    /**
     * Sets the rewrite function.
     *
     * @param string $function The function.
     *
     * @return StubGenerator The stub generator.
     */
    public function rewrite($function)
    {
        $this->rewrite = $function;

        return $this;
    }

    /**
     * Sets the shebang line.
     *
     * @param string $shebang The shebang line.
     *
     * @return StubGenerator The stub generator.
     */
    public function shebang($shebang)
    {
        $this->shebang = $shebang;

        return $this;
    }

    /**
     * Use Phar::webPhar() instead of Phar::mapPhar()?
     *
     * @param boolean $web Use Phar::webPhar()?
     *
     * @return StubGenerator The stub generator.
     */
    public function web($web)
    {
        $this->web = $web;

        return $this;
    }

    /**
     * Escapes an argument so it can be written as a string in a call.
     *
     * @param string $arg   The argument.
     * @param string $quote The quote.
     *
     * @return string The escaped argument.
     */
    private function arg($arg, $quote = "'")
    {
        return $quote . addcslashes($arg, $quote) . $quote;
    }

    /**
     * Returns the alias map.
     *
     * @return string The alias map.
     */
    private function getAlias()
    {
        $stub = '';
        $prefix = '';

        if ($this->extractForce) {
            $prefix = '$dir/';
        }

        if ($this->web) {
            $stub .= 'Phar::webPhar(' . $this->arg($this->alias);

            if ($this->index) {
                $stub .= ', ' . $this->arg($prefix . $this->index, '"');

                if ($this->notFound) {
                    $stub .= ', ' . $this->arg($prefix . $this->notFound, '"');

                    if ($this->mimetypes) {
                        $stub .= ', ' . var_export(
                            $this->mimetypes,
                            true
                        );

                        if ($this->rewrite) {
                            $stub .= ', ' . $this->arg($this->rewrite);
                        }
                    }
                }
            }

            $stub .= ');';
        } else {
            $stub .= 'Phar::mapPhar(' . $this->arg($this->alias) . ');';
        }

        return $stub;
    }

    /**
     * Returns the banner after it has been processed.
     *
     * @return string The processed banner.
     */
    private function getBanner()
    {
        $banner = "/**\n * ";
        $banner .= str_replace(
            " \n",
            "\n",
            str_replace("\n", "\n * ", $this->banner)
        );

        $banner .= "\n */";

        return $banner;
    }

    /**
     * Returns the self extracting sections of the stub.
     *
     * @return array The stub sections.
     */
    private function getExtractSections()
    {
        return array(
            '$extract = new Extract(__FILE__, Extract::findStubLength(__FILE__));',
            '$dir = $extract->go();',
            'set_include_path($dir . PATH_SEPARATOR . get_include_path());',
        );
    }

    /**
     * Returns the sections of the stub that use the Phar class.
     *
     * @return array The stub sections.
     */
    private function getPharSections()
    {
        $stub = array(
            'if (class_exists(\'Phar\')) {',
            $this->getAlias(),
        );

        if ($this->intercept) {
            $stub[] = "Phar::interceptFileFuncs();";
        }

        if ($this->mung) {
            $stub[] = 'Phar::mungServer(' . var_export($this->mung, true) . ");";
        }

        if ($this->index && !$this->web && !$this->extractForce) {
            $stub[] = "require 'phar://' . __FILE__ . '/{$this->index}';";
        }

        $stub[] = '}';

        return $stub;
    }
}
<?php

namespace Clue\PharComposer\Package;

use Symfony\Component\Finder\Finder;

/**
 * A bundle represents all resources from a package that should be bundled into
 * the target phar.
 */
class Bundle implements \IteratorAggregate
{
    /**
     * list of resources in this bundle
     *
     * @type  array
     */
    private $resources = array();

    /**
     * add given file to bundle
     *
     * @param   string  $file
     * @return  Bundle
     */
    public function addFile($file)
    {
        $this->resources[] = $file;
        return $this;
    }

    /**
     * add given directory to bundle
     *
     * @param   Finder  $dir
     * @return  Bundle
     */
    public function addDir(Finder $dir)
    {
        $this->resources[] = $dir;
        return $this;
    }

    /**
     * checks if a bundle contains given resource
     *
     * @param   string  $resource
     * @return  bool
     */
    public function contains($resource)
    {
        foreach ($this->resources as $containedResource) {
            if (is_string($containedResource) && $containedResource == $resource) {
                return true;
            }

            if ($containedResource instanceof Finder && $this->directoryContains($containedResource, $resource)) {
                return true;
            }
        }

        return false;
    }

    /**
     * checks if given directory contains given resource
     *
     * @param   Finder  $dir
     * @param   string  $resource
     * @return  bool
     */
    private function directoryContains(Finder $dir, $resource)
    {
        foreach ($dir as $containedResource) {
            /* @var $containedResource \SplFileInfo */
            if (substr($containedResource->getRealPath(), 0, strlen($resource)) == $resource) {
                return true;
            }
        }

        return false;
    }

    /**
     * returns list of resources
     *
     * @return  \Traversable
     */
    #[\ReturnTypeWillChange]
    public function getIterator()
    {
        return new \ArrayIterator($this->resources);
    }
}
<?php

namespace Clue\PharComposer\Package;

use Symfony\Component\Finder\Finder;

/**
 * The package represents either the main/root package or one of the vendor packages.
 */
class Package
{
    private $package;
    private $directory;

    /**
     * Instantiate package
     *
     * @param array  $package   package information (parsed composer.json)
     * @param string $directory base directory of this package
     */
    public function __construct(array $package, $directory)
    {
        $this->package = $package;
        $this->directory = rtrim($directory, '/') . '/';
    }

    /**
     * get package name as defined in composer.json
     *
     * @return ?string
     */
    public function getName()
    {
        return isset($this->package['name']) ? $this->package['name'] : null;
    }

    /**
     * @return string
     */
    public function getShortName()
    {
        // skip vendor name from package name or default to last directory component
        $name = $this->getName();
        if ($name === null) {
            $name = realpath($this->directory);
            if ($name === false) {
                $name = $this->directory;
            }
        }
        return basename($name);
    }

    /**
     * Get path to vendor directory (relative to package directory, always ends with slash)
     *
     * @return string
     */
    public function getPathVendor()
    {
        $vendor = 'vendor';
        if (isset($this->package['config']['vendor-dir'])) {
            $vendor = $this->package['config']['vendor-dir'];
        }
        return $vendor . '/';
    }

    /**
     * Get package directory (the directory containing its composer.json, always ends with slash)
     *
     * @return string
     */
    public function getDirectory()
    {
        return $this->directory;
    }

    /**
     * @return \Clue\PharComposer\Package\Bundle
     */
    public function bundle()
    {
        $bundle = new Bundle();

        // return empty bundle if this package does not define any files and directory does not exist
        if (empty($this->package['autoload']) && !is_dir($this->directory . $this->getPathVendor())) {
            return $bundle;
        }

        $iterator = Finder::create()
            ->files()
            ->ignoreVCS(true)
            ->exclude(rtrim($this->getPathVendor(), '/'))
            ->notPath('/^composer\.phar/')
            ->notPath('/^phar-composer\.phar/')
            ->in($this->getDirectory());

        return $bundle->addDir($iterator);
    }

    /**
     * Get list of files defined as "bin" (relative to package directory)
     *
     * @return string[]
     */
    public function getBins()
    {
        return isset($this->package['bin']) ? $this->package['bin'] : array();
    }
}
<?php

namespace Clue\PharComposer;

/**
 * Interface for logging outout.
 *
 * TODO: should be used in the Command classes as well
 */
class Logger
{
    private $output = true;

    /**
     * set output function to use to output log messages
     *
     * @param callable|boolean $output callable that receives a single $line argument or boolean echo
     *
     * TODO: think about whether this should be a constructor instead
     */
    public function setOutput($output)
    {
        $this->output = $output;
    }

    public function log($message)
    {
        $this->output($message . PHP_EOL);
    }

    private function output($message)
    {
        if ($this->output === true) {
            echo $message;
        } elseif ($this->output !== false) {
            call_user_func($this->output, $message);
        }
    }
}
<?php

namespace Clue\PharComposer;

use Symfony\Component\Console\Application as BaseApplication;

class App extends BaseApplication
{
    public function __construct()
    {
        parent::__construct('phar-composer', '1.4.0');

        $this->add(new Command\Build());
        $this->add(new Command\Search());
        $this->add(new Command\Install());

        $this->setDefaultCommand('search');
    }
}
<?php

namespace Clue\PharComposer\Command;

use Clue\PharComposer\Phar\Packager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class Build extends Command
{
    /** @var Packager */
    private $packager;

    public function __construct(Packager $packager = null)
    {
        parent::__construct();

        if ($packager === null) {
            $packager = new Packager();
        }
        $this->packager = $packager;
    }

    protected function configure()
    {
        $this->setName('build')
             ->setDescription('Build phar for the given composer project')
             ->addArgument('project', InputArgument::OPTIONAL, 'Path to project directory or composer.json', '.')
             ->addArgument('target', InputArgument::OPTIONAL, 'Path to write phar output to (defaults to project name)');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->packager->setOutput($output);
        $this->packager->coerceWritable();

        $pharer = $this->packager->getPharer($input->getArgument('project'));

        $target = $input->getArgument('target');
        if ($target !== null) {
            $pharer->setTarget($target);
        }

        $pharer->build();

        return 0;
    }
}
<?php


namespace Clue\PharComposer\Command;

use Clue\PharComposer\Phar\Packager;
use Packagist\Api\Client;
use Packagist\Api\Result\Package;
use Packagist\Api\Result\Package\Version;
use Packagist\Api\Result\Result;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ChoiceQuestion;
use Symfony\Component\Console\Question\Question;

class Search extends Command
{
    /** @var Packager */
    private $packager;

    /** @var Client */
    private $packagist;

    /** @var bool */
    private $isWindows;

    public function __construct(Packager $packager = null, Client $packagist = null, $isWindows = null)
    {
        if ($packager === null) {
            $packager = new Packager();
        }
        if ($packagist === null) {
            $packagist = new Client();
        }
        if ($isWindows === null) {
            $isWindows = DIRECTORY_SEPARATOR === '\\';
        }
        $this->packager = $packager;
        $this->packagist = $packagist;
        $this->isWindows = $isWindows;

        parent::__construct();
    }

    protected function configure()
    {
        $this->setName('search')
             ->setDescription('Interactive search for project name')
             ->addArgument('project', InputArgument::OPTIONAL, 'Project name or path', null);
    }

    /**
     * @param InputInterface       $input
     * @param OutputInterface      $output
     * @param string               $label
     * @param array<string,string> $choices
     * @param ?string              $abortable
     * @return ?string
     */
    protected function select(InputInterface $input, OutputInterface $output, $label, array $choices, $abortable = null)
    {
        $helper = $this->getHelper('question');
        assert($helper instanceof QuestionHelper);

        if (!$choices) {
            $output->writeln('<error>No matching packages found</error>');
            return null;
        }

        // use numeric keys for all options
        $select = array_merge(array(0 => $abortable), array_values($choices));
        if ($abortable === null) {
            unset($select[0]);
        }

        $question = new ChoiceQuestion($label, $select);
        $index = array_search($helper->ask($input, $output, $question), $select);

        if ($index === 0) {
            return null;
        }

        $indices = array_keys($choices);
        return $indices[$index - 1];
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->packager->setOutput($output);
        $this->packager->coerceWritable();

        $helper = $this->getHelper('question');
        assert($helper instanceof QuestionHelper);

        $project = $input->getArgument('project');

        do {
            if ($project === null) {
                // ask for input
                $question = new Question('Enter (partial) project name > ', '');
                $project = $helper->ask($input, $output, $question);
            } else {
                $output->writeln('Searching for <info>' . $project . '</info>...');
            }

            $choices = array();
            foreach ($this->packagist->search($project) as $result) {
                assert($result instanceof Result);

                $label = str_pad($result->getName(), 39) . ' ';
                $label = str_replace($project, '<info>' . $project . '</info>', $label);
                $label .= $result->getDescription();

                $label .= ' (⤓' . $result->getDownloads() . ')';

                $choices[$result->getName()] = $label;
            }

            $project = $this->select($input, $output, 'Select matching package', $choices, 'Start new search');
        } while ($project === null);

        $output->writeln('Selected <info>' . $project . '</info>, listing versions...');

        $package = $this->packagist->get($project);
        assert($package instanceof Package);

        $choices = array();
        foreach ($package->getVersions() as $version) {
            assert($version instanceof Version);

            $label = $version->getVersion();

            /* @var ?string $bin */
            $bin = $version->getBin();
            $label .= $bin !== null ? ' (☑ executable bin)' : ' (<error>no executable bin</error>)';

            $choices[$version->getVersion()] = $label;
        }

        $version = $this->select($input, $output, 'Select available version', $choices);

        $action = $this->select(
            $input,
            $output,
            'Action',
            array_filter(array(
                'build'   => 'Build project',
                'install' => $this->isWindows ? null : 'Install project system-wide'
            )),
            'Quit'
        );

        if ($action === null) {
            return 0;
        }

        $pharer = $this->packager->getPharer($project, $version);

        if ($action === 'install') {
            $path = $this->packager->getSystemBin($pharer->getPackageRoot());
            $this->packager->install($pharer, $path);
        } else {
            $pharer->build();
        }

        return 0;
    }
}
<?php

namespace Clue\PharComposer\Command;

use Clue\PharComposer\Phar\Packager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;

class Install extends Command
{
    /** @var Packager */
    private $packager;

    /** @var bool */
    private $isWindows;

    public function __construct(Packager $packager = null, $isWindows = null)
    {
        if ($packager === null) {
            $packager = new Packager();
        }
        if ($isWindows === null) {
            $isWindows = DIRECTORY_SEPARATOR === '\\';
        }
        $this->packager = $packager;
        $this->isWindows = $isWindows;

        parent::__construct();
    }

    protected function configure()
    {
        $this->setName('install')
             ->setDescription('Install phar into system wide binary directory' . ($this->isWindows ? ' (not available on Windows)' : ''))
             ->addArgument('project', InputArgument::OPTIONAL, 'Project name or path', '.')
             ->addArgument('target', InputArgument::OPTIONAL, 'Path to install to', '/usr/local/bin');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        if ($this->isWindows) {
            $output->writeln('<error>Command not available on this platform. Please use the "build" command and place Phar in your $PATH manually.</error>');
            return 1;
        }

        $this->packager->setOutput($output);
        $this->packager->coerceWritable();

        $pharer = $this->packager->getPharer($input->getArgument('project'));

        $path = $this->packager->getSystemBin($pharer->getPackageRoot(), $input->getArgument('target'));

        if (is_file($path)) {
            $helper = $this->getHelper('question');
            assert($helper instanceof QuestionHelper);

            $question = new ConfirmationQuestion('Overwrite existing file <info>' . $path . '</info>? [y] > ', true);
            if (!$helper->ask($input, $output, $question)) {
                $output->writeln('Aborting');
                return 0;
            }
        }

        $this->packager->install($pharer, $path);

        return 0;
    }
}
<?php

namespace Clue\PharComposer\Phar;

use Clue\PharComposer\Logger;
use Clue\PharComposer\Package\Package;
use Clue\PharComposer\Box\StubGenerator;

/**
 * The PharComposer is responsible for collecting options and then building the target phar
 */
class PharComposer
{
    private $package;
    private $main = null;
    private $target = null;
    private $logger;
    private $step = '?';

    /**
     * @param string $path path to composer.json file
     * @throws \InvalidArgumentException when given $path can not be parsed as JSON
     */
    public function __construct($path)
    {
        $this->package = new Package($this->loadJson($path), dirname(realpath($path)));
        $this->logger = new Logger();
    }

    /**
     * set output function to use to output log messages
     *
     * @param callable|boolean $output callable that receives a single $line argument or boolean echo
     */
    public function setOutput($output)
    {
        $this->logger->setOutput($output);
    }

    /**
     * Get path to target phar file (absolute path or relative to current directory)
     *
     * @return string
     */
    public function getTarget()
    {
        if ($this->target === null) {
            $this->target = $this->package->getShortName() . '.phar';
        }
        return $this->target;
    }

    /**
     * Set path to target phar file (absolute path or relative to current directory)
     *
     * If the given path is a directory, the default target (package short name)
     * will be appended automatically.
     *
     * @param string $target
     * @return $this
     */
    public function setTarget($target)
    {
        // path is actually a directory => append package name
        if (is_dir($target)) {
            $this->target = null;
            $target = rtrim($target, '/') . '/' . $this->getTarget();
        }
        $this->target = $target;
        return $this;
    }

    /**
     * Get path to main bin (relative to package directory)
     *
     * @return string
     * @throws \UnexpectedValueException
     */
    public function getMain()
    {
        if ($this->main === null) {
            foreach ($this->package->getBins() as $path) {
                if (!file_exists($this->package->getDirectory() . $path)) {
                    throw new \UnexpectedValueException('Bin file "' . $path . '" does not exist');
                }
                $this->main = $path;
                break;
            }
        }
        return $this->main;
    }

    /**
     * set path to main bin (relative to package directory)
     *
     * @param string $main
     * @return $this
     */
    public function setMain($main)
    {
        $this->main = $main;
        return $this;
    }

    /**
     *
     * @return Package
     */
    public function getPackageRoot()
    {
        return $this->package;
    }

    /**
     *
     * @return Package[]
     */
    public function getPackagesDependencies()
    {
        $packages = array();

        $pathVendor = $this->package->getDirectory() . $this->package->getPathVendor();

        // load all installed packages (use installed.json which also includes version instead of composer.lock)
        if (is_file($pathVendor . 'composer/installed.json')) {
            // file does not exist if there's nothing to be installed
            $installed = $this->loadJson($pathVendor . 'composer/installed.json');

            // Composer 2.0 format wrapped in additional root key
            if (isset($installed['packages'])) {
                $installed = $installed['packages'];
            }

            foreach ($installed as $package) {
                $dir = $package['name'] . '/';
                if (isset($package['target-dir'])) {
                    $dir .= trim($package['target-dir'], '/') . '/';
                }

                $dir = $pathVendor . $dir;
                $packages []= new Package($package, $dir);
            }
        }

        return $packages;
    }

    public function build()
    {
        $this->log('[' . $this->step . '/' . $this->step.'] Creating phar <info>' . $this->getTarget() . '</info>');
        $time = microtime(true);

        $pathVendor = $this->package->getDirectory() . $this->package->getPathVendor();
        if (!is_dir($pathVendor)) {
            throw new \RuntimeException('Directory "' . $pathVendor . '" not properly installed, did you run "composer install"?');
        }

        // get target and tempory file name to write to
        $target = $this->getTarget();
        do {
            $tmp = $target . '.' . mt_rand() . '.phar';
        } while (file_exists($tmp));

        $targetPhar = new TargetPhar(new \Phar($tmp), $this);
        $this->log('  - Adding main package "' . $this->package->getName() . '"');
        $targetPhar->addBundle($this->package->bundle());

        $this->log('  - Adding composer base files');
        // explicitly add composer autoloader
        $targetPhar->addFile($pathVendor . 'autoload.php');

        // only add composer base directory (no sub-directories!)
        $targetPhar->buildFromIterator(new \GlobIterator($pathVendor . 'composer/*.*', \FilesystemIterator::KEY_AS_FILENAME));

        foreach ($this->getPackagesDependencies() as $package) {
            $this->log('  - Adding dependency "' . $package->getName() . '" from "' . $this->getPathLocalToBase($package->getDirectory()) . '"');
            $targetPhar->addBundle($package->bundle());
        }

        $this->log('  - Setting main/stub');
        $chmod = 0755;
        $main = $this->getMain();
        if ($main === null) {
            $this->log('    WARNING: No main bin file defined! Resulting phar will NOT be executable');
        } else {
            $generator = StubGenerator::create()
                ->index($main)
                ->extract(true)
                ->banner("Bundled by phar-composer with the help of php-box.\n\n@link https://github.com/clue/phar-composer");

            $lines = file($this->package->getDirectory() . $main, FILE_IGNORE_NEW_LINES);
            if (substr($lines[0], 0, 2) === '#!') {
                $this->log('    Using referenced shebang "'. $lines[0] . '"');
                $generator->shebang($lines[0]);

                // remove shebang from main file and add (overwrite)
                unset($lines[0]);
                $targetPhar->addFromString($main, implode("\n", $lines));
            }

            $targetPhar->setStub($generator->generate());

            $chmod = octdec(substr(decoct(fileperms($this->package->getDirectory() . $main)),-4));
            $this->log('    Using referenced chmod ' . sprintf('%04o', $chmod));
        }

        // stop buffering contents in memory and write to file
        // failure to write will emit a warning (ignore) and throw an (uncaught) exception
        try {
            @$targetPhar->stopBuffering();
            $targetPhar = null;
        } catch (\PharException $e) {
            throw new \RuntimeException('Unable to write phar: ' . $e->getMessage());
        }

        if ($chmod !== null) {
            $this->log('    Applying chmod ' . sprintf('%04o', $chmod));
            if (chmod($tmp, $chmod) === false) {
                throw new \UnexpectedValueException('Unable to chmod target file "' . $target .'"');
            }
        }

        if (file_exists($target)) {
            $this->log('  - Overwriting existing file <info>' . $target . '</info> (' . $this->getSize($target) . ')');
        }

        if (@rename($tmp, $target) === false) {
            // retry renaming after sleeping to give slow network drives some time to flush data
            sleep(5);
            if (rename($tmp, $target) === false) {
                throw new \UnexpectedValueException('Unable to rename temporary phar archive to "'.$target.'"');
            }
        }

        $time = max(microtime(true) - $time, 0);

        $this->log('');
        $this->log('    <info>OK</info> - Creating <info>' . $this->getTarget() .'</info> (' . $this->getSize($this->getTarget()) . ') completed after ' . round($time, 1) . 's');
    }

    private function getSize($path)
    {
        return round(filesize($path) / 1024, 1) . ' KiB';
    }

    public function getPathLocalToBase($path)
    {
        $root = $this->package->getDirectory();
        if (strpos($path, $root) !== 0) {
            throw new \UnexpectedValueException('Path "' . $path . '" is not within base project path "' . $root . '"');
        }
        return substr($path, strlen($root));
    }

    public function log($message)
    {
        $this->logger->log($message);
    }

    public function setStep($step)
    {
        $this->step = $step;
    }

    /**
     * @param string $path
     * @return mixed
     * @throws \InvalidArgumentException
     */
    private function loadJson($path)
    {
        $ret = @json_decode(file_get_contents($path), true);
        if ($ret === null) {
            throw new \InvalidArgumentException('Unable to parse given path "' . $path . '"', json_last_error());
        }
        return $ret;
    }
}
<?php

namespace Clue\PharComposer\Phar;

use Clue\PharComposer\Package\Bundle;

/**
 * Represents the target phar to be created.
 */
class TargetPhar
{
    /** @var \Phar */
    private $phar;

    /** @var  PharComposer */
    private $pharComposer;

    public function __construct(\Phar $phar, PharComposer $pharComposer)
    {
        $phar->startBuffering();
        $this->phar = $phar;
        $this->pharComposer = $pharComposer;
    }

    /**
     * finalize writing of phar file
     */
    public function stopBuffering()
    {
        $this->phar->stopBuffering();
    }

    /**
     * adds given list of resources to phar
     *
     * @param  Bundle  $bundle
     */
    public function addBundle(Bundle $bundle)
    {
        foreach ($bundle as $resource) {
            if (is_string($resource)) {
                $this->addFile($resource);
            } else {
                $this->buildFromIterator($resource);
            }
        }
    }

     /**
     * Adds a file to the Phar
     *
     * @param string $file  The file name.
     */
    public function addFile($file)
    {
        $this->phar->addFile($file, $this->pharComposer->getPathLocalToBase($file));
    }

    public function buildFromIterator(\Traversable $iterator)
    {
        $this->phar->buildFromIterator($iterator, $this->pharComposer->getPackageRoot()->getDirectory());
    }

    /**
     * Used to set the PHP loader or bootstrap stub of a Phar archive
     *
     * @param  string $stub
     */
    public function setStub($stub)
    {
        $this->phar->setStub($stub);
    }

    public function addFromString($local, $contents)
    {
        $this->phar->addFromString($local, $contents);
    }
}
<?php

namespace Clue\PharComposer\Phar;

use Symfony\Component\Process\Process;
use Symfony\Component\Process\ExecutableFinder;
use UnexpectedValueException;
use InvalidArgumentException;
use RuntimeException;
use Symfony\Component\Console\Output\OutputInterface;
use Clue\PharComposer\Package\Package;

class Packager
{
    const PATH_BIN = '/usr/local/bin';

    private $output;
    private $binSudo = 'sudo';

    public function __construct()
    {
        $this->setOutput(true);
    }

    private function log($message)
    {
        $fn = $this->output;
        $fn($message . PHP_EOL);
    }

    public function setBinSudo($bin)
    {
        $this->binSudo = $bin;
    }

    /**
     * @param OutputInterface|bool|callable $fn
     */
    public function setOutput($fn)
    {
        if ($fn instanceof OutputInterface) {
            $fn = function ($line) use ($fn) {
                $fn->write($line);
            };
        } elseif ($fn === true) {
            $fn = function ($line) {
                echo $line;
            };
        } elseif ($fn === false) {
            $fn = function () { };
        }
        $this->output = $fn;
    }

    /**
     * ensure writing phar files is enabled or respawn with PHP setting which allows writing
     *
     * @param int $wait
     * @return void
     * @uses assertWritable()
     */
    public function coerceWritable($wait = 1)
    {
        try {
            $this->assertWritable();
        }
        catch (UnexpectedValueException $e) {
            if (!function_exists('pcntl_exec')) {
                $this->log('<error>' . $e->getMessage() . '</error>');
                return;
            }

            $this->log('<info>' . $e->getMessage() . ', trying to re-spawn with correct config</info>');
            if ($wait) {
                sleep($wait);
            }

            $args = array_merge(array('php', '-d phar.readonly=off'), $_SERVER['argv']);
            if (pcntl_exec('/usr/bin/env', $args) === false) {
                $this->log('<error>Unable to switch into new configuration</error>');
                return;
            }
        }
    }

    /**
     * ensure writing phar files is enabled or throw an exception
     *
     * @throws UnexpectedValueException
     */
    public function assertWritable()
    {
        if (ini_get('phar.readonly') === '1') {
            throw new UnexpectedValueException('Your configuration disabled writing phar files (phar.readonly = On), please update your configuration or run with "php -d phar.readonly=off ' . $_SERVER['argv'][0].'"');
        }
    }

    /**
     * @param string $path
     * @param string $version
     * @return PharComposer
     * @throws UnexpectedValueException
     * @throws InvalidArgumentException
     * @throws RuntimeException
     */
    public function getPharer($path, $version = null)
    {
        if ($version !== null) {
            // TODO: should be the other way around
            $path .= ':' . $version;
        }

        $step = 1;
        $steps = 1;

        if ($this->isPackageUrl($path)) {
            $url = $path;
            $version = null;
            $steps = 3;

            if (preg_match('/(.+)\:((?:dev\-|v\d)\S+)$/i', $url, $match)) {
                $url = $match[1];
                $version = $match[2];
                if (substr($version, 0, 4) === 'dev-') {
                    $version = substr($version, 4);
                }
            }


            $path = $this->getDirTemporary();

            $finder = new ExecutableFinder();

            $git = escapeshellarg($finder->find('git', 'git'));

            $that = $this;
            $this->displayMeasure(
                '[' . $step++ . '/' . $steps.'] Cloning <info>' . $url . '</info> into temporary directory <info>' . $path . '</info>',
                function() use ($that, $url, $path, $version, $git) {
                    $that->exec($git . ' clone ' . escapeshellarg($url) . ' ' . escapeshellarg($path));

                    if ($version !== null) {
                        $this->exec($git . ' checkout ' . escapeshellarg($version) . ' 2>&1', $path);
                    }
                },
                'Cloning base repository completed'
            );

            $pharcomposer = new PharComposer($path . '/composer.json');
            $package = $pharcomposer->getPackageRoot()->getName();

            if (is_file('composer.phar')) {
                $command = escapeshellarg($finder->find('php', 'php')) . ' composer.phar';
            } else {
                $command = escapeshellarg($finder->find('composer', 'composer'));
            }
            $command .= ' install --no-dev --no-progress --no-scripts';

            $this->displayMeasure(
                '[' . $step++ . '/' . $steps.'] Installing dependencies for <info>' . $package . '</info> into <info>' . $path . '</info> (using <info>' . $command . '</info>)',
                function () use ($that, $command, $path) {
                    try {
                        $that->exec($command, $path);
                    }
                    catch (UnexpectedValueException $e) {
                        throw new UnexpectedValueException('Installing dependencies via composer failed', 0, $e);
                    }
                },
                'Downloading dependencies completed'
            );
        } elseif ($this->isPackageName($path)) {
            if (is_dir($path)) {
                $this->log('<info>There\'s also a directory with the given name</info>');
            }
            $steps = 2;
            $package = $path;

            $path = $this->getDirTemporary();

            $finder = new ExecutableFinder();
            if (is_file('composer.phar')) {
                $command = escapeshellarg($finder->find('php', 'php')) . ' composer.phar';
            } else {
                $command = escapeshellarg($finder->find('composer', 'composer'));
            }
            $command .= ' create-project ' . escapeshellarg($package) . ' ' . escapeshellarg($path) . ' --no-dev --no-progress --no-scripts';

            $that = $this;
            $this->displayMeasure(
                '[' . $step++ . '/' . $steps.'] Installing <info>' . $package . '</info> to temporary directory <info>' . $path . '</info> (using <info>' . $command . '</info>)',
                function () use ($that, $command) {
                    try {
                        $that->exec($command);
                    }
                    catch (UnexpectedValueException $e) {
                        throw new UnexpectedValueException('Installing package via composer failed', 0, $e);
                    }
                },
                'Downloading package completed'
            );
        }

        if (is_dir($path)) {
            $path = rtrim($path, '/') . '/composer.json';
        }
        if (!is_file($path)) {
            throw new InvalidArgumentException('The given path "' . $path . '" is not a readable file');
        }

        $pharer = new PharComposer($path);
        $pharer->setOutput($this->output);
        $pharer->setStep($step);

        $pathVendor = $pharer->getPackageRoot()->getDirectory() . $pharer->getPackageRoot()->getPathVendor();
        if (!is_dir($pathVendor)) {
            throw new RuntimeException('Project is not installed via composer. Run "composer install" manually');
        }

        return $pharer;
    }

    public function measure($fn)
    {
        $time = microtime(true);

        $fn();

        return max(microtime(true) - $time, 0);
    }

    public function displayMeasure($title, $fn, $success)
    {
        $this->log($title);

        $time = $this->measure($fn);

        $this->log('');
        $this->log('    <info>OK</info> - ' . $success .' (after ' . round($time, 1) . 's)');
    }

    /**
     * @param string $cmd
     * @param ?string $chdir
     * @return void
     * @throws UnexpectedValueException
     */
    public function exec($cmd, $chdir = null)
    {
        $nl = true;

        //
        $output = $this->output;

        // Symfony 5+ requires 'fromShellCommandline', older versions support direct instantiation with command line
        // @codeCoverageIgnoreStart
        try {
            new \ReflectionMethod('Symfony\Component\Process\Process', 'fromShellCommandline');
            $process = Process::fromShellCommandline($cmd, $chdir);
        } catch (\ReflectionException $e) {
            $process = new Process($cmd, $chdir);
        }
        // @codeCoverageIgnoreEnd

        $process->setTimeout(null);
        $code = $process->run(function($type, $data) use ($output, &$nl) {
            if ($nl === true) {
                $data = PHP_EOL . $data;
                $nl = false;
            }
            if (substr($data, -1) === "\n") {
                $nl = true;
                $data = substr($data, 0, -strlen(PHP_EOL));
            }
            $data = str_replace("\n", "\n    ", $data);

            $output($data);
        });
        if ($nl) {
            $this->log('');
        }

        if ($code !== 0) {
            throw new UnexpectedValueException('Error status code: ' . $process->getExitCodeText() . ' (code ' . $code . ')');
        }
    }

    public function install(PharComposer $pharer, $path)
    {
        $pharer->build();

        $this->log('Move resulting phar to <info>' . $path . '</info>');
        $this->exec($this->binSudo . ' -- mv -f ' . escapeshellarg($pharer->getTarget()) . ' ' . escapeshellarg($path));

        $this->log('');
        $this->log('    <info>OK</info> - Moved to <info>' . $path . '</info>');
    }

    /**
     * @param Package $package
     * @param ?string $path
     * @return string
     */
    public function getSystemBin(Package $package, $path = null)
    {
        // no path given => place in system bin path
        if ($path === null) {
            $path = self::PATH_BIN;
        }

        // no slash => path is relative to system bin path
        if (strpos($path, '/') === false) {
            $path = self::PATH_BIN . '/' . $path;
        }

        // path is actually a directory => append package name
        if (is_dir($path)) {
            $path = rtrim($path, '/') . '/' . $package->getShortName();
        }

        return $path;
    }

    private function isPackageName($path)
    {
        return !!preg_match('/^[^\s\/]+\/[^\s\/]+(\:[^\s]+)?$/i', $path);
    }

    public function isPackageUrl($path)
    {
        return (strpos($path, '://') !== false && @parse_url($path) !== false) || preg_match('/^[^-\/\s][^:\/\s]*:[^\s\\\\]\S*/', $path);
    }

    private function getDirTemporary()
    {
        $path = sys_get_temp_dir() . '/phar-composer' . mt_rand(0,9);
        while (is_dir($path)) {
            $path .= mt_rand(0, 9);
        }

        return $path;
    }
}
<?php

if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
    require __DIR__ . '/../vendor/autoload.php';
} elseif (file_exists(__DIR__ . '/../../../autoload.php')) {
    require __DIR__ . '/../../../autoload.php';
} else {
    fwrite(STDERR, 'ERROR: Composer dependencies not properly set up! Run "composer install" or see README.md for more details' . PHP_EOL);
    exit(1);
}

// hide PHP 8.1 deprecations
error_reporting(E_ALL & ~E_DEPRECATED);

$app = new Clue\PharComposer\App();
$app->run();<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit9b76e4febe4b72af3903e5915e2ed009::getLoader();
<?php

/*
 * This file is part of Composer.
 *
 * (c) Nils Adermann <naderman@naderman.de>
 *     Jordi Boggiano <j.boggiano@seld.be>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Composer\Autoload;

/**
 * ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
 *
 *     $loader = new \Composer\Autoload\ClassLoader();
 *
 *     // register classes with namespaces
 *     $loader->add('Symfony\Component', __DIR__.'/component');
 *     $loader->add('Symfony',           __DIR__.'/framework');
 *
 *     // activate the autoloader
 *     $loader->register();
 *
 *     // to enable searching the include path (eg. for PEAR packages)
 *     $loader->setUseIncludePath(true);
 *
 * In this example, if you try to use a class in the Symfony\Component
 * namespace or one of its children (Symfony\Component\Console for instance),
 * the autoloader will first look for the class under the component/
 * directory, and it will then fallback to the framework/ directory if not
 * found before giving up.
 *
 * This class is loosely based on the Symfony UniversalClassLoader.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 * @author Jordi Boggiano <j.boggiano@seld.be>
 * @see    https://www.php-fig.org/psr/psr-0/
 * @see    https://www.php-fig.org/psr/psr-4/
 */
class ClassLoader
{
    /** @var ?string */
    private $vendorDir;

    // PSR-4
    /**
     * @var array[]
     * @psalm-var array<string, array<string, int>>
     */
    private $prefixLengthsPsr4 = array();
    /**
     * @var array[]
     * @psalm-var array<string, array<int, string>>
     */
    private $prefixDirsPsr4 = array();
    /**
     * @var array[]
     * @psalm-var array<string, string>
     */
    private $fallbackDirsPsr4 = array();

    // PSR-0
    /**
     * @var array[]
     * @psalm-var array<string, array<string, string[]>>
     */
    private $prefixesPsr0 = array();
    /**
     * @var array[]
     * @psalm-var array<string, string>
     */
    private $fallbackDirsPsr0 = array();

    /** @var bool */
    private $useIncludePath = false;

    /**
     * @var string[]
     * @psalm-var array<string, string>
     */
    private $classMap = array();

    /** @var bool */
    private $classMapAuthoritative = false;

    /**
     * @var bool[]
     * @psalm-var array<string, bool>
     */
    private $missingClasses = array();

    /** @var ?string */
    private $apcuPrefix;

    /**
     * @var self[]
     */
    private static $registeredLoaders = array();

    /**
     * @param ?string $vendorDir
     */
    public function __construct($vendorDir = null)
    {
        $this->vendorDir = $vendorDir;
    }

    /**
     * @return string[]
     */
    public function getPrefixes()
    {
        if (!empty($this->prefixesPsr0)) {
            return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
        }

        return array();
    }

    /**
     * @return array[]
     * @psalm-return array<string, array<int, string>>
     */
    public function getPrefixesPsr4()
    {
        return $this->prefixDirsPsr4;
    }

    /**
     * @return array[]
     * @psalm-return array<string, string>
     */
    public function getFallbackDirs()
    {
        return $this->fallbackDirsPsr0;
    }

    /**
     * @return array[]
     * @psalm-return array<string, string>
     */
    public function getFallbackDirsPsr4()
    {
        return $this->fallbackDirsPsr4;
    }

    /**
     * @return string[] Array of classname => path
     * @psalm-return array<string, string>
     */
    public function getClassMap()
    {
        return $this->classMap;
    }

    /**
     * @param string[] $classMap Class to filename map
     * @psalm-param array<string, string> $classMap
     *
     * @return void
     */
    public function addClassMap(array $classMap)
    {
        if ($this->classMap) {
            $this->classMap = array_merge($this->classMap, $classMap);
        } else {
            $this->classMap = $classMap;
        }
    }

    /**
     * Registers a set of PSR-0 directories for a given prefix, either
     * appending or prepending to the ones previously set for this prefix.
     *
     * @param string          $prefix  The prefix
     * @param string[]|string $paths   The PSR-0 root directories
     * @param bool            $prepend Whether to prepend the directories
     *
     * @return void
     */
    public function add($prefix, $paths, $prepend = false)
    {
        if (!$prefix) {
            if ($prepend) {
                $this->fallbackDirsPsr0 = array_merge(
                    (array) $paths,
                    $this->fallbackDirsPsr0
                );
            } else {
                $this->fallbackDirsPsr0 = array_merge(
                    $this->fallbackDirsPsr0,
                    (array) $paths
                );
            }

            return;
        }

        $first = $prefix[0];
        if (!isset($this->prefixesPsr0[$first][$prefix])) {
            $this->prefixesPsr0[$first][$prefix] = (array) $paths;

            return;
        }
        if ($prepend) {
            $this->prefixesPsr0[$first][$prefix] = array_merge(
                (array) $paths,
                $this->prefixesPsr0[$first][$prefix]
            );
        } else {
            $this->prefixesPsr0[$first][$prefix] = array_merge(
                $this->prefixesPsr0[$first][$prefix],
                (array) $paths
            );
        }
    }

    /**
     * Registers a set of PSR-4 directories for a given namespace, either
     * appending or prepending to the ones previously set for this namespace.
     *
     * @param string          $prefix  The prefix/namespace, with trailing '\\'
     * @param string[]|string $paths   The PSR-4 base directories
     * @param bool            $prepend Whether to prepend the directories
     *
     * @throws \InvalidArgumentException
     *
     * @return void
     */
    public function addPsr4($prefix, $paths, $prepend = false)
    {
        if (!$prefix) {
            // Register directories for the root namespace.
            if ($prepend) {
                $this->fallbackDirsPsr4 = array_merge(
                    (array) $paths,
                    $this->fallbackDirsPsr4
                );
            } else {
                $this->fallbackDirsPsr4 = array_merge(
                    $this->fallbackDirsPsr4,
                    (array) $paths
                );
            }
        } elseif (!isset($this->prefixDirsPsr4[$prefix])) {
            // Register directories for a new namespace.
            $length = strlen($prefix);
            if ('\\' !== $prefix[$length - 1]) {
                throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
            }
            $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
            $this->prefixDirsPsr4[$prefix] = (array) $paths;
        } elseif ($prepend) {
            // Prepend directories for an already registered namespace.
            $this->prefixDirsPsr4[$prefix] = array_merge(
                (array) $paths,
                $this->prefixDirsPsr4[$prefix]
            );
        } else {
            // Append directories for an already registered namespace.
            $this->prefixDirsPsr4[$prefix] = array_merge(
                $this->prefixDirsPsr4[$prefix],
                (array) $paths
            );
        }
    }

    /**
     * Registers a set of PSR-0 directories for a given prefix,
     * replacing any others previously set for this prefix.
     *
     * @param string          $prefix The prefix
     * @param string[]|string $paths  The PSR-0 base directories
     *
     * @return void
     */
    public function set($prefix, $paths)
    {
        if (!$prefix) {
            $this->fallbackDirsPsr0 = (array) $paths;
        } else {
            $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
        }
    }

    /**
     * Registers a set of PSR-4 directories for a given namespace,
     * replacing any others previously set for this namespace.
     *
     * @param string          $prefix The prefix/namespace, with trailing '\\'
     * @param string[]|string $paths  The PSR-4 base directories
     *
     * @throws \InvalidArgumentException
     *
     * @return void
     */
    public function setPsr4($prefix, $paths)
    {
        if (!$prefix) {
            $this->fallbackDirsPsr4 = (array) $paths;
        } else {
            $length = strlen($prefix);
            if ('\\' !== $prefix[$length - 1]) {
                throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
            }
            $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
            $this->prefixDirsPsr4[$prefix] = (array) $paths;
        }
    }

    /**
     * Turns on searching the include path for class files.
     *
     * @param bool $useIncludePath
     *
     * @return void
     */
    public function setUseIncludePath($useIncludePath)
    {
        $this->useIncludePath = $useIncludePath;
    }

    /**
     * Can be used to check if the autoloader uses the include path to check
     * for classes.
     *
     * @return bool
     */
    public function getUseIncludePath()
    {
        return $this->useIncludePath;
    }

    /**
     * Turns off searching the prefix and fallback directories for classes
     * that have not been registered with the class map.
     *
     * @param bool $classMapAuthoritative
     *
     * @return void
     */
    public function setClassMapAuthoritative($classMapAuthoritative)
    {
        $this->classMapAuthoritative = $classMapAuthoritative;
    }

    /**
     * Should class lookup fail if not found in the current class map?
     *
     * @return bool
     */
    public function isClassMapAuthoritative()
    {
        return $this->classMapAuthoritative;
    }

    /**
     * APCu prefix to use to cache found/not-found classes, if the extension is enabled.
     *
     * @param string|null $apcuPrefix
     *
     * @return void
     */
    public function setApcuPrefix($apcuPrefix)
    {
        $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
    }

    /**
     * The APCu prefix in use, or null if APCu caching is not enabled.
     *
     * @return string|null
     */
    public function getApcuPrefix()
    {
        return $this->apcuPrefix;
    }

    /**
     * Registers this instance as an autoloader.
     *
     * @param bool $prepend Whether to prepend the autoloader or not
     *
     * @return void
     */
    public function register($prepend = false)
    {
        spl_autoload_register(array($this, 'loadClass'), true, $prepend);

        if (null === $this->vendorDir) {
            return;
        }

        if ($prepend) {
            self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
        } else {
            unset(self::$registeredLoaders[$this->vendorDir]);
            self::$registeredLoaders[$this->vendorDir] = $this;
        }
    }

    /**
     * Unregisters this instance as an autoloader.
     *
     * @return void
     */
    public function unregister()
    {
        spl_autoload_unregister(array($this, 'loadClass'));

        if (null !== $this->vendorDir) {
            unset(self::$registeredLoaders[$this->vendorDir]);
        }
    }

    /**
     * Loads the given class or interface.
     *
     * @param  string    $class The name of the class
     * @return true|null True if loaded, null otherwise
     */
    public function loadClass($class)
    {
        if ($file = $this->findFile($class)) {
            includeFile($file);

            return true;
        }

        return null;
    }

    /**
     * Finds the path to the file where the class is defined.
     *
     * @param string $class The name of the class
     *
     * @return string|false The path if found, false otherwise
     */
    public function findFile($class)
    {
        // class map lookup
        if (isset($this->classMap[$class])) {
            return $this->classMap[$class];
        }
        if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
            return false;
        }
        if (null !== $this->apcuPrefix) {
            $file = apcu_fetch($this->apcuPrefix.$class, $hit);
            if ($hit) {
                return $file;
            }
        }

        $file = $this->findFileWithExtension($class, '.php');

        // Search for Hack files if we are running on HHVM
        if (false === $file && defined('HHVM_VERSION')) {
            $file = $this->findFileWithExtension($class, '.hh');
        }

        if (null !== $this->apcuPrefix) {
            apcu_add($this->apcuPrefix.$class, $file);
        }

        if (false === $file) {
            // Remember that this class does not exist.
            $this->missingClasses[$class] = true;
        }

        return $file;
    }

    /**
     * Returns the currently registered loaders indexed by their corresponding vendor directories.
     *
     * @return self[]
     */
    public static function getRegisteredLoaders()
    {
        return self::$registeredLoaders;
    }

    /**
     * @param  string       $class
     * @param  string       $ext
     * @return string|false
     */
    private function findFileWithExtension($class, $ext)
    {
        // PSR-4 lookup
        $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;

        $first = $class[0];
        if (isset($this->prefixLengthsPsr4[$first])) {
            $subPath = $class;
            while (false !== $lastPos = strrpos($subPath, '\\')) {
                $subPath = substr($subPath, 0, $lastPos);
                $search = $subPath . '\\';
                if (isset($this->prefixDirsPsr4[$search])) {
                    $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
                    foreach ($this->prefixDirsPsr4[$search] as $dir) {
                        if (file_exists($file = $dir . $pathEnd)) {
                            return $file;
                        }
                    }
                }
            }
        }

        // PSR-4 fallback dirs
        foreach ($this->fallbackDirsPsr4 as $dir) {
            if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
                return $file;
            }
        }

        // PSR-0 lookup
        if (false !== $pos = strrpos($class, '\\')) {
            // namespaced class name
            $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
                . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
        } else {
            // PEAR-like class name
            $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
        }

        if (isset($this->prefixesPsr0[$first])) {
            foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
                if (0 === strpos($class, $prefix)) {
                    foreach ($dirs as $dir) {
                        if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
                            return $file;
                        }
                    }
                }
            }
        }

        // PSR-0 fallback dirs
        foreach ($this->fallbackDirsPsr0 as $dir) {
            if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
                return $file;
            }
        }

        // PSR-0 include paths.
        if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
            return $file;
        }

        return false;
    }
}

/**
 * Scope isolated include.
 *
 * Prevents access to $this/self from included files.
 *
 * @param  string $file
 * @return void
 * @private
 */
function includeFile($file)
{
    include $file;
}
<?php

/*
 * This file is part of Composer.
 *
 * (c) Nils Adermann <naderman@naderman.de>
 *     Jordi Boggiano <j.boggiano@seld.be>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Composer;

use Composer\Autoload\ClassLoader;
use Composer\Semver\VersionParser;

/**
 * This class is copied in every Composer installed project and available to all
 *
 * See also https://getcomposer.org/doc/07-runtime.md#installed-versions
 *
 * To require its presence, you can require `composer-runtime-api ^2.0`
 */
class InstalledVersions
{
    /**
     * @var mixed[]|null
     * @psalm-var array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}|array{}|null
     */
    private static $installed;

    /**
     * @var bool|null
     */
    private static $canGetVendors;

    /**
     * @var array[]
     * @psalm-var array<string, array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
     */
    private static $installedByVendor = array();

    /**
     * Returns a list of all package names which are present, either by being installed, replaced or provided
     *
     * @return string[]
     * @psalm-return list<string>
     */
    public static function getInstalledPackages()
    {
        $packages = array();
        foreach (self::getInstalled() as $installed) {
            $packages[] = array_keys($installed['versions']);
        }

        if (1 === \count($packages)) {
            return $packages[0];
        }

        return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
    }

    /**
     * Returns a list of all package names with a specific type e.g. 'library'
     *
     * @param  string   $type
     * @return string[]
     * @psalm-return list<string>
     */
    public static function getInstalledPackagesByType($type)
    {
        $packagesByType = array();

        foreach (self::getInstalled() as $installed) {
            foreach ($installed['versions'] as $name => $package) {
                if (isset($package['type']) && $package['type'] === $type) {
                    $packagesByType[] = $name;
                }
            }
        }

        return $packagesByType;
    }

    /**
     * Checks whether the given package is installed
     *
     * This also returns true if the package name is provided or replaced by another package
     *
     * @param  string $packageName
     * @param  bool   $includeDevRequirements
     * @return bool
     */
    public static function isInstalled($packageName, $includeDevRequirements = true)
    {
        foreach (self::getInstalled() as $installed) {
            if (isset($installed['versions'][$packageName])) {
                return $includeDevRequirements || empty($installed['versions'][$packageName]['dev_requirement']);
            }
        }

        return false;
    }

    /**
     * Checks whether the given package satisfies a version constraint
     *
     * e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call:
     *
     *   Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3')
     *
     * @param  VersionParser $parser      Install composer/semver to have access to this class and functionality
     * @param  string        $packageName
     * @param  string|null   $constraint  A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package
     * @return bool
     */
    public static function satisfies(VersionParser $parser, $packageName, $constraint)
    {
        $constraint = $parser->parseConstraints($constraint);
        $provided = $parser->parseConstraints(self::getVersionRanges($packageName));

        return $provided->matches($constraint);
    }

    /**
     * Returns a version constraint representing all the range(s) which are installed for a given package
     *
     * It is easier to use this via isInstalled() with the $constraint argument if you need to check
     * whether a given version of a package is installed, and not just whether it exists
     *
     * @param  string $packageName
     * @return string Version constraint usable with composer/semver
     */
    public static function getVersionRanges($packageName)
    {
        foreach (self::getInstalled() as $installed) {
            if (!isset($installed['versions'][$packageName])) {
                continue;
            }

            $ranges = array();
            if (isset($installed['versions'][$packageName]['pretty_version'])) {
                $ranges[] = $installed['versions'][$packageName]['pretty_version'];
            }
            if (array_key_exists('aliases', $installed['versions'][$packageName])) {
                $ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']);
            }
            if (array_key_exists('replaced', $installed['versions'][$packageName])) {
                $ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']);
            }
            if (array_key_exists('provided', $installed['versions'][$packageName])) {
                $ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']);
            }

            return implode(' || ', $ranges);
        }

        throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
    }

    /**
     * @param  string      $packageName
     * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
     */
    public static function getVersion($packageName)
    {
        foreach (self::getInstalled() as $installed) {
            if (!isset($installed['versions'][$packageName])) {
                continue;
            }

            if (!isset($installed['versions'][$packageName]['version'])) {
                return null;
            }

            return $installed['versions'][$packageName]['version'];
        }

        throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
    }

    /**
     * @param  string      $packageName
     * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
     */
    public static function getPrettyVersion($packageName)
    {
        foreach (self::getInstalled() as $installed) {
            if (!isset($installed['versions'][$packageName])) {
                continue;
            }

            if (!isset($installed['versions'][$packageName]['pretty_version'])) {
                return null;
            }

            return $installed['versions'][$packageName]['pretty_version'];
        }

        throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
    }

    /**
     * @param  string      $packageName
     * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference
     */
    public static function getReference($packageName)
    {
        foreach (self::getInstalled() as $installed) {
            if (!isset($installed['versions'][$packageName])) {
                continue;
            }

            if (!isset($installed['versions'][$packageName]['reference'])) {
                return null;
            }

            return $installed['versions'][$packageName]['reference'];
        }

        throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
    }

    /**
     * @param  string      $packageName
     * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path.
     */
    public static function getInstallPath($packageName)
    {
        foreach (self::getInstalled() as $installed) {
            if (!isset($installed['versions'][$packageName])) {
                continue;
            }

            return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null;
        }

        throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
    }

    /**
     * @return array
     * @psalm-return array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}
     */
    public static function getRootPackage()
    {
        $installed = self::getInstalled();

        return $installed[0]['root'];
    }

    /**
     * Returns the raw installed.php data for custom implementations
     *
     * @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect.
     * @return array[]
     * @psalm-return array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}
     */
    public static function getRawData()
    {
        @trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED);

        if (null === self::$installed) {
            // only require the installed.php file if this file is loaded from its dumped location,
            // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
            if (substr(__DIR__, -8, 1) !== 'C') {
                self::$installed = include __DIR__ . '/installed.php';
            } else {
                self::$installed = array();
            }
        }

        return self::$installed;
    }

    /**
     * Returns the raw data of all installed.php which are currently loaded for custom implementations
     *
     * @return array[]
     * @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
     */
    public static function getAllRawData()
    {
        return self::getInstalled();
    }

    /**
     * Lets you reload the static array from another file
     *
     * This is only useful for complex integrations in which a project needs to use
     * this class but then also needs to execute another project's autoloader in process,
     * and wants to ensure both projects have access to their version of installed.php.
     *
     * A typical case would be PHPUnit, where it would need to make sure it reads all
     * the data it needs from this class, then call reload() with
     * `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure
     * the project in which it runs can then also use this class safely, without
     * interference between PHPUnit's dependencies and the project's dependencies.
     *
     * @param  array[] $data A vendor/composer/installed.php data set
     * @return void
     *
     * @psalm-param array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>} $data
     */
    public static function reload($data)
    {
        self::$installed = $data;
        self::$installedByVendor = array();
    }

    /**
     * @return array[]
     * @psalm-return list<array{root: array{name: string, version: string, reference: string, pretty_version: string, aliases: string[], dev: bool, install_path: string, type: string}, versions: array<string, array{dev_requirement: bool, pretty_version?: string, version?: string, aliases?: string[], reference?: string, replaced?: string[], provided?: string[], install_path?: string, type?: string}>}>
     */
    private static function getInstalled()
    {
        if (null === self::$canGetVendors) {
            self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
        }

        $installed = array();

        if (self::$canGetVendors) {
            foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
                if (isset(self::$installedByVendor[$vendorDir])) {
                    $installed[] = self::$installedByVendor[$vendorDir];
                } elseif (is_file($vendorDir.'/composer/installed.php')) {
                    $installed[] = self::$installedByVendor[$vendorDir] = require $vendorDir.'/composer/installed.php';
                    if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
                        self::$installed = $installed[count($installed) - 1];
                    }
                }
            }
        }

        if (null === self::$installed) {
            // only require the installed.php file if this file is loaded from its dumped location,
            // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
            if (substr(__DIR__, -8, 1) !== 'C') {
                self::$installed = require __DIR__ . '/installed.php';
            } else {
                self::$installed = array();
            }
        }
        $installed[] = self::$installed;

        return $installed;
    }
}
<?php

// autoload_classmap.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
    'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
);
<?php

// autoload_namespaces.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
    'Symfony\\Component\\Process\\' => array($vendorDir . '/symfony/process'),
    'Symfony\\Component\\Finder\\' => array($vendorDir . '/symfony/finder'),
    'Symfony\\Component\\EventDispatcher\\' => array($vendorDir . '/symfony/event-dispatcher'),
    'Symfony\\Component\\Console\\' => array($vendorDir . '/symfony/console'),
    'Packagist\\Api\\' => array($vendorDir . '/knplabs/packagist-api/src'),
    'Guzzle\\Tests' => array($vendorDir . '/guzzle/guzzle/tests'),
    'Guzzle' => array($vendorDir . '/guzzle/guzzle/src'),
    'Doctrine\\Common\\Inflector\\' => array($vendorDir . '/doctrine/inflector/lib'),
);
<?php

// autoload_psr4.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
    'Clue\\PharComposer\\' => array($baseDir . '/src'),
);
<?php

// autoload_real.php @generated by Composer

class ComposerAutoloaderInit9b76e4febe4b72af3903e5915e2ed009
{
    private static $loader;

    public static function loadClassLoader($class)
    {
        if ('Composer\Autoload\ClassLoader' === $class) {
            require __DIR__ . '/ClassLoader.php';
        }
    }

    /**
     * @return \Composer\Autoload\ClassLoader
     */
    public static function getLoader()
    {
        if (null !== self::$loader) {
            return self::$loader;
        }

        require __DIR__ . '/platform_check.php';

        spl_autoload_register(array('ComposerAutoloaderInit9b76e4febe4b72af3903e5915e2ed009', 'loadClassLoader'), true, true);
        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
        spl_autoload_unregister(array('ComposerAutoloaderInit9b76e4febe4b72af3903e5915e2ed009', 'loadClassLoader'));

        $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
        if ($useStaticLoader) {
            require __DIR__ . '/autoload_static.php';

            call_user_func(\Composer\Autoload\ComposerStaticInit9b76e4febe4b72af3903e5915e2ed009::getInitializer($loader));
        } else {
            $map = require __DIR__ . '/autoload_namespaces.php';
            foreach ($map as $namespace => $path) {
                $loader->set($namespace, $path);
            }

            $map = require __DIR__ . '/autoload_psr4.php';
            foreach ($map as $namespace => $path) {
                $loader->setPsr4($namespace, $path);
            }

            $classMap = require __DIR__ . '/autoload_classmap.php';
            if ($classMap) {
                $loader->addClassMap($classMap);
            }
        }

        $loader->register(true);

        return $loader;
    }
}
<?php

// autoload_static.php @generated by Composer

namespace Composer\Autoload;

class ComposerStaticInit9b76e4febe4b72af3903e5915e2ed009
{
    public static $prefixLengthsPsr4 = array (
        'C' => 
        array (
            'Clue\\PharComposer\\' => 18,
        ),
    );

    public static $prefixDirsPsr4 = array (
        'Clue\\PharComposer\\' => 
        array (
            0 => __DIR__ . '/../..' . '/src',
        ),
    );

    public static $prefixesPsr0 = array (
        'S' => 
        array (
            'Symfony\\Component\\Process\\' => 
            array (
                0 => __DIR__ . '/..' . '/symfony/process',
            ),
            'Symfony\\Component\\Finder\\' => 
            array (
                0 => __DIR__ . '/..' . '/symfony/finder',
            ),
            'Symfony\\Component\\EventDispatcher\\' => 
            array (
                0 => __DIR__ . '/..' . '/symfony/event-dispatcher',
            ),
            'Symfony\\Component\\Console\\' => 
            array (
                0 => __DIR__ . '/..' . '/symfony/console',
            ),
        ),
        'P' => 
        array (
            'Packagist\\Api\\' => 
            array (
                0 => __DIR__ . '/..' . '/knplabs/packagist-api/src',
            ),
        ),
        'G' => 
        array (
            'Guzzle\\Tests' => 
            array (
                0 => __DIR__ . '/..' . '/guzzle/guzzle/tests',
            ),
            'Guzzle' => 
            array (
                0 => __DIR__ . '/..' . '/guzzle/guzzle/src',
            ),
        ),
        'D' => 
        array (
            'Doctrine\\Common\\Inflector\\' => 
            array (
                0 => __DIR__ . '/..' . '/doctrine/inflector/lib',
            ),
        ),
    );

    public static $classMap = array (
        'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
    );

    public static function getInitializer(ClassLoader $loader)
    {
        return \Closure::bind(function () use ($loader) {
            $loader->prefixLengthsPsr4 = ComposerStaticInit9b76e4febe4b72af3903e5915e2ed009::$prefixLengthsPsr4;
            $loader->prefixDirsPsr4 = ComposerStaticInit9b76e4febe4b72af3903e5915e2ed009::$prefixDirsPsr4;
            $loader->prefixesPsr0 = ComposerStaticInit9b76e4febe4b72af3903e5915e2ed009::$prefixesPsr0;
            $loader->classMap = ComposerStaticInit9b76e4febe4b72af3903e5915e2ed009::$classMap;

        }, null, ClassLoader::class);
    }
}
{
    "packages": [
        {
            "name": "doctrine/inflector",
            "version": "v1.1.0",
            "version_normalized": "1.1.0.0",
            "source": {
                "type": "git",
                "url": "https://github.com/doctrine/inflector.git",
                "reference": "90b2128806bfde671b6952ab8bea493942c1fdae"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/doctrine/inflector/zipball/90b2128806bfde671b6952ab8bea493942c1fdae",
                "reference": "90b2128806bfde671b6952ab8bea493942c1fdae",
                "shasum": ""
            },
            "require": {
                "php": ">=5.3.2"
            },
            "require-dev": {
                "phpunit/phpunit": "4.*"
            },
            "time": "2015-11-06T14:35:42+00:00",
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "1.1.x-dev"
                }
            },
            "installation-source": "dist",
            "autoload": {
                "psr-0": {
                    "Doctrine\\Common\\Inflector\\": "lib/"
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Roman Borschel",
                    "email": "roman@code-factory.org"
                },
                {
                    "name": "Benjamin Eberlei",
                    "email": "kontakt@beberlei.de"
                },
                {
                    "name": "Guilherme Blanco",
                    "email": "guilhermeblanco@gmail.com"
                },
                {
                    "name": "Jonathan Wage",
                    "email": "jonwage@gmail.com"
                },
                {
                    "name": "Johannes Schmitt",
                    "email": "schmittjoh@gmail.com"
                }
            ],
            "description": "Common String Manipulations with regard to casing and singular/plural rules.",
            "homepage": "http://www.doctrine-project.org",
            "keywords": [
                "inflection",
                "pluralize",
                "singularize",
                "string"
            ],
            "support": {
                "source": "https://github.com/doctrine/inflector/tree/master"
            },
            "install-path": "../doctrine/inflector"
        },
        {
            "name": "guzzle/guzzle",
            "version": "v3.9.3",
            "version_normalized": "3.9.3.0",
            "source": {
                "type": "git",
                "url": "https://github.com/guzzle/guzzle3.git",
                "reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/guzzle/guzzle3/zipball/0645b70d953bc1c067bbc8d5bc53194706b628d9",
                "reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9",
                "shasum": ""
            },
            "require": {
                "ext-curl": "*",
                "php": ">=5.3.3",
                "symfony/event-dispatcher": "~2.1"
            },
            "replace": {
                "guzzle/batch": "self.version",
                "guzzle/cache": "self.version",
                "guzzle/common": "self.version",
                "guzzle/http": "self.version",
                "guzzle/inflection": "self.version",
                "guzzle/iterator": "self.version",
                "guzzle/log": "self.version",
                "guzzle/parser": "self.version",
                "guzzle/plugin": "self.version",
                "guzzle/plugin-async": "self.version",
                "guzzle/plugin-backoff": "self.version",
                "guzzle/plugin-cache": "self.version",
                "guzzle/plugin-cookie": "self.version",
                "guzzle/plugin-curlauth": "self.version",
                "guzzle/plugin-error-response": "self.version",
                "guzzle/plugin-history": "self.version",
                "guzzle/plugin-log": "self.version",
                "guzzle/plugin-md5": "self.version",
                "guzzle/plugin-mock": "self.version",
                "guzzle/plugin-oauth": "self.version",
                "guzzle/service": "self.version",
                "guzzle/stream": "self.version"
            },
            "require-dev": {
                "doctrine/cache": "~1.3",
                "monolog/monolog": "~1.0",
                "phpunit/phpunit": "3.7.*",
                "psr/log": "~1.0",
                "symfony/class-loader": "~2.1",
                "zendframework/zend-cache": "2.*,<2.3",
                "zendframework/zend-log": "2.*,<2.3"
            },
            "suggest": {
                "guzzlehttp/guzzle": "Guzzle 5 has moved to a new package name. The package you have installed, Guzzle 3, is deprecated."
            },
            "time": "2015-03-18T18:23:50+00:00",
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "3.9-dev"
                }
            },
            "installation-source": "dist",
            "autoload": {
                "psr-0": {
                    "Guzzle": "src/",
                    "Guzzle\\Tests": "tests/"
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Michael Dowling",
                    "email": "mtdowling@gmail.com",
                    "homepage": "https://github.com/mtdowling"
                },
                {
                    "name": "Guzzle Community",
                    "homepage": "https://github.com/guzzle/guzzle/contributors"
                }
            ],
            "description": "PHP HTTP client. This library is deprecated in favor of https://packagist.org/packages/guzzlehttp/guzzle",
            "homepage": "http://guzzlephp.org/",
            "keywords": [
                "client",
                "curl",
                "framework",
                "http",
                "http client",
                "rest",
                "web service"
            ],
            "support": {
                "issues": "https://github.com/guzzle/guzzle3/issues",
                "source": "https://github.com/guzzle/guzzle3/tree/master"
            },
            "abandoned": "guzzlehttp/guzzle",
            "install-path": "../guzzle/guzzle"
        },
        {
            "name": "knplabs/packagist-api",
            "version": "1.3.0",
            "version_normalized": "1.3.0.0",
            "source": {
                "type": "git",
                "url": "https://github.com/KnpLabs/packagist-api.git",
                "reference": "9aebf8238943289d3bc3ab51e0014ed94a7a266a"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/KnpLabs/packagist-api/zipball/9aebf8238943289d3bc3ab51e0014ed94a7a266a",
                "reference": "9aebf8238943289d3bc3ab51e0014ed94a7a266a",
                "shasum": ""
            },
            "require": {
                "doctrine/inflector": "~1.0",
                "guzzle/guzzle": "~3.0",
                "php": ">=5.3.2"
            },
            "require-dev": {
                "phpspec/php-diff": "*@dev",
                "phpspec/phpspec": "~2.0"
            },
            "time": "2015-09-07T14:25:16+00:00",
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "1.x-dev"
                }
            },
            "installation-source": "dist",
            "autoload": {
                "psr-0": {
                    "Packagist\\Api\\": "src/"
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "KnpLabs Team",
                    "homepage": "http://knplabs.com"
                }
            ],
            "description": "Packagist API client.",
            "homepage": "http://knplabs.com",
            "keywords": [
                "api",
                "composer",
                "packagist"
            ],
            "support": {
                "issues": "https://github.com/KnpLabs/packagist-api/issues",
                "source": "https://github.com/KnpLabs/packagist-api/tree/master"
            },
            "install-path": "../knplabs/packagist-api"
        },
        {
            "name": "symfony/console",
            "version": "v2.6.13",
            "version_normalized": "2.6.13.0",
            "target-dir": "Symfony/Component/Console",
            "source": {
                "type": "git",
                "url": "https://github.com/symfony/console.git",
                "reference": "0e5e18ae09d3f5c06367759be940e9ed3f568359"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/symfony/console/zipball/0e5e18ae09d3f5c06367759be940e9ed3f568359",
                "reference": "0e5e18ae09d3f5c06367759be940e9ed3f568359",
                "shasum": ""
            },
            "require": {
                "php": ">=5.3.3"
            },
            "require-dev": {
                "psr/log": "~1.0",
                "symfony/event-dispatcher": "~2.1",
                "symfony/phpunit-bridge": "~2.7",
                "symfony/process": "~2.1"
            },
            "suggest": {
                "psr/log": "For using the console logger",
                "symfony/event-dispatcher": "",
                "symfony/process": ""
            },
            "time": "2015-07-26T09:08:40+00:00",
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "2.6-dev"
                }
            },
            "installation-source": "dist",
            "autoload": {
                "psr-0": {
                    "Symfony\\Component\\Console\\": ""
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Fabien Potencier",
                    "email": "fabien@symfony.com"
                },
                {
                    "name": "Symfony Community",
                    "homepage": "https://symfony.com/contributors"
                }
            ],
            "description": "Symfony Console Component",
            "homepage": "https://symfony.com",
            "support": {
                "source": "https://github.com/symfony/console/tree/v2.6.11"
            },
            "install-path": "../symfony/console/Symfony/Component/Console"
        },
        {
            "name": "symfony/event-dispatcher",
            "version": "v2.6.13",
            "version_normalized": "2.6.13.0",
            "target-dir": "Symfony/Component/EventDispatcher",
            "source": {
                "type": "git",
                "url": "https://github.com/symfony/event-dispatcher.git",
                "reference": "672593bc4b0043a0acf91903bb75a1c82d8f2e02"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/672593bc4b0043a0acf91903bb75a1c82d8f2e02",
                "reference": "672593bc4b0043a0acf91903bb75a1c82d8f2e02",
                "shasum": ""
            },
            "require": {
                "php": ">=5.3.3"
            },
            "require-dev": {
                "psr/log": "~1.0",
                "symfony/config": "~2.0,>=2.0.5",
                "symfony/dependency-injection": "~2.6",
                "symfony/expression-language": "~2.6",
                "symfony/phpunit-bridge": "~2.7",
                "symfony/stopwatch": "~2.3"
            },
            "suggest": {
                "symfony/dependency-injection": "",
                "symfony/http-kernel": ""
            },
            "time": "2015-05-02T15:18:45+00:00",
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "2.6-dev"
                }
            },
            "installation-source": "dist",
            "autoload": {
                "psr-0": {
                    "Symfony\\Component\\EventDispatcher\\": ""
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Fabien Potencier",
                    "email": "fabien@symfony.com"
                },
                {
                    "name": "Symfony Community",
                    "homepage": "https://symfony.com/contributors"
                }
            ],
            "description": "Symfony EventDispatcher Component",
            "homepage": "https://symfony.com",
            "support": {
                "source": "https://github.com/symfony/event-dispatcher/tree/v2.6.11"
            },
            "install-path": "../symfony/event-dispatcher/Symfony/Component/EventDispatcher"
        },
        {
            "name": "symfony/finder",
            "version": "v2.6.13",
            "version_normalized": "2.6.13.0",
            "target-dir": "Symfony/Component/Finder",
            "source": {
                "type": "git",
                "url": "https://github.com/symfony/finder.git",
                "reference": "203a10f928ae30176deeba33512999233181dd28"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/symfony/finder/zipball/203a10f928ae30176deeba33512999233181dd28",
                "reference": "203a10f928ae30176deeba33512999233181dd28",
                "shasum": ""
            },
            "require": {
                "php": ">=5.3.3"
            },
            "require-dev": {
                "symfony/phpunit-bridge": "~2.7"
            },
            "time": "2015-07-09T16:02:48+00:00",
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "2.6-dev"
                }
            },
            "installation-source": "dist",
            "autoload": {
                "psr-0": {
                    "Symfony\\Component\\Finder\\": ""
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Fabien Potencier",
                    "email": "fabien@symfony.com"
                },
                {
                    "name": "Symfony Community",
                    "homepage": "https://symfony.com/contributors"
                }
            ],
            "description": "Symfony Finder Component",
            "homepage": "https://symfony.com",
            "support": {
                "source": "https://github.com/symfony/finder/tree/v2.6.11"
            },
            "install-path": "../symfony/finder/Symfony/Component/Finder"
        },
        {
            "name": "symfony/process",
            "version": "v2.6.13",
            "version_normalized": "2.6.13.0",
            "target-dir": "Symfony/Component/Process",
            "source": {
                "type": "git",
                "url": "https://github.com/symfony/process.git",
                "reference": "57f1e88bb5dafa449b83f9f265b11d52d517b3e9"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/symfony/process/zipball/57f1e88bb5dafa449b83f9f265b11d52d517b3e9",
                "reference": "57f1e88bb5dafa449b83f9f265b11d52d517b3e9",
                "shasum": ""
            },
            "require": {
                "php": ">=5.3.3"
            },
            "require-dev": {
                "symfony/phpunit-bridge": "~2.7"
            },
            "time": "2015-06-30T16:10:16+00:00",
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "2.6-dev"
                }
            },
            "installation-source": "dist",
            "autoload": {
                "psr-0": {
                    "Symfony\\Component\\Process\\": ""
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Fabien Potencier",
                    "email": "fabien@symfony.com"
                },
                {
                    "name": "Symfony Community",
                    "homepage": "https://symfony.com/contributors"
                }
            ],
            "description": "Symfony Process Component",
            "homepage": "https://symfony.com",
            "support": {
                "source": "https://github.com/symfony/process/tree/v2.6.11"
            },
            "install-path": "../symfony/process/Symfony/Component/Process"
        }
    ],
    "dev": false,
    "dev-package-names": []
}
<?php return array(
    'root' => array(
        'pretty_version' => 'dev-master',
        'version' => 'dev-master',
        'type' => 'library',
        'install_path' => __DIR__ . '/../../',
        'aliases' => array(),
        'reference' => '0cae6984e0da45639881d3b26442d525b8b65406',
        'name' => 'clue/phar-composer',
        'dev' => false,
    ),
    'versions' => array(
        'clue/phar-composer' => array(
            'pretty_version' => 'dev-master',
            'version' => 'dev-master',
            'type' => 'library',
            'install_path' => __DIR__ . '/../../',
            'aliases' => array(),
            'reference' => '0cae6984e0da45639881d3b26442d525b8b65406',
            'dev_requirement' => false,
        ),
        'doctrine/inflector' => array(
            'pretty_version' => 'v1.1.0',
            'version' => '1.1.0.0',
            'type' => 'library',
            'install_path' => __DIR__ . '/../doctrine/inflector',
            'aliases' => array(),
            'reference' => '90b2128806bfde671b6952ab8bea493942c1fdae',
            'dev_requirement' => false,
        ),
        'guzzle/batch' => array(
            'dev_requirement' => false,
            'replaced' => array(
                0 => 'v3.9.3',
            ),
        ),
        'guzzle/cache' => array(
            'dev_requirement' => false,
            'replaced' => array(
                0 => 'v3.9.3',
            ),
        ),
        'guzzle/common' => array(
            'dev_requirement' => false,
            'replaced' => array(
                0 => 'v3.9.3',
            ),
        ),
        'guzzle/guzzle' => array(
            'pretty_version' => 'v3.9.3',
            'version' => '3.9.3.0',
            'type' => 'library',
            'install_path' => __DIR__ . '/../guzzle/guzzle',
            'aliases' => array(),
            'reference' => '0645b70d953bc1c067bbc8d5bc53194706b628d9',
            'dev_requirement' => false,
        ),
        'guzzle/http' => array(
            'dev_requirement' => false,
            'replaced' => array(
                0 => 'v3.9.3',
            ),
        ),
        'guzzle/inflection' => array(
            'dev_requirement' => false,
            'replaced' => array(
                0 => 'v3.9.3',
            ),
        ),
        'guzzle/iterator' => array(
            'dev_requirement' => false,
            'replaced' => array(
                0 => 'v3.9.3',
            ),
        ),
        'guzzle/log' => array(
            'dev_requirement' => false,
            'replaced' => array(
                0 => 'v3.9.3',
            ),
        ),
        'guzzle/parser' => array(
            'dev_requirement' => false,
            'replaced' => array(
                0 => 'v3.9.3',
            ),
        ),
        'guzzle/plugin' => array(
            'dev_requirement' => false,
            'replaced' => array(
                0 => 'v3.9.3',
            ),
        ),
        'guzzle/plugin-async' => array(
            'dev_requirement' => false,
            'replaced' => array(
                0 => 'v3.9.3',
            ),
        ),
        'guzzle/plugin-backoff' => array(
            'dev_requirement' => false,
            'replaced' => array(
                0 => 'v3.9.3',
            ),
        ),
        'guzzle/plugin-cache' => array(
            'dev_requirement' => false,
            'replaced' => array(
                0 => 'v3.9.3',
            ),
        ),
        'guzzle/plugin-cookie' => array(
            'dev_requirement' => false,
            'replaced' => array(
                0 => 'v3.9.3',
            ),
        ),
        'guzzle/plugin-curlauth' => array(
            'dev_requirement' => false,
            'replaced' => array(
                0 => 'v3.9.3',
            ),
        ),
        'guzzle/plugin-error-response' => array(
            'dev_requirement' => false,
            'replaced' => array(
                0 => 'v3.9.3',
            ),
        ),
        'guzzle/plugin-history' => array(
            'dev_requirement' => false,
            'replaced' => array(
                0 => 'v3.9.3',
            ),
        ),
        'guzzle/plugin-log' => array(
            'dev_requirement' => false,
            'replaced' => array(
                0 => 'v3.9.3',
            ),
        ),
        'guzzle/plugin-md5' => array(
            'dev_requirement' => false,
            'replaced' => array(
                0 => 'v3.9.3',
            ),
        ),
        'guzzle/plugin-mock' => array(
            'dev_requirement' => false,
            'replaced' => array(
                0 => 'v3.9.3',
            ),
        ),
        'guzzle/plugin-oauth' => array(
            'dev_requirement' => false,
            'replaced' => array(
                0 => 'v3.9.3',
            ),
        ),
        'guzzle/service' => array(
            'dev_requirement' => false,
            'replaced' => array(
                0 => 'v3.9.3',
            ),
        ),
        'guzzle/stream' => array(
            'dev_requirement' => false,
            'replaced' => array(
                0 => 'v3.9.3',
            ),
        ),
        'knplabs/packagist-api' => array(
            'pretty_version' => '1.3.0',
            'version' => '1.3.0.0',
            'type' => 'library',
            'install_path' => __DIR__ . '/../knplabs/packagist-api',
            'aliases' => array(),
            'reference' => '9aebf8238943289d3bc3ab51e0014ed94a7a266a',
            'dev_requirement' => false,
        ),
        'symfony/console' => array(
            'pretty_version' => 'v2.6.13',
            'version' => '2.6.13.0',
            'type' => 'library',
            'install_path' => __DIR__ . '/../symfony/console/Symfony/Component/Console',
            'aliases' => array(),
            'reference' => '0e5e18ae09d3f5c06367759be940e9ed3f568359',
            'dev_requirement' => false,
        ),
        'symfony/event-dispatcher' => array(
            'pretty_version' => 'v2.6.13',
            'version' => '2.6.13.0',
            'type' => 'library',
            'install_path' => __DIR__ . '/../symfony/event-dispatcher/Symfony/Component/EventDispatcher',
            'aliases' => array(),
            'reference' => '672593bc4b0043a0acf91903bb75a1c82d8f2e02',
            'dev_requirement' => false,
        ),
        'symfony/finder' => array(
            'pretty_version' => 'v2.6.13',
            'version' => '2.6.13.0',
            'type' => 'library',
            'install_path' => __DIR__ . '/../symfony/finder/Symfony/Component/Finder',
            'aliases' => array(),
            'reference' => '203a10f928ae30176deeba33512999233181dd28',
            'dev_requirement' => false,
        ),
        'symfony/process' => array(
            'pretty_version' => 'v2.6.13',
            'version' => '2.6.13.0',
            'type' => 'library',
            'install_path' => __DIR__ . '/../symfony/process/Symfony/Component/Process',
            'aliases' => array(),
            'reference' => '57f1e88bb5dafa449b83f9f265b11d52d517b3e9',
            'dev_requirement' => false,
        ),
    ),
);
<?php

// platform_check.php @generated by Composer

$issues = array();

if (!(PHP_VERSION_ID >= 50306)) {
    $issues[] = 'Your Composer dependencies require a PHP version ">= 5.3.6". You are running ' . PHP_VERSION . '.';
}

if ($issues) {
    if (!headers_sent()) {
        header('HTTP/1.1 500 Internal Server Error');
    }
    if (!ini_get('display_errors')) {
        if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
            fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL);
        } elseif (!headers_sent()) {
            echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL;
        }
    }
    trigger_error(
        'Composer detected issues in your platform: ' . implode(' ', $issues),
        E_USER_ERROR
    );
}
Copyright (c) 2006-2015 Doctrine Project

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
<?php
/*
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This software consists of voluntary contributions made by many individuals
 * and is licensed under the MIT license. For more information, see
 * <http://www.doctrine-project.org>.
 */

namespace Doctrine\Common\Inflector;

/**
 * Doctrine inflector has static methods for inflecting text.
 *
 * The methods in these classes are from several different sources collected
 * across several different php projects and several different authors. The
 * original author names and emails are not known.
 *
 * Pluralize & Singularize implementation are borrowed from CakePHP with some modifications.
 *
 * @link   www.doctrine-project.org
 * @since  1.0
 * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
 * @author Jonathan H. Wage <jonwage@gmail.com>
 */
class Inflector
{
    /**
     * Plural inflector rules.
     *
     * @var array
     */
    private static $plural = array(
        'rules' => array(
            '/(s)tatus$/i' => '\1\2tatuses',
            '/(quiz)$/i' => '\1zes',
            '/^(ox)$/i' => '\1\2en',
            '/([m|l])ouse$/i' => '\1ice',
            '/(matr|vert|ind)(ix|ex)$/i' => '\1ices',
            '/(x|ch|ss|sh)$/i' => '\1es',
            '/([^aeiouy]|qu)y$/i' => '\1ies',
            '/(hive)$/i' => '\1s',
            '/(?:([^f])fe|([lr])f)$/i' => '\1\2ves',
            '/sis$/i' => 'ses',
            '/([ti])um$/i' => '\1a',
            '/(p)erson$/i' => '\1eople',
            '/(m)an$/i' => '\1en',
            '/(c)hild$/i' => '\1hildren',
            '/(f)oot$/i' => '\1eet',
            '/(buffal|her|potat|tomat|volcan)o$/i' => '\1\2oes',
            '/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|vir)us$/i' => '\1i',
            '/us$/i' => 'uses',
            '/(alias)$/i' => '\1es',
            '/(analys|ax|cris|test|thes)is$/i' => '\1es',
            '/s$/' => 's',
            '/^$/' => '',
            '/$/' => 's',
        ),
        'uninflected' => array(
            '.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox', '.*sheep', 'people', 'cookie'
        ),
        'irregular' => array(
            'atlas' => 'atlases',
            'axe' => 'axes',
            'beef' => 'beefs',
            'brother' => 'brothers',
            'cafe' => 'cafes',
            'chateau' => 'chateaux',
            'child' => 'children',
            'cookie' => 'cookies',
            'corpus' => 'corpuses',
            'cow' => 'cows',
            'criterion' => 'criteria',
            'curriculum' => 'curricula',
            'demo' => 'demos',
            'domino' => 'dominoes',
            'echo' => 'echoes',
            'foot' => 'feet',
            'fungus' => 'fungi',
            'ganglion' => 'ganglions',
            'genie' => 'genies',
            'genus' => 'genera',
            'graffito' => 'graffiti',
            'hippopotamus' => 'hippopotami',
            'hoof' => 'hoofs',
            'human' => 'humans',
            'iris' => 'irises',
            'leaf' => 'leaves',
            'loaf' => 'loaves',
            'man' => 'men',
            'medium' => 'media',
            'memorandum' => 'memoranda',
            'money' => 'monies',
            'mongoose' => 'mongooses',
            'motto' => 'mottoes',
            'move' => 'moves',
            'mythos' => 'mythoi',
            'niche' => 'niches',
            'nucleus' => 'nuclei',
            'numen' => 'numina',
            'occiput' => 'occiputs',
            'octopus' => 'octopuses',
            'opus' => 'opuses',
            'ox' => 'oxen',
            'penis' => 'penises',
            'person' => 'people',
            'plateau' => 'plateaux',
            'runner-up' => 'runners-up',
            'sex' => 'sexes',
            'soliloquy' => 'soliloquies',
            'son-in-law' => 'sons-in-law',
            'syllabus' => 'syllabi',
            'testis' => 'testes',
            'thief' => 'thieves',
            'tooth' => 'teeth',
            'tornado' => 'tornadoes',
            'trilby' => 'trilbys',
            'turf' => 'turfs',
            'volcano' => 'volcanoes',
        )
    );

    /**
     * Singular inflector rules.
     *
     * @var array
     */
    private static $singular = array(
        'rules' => array(
            '/(s)tatuses$/i' => '\1\2tatus',
            '/^(.*)(menu)s$/i' => '\1\2',
            '/(quiz)zes$/i' => '\\1',
            '/(matr)ices$/i' => '\1ix',
            '/(vert|ind)ices$/i' => '\1ex',
            '/^(ox)en/i' => '\1',
            '/(alias)(es)*$/i' => '\1',
            '/(buffal|her|potat|tomat|volcan)oes$/i' => '\1o',
            '/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|syllab|termin|viri?)i$/i' => '\1us',
            '/([ftw]ax)es/i' => '\1',
            '/(analys|ax|cris|test|thes)es$/i' => '\1is',
            '/(shoe|slave)s$/i' => '\1',
            '/(o)es$/i' => '\1',
            '/ouses$/' => 'ouse',
            '/([^a])uses$/' => '\1us',
            '/([m|l])ice$/i' => '\1ouse',
            '/(x|ch|ss|sh)es$/i' => '\1',
            '/(m)ovies$/i' => '\1\2ovie',
            '/(s)eries$/i' => '\1\2eries',
            '/([^aeiouy]|qu)ies$/i' => '\1y',
            '/([lr])ves$/i' => '\1f',
            '/(tive)s$/i' => '\1',
            '/(hive)s$/i' => '\1',
            '/(drive)s$/i' => '\1',
            '/([^fo])ves$/i' => '\1fe',
            '/(^analy)ses$/i' => '\1sis',
            '/(analy|diagno|^ba|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis',
            '/([ti])a$/i' => '\1um',
            '/(p)eople$/i' => '\1\2erson',
            '/(m)en$/i' => '\1an',
            '/(c)hildren$/i' => '\1\2hild',
            '/(f)eet$/i' => '\1oot',
            '/(n)ews$/i' => '\1\2ews',
            '/eaus$/' => 'eau',
            '/^(.*us)$/' => '\\1',
            '/s$/i' => '',
        ),
        'uninflected' => array(
            '.*[nrlm]ese',
            '.*deer',
            '.*fish',
            '.*measles',
            '.*ois',
            '.*pox',
            '.*sheep',
            '.*ss',
        ),
        'irregular' => array(
            'criteria'  => 'criterion',
            'curves'    => 'curve',
            'emphases'  => 'emphasis',
            'foes'      => 'foe',
            'hoaxes'    => 'hoax',
            'media'     => 'medium',
            'neuroses'  => 'neurosis',
            'waves'     => 'wave',
            'oases'     => 'oasis',
        )
    );

    /**
     * Words that should not be inflected.
     *
     * @var array
     */
    private static $uninflected = array(
        'Amoyese', 'bison', 'Borghese', 'bream', 'breeches', 'britches', 'buffalo', 'cantus',
        'carp', 'chassis', 'clippers', 'cod', 'coitus', 'Congoese', 'contretemps', 'corps',
        'debris', 'diabetes', 'djinn', 'eland', 'elk', 'equipment', 'Faroese', 'flounder',
        'Foochowese', 'gallows', 'Genevese', 'Genoese', 'Gilbertese', 'graffiti',
        'headquarters', 'herpes', 'hijinks', 'Hottentotese', 'information', 'innings',
        'jackanapes', 'Kiplingese', 'Kongoese', 'Lucchese', 'mackerel', 'Maltese', '.*?media',
        'mews', 'moose', 'mumps', 'Nankingese', 'news', 'nexus', 'Niasese',
        'Pekingese', 'Piedmontese', 'pincers', 'Pistoiese', 'pliers', 'Portuguese',
        'proceedings', 'rabies', 'rice', 'rhinoceros', 'salmon', 'Sarawakese', 'scissors',
        'sea[- ]bass', 'series', 'Shavese', 'shears', 'siemens', 'species', 'staff', 'swine',
        'testes', 'trousers', 'trout', 'tuna', 'Vermontese', 'Wenchowese', 'whiting',
        'wildebeest', 'Yengeese'
    );

    /**
     * Method cache array.
     *
     * @var array
     */
    private static $cache = array();

    /**
     * The initial state of Inflector so reset() works.
     *
     * @var array
     */
    private static $initialState = array();

    /**
     * Converts a word into the format for a Doctrine table name. Converts 'ModelName' to 'model_name'.
     *
     * @param string $word The word to tableize.
     *
     * @return string The tableized word.
     */
    public static function tableize($word)
    {
        return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $word));
    }

    /**
     * Converts a word into the format for a Doctrine class name. Converts 'table_name' to 'TableName'.
     *
     * @param string $word The word to classify.
     *
     * @return string The classified word.
     */
    public static function classify($word)
    {
        return str_replace(" ", "", ucwords(strtr($word, "_-", "  ")));
    }

    /**
     * Camelizes a word. This uses the classify() method and turns the first character to lowercase.
     *
     * @param string $word The word to camelize.
     *
     * @return string The camelized word.
     */
    public static function camelize($word)
    {
        return lcfirst(self::classify($word));
    }

    /**
     * Uppercases words with configurable delimeters between words.
     *
     * Takes a string and capitalizes all of the words, like PHP's built-in
     * ucwords function.  This extends that behavior, however, by allowing the
     * word delimeters to be configured, rather than only separating on
     * whitespace.
     *
     * Here is an example:
     * <code>
     * <?php
     * $string = 'top-o-the-morning to all_of_you!';
     * echo \Doctrine\Common\Inflector\Inflector::ucwords($string);
     * // Top-O-The-Morning To All_of_you!
     *
     * echo \Doctrine\Common\Inflector\Inflector::ucwords($string, '-_ ');
     * // Top-O-The-Morning To All_Of_You!
     * ?>
     * </code>
     *
     * @param string $string The string to operate on.
     * @param string $delimiters A list of word separators.
     *
     * @return string The string with all delimeter-separated words capitalized.
     */
    public static function ucwords($string, $delimiters = " \n\t\r\0\x0B-")
    {
        return preg_replace_callback(
            '/[^' . preg_quote($delimiters, '/') . ']+/',
            function($matches) {
                return ucfirst($matches[0]);
            },
            $string
        );
    }

    /**
     * Clears Inflectors inflected value caches, and resets the inflection
     * rules to the initial values.
     *
     * @return void
     */
    public static function reset()
    {
        if (empty(self::$initialState)) {
            self::$initialState = get_class_vars('Inflector');

            return;
        }

        foreach (self::$initialState as $key => $val) {
            if ($key != 'initialState') {
                self::${$key} = $val;
            }
        }
    }

    /**
     * Adds custom inflection $rules, of either 'plural' or 'singular' $type.
     *
     * ### Usage:
     *
     * {{{
     * Inflector::rules('plural', array('/^(inflect)or$/i' => '\1ables'));
     * Inflector::rules('plural', array(
     *     'rules' => array('/^(inflect)ors$/i' => '\1ables'),
     *     'uninflected' => array('dontinflectme'),
     *     'irregular' => array('red' => 'redlings')
     * ));
     * }}}
     *
     * @param string  $type  The type of inflection, either 'plural' or 'singular'
     * @param array   $rules An array of rules to be added.
     * @param boolean $reset If true, will unset default inflections for all
     *                       new rules that are being defined in $rules.
     *
     * @return void
     */
    public static function rules($type, $rules, $reset = false)
    {
        foreach ($rules as $rule => $pattern) {
            if ( ! is_array($pattern)) {
                continue;
            }

            if ($reset) {
                self::${$type}[$rule] = $pattern;
            } else {
                self::${$type}[$rule] = ($rule === 'uninflected')
                    ? array_merge($pattern, self::${$type}[$rule])
                    : $pattern + self::${$type}[$rule];
            }

            unset($rules[$rule], self::${$type}['cache' . ucfirst($rule)]);

            if (isset(self::${$type}['merged'][$rule])) {
                unset(self::${$type}['merged'][$rule]);
            }

            if ($type === 'plural') {
                self::$cache['pluralize'] = self::$cache['tableize'] = array();
            } elseif ($type === 'singular') {
                self::$cache['singularize'] = array();
            }
        }

        self::${$type}['rules'] = $rules + self::${$type}['rules'];
    }

    /**
     * Returns a word in plural form.
     *
     * @param string $word The word in singular form.
     *
     * @return string The word in plural form.
     */
    public static function pluralize($word)
    {
        if (isset(self::$cache['pluralize'][$word])) {
            return self::$cache['pluralize'][$word];
        }

        if (!isset(self::$plural['merged']['irregular'])) {
            self::$plural['merged']['irregular'] = self::$plural['irregular'];
        }

        if (!isset(self::$plural['merged']['uninflected'])) {
            self::$plural['merged']['uninflected'] = array_merge(self::$plural['uninflected'], self::$uninflected);
        }

        if (!isset(self::$plural['cacheUninflected']) || !isset(self::$plural['cacheIrregular'])) {
            self::$plural['cacheUninflected'] = '(?:' . implode('|', self::$plural['merged']['uninflected']) . ')';
            self::$plural['cacheIrregular']   = '(?:' . implode('|', array_keys(self::$plural['merged']['irregular'])) . ')';
        }

        if (preg_match('/(.*)\\b(' . self::$plural['cacheIrregular'] . ')$/i', $word, $regs)) {
            self::$cache['pluralize'][$word] = $regs[1] . substr($word, 0, 1) . substr(self::$plural['merged']['irregular'][strtolower($regs[2])], 1);
            
            return self::$cache['pluralize'][$word];
        }

        if (preg_match('/^(' . self::$plural['cacheUninflected'] . ')$/i', $word, $regs)) {
            self::$cache['pluralize'][$word] = $word;

            return $word;
        }

        foreach (self::$plural['rules'] as $rule => $replacement) {
            if (preg_match($rule, $word)) {
                self::$cache['pluralize'][$word] = preg_replace($rule, $replacement, $word);

                return self::$cache['pluralize'][$word];
            }
        }
    }

    /**
     * Returns a word in singular form.
     *
     * @param string $word The word in plural form.
     *
     * @return string The word in singular form.
     */
    public static function singularize($word)
    {
        if (isset(self::$cache['singularize'][$word])) {
            return self::$cache['singularize'][$word];
        }

        if (!isset(self::$singular['merged']['uninflected'])) {
            self::$singular['merged']['uninflected'] = array_merge(
                self::$singular['uninflected'],
                self::$uninflected
            );
        }

        if (!isset(self::$singular['merged']['irregular'])) {
            self::$singular['merged']['irregular'] = array_merge(
                self::$singular['irregular'],
                array_flip(self::$plural['irregular'])
            );
        }

        if (!isset(self::$singular['cacheUninflected']) || !isset(self::$singular['cacheIrregular'])) {
            self::$singular['cacheUninflected'] = '(?:' . join('|', self::$singular['merged']['uninflected']) . ')';
            self::$singular['cacheIrregular'] = '(?:' . join('|', array_keys(self::$singular['merged']['irregular'])) . ')';
        }

        if (preg_match('/(.*)\\b(' . self::$singular['cacheIrregular'] . ')$/i', $word, $regs)) {
            self::$cache['singularize'][$word] = $regs[1] . substr($word, 0, 1) . substr(self::$singular['merged']['irregular'][strtolower($regs[2])], 1);
            
            return self::$cache['singularize'][$word];
        }

        if (preg_match('/^(' . self::$singular['cacheUninflected'] . ')$/i', $word, $regs)) {
            self::$cache['singularize'][$word] = $word;

            return $word;
        }

        foreach (self::$singular['rules'] as $rule => $replacement) {
            if (preg_match($rule, $word)) {
                self::$cache['singularize'][$word] = preg_replace($rule, $replacement, $word);

                return self::$cache['singularize'][$word];
            }
        }

        self::$cache['singularize'][$word] = $word;

        return $word;
    }
}
Copyright (c) 2011 Michael Dowling, https://github.com/mtdowling <mtdowling@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
<?php

namespace Guzzle\Cache;

/**
 * Abstract cache adapter
 */
abstract class AbstractCacheAdapter implements CacheAdapterInterface
{
    protected $cache;

    /**
     * Get the object owned by the adapter
     *
     * @return mixed
     */
    public function getCacheObject()
    {
        return $this->cache;
    }
}
<?php

namespace Guzzle\Cache;

use Doctrine\Common\Cache\Cache;
use Guzzle\Common\Version;
use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Common\Exception\RuntimeException;
use Guzzle\Common\FromConfigInterface;
use Zend\Cache\Storage\StorageInterface;

/**
 * Generates cache adapters from any number of known cache implementations
 */
class CacheAdapterFactory implements FromConfigInterface
{
    /**
     * Create a Guzzle cache adapter based on an array of options
     *
     * @param mixed $cache Cache value
     *
     * @return CacheAdapterInterface
     * @throws InvalidArgumentException
     */
    public static function fromCache($cache)
    {
        if (!is_object($cache)) {
            throw new InvalidArgumentException('Cache must be one of the known cache objects');
        }

        if ($cache instanceof CacheAdapterInterface) {
            return $cache;
        } elseif ($cache instanceof Cache) {
            return new DoctrineCacheAdapter($cache);
        } elseif ($cache instanceof StorageInterface) {
            return new Zf2CacheAdapter($cache);
        } else {
            throw new InvalidArgumentException('Unknown cache type: ' . get_class($cache));
        }
    }

    /**
     * Create a Guzzle cache adapter based on an array of options
     *
     * @param array $config Array of configuration options
     *
     * @return CacheAdapterInterface
     * @throws InvalidArgumentException
     * @deprecated This will be removed in a future version
     * @codeCoverageIgnore
     */
    public static function factory($config = array())
    {
        Version::warn(__METHOD__ . ' is deprecated');
        if (!is_array($config)) {
            throw new InvalidArgumentException('$config must be an array');
        }

        if (!isset($config['cache.adapter']) && !isset($config['cache.provider'])) {
            $config['cache.adapter'] = 'Guzzle\Cache\NullCacheAdapter';
            $config['cache.provider'] = null;
        } else {
            // Validate that the options are valid
            foreach (array('cache.adapter', 'cache.provider') as $required) {
                if (!isset($config[$required])) {
                    throw new InvalidArgumentException("{$required} is a required CacheAdapterFactory option");
                }
                if (is_string($config[$required])) {
                    // Convert dot notation to namespaces
                    $config[$required] = str_replace('.', '\\', $config[$required]);
                    if (!class_exists($config[$required])) {
                        throw new InvalidArgumentException("{$config[$required]} is not a valid class for {$required}");
                    }
                }
            }
            // Instantiate the cache provider
            if (is_string($config['cache.provider'])) {
                $args = isset($config['cache.provider.args']) ? $config['cache.provider.args'] : null;
                $config['cache.provider'] = self::createObject($config['cache.provider'], $args);
            }
        }

        // Instantiate the cache adapter using the provider and options
        if (is_string($config['cache.adapter'])) {
            $args = isset($config['cache.adapter.args']) ? $config['cache.adapter.args'] : array();
            array_unshift($args, $config['cache.provider']);
            $config['cache.adapter'] = self::createObject($config['cache.adapter'], $args);
        }

        return $config['cache.adapter'];
    }

    /**
     * Create a class using an array of constructor arguments
     *
     * @param string $className Class name
     * @param array  $args      Arguments for the class constructor
     *
     * @return mixed
     * @throws RuntimeException
     * @deprecated
     * @codeCoverageIgnore
     */
    private static function createObject($className, array $args = null)
    {
        try {
            if (!$args) {
                return new $className;
            } else {
                $c = new \ReflectionClass($className);
                return $c->newInstanceArgs($args);
            }
        } catch (\Exception $e) {
            throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
        }
    }
}
{
    "name": "guzzle/cache",
    "description": "Guzzle cache adapter component",
    "homepage": "http://guzzlephp.org/",
    "keywords": ["cache", "adapter", "zf", "doctrine", "guzzle"],
    "license": "MIT",
    "authors": [
        {
            "name": "Michael Dowling",
            "email": "mtdowling@gmail.com",
            "homepage": "https://github.com/mtdowling"
        }
    ],
    "require": {
        "php": ">=5.3.2",
        "guzzle/common": "self.version"
    },
    "autoload": {
        "psr-0": { "Guzzle\\Cache": "" }
    },
    "target-dir": "Guzzle/Cache",
    "extra": {
        "branch-alias": {
            "dev-master": "3.7-dev"
        }
    }
}
<?php

namespace Guzzle\Cache;

use Zend\Cache\Storage\StorageInterface;

/**
 * Zend Framework 2 cache adapter
 *
 * @link http://packages.zendframework.com/docs/latest/manual/en/zend.cache.html
 */
class Zf2CacheAdapter extends AbstractCacheAdapter
{
    /**
     * @param StorageInterface $cache Zend Framework 2 cache adapter
     */
    public function __construct(StorageInterface $cache)
    {
        $this->cache = $cache;
    }

    public function contains($id, array $options = null)
    {
        return $this->cache->hasItem($id);
    }

    public function delete($id, array $options = null)
    {
        return $this->cache->removeItem($id);
    }

    public function fetch($id, array $options = null)
    {
        return $this->cache->getItem($id);
    }

    public function save($id, $data, $lifeTime = false, array $options = null)
    {
        return $this->cache->setItem($id, $data);
    }
}
<?php

namespace Guzzle\Cache;

use Doctrine\Common\Cache\Cache;

/**
 * Doctrine 2 cache adapter
 *
 * @link http://www.doctrine-project.org/
 */
class DoctrineCacheAdapter extends AbstractCacheAdapter
{
    /**
     * @param Cache $cache Doctrine cache object
     */
    public function __construct(Cache $cache)
    {
        $this->cache = $cache;
    }

    public function contains($id, array $options = null)
    {
        return $this->cache->contains($id);
    }

    public function delete($id, array $options = null)
    {
        return $this->cache->delete($id);
    }

    public function fetch($id, array $options = null)
    {
        return $this->cache->fetch($id);
    }

    public function save($id, $data, $lifeTime = false, array $options = null)
    {
        return $this->cache->save($id, $data, $lifeTime !== false ? $lifeTime : 0);
    }
}
<?php

namespace Guzzle\Cache;

/**
 * Interface for cache adapters.
 *
 * Cache adapters allow Guzzle to utilize various frameworks for caching HTTP responses.
 *
 * @link http://www.doctrine-project.org/ Inspired by Doctrine 2
 */
interface CacheAdapterInterface
{
    /**
     * Test if an entry exists in the cache.
     *
     * @param string $id      cache id The cache id of the entry to check for.
     * @param array  $options Array of cache adapter options
     *
     * @return bool Returns TRUE if a cache entry exists for the given cache id, FALSE otherwise.
     */
    public function contains($id, array $options = null);

    /**
     * Deletes a cache entry.
     *
     * @param string $id      cache id
     * @param array  $options Array of cache adapter options
     *
     * @return bool TRUE on success, FALSE on failure
     */
    public function delete($id, array $options = null);

    /**
     * Fetches an entry from the cache.
     *
     * @param string $id      cache id The id of the cache entry to fetch.
     * @param array  $options Array of cache adapter options
     *
     * @return string The cached data or FALSE, if no cache entry exists for the given id.
     */
    public function fetch($id, array $options = null);

    /**
     * Puts data into the cache.
     *
     * @param string   $id       The cache id
     * @param string   $data     The cache entry/data
     * @param int|bool $lifeTime The lifetime. If != false, sets a specific lifetime for this cache entry
     * @param array    $options  Array of cache adapter options
     *
     * @return bool TRUE if the entry was successfully stored in the cache, FALSE otherwise.
     */
    public function save($id, $data, $lifeTime = false, array $options = null);
}
<?php

namespace Guzzle\Cache;

/**
 * Cache adapter that defers to closures for implementation
 */
class ClosureCacheAdapter implements CacheAdapterInterface
{
    /**
     * @var array Mapping of method names to callables
     */
    protected $callables;

    /**
     * The callables array is an array mapping the actions of the cache adapter to callables.
     * - contains: Callable that accepts an $id and $options argument
     * - delete:   Callable that accepts an $id and $options argument
     * - fetch:    Callable that accepts an $id and $options argument
     * - save:     Callable that accepts an $id, $data, $lifeTime, and $options argument
     *
     * @param array $callables array of action names to callable
     *
     * @throws \InvalidArgumentException if the callable is not callable
     */
    public function __construct(array $callables)
    {
        // Validate each key to ensure it exists and is callable
        foreach (array('contains', 'delete', 'fetch', 'save') as $key) {
            if (!array_key_exists($key, $callables) || !is_callable($callables[$key])) {
                throw new \InvalidArgumentException("callables must contain a callable {$key} key");
            }
        }

        $this->callables = $callables;
    }

    public function contains($id, array $options = null)
    {
        return call_user_func($this->callables['contains'], $id, $options);
    }

    public function delete($id, array $options = null)
    {
        return call_user_func($this->callables['delete'], $id, $options);
    }

    public function fetch($id, array $options = null)
    {
        return call_user_func($this->callables['fetch'], $id, $options);
    }

    public function save($id, $data, $lifeTime = false, array $options = null)
    {
        return call_user_func($this->callables['save'], $id, $data, $lifeTime, $options);
    }
}
<?php

namespace Guzzle\Cache;

use Guzzle\Common\Version;

/**
 * Zend Framework 1 cache adapter
 *
 * @link http://framework.zend.com/manual/en/zend.cache.html
 * @deprecated
 * @codeCoverageIgnore
 */
class Zf1CacheAdapter extends AbstractCacheAdapter
{
    /**
     * @param \Zend_Cache_Backend $cache Cache object to wrap
     */
    public function __construct(\Zend_Cache_Backend $cache)
    {
        Version::warn(__CLASS__ . ' is deprecated. Upgrade to ZF2 or use PsrCacheAdapter');
        $this->cache = $cache;
    }

    public function contains($id, array $options = null)
    {
        return $this->cache->test($id);
    }

    public function delete($id, array $options = null)
    {
        return $this->cache->remove($id);
    }

    public function fetch($id, array $options = null)
    {
        return $this->cache->load($id);
    }

    public function save($id, $data, $lifeTime = false, array $options = null)
    {
        return $this->cache->save($data, $id, array(), $lifeTime);
    }
}
<?php

namespace Guzzle\Cache;

/**
 * Null cache adapter
 */
class NullCacheAdapter extends AbstractCacheAdapter
{
    public function __construct() {}

    public function contains($id, array $options = null)
    {
        return false;
    }

    public function delete($id, array $options = null)
    {
        return true;
    }

    public function fetch($id, array $options = null)
    {
        return false;
    }

    public function save($id, $data, $lifeTime = false, array $options = null)
    {
        return true;
    }
}
<?php

namespace Guzzle\Service;

use Guzzle\Common\FromConfigInterface;
use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Http\ClientInterface as HttpClientInterface;
use Guzzle\Service\Exception\CommandTransferException;
use Guzzle\Service\Command\CommandInterface;
use Guzzle\Service\Description\ServiceDescriptionInterface;
use Guzzle\Service\Resource\ResourceIteratorInterface;

/**
 * Client interface for executing commands on a web service.
 */
interface ClientInterface extends HttpClientInterface, FromConfigInterface
{
    /**
     * Get a command by name. First, the client will see if it has a service description and if the service description
     * defines a command by the supplied name. If no dynamic command is found, the client will look for a concrete
     * command class exists matching the name supplied. If neither are found, an InvalidArgumentException is thrown.
     *
     * @param string $name Name of the command to retrieve
     * @param array  $args Arguments to pass to the command
     *
     * @return CommandInterface
     * @throws InvalidArgumentException if no command can be found by name
     */
    public function getCommand($name, array $args = array());

    /**
     * Execute one or more commands
     *
     * @param CommandInterface|array|Traversable $command Command, array of commands or Traversable object containing commands to execute
     *
     * @return mixed Returns the result of the executed command or an array of commands if executing multiple commands
     * @throws InvalidArgumentException if an invalid command is passed
     * @throws CommandTransferException if an exception is encountered when transferring multiple commands
     */
    public function execute($command);

    /**
     * Set the service description of the client
     *
     * @param ServiceDescriptionInterface $service Service description
     *
     * @return ClientInterface
     */
    public function setDescription(ServiceDescriptionInterface $service);

    /**
     * Get the service description of the client
     *
     * @return ServiceDescriptionInterface|null
     */
    public function getDescription();

    /**
     * Get a resource iterator from the client.
     *
     * @param string|CommandInterface $command         Command class or command name.
     * @param array                   $commandOptions  Command options used when creating commands.
     * @param array                   $iteratorOptions Iterator options passed to the iterator when it is instantiated.
     *
     * @return ResourceIteratorInterface
     */
    public function getIterator($command, array $commandOptions = null, array $iteratorOptions = array());
}
<?php

namespace Guzzle\Service;

use Guzzle\Cache\CacheAdapterInterface;

/**
 * Decorator that adds caching to a service description loader
 */
class CachingConfigLoader implements ConfigLoaderInterface
{
    /** @var ConfigLoaderInterface */
    protected $loader;

    /** @var CacheAdapterInterface */
    protected $cache;

    /**
     * @param ConfigLoaderInterface $loader Loader used to load the config when there is a cache miss
     * @param CacheAdapterInterface $cache  Object used to cache the loaded result
     */
    public function __construct(ConfigLoaderInterface $loader, CacheAdapterInterface $cache)
    {
        $this->loader = $loader;
        $this->cache = $cache;
    }

    public function load($config, array $options = array())
    {
        if (!is_string($config)) {
            $key = false;
        } else {
            $key = 'loader_' . crc32($config);
            if ($result = $this->cache->fetch($key)) {
                return $result;
            }
        }

        $result = $this->loader->load($config, $options);
        if ($key) {
            $this->cache->save($key, $result);
        }

        return $result;
    }
}
<?php

namespace Guzzle\Service\Builder;

use Guzzle\Common\AbstractHasDispatcher;
use Guzzle\Service\ClientInterface;
use Guzzle\Service\Exception\ServiceBuilderException;
use Guzzle\Service\Exception\ServiceNotFoundException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * {@inheritdoc}
 *
 * Clients and data can be set, retrieved, and removed by accessing the service builder like an associative array.
 */
class ServiceBuilder extends AbstractHasDispatcher implements ServiceBuilderInterface, \ArrayAccess, \Serializable
{
    /** @var array Service builder configuration data */
    protected $builderConfig = array();

    /** @var array Instantiated client objects */
    protected $clients = array();

    /** @var ServiceBuilderLoader Cached instance of the service builder loader */
    protected static $cachedFactory;

    /** @var array Plugins to attach to each client created by the service builder */
    protected $plugins = array();

    /**
     * Create a new ServiceBuilder using configuration data sourced from an
     * array, .js|.json or .php file.
     *
     * @param array|string $config           The full path to an .json|.js or .php file, or an associative array
     * @param array        $globalParameters Array of global parameters to pass to every service as it is instantiated.
     *
     * @return ServiceBuilderInterface
     * @throws ServiceBuilderException if a file cannot be opened
     * @throws ServiceNotFoundException when trying to extend a missing client
     */
    public static function factory($config = null, array $globalParameters = array())
    {
        // @codeCoverageIgnoreStart
        if (!static::$cachedFactory) {
            static::$cachedFactory = new ServiceBuilderLoader();
        }
        // @codeCoverageIgnoreEnd

        return self::$cachedFactory->load($config, $globalParameters);
    }

    /**
     * @param array $serviceBuilderConfig Service configuration settings:
     *     - name: Name of the service
     *     - class: Client class to instantiate using a factory method
     *     - params: array of key value pair configuration settings for the builder
     */
    public function __construct(array $serviceBuilderConfig = array())
    {
        $this->builderConfig = $serviceBuilderConfig;
    }

    public static function getAllEvents()
    {
        return array('service_builder.create_client');
    }

    public function unserialize($serialized)
    {
        $this->builderConfig = json_decode($serialized, true);
    }

    public function serialize()
    {
        return json_encode($this->builderConfig);
    }

    /**
     * Attach a plugin to every client created by the builder
     *
     * @param EventSubscriberInterface $plugin Plugin to attach to each client
     *
     * @return self
     */
    public function addGlobalPlugin(EventSubscriberInterface $plugin)
    {
        $this->plugins[] = $plugin;

        return $this;
    }

    /**
     * Get data from the service builder without triggering the building of a service
     *
     * @param string $name Name of the service to retrieve
     *
     * @return array|null
     */
    public function getData($name)
    {
        return isset($this->builderConfig[$name]) ? $this->builderConfig[$name] : null;
    }

    public function get($name, $throwAway = false)
    {
        if (!isset($this->builderConfig[$name])) {

            // Check to see if arbitrary data is being referenced
            if (isset($this->clients[$name])) {
                return $this->clients[$name];
            }

            // Check aliases and return a match if found
            foreach ($this->builderConfig as $actualName => $config) {
                if (isset($config['alias']) && $config['alias'] == $name) {
                    return $this->get($actualName, $throwAway);
                }
            }
            throw new ServiceNotFoundException('No service is registered as ' . $name);
        }

        if (!$throwAway && isset($this->clients[$name])) {
            return $this->clients[$name];
        }

        $builder =& $this->builderConfig[$name];

        // Convert references to the actual client
        foreach ($builder['params'] as &$v) {
            if (is_string($v) && substr($v, 0, 1) == '{' && substr($v, -1) == '}') {
                $v = $this->get(trim($v, '{} '));
            }
        }

        // Get the configured parameters and merge in any parameters provided for throw-away clients
        $config = $builder['params'];
        if (is_array($throwAway)) {
            $config = $throwAway + $config;
        }

        $client = $builder['class']::factory($config);

        if (!$throwAway) {
            $this->clients[$name] = $client;
        }

        if ($client instanceof ClientInterface) {
            foreach ($this->plugins as $plugin) {
                $client->addSubscriber($plugin);
            }
            // Dispatch an event letting listeners know a client was created
            $this->dispatch('service_builder.create_client', array('client' => $client));
        }

        return $client;
    }

    public function set($key, $service)
    {
        if (is_array($service) && isset($service['class']) && isset($service['params'])) {
            $this->builderConfig[$key] = $service;
        } else {
            $this->clients[$key] = $service;
        }

        return $this;
    }

    public function offsetSet($offset, $value)
    {
        $this->set($offset, $value);
    }

    public function offsetUnset($offset)
    {
        unset($this->builderConfig[$offset]);
        unset($this->clients[$offset]);
    }

    public function offsetExists($offset)
    {
        return isset($this->builderConfig[$offset]) || isset($this->clients[$offset]);
    }

    public function offsetGet($offset)
    {
        return $this->get($offset);
    }
}
<?php

namespace Guzzle\Service\Builder;

use Guzzle\Service\Exception\ServiceNotFoundException;

/**
 * Service builder used to store and build clients or arbitrary data. Client configuration data can be supplied to tell
 * the service builder how to create and cache {@see \Guzzle\Service\ClientInterface} objects. Arbitrary data can be
 * supplied and accessed from a service builder. Arbitrary data and other clients can be referenced by name in client
 * configuration arrays to make them input for building other clients (e.g. "{key}").
 */
interface ServiceBuilderInterface
{
    /**
     * Get a ClientInterface object or arbitrary data from the service builder
     *
     * @param string     $name      Name of the registered service or data to retrieve
     * @param bool|array $throwAway Only pertains to retrieving client objects built using a configuration array.
     *                              Set to TRUE to not store the client for later retrieval from the ServiceBuilder.
     *                              If an array is specified, that data will overwrite the configured params of the
     *                              client if the client implements {@see \Guzzle\Common\FromConfigInterface} and will
     *                              not store the client for later retrieval.
     *
     * @return \Guzzle\Service\ClientInterface|mixed
     * @throws ServiceNotFoundException when a client or data cannot be found by the given name
     */
    public function get($name, $throwAway = false);

    /**
     * Register a service or arbitrary data by name with the service builder
     *
     * @param string $key     Name of the client or data to register
     * @param mixed  $service Client configuration array or arbitrary data to register. The client configuration array
     *                        must include a 'class' (string) and 'params' (array) key.
     *
     * @return ServiceBuilderInterface
     */
    public function set($key, $service);
}
<?php

namespace Guzzle\Service\Builder;

use Guzzle\Service\AbstractConfigLoader;
use Guzzle\Service\Exception\ServiceNotFoundException;

/**
 * Service builder config loader
 */
class ServiceBuilderLoader extends AbstractConfigLoader
{
    protected function build($config, array $options)
    {
        // A service builder class can be specified in the class field
        $class = !empty($config['class']) ? $config['class'] : __NAMESPACE__ . '\\ServiceBuilder';

        // Account for old style configs that do not have a services array
        $services = isset($config['services']) ? $config['services'] : $config;

        // Validate the configuration and handle extensions
        foreach ($services as $name => &$service) {

            $service['params'] = isset($service['params']) ? $service['params'] : array();

            // Check if this client builder extends another client
            if (!empty($service['extends'])) {

                // Make sure that the service it's extending has been defined
                if (!isset($services[$service['extends']])) {
                    throw new ServiceNotFoundException(
                        "{$name} is trying to extend a non-existent service: {$service['extends']}"
                    );
                }

                $extended = &$services[$service['extends']];

                // Use the correct class attribute
                if (empty($service['class'])) {
                    $service['class'] = isset($extended['class']) ? $extended['class'] : '';
                }
                if ($extendsParams = isset($extended['params']) ? $extended['params'] : false) {
                    $service['params'] = $service['params'] + $extendsParams;
                }
            }

            // Overwrite default values with global parameter values
            if (!empty($options)) {
                $service['params'] = $options + $service['params'];
            }

            $service['class'] = isset($service['class']) ? $service['class'] : '';
        }

        return new $class($services);
    }

    protected function mergeData(array $a, array $b)
    {
        $result = $b + $a;

        // Merge services using a recursive union of arrays
        if (isset($a['services']) && $b['services']) {

            // Get a union of the services of the two arrays
            $result['services'] = $b['services'] + $a['services'];

            // Merge each service in using a union of the two arrays
            foreach ($result['services'] as $name => &$service) {

                // By default, services completely override a previously defined service unless it extends itself
                if (isset($a['services'][$name]['extends'])
                    && isset($b['services'][$name]['extends'])
                    && $b['services'][$name]['extends'] == $name
                ) {
                    $service += $a['services'][$name];
                    // Use the `extends` attribute of the parent
                    $service['extends'] = $a['services'][$name]['extends'];
                    // Merge parameters using a union if both have parameters
                    if (isset($a['services'][$name]['params'])) {
                        $service['params'] += $a['services'][$name]['params'];
                    }
                }
            }
        }

        return $result;
    }
}
<?php

namespace Guzzle\Service\Exception;

class ServiceNotFoundException extends ServiceBuilderException {}
<?php

namespace Guzzle\Service\Exception;

use Guzzle\Common\Exception\RuntimeException;

class CommandException extends RuntimeException {}
<?php

namespace Guzzle\Service\Exception;

use Guzzle\Common\Exception\RuntimeException;

class ResponseClassException extends RuntimeException
{
}
<?php

namespace Guzzle\Service\Exception;

use Guzzle\Common\Exception\RuntimeException;

class DescriptionBuilderException extends RuntimeException {}
<?php

namespace Guzzle\Service\Exception;

use Guzzle\Http\Exception\MultiTransferException;
use Guzzle\Service\Command\CommandInterface;

/**
 * Exception thrown when transferring commands in parallel
 */
class CommandTransferException extends MultiTransferException
{
    protected $successfulCommands = array();
    protected $failedCommands = array();

    /**
     * Creates a new CommandTransferException from a MultiTransferException
     *
     * @param MultiTransferException $e Exception to base a new exception on
     *
     * @return self
     */
    public static function fromMultiTransferException(MultiTransferException $e)
    {
        $ce = new self($e->getMessage(), $e->getCode(), $e->getPrevious());
        $ce->setSuccessfulRequests($e->getSuccessfulRequests());

        $alreadyAddedExceptions = array();
        foreach ($e->getFailedRequests() as $request) {
            if ($re = $e->getExceptionForFailedRequest($request)) {
                $alreadyAddedExceptions[] = $re;
                $ce->addFailedRequestWithException($request, $re);
            } else {
                $ce->addFailedRequest($request);
            }
        }

        // Add any exceptions that did not map to a request
        if (count($alreadyAddedExceptions) < count($e)) {
            foreach ($e as $ex) {
                if (!in_array($ex, $alreadyAddedExceptions)) {
                    $ce->add($ex);
                }
            }
        }

        return $ce;
    }

    /**
     * Get all of the commands in the transfer
     *
     * @return array
     */
    public function getAllCommands()
    {
        return array_merge($this->successfulCommands, $this->failedCommands);
    }

    /**
     * Add to the array of successful commands
     *
     * @param CommandInterface $command Successful command
     *
     * @return self
     */
    public function addSuccessfulCommand(CommandInterface $command)
    {
        $this->successfulCommands[] = $command;

        return $this;
    }

    /**
     * Add to the array of failed commands
     *
     * @param CommandInterface $command Failed command
     *
     * @return self
     */
    public function addFailedCommand(CommandInterface $command)
    {
        $this->failedCommands[] = $command;

        return $this;
    }

    /**
     * Get an array of successful commands
     *
     * @return array
     */
    public function getSuccessfulCommands()
    {
        return $this->successfulCommands;
    }

    /**
     * Get an array of failed commands
     *
     * @return array
     */
    public function getFailedCommands()
    {
        return $this->failedCommands;
    }

    /**
     * Get the Exception that caused the given $command to fail
     *
     * @param CommandInterface $command Failed command
     *
     * @return \Exception|null
     */
    public function getExceptionForFailedCommand(CommandInterface $command)
    {
        return $this->getExceptionForFailedRequest($command->getRequest());
    }
}
<?php

namespace Guzzle\Service\Exception;

use Guzzle\Common\Exception\RuntimeException;

/**
 * Command transfer exception when commands do not all use the same client
 */
class InconsistentClientTransferException extends RuntimeException
{
    /**
     * @var array Commands with an invalid client
     */
    private $invalidCommands = array();

    /**
     * @param array $commands Invalid commands
     */
    public function __construct(array $commands)
    {
        $this->invalidCommands = $commands;
        parent::__construct(
            'Encountered commands in a batch transfer that use inconsistent clients. The batching ' .
            'strategy you use with a command transfer must divide command batches by client.'
        );
    }

    /**
     * Get the invalid commands
     *
     * @return array
     */
    public function getCommands()
    {
        return $this->invalidCommands;
    }
}
<?php

namespace Guzzle\Service\Exception;

use Guzzle\Common\Exception\RuntimeException;

class ServiceBuilderException extends RuntimeException {}
<?php

namespace Guzzle\Service\Exception;

use Guzzle\Common\Exception\RuntimeException;

class ValidationException extends RuntimeException
{
    protected $errors = array();

    /**
     * Set the validation error messages
     *
     * @param array $errors Array of validation errors
     */
    public function setErrors(array $errors)
    {
        $this->errors = $errors;
    }

    /**
     * Get any validation errors
     *
     * @return array
     */
    public function getErrors()
    {
        return $this->errors;
    }
}
{
    "name": "guzzle/service",
    "description": "Guzzle service component for abstracting RESTful web services",
    "homepage": "http://guzzlephp.org/",
    "keywords": ["web service", "webservice", "REST", "guzzle"],
    "license": "MIT",
    "authors": [
        {
            "name": "Michael Dowling",
            "email": "mtdowling@gmail.com",
            "homepage": "https://github.com/mtdowling"
        }
    ],
    "require": {
        "php": ">=5.3.2",
        "guzzle/cache": "self.version",
        "guzzle/http": "self.version",
        "guzzle/inflection": "self.version"
    },
    "autoload": {
        "psr-0": { "Guzzle\\Service": "" }
    },
    "target-dir": "Guzzle/Service",
    "extra": {
        "branch-alias": {
            "dev-master": "3.7-dev"
        }
    }
}
<?php

namespace Guzzle\Service;

use Guzzle\Common\Collection;
use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Common\Exception\BadMethodCallException;
use Guzzle\Common\Version;
use Guzzle\Inflection\InflectorInterface;
use Guzzle\Inflection\Inflector;
use Guzzle\Http\Client as HttpClient;
use Guzzle\Http\Exception\MultiTransferException;
use Guzzle\Service\Exception\CommandTransferException;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Service\Command\CommandInterface;
use Guzzle\Service\Command\Factory\CompositeFactory;
use Guzzle\Service\Command\Factory\FactoryInterface as CommandFactoryInterface;
use Guzzle\Service\Resource\ResourceIteratorClassFactory;
use Guzzle\Service\Resource\ResourceIteratorFactoryInterface;
use Guzzle\Service\Description\ServiceDescriptionInterface;

/**
 * Client object for executing commands on a web service.
 */
class Client extends HttpClient implements ClientInterface
{
    const COMMAND_PARAMS = 'command.params';

    /** @var ServiceDescriptionInterface Description of the service and possible commands */
    protected $serviceDescription;

    /** @var CommandFactoryInterface */
    protected $commandFactory;

    /** @var ResourceIteratorFactoryInterface */
    protected $resourceIteratorFactory;

    /** @var InflectorInterface Inflector associated with the service/client */
    protected $inflector;

    /**
     * Basic factory method to create a new client. Extend this method in subclasses to build more complex clients.
     *
     * @param array|Collection $config Configuration data
     *
     * @return Client
     */
    public static function factory($config = array())
    {
        return new static(isset($config['base_url']) ? $config['base_url'] : null, $config);
    }

    public static function getAllEvents()
    {
        return array_merge(HttpClient::getAllEvents(), array(
            'client.command.create',
            'command.before_prepare',
            'command.after_prepare',
            'command.before_send',
            'command.after_send',
            'command.parse_response'
        ));
    }

    /**
     * Magic method used to retrieve a command
     *
     * @param string $method Name of the command object to instantiate
     * @param array  $args   Arguments to pass to the command
     *
     * @return mixed Returns the result of the command
     * @throws BadMethodCallException when a command is not found
     */
    public function __call($method, $args)
    {
        return $this->getCommand($method, isset($args[0]) ? $args[0] : array())->getResult();
    }

    public function getCommand($name, array $args = array())
    {
        // Add global client options to the command
        if ($options = $this->getConfig(self::COMMAND_PARAMS)) {
            $args += $options;
        }

        if (!($command = $this->getCommandFactory()->factory($name, $args))) {
            throw new InvalidArgumentException("Command was not found matching {$name}");
        }

        $command->setClient($this);
        $this->dispatch('client.command.create', array('client' => $this, 'command' => $command));

        return $command;
    }

    /**
     * Set the command factory used to create commands by name
     *
     * @param CommandFactoryInterface $factory Command factory
     *
     * @return self
     */
    public function setCommandFactory(CommandFactoryInterface $factory)
    {
        $this->commandFactory = $factory;

        return $this;
    }

    /**
     * Set the resource iterator factory associated with the client
     *
     * @param ResourceIteratorFactoryInterface $factory Resource iterator factory
     *
     * @return self
     */
    public function setResourceIteratorFactory(ResourceIteratorFactoryInterface $factory)
    {
        $this->resourceIteratorFactory = $factory;

        return $this;
    }

    public function getIterator($command, array $commandOptions = null, array $iteratorOptions = array())
    {
        if (!($command instanceof CommandInterface)) {
            $command = $this->getCommand($command, $commandOptions ?: array());
        }

        return $this->getResourceIteratorFactory()->build($command, $iteratorOptions);
    }

    public function execute($command)
    {
        if ($command instanceof CommandInterface) {
            $this->send($this->prepareCommand($command));
            $this->dispatch('command.after_send', array('command' => $command));
            return $command->getResult();
        } elseif (is_array($command) || $command instanceof \Traversable) {
            return $this->executeMultiple($command);
        } else {
            throw new InvalidArgumentException('Command must be a command or array of commands');
        }
    }

    public function setDescription(ServiceDescriptionInterface $service)
    {
        $this->serviceDescription = $service;

        if ($this->getCommandFactory() && $this->getCommandFactory() instanceof CompositeFactory) {
            $this->commandFactory->add(new Command\Factory\ServiceDescriptionFactory($service));
        }

        // If a baseUrl was set on the description, then update the client
        if ($baseUrl = $service->getBaseUrl()) {
            $this->setBaseUrl($baseUrl);
        }

        return $this;
    }

    public function getDescription()
    {
        return $this->serviceDescription;
    }

    /**
     * Set the inflector used with the client
     *
     * @param InflectorInterface $inflector Inflection object
     *
     * @return self
     */
    public function setInflector(InflectorInterface $inflector)
    {
        $this->inflector = $inflector;

        return $this;
    }

    /**
     * Get the inflector used with the client
     *
     * @return self
     */
    public function getInflector()
    {
        if (!$this->inflector) {
            $this->inflector = Inflector::getDefault();
        }

        return $this->inflector;
    }

    /**
     * Prepare a command for sending and get the RequestInterface object created by the command
     *
     * @param CommandInterface $command Command to prepare
     *
     * @return RequestInterface
     */
    protected function prepareCommand(CommandInterface $command)
    {
        // Set the client and prepare the command
        $request = $command->setClient($this)->prepare();
        // Set the state to new if the command was previously executed
        $request->setState(RequestInterface::STATE_NEW);
        $this->dispatch('command.before_send', array('command' => $command));

        return $request;
    }

    /**
     * Execute multiple commands in parallel
     *
     * @param array|Traversable $commands Array of CommandInterface objects to execute
     *
     * @return array Returns an array of the executed commands
     * @throws Exception\CommandTransferException
     */
    protected function executeMultiple($commands)
    {
        $requests = array();
        $commandRequests = new \SplObjectStorage();

        foreach ($commands as $command) {
            $request = $this->prepareCommand($command);
            $commandRequests[$request] = $command;
            $requests[] = $request;
        }

        try {
            $this->send($requests);
            foreach ($commands as $command) {
                $this->dispatch('command.after_send', array('command' => $command));
            }
            return $commands;
        } catch (MultiTransferException $failureException) {
            // Throw a CommandTransferException using the successful and failed commands
            $e = CommandTransferException::fromMultiTransferException($failureException);

            // Remove failed requests from the successful requests array and add to the failures array
            foreach ($failureException->getFailedRequests() as $request) {
                if (isset($commandRequests[$request])) {
                    $e->addFailedCommand($commandRequests[$request]);
                    unset($commandRequests[$request]);
                }
            }

            // Always emit the command after_send events for successful commands
            foreach ($commandRequests as $success) {
                $e->addSuccessfulCommand($commandRequests[$success]);
                $this->dispatch('command.after_send', array('command' => $commandRequests[$success]));
            }

            throw $e;
        }
    }

    protected function getResourceIteratorFactory()
    {
        if (!$this->resourceIteratorFactory) {
            // Build the default resource iterator factory if one is not set
            $clientClass = get_class($this);
            $prefix = substr($clientClass, 0, strrpos($clientClass, '\\'));
            $this->resourceIteratorFactory = new ResourceIteratorClassFactory(array(
                "{$prefix}\\Iterator",
                "{$prefix}\\Model"
            ));
        }

        return $this->resourceIteratorFactory;
    }

    /**
     * Get the command factory associated with the client
     *
     * @return CommandFactoryInterface
     */
    protected function getCommandFactory()
    {
        if (!$this->commandFactory) {
            $this->commandFactory = CompositeFactory::getDefaultChain($this);
        }

        return $this->commandFactory;
    }

    /**
     * @deprecated
     * @codeCoverageIgnore
     */
    public function enableMagicMethods($isEnabled)
    {
        Version::warn(__METHOD__ . ' is deprecated');
    }
}
<?php

namespace Guzzle\Service;

use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Common\Exception\RuntimeException;

/**
 * Abstract config loader
 */
abstract class AbstractConfigLoader implements ConfigLoaderInterface
{
    /** @var array Array of aliases for actual filenames */
    protected $aliases = array();

    /** @var array Hash of previously loaded filenames */
    protected $loadedFiles = array();

    /** @var array JSON error code mappings */
    protected static $jsonErrors = array(
        JSON_ERROR_NONE => 'JSON_ERROR_NONE - No errors',
        JSON_ERROR_DEPTH => 'JSON_ERROR_DEPTH - Maximum stack depth exceeded',
        JSON_ERROR_STATE_MISMATCH => 'JSON_ERROR_STATE_MISMATCH - Underflow or the modes mismatch',
        JSON_ERROR_CTRL_CHAR => 'JSON_ERROR_CTRL_CHAR - Unexpected control character found',
        JSON_ERROR_SYNTAX => 'JSON_ERROR_SYNTAX - Syntax error, malformed JSON',
        JSON_ERROR_UTF8 => 'JSON_ERROR_UTF8 - Malformed UTF-8 characters, possibly incorrectly encoded'
    );

    public function load($config, array $options = array())
    {
        // Reset the array of loaded files because this is a new config
        $this->loadedFiles = array();

        if (is_string($config)) {
            $config = $this->loadFile($config);
        } elseif (!is_array($config)) {
            throw new InvalidArgumentException('Unknown type passed to configuration loader: ' . gettype($config));
        } else {
            $this->mergeIncludes($config);
        }

        return $this->build($config, $options);
    }

    /**
     * Add an include alias to the loader
     *
     * @param string $filename Filename to alias (e.g. _foo)
     * @param string $alias    Actual file to use (e.g. /path/to/foo.json)
     *
     * @return self
     */
    public function addAlias($filename, $alias)
    {
        $this->aliases[$filename] = $alias;

        return $this;
    }

    /**
     * Remove an alias from the loader
     *
     * @param string $alias Alias to remove
     *
     * @return self
     */
    public function removeAlias($alias)
    {
        unset($this->aliases[$alias]);

        return $this;
    }

    /**
     * Perform the parsing of a config file and create the end result
     *
     * @param array $config  Configuration data
     * @param array $options Options to use when building
     *
     * @return mixed
     */
    protected abstract function build($config, array $options);

    /**
     * Load a configuration file (can load JSON or PHP files that return an array when included)
     *
     * @param string $filename File to load
     *
     * @return array
     * @throws InvalidArgumentException
     * @throws RuntimeException when the JSON cannot be parsed
     */
    protected function loadFile($filename)
    {
        if (isset($this->aliases[$filename])) {
            $filename = $this->aliases[$filename];
        }

        switch (pathinfo($filename, PATHINFO_EXTENSION)) {
            case 'js':
            case 'json':
                $level = error_reporting(0);
                $json = file_get_contents($filename);
                error_reporting($level);

                if ($json === false) {
                    $err = error_get_last();
                    throw new InvalidArgumentException("Unable to open {$filename}: " . $err['message']);
                }

                $config = json_decode($json, true);
                // Throw an exception if there was an error loading the file
                if ($error = json_last_error()) {
                    $message = isset(self::$jsonErrors[$error]) ? self::$jsonErrors[$error] : 'Unknown error';
                    throw new RuntimeException("Error loading JSON data from {$filename}: ({$error}) - {$message}");
                }
                break;
            case 'php':
                if (!is_readable($filename)) {
                    throw new InvalidArgumentException("Unable to open {$filename} for reading");
                }
                $config = require $filename;
                if (!is_array($config)) {
                    throw new InvalidArgumentException('PHP files must return an array of configuration data');
                }
                break;
            default:
                throw new InvalidArgumentException('Unknown file extension: ' . $filename);
        }

        // Keep track of this file being loaded to prevent infinite recursion
        $this->loadedFiles[$filename] = true;

        // Merge include files into the configuration array
        $this->mergeIncludes($config, dirname($filename));

        return $config;
    }

    /**
     * Merges in all include files
     *
     * @param array  $config   Config data that contains includes
     * @param string $basePath Base path to use when a relative path is encountered
     *
     * @return array Returns the merged and included data
     */
    protected function mergeIncludes(&$config, $basePath = null)
    {
        if (!empty($config['includes'])) {
            foreach ($config['includes'] as &$path) {
                // Account for relative paths
                if ($path[0] != DIRECTORY_SEPARATOR && !isset($this->aliases[$path]) && $basePath) {
                    $path = "{$basePath}/{$path}";
                }
                // Don't load the same files more than once
                if (!isset($this->loadedFiles[$path])) {
                    $this->loadedFiles[$path] = true;
                    $config = $this->mergeData($this->loadFile($path), $config);
                }
            }
        }
    }

    /**
     * Default implementation for merging two arrays of data (uses array_merge_recursive)
     *
     * @param array $a Original data
     * @param array $b Data to merge into the original and overwrite existing values
     *
     * @return array
     */
    protected function mergeData(array $a, array $b)
    {
        return array_merge_recursive($a, $b);
    }
}
<?php

namespace Guzzle\Service\Resource;

use Guzzle\Service\Command\CommandInterface;

/**
 * Factory for creating {@see ResourceIteratorInterface} objects
 */
interface ResourceIteratorFactoryInterface
{
    /**
     * Create a resource iterator
     *
     * @param CommandInterface $command Command to create an iterator for
     * @param array                 $options Iterator options that are exposed as data.
     *
     * @return ResourceIteratorInterface
     */
    public function build(CommandInterface $command, array $options = array());

    /**
     * Check if the factory can create an iterator
     *
     * @param CommandInterface $command Command to create an iterator for
     *
     * @return bool
     */
    public function canBuild(CommandInterface $command);
}
<?php

namespace Guzzle\Service\Resource;

use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Service\Command\CommandInterface;

/**
 * Factory that utilizes multiple factories for creating iterators
 */
class CompositeResourceIteratorFactory implements ResourceIteratorFactoryInterface
{
    /** @var array Array of factories */
    protected $factories;

    /** @param array $factories Array of factories used to instantiate iterators */
    public function __construct(array $factories)
    {
        $this->factories = $factories;
    }

    public function build(CommandInterface $command, array $options = array())
    {
        if (!($factory = $this->getFactory($command))) {
            throw new InvalidArgumentException('Iterator was not found for ' . $command->getName());
        }

        return $factory->build($command, $options);
    }

    public function canBuild(CommandInterface $command)
    {
        return $this->getFactory($command) !== false;
    }

    /**
     * Add a factory to the composite factory
     *
     * @param ResourceIteratorFactoryInterface $factory Factory to add
     *
     * @return self
     */
    public function addFactory(ResourceIteratorFactoryInterface $factory)
    {
        $this->factories[] = $factory;

        return $this;
    }

    /**
     * Get the factory that matches the command object
     *
     * @param CommandInterface $command Command retrieving the iterator for
     *
     * @return ResourceIteratorFactoryInterface|bool
     */
    protected function getFactory(CommandInterface $command)
    {
        foreach ($this->factories as $factory) {
            if ($factory->canBuild($command)) {
                return $factory;
            }
        }

        return false;
    }
}
<?php

namespace Guzzle\Service\Resource;

use Guzzle\Service\Command\CommandInterface;

/**
 * Resource iterator factory used when explicitly mapping strings to iterator classes
 */
class MapResourceIteratorFactory extends AbstractResourceIteratorFactory
{
    /** @var array Associative array mapping iterator names to class names */
    protected $map;

    /** @param array $map Associative array mapping iterator names to class names */
    public function __construct(array $map)
    {
        $this->map = $map;
    }

    public function getClassName(CommandInterface $command)
    {
        $className = $command->getName();

        if (isset($this->map[$className])) {
            return $this->map[$className];
        } elseif (isset($this->map['*'])) {
            // If a wildcard was added, then always use that
            return $this->map['*'];
        }

        return null;
    }
}
<?php

namespace Guzzle\Service\Resource;

use Guzzle\Common\HasDispatcherInterface;
use Guzzle\Common\ToArrayInterface;

/**
 * Iterates over a paginated resource using subsequent requests in order to retrieve the entire matching result set
 */
interface ResourceIteratorInterface extends ToArrayInterface, HasDispatcherInterface, \Iterator, \Countable
{
    /**
     * Retrieve the NextToken that can be used in other iterators.
     *
     * @return string Returns a NextToken
     */
    public function getNextToken();

    /**
     * Attempt to limit the total number of resources returned by the iterator.
     *
     * You may still receive more items than you specify. Set to 0 to specify no limit.
     *
     * @param int $limit Limit amount
     *
     * @return ResourceIteratorInterface
     */
    public function setLimit($limit);

    /**
     * Attempt to limit the total number of resources retrieved per request by  the iterator.
     *
     * The iterator may return more than you specify in the page size argument depending on the service and underlying
     * command implementation.  Set to 0 to specify no page size limitation.
     *
     * @param int $pageSize Limit amount
     *
     * @return ResourceIteratorInterface
     */
    public function setPageSize($pageSize);

    /**
     * Get a data option from the iterator
     *
     * @param string $key Key of the option to retrieve
     *
     * @return mixed|null Returns NULL if not set or the value if set
     */
    public function get($key);

    /**
     * Set a data option on the iterator
     *
     * @param string $key   Key of the option to set
     * @param mixed  $value Value to set for the option
     *
     * @return ResourceIteratorInterface
     */
    public function set($key, $value);
}
<?php

namespace Guzzle\Service\Resource;

use Guzzle\Inflection\InflectorInterface;
use Guzzle\Inflection\Inflector;
use Guzzle\Service\Command\CommandInterface;

/**
 * Factory for creating {@see ResourceIteratorInterface} objects using a convention of storing iterator classes under a
 * root namespace using the name of a {@see CommandInterface} object as a convention for determining the name of an
 * iterator class. The command name is converted to CamelCase and Iterator is appended (e.g. abc_foo => AbcFoo).
 */
class ResourceIteratorClassFactory extends AbstractResourceIteratorFactory
{
    /** @var array List of namespaces used to look for classes */
    protected $namespaces;

    /** @var InflectorInterface Inflector used to determine class names */
    protected $inflector;

    /**
     * @param string|array       $namespaces List of namespaces for iterator objects
     * @param InflectorInterface $inflector  Inflector used to resolve class names
     */
    public function __construct($namespaces = array(), InflectorInterface $inflector = null)
    {
        $this->namespaces = (array) $namespaces;
        $this->inflector = $inflector ?: Inflector::getDefault();
    }

    /**
     * Registers a namespace to check for Iterators
     *
     * @param string $namespace Namespace which contains Iterator classes
     *
     * @return self
     */
    public function registerNamespace($namespace)
    {
        array_unshift($this->namespaces, $namespace);

        return $this;
    }

    protected function getClassName(CommandInterface $command)
    {
        $iteratorName = $this->inflector->camel($command->getName()) . 'Iterator';

        // Determine the name of the class to load
        foreach ($this->namespaces as $namespace) {
            $potentialClassName = $namespace . '\\' . $iteratorName;
            if (class_exists($potentialClassName)) {
                return $potentialClassName;
            }
        }

        return false;
    }
}
<?php

namespace Guzzle\Service\Resource;

use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Service\Command\CommandInterface;

/**
 * Abstract resource iterator factory implementation
 */
abstract class AbstractResourceIteratorFactory implements ResourceIteratorFactoryInterface
{
    public function build(CommandInterface $command, array $options = array())
    {
        if (!$this->canBuild($command)) {
            throw new InvalidArgumentException('Iterator was not found for ' . $command->getName());
        }

        $className = $this->getClassName($command);

        return new $className($command, $options);
    }

    public function canBuild(CommandInterface $command)
    {
        return (bool) $this->getClassName($command);
    }

    /**
     * Get the name of the class to instantiate for the command
     *
     * @param CommandInterface $command Command that is associated with the iterator
     *
     * @return string
     */
    abstract protected function getClassName(CommandInterface $command);
}
<?php

namespace Guzzle\Service\Resource;

use Guzzle\Common\Collection;
use Guzzle\Service\Description\Parameter;

/**
 * Default model created when commands create service description model responses
 */
class Model extends Collection
{
    /** @var Parameter Structure of the model */
    protected $structure;

    /**
     * @param array     $data      Data contained by the model
     * @param Parameter $structure The structure of the model
     */
    public function __construct(array $data = array(), Parameter $structure = null)
    {
        $this->data = $data;
        $this->structure = $structure;
    }

    /**
     * Get the structure of the model
     *
     * @return Parameter
     */
    public function getStructure()
    {
        return $this->structure ?: new Parameter();
    }

    /**
     * Provides debug information about the model object
     *
     * @return string
     */
    public function __toString()
    {
        $output = 'Debug output of ';
        if ($this->structure) {
            $output .= $this->structure->getName() . ' ';
        }
        $output .= 'model';
        $output = str_repeat('=', strlen($output)) . "\n" . $output . "\n" . str_repeat('=', strlen($output)) . "\n\n";
        $output .= "Model data\n-----------\n\n";
        $output .= "This data can be retrieved from the model object using the get() method of the model "
            . "(e.g. \$model->get(\$key)) or accessing the model like an associative array (e.g. \$model['key']).\n\n";
        $lines = array_slice(explode("\n", trim(print_r($this->toArray(), true))), 2, -1);
        $output .=  implode("\n", $lines);

        if ($this->structure) {
            $output .= "\n\nModel structure\n---------------\n\n";
            $output .= "The following JSON document defines how the model was parsed from an HTTP response into the "
                . "associative array structure you see above.\n\n";
            $output .= '  ' . json_encode($this->structure->toArray()) . "\n\n";
        }

        return $output . "\n";
    }
}
<?php

namespace Guzzle\Service\Resource;

use Guzzle\Common\AbstractHasDispatcher;
use Guzzle\Service\Command\CommandInterface;

abstract class ResourceIterator extends AbstractHasDispatcher implements ResourceIteratorInterface
{
    /** @var CommandInterface Command used to send requests */
    protected $command;

    /** @var CommandInterface First sent command */
    protected $originalCommand;

    /** @var array Currently loaded resources */
    protected $resources;

    /** @var int Total number of resources that have been retrieved */
    protected $retrievedCount = 0;

    /** @var int Total number of resources that have been iterated */
    protected $iteratedCount = 0;

    /** @var string NextToken/Marker for a subsequent request */
    protected $nextToken = false;

    /** @var int Maximum number of resources to fetch per request */
    protected $pageSize;

    /** @var int Maximum number of resources to retrieve in total */
    protected $limit;

    /** @var int Number of requests sent */
    protected $requestCount = 0;

    /** @var array Initial data passed to the constructor */
    protected $data = array();

    /** @var bool Whether or not the current value is known to be invalid */
    protected $invalid;

    public static function getAllEvents()
    {
        return array(
            // About to issue another command to get more results
            'resource_iterator.before_send',
            // Issued another command to get more results
            'resource_iterator.after_send'
        );
    }

    /**
     * @param CommandInterface $command Initial command used for iteration
     * @param array            $data    Associative array of additional parameters. You may specify any number of custom
     *     options for an iterator. Among these options, you may also specify the following values:
     *     - limit: Attempt to limit the maximum number of resources to this amount
     *     - page_size: Attempt to retrieve this number of resources per request
     */
    public function __construct(CommandInterface $command, array $data = array())
    {
        // Clone the command to keep track of the originating command for rewind
        $this->originalCommand = $command;

        // Parse options from the array of options
        $this->data = $data;
        $this->limit = array_key_exists('limit', $data) ? $data['limit'] : 0;
        $this->pageSize = array_key_exists('page_size', $data) ? $data['page_size'] : false;
    }

    /**
     * Get all of the resources as an array (Warning: this could issue a large number of requests)
     *
     * @return array
     */
    public function toArray()
    {
        return iterator_to_array($this, false);
    }

    public function setLimit($limit)
    {
        $this->limit = $limit;
        $this->resetState();

        return $this;
    }

    public function setPageSize($pageSize)
    {
        $this->pageSize = $pageSize;
        $this->resetState();

        return $this;
    }

    /**
     * Get an option from the iterator
     *
     * @param string $key Key of the option to retrieve
     *
     * @return mixed|null Returns NULL if not set or the value if set
     */
    public function get($key)
    {
        return array_key_exists($key, $this->data) ? $this->data[$key] : null;
    }

    /**
     * Set an option on the iterator
     *
     * @param string $key   Key of the option to set
     * @param mixed  $value Value to set for the option
     *
     * @return ResourceIterator
     */
    public function set($key, $value)
    {
        $this->data[$key] = $value;

        return $this;
    }

    public function current()
    {
        return $this->resources ? current($this->resources) : false;
    }

    public function key()
    {
        return max(0, $this->iteratedCount - 1);
    }

    public function count()
    {
        return $this->retrievedCount;
    }

    /**
     * Get the total number of requests sent
     *
     * @return int
     */
    public function getRequestCount()
    {
        return $this->requestCount;
    }

    /**
     * Rewind the Iterator to the first element and send the original command
     */
    public function rewind()
    {
        // Use the original command
        $this->command = clone $this->originalCommand;
        $this->resetState();
        $this->next();
    }

    public function valid()
    {
        return !$this->invalid && (!$this->resources || $this->current() || $this->nextToken)
            && (!$this->limit || $this->iteratedCount < $this->limit + 1);
    }

    public function next()
    {
        $this->iteratedCount++;

        // Check if a new set of resources needs to be retrieved
        $sendRequest = false;
        if (!$this->resources) {
            $sendRequest = true;
        } else {
            // iterate over the internal array
            $current = next($this->resources);
            $sendRequest = $current === false && $this->nextToken && (!$this->limit || $this->iteratedCount < $this->limit + 1);
        }

        if ($sendRequest) {

            $this->dispatch('resource_iterator.before_send', array(
                'iterator'  => $this,
                'resources' => $this->resources
            ));

            // Get a new command object from the original command
            $this->command = clone $this->originalCommand;
            // Send a request and retrieve the newly loaded resources
            $this->resources = $this->sendRequest();
            $this->requestCount++;

            // If no resources were found, then the last request was not needed
            // and iteration must stop
            if (empty($this->resources)) {
                $this->invalid = true;
            } else {
                // Add to the number of retrieved resources
                $this->retrievedCount += count($this->resources);
                // Ensure that we rewind to the beginning of the array
                reset($this->resources);
            }

            $this->dispatch('resource_iterator.after_send', array(
                'iterator'  => $this,
                'resources' => $this->resources
            ));
        }
    }

    /**
     * Retrieve the NextToken that can be used in other iterators.
     *
     * @return string Returns a NextToken
     */
    public function getNextToken()
    {
        return $this->nextToken;
    }

    /**
     * Returns the value that should be specified for the page size for a request that will maintain any hard limits,
     * but still honor the specified pageSize if the number of items retrieved + pageSize < hard limit
     *
     * @return int Returns the page size of the next request.
     */
    protected function calculatePageSize()
    {
        if ($this->limit && $this->iteratedCount + $this->pageSize > $this->limit) {
            return 1 + ($this->limit - $this->iteratedCount);
        }

        return (int) $this->pageSize;
    }

    /**
     * Reset the internal state of the iterator without triggering a rewind()
     */
    protected function resetState()
    {
        $this->iteratedCount = 0;
        $this->retrievedCount = 0;
        $this->nextToken = false;
        $this->resources = null;
        $this->invalid = false;
    }

    /**
     * Send a request to retrieve the next page of results. Hook for subclasses to implement.
     *
     * @return array Returns the newly loaded resources
     */
    abstract protected function sendRequest();
}
<?php

namespace Guzzle\Service\Resource;

use Guzzle\Common\AbstractHasDispatcher;
use Guzzle\Batch\BatchBuilder;
use Guzzle\Batch\BatchSizeDivisor;
use Guzzle\Batch\BatchClosureTransfer;
use Guzzle\Common\Version;

/**
 * Apply a callback to the contents of a {@see ResourceIteratorInterface}
 * @deprecated Will be removed in a future version and is no longer maintained. Use the Batch\ abstractions instead.
 * @codeCoverageIgnore
 */
class ResourceIteratorApplyBatched extends AbstractHasDispatcher
{
    /** @var callable|array */
    protected $callback;

    /** @var ResourceIteratorInterface */
    protected $iterator;

    /** @var integer Total number of sent batches */
    protected $batches = 0;

    /** @var int Total number of iterated resources */
    protected $iterated = 0;

    public static function getAllEvents()
    {
        return array(
            // About to send a batch of requests to the callback
            'iterator_batch.before_batch',
            // Finished sending a batch of requests to the callback
            'iterator_batch.after_batch',
            // Created the batch object
            'iterator_batch.created_batch'
        );
    }

    /**
     * @param ResourceIteratorInterface $iterator Resource iterator to apply a callback to
     * @param array|callable            $callback Callback method accepting the resource iterator
     *                                            and an array of the iterator's current resources
     */
    public function __construct(ResourceIteratorInterface $iterator, $callback)
    {
        $this->iterator = $iterator;
        $this->callback = $callback;
        Version::warn(__CLASS__ . ' is deprecated');
    }

    /**
     * Apply the callback to the contents of the resource iterator
     *
     * @param int $perBatch The number of records to group per batch transfer
     *
     * @return int Returns the number of iterated resources
     */
    public function apply($perBatch = 50)
    {
        $this->iterated = $this->batches = $batches = 0;
        $that = $this;
        $it = $this->iterator;
        $callback = $this->callback;

        $batch = BatchBuilder::factory()
            ->createBatchesWith(new BatchSizeDivisor($perBatch))
            ->transferWith(new BatchClosureTransfer(function (array $batch) use ($that, $callback, &$batches, $it) {
                $batches++;
                $that->dispatch('iterator_batch.before_batch', array('iterator' => $it, 'batch' => $batch));
                call_user_func_array($callback, array($it, $batch));
                $that->dispatch('iterator_batch.after_batch', array('iterator' => $it, 'batch' => $batch));
            }))
            ->autoFlushAt($perBatch)
            ->build();

        $this->dispatch('iterator_batch.created_batch', array('batch' => $batch));

        foreach ($this->iterator as $resource) {
            $this->iterated++;
            $batch->add($resource);
        }

        $batch->flush();
        $this->batches = $batches;

        return $this->iterated;
    }

    /**
     * Get the total number of batches sent
     *
     * @return int
     */
    public function getBatchCount()
    {
        return $this->batches;
    }

    /**
     * Get the total number of iterated resources
     *
     * @return int
     */
    public function getIteratedCount()
    {
        return $this->iterated;
    }
}
<?php

namespace Guzzle\Service\Description;

/**
 * A ServiceDescription stores service information based on a service document
 */
interface ServiceDescriptionInterface extends \Serializable
{
    /**
     * Get the basePath/baseUrl of the description
     *
     * @return string
     */
    public function getBaseUrl();

    /**
     * Get the API operations of the service
     *
     * @return array Returns an array of {@see OperationInterface} objects
     */
    public function getOperations();

    /**
     * Check if the service has an operation by name
     *
     * @param string $name Name of the operation to check
     *
     * @return bool
     */
    public function hasOperation($name);

    /**
     * Get an API operation by name
     *
     * @param string $name Name of the command
     *
     * @return OperationInterface|null
     */
    public function getOperation($name);

    /**
     * Get a specific model from the description
     *
     * @param string $id ID of the model
     *
     * @return Parameter|null
     */
    public function getModel($id);

    /**
     * Get all service description models
     *
     * @return array
     */
    public function getModels();

    /**
     * Check if the description has a specific model by name
     *
     * @param string $id ID of the model
     *
     * @return bool
     */
    public function hasModel($id);

    /**
     * Get the API version of the service
     *
     * @return string
     */
    public function getApiVersion();

    /**
     * Get the name of the API
     *
     * @return string
     */
    public function getName();

    /**
     * Get a summary of the purpose of the API
     *
     * @return string
     */
    public function getDescription();

    /**
     * Get arbitrary data from the service description that is not part of the Guzzle spec
     *
     * @param string $key Data key to retrieve
     *
     * @return null|mixed
     */
    public function getData($key);

    /**
     * Set arbitrary data on the service description
     *
     * @param string $key   Data key to set
     * @param mixed  $value Value to set
     *
     * @return self
     */
    public function setData($key, $value);
}
<?php

namespace Guzzle\Service\Description;

use Guzzle\Common\Exception\InvalidArgumentException;

/**
 * API parameter object used with service descriptions
 */
class Parameter
{
    protected $name;
    protected $description;
    protected $serviceDescription;
    protected $type;
    protected $required;
    protected $enum;
    protected $pattern;
    protected $minimum;
    protected $maximum;
    protected $minLength;
    protected $maxLength;
    protected $minItems;
    protected $maxItems;
    protected $default;
    protected $static;
    protected $instanceOf;
    protected $filters;
    protected $location;
    protected $sentAs;
    protected $data;
    protected $properties = array();
    protected $additionalProperties;
    protected $items;
    protected $parent;
    protected $ref;
    protected $format;
    protected $propertiesCache = null;

    /**
     * Create a new Parameter using an associative array of data. The array can contain the following information:
     * - name:          (string) Unique name of the parameter
     * - type:          (string|array) Type of variable (string, number, integer, boolean, object, array, numeric,
     *                  null, any). Types are using for validation and determining the structure of a parameter. You
     *                  can use a union type by providing an array of simple types. If one of the union types matches
     *                  the provided value, then the value is valid.
     * - instanceOf:    (string) When the type is an object, you can specify the class that the object must implement
     * - required:      (bool) Whether or not the parameter is required
     * - default:       (mixed) Default value to use if no value is supplied
     * - static:        (bool) Set to true to specify that the parameter value cannot be changed from the default
     * - description:   (string) Documentation of the parameter
     * - location:      (string) The location of a request used to apply a parameter. Custom locations can be registered
     *                  with a command, but the defaults are uri, query, header, body, json, xml, postField, postFile.
     * - sentAs:        (string) Specifies how the data being modeled is sent over the wire. For example, you may wish
     *                  to include certain headers in a response model that have a normalized casing of FooBar, but the
     *                  actual header is x-foo-bar. In this case, sentAs would be set to x-foo-bar.
     * - filters:       (array) Array of static method names to to run a parameter value through. Each value in the
     *                  array must be a string containing the full class path to a static method or an array of complex
     *                  filter information. You can specify static methods of classes using the full namespace class
     *                  name followed by '::' (e.g. Foo\Bar::baz()). Some filters require arguments in order to properly
     *                  filter a value. For complex filters, use a hash containing a 'method' key pointing to a static
     *                  method, and an 'args' key containing an array of positional arguments to pass to the method.
     *                  Arguments can contain keywords that are replaced when filtering a value: '@value' is replaced
     *                  with the value being validated, '@api' is replaced with the Parameter object.
     * - properties:    When the type is an object, you can specify nested parameters
     * - additionalProperties: (array) This attribute defines a schema for all properties that are not explicitly
     *                  defined in an object type definition. If specified, the value MUST be a schema or a boolean. If
     *                  false is provided, no additional properties are allowed beyond the properties defined in the
     *                  schema. The default value is an empty schema which allows any value for additional properties.
     * - items:         This attribute defines the allowed items in an instance array, and MUST be a schema or an array
     *                  of schemas. The default value is an empty schema which allows any value for items in the
     *                  instance array.
     *                  When this attribute value is a schema and the instance value is an array, then all the items
     *                  in the array MUST be valid according to the schema.
     * - pattern:       When the type is a string, you can specify the regex pattern that a value must match
     * - enum:          When the type is a string, you can specify a list of acceptable values
     * - minItems:      (int) Minimum number of items allowed in an array
     * - maxItems:      (int) Maximum number of items allowed in an array
     * - minLength:     (int) Minimum length of a string
     * - maxLength:     (int) Maximum length of a string
     * - minimum:       (int) Minimum value of an integer
     * - maximum:       (int) Maximum value of an integer
     * - data:          (array) Any additional custom data to use when serializing, validating, etc
     * - format:        (string) Format used to coax a value into the correct format when serializing or unserializing.
     *                  You may specify either an array of filters OR a format, but not both.
     *                  Supported values: date-time, date, time, timestamp, date-time-http
     * - $ref:          (string) String referencing a service description model. The parameter is replaced by the
     *                  schema contained in the model.
     *
     * @param array                       $data        Array of data as seen in service descriptions
     * @param ServiceDescriptionInterface $description Service description used to resolve models if $ref tags are found
     *
     * @throws InvalidArgumentException
     */
    public function __construct(array $data = array(), ServiceDescriptionInterface $description = null)
    {
        if ($description) {
            if (isset($data['$ref'])) {
                if ($model = $description->getModel($data['$ref'])) {
                    $data = $model->toArray() + $data;
                }
            } elseif (isset($data['extends'])) {
                // If this parameter extends from another parameter then start with the actual data
                // union in the parent's data (e.g. actual supersedes parent)
                if ($extends = $description->getModel($data['extends'])) {
                    $data += $extends->toArray();
                }
            }
        }

        // Pull configuration data into the parameter
        foreach ($data as $key => $value) {
            $this->{$key} = $value;
        }

        $this->serviceDescription = $description;
        $this->required = (bool) $this->required;
        $this->data = (array) $this->data;

        if ($this->filters) {
            $this->setFilters((array) $this->filters);
        }

        if ($this->type == 'object' && $this->additionalProperties === null) {
            $this->additionalProperties = true;
        }
    }

    /**
     * Convert the object to an array
     *
     * @return array
     */
    public function toArray()
    {
        static $checks = array('required', 'description', 'static', 'type', 'format', 'instanceOf', 'location', 'sentAs',
            'pattern', 'minimum', 'maximum', 'minItems', 'maxItems', 'minLength', 'maxLength', 'data', 'enum',
            'filters');

        $result = array();

        // Anything that is in the `Items` attribute of an array *must* include it's name if available
        if ($this->parent instanceof self && $this->parent->getType() == 'array' && isset($this->name)) {
            $result['name'] = $this->name;
        }

        foreach ($checks as $c) {
            if ($value = $this->{$c}) {
                $result[$c] = $value;
            }
        }

        if ($this->default !== null) {
            $result['default'] = $this->default;
        }

        if ($this->items !== null) {
            $result['items'] = $this->getItems()->toArray();
        }

        if ($this->additionalProperties !== null) {
            $result['additionalProperties'] = $this->getAdditionalProperties();
            if ($result['additionalProperties'] instanceof self) {
                $result['additionalProperties'] = $result['additionalProperties']->toArray();
            }
        }

        if ($this->type == 'object' && $this->properties) {
            $result['properties'] = array();
            foreach ($this->getProperties() as $name => $property) {
                $result['properties'][$name] = $property->toArray();
            }
        }

        return $result;
    }

    /**
     * Get the default or static value of the command based on a value
     *
     * @param string $value Value that is currently set
     *
     * @return mixed Returns the value, a static value if one is present, or a default value
     */
    public function getValue($value)
    {
        if ($this->static || ($this->default !== null && $value === null)) {
            return $this->default;
        }

        return $value;
    }

    /**
     * Run a value through the filters OR format attribute associated with the parameter
     *
     * @param mixed $value Value to filter
     *
     * @return mixed Returns the filtered value
     */
    public function filter($value)
    {
        // Formats are applied exclusively and supersed filters
        if ($this->format) {
            return SchemaFormatter::format($this->format, $value);
        }

        // Convert Boolean values
        if ($this->type == 'boolean' && !is_bool($value)) {
            $value = filter_var($value, FILTER_VALIDATE_BOOLEAN);
        }

        // Apply filters to the value
        if ($this->filters) {
            foreach ($this->filters as $filter) {
                if (is_array($filter)) {
                    // Convert complex filters that hold value place holders
                    foreach ($filter['args'] as &$data) {
                        if ($data == '@value') {
                            $data = $value;
                        } elseif ($data == '@api') {
                            $data = $this;
                        }
                    }
                    $value = call_user_func_array($filter['method'], $filter['args']);
                } else {
                    $value = call_user_func($filter, $value);
                }
            }
        }

        return $value;
    }

    /**
     * Get the name of the parameter
     *
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Get the key of the parameter, where sentAs will supersede name if it is set
     *
     * @return string
     */
    public function getWireName()
    {
        return $this->sentAs ?: $this->name;
    }

    /**
     * Set the name of the parameter
     *
     * @param string $name Name to set
     *
     * @return self
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get the type(s) of the parameter
     *
     * @return string|array
     */
    public function getType()
    {
        return $this->type;
    }

    /**
     * Set the type(s) of the parameter
     *
     * @param string|array $type Type of parameter or array of simple types used in a union
     *
     * @return self
     */
    public function setType($type)
    {
        $this->type = $type;

        return $this;
    }

    /**
     * Get if the parameter is required
     *
     * @return bool
     */
    public function getRequired()
    {
        return $this->required;
    }

    /**
     * Set if the parameter is required
     *
     * @param bool $isRequired Whether or not the parameter is required
     *
     * @return self
     */
    public function setRequired($isRequired)
    {
        $this->required = (bool) $isRequired;

        return $this;
    }

    /**
     * Get the default value of the parameter
     *
     * @return string|null
     */
    public function getDefault()
    {
        return $this->default;
    }

    /**
     * Set the default value of the parameter
     *
     * @param string|null $default Default value to set
     *
     * @return self
     */
    public function setDefault($default)
    {
        $this->default = $default;

        return $this;
    }

    /**
     * Get the description of the parameter
     *
     * @return string|null
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * Set the description of the parameter
     *
     * @param string $description Description
     *
     * @return self
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

    /**
     * Get the minimum acceptable value for an integer
     *
     * @return int|null
     */
    public function getMinimum()
    {
        return $this->minimum;
    }

    /**
     * Set the minimum acceptable value for an integer
     *
     * @param int|null $min Minimum
     *
     * @return self
     */
    public function setMinimum($min)
    {
        $this->minimum = $min;

        return $this;
    }

    /**
     * Get the maximum acceptable value for an integer
     *
     * @return int|null
     */
    public function getMaximum()
    {
        return $this->maximum;
    }

    /**
     * Set the maximum acceptable value for an integer
     *
     * @param int $max Maximum
     *
     * @return self
     */
    public function setMaximum($max)
    {
        $this->maximum = $max;

        return $this;
    }

    /**
     * Get the minimum allowed length of a string value
     *
     * @return int
     */
    public function getMinLength()
    {
        return $this->minLength;
    }

    /**
     * Set the minimum allowed length of a string value
     *
     * @param int|null $min Minimum
     *
     * @return self
     */
    public function setMinLength($min)
    {
        $this->minLength = $min;

        return $this;
    }

    /**
     * Get the maximum allowed length of a string value
     *
     * @return int|null
     */
    public function getMaxLength()
    {
        return $this->maxLength;
    }

    /**
     * Set the maximum allowed length of a string value
     *
     * @param int $max Maximum length
     *
     * @return self
     */
    public function setMaxLength($max)
    {
        $this->maxLength = $max;

        return $this;
    }

    /**
     * Get the maximum allowed number of items in an array value
     *
     * @return int|null
     */
    public function getMaxItems()
    {
        return $this->maxItems;
    }

    /**
     * Set the maximum allowed number of items in an array value
     *
     * @param int $max Maximum
     *
     * @return self
     */
    public function setMaxItems($max)
    {
        $this->maxItems = $max;

        return $this;
    }

    /**
     * Get the minimum allowed number of items in an array value
     *
     * @return int
     */
    public function getMinItems()
    {
        return $this->minItems;
    }

    /**
     * Set the minimum allowed number of items in an array value
     *
     * @param int|null $min Minimum
     *
     * @return self
     */
    public function setMinItems($min)
    {
        $this->minItems = $min;

        return $this;
    }

    /**
     * Get the location of the parameter
     *
     * @return string|null
     */
    public function getLocation()
    {
        return $this->location;
    }

    /**
     * Set the location of the parameter
     *
     * @param string|null $location Location of the parameter
     *
     * @return self
     */
    public function setLocation($location)
    {
        $this->location = $location;

        return $this;
    }

    /**
     * Get the sentAs attribute of the parameter that used with locations to sentAs an attribute when it is being
     * applied to a location.
     *
     * @return string|null
     */
    public function getSentAs()
    {
        return $this->sentAs;
    }

    /**
     * Set the sentAs attribute
     *
     * @param string|null $name Name of the value as it is sent over the wire
     *
     * @return self
     */
    public function setSentAs($name)
    {
        $this->sentAs = $name;

        return $this;
    }

    /**
     * Retrieve a known property from the parameter by name or a data property by name. When not specific name value
     * is specified, all data properties will be returned.
     *
     * @param string|null $name Specify a particular property name to retrieve
     *
     * @return array|mixed|null
     */
    public function getData($name = null)
    {
        if (!$name) {
            return $this->data;
        }

        if (isset($this->data[$name])) {
            return $this->data[$name];
        } elseif (isset($this->{$name})) {
            return $this->{$name};
        }

        return null;
    }

    /**
     * Set the extra data properties of the parameter or set a specific extra property
     *
     * @param string|array|null $nameOrData The name of a specific extra to set or an array of extras to set
     * @param mixed|null        $data       When setting a specific extra property, specify the data to set for it
     *
     * @return self
     */
    public function setData($nameOrData, $data = null)
    {
        if (is_array($nameOrData)) {
            $this->data = $nameOrData;
        } else {
            $this->data[$nameOrData] = $data;
        }

        return $this;
    }

    /**
     * Get whether or not the default value can be changed
     *
     * @return mixed|null
     */
    public function getStatic()
    {
        return $this->static;
    }

    /**
     * Set to true if the default value cannot be changed
     *
     * @param bool $static True or false
     *
     * @return self
     */
    public function setStatic($static)
    {
        $this->static = (bool) $static;

        return $this;
    }

    /**
     * Get an array of filters used by the parameter
     *
     * @return array
     */
    public function getFilters()
    {
        return $this->filters ?: array();
    }

    /**
     * Set the array of filters used by the parameter
     *
     * @param array $filters Array of functions to use as filters
     *
     * @return self
     */
    public function setFilters(array $filters)
    {
        $this->filters = array();
        foreach ($filters as $filter) {
            $this->addFilter($filter);
        }

        return $this;
    }

    /**
     * Add a filter to the parameter
     *
     * @param string|array $filter Method to filter the value through
     *
     * @return self
     * @throws InvalidArgumentException
     */
    public function addFilter($filter)
    {
        if (is_array($filter)) {
            if (!isset($filter['method'])) {
                throw new InvalidArgumentException('A [method] value must be specified for each complex filter');
            }
        }

        if (!$this->filters) {
            $this->filters = array($filter);
        } else {
            $this->filters[] = $filter;
        }

        return $this;
    }

    /**
     * Get the parent object (an {@see OperationInterface} or {@see Parameter}
     *
     * @return OperationInterface|Parameter|null
     */
    public function getParent()
    {
        return $this->parent;
    }

    /**
     * Set the parent object of the parameter
     *
     * @param OperationInterface|Parameter|null $parent Parent container of the parameter
     *
     * @return self
     */
    public function setParent($parent)
    {
        $this->parent = $parent;

        return $this;
    }

    /**
     * Get the properties of the parameter
     *
     * @return array
     */
    public function getProperties()
    {
        if (!$this->propertiesCache) {
            $this->propertiesCache = array();
            foreach (array_keys($this->properties) as $name) {
                $this->propertiesCache[$name] = $this->getProperty($name);
            }
        }

        return $this->propertiesCache;
    }

    /**
     * Get a specific property from the parameter
     *
     * @param string $name Name of the property to retrieve
     *
     * @return null|Parameter
     */
    public function getProperty($name)
    {
        if (!isset($this->properties[$name])) {
            return null;
        }

        if (!($this->properties[$name] instanceof self)) {
            $this->properties[$name]['name'] = $name;
            $this->properties[$name] = new static($this->properties[$name], $this->serviceDescription);
            $this->properties[$name]->setParent($this);
        }

        return $this->properties[$name];
    }

    /**
     * Remove a property from the parameter
     *
     * @param string $name Name of the property to remove
     *
     * @return self
     */
    public function removeProperty($name)
    {
        unset($this->properties[$name]);
        $this->propertiesCache = null;

        return $this;
    }

    /**
     * Add a property to the parameter
     *
     * @param Parameter $property Properties to set
     *
     * @return self
     */
    public function addProperty(Parameter $property)
    {
        $this->properties[$property->getName()] = $property;
        $property->setParent($this);
        $this->propertiesCache = null;

        return $this;
    }

    /**
     * Get the additionalProperties value of the parameter
     *
     * @return bool|Parameter|null
     */
    public function getAdditionalProperties()
    {
        if (is_array($this->additionalProperties)) {
            $this->additionalProperties = new static($this->additionalProperties, $this->serviceDescription);
            $this->additionalProperties->setParent($this);
        }

        return $this->additionalProperties;
    }

    /**
     * Set the additionalProperties value of the parameter
     *
     * @param bool|Parameter|null $additional Boolean to allow any, an Parameter to specify a schema, or false to disallow
     *
     * @return self
     */
    public function setAdditionalProperties($additional)
    {
        $this->additionalProperties = $additional;

        return $this;
    }

    /**
     * Set the items data of the parameter
     *
     * @param Parameter|null $items Items to set
     *
     * @return self
     */
    public function setItems(Parameter $items = null)
    {
        if ($this->items = $items) {
            $this->items->setParent($this);
        }

        return $this;
    }

    /**
     * Get the item data of the parameter
     *
     * @return Parameter|null
     */
    public function getItems()
    {
        if (is_array($this->items)) {
            $this->items = new static($this->items, $this->serviceDescription);
            $this->items->setParent($this);
        }

        return $this->items;
    }

    /**
     * Get the class that the parameter must implement
     *
     * @return null|string
     */
    public function getInstanceOf()
    {
        return $this->instanceOf;
    }

    /**
     * Set the class that the parameter must be an instance of
     *
     * @param string|null $instanceOf Class or interface name
     *
     * @return self
     */
    public function setInstanceOf($instanceOf)
    {
        $this->instanceOf = $instanceOf;

        return $this;
    }

    /**
     * Get the enum of strings that are valid for the parameter
     *
     * @return array|null
     */
    public function getEnum()
    {
        return $this->enum;
    }

    /**
     * Set the enum of strings that are valid for the parameter
     *
     * @param array|null $enum Array of strings or null
     *
     * @return self
     */
    public function setEnum(array $enum = null)
    {
        $this->enum = $enum;

        return $this;
    }

    /**
     * Get the regex pattern that must match a value when the value is a string
     *
     * @return string
     */
    public function getPattern()
    {
        return $this->pattern;
    }

    /**
     * Set the regex pattern that must match a value when the value is a string
     *
     * @param string $pattern Regex pattern
     *
     * @return self
     */
    public function setPattern($pattern)
    {
        $this->pattern = $pattern;

        return $this;
    }

    /**
     * Get the format attribute of the schema
     *
     * @return string
     */
    public function getFormat()
    {
        return $this->format;
    }

    /**
     * Set the format attribute of the schema
     *
     * @param string $format Format to set (e.g. date, date-time, timestamp, time, date-time-http)
     *
     * @return self
     */
    public function setFormat($format)
    {
        $this->format = $format;

        return $this;
    }
}
<?php

namespace Guzzle\Service\Description;

use Guzzle\Service\AbstractConfigLoader;
use Guzzle\Service\Exception\DescriptionBuilderException;

/**
 * Loader for service descriptions
 */
class ServiceDescriptionLoader extends AbstractConfigLoader
{
    protected function build($config, array $options)
    {
        $operations = array();
        if (!empty($config['operations'])) {
            foreach ($config['operations'] as $name => $op) {
                $name = $op['name'] = isset($op['name']) ? $op['name'] : $name;
                // Extend other operations
                if (!empty($op['extends'])) {
                    $this->resolveExtension($name, $op, $operations);
                }
                $op['parameters'] = isset($op['parameters']) ? $op['parameters'] : array();
                $operations[$name] = $op;
            }
        }

        return new ServiceDescription(array(
            'apiVersion'  => isset($config['apiVersion']) ? $config['apiVersion'] : null,
            'baseUrl'     => isset($config['baseUrl']) ? $config['baseUrl'] : null,
            'description' => isset($config['description']) ? $config['description'] : null,
            'operations'  => $operations,
            'models'      => isset($config['models']) ? $config['models'] : null
        ) + $config);
    }

    /**
     * @param string $name       Name of the operation
     * @param array  $op         Operation value array
     * @param array  $operations Currently loaded operations
     * @throws DescriptionBuilderException when extending a non-existent operation
     */
    protected function resolveExtension($name, array &$op, array &$operations)
    {
        $resolved = array();
        $original = empty($op['parameters']) ? false: $op['parameters'];
        $hasClass = !empty($op['class']);
        foreach ((array) $op['extends'] as $extendedCommand) {
            if (empty($operations[$extendedCommand])) {
                throw new DescriptionBuilderException("{$name} extends missing operation {$extendedCommand}");
            }
            $toArray = $operations[$extendedCommand];
            $resolved = empty($resolved)
                ? $toArray['parameters']
                : array_merge($resolved, $toArray['parameters']);

            $op = $op + $toArray;
            if (!$hasClass && isset($toArray['class'])) {
                $op['class'] = $toArray['class'];
            }
        }
        $op['parameters'] = $original ? array_merge($resolved, $original) : $resolved;
    }
}
<?php

namespace Guzzle\Service\Description;

/**
 * Validator responsible for preparing and validating parameters against the parameter's schema
 */
interface ValidatorInterface
{
    /**
     * Validate a value against the acceptable types, regular expressions, minimum, maximums, instanceOf, enums, etc
     * Add default and static values to the passed in variable. If the validation completes successfully, the input
     * must be run correctly through the matching schema's filters attribute.
     *
     * @param Parameter $param Schema that is being validated against the value
     * @param mixed     $value Value to validate and process. The value may change during this process.
     *
     * @return bool  Returns true if the input data is valid for the schema
     */
    public function validate(Parameter $param, &$value);

    /**
     * Get validation errors encountered while validating
     *
     * @return array
     */
    public function getErrors();
}
<?php

namespace Guzzle\Service\Description;

use Guzzle\Common\Exception\InvalidArgumentException;

/**
 * JSON Schema formatter class
 */
class SchemaFormatter
{
    /** @var \DateTimeZone */
    protected static $utcTimeZone;

    /**
     * Format a value by a registered format name
     *
     * @param string $format Registered format used to format the value
     * @param mixed  $value  Value being formatted
     *
     * @return mixed
     */
    public static function format($format, $value)
    {
        switch ($format) {
            case 'date-time':
                return self::formatDateTime($value);
            case 'date-time-http':
                return self::formatDateTimeHttp($value);
            case 'date':
                return self::formatDate($value);
            case 'time':
                return self::formatTime($value);
            case 'timestamp':
                return self::formatTimestamp($value);
            case 'boolean-string':
                return self::formatBooleanAsString($value);
            default:
                return $value;
        }
    }

    /**
     * Create a ISO 8601 (YYYY-MM-DDThh:mm:ssZ) formatted date time value in UTC time
     *
     * @param string|integer|\DateTime $value Date time value
     *
     * @return string
     */
    public static function formatDateTime($value)
    {
        return self::dateFormatter($value, 'Y-m-d\TH:i:s\Z');
    }

    /**
     * Create an HTTP date (RFC 1123 / RFC 822) formatted UTC date-time string
     *
     * @param string|integer|\DateTime $value Date time value
     *
     * @return string
     */
    public static function formatDateTimeHttp($value)
    {
        return self::dateFormatter($value, 'D, d M Y H:i:s \G\M\T');
    }

    /**
     * Create a YYYY-MM-DD formatted string
     *
     * @param string|integer|\DateTime $value Date time value
     *
     * @return string
     */
    public static function formatDate($value)
    {
        return self::dateFormatter($value, 'Y-m-d');
    }

    /**
     * Create a hh:mm:ss formatted string
     *
     * @param string|integer|\DateTime $value Date time value
     *
     * @return string
     */
    public static function formatTime($value)
    {
        return self::dateFormatter($value, 'H:i:s');
    }

    /**
     * Formats a boolean value as a string
     *
     * @param string|integer|bool $value Value to convert to a boolean 'true' / 'false' value
     *
     * @return string
     */
    public static function formatBooleanAsString($value)
    {
        return filter_var($value, FILTER_VALIDATE_BOOLEAN) ? 'true' : 'false';
    }

    /**
     * Return a UNIX timestamp in the UTC timezone
     *
     * @param string|integer|\DateTime $value Time value
     *
     * @return int
     */
    public static function formatTimestamp($value)
    {
        return (int) self::dateFormatter($value, 'U');
    }

    /**
     * Get a UTC DateTimeZone object
     *
     * @return \DateTimeZone
     */
    protected static function getUtcTimeZone()
    {
        // @codeCoverageIgnoreStart
        if (!self::$utcTimeZone) {
            self::$utcTimeZone = new \DateTimeZone('UTC');
        }
        // @codeCoverageIgnoreEnd

        return self::$utcTimeZone;
    }

    /**
     * Perform the actual DateTime formatting
     *
     * @param int|string|\DateTime $dateTime Date time value
     * @param string               $format   Format of the result
     *
     * @return string
     * @throws InvalidArgumentException
     */
    protected static function dateFormatter($dateTime, $format)
    {
        if (is_numeric($dateTime)) {
            return gmdate($format, (int) $dateTime);
        }

        if (is_string($dateTime)) {
            $dateTime = new \DateTime($dateTime);
        }

        if ($dateTime instanceof \DateTime) {
            return $dateTime->setTimezone(self::getUtcTimeZone())->format($format);
        }

        throw new InvalidArgumentException('Date/Time values must be either a string, integer, or DateTime object');
    }
}
<?php

namespace Guzzle\Service\Description;

use Guzzle\Common\ToArrayInterface;

/**
 * Default parameter validator
 */
class SchemaValidator implements ValidatorInterface
{
    /** @var self Cache instance of the object */
    protected static $instance;

    /** @var bool Whether or not integers are converted to strings when an integer is received for a string input */
    protected $castIntegerToStringType;

    /** @var array Errors encountered while validating */
    protected $errors;

    /**
     * @return self
     * @codeCoverageIgnore
     */
    public static function getInstance()
    {
        if (!self::$instance) {
            self::$instance = new self();
        }

        return self::$instance;
    }

    /**
     * @param bool $castIntegerToStringType Set to true to convert integers into strings when a required type is a
     *                                      string and the input value is an integer. Defaults to true.
     */
    public function __construct($castIntegerToStringType = true)
    {
        $this->castIntegerToStringType = $castIntegerToStringType;
    }

    public function validate(Parameter $param, &$value)
    {
        $this->errors = array();
        $this->recursiveProcess($param, $value);

        if (empty($this->errors)) {
            return true;
        } else {
            sort($this->errors);
            return false;
        }
    }

    /**
     * Get the errors encountered while validating
     *
     * @return array
     */
    public function getErrors()
    {
        return $this->errors ?: array();
    }

    /**
     * Recursively validate a parameter
     *
     * @param Parameter $param  API parameter being validated
     * @param mixed     $value  Value to validate and validate. The value may change during this validate.
     * @param string    $path   Current validation path (used for error reporting)
     * @param int       $depth  Current depth in the validation validate
     *
     * @return bool Returns true if valid, or false if invalid
     */
    protected function recursiveProcess(Parameter $param, &$value, $path = '', $depth = 0)
    {
        // Update the value by adding default or static values
        $value = $param->getValue($value);

        $required = $param->getRequired();
        // if the value is null and the parameter is not required or is static, then skip any further recursion
        if ((null === $value && !$required) || $param->getStatic()) {
            return true;
        }

        $type = $param->getType();
        // Attempt to limit the number of times is_array is called by tracking if the value is an array
        $valueIsArray = is_array($value);
        // If a name is set then update the path so that validation messages are more helpful
        if ($name = $param->getName()) {
            $path .= "[{$name}]";
        }

        if ($type == 'object') {

            // Objects are either associative arrays, ToArrayInterface, or some other object
            if ($param->getInstanceOf()) {
                $instance = $param->getInstanceOf();
                if (!($value instanceof $instance)) {
                    $this->errors[] = "{$path} must be an instance of {$instance}";
                    return false;
                }
            }

            // Determine whether or not this "value" has properties and should be traversed
            $traverse = $temporaryValue = false;

            // Convert the value to an array
            if (!$valueIsArray && $value instanceof ToArrayInterface) {
                $value = $value->toArray();
            }

            if ($valueIsArray) {
                // Ensure that the array is associative and not numerically indexed
                if (isset($value[0])) {
                    $this->errors[] = "{$path} must be an array of properties. Got a numerically indexed array.";
                    return false;
                }
                $traverse = true;
            } elseif ($value === null) {
                // Attempt to let the contents be built up by default values if possible
                $value = array();
                $temporaryValue = $valueIsArray = $traverse = true;
            }

            if ($traverse) {

                if ($properties = $param->getProperties()) {
                    // if properties were found, the validate each property of the value
                    foreach ($properties as $property) {
                        $name = $property->getName();
                        if (isset($value[$name])) {
                            $this->recursiveProcess($property, $value[$name], $path, $depth + 1);
                        } else {
                            $current = null;
                            $this->recursiveProcess($property, $current, $path, $depth + 1);
                            // Only set the value if it was populated with something
                            if (null !== $current) {
                                $value[$name] = $current;
                            }
                        }
                    }
                }

                $additional = $param->getAdditionalProperties();
                if ($additional !== true) {
                    // If additional properties were found, then validate each against the additionalProperties attr.
                    $keys = array_keys($value);
                    // Determine the keys that were specified that were not listed in the properties of the schema
                    $diff = array_diff($keys, array_keys($properties));
                    if (!empty($diff)) {
                        // Determine which keys are not in the properties
                        if ($additional instanceOf Parameter) {
                            foreach ($diff as $key) {
                                $this->recursiveProcess($additional, $value[$key], "{$path}[{$key}]", $depth);
                            }
                        } else {
                            // if additionalProperties is set to false and there are additionalProperties in the values, then fail
                            foreach ($diff as $prop) {
                                $this->errors[] = sprintf('%s[%s] is not an allowed property', $path, $prop);
                            }
                        }
                    }
                }

                // A temporary value will be used to traverse elements that have no corresponding input value.
                // This allows nested required parameters with default values to bubble up into the input.
                // Here we check if we used a temp value and nothing bubbled up, then we need to remote the value.
                if ($temporaryValue && empty($value)) {
                    $value = null;
                    $valueIsArray = false;
                }
            }

        } elseif ($type == 'array' && $valueIsArray && $param->getItems()) {
            foreach ($value as $i => &$item) {
                // Validate each item in an array against the items attribute of the schema
                $this->recursiveProcess($param->getItems(), $item, $path . "[{$i}]", $depth + 1);
            }
        }

        // If the value is required and the type is not null, then there is an error if the value is not set
        if ($required && $value === null && $type != 'null') {
            $message = "{$path} is " . ($param->getType() ? ('a required ' . implode(' or ', (array) $param->getType())) : 'required');
            if ($param->getDescription()) {
                $message .= ': ' . $param->getDescription();
            }
            $this->errors[] = $message;
            return false;
        }

        // Validate that the type is correct. If the type is string but an integer was passed, the class can be
        // instructed to cast the integer to a string to pass validation. This is the default behavior.
        if ($type && (!$type = $this->determineType($type, $value))) {
            if ($this->castIntegerToStringType && $param->getType() == 'string' && is_integer($value)) {
                $value = (string) $value;
            } else {
                $this->errors[] = "{$path} must be of type " . implode(' or ', (array) $param->getType());
            }
        }

        // Perform type specific validation for strings, arrays, and integers
        if ($type == 'string') {

            // Strings can have enums which are a list of predefined values
            if (($enum = $param->getEnum()) && !in_array($value, $enum)) {
                $this->errors[] = "{$path} must be one of " . implode(' or ', array_map(function ($s) {
                    return '"' . addslashes($s) . '"';
                }, $enum));
            }
            // Strings can have a regex pattern that the value must match
            if (($pattern  = $param->getPattern()) && !preg_match($pattern, $value)) {
                $this->errors[] = "{$path} must match the following regular expression: {$pattern}";
            }

            $strLen = null;
            if ($min = $param->getMinLength()) {
                $strLen = strlen($value);
                if ($strLen < $min) {
                    $this->errors[] = "{$path} length must be greater than or equal to {$min}";
                }
            }
            if ($max = $param->getMaxLength()) {
                if (($strLen ?: strlen($value)) > $max) {
                    $this->errors[] = "{$path} length must be less than or equal to {$max}";
                }
            }

        } elseif ($type == 'array') {

            $size = null;
            if ($min = $param->getMinItems()) {
                $size = count($value);
                if ($size < $min) {
                    $this->errors[] = "{$path} must contain {$min} or more elements";
                }
            }
            if ($max = $param->getMaxItems()) {
                if (($size ?: count($value)) > $max) {
                    $this->errors[] = "{$path} must contain {$max} or fewer elements";
                }
            }

        } elseif ($type == 'integer' || $type == 'number' || $type == 'numeric') {
            if (($min = $param->getMinimum()) && $value < $min) {
                $this->errors[] = "{$path} must be greater than or equal to {$min}";
            }
            if (($max = $param->getMaximum()) && $value > $max) {
                $this->errors[] = "{$path} must be less than or equal to {$max}";
            }
        }

        return empty($this->errors);
    }

    /**
     * From the allowable types, determine the type that the variable matches
     *
     * @param string $type  Parameter type
     * @param mixed  $value Value to determine the type
     *
     * @return string|bool Returns the matching type on
     */
    protected function determineType($type, $value)
    {
        foreach ((array) $type as $t) {
            if ($t == 'string' && (is_string($value) || (is_object($value) && method_exists($value, '__toString')))) {
                return 'string';
            } elseif ($t == 'object' && (is_array($value) || is_object($value))) {
                return 'object';
            } elseif ($t == 'array' && is_array($value)) {
                return 'array';
            } elseif ($t == 'integer' && is_integer($value)) {
                return 'integer';
            } elseif ($t == 'boolean' && is_bool($value)) {
                return 'boolean';
            } elseif ($t == 'number' && is_numeric($value)) {
                return 'number';
            } elseif ($t == 'numeric' && is_numeric($value)) {
                return 'numeric';
            } elseif ($t == 'null' && !$value) {
                return 'null';
            } elseif ($t == 'any') {
                return 'any';
            }
        }

        return false;
    }
}
<?php

namespace Guzzle\Service\Description;

use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Common\ToArrayInterface;

/**
 * A ServiceDescription stores service information based on a service document
 */
class ServiceDescription implements ServiceDescriptionInterface, ToArrayInterface
{
    /** @var array Array of {@see OperationInterface} objects */
    protected $operations = array();

    /** @var array Array of API models */
    protected $models = array();

    /** @var string Name of the API */
    protected $name;

    /** @var string API version */
    protected $apiVersion;

    /** @var string Summary of the API */
    protected $description;

    /** @var array Any extra API data */
    protected $extraData = array();

    /** @var ServiceDescriptionLoader Factory used in factory method */
    protected static $descriptionLoader;

    /** @var string baseUrl/basePath */
    protected $baseUrl;

    /**
     * {@inheritdoc}
     * @param string|array $config  File to build or array of operation information
     * @param array        $options Service description factory options
     *
     * @return self
     */
    public static function factory($config, array $options = array())
    {
        // @codeCoverageIgnoreStart
        if (!self::$descriptionLoader) {
            self::$descriptionLoader = new ServiceDescriptionLoader();
        }
        // @codeCoverageIgnoreEnd

        return self::$descriptionLoader->load($config, $options);
    }

    /**
     * @param array $config Array of configuration data
     */
    public function __construct(array $config = array())
    {
        $this->fromArray($config);
    }

    public function serialize()
    {
        return json_encode($this->toArray());
    }

    public function unserialize($json)
    {
        $this->operations = array();
        $this->fromArray(json_decode($json, true));
    }

    public function toArray()
    {
        $result = array(
            'name'        => $this->name,
            'apiVersion'  => $this->apiVersion,
            'baseUrl'     => $this->baseUrl,
            'description' => $this->description
        ) + $this->extraData;
        $result['operations'] = array();
        foreach ($this->getOperations() as $name => $operation) {
            $result['operations'][$operation->getName() ?: $name] = $operation->toArray();
        }
        if (!empty($this->models)) {
            $result['models'] = array();
            foreach ($this->models as $id => $model) {
                $result['models'][$id] = $model instanceof Parameter ? $model->toArray(): $model;
            }
        }

        return array_filter($result);
    }

    public function getBaseUrl()
    {
        return $this->baseUrl;
    }

    /**
     * Set the baseUrl of the description
     *
     * @param string $baseUrl Base URL of each operation
     *
     * @return self
     */
    public function setBaseUrl($baseUrl)
    {
        $this->baseUrl = $baseUrl;

        return $this;
    }

    public function getOperations()
    {
        foreach (array_keys($this->operations) as $name) {
            $this->getOperation($name);
        }

        return $this->operations;
    }

    public function hasOperation($name)
    {
        return isset($this->operations[$name]);
    }

    public function getOperation($name)
    {
        // Lazily retrieve and build operations
        if (!isset($this->operations[$name])) {
            return null;
        }

        if (!($this->operations[$name] instanceof Operation)) {
            $this->operations[$name] = new Operation($this->operations[$name], $this);
        }

        return $this->operations[$name];
    }

    /**
     * Add a operation to the service description
     *
     * @param OperationInterface $operation Operation to add
     *
     * @return self
     */
    public function addOperation(OperationInterface $operation)
    {
        $this->operations[$operation->getName()] = $operation->setServiceDescription($this);

        return $this;
    }

    public function getModel($id)
    {
        if (!isset($this->models[$id])) {
            return null;
        }

        if (!($this->models[$id] instanceof Parameter)) {
            $this->models[$id] = new Parameter($this->models[$id] + array('name' => $id), $this);
        }

        return $this->models[$id];
    }

    public function getModels()
    {
        // Ensure all models are converted into parameter objects
        foreach (array_keys($this->models) as $id) {
            $this->getModel($id);
        }

        return $this->models;
    }

    public function hasModel($id)
    {
        return isset($this->models[$id]);
    }

    /**
     * Add a model to the service description
     *
     * @param Parameter $model Model to add
     *
     * @return self
     */
    public function addModel(Parameter $model)
    {
        $this->models[$model->getName()] = $model;

        return $this;
    }

    public function getApiVersion()
    {
        return $this->apiVersion;
    }

    public function getName()
    {
        return $this->name;
    }

    public function getDescription()
    {
        return $this->description;
    }

    public function getData($key)
    {
        return isset($this->extraData[$key]) ? $this->extraData[$key] : null;
    }

    public function setData($key, $value)
    {
        $this->extraData[$key] = $value;

        return $this;
    }

    /**
     * Initialize the state from an array
     *
     * @param array $config Configuration data
     * @throws InvalidArgumentException
     */
    protected function fromArray(array $config)
    {
        // Keep a list of default keys used in service descriptions that is later used to determine extra data keys
        static $defaultKeys = array('name', 'models', 'apiVersion', 'baseUrl', 'description');
        // Pull in the default configuration values
        foreach ($defaultKeys as $key) {
            if (isset($config[$key])) {
                $this->{$key} = $config[$key];
            }
        }

        // Account for the Swagger name for Guzzle's baseUrl
        if (isset($config['basePath'])) {
            $this->baseUrl = $config['basePath'];
        }

        // Ensure that the models and operations properties are always arrays
        $this->models = (array) $this->models;
        $this->operations = (array) $this->operations;

        // We want to add operations differently than adding the other properties
        $defaultKeys[] = 'operations';

        // Create operations for each operation
        if (isset($config['operations'])) {
            foreach ($config['operations'] as $name => $operation) {
                if (!($operation instanceof Operation) && !is_array($operation)) {
                    throw new InvalidArgumentException('Invalid operation in service description: '
                        . gettype($operation));
                }
                $this->operations[$name] = $operation;
            }
        }

        // Get all of the additional properties of the service description and store them in a data array
        foreach (array_diff(array_keys($config), $defaultKeys) as $key) {
            $this->extraData[$key] = $config[$key];
        }
    }
}
<?php

namespace Guzzle\Service\Description;

use Guzzle\Common\Exception\InvalidArgumentException;

/**
 * Data object holding the information of an API command
 */
class Operation implements OperationInterface
{
    /** @var string Default command class to use when none is specified */
    const DEFAULT_COMMAND_CLASS = 'Guzzle\\Service\\Command\\OperationCommand';

    /** @var array Hashmap of properties that can be specified. Represented as a hash to speed up constructor. */
    protected static $properties = array(
        'name' => true, 'httpMethod' => true, 'uri' => true, 'class' => true, 'responseClass' => true,
        'responseType' => true, 'responseNotes' => true, 'notes' => true, 'summary' => true, 'documentationUrl' => true,
        'deprecated' => true, 'data' => true, 'parameters' => true, 'additionalParameters' => true,
        'errorResponses' => true
    );

    /** @var array Parameters */
    protected $parameters = array();

    /** @var Parameter Additional parameters schema */
    protected $additionalParameters;

    /** @var string Name of the command */
    protected $name;

    /** @var string HTTP method */
    protected $httpMethod;

    /** @var string This is a short summary of what the operation does */
    protected $summary;

    /** @var string A longer text field to explain the behavior of the operation. */
    protected $notes;

    /** @var string Reference URL providing more information about the operation */
    protected $documentationUrl;

    /** @var string HTTP URI of the command */
    protected $uri;

    /** @var string Class of the command object */
    protected $class;

    /** @var string This is what is returned from the method */
    protected $responseClass;

    /** @var string Type information about the response */
    protected $responseType;

    /** @var string Information about the response returned by the operation */
    protected $responseNotes;

    /** @var bool Whether or not the command is deprecated */
    protected $deprecated;

    /** @var array Array of errors that could occur when running the command */
    protected $errorResponses;

    /** @var ServiceDescriptionInterface */
    protected $description;

    /** @var array Extra operation information */
    protected $data;

    /**
     * Builds an Operation object using an array of configuration data:
     * - name:               (string) Name of the command
     * - httpMethod:         (string) HTTP method of the operation
     * - uri:                (string) URI template that can create a relative or absolute URL
     * - class:              (string) Concrete class that implements this command
     * - parameters:         (array) Associative array of parameters for the command. {@see Parameter} for information.
     * - summary:            (string) This is a short summary of what the operation does
     * - notes:              (string) A longer text field to explain the behavior of the operation.
     * - documentationUrl:   (string) Reference URL providing more information about the operation
     * - responseClass:      (string) This is what is returned from the method. Can be a primitive, PSR-0 compliant
     *                       class name, or model.
     * - responseNotes:      (string) Information about the response returned by the operation
     * - responseType:       (string) One of 'primitive', 'class', 'model', or 'documentation'. If not specified, this
     *                       value will be automatically inferred based on whether or not there is a model matching the
     *                       name, if a matching PSR-0 compliant class name is found, or set to 'primitive' by default.
     * - deprecated:         (bool) Set to true if this is a deprecated command
     * - errorResponses:     (array) Errors that could occur when executing the command. Array of hashes, each with a
     *                       'code' (the HTTP response code), 'reason' (response reason phrase or description of the
     *                       error), and 'class' (a custom exception class that would be thrown if the error is
     *                       encountered).
     * - data:               (array) Any extra data that might be used to help build or serialize the operation
     * - additionalParameters: (null|array) Parameter schema to use when an option is passed to the operation that is
     *                                      not in the schema
     *
     * @param array                       $config      Array of configuration data
     * @param ServiceDescriptionInterface $description Service description used to resolve models if $ref tags are found
     */
    public function __construct(array $config = array(), ServiceDescriptionInterface $description = null)
    {
        $this->description = $description;

        // Get the intersection of the available properties and properties set on the operation
        foreach (array_intersect_key($config, self::$properties) as $key => $value) {
            $this->{$key} = $value;
        }

        $this->class = $this->class ?: self::DEFAULT_COMMAND_CLASS;
        $this->deprecated = (bool) $this->deprecated;
        $this->errorResponses = $this->errorResponses ?: array();
        $this->data = $this->data ?: array();

        if (!$this->responseClass) {
            $this->responseClass = 'array';
            $this->responseType = 'primitive';
        } elseif ($this->responseType) {
            // Set the response type to perform validation
            $this->setResponseType($this->responseType);
        } else {
            // A response class was set and no response type was set, so guess what the type is
            $this->inferResponseType();
        }

        // Parameters need special handling when adding
        if ($this->parameters) {
            foreach ($this->parameters as $name => $param) {
                if ($param instanceof Parameter) {
                    $param->setName($name)->setParent($this);
                } elseif (is_array($param)) {
                    $param['name'] = $name;
                    $this->addParam(new Parameter($param, $this->description));
                }
            }
        }

        if ($this->additionalParameters) {
            if ($this->additionalParameters instanceof Parameter) {
                $this->additionalParameters->setParent($this);
            } elseif (is_array($this->additionalParameters)) {
                $this->setadditionalParameters(new Parameter($this->additionalParameters, $this->description));
            }
        }
    }

    public function toArray()
    {
        $result = array();
        // Grab valid properties and filter out values that weren't set
        foreach (array_keys(self::$properties) as $check) {
            if ($value = $this->{$check}) {
                $result[$check] = $value;
            }
        }
        // Remove the name property
        unset($result['name']);
        // Parameters need to be converted to arrays
        $result['parameters'] = array();
        foreach ($this->parameters as $key => $param) {
            $result['parameters'][$key] = $param->toArray();
        }
        // Additional parameters need to be cast to an array
        if ($this->additionalParameters instanceof Parameter) {
            $result['additionalParameters'] = $this->additionalParameters->toArray();
        }

        return $result;
    }

    public function getServiceDescription()
    {
        return $this->description;
    }

    public function setServiceDescription(ServiceDescriptionInterface $description)
    {
        $this->description = $description;

        return $this;
    }

    public function getParams()
    {
        return $this->parameters;
    }

    public function getParamNames()
    {
        return array_keys($this->parameters);
    }

    public function hasParam($name)
    {
        return isset($this->parameters[$name]);
    }

    public function getParam($param)
    {
        return isset($this->parameters[$param]) ? $this->parameters[$param] : null;
    }

    /**
     * Add a parameter to the command
     *
     * @param Parameter $param Parameter to add
     *
     * @return self
     */
    public function addParam(Parameter $param)
    {
        $this->parameters[$param->getName()] = $param;
        $param->setParent($this);

        return $this;
    }

    /**
     * Remove a parameter from the command
     *
     * @param string $name Name of the parameter to remove
     *
     * @return self
     */
    public function removeParam($name)
    {
        unset($this->parameters[$name]);

        return $this;
    }

    public function getHttpMethod()
    {
        return $this->httpMethod;
    }

    /**
     * Set the HTTP method of the command
     *
     * @param string $httpMethod Method to set
     *
     * @return self
     */
    public function setHttpMethod($httpMethod)
    {
        $this->httpMethod = $httpMethod;

        return $this;
    }

    public function getClass()
    {
        return $this->class;
    }

    /**
     * Set the concrete class of the command
     *
     * @param string $className Concrete class name
     *
     * @return self
     */
    public function setClass($className)
    {
        $this->class = $className;

        return $this;
    }

    public function getName()
    {
        return $this->name;
    }

    /**
     * Set the name of the command
     *
     * @param string $name Name of the command
     *
     * @return self
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    public function getSummary()
    {
        return $this->summary;
    }

    /**
     * Set a short summary of what the operation does
     *
     * @param string $summary Short summary of the operation
     *
     * @return self
     */
    public function setSummary($summary)
    {
        $this->summary = $summary;

        return $this;
    }

    public function getNotes()
    {
        return $this->notes;
    }

    /**
     * Set a longer text field to explain the behavior of the operation.
     *
     * @param string $notes Notes on the operation
     *
     * @return self
     */
    public function setNotes($notes)
    {
        $this->notes = $notes;

        return $this;
    }

    public function getDocumentationUrl()
    {
        return $this->documentationUrl;
    }

    /**
     * Set the URL pointing to additional documentation on the command
     *
     * @param string $docUrl Documentation URL
     *
     * @return self
     */
    public function setDocumentationUrl($docUrl)
    {
        $this->documentationUrl = $docUrl;

        return $this;
    }

    public function getResponseClass()
    {
        return $this->responseClass;
    }

    /**
     * Set what is returned from the method. Can be a primitive, class name, or model. For example: 'array',
     * 'Guzzle\\Foo\\Baz', or 'MyModelName' (to reference a model by ID).
     *
     * @param string $responseClass Type of response
     *
     * @return self
     */
    public function setResponseClass($responseClass)
    {
        $this->responseClass = $responseClass;
        $this->inferResponseType();

        return $this;
    }

    public function getResponseType()
    {
        return $this->responseType;
    }

    /**
     * Set qualifying information about the responseClass. One of 'primitive', 'class', 'model', or 'documentation'
     *
     * @param string $responseType Response type information
     *
     * @return self
     * @throws InvalidArgumentException
     */
    public function setResponseType($responseType)
    {
        static $types = array(
            self::TYPE_PRIMITIVE => true,
            self::TYPE_CLASS => true,
            self::TYPE_MODEL => true,
            self::TYPE_DOCUMENTATION => true
        );
        if (!isset($types[$responseType])) {
            throw new InvalidArgumentException('responseType must be one of ' . implode(', ', array_keys($types)));
        }

        $this->responseType = $responseType;

        return $this;
    }

    public function getResponseNotes()
    {
        return $this->responseNotes;
    }

    /**
     * Set notes about the response of the operation
     *
     * @param string $notes Response notes
     *
     * @return self
     */
    public function setResponseNotes($notes)
    {
        $this->responseNotes = $notes;

        return $this;
    }

    public function getDeprecated()
    {
        return $this->deprecated;
    }

    /**
     * Set whether or not the command is deprecated
     *
     * @param bool $isDeprecated Set to true to mark as deprecated
     *
     * @return self
     */
    public function setDeprecated($isDeprecated)
    {
        $this->deprecated = $isDeprecated;

        return $this;
    }

    public function getUri()
    {
        return $this->uri;
    }

    /**
     * Set the URI template of the command
     *
     * @param string $uri URI template to set
     *
     * @return self
     */
    public function setUri($uri)
    {
        $this->uri = $uri;

        return $this;
    }

    public function getErrorResponses()
    {
        return $this->errorResponses;
    }

    /**
     * Add an error to the command
     *
     * @param string $code   HTTP response code
     * @param string $reason HTTP response reason phrase or information about the error
     * @param string $class  Exception class associated with the error
     *
     * @return self
     */
    public function addErrorResponse($code, $reason, $class)
    {
        $this->errorResponses[] = array('code' => $code, 'reason' => $reason, 'class' => $class);

        return $this;
    }

    /**
     * Set all of the error responses of the operation
     *
     * @param array $errorResponses Hash of error name to a hash containing a code, reason, class
     *
     * @return self
     */
    public function setErrorResponses(array $errorResponses)
    {
        $this->errorResponses = $errorResponses;

        return $this;
    }

    public function getData($name)
    {
        return isset($this->data[$name]) ? $this->data[$name] : null;
    }

    /**
     * Set a particular data point on the operation
     *
     * @param string $name  Name of the data value
     * @param mixed  $value Value to set
     *
     * @return self
     */
    public function setData($name, $value)
    {
        $this->data[$name] = $value;

        return $this;
    }

    /**
     * Get the additionalParameters of the operation
     *
     * @return Parameter|null
     */
    public function getAdditionalParameters()
    {
        return $this->additionalParameters;
    }

    /**
     * Set the additionalParameters of the operation
     *
     * @param Parameter|null $parameter Parameter to set
     *
     * @return self
     */
    public function setAdditionalParameters($parameter)
    {
        if ($this->additionalParameters = $parameter) {
            $this->additionalParameters->setParent($this);
        }

        return $this;
    }

    /**
     * Infer the response type from the responseClass value
     */
    protected function inferResponseType()
    {
        static $primitives = array('array' => 1, 'boolean' => 1, 'string' => 1, 'integer' => 1, '' => 1);
        if (isset($primitives[$this->responseClass])) {
            $this->responseType = self::TYPE_PRIMITIVE;
        } elseif ($this->description && $this->description->hasModel($this->responseClass)) {
            $this->responseType = self::TYPE_MODEL;
        } else {
            $this->responseType = self::TYPE_CLASS;
        }
    }
}
<?php

namespace Guzzle\Service\Description;

use Guzzle\Common\ToArrayInterface;

/**
 * Interface defining data objects that hold the information of an API operation
 */
interface OperationInterface extends ToArrayInterface
{
    const TYPE_PRIMITIVE = 'primitive';
    const TYPE_CLASS = 'class';
    const TYPE_DOCUMENTATION = 'documentation';
    const TYPE_MODEL = 'model';

    /**
     * Get the service description that the operation belongs to
     *
     * @return ServiceDescriptionInterface|null
     */
    public function getServiceDescription();

    /**
     * Set the service description that the operation belongs to
     *
     * @param ServiceDescriptionInterface $description Service description
     *
     * @return self
     */
    public function setServiceDescription(ServiceDescriptionInterface $description);

    /**
     * Get the params of the operation
     *
     * @return array
     */
    public function getParams();

    /**
     * Returns an array of parameter names
     *
     * @return array
     */
    public function getParamNames();

    /**
     * Check if the operation has a specific parameter by name
     *
     * @param string $name Name of the param
     *
     * @return bool
     */
    public function hasParam($name);

    /**
     * Get a single parameter of the operation
     *
     * @param string $param Parameter to retrieve by name
     *
     * @return Parameter|null
     */
    public function getParam($param);

    /**
     * Get the HTTP method of the operation
     *
     * @return string|null
     */
    public function getHttpMethod();

    /**
     * Get the concrete operation class that implements this operation
     *
     * @return string
     */
    public function getClass();

    /**
     * Get the name of the operation
     *
     * @return string|null
     */
    public function getName();

    /**
     * Get a short summary of what the operation does
     *
     * @return string|null
     */
    public function getSummary();

    /**
     * Get a longer text field to explain the behavior of the operation
     *
     * @return string|null
     */
    public function getNotes();

    /**
     * Get the documentation URL of the operation
     *
     * @return string|null
     */
    public function getDocumentationUrl();

    /**
     * Get what is returned from the method. Can be a primitive, class name, or model. For example, the responseClass
     * could be 'array', which would inherently use a responseType of 'primitive'. Using a class name would set a
     * responseType of 'class'. Specifying a model by ID will use a responseType of 'model'.
     *
     * @return string|null
     */
    public function getResponseClass();

    /**
     * Get information about how the response is unmarshalled: One of 'primitive', 'class', 'model', or 'documentation'
     *
     * @return string
     */
    public function getResponseType();

    /**
     * Get notes about the response of the operation
     *
     * @return string|null
     */
    public function getResponseNotes();

    /**
     * Get whether or not the operation is deprecated
     *
     * @return bool
     */
    public function getDeprecated();

    /**
     * Get the URI that will be merged into the generated request
     *
     * @return string
     */
    public function getUri();

    /**
     * Get the errors that could be encountered when executing the operation
     *
     * @return array
     */
    public function getErrorResponses();

    /**
     * Get extra data from the operation
     *
     * @param string $name Name of the data point to retrieve
     *
     * @return mixed|null
     */
    public function getData($name);
}
<?php

namespace Guzzle\Service\Command;

use Guzzle\Http\Message\Response;

/**
 * Default HTTP response parser used to marshal JSON responses into arrays and XML responses into SimpleXMLElement
 */
class DefaultResponseParser implements ResponseParserInterface
{
    /** @var self */
    protected static $instance;

    /**
     * @return self
     * @codeCoverageIgnore
     */
    public static function getInstance()
    {
        if (!self::$instance) {
            self::$instance = new self;
        }

        return self::$instance;
    }

    public function parse(CommandInterface $command)
    {
        $response = $command->getRequest()->getResponse();

        // Account for hard coded content-type values specified in service descriptions
        if ($contentType = $command['command.expects']) {
            $response->setHeader('Content-Type', $contentType);
        } else {
            $contentType = (string) $response->getHeader('Content-Type');
        }

        return $this->handleParsing($command, $response, $contentType);
    }

    protected function handleParsing(CommandInterface $command, Response $response, $contentType)
    {
        $result = $response;
        if ($result->getBody()) {
            if (stripos($contentType, 'json') !== false) {
                $result = $result->json();
            } elseif (stripos($contentType, 'xml') !== false) {
                $result = $result->xml();
            }
        }

        return $result;
    }
}
<?php

namespace Guzzle\Service\Command\Factory;

use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Service\ClientInterface;

/**
 * Command factory used when you need to provide aliases to commands
 */
class AliasFactory implements FactoryInterface
{
    /** @var array Associative array mapping command aliases to the aliased command */
    protected $aliases;

    /** @var ClientInterface Client used to retry using aliases */
    protected $client;

    /**
     * @param ClientInterface $client  Client used to retry with the alias
     * @param array           $aliases Associative array mapping aliases to the alias
     */
    public function __construct(ClientInterface $client, array $aliases)
    {
        $this->client = $client;
        $this->aliases = $aliases;
    }

    public function factory($name, array $args = array())
    {
        if (isset($this->aliases[$name])) {
            try {
                return $this->client->getCommand($this->aliases[$name], $args);
            } catch (InvalidArgumentException $e) {
                return null;
            }
        }
    }
}
<?php

namespace Guzzle\Service\Command\Factory;

use Guzzle\Inflection\InflectorInterface;
use Guzzle\Inflection\Inflector;
use Guzzle\Service\ClientInterface;

/**
 * Command factory used to create commands referencing concrete command classes
 */
class ConcreteClassFactory implements FactoryInterface
{
    /** @var ClientInterface */
    protected $client;

    /** @var InflectorInterface */
    protected $inflector;

    /**
     * @param ClientInterface    $client    Client that owns the commands
     * @param InflectorInterface $inflector Inflector used to resolve class names
     */
    public function __construct(ClientInterface $client, InflectorInterface $inflector = null)
    {
        $this->client = $client;
        $this->inflector = $inflector ?: Inflector::getDefault();
    }

    public function factory($name, array $args = array())
    {
        // Determine the class to instantiate based on the namespace of the current client and the default directory
        $prefix = $this->client->getConfig('command.prefix');
        if (!$prefix) {
            // The prefix can be specified in a factory method and is cached
            $prefix = implode('\\', array_slice(explode('\\', get_class($this->client)), 0, -1)) . '\\Command\\';
            $this->client->getConfig()->set('command.prefix', $prefix);
        }

        $class = $prefix . str_replace(' ', '\\', ucwords(str_replace('.', ' ', $this->inflector->camel($name))));

        // Create the concrete command if it exists
        if (class_exists($class)) {
            return new $class($args);
        }
    }
}
<?php

namespace Guzzle\Service\Command\Factory;

use Guzzle\Service\Command\CommandInterface;
use Guzzle\Service\ClientInterface;

/**
 * Composite factory used by a client object to create command objects utilizing multiple factories
 */
class CompositeFactory implements \IteratorAggregate, \Countable, FactoryInterface
{
    /** @var array Array of command factories */
    protected $factories;

    /**
     * Get the default chain to use with clients
     *
     * @param ClientInterface $client Client to base the chain on
     *
     * @return self
     */
    public static function getDefaultChain(ClientInterface $client)
    {
        $factories = array();
        if ($description = $client->getDescription()) {
            $factories[] = new ServiceDescriptionFactory($description);
        }
        $factories[] = new ConcreteClassFactory($client);

        return new self($factories);
    }

    /**
     * @param array $factories Array of command factories
     */
    public function __construct(array $factories = array())
    {
        $this->factories = $factories;
    }

    /**
     * Add a command factory to the chain
     *
     * @param FactoryInterface        $factory Factory to add
     * @param string|FactoryInterface $before  Insert the new command factory before a command factory class or object
     *                                         matching a class name.
     * @return CompositeFactory
     */
    public function add(FactoryInterface $factory, $before = null)
    {
        $pos = null;

        if ($before) {
            foreach ($this->factories as $i => $f) {
                if ($before instanceof FactoryInterface) {
                    if ($f === $before) {
                        $pos = $i;
                        break;
                    }
                } elseif (is_string($before)) {
                    if ($f instanceof $before) {
                        $pos = $i;
                        break;
                    }
                }
            }
        }

        if ($pos === null) {
            $this->factories[] = $factory;
        } else {
            array_splice($this->factories, $i, 0, array($factory));
        }

        return $this;
    }

    /**
     * Check if the chain contains a specific command factory
     *
     * @param FactoryInterface|string $factory Factory to check
     *
     * @return bool
     */
    public function has($factory)
    {
        return (bool) $this->find($factory);
    }

    /**
     * Remove a specific command factory from the chain
     *
     * @param string|FactoryInterface $factory Factory to remove by name or instance
     *
     * @return CompositeFactory
     */
    public function remove($factory = null)
    {
        if (!($factory instanceof FactoryInterface)) {
            $factory = $this->find($factory);
        }

        $this->factories = array_values(array_filter($this->factories, function($f) use ($factory) {
            return $f !== $factory;
        }));

        return $this;
    }

    /**
     * Get a command factory by class name
     *
     * @param string|FactoryInterface $factory Command factory class or instance
     *
     * @return null|FactoryInterface
     */
    public function find($factory)
    {
        foreach ($this->factories as $f) {
            if ($factory === $f || (is_string($factory) && $f instanceof $factory)) {
                return $f;
            }
        }
    }

    /**
     * Create a command using the associated command factories
     *
     * @param string $name Name of the command
     * @param array  $args Command arguments
     *
     * @return CommandInterface
     */
    public function factory($name, array $args = array())
    {
        foreach ($this->factories as $factory) {
            $command = $factory->factory($name, $args);
            if ($command) {
                return $command;
            }
        }
    }

    public function count()
    {
        return count($this->factories);
    }

    public function getIterator()
    {
        return new \ArrayIterator($this->factories);
    }
}
<?php

namespace Guzzle\Service\Command\Factory;

use Guzzle\Service\Command\CommandInterface;

/**
 * Interface for creating commands by name
 */
interface FactoryInterface
{
    /**
     * Create a command by name
     *
     * @param string $name Command to create
     * @param array  $args Command arguments
     *
     * @return CommandInterface|null
     */
    public function factory($name, array $args = array());
}
<?php

namespace Guzzle\Service\Command\Factory;

use Guzzle\Service\Description\ServiceDescriptionInterface;
use Guzzle\Inflection\InflectorInterface;

/**
 * Command factory used to create commands based on service descriptions
 */
class ServiceDescriptionFactory implements FactoryInterface
{
    /** @var ServiceDescriptionInterface */
    protected $description;

    /** @var InflectorInterface */
    protected $inflector;

    /**
     * @param ServiceDescriptionInterface $description Service description
     * @param InflectorInterface          $inflector   Optional inflector to use if the command is not at first found
     */
    public function __construct(ServiceDescriptionInterface $description, InflectorInterface $inflector = null)
    {
        $this->setServiceDescription($description);
        $this->inflector = $inflector;
    }

    /**
     * Change the service description used with the factory
     *
     * @param ServiceDescriptionInterface $description Service description to use
     *
     * @return FactoryInterface
     */
    public function setServiceDescription(ServiceDescriptionInterface $description)
    {
        $this->description = $description;

        return $this;
    }

    /**
     * Returns the service description
     *
     * @return ServiceDescriptionInterface
     */
    public function getServiceDescription()
    {
        return $this->description;
    }

    public function factory($name, array $args = array())
    {
        $command = $this->description->getOperation($name);

        // If a command wasn't found, then try to uppercase the first letter and try again
        if (!$command) {
            $command = $this->description->getOperation(ucfirst($name));
            // If an inflector was passed, then attempt to get the command using snake_case inflection
            if (!$command && $this->inflector) {
                $command = $this->description->getOperation($this->inflector->snake($name));
            }
        }

        if ($command) {
            $class = $command->getClass();
            return new $class($args, $command, $this->description);
        }
    }
}
<?php

namespace Guzzle\Service\Command\Factory;

/**
 * Command factory used when explicitly mapping strings to command classes
 */
class MapFactory implements FactoryInterface
{
    /** @var array Associative array mapping command names to classes */
    protected $map;

    /** @param array $map Associative array mapping command names to classes */
    public function __construct(array $map)
    {
        $this->map = $map;
    }

    public function factory($name, array $args = array())
    {
        if (isset($this->map[$name])) {
            $class = $this->map[$name];

            return new $class($args);
        }
    }
}
<?php

namespace Guzzle\Service\Command;

use Guzzle\Common\Event;

/**
 * Event class emitted with the operation.parse_class event
 */
class CreateResponseClassEvent extends Event
{
    /**
     * Set the result of the object creation
     *
     * @param mixed $result Result value to set
     */
    public function setResult($result)
    {
        $this['result'] = $result;
        $this->stopPropagation();
    }

    /**
     * Get the created object
     *
     * @return mixed
     */
    public function getResult()
    {
        return $this['result'];
    }
}
<?php

namespace Guzzle\Service\Command;

use Guzzle\Http\Message\Response;
use Guzzle\Service\Command\LocationVisitor\VisitorFlyweight;
use Guzzle\Service\Command\LocationVisitor\Response\ResponseVisitorInterface;
use Guzzle\Service\Description\Parameter;
use Guzzle\Service\Description\OperationInterface;
use Guzzle\Service\Description\Operation;
use Guzzle\Service\Exception\ResponseClassException;
use Guzzle\Service\Resource\Model;

/**
 * Response parser that attempts to marshal responses into an associative array based on models in a service description
 */
class OperationResponseParser extends DefaultResponseParser
{
    /** @var VisitorFlyweight $factory Visitor factory */
    protected $factory;

    /** @var self */
    protected static $instance;

    /** @var bool */
    private $schemaInModels;

    /**
     * @return self
     * @codeCoverageIgnore
     */
    public static function getInstance()
    {
        if (!static::$instance) {
            static::$instance = new static(VisitorFlyweight::getInstance());
        }

        return static::$instance;
    }

    /**
     * @param VisitorFlyweight $factory        Factory to use when creating visitors
     * @param bool             $schemaInModels Set to true to inject schemas into models
     */
    public function __construct(VisitorFlyweight $factory, $schemaInModels = false)
    {
        $this->factory = $factory;
        $this->schemaInModels = $schemaInModels;
    }

    /**
     * Add a location visitor to the command
     *
     * @param string                   $location Location to associate with the visitor
     * @param ResponseVisitorInterface $visitor  Visitor to attach
     *
     * @return self
     */
    public function addVisitor($location, ResponseVisitorInterface $visitor)
    {
        $this->factory->addResponseVisitor($location, $visitor);

        return $this;
    }

    protected function handleParsing(CommandInterface $command, Response $response, $contentType)
    {
        $operation = $command->getOperation();
        $type = $operation->getResponseType();
        $model = null;

        if ($type == OperationInterface::TYPE_MODEL) {
            $model = $operation->getServiceDescription()->getModel($operation->getResponseClass());
        } elseif ($type == OperationInterface::TYPE_CLASS) {
            return $this->parseClass($command);
        }

        if (!$model) {
            // Return basic processing if the responseType is not model or the model cannot be found
            return parent::handleParsing($command, $response, $contentType);
        } elseif ($command[AbstractCommand::RESPONSE_PROCESSING] != AbstractCommand::TYPE_MODEL) {
            // Returns a model with no visiting if the command response processing is not model
            return new Model(parent::handleParsing($command, $response, $contentType));
        } else {
            // Only inject the schema into the model if "schemaInModel" is true
            return new Model($this->visitResult($model, $command, $response), $this->schemaInModels ? $model : null);
        }
    }

    /**
     * Parse a class object
     *
     * @param CommandInterface $command Command to parse into an object
     *
     * @return mixed
     * @throws ResponseClassException
     */
    protected function parseClass(CommandInterface $command)
    {
        // Emit the operation.parse_class event. If a listener injects a 'result' property, then that will be the result
        $event = new CreateResponseClassEvent(array('command' => $command));
        $command->getClient()->getEventDispatcher()->dispatch('command.parse_response', $event);
        if ($result = $event->getResult()) {
            return $result;
        }

        $className = $command->getOperation()->getResponseClass();
        if (!method_exists($className, 'fromCommand')) {
            throw new ResponseClassException("{$className} must exist and implement a static fromCommand() method");
        }

        return $className::fromCommand($command);
    }

    /**
     * Perform transformations on the result array
     *
     * @param Parameter        $model    Model that defines the structure
     * @param CommandInterface $command  Command that performed the operation
     * @param Response         $response Response received
     *
     * @return array Returns the array of result data
     */
    protected function visitResult(Parameter $model, CommandInterface $command, Response $response)
    {
        $foundVisitors = $result = $knownProps = array();
        $props = $model->getProperties();

        foreach ($props as $schema) {
            if ($location = $schema->getLocation()) {
                // Trigger the before method on the first found visitor of this type
                if (!isset($foundVisitors[$location])) {
                    $foundVisitors[$location] = $this->factory->getResponseVisitor($location);
                    $foundVisitors[$location]->before($command, $result);
                }
            }
        }

        // Visit additional properties when it is an actual schema
        if (($additional = $model->getAdditionalProperties()) instanceof Parameter) {
            $this->visitAdditionalProperties($model, $command, $response, $additional, $result, $foundVisitors);
        }

        // Apply the parameter value with the location visitor
        foreach ($props as $schema) {
            $knownProps[$schema->getName()] = 1;
            if ($location = $schema->getLocation()) {
                $foundVisitors[$location]->visit($command, $response, $schema, $result);
            }
        }

        // Remove any unknown and potentially unsafe top-level properties
        if ($additional === false) {
            $result = array_intersect_key($result, $knownProps);
        }

        // Call the after() method of each found visitor
        foreach ($foundVisitors as $visitor) {
            $visitor->after($command);
        }

        return $result;
    }

    protected function visitAdditionalProperties(
        Parameter $model,
        CommandInterface $command,
        Response $response,
        Parameter $additional,
        &$result,
        array &$foundVisitors
    ) {
        // Only visit when a location is specified
        if ($location = $additional->getLocation()) {
            if (!isset($foundVisitors[$location])) {
                $foundVisitors[$location] = $this->factory->getResponseVisitor($location);
                $foundVisitors[$location]->before($command, $result);
            }
            // Only traverse if an array was parsed from the before() visitors
            if (is_array($result)) {
                // Find each additional property
                foreach (array_keys($result) as $key) {
                    // Check if the model actually knows this property. If so, then it is not additional
                    if (!$model->getProperty($key)) {
                        // Set the name to the key so that we can parse it with each visitor
                        $additional->setName($key);
                        $foundVisitors[$location]->visit($command, $response, $additional, $result);
                    }
                }
                // Reset the additionalProperties name to null
                $additional->setName(null);
            }
        }
    }
}
<?php

namespace Guzzle\Service\Command;

/**
 * Interface used to accept a completed OperationCommand and parse the result into a specific response type
 */
interface ResponseClassInterface
{
    /**
     * Create a response model object from a completed command
     *
     * @param OperationCommand $command That serialized the request
     *
     * @return self
     */
    public static function fromCommand(OperationCommand $command);
}
<?php

namespace Guzzle\Service\Command;

use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Common\Exception\UnexpectedValueException;
use Guzzle\Http\Message\RequestInterface;

/**
 * A ClosureCommand is a command that allows dynamic commands to be created at runtime using a closure to prepare the
 * request. A closure key and \Closure value must be passed to the command in the constructor. The closure must
 * accept the command object as an argument.
 */
class ClosureCommand extends AbstractCommand
{
    /**
     * {@inheritdoc}
     * @throws InvalidArgumentException if a closure was not passed
     */
    protected function init()
    {
        if (!$this['closure']) {
            throw new InvalidArgumentException('A closure must be passed in the parameters array');
        }
    }

    /**
     * {@inheritdoc}
     * @throws UnexpectedValueException If the closure does not return a request
     */
    protected function build()
    {
        $closure = $this['closure'];
        /** @var $closure \Closure */
        $this->request = $closure($this, $this->operation);

        if (!$this->request || !$this->request instanceof RequestInterface) {
            throw new UnexpectedValueException('Closure command did not return a RequestInterface object');
        }
    }
}
<?php

namespace Guzzle\Service\Command;

/**
 * Parses the HTTP response of a command and sets the appropriate result on a command object
 */
interface ResponseParserInterface
{
    /**
     * Parse the HTTP response received by the command and update the command's result contents
     *
     * @param CommandInterface $command Command to parse and update
     *
     * @return mixed Returns the result to set on the command
     */
    public function parse(CommandInterface $command);
}
<?php

namespace Guzzle\Service\Command;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Service\Command\CommandInterface;

/**
 * Translates command options and operation parameters into a request object
 */
interface RequestSerializerInterface
{
    /**
     * Create a request for a command
     *
     * @param CommandInterface $command Command that will own the request
     *
     * @return RequestInterface
     */
    public function prepare(CommandInterface $command);
}
<?php

namespace Guzzle\Service\Command;

use Guzzle\Common\Collection;
use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Curl\CurlHandle;
use Guzzle\Service\Client;
use Guzzle\Service\ClientInterface;
use Guzzle\Service\Description\Operation;
use Guzzle\Service\Description\OperationInterface;
use Guzzle\Service\Description\ValidatorInterface;
use Guzzle\Service\Description\SchemaValidator;
use Guzzle\Service\Exception\CommandException;
use Guzzle\Service\Exception\ValidationException;

/**
 * Command object to handle preparing and processing client requests and responses of the requests
 */
abstract class AbstractCommand extends Collection implements CommandInterface
{
    // @deprecated: Option used to specify custom headers to add to the generated request
    const HEADERS_OPTION = 'command.headers';
    // @deprecated: Option used to add an onComplete method to a command
    const ON_COMPLETE = 'command.on_complete';
    // @deprecated: Option used to change the entity body used to store a response
    const RESPONSE_BODY = 'command.response_body';

    // Option used to add request options to the request created by a command
    const REQUEST_OPTIONS = 'command.request_options';
    // command values to not count as additionalParameters
    const HIDDEN_PARAMS = 'command.hidden_params';
    // Option used to disable any pre-sending command validation
    const DISABLE_VALIDATION = 'command.disable_validation';
    // Option used to override how a command result will be formatted
    const RESPONSE_PROCESSING = 'command.response_processing';
    // Different response types that commands can use
    const TYPE_RAW = 'raw';
    const TYPE_MODEL = 'model';
    const TYPE_NO_TRANSLATION = 'no_translation';

    /** @var ClientInterface Client object used to execute the command */
    protected $client;

    /** @var RequestInterface The request object associated with the command */
    protected $request;

    /** @var mixed The result of the command */
    protected $result;

    /** @var OperationInterface API information about the command */
    protected $operation;

    /** @var mixed callable */
    protected $onComplete;

    /** @var ValidatorInterface Validator used to prepare and validate properties against a JSON schema */
    protected $validator;

    /**
     * @param array|Collection   $parameters Collection of parameters to set on the command
     * @param OperationInterface $operation Command definition from description
     */
    public function __construct($parameters = array(), OperationInterface $operation = null)
    {
        parent::__construct($parameters);
        $this->operation = $operation ?: $this->createOperation();
        foreach ($this->operation->getParams() as $name => $arg) {
            $currentValue = $this[$name];
            $configValue = $arg->getValue($currentValue);
            // If default or static values are set, then this should always be updated on the config object
            if ($currentValue !== $configValue) {
                $this[$name] = $configValue;
            }
        }

        $headers = $this[self::HEADERS_OPTION];
        if (!$headers instanceof Collection) {
            $this[self::HEADERS_OPTION] = new Collection((array) $headers);
        }

        // You can set a command.on_complete option in your parameters to set an onComplete callback
        if ($onComplete = $this['command.on_complete']) {
            unset($this['command.on_complete']);
            $this->setOnComplete($onComplete);
        }

        // Set the hidden additional parameters
        if (!$this[self::HIDDEN_PARAMS]) {
            $this[self::HIDDEN_PARAMS] = array(
                self::HEADERS_OPTION,
                self::RESPONSE_PROCESSING,
                self::HIDDEN_PARAMS,
                self::REQUEST_OPTIONS
            );
        }

        $this->init();
    }

    /**
     * Custom clone behavior
     */
    public function __clone()
    {
        $this->request = null;
        $this->result = null;
    }

    /**
     * Execute the command in the same manner as calling a function
     *
     * @return mixed Returns the result of {@see AbstractCommand::execute}
     */
    public function __invoke()
    {
        return $this->execute();
    }

    public function getName()
    {
        return $this->operation->getName();
    }

    /**
     * Get the API command information about the command
     *
     * @return OperationInterface
     */
    public function getOperation()
    {
        return $this->operation;
    }

    public function setOnComplete($callable)
    {
        if (!is_callable($callable)) {
            throw new InvalidArgumentException('The onComplete function must be callable');
        }

        $this->onComplete = $callable;

        return $this;
    }

    public function execute()
    {
        if (!$this->client) {
            throw new CommandException('A client must be associated with the command before it can be executed.');
        }

        return $this->client->execute($this);
    }

    public function getClient()
    {
        return $this->client;
    }

    public function setClient(ClientInterface $client)
    {
        $this->client = $client;

        return $this;
    }

    public function getRequest()
    {
        if (!$this->request) {
            throw new CommandException('The command must be prepared before retrieving the request');
        }

        return $this->request;
    }

    public function getResponse()
    {
        if (!$this->isExecuted()) {
            $this->execute();
        }

        return $this->request->getResponse();
    }

    public function getResult()
    {
        if (!$this->isExecuted()) {
            $this->execute();
        }

        if (null === $this->result) {
            $this->process();
            // Call the onComplete method if one is set
            if ($this->onComplete) {
                call_user_func($this->onComplete, $this);
            }
        }

        return $this->result;
    }

    public function setResult($result)
    {
        $this->result = $result;

        return $this;
    }

    public function isPrepared()
    {
        return $this->request !== null;
    }

    public function isExecuted()
    {
        return $this->request !== null && $this->request->getState() == 'complete';
    }

    public function prepare()
    {
        if (!$this->isPrepared()) {
            if (!$this->client) {
                throw new CommandException('A client must be associated with the command before it can be prepared.');
            }

            // If no response processing value was specified, then attempt to use the highest level of processing
            if (!isset($this[self::RESPONSE_PROCESSING])) {
                $this[self::RESPONSE_PROCESSING] = self::TYPE_MODEL;
            }

            // Notify subscribers of the client that the command is being prepared
            $this->client->dispatch('command.before_prepare', array('command' => $this));

            // Fail on missing required arguments, and change parameters via filters
            $this->validate();
            // Delegate to the subclass that implements the build method
            $this->build();

            // Add custom request headers set on the command
            if ($headers = $this[self::HEADERS_OPTION]) {
                foreach ($headers as $key => $value) {
                    $this->request->setHeader($key, $value);
                }
            }

            // Add any curl options to the request
            if ($options = $this[Client::CURL_OPTIONS]) {
                $this->request->getCurlOptions()->overwriteWith(CurlHandle::parseCurlConfig($options));
            }

            // Set a custom response body
            if ($responseBody = $this[self::RESPONSE_BODY]) {
                $this->request->setResponseBody($responseBody);
            }

            $this->client->dispatch('command.after_prepare', array('command' => $this));
        }

        return $this->request;
    }

    /**
     * Set the validator used to validate and prepare command parameters and nested JSON schemas. If no validator is
     * set, then the command will validate using the default {@see SchemaValidator}.
     *
     * @param ValidatorInterface $validator Validator used to prepare and validate properties against a JSON schema
     *
     * @return self
     */
    public function setValidator(ValidatorInterface $validator)
    {
        $this->validator = $validator;

        return $this;
    }

    public function getRequestHeaders()
    {
        return $this[self::HEADERS_OPTION];
    }

    /**
     * Initialize the command (hook that can be implemented in subclasses)
     */
    protected function init() {}

    /**
     * Create the request object that will carry out the command
     */
    abstract protected function build();

    /**
     * Hook used to create an operation for concrete commands that are not associated with a service description
     *
     * @return OperationInterface
     */
    protected function createOperation()
    {
        return new Operation(array('name' => get_class($this)));
    }

    /**
     * Create the result of the command after the request has been completed.
     * Override this method in subclasses to customize this behavior
     */
    protected function process()
    {
        $this->result = $this[self::RESPONSE_PROCESSING] != self::TYPE_RAW
            ? DefaultResponseParser::getInstance()->parse($this)
            : $this->request->getResponse();
    }

    /**
     * Validate and prepare the command based on the schema and rules defined by the command's Operation object
     *
     * @throws ValidationException when validation errors occur
     */
    protected function validate()
    {
        // Do not perform request validation/transformation if it is disable
        if ($this[self::DISABLE_VALIDATION]) {
            return;
        }

        $errors = array();
        $validator = $this->getValidator();
        foreach ($this->operation->getParams() as $name => $schema) {
            $value = $this[$name];
            if (!$validator->validate($schema, $value)) {
                $errors = array_merge($errors, $validator->getErrors());
            } elseif ($value !== $this[$name]) {
                // Update the config value if it changed and no validation errors were encountered
                $this->data[$name] = $value;
            }
        }

        // Validate additional parameters
        $hidden = $this[self::HIDDEN_PARAMS];

        if ($properties = $this->operation->getAdditionalParameters()) {
            foreach ($this->toArray() as $name => $value) {
                // It's only additional if it isn't defined in the schema
                if (!$this->operation->hasParam($name) && !in_array($name, $hidden)) {
                    // Always set the name so that error messages are useful
                    $properties->setName($name);
                    if (!$validator->validate($properties, $value)) {
                        $errors = array_merge($errors, $validator->getErrors());
                    } elseif ($value !== $this[$name]) {
                        $this->data[$name] = $value;
                    }
                }
            }
        }

        if (!empty($errors)) {
            $e = new ValidationException('Validation errors: ' . implode("\n", $errors));
            $e->setErrors($errors);
            throw $e;
        }
    }

    /**
     * Get the validator used to prepare and validate properties. If no validator has been set on the command, then
     * the default {@see SchemaValidator} will be used.
     *
     * @return ValidatorInterface
     */
    protected function getValidator()
    {
        if (!$this->validator) {
            $this->validator = SchemaValidator::getInstance();
        }

        return $this->validator;
    }

    /**
     * Get array of any validation errors
     * If no validator has been set then return false
     */
    public function getValidationErrors()
    {
        if (!$this->validator) {
            return false;
        }

        return $this->validator->getErrors();
    }
}
<?php

namespace Guzzle\Service\Command;

use Guzzle\Common\Collection;
use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Http\Message\Response;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Service\Exception\CommandException;
use Guzzle\Service\Description\OperationInterface;
use Guzzle\Service\ClientInterface;
use Guzzle\Common\ToArrayInterface;

/**
 * A command object that contains parameters that can be modified and accessed like an array and turned into an array
 */
interface CommandInterface extends \ArrayAccess, ToArrayInterface
{
    /**
     * Get the short form name of the command
     *
     * @return string
     */
    public function getName();

    /**
     * Get the API operation information about the command
     *
     * @return OperationInterface
     */
    public function getOperation();

    /**
     * Execute the command and return the result
     *
     * @return mixed Returns the result of {@see CommandInterface::execute}
     * @throws CommandException if a client has not been associated with the command
     */
    public function execute();

    /**
     * Get the client object that will execute the command
     *
     * @return ClientInterface|null
     */
    public function getClient();

    /**
     * Set the client object that will execute the command
     *
     * @param ClientInterface $client The client object that will execute the command
     *
     * @return self
     */
    public function setClient(ClientInterface $client);

    /**
     * Get the request object associated with the command
     *
     * @return RequestInterface
     * @throws CommandException if the command has not been executed
     */
    public function getRequest();

    /**
     * Get the response object associated with the command
     *
     * @return Response
     * @throws CommandException if the command has not been executed
     */
    public function getResponse();

    /**
     * Get the result of the command
     *
     * @return Response By default, commands return a Response object unless overridden in a subclass
     * @throws CommandException if the command has not been executed
     */
    public function getResult();

    /**
     * Set the result of the command
     *
     * @param mixed $result Result to set
     *
     * @return self
     */
    public function setResult($result);

    /**
     * Returns TRUE if the command has been prepared for executing
     *
     * @return bool
     */
    public function isPrepared();

    /**
     * Returns TRUE if the command has been executed
     *
     * @return bool
     */
    public function isExecuted();

    /**
     * Prepare the command for executing and create a request object.
     *
     * @return RequestInterface Returns the generated request
     * @throws CommandException if a client object has not been set previously or in the prepare()
     */
    public function prepare();

    /**
     * Get the object that manages the request headers that will be set on any outbound requests from the command
     *
     * @return Collection
     */
    public function getRequestHeaders();

    /**
     * Specify a callable to execute when the command completes
     *
     * @param mixed $callable Callable to execute when the command completes. The callable must accept a
     *                        {@see CommandInterface} object as the only argument.
     * @return self
     * @throws InvalidArgumentException
     */
    public function setOnComplete($callable);
}
<?php

namespace Guzzle\Service\Command;

/**
 * A command that creates requests based on {@see Guzzle\Service\Description\OperationInterface} objects, and if the
 * matching operation uses a service description model in the responseClass attribute, then this command will marshal
 * the response into an associative array based on the JSON schema of the model.
 */
class OperationCommand extends AbstractCommand
{
    /** @var RequestSerializerInterface */
    protected $requestSerializer;

    /** @var ResponseParserInterface Response parser */
    protected $responseParser;

    /**
     * Set the response parser used with the command
     *
     * @param ResponseParserInterface $parser Response parser
     *
     * @return self
     */
    public function setResponseParser(ResponseParserInterface $parser)
    {
        $this->responseParser = $parser;

        return $this;
    }

    /**
     * Set the request serializer used with the command
     *
     * @param RequestSerializerInterface $serializer Request serializer
     *
     * @return self
     */
    public function setRequestSerializer(RequestSerializerInterface $serializer)
    {
        $this->requestSerializer = $serializer;

        return $this;
    }

    /**
     * Get the request serializer used with the command
     *
     * @return RequestSerializerInterface
     */
    public function getRequestSerializer()
    {
        if (!$this->requestSerializer) {
            // Use the default request serializer if none was found
            $this->requestSerializer = DefaultRequestSerializer::getInstance();
        }

        return $this->requestSerializer;
    }

    /**
     * Get the response parser used for the operation
     *
     * @return ResponseParserInterface
     */
    public function getResponseParser()
    {
        if (!$this->responseParser) {
            // Use the default response parser if none was found
            $this->responseParser = OperationResponseParser::getInstance();
        }

        return $this->responseParser;
    }

    protected function build()
    {
        // Prepare and serialize the request
        $this->request = $this->getRequestSerializer()->prepare($this);
    }

    protected function process()
    {
        // Do not process the response if 'command.response_processing' is set to 'raw'
        $this->result = $this[self::RESPONSE_PROCESSING] == self::TYPE_RAW
            ? $this->request->getResponse()
            : $this->getResponseParser()->parse($this);
    }
}
<?php

namespace Guzzle\Service\Command\LocationVisitor\Request;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\PostFileInterface;
use Guzzle\Service\Command\CommandInterface;
use Guzzle\Service\Description\Parameter;

/**
 * Visitor used to apply a parameter to a POST file
 */
class PostFileVisitor extends AbstractRequestVisitor
{
    public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
    {
        $value = $param->filter($value);
        if ($value instanceof PostFileInterface) {
            $request->addPostFile($value);
        } else {
            $request->addPostFile($param->getWireName(), $value);
        }
    }
}
<?php

namespace Guzzle\Service\Command\LocationVisitor\Request;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Service\Command\CommandInterface;
use Guzzle\Service\Description\Parameter;

/**
 * Visitor used to apply a parameter to an array that will be serialized as a top level key-value pair in a JSON body
 */
class JsonVisitor extends AbstractRequestVisitor
{
    /** @var bool Whether or not to add a Content-Type header when JSON is found */
    protected $jsonContentType = 'application/json';

    /** @var \SplObjectStorage Data object for persisting JSON data */
    protected $data;

    public function __construct()
    {
        $this->data = new \SplObjectStorage();
    }

    /**
     * Set the Content-Type header to add to the request if JSON is added to the body. This visitor does not add a
     * Content-Type header unless you specify one here.
     *
     * @param string $header Header to set when JSON is added (e.g. application/json)
     *
     * @return self
     */
    public function setContentTypeHeader($header = 'application/json')
    {
        $this->jsonContentType = $header;

        return $this;
    }

    public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
    {
        if (isset($this->data[$command])) {
            $json = $this->data[$command];
        } else {
            $json = array();
        }
        $json[$param->getWireName()] = $this->prepareValue($value, $param);
        $this->data[$command] = $json;
    }

    public function after(CommandInterface $command, RequestInterface $request)
    {
        if (isset($this->data[$command])) {
            // Don't overwrite the Content-Type if one is set
            if ($this->jsonContentType && !$request->hasHeader('Content-Type')) {
                $request->setHeader('Content-Type', $this->jsonContentType);
            }

            $request->setBody(json_encode($this->data[$command]));
            unset($this->data[$command]);
        }
    }
}
<?php

namespace Guzzle\Service\Command\LocationVisitor\Request;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Service\Command\CommandInterface;
use Guzzle\Service\Description\Parameter;

/**
 * Visitor used to apply a parameter to a request's query string
 */
class QueryVisitor extends AbstractRequestVisitor
{
    public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
    {
        $request->getQuery()->set($param->getWireName(), $this->prepareValue($value, $param));
    }
}
<?php

namespace Guzzle\Service\Command\LocationVisitor\Request;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Service\Command\CommandInterface;
use Guzzle\Service\Description\Parameter;

/**
 * Visitor used to change the location in which a response body is saved
 */
class ResponseBodyVisitor extends AbstractRequestVisitor
{
    public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
    {
        $request->setResponseBody($value);
    }
}
<?php

namespace Guzzle\Service\Command\LocationVisitor\Request;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Service\Command\CommandInterface;
use Guzzle\Service\Description\Parameter;

/**
 * Visitor used to apply a parameter to a POST field
 */
class PostFieldVisitor extends AbstractRequestVisitor
{
    public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
    {
        $request->setPostField($param->getWireName(), $this->prepareValue($value, $param));
    }
}
<?php

namespace Guzzle\Service\Command\LocationVisitor\Request;

use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Service\Command\CommandInterface;
use Guzzle\Service\Description\Parameter;

/**
 * Visitor used to apply a parameter to a header value
 */
class HeaderVisitor extends AbstractRequestVisitor
{
    public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
    {
        $value = $param->filter($value);
        if ($param->getType() == 'object' && $param->getAdditionalProperties() instanceof Parameter) {
            $this->addPrefixedHeaders($request, $param, $value);
        } else {
            $request->setHeader($param->getWireName(), $value);
        }
    }

    /**
     * Add a prefixed array of headers to the request
     *
     * @param RequestInterface $request Request to update
     * @param Parameter        $param   Parameter object
     * @param array            $value   Header array to add
     *
     * @throws InvalidArgumentException
     */
    protected function addPrefixedHeaders(RequestInterface $request, Parameter $param, $value)
    {
        if (!is_array($value)) {
            throw new InvalidArgumentException('An array of mapped headers expected, but received a single value');
        }
        $prefix = $param->getSentAs();
        foreach ($value as $headerName => $headerValue) {
            $request->setHeader($prefix . $headerName, $headerValue);
        }
    }
}
<?php

namespace Guzzle\Service\Command\LocationVisitor\Request;

use Guzzle\Http\EntityBody;
use Guzzle\Http\Message\EntityEnclosingRequestInterface;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\EntityBodyInterface;
use Guzzle\Service\Command\CommandInterface;
use Guzzle\Service\Description\Parameter;

/**
 * Visitor used to apply a body to a request
 *
 * This visitor can use a data parameter of 'expect' to control the Expect header. Set the expect data parameter to
 * false to disable the expect header, or set the value to an integer so that the expect 100-continue header is only
 * added if the Content-Length of the entity body is greater than the value.
 */
class BodyVisitor extends AbstractRequestVisitor
{
    public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
    {
        $value = $param->filter($value);
        $entityBody = EntityBody::factory($value);
        $request->setBody($entityBody);
        $this->addExpectHeader($request, $entityBody, $param->getData('expect_header'));
        // Add the Content-Encoding header if one is set on the EntityBody
        if ($encoding = $entityBody->getContentEncoding()) {
            $request->setHeader('Content-Encoding', $encoding);
        }
    }

    /**
     * Add the appropriate expect header to a request
     *
     * @param EntityEnclosingRequestInterface $request Request to update
     * @param EntityBodyInterface             $body    Entity body of the request
     * @param string|int                      $expect  Expect header setting
     */
    protected function addExpectHeader(EntityEnclosingRequestInterface $request, EntityBodyInterface $body, $expect)
    {
        // Allow the `expect` data parameter to be set to remove the Expect header from the request
        if ($expect === false) {
            $request->removeHeader('Expect');
        } elseif ($expect !== true) {
            // Default to using a MB as the point in which to start using the expect header
            $expect = $expect ?: 1048576;
            // If the expect_header value is numeric then only add if the size is greater than the cutoff
            if (is_numeric($expect) && $body->getSize()) {
                if ($body->getSize() < $expect) {
                    $request->removeHeader('Expect');
                } else {
                    $request->setHeader('Expect', '100-Continue');
                }
            }
        }
    }
}
<?php

namespace Guzzle\Service\Command\LocationVisitor\Request;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Service\Description\Parameter;
use Guzzle\Service\Command\CommandInterface;

/**
 * Location visitor used to add values to different locations in a request with different behaviors as needed
 */
interface RequestVisitorInterface
{
    /**
     * Called after visiting all parameters
     *
     * @param CommandInterface $command Command being visited
     * @param RequestInterface $request Request being visited
     */
    public function after(CommandInterface $command, RequestInterface $request);

    /**
     * Called once for each parameter being visited that matches the location type
     *
     * @param CommandInterface $command Command being visited
     * @param RequestInterface $request Request being visited
     * @param Parameter        $param   Parameter being visited
     * @param mixed            $value   Value to set
     */
    public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value);
}
<?php

namespace Guzzle\Service\Command\LocationVisitor\Request;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Service\Command\CommandInterface;
use Guzzle\Service\Description\Operation;
use Guzzle\Service\Description\Parameter;

/**
 * Location visitor used to serialize XML bodies
 */
class XmlVisitor extends AbstractRequestVisitor
{
    /** @var \SplObjectStorage Data object for persisting XML data */
    protected $data;

    /** @var bool Content-Type header added when XML is found */
    protected $contentType = 'application/xml';

    public function __construct()
    {
        $this->data = new \SplObjectStorage();
    }

    /**
     * Change the content-type header that is added when XML is found
     *
     * @param string $header Header to set when XML is found
     *
     * @return self
     */
    public function setContentTypeHeader($header)
    {
        $this->contentType = $header;

        return $this;
    }

    public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
    {
        $xml = isset($this->data[$command])
            ? $this->data[$command]
            : $this->createRootElement($param->getParent());
        $this->addXml($xml, $param, $value);

        $this->data[$command] = $xml;
    }

    public function after(CommandInterface $command, RequestInterface $request)
    {
        $xml = null;

        // If data was found that needs to be serialized, then do so
        if (isset($this->data[$command])) {
            $xml = $this->finishDocument($this->data[$command]);
            unset($this->data[$command]);
        } else {
            // Check if XML should always be sent for the command
            $operation = $command->getOperation();
            if ($operation->getData('xmlAllowEmpty')) {
                $xmlWriter = $this->createRootElement($operation);
                $xml = $this->finishDocument($xmlWriter);
            }
        }

        if ($xml) {
            // Don't overwrite the Content-Type if one is set
            if ($this->contentType && !$request->hasHeader('Content-Type')) {
                $request->setHeader('Content-Type', $this->contentType);
            }
            $request->setBody($xml);
        }
    }

    /**
     * Create the root XML element to use with a request
     *
     * @param Operation $operation Operation object
     *
     * @return \XMLWriter
     */
    protected function createRootElement(Operation $operation)
    {
        static $defaultRoot = array('name' => 'Request');
        // If no root element was specified, then just wrap the XML in 'Request'
        $root = $operation->getData('xmlRoot') ?: $defaultRoot;
        // Allow the XML declaration to be customized with xmlEncoding
        $encoding = $operation->getData('xmlEncoding');

        $xmlWriter = $this->startDocument($encoding);

        $xmlWriter->startElement($root['name']);
        // Create the wrapping element with no namespaces if no namespaces were present
        if (!empty($root['namespaces'])) {
            // Create the wrapping element with an array of one or more namespaces
            foreach ((array) $root['namespaces'] as $prefix => $uri) {
                $nsLabel = 'xmlns';
                if (!is_numeric($prefix)) {
                    $nsLabel .= ':'.$prefix;
                }
                $xmlWriter->writeAttribute($nsLabel, $uri);
            }
        }
        return $xmlWriter;
    }

    /**
     * Recursively build the XML body
     *
     * @param \XMLWriter $xmlWriter XML to modify
     * @param Parameter  $param     API Parameter
     * @param mixed      $value     Value to add
     */
    protected function addXml(\XMLWriter $xmlWriter, Parameter $param, $value)
    {
        if ($value === null) {
            return;
        }

        $value = $param->filter($value);
        $type = $param->getType();
        $name = $param->getWireName();
        $prefix = null;
        $namespace = $param->getData('xmlNamespace');
        if (false !== strpos($name, ':')) {
            list($prefix, $name) = explode(':', $name, 2);
        }

        if ($type == 'object' || $type == 'array') {
            if (!$param->getData('xmlFlattened')) {
                $xmlWriter->startElementNS(null, $name, $namespace);
            }
            if ($param->getType() == 'array') {
                $this->addXmlArray($xmlWriter, $param, $value);
            } elseif ($param->getType() == 'object') {
                $this->addXmlObject($xmlWriter, $param, $value);
            }
            if (!$param->getData('xmlFlattened')) {
                $xmlWriter->endElement();
            }
            return;
        }
        if ($param->getData('xmlAttribute')) {
            $this->writeAttribute($xmlWriter, $prefix, $name, $namespace, $value);
        } else {
            $this->writeElement($xmlWriter, $prefix, $name, $namespace, $value);
        }
    }

    /**
     * Write an attribute with namespace if used
     *
     * @param  \XMLWriter $xmlWriter XMLWriter instance
     * @param  string     $prefix    Namespace prefix if any
     * @param  string     $name      Attribute name
     * @param  string     $namespace The uri of the namespace
     * @param  string     $value     The attribute content
     */
    protected function writeAttribute($xmlWriter, $prefix, $name, $namespace, $value)
    {
        if (empty($namespace)) {
            $xmlWriter->writeAttribute($name, $value);
        } else {
            $xmlWriter->writeAttributeNS($prefix, $name, $namespace, $value);
        }
    }

    /**
     * Write an element with namespace if used
     *
     * @param  \XMLWriter $xmlWriter XML writer resource
     * @param  string     $prefix    Namespace prefix if any
     * @param  string     $name      Element name
     * @param  string     $namespace The uri of the namespace
     * @param  string     $value     The element content
     */
    protected function writeElement(\XMLWriter $xmlWriter, $prefix, $name, $namespace, $value)
    {
        $xmlWriter->startElementNS($prefix, $name, $namespace);
        if (strpbrk($value, '<>&')) {
            $xmlWriter->writeCData($value);
        } else {
            $xmlWriter->writeRaw($value);
        }
        $xmlWriter->endElement();
    }

    /**
     * Create a new xml writer and start a document
     *
     * @param  string $encoding document encoding
     *
     * @return \XMLWriter the writer resource
     */
    protected function startDocument($encoding)
    {
        $xmlWriter = new \XMLWriter();
        $xmlWriter->openMemory();
        $xmlWriter->startDocument('1.0', $encoding);

        return $xmlWriter;
    }

    /**
     * End the document and return the output
     *
     * @param \XMLWriter $xmlWriter
     *
     * @return \string the writer resource
     */
    protected function finishDocument($xmlWriter)
    {
        $xmlWriter->endDocument();

        return $xmlWriter->outputMemory();
    }

    /**
     * Add an array to the XML
     */
    protected function addXmlArray(\XMLWriter $xmlWriter, Parameter $param, &$value)
    {
        if ($items = $param->getItems()) {
            foreach ($value as $v) {
                $this->addXml($xmlWriter, $items, $v);
            }
        }
    }

    /**
     * Add an object to the XML
     */
    protected function addXmlObject(\XMLWriter $xmlWriter, Parameter $param, &$value)
    {
        $noAttributes = array();
        // add values which have attributes
        foreach ($value as $name => $v) {
            if ($property = $param->getProperty($name)) {
                if ($property->getData('xmlAttribute')) {
                    $this->addXml($xmlWriter, $property, $v);
                } else {
                    $noAttributes[] = array('value' => $v, 'property' => $property);
                }
            }
        }
        // now add values with no attributes
        foreach ($noAttributes as $element) {
            $this->addXml($xmlWriter, $element['property'], $element['value']);
        }
    }
}
<?php

namespace Guzzle\Service\Command\LocationVisitor\Request;

use Guzzle\Service\Command\CommandInterface;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Service\Description\Parameter;

abstract class AbstractRequestVisitor implements RequestVisitorInterface
{
    /**
     * @codeCoverageIgnore
     */
    public function after(CommandInterface $command, RequestInterface $request) {}

    /**
     * @codeCoverageIgnore
     */
    public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value) {}

    /**
     * Prepare (filter and set desired name for request item) the value for request.
     *
     * @param mixed                                     $value
     * @param \Guzzle\Service\Description\Parameter     $param
     *
     * @return array|mixed
     */
    protected function prepareValue($value, Parameter $param)
    {
        return is_array($value)
            ? $this->resolveRecursively($value, $param)
            : $param->filter($value);
    }

    /**
     * Map nested parameters into the location_key based parameters
     *
     * @param array     $value Value to map
     * @param Parameter $param Parameter that holds information about the current key
     *
     * @return array Returns the mapped array
     */
    protected function resolveRecursively(array $value, Parameter $param)
    {
        foreach ($value as $name => &$v) {
            switch ($param->getType()) {
                case 'object':
                    if ($subParam = $param->getProperty($name)) {
                        $key = $subParam->getWireName();
                        $value[$key] = $this->prepareValue($v, $subParam);
                        if ($name != $key) {
                            unset($value[$name]);
                        }
                    } elseif ($param->getAdditionalProperties() instanceof Parameter) {
                        $v = $this->prepareValue($v, $param->getAdditionalProperties());
                    }
                    break;
                case 'array':
                    if ($items = $param->getItems()) {
                        $v = $this->prepareValue($v, $items);
                    }
                    break;
            }
        }

        return $param->filter($value);
    }
}
<?php

namespace Guzzle\Service\Command\LocationVisitor\Response;

use Guzzle\Http\Message\Response;
use Guzzle\Service\Description\Parameter;
use Guzzle\Service\Command\CommandInterface;

/**
 * Location visitor used to add the reason phrase of a response to a key in the result
 */
class ReasonPhraseVisitor extends AbstractResponseVisitor
{
    public function visit(
        CommandInterface $command,
        Response $response,
        Parameter $param,
        &$value,
        $context =  null
    ) {
        $value[$param->getName()] = $response->getReasonPhrase();
    }
}
<?php

namespace Guzzle\Service\Command\LocationVisitor\Response;

use Guzzle\Http\Message\Response;
use Guzzle\Service\Description\Parameter;
use Guzzle\Service\Command\CommandInterface;

/**
 * Location visitor used to marshal JSON response data into a formatted array.
 *
 * Allows top level JSON parameters to be inserted into the result of a command. The top level attributes are grabbed
 * from the response's JSON data using the name value by default. Filters can be applied to parameters as they are
 * traversed. This allows data to be normalized before returning it to users (for example converting timestamps to
 * DateTime objects).
 */
class JsonVisitor extends AbstractResponseVisitor
{
    public function before(CommandInterface $command, array &$result)
    {
        // Ensure that the result of the command is always rooted with the parsed JSON data
        $result = $command->getResponse()->json();
    }

    public function visit(
        CommandInterface $command,
        Response $response,
        Parameter $param,
        &$value,
        $context =  null
    ) {
        $name = $param->getName();
        $key = $param->getWireName();
        if (isset($value[$key])) {
            $this->recursiveProcess($param, $value[$key]);
            if ($key != $name) {
                $value[$name] = $value[$key];
                unset($value[$key]);
            }
        }
    }

    /**
     * Recursively process a parameter while applying filters
     *
     * @param Parameter $param API parameter being validated
     * @param mixed     $value Value to validate and process. The value may change during this process.
     */
    protected function recursiveProcess(Parameter $param, &$value)
    {
        if ($value === null) {
            return;
        }

        if (is_array($value)) {
            $type = $param->getType();
            if ($type == 'array') {
                foreach ($value as &$item) {
                    $this->recursiveProcess($param->getItems(), $item);
                }
            } elseif ($type == 'object' && !isset($value[0])) {
                // On the above line, we ensure that the array is associative and not numerically indexed
                $knownProperties = array();
                if ($properties = $param->getProperties()) {
                    foreach ($properties as $property) {
                        $name = $property->getName();
                        $key = $property->getWireName();
                        $knownProperties[$name] = 1;
                        if (isset($value[$key])) {
                            $this->recursiveProcess($property, $value[$key]);
                            if ($key != $name) {
                                $value[$name] = $value[$key];
                                unset($value[$key]);
                            }
                        }
                    }
                }

                // Remove any unknown and potentially unsafe properties
                if ($param->getAdditionalProperties() === false) {
                    $value = array_intersect_key($value, $knownProperties);
                } elseif (($additional = $param->getAdditionalProperties()) !== true) {
                    // Validate and filter additional properties
                    foreach ($value as &$v) {
                        $this->recursiveProcess($additional, $v);
                    }
                }
            }
        }

        $value = $param->filter($value);
    }
}
<?php

namespace Guzzle\Service\Command\LocationVisitor\Response;

use Guzzle\Http\Message\Response;
use Guzzle\Service\Description\Parameter;
use Guzzle\Service\Command\CommandInterface;

/**
 * Location visitor used to add a particular header of a response to a key in the result
 */
class HeaderVisitor extends AbstractResponseVisitor
{
    public function visit(
        CommandInterface $command,
        Response $response,
        Parameter $param,
        &$value,
        $context =  null
    ) {
        if ($param->getType() == 'object' && $param->getAdditionalProperties() instanceof Parameter) {
            $this->processPrefixedHeaders($response, $param, $value);
        } else {
            $value[$param->getName()] = $param->filter((string) $response->getHeader($param->getWireName()));
        }
    }

    /**
     * Process a prefixed header array
     *
     * @param Response  $response Response that contains the headers
     * @param Parameter $param    Parameter object
     * @param array     $value    Value response array to modify
     */
    protected function processPrefixedHeaders(Response $response, Parameter $param, &$value)
    {
        // Grab prefixed headers that should be placed into an array with the prefix stripped
        if ($prefix = $param->getSentAs()) {
            $container = $param->getName();
            $len = strlen($prefix);
            // Find all matching headers and place them into the containing element
            foreach ($response->getHeaders()->toArray() as $key => $header) {
                if (stripos($key, $prefix) === 0) {
                    // Account for multi-value headers
                    $value[$container][substr($key, $len)] = count($header) == 1 ? end($header) : $header;
                }
            }
        }
    }
}
<?php

namespace Guzzle\Service\Command\LocationVisitor\Response;

use Guzzle\Http\Message\Response;
use Guzzle\Service\Description\Parameter;
use Guzzle\Service\Command\CommandInterface;

/**
 * Location visitor used to parse values out of a response into an associative array
 */
interface ResponseVisitorInterface
{
    /**
     * Called before visiting all parameters. This can be used for seeding the result of a command with default
     * data (e.g. populating with JSON data in the response then adding to the parsed data).
     *
     * @param CommandInterface $command Command being visited
     * @param array            $result  Result value to update if needed (e.g. parsing XML or JSON)
     */
    public function before(CommandInterface $command, array &$result);

    /**
     * Called after visiting all parameters
     *
     * @param CommandInterface $command Command being visited
     */
    public function after(CommandInterface $command);

    /**
     * Called once for each parameter being visited that matches the location type
     *
     * @param CommandInterface $command  Command being visited
     * @param Response         $response Response being visited
     * @param Parameter        $param    Parameter being visited
     * @param mixed            $value    Result associative array value being updated by reference
     * @param mixed            $context  Parsing context
     */
    public function visit(
        CommandInterface $command,
        Response $response,
        Parameter $param,
        &$value,
        $context =  null
    );
}
<?php

namespace Guzzle\Service\Command\LocationVisitor\Response;

use Guzzle\Http\Message\Response;
use Guzzle\Service\Description\Parameter;
use Guzzle\Service\Command\CommandInterface;

/**
 * Location visitor used to add the status code of a response to a key in the result
 */
class StatusCodeVisitor extends AbstractResponseVisitor
{
    public function visit(
        CommandInterface $command,
        Response $response,
        Parameter $param,
        &$value,
        $context =  null
    ) {
        $value[$param->getName()] = $response->getStatusCode();
    }
}
<?php

namespace Guzzle\Service\Command\LocationVisitor\Response;

use Guzzle\Service\Command\CommandInterface;
use Guzzle\Http\Message\Response;
use Guzzle\Service\Description\Parameter;

/**
 * Visitor used to add the body of a response to a particular key
 */
class BodyVisitor extends AbstractResponseVisitor
{
    public function visit(
        CommandInterface $command,
        Response $response,
        Parameter $param,
        &$value,
        $context =  null
    ) {
        $value[$param->getName()] = $param->filter($response->getBody());
    }
}
<?php

namespace Guzzle\Service\Command\LocationVisitor\Response;

use Guzzle\Service\Command\CommandInterface;
use Guzzle\Http\Message\Response;
use Guzzle\Service\Description\Parameter;

/**
 * {@inheritdoc}
 * @codeCoverageIgnore
 */
abstract class AbstractResponseVisitor implements ResponseVisitorInterface
{
    public function before(CommandInterface $command, array &$result) {}

    public function after(CommandInterface $command) {}

    public function visit(
        CommandInterface $command,
        Response $response,
        Parameter $param,
        &$value,
        $context =  null
    ) {}
}
<?php

namespace Guzzle\Service\Command\LocationVisitor\Response;

use Guzzle\Http\Message\Response;
use Guzzle\Service\Description\Parameter;
use Guzzle\Service\Command\CommandInterface;

/**
 * Location visitor used to marshal XML response data into a formatted array
 */
class XmlVisitor extends AbstractResponseVisitor
{
    public function before(CommandInterface $command, array &$result)
    {
        // Set the result of the command to the array conversion of the XML body
        $result = json_decode(json_encode($command->getResponse()->xml()), true);
    }

    public function visit(
        CommandInterface $command,
        Response $response,
        Parameter $param,
        &$value,
        $context =  null
    ) {
        $sentAs = $param->getWireName();
        $name = $param->getName();
        if (isset($value[$sentAs])) {
            $this->recursiveProcess($param, $value[$sentAs]);
            if ($name != $sentAs) {
                $value[$name] = $value[$sentAs];
                unset($value[$sentAs]);
            }
        }
    }

    /**
     * Recursively process a parameter while applying filters
     *
     * @param Parameter $param API parameter being processed
     * @param mixed     $value Value to validate and process. The value may change during this process.
     */
    protected function recursiveProcess(Parameter $param, &$value)
    {
        $type = $param->getType();

        if (!is_array($value)) {
            if ($type == 'array') {
                // Cast to an array if the value was a string, but should be an array
                $this->recursiveProcess($param->getItems(), $value);
                $value = array($value);
            }
        } elseif ($type == 'object') {
            $this->processObject($param, $value);
        } elseif ($type == 'array') {
            $this->processArray($param, $value);
        } elseif ($type == 'string' && gettype($value) == 'array') {
            $value = '';
        }

        if ($value !== null) {
            $value = $param->filter($value);
        }
    }

    /**
     * Process an array
     *
     * @param Parameter $param API parameter being parsed
     * @param mixed     $value Value to process
     */
    protected function processArray(Parameter $param, &$value)
    {
        // Convert the node if it was meant to be an array
        if (!isset($value[0])) {
            // Collections fo nodes are sometimes wrapped in an additional array. For example:
            // <Items><Item><a>1</a></Item><Item><a>2</a></Item></Items> should become:
            // array('Items' => array(array('a' => 1), array('a' => 2))
            // Some nodes are not wrapped. For example: <Foo><a>1</a></Foo><Foo><a>2</a></Foo>
            // should become array('Foo' => array(array('a' => 1), array('a' => 2))
            if ($param->getItems() && isset($value[$param->getItems()->getWireName()])) {
                // Account for the case of a collection wrapping wrapped nodes: Items => Item[]
                $value = $value[$param->getItems()->getWireName()];
                // If the wrapped node only had one value, then make it an array of nodes
                if (!isset($value[0]) || !is_array($value)) {
                    $value = array($value);
                }
            } elseif (!empty($value)) {
                // Account for repeated nodes that must be an array: Foo => Baz, Foo => Baz, but only if the
                // value is set and not empty
                $value = array($value);
            }
        }

        foreach ($value as &$item) {
            $this->recursiveProcess($param->getItems(), $item);
        }
    }

    /**
     * Process an object
     *
     * @param Parameter $param API parameter being parsed
     * @param mixed     $value Value to process
     */
    protected function processObject(Parameter $param, &$value)
    {
        // Ensure that the array is associative and not numerically indexed
        if (!isset($value[0]) && ($properties = $param->getProperties())) {
            $knownProperties = array();
            foreach ($properties as $property) {
                $name = $property->getName();
                $sentAs = $property->getWireName();
                $knownProperties[$name] = 1;
                if ($property->getData('xmlAttribute')) {
                    $this->processXmlAttribute($property, $value);
                } elseif (isset($value[$sentAs])) {
                    $this->recursiveProcess($property, $value[$sentAs]);
                    if ($name != $sentAs) {
                        $value[$name] = $value[$sentAs];
                        unset($value[$sentAs]);
                    }
                }
            }

            // Remove any unknown and potentially unsafe properties
            if ($param->getAdditionalProperties() === false) {
                $value = array_intersect_key($value, $knownProperties);
            }
        }
    }

    /**
     * Process an XML attribute property
     *
     * @param Parameter $property Property to process
     * @param array     $value    Value to process and update
     */
    protected function processXmlAttribute(Parameter $property, array &$value)
    {
        $sentAs = $property->getWireName();
        if (isset($value['@attributes'][$sentAs])) {
            $value[$property->getName()] = $value['@attributes'][$sentAs];
            unset($value['@attributes'][$sentAs]);
            if (empty($value['@attributes'])) {
                unset($value['@attributes']);
            }
        }
    }
}
<?php

namespace Guzzle\Service\Command\LocationVisitor;

use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Service\Command\LocationVisitor\Request\RequestVisitorInterface;
use Guzzle\Service\Command\LocationVisitor\Response\ResponseVisitorInterface;

/**
 * Flyweight factory used to instantiate request and response visitors
 */
class VisitorFlyweight
{
    /** @var self Singleton instance of self */
    protected static $instance;

    /** @var array Default array of mappings of location names to classes */
    protected static $defaultMappings = array(
        'request.body'          => 'Guzzle\Service\Command\LocationVisitor\Request\BodyVisitor',
        'request.header'        => 'Guzzle\Service\Command\LocationVisitor\Request\HeaderVisitor',
        'request.json'          => 'Guzzle\Service\Command\LocationVisitor\Request\JsonVisitor',
        'request.postField'     => 'Guzzle\Service\Command\LocationVisitor\Request\PostFieldVisitor',
        'request.postFile'      => 'Guzzle\Service\Command\LocationVisitor\Request\PostFileVisitor',
        'request.query'         => 'Guzzle\Service\Command\LocationVisitor\Request\QueryVisitor',
        'request.response_body' => 'Guzzle\Service\Command\LocationVisitor\Request\ResponseBodyVisitor',
        'request.responseBody'  => 'Guzzle\Service\Command\LocationVisitor\Request\ResponseBodyVisitor',
        'request.xml'           => 'Guzzle\Service\Command\LocationVisitor\Request\XmlVisitor',
        'response.body'         => 'Guzzle\Service\Command\LocationVisitor\Response\BodyVisitor',
        'response.header'       => 'Guzzle\Service\Command\LocationVisitor\Response\HeaderVisitor',
        'response.json'         => 'Guzzle\Service\Command\LocationVisitor\Response\JsonVisitor',
        'response.reasonPhrase' => 'Guzzle\Service\Command\LocationVisitor\Response\ReasonPhraseVisitor',
        'response.statusCode'   => 'Guzzle\Service\Command\LocationVisitor\Response\StatusCodeVisitor',
        'response.xml'          => 'Guzzle\Service\Command\LocationVisitor\Response\XmlVisitor'
    );

    /** @var array Array of mappings of location names to classes */
    protected $mappings;

    /** @var array Cache of instantiated visitors */
    protected $cache = array();

    /**
     * @return self
     * @codeCoverageIgnore
     */
    public static function getInstance()
    {
        if (!self::$instance) {
            self::$instance = new self();
        }

        return self::$instance;
    }

    /**
     * @param array $mappings Array mapping request.name and response.name to location visitor classes. Leave null to
     *                        use the default values.
     */
    public function __construct(array $mappings = null)
    {
        $this->mappings = $mappings === null ? self::$defaultMappings : $mappings;
    }

    /**
     * Get an instance of a request visitor by location name
     *
     * @param string $visitor Visitor name
     *
     * @return RequestVisitorInterface
     */
    public function getRequestVisitor($visitor)
    {
        return $this->getKey('request.' . $visitor);
    }

    /**
     * Get an instance of a response visitor by location name
     *
     * @param string $visitor Visitor name
     *
     * @return ResponseVisitorInterface
     */
    public function getResponseVisitor($visitor)
    {
        return $this->getKey('response.' . $visitor);
    }

    /**
     * Add a response visitor to the factory by name
     *
     * @param string                  $name    Name of the visitor
     * @param RequestVisitorInterface $visitor Visitor to add
     *
     * @return self
     */
    public function addRequestVisitor($name, RequestVisitorInterface $visitor)
    {
        $this->cache['request.' . $name] = $visitor;

        return $this;
    }

    /**
     * Add a response visitor to the factory by name
     *
     * @param string                   $name    Name of the visitor
     * @param ResponseVisitorInterface $visitor Visitor to add
     *
     * @return self
     */
    public function addResponseVisitor($name, ResponseVisitorInterface $visitor)
    {
        $this->cache['response.' . $name] = $visitor;

        return $this;
    }

    /**
     * Get a visitor by key value name
     *
     * @param string $key Key name to retrieve
     *
     * @return mixed
     * @throws InvalidArgumentException
     */
    private function getKey($key)
    {
        if (!isset($this->cache[$key])) {
            if (!isset($this->mappings[$key])) {
                list($type, $name) = explode('.', $key);
                throw new InvalidArgumentException("No {$type} visitor has been mapped for {$name}");
            }
            $this->cache[$key] = new $this->mappings[$key];
        }

        return $this->cache[$key];
    }
}
<?php

namespace Guzzle\Service\Command;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Service\Command\LocationVisitor\Request\RequestVisitorInterface;
use Guzzle\Service\Command\LocationVisitor\VisitorFlyweight;
use Guzzle\Service\Description\OperationInterface;
use Guzzle\Service\Description\Parameter;

/**
 * Default request serializer that transforms command options and operation parameters into a request
 */
class DefaultRequestSerializer implements RequestSerializerInterface
{
    /** @var VisitorFlyweight $factory Visitor factory */
    protected $factory;

    /** @var self */
    protected static $instance;

    /**
     * @return self
     * @codeCoverageIgnore
     */
    public static function getInstance()
    {
        if (!self::$instance) {
            self::$instance = new self(VisitorFlyweight::getInstance());
        }

        return self::$instance;
    }

    /**
     * @param VisitorFlyweight $factory Factory to use when creating visitors
     */
    public function __construct(VisitorFlyweight $factory)
    {
        $this->factory = $factory;
    }

    /**
     * Add a location visitor to the serializer
     *
     * @param string                   $location Location to associate with the visitor
     * @param RequestVisitorInterface  $visitor  Visitor to attach
     *
     * @return self
     */
    public function addVisitor($location, RequestVisitorInterface $visitor)
    {
        $this->factory->addRequestVisitor($location, $visitor);

        return $this;
    }

    public function prepare(CommandInterface $command)
    {
        $request = $this->createRequest($command);
        // Keep an array of visitors found in the operation
        $foundVisitors = array();
        $operation = $command->getOperation();

        // Add arguments to the request using the location attribute
        foreach ($operation->getParams() as $name => $arg) {
            /** @var $arg \Guzzle\Service\Description\Parameter */
            $location = $arg->getLocation();
            // Skip 'uri' locations because they've already been processed
            if ($location && $location != 'uri') {
                // Instantiate visitors as they are detected in the properties
                if (!isset($foundVisitors[$location])) {
                    $foundVisitors[$location] = $this->factory->getRequestVisitor($location);
                }
                // Ensure that a value has been set for this parameter
                $value = $command[$name];
                if ($value !== null) {
                    // Apply the parameter value with the location visitor
                    $foundVisitors[$location]->visit($command, $request, $arg, $value);
                }
            }
        }

        // Serialize additional parameters
        if ($additional = $operation->getAdditionalParameters()) {
            if ($visitor = $this->prepareAdditionalParameters($operation, $command, $request, $additional)) {
                $foundVisitors[$additional->getLocation()] = $visitor;
            }
        }

        // Call the after method on each visitor found in the operation
        foreach ($foundVisitors as $visitor) {
            $visitor->after($command, $request);
        }

        return $request;
    }

    /**
     * Serialize additional parameters
     *
     * @param OperationInterface $operation  Operation that owns the command
     * @param CommandInterface   $command    Command to prepare
     * @param RequestInterface   $request    Request to serialize
     * @param Parameter          $additional Additional parameters
     *
     * @return null|RequestVisitorInterface
     */
    protected function prepareAdditionalParameters(
        OperationInterface $operation,
        CommandInterface $command,
        RequestInterface $request,
        Parameter $additional
    ) {
        if (!($location = $additional->getLocation())) {
            return;
        }

        $visitor = $this->factory->getRequestVisitor($location);
        $hidden = $command[$command::HIDDEN_PARAMS];

        foreach ($command->toArray() as $key => $value) {
            // Ignore values that are null or built-in command options
            if ($value !== null
                && !in_array($key, $hidden)
                && !$operation->hasParam($key)
            ) {
                $additional->setName($key);
                $visitor->visit($command, $request, $additional, $value);
            }
        }

        return $visitor;
    }

    /**
     * Create a request for the command and operation
     *
     * @param CommandInterface $command Command to create a request for
     *
     * @return RequestInterface
     */
    protected function createRequest(CommandInterface $command)
    {
        $operation = $command->getOperation();
        $client = $command->getClient();
        $options = $command[AbstractCommand::REQUEST_OPTIONS] ?: array();

        // If the command does not specify a template, then assume the base URL of the client
        if (!($uri = $operation->getUri())) {
            return $client->createRequest($operation->getHttpMethod(), $client->getBaseUrl(), null, null, $options);
        }

        // Get the path values and use the client config settings
        $variables = array();
        foreach ($operation->getParams() as $name => $arg) {
            if ($arg->getLocation() == 'uri') {
                if (isset($command[$name])) {
                    $variables[$name] = $arg->filter($command[$name]);
                    if (!is_array($variables[$name])) {
                        $variables[$name] = (string) $variables[$name];
                    }
                }
            }
        }

        return $client->createRequest($operation->getHttpMethod(), array($uri, $variables), null, null, $options);
    }
}
<?php

namespace Guzzle\Service;

/**
 * Interface used for loading configuration data (service descriptions, service builder configs, etc)
 *
 * If a loaded configuration data sets includes a top level key containing an 'includes' section, then the data in the
 * file will extend the merged result of all of the included config files.
 */
interface ConfigLoaderInterface
{
    /**
     * Loads configuration data and returns an array of the loaded result
     *
     * @param mixed $config  Data to load (filename or array of data)
     * @param array $options Array of options to use when loading
     *
     * @return mixed
     */
    public function load($config, array $options = array());
}
<?php

namespace Guzzle\Plugin\Cache;

use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response;

/**
 * Determines if a request can be cached using a callback
 */
class CallbackCanCacheStrategy extends DefaultCanCacheStrategy
{
    /** @var callable Callback for request */
    protected $requestCallback;

    /** @var callable Callback for response */
    protected $responseCallback;

    /**
     * @param \Closure|array|mixed $requestCallback  Callable method to invoke for requests
     * @param \Closure|array|mixed $responseCallback Callable method to invoke for responses
     *
     * @throws InvalidArgumentException
     */
    public function __construct($requestCallback = null, $responseCallback = null)
    {
        if ($requestCallback && !is_callable($requestCallback)) {
            throw new InvalidArgumentException('Method must be callable');
        }

        if ($responseCallback && !is_callable($responseCallback)) {
            throw new InvalidArgumentException('Method must be callable');
        }

        $this->requestCallback = $requestCallback;
        $this->responseCallback = $responseCallback;
    }

    public function canCacheRequest(RequestInterface $request)
    {
        return $this->requestCallback
            ? call_user_func($this->requestCallback, $request)
            : parent::canCacheRequest($request);
    }

    public function canCacheResponse(Response $response)
    {
        return $this->responseCallback
            ? call_user_func($this->responseCallback, $response)
            : parent::canCacheResponse($response);
    }
}
<?php

namespace Guzzle\Plugin\Cache;

use Guzzle\Http\Message\RequestInterface;

\Guzzle\Common\Version::warn('Guzzle\Plugin\Cache\DefaultCacheKeyProvider is no longer used');

/**
 * @deprecated This class is no longer used
 * @codeCoverageIgnore
 */
class DefaultCacheKeyProvider implements CacheKeyProviderInterface
{
    public function getCacheKey(RequestInterface $request)
    {
        // See if the key has already been calculated
        $key = $request->getParams()->get(self::CACHE_KEY);

        if (!$key) {

            $cloned = clone $request;
            $cloned->removeHeader('Cache-Control');

            // Check to see how and if the key should be filtered
            foreach (explode(';', $request->getParams()->get(self::CACHE_KEY_FILTER)) as $part) {
                $pieces = array_map('trim', explode('=', $part));
                if (isset($pieces[1])) {
                    foreach (array_map('trim', explode(',', $pieces[1])) as $remove) {
                        if ($pieces[0] == 'header') {
                            $cloned->removeHeader($remove);
                        } elseif ($pieces[0] == 'query') {
                            $cloned->getQuery()->remove($remove);
                        }
                    }
                }
            }

            $raw = (string) $cloned;
            $key = 'GZ' . md5($raw);
            $request->getParams()->set(self::CACHE_KEY, $key)->set(self::CACHE_KEY_RAW, $raw);
        }

        return $key;
    }
}
<?php

namespace Guzzle\Plugin\Cache;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response;

/**
 * Never performs cache revalidation and just assumes the request is still ok
 */
class SkipRevalidation extends DefaultRevalidation
{
    public function __construct() {}

    public function revalidate(RequestInterface $request, Response $response)
    {
        return true;
    }
}
<?php

namespace Guzzle\Plugin\Cache;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response;

/**
 * Strategy used to determine if a request can be cached
 */
interface CanCacheStrategyInterface
{
    /**
     * Determine if a request can be cached
     *
     * @param RequestInterface $request Request to determine
     *
     * @return bool
     */
    public function canCacheRequest(RequestInterface $request);

    /**
     * Determine if a response can be cached
     *
     * @param Response $response Response to determine
     *
     * @return bool
     */
    public function canCacheResponse(Response $response);
}
{
    "name": "guzzle/plugin-cache",
    "description": "Guzzle HTTP cache plugin",
    "homepage": "http://guzzlephp.org/",
    "keywords": ["plugin", "guzzle"],
    "license": "MIT",
    "authors": [
        {
            "name": "Michael Dowling",
            "email": "mtdowling@gmail.com",
            "homepage": "https://github.com/mtdowling"
        }
    ],
    "require": {
        "php": ">=5.3.2",
        "guzzle/http": "self.version",
        "guzzle/cache": "self.version"
    },
    "autoload": {
        "psr-0": { "Guzzle\\Plugin\\Cache": "" }
    },
    "target-dir": "Guzzle/Plugin/Cache",
    "extra": {
        "branch-alias": {
            "dev-master": "3.7-dev"
        }
    }
}
<?php

namespace Guzzle\Plugin\Cache;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response;

/**
 * Interface used to cache HTTP requests
 */
interface CacheStorageInterface
{
    /**
     * Get a Response from the cache for a request
     *
     * @param RequestInterface $request
     *
     * @return null|Response
     */
    public function fetch(RequestInterface $request);

    /**
     * Cache an HTTP request
     *
     * @param RequestInterface $request  Request being cached
     * @param Response         $response Response to cache
     */
    public function cache(RequestInterface $request, Response $response);

    /**
     * Deletes cache entries that match a request
     *
     * @param RequestInterface $request Request to delete from cache
     */
    public function delete(RequestInterface $request);

    /**
     * Purge all cache entries for a given URL
     *
     * @param string $url
     */
    public function purge($url);
}
<?php

namespace Guzzle\Plugin\Cache;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response;

/**
 * Default strategy used to determine of an HTTP request can be cached
 */
class DefaultCanCacheStrategy implements CanCacheStrategyInterface
{
    public function canCacheRequest(RequestInterface $request)
    {
        // Only GET and HEAD requests can be cached
        if ($request->getMethod() != RequestInterface::GET && $request->getMethod() != RequestInterface::HEAD) {
            return false;
        }

        // Never cache requests when using no-store
        if ($request->hasHeader('Cache-Control') && $request->getHeader('Cache-Control')->hasDirective('no-store')) {
            return false;
        }

        return true;
    }

    public function canCacheResponse(Response $response)
    {
        return $response->isSuccessful() && $response->canCache();
    }
}
<?php

namespace Guzzle\Plugin\Cache;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response;

/**
 * Never performs cache revalidation and just assumes the request is invalid
 */
class DenyRevalidation extends DefaultRevalidation
{
    public function __construct() {}

    public function revalidate(RequestInterface $request, Response $response)
    {
        return false;
    }
}
<?php

namespace Guzzle\Plugin\Cache;

use Guzzle\Cache\CacheAdapterFactory;
use Guzzle\Cache\CacheAdapterInterface;
use Guzzle\Common\Event;
use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Common\Version;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response;
use Guzzle\Cache\DoctrineCacheAdapter;
use Guzzle\Http\Exception\CurlException;
use Doctrine\Common\Cache\ArrayCache;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Plugin to enable the caching of GET and HEAD requests.  Caching can be done on all requests passing through this
 * plugin or only after retrieving resources with cacheable response headers.
 *
 * This is a simple implementation of RFC 2616 and should be considered a private transparent proxy cache, meaning
 * authorization and private data can be cached.
 *
 * It also implements RFC 5861's `stale-if-error` Cache-Control extension, allowing stale cache responses to be used
 * when an error is encountered (such as a `500 Internal Server Error` or DNS failure).
 */
class CachePlugin implements EventSubscriberInterface
{
    /** @var RevalidationInterface Cache revalidation strategy */
    protected $revalidation;

    /** @var CanCacheStrategyInterface Object used to determine if a request can be cached */
    protected $canCache;

    /** @var CacheStorageInterface $cache Object used to cache responses */
    protected $storage;

    /** @var bool */
    protected $autoPurge;

    /**
     * @param array|CacheAdapterInterface|CacheStorageInterface $options Array of options for the cache plugin,
     *     cache adapter, or cache storage object.
     *     - CacheStorageInterface storage:      Adapter used to cache responses
     *     - RevalidationInterface revalidation: Cache revalidation strategy
     *     - CanCacheInterface     can_cache:    Object used to determine if a request can be cached
     *     - bool                  auto_purge    Set to true to automatically PURGE resources when non-idempotent
     *                                           requests are sent to a resource. Defaults to false.
     * @throws InvalidArgumentException if no cache is provided and Doctrine cache is not installed
     */
    public function __construct($options = null)
    {
        if (!is_array($options)) {
            if ($options instanceof CacheAdapterInterface) {
                $options = array('storage' => new DefaultCacheStorage($options));
            } elseif ($options instanceof CacheStorageInterface) {
                $options = array('storage' => $options);
            } elseif ($options) {
                $options = array('storage' => new DefaultCacheStorage(CacheAdapterFactory::fromCache($options)));
            } elseif (!class_exists('Doctrine\Common\Cache\ArrayCache')) {
                // @codeCoverageIgnoreStart
                throw new InvalidArgumentException('No cache was provided and Doctrine is not installed');
                // @codeCoverageIgnoreEnd
            }
        }

        $this->autoPurge = isset($options['auto_purge']) ? $options['auto_purge'] : false;

        // Add a cache storage if a cache adapter was provided
        $this->storage = isset($options['storage'])
            ? $options['storage']
            : new DefaultCacheStorage(new DoctrineCacheAdapter(new ArrayCache()));

        if (!isset($options['can_cache'])) {
            $this->canCache = new DefaultCanCacheStrategy();
        } else {
            $this->canCache = is_callable($options['can_cache'])
                ? new CallbackCanCacheStrategy($options['can_cache'])
                : $options['can_cache'];
        }

        // Use the provided revalidation strategy or the default
        $this->revalidation = isset($options['revalidation'])
            ? $options['revalidation']
            : new DefaultRevalidation($this->storage, $this->canCache);
    }

    public static function getSubscribedEvents()
    {
        return array(
            'request.before_send' => array('onRequestBeforeSend', -255),
            'request.sent'        => array('onRequestSent', 255),
            'request.error'       => array('onRequestError', 0),
            'request.exception'   => array('onRequestException', 0),
        );
    }

    /**
     * Check if a response in cache will satisfy the request before sending
     *
     * @param Event $event
     */
    public function onRequestBeforeSend(Event $event)
    {
        $request = $event['request'];
        $request->addHeader('Via', sprintf('%s GuzzleCache/%s', $request->getProtocolVersion(), Version::VERSION));

        if (!$this->canCache->canCacheRequest($request)) {
            switch ($request->getMethod()) {
                case 'PURGE':
                    $this->purge($request);
                    $request->setResponse(new Response(200, array(), 'purged'));
                    break;
                case 'PUT':
                case 'POST':
                case 'DELETE':
                case 'PATCH':
                    if ($this->autoPurge) {
                        $this->purge($request);
                    }
            }
            return;
        }

        if ($response = $this->storage->fetch($request)) {
            $params = $request->getParams();
            $params['cache.lookup'] = true;
            $response->setHeader(
                'Age',
                time() - strtotime($response->getDate() ? : $response->getLastModified() ?: 'now')
            );
            // Validate that the response satisfies the request
            if ($this->canResponseSatisfyRequest($request, $response)) {
                if (!isset($params['cache.hit'])) {
                    $params['cache.hit'] = true;
                }
                $request->setResponse($response);
            }
        }
    }

    /**
     * If possible, store a response in cache after sending
     *
     * @param Event $event
     */
    public function onRequestSent(Event $event)
    {
        $request = $event['request'];
        $response = $event['response'];

        if ($request->getParams()->get('cache.hit') === null &&
            $this->canCache->canCacheRequest($request) &&
            $this->canCache->canCacheResponse($response)
        ) {
            $this->storage->cache($request, $response);
        }

        $this->addResponseHeaders($request, $response);
    }

    /**
     * If possible, return a cache response on an error
     *
     * @param Event $event
     */
    public function onRequestError(Event $event)
    {
        $request = $event['request'];

        if (!$this->canCache->canCacheRequest($request)) {
            return;
        }

        if ($response = $this->storage->fetch($request)) {
            $response->setHeader(
                'Age',
                time() - strtotime($response->getLastModified() ? : $response->getDate() ?: 'now')
            );

            if ($this->canResponseSatisfyFailedRequest($request, $response)) {
                $request->getParams()->set('cache.hit', 'error');
                $this->addResponseHeaders($request, $response);
                $event['response'] = $response;
                $event->stopPropagation();
            }
        }
    }

    /**
     * If possible, set a cache response on a cURL exception
     *
     * @param Event $event
     *
     * @return null
     */
    public function onRequestException(Event $event)
    {
        if (!$event['exception'] instanceof CurlException) {
            return;
        }

        $request = $event['request'];
        if (!$this->canCache->canCacheRequest($request)) {
            return;
        }

        if ($response = $this->storage->fetch($request)) {
            $response->setHeader('Age', time() - strtotime($response->getDate() ? : 'now'));
            if (!$this->canResponseSatisfyFailedRequest($request, $response)) {
                return;
            }
            $request->getParams()->set('cache.hit', 'error');
            $request->setResponse($response);
            $this->addResponseHeaders($request, $response);
            $event->stopPropagation();
        }
    }

    /**
     * Check if a cache response satisfies a request's caching constraints
     *
     * @param RequestInterface $request  Request to validate
     * @param Response         $response Response to validate
     *
     * @return bool
     */
    public function canResponseSatisfyRequest(RequestInterface $request, Response $response)
    {
        $responseAge = $response->calculateAge();
        $reqc = $request->getHeader('Cache-Control');
        $resc = $response->getHeader('Cache-Control');

        // Check the request's max-age header against the age of the response
        if ($reqc && $reqc->hasDirective('max-age') &&
            $responseAge > $reqc->getDirective('max-age')) {
            return false;
        }

        // Check the response's max-age header
        if ($response->isFresh() === false) {
            $maxStale = $reqc ? $reqc->getDirective('max-stale') : null;
            if (null !== $maxStale) {
                if ($maxStale !== true && $response->getFreshness() < (-1 * $maxStale)) {
                    return false;
                }
            } elseif ($resc && $resc->hasDirective('max-age')
                && $responseAge > $resc->getDirective('max-age')
            ) {
                return false;
            }
        }

        if ($this->revalidation->shouldRevalidate($request, $response)) {
            try {
                return $this->revalidation->revalidate($request, $response);
            } catch (CurlException $e) {
                $request->getParams()->set('cache.hit', 'error');
                return $this->canResponseSatisfyFailedRequest($request, $response);
            }
        }

        return true;
    }

    /**
     * Check if a cache response satisfies a failed request's caching constraints
     *
     * @param RequestInterface $request  Request to validate
     * @param Response         $response Response to validate
     *
     * @return bool
     */
    public function canResponseSatisfyFailedRequest(RequestInterface $request, Response $response)
    {
        $reqc = $request->getHeader('Cache-Control');
        $resc = $response->getHeader('Cache-Control');
        $requestStaleIfError = $reqc ? $reqc->getDirective('stale-if-error') : null;
        $responseStaleIfError = $resc ? $resc->getDirective('stale-if-error') : null;

        if (!$requestStaleIfError && !$responseStaleIfError) {
            return false;
        }

        if (is_numeric($requestStaleIfError) && $response->getAge() - $response->getMaxAge() > $requestStaleIfError) {
            return false;
        }

        if (is_numeric($responseStaleIfError) && $response->getAge() - $response->getMaxAge() > $responseStaleIfError) {
            return false;
        }

        return true;
    }

    /**
     * Purge all cache entries for a given URL
     *
     * @param string $url URL to purge
     */
    public function purge($url)
    {
        // BC compatibility with previous version that accepted a Request object
        $url = $url instanceof RequestInterface ? $url->getUrl() : $url;
        $this->storage->purge($url);
    }

    /**
     * Add the plugin's headers to a response
     *
     * @param RequestInterface $request  Request
     * @param Response         $response Response to add headers to
     */
    protected function addResponseHeaders(RequestInterface $request, Response $response)
    {
        $params = $request->getParams();
        $response->setHeader('Via', sprintf('%s GuzzleCache/%s', $request->getProtocolVersion(), Version::VERSION));

        $lookup = ($params['cache.lookup'] === true ? 'HIT' : 'MISS') . ' from GuzzleCache';
        if ($header = $response->getHeader('X-Cache-Lookup')) {
            // Don't add duplicates
            $values = $header->toArray();
            $values[] = $lookup;
            $response->setHeader('X-Cache-Lookup', array_unique($values));
        } else {
            $response->setHeader('X-Cache-Lookup', $lookup);
        }

        if ($params['cache.hit'] === true) {
            $xcache = 'HIT from GuzzleCache';
        } elseif ($params['cache.hit'] == 'error') {
            $xcache = 'HIT_ERROR from GuzzleCache';
        } else {
            $xcache = 'MISS from GuzzleCache';
        }

        if ($header = $response->getHeader('X-Cache')) {
            // Don't add duplicates
            $values = $header->toArray();
            $values[] = $xcache;
            $response->setHeader('X-Cache', array_unique($values));
        } else {
            $response->setHeader('X-Cache', $xcache);
        }

        if ($response->isFresh() === false) {
            $response->addHeader('Warning', sprintf('110 GuzzleCache/%s "Response is stale"', Version::VERSION));
            if ($params['cache.hit'] === 'error') {
                $response->addHeader('Warning', sprintf('111 GuzzleCache/%s "Revalidation failed"', Version::VERSION));
            }
        }
    }
}
<?php

namespace Guzzle\Plugin\Cache;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response;

/**
 * Cache revalidation interface
 */
interface RevalidationInterface
{
    /**
     * Performs a cache revalidation
     *
     * @param RequestInterface $request    Request to revalidate
     * @param Response         $response   Response that was received
     *
     * @return bool Returns true if the request can be cached
     */
    public function revalidate(RequestInterface $request, Response $response);

    /**
     * Returns true if the response should be revalidated
     *
     * @param RequestInterface $request  Request to check
     * @param Response         $response Response to check
     *
     * @return bool
     */
    public function shouldRevalidate(RequestInterface $request, Response $response);
}
<?php

namespace Guzzle\Plugin\Cache;

use Guzzle\Cache\CacheAdapterFactory;
use Guzzle\Cache\CacheAdapterInterface;
use Guzzle\Http\EntityBodyInterface;
use Guzzle\Http\Message\MessageInterface;
use Guzzle\Http\Message\Request;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response;

/**
 * Default cache storage implementation
 */
class DefaultCacheStorage implements CacheStorageInterface
{
    /** @var string */
    protected $keyPrefix;

    /** @var CacheAdapterInterface Cache used to store cache data */
    protected $cache;

    /** @var int Default cache TTL */
    protected $defaultTtl;

    /**
     * @param mixed  $cache      Cache used to store cache data
     * @param string $keyPrefix  Provide an optional key prefix to prefix on all cache keys
     * @param int    $defaultTtl Default cache TTL
     */
    public function __construct($cache, $keyPrefix = '', $defaultTtl = 3600)
    {
        $this->cache = CacheAdapterFactory::fromCache($cache);
        $this->defaultTtl = $defaultTtl;
        $this->keyPrefix = $keyPrefix;
    }

    public function cache(RequestInterface $request, Response $response)
    {
        $currentTime = time();

        $overrideTtl = $request->getParams()->get('cache.override_ttl');
        if ($overrideTtl) {
            $ttl = $overrideTtl;
        } else {
            $maxAge = $response->getMaxAge();
            if ($maxAge !== null) {
                $ttl = $maxAge;
            } else {
                $ttl = $this->defaultTtl;
            }
        }

        if ($cacheControl = $response->getHeader('Cache-Control')) {
            $stale = $cacheControl->getDirective('stale-if-error');
            if ($stale === true) {
                $ttl += $ttl;
            } else if (is_numeric($stale)) {
                $ttl += $stale;
            }
        }

        // Determine which manifest key should be used
        $key = $this->getCacheKey($request);
        $persistedRequest = $this->persistHeaders($request);
        $entries = array();

        if ($manifest = $this->cache->fetch($key)) {
            // Determine which cache entries should still be in the cache
            $vary = $response->getVary();
            foreach (unserialize($manifest) as $entry) {
                // Check if the entry is expired
                if ($entry[4] < $currentTime) {
                    continue;
                }
                $entry[1]['vary'] = isset($entry[1]['vary']) ? $entry[1]['vary'] : '';
                if ($vary != $entry[1]['vary'] || !$this->requestsMatch($vary, $entry[0], $persistedRequest)) {
                    $entries[] = $entry;
                }
            }
        }

        // Persist the response body if needed
        $bodyDigest = null;
        if ($response->getBody() && $response->getBody()->getContentLength() > 0) {
            $bodyDigest = $this->getBodyKey($request->getUrl(), $response->getBody());
            $this->cache->save($bodyDigest, (string) $response->getBody(), $ttl);
        }

        array_unshift($entries, array(
            $persistedRequest,
            $this->persistHeaders($response),
            $response->getStatusCode(),
            $bodyDigest,
            $currentTime + $ttl
        ));

        $this->cache->save($key, serialize($entries));
    }

    public function delete(RequestInterface $request)
    {
        $key = $this->getCacheKey($request);
        if ($entries = $this->cache->fetch($key)) {
            // Delete each cached body
            foreach (unserialize($entries) as $entry) {
                if ($entry[3]) {
                    $this->cache->delete($entry[3]);
                }
            }
            $this->cache->delete($key);
        }
    }

    public function purge($url)
    {
        foreach (array('GET', 'HEAD', 'POST', 'PUT', 'DELETE') as $method) {
            $this->delete(new Request($method, $url));
        }
    }

    public function fetch(RequestInterface $request)
    {
        $key = $this->getCacheKey($request);
        if (!($entries = $this->cache->fetch($key))) {
            return null;
        }

        $match = null;
        $headers = $this->persistHeaders($request);
        $entries = unserialize($entries);
        foreach ($entries as $index => $entry) {
            if ($this->requestsMatch(isset($entry[1]['vary']) ? $entry[1]['vary'] : '', $headers, $entry[0])) {
                $match = $entry;
                break;
            }
        }

        if (!$match) {
            return null;
        }

        // Ensure that the response is not expired
        $response = null;
        if ($match[4] < time()) {
            $response = -1;
        } else {
            $response = new Response($match[2], $match[1]);
            if ($match[3]) {
                if ($body = $this->cache->fetch($match[3])) {
                    $response->setBody($body);
                } else {
                    // The response is not valid because the body was somehow deleted
                    $response = -1;
                }
            }
        }

        if ($response === -1) {
            // Remove the entry from the metadata and update the cache
            unset($entries[$index]);
            if ($entries) {
                $this->cache->save($key, serialize($entries));
            } else {
                $this->cache->delete($key);
            }
            return null;
        }

        return $response;
    }

    /**
     * Hash a request URL into a string that returns cache metadata
     *
     * @param RequestInterface $request
     *
     * @return string
     */
    protected function getCacheKey(RequestInterface $request)
    {
        // Allow cache.key_filter to trim down the URL cache key by removing generate query string values (e.g. auth)
        if ($filter = $request->getParams()->get('cache.key_filter')) {
            $url = $request->getUrl(true);
            foreach (explode(',', $filter) as $remove) {
                $url->getQuery()->remove(trim($remove));
            }
        } else {
            $url = $request->getUrl();
        }

        return $this->keyPrefix . md5($request->getMethod() . ' ' . $url);
    }

    /**
     * Create a cache key for a response's body
     *
     * @param string              $url  URL of the entry
     * @param EntityBodyInterface $body Response body
     *
     * @return string
     */
    protected function getBodyKey($url, EntityBodyInterface $body)
    {
        return $this->keyPrefix . md5($url) . $body->getContentMd5();
    }

    /**
     * Determines whether two Request HTTP header sets are non-varying
     *
     * @param string $vary Response vary header
     * @param array  $r1   HTTP header array
     * @param array  $r2   HTTP header array
     *
     * @return bool
     */
    private function requestsMatch($vary, $r1, $r2)
    {
        if ($vary) {
            foreach (explode(',', $vary) as $header) {
                $key = trim(strtolower($header));
                $v1 = isset($r1[$key]) ? $r1[$key] : null;
                $v2 = isset($r2[$key]) ? $r2[$key] : null;
                if ($v1 !== $v2) {
                    return false;
                }
            }
        }

        return true;
    }

    /**
     * Creates an array of cacheable and normalized message headers
     *
     * @param MessageInterface $message
     *
     * @return array
     */
    private function persistHeaders(MessageInterface $message)
    {
        // Headers are excluded from the caching (see RFC 2616:13.5.1)
        static $noCache = array(
            'age' => true,
            'connection' => true,
            'keep-alive' => true,
            'proxy-authenticate' => true,
            'proxy-authorization' => true,
            'te' => true,
            'trailers' => true,
            'transfer-encoding' => true,
            'upgrade' => true,
            'set-cookie' => true,
            'set-cookie2' => true
        );

        // Clone the response to not destroy any necessary headers when caching
        $headers = $message->getHeaders()->getAll();
        $headers = array_diff_key($headers, $noCache);
        // Cast the headers to a string
        $headers = array_map(function ($h) { return (string) $h; }, $headers);

        return $headers;
    }
}
<?php

namespace Guzzle\Plugin\Cache;

\Guzzle\Common\Version::warn('Guzzle\Plugin\Cache\CacheKeyProviderInterface is no longer used');

/**
 * @deprecated This is no longer used
 * @codeCoverageIgnore
 */
interface CacheKeyProviderInterface {}
<?php

namespace Guzzle\Plugin\Cache;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response;
use Guzzle\Http\Exception\BadResponseException;

/**
 * Default revalidation strategy
 */
class DefaultRevalidation implements RevalidationInterface
{
    /** @var CacheStorageInterface Cache object storing cache data */
    protected $storage;

    /** @var CanCacheStrategyInterface */
    protected $canCache;

    /**
     * @param CacheStorageInterface     $cache    Cache storage
     * @param CanCacheStrategyInterface $canCache Determines if a message can be cached
     */
    public function __construct(CacheStorageInterface $cache, CanCacheStrategyInterface $canCache = null)
    {
        $this->storage = $cache;
        $this->canCache = $canCache ?: new DefaultCanCacheStrategy();
    }

    public function revalidate(RequestInterface $request, Response $response)
    {
        try {
            $revalidate = $this->createRevalidationRequest($request, $response);
            $validateResponse = $revalidate->send();
            if ($validateResponse->getStatusCode() == 200) {
                return $this->handle200Response($request, $validateResponse);
            } elseif ($validateResponse->getStatusCode() == 304) {
                return $this->handle304Response($request, $validateResponse, $response);
            }
        } catch (BadResponseException $e) {
            $this->handleBadResponse($e);
        }

        // Other exceptions encountered in the revalidation request are ignored
        // in hopes that sending a request to the origin server will fix it
        return false;
    }

    public function shouldRevalidate(RequestInterface $request, Response $response)
    {
        if ($request->getMethod() != RequestInterface::GET) {
            return false;
        }

        $reqCache = $request->getHeader('Cache-Control');
        $resCache = $response->getHeader('Cache-Control');

        $revalidate = $request->getHeader('Pragma') == 'no-cache' ||
            ($reqCache && ($reqCache->hasDirective('no-cache') || $reqCache->hasDirective('must-revalidate'))) ||
            ($resCache && ($resCache->hasDirective('no-cache') || $resCache->hasDirective('must-revalidate')));

        // Use the strong ETag validator if available and the response contains no Cache-Control directive
        if (!$revalidate && !$resCache && $response->hasHeader('ETag')) {
            $revalidate = true;
        }

        return $revalidate;
    }

    /**
     * Handles a bad response when attempting to revalidate
     *
     * @param BadResponseException $e Exception encountered
     *
     * @throws BadResponseException
     */
    protected function handleBadResponse(BadResponseException $e)
    {
        // 404 errors mean the resource no longer exists, so remove from
        // cache, and prevent an additional request by throwing the exception
        if ($e->getResponse()->getStatusCode() == 404) {
            $this->storage->delete($e->getRequest());
            throw $e;
        }
    }

    /**
     * Creates a request to use for revalidation
     *
     * @param RequestInterface $request  Request
     * @param Response         $response Response to revalidate
     *
     * @return RequestInterface returns a revalidation request
     */
    protected function createRevalidationRequest(RequestInterface $request, Response $response)
    {
        $revalidate = clone $request;
        $revalidate->removeHeader('Pragma')->removeHeader('Cache-Control');

        if ($response->getLastModified()) {
            $revalidate->setHeader('If-Modified-Since', $response->getLastModified());
        }

        if ($response->getEtag()) {
            $revalidate->setHeader('If-None-Match', $response->getEtag());
        }

        // Remove any cache plugins that might be on the request to prevent infinite recursive revalidations
        $dispatcher = $revalidate->getEventDispatcher();
        foreach ($dispatcher->getListeners() as $eventName => $listeners) {
            foreach ($listeners as $listener) {
                if (is_array($listener) && $listener[0] instanceof CachePlugin) {
                    $dispatcher->removeListener($eventName, $listener);
                }
            }
        }

        return $revalidate;
    }

    /**
     * Handles a 200 response response from revalidating. The server does not support validation, so use this response.
     *
     * @param RequestInterface $request          Request that was sent
     * @param Response         $validateResponse Response received
     *
     * @return bool Returns true if valid, false if invalid
     */
    protected function handle200Response(RequestInterface $request, Response $validateResponse)
    {
        $request->setResponse($validateResponse);
        if ($this->canCache->canCacheResponse($validateResponse)) {
            $this->storage->cache($request, $validateResponse);
        }

        return false;
    }

    /**
     * Handle a 304 response and ensure that it is still valid
     *
     * @param RequestInterface $request          Request that was sent
     * @param Response         $validateResponse Response received
     * @param Response         $response         Original cached response
     *
     * @return bool Returns true if valid, false if invalid
     */
    protected function handle304Response(RequestInterface $request, Response $validateResponse, Response $response)
    {
        static $replaceHeaders = array('Date', 'Expires', 'Cache-Control', 'ETag', 'Last-Modified');

        // Make sure that this response has the same ETag
        if ($validateResponse->getEtag() != $response->getEtag()) {
            return false;
        }

        // Replace cached headers with any of these headers from the
        // origin server that might be more up to date
        $modified = false;
        foreach ($replaceHeaders as $name) {
            if ($validateResponse->hasHeader($name)) {
                $modified = true;
                $response->setHeader($name, $validateResponse->getHeader($name));
            }
        }

        // Store the updated response in cache
        if ($modified && $this->canCache->canCacheResponse($response)) {
            $this->storage->cache($request, $response);
        }

        return true;
    }
}
{
    "name": "guzzle/plugin",
    "description": "Guzzle plugin component containing all Guzzle HTTP plugins",
    "homepage": "http://guzzlephp.org/",
    "keywords": ["http", "client", "plugin", "extension", "guzzle"],
    "license": "MIT",
    "authors": [
        {
            "name": "Michael Dowling",
            "email": "mtdowling@gmail.com",
            "homepage": "https://github.com/mtdowling"
        }
    ],
    "require": {
        "php": ">=5.3.2",
        "guzzle/http": "self.version"
    },
    "suggest": {
        "guzzle/cache": "self.version",
        "guzzle/log": "self.version"
    },
    "autoload": {
        "psr-0": { "Guzzle\\Plugin": "" }
    },
    "target-dir": "Guzzle/Plugin",
    "replace": {
        "guzzle/plugin-async": "self.version",
        "guzzle/plugin-backoff": "self.version",
        "guzzle/plugin-cache": "self.version",
        "guzzle/plugin-cookie": "self.version",
        "guzzle/plugin-curlauth": "self.version",
        "guzzle/plugin-error-response": "self.version",
        "guzzle/plugin-history": "self.version",
        "guzzle/plugin-log": "self.version",
        "guzzle/plugin-md5": "self.version",
        "guzzle/plugin-mock": "self.version",
        "guzzle/plugin-oauth": "self.version"
    },
    "extra": {
        "branch-alias": {
            "dev-master": "3.7-dev"
        }
    }
}
{
    "name": "guzzle/plugin-history",
    "description": "Guzzle history plugin",
    "homepage": "http://guzzlephp.org/",
    "keywords": ["plugin", "guzzle"],
    "license": "MIT",
    "authors": [
        {
            "name": "Michael Dowling",
            "email": "mtdowling@gmail.com",
            "homepage": "https://github.com/mtdowling"
        }
    ],
    "require": {
        "php": ">=5.3.2",
        "guzzle/http": "self.version"
    },
    "autoload": {
        "psr-0": { "Guzzle\\Plugin\\History": "" }
    },
    "target-dir": "Guzzle/Plugin/History",
    "extra": {
        "branch-alias": {
            "dev-master": "3.7-dev"
        }
    }
}
<?php

namespace Guzzle\Plugin\History;

use Guzzle\Common\Event;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Maintains a list of requests and responses sent using a request or client
 */
class HistoryPlugin implements EventSubscriberInterface, \IteratorAggregate, \Countable
{
    /** @var int The maximum number of requests to maintain in the history */
    protected $limit = 10;

    /** @var array Requests and responses that have passed through the plugin */
    protected $transactions = array();

    public static function getSubscribedEvents()
    {
        return array('request.sent' => array('onRequestSent', 9999));
    }

    /**
     * Convert to a string that contains all request and response headers
     *
     * @return string
     */
    public function __toString()
    {
        $lines = array();
        foreach ($this->transactions as $entry) {
            $response = isset($entry['response']) ? $entry['response'] : '';
            $lines[] = '> ' . trim($entry['request']) . "\n\n< " . trim($response) . "\n";
        }

        return implode("\n", $lines);
    }

    /**
     * Add a request to the history
     *
     * @param RequestInterface $request  Request to add
     * @param Response         $response Response of the request
     *
     * @return HistoryPlugin
     */
    public function add(RequestInterface $request, Response $response = null)
    {
        if (!$response && $request->getResponse()) {
            $response = $request->getResponse();
        }

        $this->transactions[] = array('request' => $request, 'response' => $response);
        if (count($this->transactions) > $this->getlimit()) {
            array_shift($this->transactions);
        }

        return $this;
    }

    /**
     * Set the max number of requests to store
     *
     * @param int $limit Limit
     *
     * @return HistoryPlugin
     */
    public function setLimit($limit)
    {
        $this->limit = (int) $limit;

        return $this;
    }

    /**
     * Get the request limit
     *
     * @return int
     */
    public function getLimit()
    {
        return $this->limit;
    }

    /**
     * Get all of the raw transactions in the form of an array of associative arrays containing
     * 'request' and 'response' keys.
     *
     * @return array
     */
    public function getAll()
    {
        return $this->transactions;
    }

    /**
     * Get the requests in the history
     *
     * @return \ArrayIterator
     */
    public function getIterator()
    {
        // Return an iterator just like the old iteration of the HistoryPlugin for BC compatibility (use getAll())
        return new \ArrayIterator(array_map(function ($entry) {
            $entry['request']->getParams()->set('actual_response', $entry['response']);
            return $entry['request'];
        }, $this->transactions));
    }

    /**
     * Get the number of requests in the history
     *
     * @return int
     */
    public function count()
    {
        return count($this->transactions);
    }

    /**
     * Get the last request sent
     *
     * @return RequestInterface
     */
    public function getLastRequest()
    {
        $last = end($this->transactions);

        return $last['request'];
    }

    /**
     * Get the last response in the history
     *
     * @return Response|null
     */
    public function getLastResponse()
    {
        $last = end($this->transactions);

        return isset($last['response']) ? $last['response'] : null;
    }

    /**
     * Clears the history
     *
     * @return HistoryPlugin
     */
    public function clear()
    {
        $this->transactions = array();

        return $this;
    }

    public function onRequestSent(Event $event)
    {
        $this->add($event['request'], $event['response']);
    }
}
<?php

namespace Guzzle\Plugin\Mock;

use Guzzle\Common\Event;
use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Common\AbstractHasDispatcher;
use Guzzle\Http\Exception\CurlException;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\EntityEnclosingRequestInterface;
use Guzzle\Http\Message\Response;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Queues mock responses or exceptions and delivers mock responses or exceptions in a fifo order.
 */
class MockPlugin extends AbstractHasDispatcher implements EventSubscriberInterface, \Countable
{
    /** @var array Array of mock responses / exceptions */
    protected $queue = array();

    /** @var bool Whether or not to remove the plugin when the queue is empty */
    protected $temporary = false;

    /** @var array Array of requests that were mocked */
    protected $received = array();

    /** @var bool Whether or not to consume an entity body when a mock response is served */
    protected $readBodies;

    /**
     * @param array $items      Array of responses or exceptions to queue
     * @param bool  $temporary  Set to TRUE to remove the plugin when the queue is empty
     * @param bool  $readBodies Set to TRUE to consume the entity body when a mock is served
     */
    public function __construct(array $items = null, $temporary = false, $readBodies = false)
    {
        $this->readBodies = $readBodies;
        $this->temporary = $temporary;
        if ($items) {
            foreach ($items as $item) {
                if ($item instanceof \Exception) {
                    $this->addException($item);
                } else {
                    $this->addResponse($item);
                }
            }
        }
    }

    public static function getSubscribedEvents()
    {
        // Use a number lower than the CachePlugin
        return array('request.before_send' => array('onRequestBeforeSend', -999));
    }

    public static function getAllEvents()
    {
        return array('mock.request');
    }

    /**
     * Get a mock response from a file
     *
     * @param string $path File to retrieve a mock response from
     *
     * @return Response
     * @throws InvalidArgumentException if the file is not found
     */
    public static function getMockFile($path)
    {
        if (!file_exists($path)) {
            throw new InvalidArgumentException('Unable to open mock file: ' . $path);
        }

        return Response::fromMessage(file_get_contents($path));
    }

    /**
     * Set whether or not to consume the entity body of a request when a mock
     * response is used
     *
     * @param bool $readBodies Set to true to read and consume entity bodies
     *
     * @return self
     */
    public function readBodies($readBodies)
    {
        $this->readBodies = $readBodies;

        return $this;
    }

    /**
     * Returns the number of remaining mock responses
     *
     * @return int
     */
    public function count()
    {
        return count($this->queue);
    }

    /**
     * Add a response to the end of the queue
     *
     * @param string|Response $response Response object or path to response file
     *
     * @return MockPlugin
     * @throws InvalidArgumentException if a string or Response is not passed
     */
    public function addResponse($response)
    {
        if (!($response instanceof Response)) {
            if (!is_string($response)) {
                throw new InvalidArgumentException('Invalid response');
            }
            $response = self::getMockFile($response);
        }

        $this->queue[] = $response;

        return $this;
    }

    /**
     * Add an exception to the end of the queue
     *
     * @param CurlException $e Exception to throw when the request is executed
     *
     * @return MockPlugin
     */
    public function addException(CurlException $e)
    {
        $this->queue[] = $e;

        return $this;
    }

    /**
     * Clear the queue
     *
     * @return MockPlugin
     */
    public function clearQueue()
    {
        $this->queue = array();

        return $this;
    }

    /**
     * Returns an array of mock responses remaining in the queue
     *
     * @return array
     */
    public function getQueue()
    {
        return $this->queue;
    }

    /**
     * Check if this is a temporary plugin
     *
     * @return bool
     */
    public function isTemporary()
    {
        return $this->temporary;
    }

    /**
     * Get a response from the front of the list and add it to a request
     *
     * @param RequestInterface $request Request to mock
     *
     * @return self
     * @throws CurlException When request.send is called and an exception is queued
     */
    public function dequeue(RequestInterface $request)
    {
        $this->dispatch('mock.request', array('plugin' => $this, 'request' => $request));

        $item = array_shift($this->queue);
        if ($item instanceof Response) {
            if ($this->readBodies && $request instanceof EntityEnclosingRequestInterface) {
                $request->getEventDispatcher()->addListener('request.sent', $f = function (Event $event) use (&$f) {
                    while ($data = $event['request']->getBody()->read(8096));
                    // Remove the listener after one-time use
                    $event['request']->getEventDispatcher()->removeListener('request.sent', $f);
                });
            }
            $request->setResponse($item);
        } elseif ($item instanceof CurlException) {
            // Emulates exceptions encountered while transferring requests
            $item->setRequest($request);
            $state = $request->setState(RequestInterface::STATE_ERROR, array('exception' => $item));
            // Only throw if the exception wasn't handled
            if ($state == RequestInterface::STATE_ERROR) {
                throw $item;
            }
        }

        return $this;
    }

    /**
     * Clear the array of received requests
     */
    public function flush()
    {
        $this->received = array();
    }

    /**
     * Get an array of requests that were mocked by this plugin
     *
     * @return array
     */
    public function getReceivedRequests()
    {
        return $this->received;
    }

    /**
     * Called when a request is about to be sent
     *
     * @param Event $event
     * @throws \OutOfBoundsException When queue is empty
     */
    public function onRequestBeforeSend(Event $event)
    {
        if (!$this->queue) {
            throw new \OutOfBoundsException('Mock queue is empty');
        }

        $request = $event['request'];
        $this->received[] = $request;
        // Detach the filter from the client so it's a one-time use
        if ($this->temporary && count($this->queue) == 1 && $request->getClient()) {
            $request->getClient()->getEventDispatcher()->removeSubscriber($this);
        }
        $this->dequeue($request);
    }
}
{
    "name": "guzzle/plugin-mock",
    "description": "Guzzle Mock plugin",
    "homepage": "http://guzzlephp.org/",
    "keywords": ["mock", "plugin", "guzzle"],
    "license": "MIT",
    "authors": [
        {
            "name": "Michael Dowling",
            "email": "mtdowling@gmail.com",
            "homepage": "https://github.com/mtdowling"
        }
    ],
    "require": {
        "php": ">=5.3.2",
        "guzzle/http": "self.version"
    },
    "autoload": {
        "psr-0": { "Guzzle\\Plugin\\Mock": "" }
    },
    "target-dir": "Guzzle/Plugin/Mock",
    "extra": {
        "branch-alias": {
            "dev-master": "3.7-dev"
        }
    }
}
{
    "name": "guzzle/plugin-oauth",
    "description": "Guzzle OAuth plugin",
    "homepage": "http://guzzlephp.org/",
    "keywords": ["oauth", "plugin", "guzzle"],
    "license": "MIT",
    "authors": [
        {
            "name": "Michael Dowling",
            "email": "mtdowling@gmail.com",
            "homepage": "https://github.com/mtdowling"
        }
    ],
    "require": {
        "php": ">=5.3.2",
        "guzzle/http": "self.version"
    },
    "autoload": {
        "psr-0": { "Guzzle\\Plugin\\Oauth": "" }
    },
    "target-dir": "Guzzle/Plugin/Oauth",
    "extra": {
        "branch-alias": {
            "dev-master": "3.7-dev"
        }
    }
}
<?php

namespace Guzzle\Plugin\Oauth;

use Guzzle\Common\Event;
use Guzzle\Common\Collection;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\EntityEnclosingRequestInterface;
use Guzzle\Http\QueryString;
use Guzzle\Http\Url;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * OAuth signing plugin
 * @link http://oauth.net/core/1.0/#rfc.section.9.1.1
 */
class OauthPlugin implements EventSubscriberInterface
{
    /**
     * Consumer request method constants. See http://oauth.net/core/1.0/#consumer_req_param
     */
    const REQUEST_METHOD_HEADER = 'header';
    const REQUEST_METHOD_QUERY  = 'query';

    /** @var Collection Configuration settings */
    protected $config;

    /**
     * Create a new OAuth 1.0 plugin
     *
     * @param array $config Configuration array containing these parameters:
     *     - string 'request_method'       Consumer request method. Use the class constants.
     *     - string 'callback'             OAuth callback
     *     - string 'consumer_key'         Consumer key
     *     - string 'consumer_secret'      Consumer secret
     *     - string 'token'                Token
     *     - string 'token_secret'         Token secret
     *     - string 'verifier'             OAuth verifier.
     *     - string 'version'              OAuth version.  Defaults to 1.0
     *     - string 'signature_method'     Custom signature method
     *     - bool   'disable_post_params'  Set to true to prevent POST parameters from being signed
     *     - array|Closure 'signature_callback' Custom signature callback that accepts a string to sign and a signing key
     */
    public function __construct($config)
    {
        $this->config = Collection::fromConfig($config, array(
            'version' => '1.0',
            'request_method' => self::REQUEST_METHOD_HEADER,
            'consumer_key' => 'anonymous',
            'consumer_secret' => 'anonymous',
            'signature_method' => 'HMAC-SHA1',
            'signature_callback' => function($stringToSign, $key) {
                return hash_hmac('sha1', $stringToSign, $key, true);
            }
        ), array(
            'signature_method', 'signature_callback', 'version',
            'consumer_key', 'consumer_secret'
        ));
    }

    public static function getSubscribedEvents()
    {
        return array(
            'request.before_send' => array('onRequestBeforeSend', -1000)
        );
    }

    /**
     * Request before-send event handler
     *
     * @param Event $event Event received
     * @return array
     * @throws \InvalidArgumentException
     */
    public function onRequestBeforeSend(Event $event)
    {
        $timestamp = $this->getTimestamp($event);
        $request = $event['request'];
        $nonce = $this->generateNonce($request);
        $authorizationParams = $this->getOauthParams($timestamp, $nonce);
        $authorizationParams['oauth_signature']  = $this->getSignature($request, $timestamp, $nonce);

        switch ($this->config['request_method']) {
            case self::REQUEST_METHOD_HEADER:
                $request->setHeader(
                    'Authorization',
                    $this->buildAuthorizationHeader($authorizationParams)
                );
                break;
            case self::REQUEST_METHOD_QUERY:
                foreach ($authorizationParams as $key => $value) {
                    $request->getQuery()->set($key, $value);
                }
                break;
            default:
                throw new \InvalidArgumentException(sprintf(
                    'Invalid consumer method "%s"',
                    $this->config['request_method']
                ));
        }

        return $authorizationParams;
    }

    /**
     * Builds the Authorization header for a request
     *
     * @param array $authorizationParams Associative array of authorization parameters
     *
     * @return string
     */
    private function buildAuthorizationHeader($authorizationParams)
    {
        $authorizationString = 'OAuth ';
        foreach ($authorizationParams as $key => $val) {
            if ($val) {
                $authorizationString .= $key . '="' . urlencode($val) . '", ';
            }
        }

        return substr($authorizationString, 0, -2);
    }

    /**
     * Calculate signature for request
     *
     * @param RequestInterface $request   Request to generate a signature for
     * @param integer          $timestamp Timestamp to use for nonce
     * @param string           $nonce
     *
     * @return string
     */
    public function getSignature(RequestInterface $request, $timestamp, $nonce)
    {
        $string = $this->getStringToSign($request, $timestamp, $nonce);
        $key = urlencode($this->config['consumer_secret']) . '&' . urlencode($this->config['token_secret']);

        return base64_encode(call_user_func($this->config['signature_callback'], $string, $key));
    }

    /**
     * Calculate string to sign
     *
     * @param RequestInterface $request   Request to generate a signature for
     * @param int              $timestamp Timestamp to use for nonce
     * @param string           $nonce
     *
     * @return string
     */
    public function getStringToSign(RequestInterface $request, $timestamp, $nonce)
    {
        $params = $this->getParamsToSign($request, $timestamp, $nonce);

        // Convert booleans to strings.
        $params = $this->prepareParameters($params);

        // Build signing string from combined params
        $parameterString = clone $request->getQuery();
        $parameterString->replace($params);

        $url = Url::factory($request->getUrl())->setQuery('')->setFragment(null);

        return strtoupper($request->getMethod()) . '&'
             . rawurlencode($url) . '&'
             . rawurlencode((string) $parameterString);
    }

    /**
     * Get the oauth parameters as named by the oauth spec
     *
     * @param $timestamp
     * @param $nonce
     * @return Collection
     */
    protected function getOauthParams($timestamp, $nonce)
    {
        $params = new Collection(array(
            'oauth_consumer_key'     => $this->config['consumer_key'],
            'oauth_nonce'            => $nonce,
            'oauth_signature_method' => $this->config['signature_method'],
            'oauth_timestamp'        => $timestamp,
        ));

        // Optional parameters should not be set if they have not been set in the config as
        // the parameter may be considered invalid by the Oauth service.
        $optionalParams = array(
            'callback'  => 'oauth_callback',
            'token'     => 'oauth_token',
            'verifier'  => 'oauth_verifier',
            'version'   => 'oauth_version'
        );

        foreach ($optionalParams as $optionName => $oauthName) {
            if (isset($this->config[$optionName]) == true) {
                $params[$oauthName] = $this->config[$optionName];
            }
        }

        return $params;
    }

    /**
     * Get all of the parameters required to sign a request including:
     * * The oauth params
     * * The request GET params
     * * The params passed in the POST body (with a content-type of application/x-www-form-urlencoded)
     *
     * @param RequestInterface $request   Request to generate a signature for
     * @param integer          $timestamp Timestamp to use for nonce
     * @param string           $nonce
     *
     * @return array
     */
    public function getParamsToSign(RequestInterface $request, $timestamp, $nonce)
    {
        $params = $this->getOauthParams($timestamp, $nonce);

        // Add query string parameters
        $params->merge($request->getQuery());

        // Add POST fields to signing string if required
        if ($this->shouldPostFieldsBeSigned($request))
        {
            $params->merge($request->getPostFields());
        }

        // Sort params
        $params = $params->toArray();
        uksort($params, 'strcmp');

        return $params;
    }

    /**
     * Decide whether the post fields should be added to the base string that Oauth signs.
     * This implementation is correct. Non-conformant APIs may require that this method be
     * overwritten e.g. the Flickr API incorrectly adds the post fields when the Content-Type
     * is 'application/x-www-form-urlencoded'
     *
     * @param $request
     * @return bool Whether the post fields should be signed or not
     */
    public function shouldPostFieldsBeSigned($request)
    {
        if (!$this->config->get('disable_post_params') &&
            $request instanceof EntityEnclosingRequestInterface &&
            false !== strpos($request->getHeader('Content-Type'), 'application/x-www-form-urlencoded'))
        {
            return true;
        }

        return false;
    }

    /**
     * Returns a Nonce Based on the unique id and URL. This will allow for multiple requests in parallel with the same
     * exact timestamp to use separate nonce's.
     *
     * @param RequestInterface $request Request to generate a nonce for
     *
     * @return string
     */
    public function generateNonce(RequestInterface $request)
    {
        return sha1(uniqid('', true) . $request->getUrl());
    }

    /**
     * Gets timestamp from event or create new timestamp
     *
     * @param Event $event Event containing contextual information
     *
     * @return int
     */
    public function getTimestamp(Event $event)
    {
       return $event['timestamp'] ?: time();
    }

    /**
     * Convert booleans to strings, removed unset parameters, and sorts the array
     *
     * @param array $data Data array
     *
     * @return array
     */
    protected function prepareParameters($data)
    {
        ksort($data);
        foreach ($data as $key => &$value) {
            switch (gettype($value)) {
                case 'NULL':
                    unset($data[$key]);
                    break;
                case 'array':
                    $data[$key] = self::prepareParameters($value);
                    break;
                case 'boolean':
                    $data[$key] = $value ? 'true' : 'false';
                    break;
            }
        }

        return $data;
    }
}
{
    "name": "guzzle/plugin-log",
    "description": "Guzzle log plugin for over the wire logging",
    "homepage": "http://guzzlephp.org/",
    "keywords": ["plugin", "log", "guzzle"],
    "license": "MIT",
    "authors": [
        {
            "name": "Michael Dowling",
            "email": "mtdowling@gmail.com",
            "homepage": "https://github.com/mtdowling"
        }
    ],
    "require": {
        "php": ">=5.3.2",
        "guzzle/http": "self.version",
        "guzzle/log": "self.version"
    },
    "autoload": {
        "psr-0": { "Guzzle\\Plugin\\Log": "" }
    },
    "target-dir": "Guzzle/Plugin/Log",
    "extra": {
        "branch-alias": {
            "dev-master": "3.7-dev"
        }
    }
}
<?php

namespace Guzzle\Plugin\Log;

use Guzzle\Common\Event;
use Guzzle\Log\LogAdapterInterface;
use Guzzle\Log\MessageFormatter;
use Guzzle\Log\ClosureLogAdapter;
use Guzzle\Http\EntityBody;
use Guzzle\Http\Message\EntityEnclosingRequestInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Plugin class that will add request and response logging to an HTTP request.
 *
 * The log plugin uses a message formatter that allows custom messages via template variable substitution.
 *
 * @see MessageLogger for a list of available log template variable substitutions
 */
class LogPlugin implements EventSubscriberInterface
{
    /** @var LogAdapterInterface Adapter responsible for writing log data */
    protected $logAdapter;

    /** @var MessageFormatter Formatter used to format messages before logging */
    protected $formatter;

    /** @var bool Whether or not to wire request and response bodies */
    protected $wireBodies;

    /**
     * @param LogAdapterInterface     $logAdapter Adapter object used to log message
     * @param string|MessageFormatter $formatter  Formatter used to format log messages or the formatter template
     * @param bool                    $wireBodies Set to true to track request and response bodies using a temporary
     *                                            buffer if the bodies are not repeatable.
     */
    public function __construct(
        LogAdapterInterface $logAdapter,
        $formatter = null,
        $wireBodies = false
    ) {
        $this->logAdapter = $logAdapter;
        $this->formatter = $formatter instanceof MessageFormatter ? $formatter : new MessageFormatter($formatter);
        $this->wireBodies = $wireBodies;
    }

    /**
     * Get a log plugin that outputs full request, response, and curl error information to stderr
     *
     * @param bool     $wireBodies Set to false to disable request/response body output when they use are not repeatable
     * @param resource $stream     Stream to write to when logging. Defaults to STDERR when it is available
     *
     * @return self
     */
    public static function getDebugPlugin($wireBodies = true, $stream = null)
    {
        if ($stream === null) {
            if (defined('STDERR')) {
                $stream = STDERR;
            } else {
                $stream = fopen('php://output', 'w');
            }
        }

        return new self(new ClosureLogAdapter(function ($m) use ($stream) {
            fwrite($stream, $m . PHP_EOL);
        }), "# Request:\n{request}\n\n# Response:\n{response}\n\n# Errors: {curl_code} {curl_error}", $wireBodies);
    }

    public static function getSubscribedEvents()
    {
        return array(
            'curl.callback.write' => array('onCurlWrite', 255),
            'curl.callback.read'  => array('onCurlRead', 255),
            'request.before_send' => array('onRequestBeforeSend', 255),
            'request.sent'        => array('onRequestSent', 255)
        );
    }

    /**
     * Event triggered when curl data is read from a request
     *
     * @param Event $event
     */
    public function onCurlRead(Event $event)
    {
        // Stream the request body to the log if the body is not repeatable
        if ($wire = $event['request']->getParams()->get('request_wire')) {
            $wire->write($event['read']);
        }
    }

    /**
     * Event triggered when curl data is written to a response
     *
     * @param Event $event
     */
    public function onCurlWrite(Event $event)
    {
        // Stream the response body to the log if the body is not repeatable
        if ($wire = $event['request']->getParams()->get('response_wire')) {
            $wire->write($event['write']);
        }
    }

    /**
     * Called before a request is sent
     *
     * @param Event $event
     */
    public function onRequestBeforeSend(Event $event)
    {
        if ($this->wireBodies) {
            $request = $event['request'];
            // Ensure that curl IO events are emitted
            $request->getCurlOptions()->set('emit_io', true);
            // We need to make special handling for content wiring and non-repeatable streams.
            if ($request instanceof EntityEnclosingRequestInterface && $request->getBody()
                && (!$request->getBody()->isSeekable() || !$request->getBody()->isReadable())
            ) {
                // The body of the request cannot be recalled so logging the body will require us to buffer it
                $request->getParams()->set('request_wire', EntityBody::factory());
            }
            if (!$request->getResponseBody()->isRepeatable()) {
                // The body of the response cannot be recalled so logging the body will require us to buffer it
                $request->getParams()->set('response_wire', EntityBody::factory());
            }
        }
    }

    /**
     * Triggers the actual log write when a request completes
     *
     * @param Event $event
     */
    public function onRequestSent(Event $event)
    {
        $request = $event['request'];
        $response = $event['response'];
        $handle = $event['handle'];

        if ($wire = $request->getParams()->get('request_wire')) {
            $request = clone $request;
            $request->setBody($wire);
        }

        if ($wire = $request->getParams()->get('response_wire')) {
            $response = clone $response;
            $response->setBody($wire);
        }

        // Send the log message to the adapter, adding a category and host
        $priority = $response && $response->isError() ? LOG_ERR : LOG_DEBUG;
        $message = $this->formatter->format($request, $response, $handle);
        $this->logAdapter->log($message, $priority, array(
            'request'  => $request,
            'response' => $response,
            'handle'   => $handle
        ));
    }
}
<?php

namespace Guzzle\Plugin\Cookie;

use Guzzle\Common\Event;
use Guzzle\Plugin\Cookie\CookieJar\ArrayCookieJar;
use Guzzle\Plugin\Cookie\CookieJar\CookieJarInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Adds, extracts, and persists cookies between HTTP requests
 */
class CookiePlugin implements EventSubscriberInterface
{
    /** @var CookieJarInterface Cookie cookieJar used to hold cookies */
    protected $cookieJar;

    /**
     * @param CookieJarInterface $cookieJar Cookie jar used to hold cookies. Creates an ArrayCookieJar by default.
     */
    public function __construct(CookieJarInterface $cookieJar = null)
    {
        $this->cookieJar = $cookieJar ?: new ArrayCookieJar();
    }

    public static function getSubscribedEvents()
    {
        return array(
            'request.before_send' => array('onRequestBeforeSend', 125),
            'request.sent'        => array('onRequestSent', 125)
        );
    }

    /**
     * Get the cookie cookieJar
     *
     * @return CookieJarInterface
     */
    public function getCookieJar()
    {
        return $this->cookieJar;
    }

    /**
     * Add cookies before a request is sent
     *
     * @param Event $event
     */
    public function onRequestBeforeSend(Event $event)
    {
        $request = $event['request'];
        if (!$request->getParams()->get('cookies.disable')) {
            $request->removeHeader('Cookie');
            // Find cookies that match this request
            foreach ($this->cookieJar->getMatchingCookies($request) as $cookie) {
                $request->addCookie($cookie->getName(), $cookie->getValue());
            }
        }
    }

    /**
     * Extract cookies from a sent request
     *
     * @param Event $event
     */
    public function onRequestSent(Event $event)
    {
        $this->cookieJar->addCookiesFromResponse($event['response'], $event['request']);
    }
}
<?php

namespace Guzzle\Plugin\Cookie\Exception;

use Guzzle\Common\Exception\InvalidArgumentException;

class InvalidCookieException extends InvalidArgumentException {}
<?php

namespace Guzzle\Plugin\Cookie\CookieJar;

use Guzzle\Common\Exception\RuntimeException;

/**
 * Persists non-session cookies using a JSON formatted file
 */
class FileCookieJar extends ArrayCookieJar
{
    /** @var string filename */
    protected $filename;

    /**
     * Create a new FileCookieJar object
     *
     * @param string $cookieFile File to store the cookie data
     *
     * @throws RuntimeException if the file cannot be found or created
     */
    public function __construct($cookieFile)
    {
        $this->filename = $cookieFile;
        $this->load();
    }

    /**
     * Saves the file when shutting down
     */
    public function __destruct()
    {
        $this->persist();
    }

    /**
     * Save the contents of the data array to the file
     *
     * @throws RuntimeException if the file cannot be found or created
     */
    protected function persist()
    {
        if (false === file_put_contents($this->filename, $this->serialize())) {
            // @codeCoverageIgnoreStart
            throw new RuntimeException('Unable to open file ' . $this->filename);
            // @codeCoverageIgnoreEnd
        }
    }

    /**
     * Load the contents of the json formatted file into the data array and discard any unsaved state
     */
    protected function load()
    {
        $json = file_get_contents($this->filename);
        if (false === $json) {
            // @codeCoverageIgnoreStart
            throw new RuntimeException('Unable to open file ' . $this->filename);
            // @codeCoverageIgnoreEnd
        }

        $this->unserialize($json);
        $this->cookies = $this->cookies ?: array();
    }
}
<?php

namespace Guzzle\Plugin\Cookie\CookieJar;

use Guzzle\Plugin\Cookie\Cookie;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response;
use Guzzle\Parser\ParserRegistry;
use Guzzle\Plugin\Cookie\Exception\InvalidCookieException;

/**
 * Cookie cookieJar that stores cookies an an array
 */
class ArrayCookieJar implements CookieJarInterface, \Serializable
{
    /** @var array Loaded cookie data */
    protected $cookies = array();

    /** @var bool Whether or not strict mode is enabled. When enabled, exceptions will be thrown for invalid cookies */
    protected $strictMode;

    /**
     * @param bool $strictMode Set to true to throw exceptions when invalid cookies are added to the cookie jar
     */
    public function __construct($strictMode = false)
    {
        $this->strictMode = $strictMode;
    }

    /**
     * Enable or disable strict mode on the cookie jar
     *
     * @param bool $strictMode Set to true to throw exceptions when invalid cookies are added. False to ignore them.
     *
     * @return self
     */
    public function setStrictMode($strictMode)
    {
        $this->strictMode = $strictMode;
    }

    public function remove($domain = null, $path = null, $name = null)
    {
        $cookies = $this->all($domain, $path, $name, false, false);
        $this->cookies = array_filter($this->cookies, function (Cookie $cookie) use ($cookies) {
            return !in_array($cookie, $cookies, true);
        });

        return $this;
    }

    public function removeTemporary()
    {
        $this->cookies = array_filter($this->cookies, function (Cookie $cookie) {
            return !$cookie->getDiscard() && $cookie->getExpires();
        });

        return $this;
    }

    public function removeExpired()
    {
        $currentTime = time();
        $this->cookies = array_filter($this->cookies, function (Cookie $cookie) use ($currentTime) {
            return !$cookie->getExpires() || $currentTime < $cookie->getExpires();
        });

        return $this;
    }

    public function all($domain = null, $path = null, $name = null, $skipDiscardable = false, $skipExpired = true)
    {
        return array_values(array_filter($this->cookies, function (Cookie $cookie) use (
            $domain,
            $path,
            $name,
            $skipDiscardable,
            $skipExpired
        ) {
            return false === (($name && $cookie->getName() != $name) ||
                ($skipExpired && $cookie->isExpired()) ||
                ($skipDiscardable && ($cookie->getDiscard() || !$cookie->getExpires())) ||
                ($path && !$cookie->matchesPath($path)) ||
                ($domain && !$cookie->matchesDomain($domain)));
        }));
    }

    public function add(Cookie $cookie)
    {
        // Only allow cookies with set and valid domain, name, value
        $result = $cookie->validate();
        if ($result !== true) {
            if ($this->strictMode) {
                throw new InvalidCookieException($result);
            } else {
                $this->removeCookieIfEmpty($cookie);
                return false;
            }
        }

        // Resolve conflicts with previously set cookies
        foreach ($this->cookies as $i => $c) {

            // Two cookies are identical, when their path, domain, port and name are identical
            if ($c->getPath() != $cookie->getPath() ||
                $c->getDomain() != $cookie->getDomain() ||
                $c->getPorts() != $cookie->getPorts() ||
                $c->getName() != $cookie->getName()
            ) {
                continue;
            }

            // The previously set cookie is a discard cookie and this one is not so allow the new cookie to be set
            if (!$cookie->getDiscard() && $c->getDiscard()) {
                unset($this->cookies[$i]);
                continue;
            }

            // If the new cookie's expiration is further into the future, then replace the old cookie
            if ($cookie->getExpires() > $c->getExpires()) {
                unset($this->cookies[$i]);
                continue;
            }

            // If the value has changed, we better change it
            if ($cookie->getValue() !== $c->getValue()) {
                unset($this->cookies[$i]);
                continue;
            }

            // The cookie exists, so no need to continue
            return false;
        }

        $this->cookies[] = $cookie;

        return true;
    }

    /**
     * Serializes the cookie cookieJar
     *
     * @return string
     */
    public function serialize()
    {
        // Only serialize long term cookies and unexpired cookies
        return json_encode(array_map(function (Cookie $cookie) {
            return $cookie->toArray();
        }, $this->all(null, null, null, true, true)));
    }

    /**
     * Unserializes the cookie cookieJar
     */
    public function unserialize($data)
    {
        $data = json_decode($data, true);
        if (empty($data)) {
            $this->cookies = array();
        } else {
            $this->cookies = array_map(function (array $cookie) {
                return new Cookie($cookie);
            }, $data);
        }
    }

    /**
     * Returns the total number of stored cookies
     *
     * @return int
     */
    public function count()
    {
        return count($this->cookies);
    }

    /**
     * Returns an iterator
     *
     * @return \ArrayIterator
     */
    public function getIterator()
    {
        return new \ArrayIterator($this->cookies);
    }

    public function addCookiesFromResponse(Response $response, RequestInterface $request = null)
    {
        if ($cookieHeader = $response->getHeader('Set-Cookie')) {
            $parser = ParserRegistry::getInstance()->getParser('cookie');
            foreach ($cookieHeader as $cookie) {
                if ($parsed = $request
                    ? $parser->parseCookie($cookie, $request->getHost(), $request->getPath())
                    : $parser->parseCookie($cookie)
                ) {
                    // Break up cookie v2 into multiple cookies
                    foreach ($parsed['cookies'] as $key => $value) {
                        $row = $parsed;
                        $row['name'] = $key;
                        $row['value'] = $value;
                        unset($row['cookies']);
                        $this->add(new Cookie($row));
                    }
                }
            }
        }
    }

    public function getMatchingCookies(RequestInterface $request)
    {
        // Find cookies that match this request
        $cookies = $this->all($request->getHost(), $request->getPath());
        // Remove ineligible cookies
        foreach ($cookies as $index => $cookie) {
            if (!$cookie->matchesPort($request->getPort()) || ($cookie->getSecure() && $request->getScheme() != 'https')) {
                unset($cookies[$index]);
            }
        };

        return $cookies;
    }

    /**
     * If a cookie already exists and the server asks to set it again with a null value, the
     * cookie must be deleted.
     *
     * @param \Guzzle\Plugin\Cookie\Cookie $cookie
     */
    private function removeCookieIfEmpty(Cookie $cookie)
    {
        $cookieValue = $cookie->getValue();
        if ($cookieValue === null || $cookieValue === '') {
            $this->remove($cookie->getDomain(), $cookie->getPath(), $cookie->getName());
        }
    }
}
<?php

namespace Guzzle\Plugin\Cookie\CookieJar;

use Guzzle\Plugin\Cookie\Cookie;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response;

/**
 * Interface for persisting cookies
 */
interface CookieJarInterface extends \Countable, \IteratorAggregate
{
    /**
     * Remove cookies currently held in the Cookie cookieJar.
     *
     * Invoking this method without arguments will empty the whole Cookie cookieJar.  If given a $domain argument only
     * cookies belonging to that domain will be removed. If given a $domain and $path argument, cookies belonging to
     * the specified path within that domain are removed. If given all three arguments, then the cookie with the
     * specified name, path and domain is removed.
     *
     * @param string $domain Set to clear only cookies matching a domain
     * @param string $path   Set to clear only cookies matching a domain and path
     * @param string $name   Set to clear only cookies matching a domain, path, and name
     *
     * @return CookieJarInterface
     */
    public function remove($domain = null, $path = null, $name = null);

    /**
     * Discard all temporary cookies.
     *
     * Scans for all cookies in the cookieJar with either no expire field or a true discard flag. To be called when the
     * user agent shuts down according to RFC 2965.
     *
     * @return CookieJarInterface
     */
    public function removeTemporary();

    /**
     * Delete any expired cookies
     *
     * @return CookieJarInterface
     */
    public function removeExpired();

    /**
     * Add a cookie to the cookie cookieJar
     *
     * @param Cookie $cookie Cookie to add
     *
     * @return bool Returns true on success or false on failure
     */
    public function add(Cookie $cookie);

    /**
     * Add cookies from a {@see Guzzle\Http\Message\Response} object
     *
     * @param Response         $response Response object
     * @param RequestInterface $request  Request that received the response
     */
    public function addCookiesFromResponse(Response $response, RequestInterface $request = null);

    /**
     * Get cookies matching a request object
     *
     * @param RequestInterface $request Request object to match
     *
     * @return array
     */
    public function getMatchingCookies(RequestInterface $request);

    /**
     * Get all of the matching cookies
     *
     * @param string $domain          Domain of the cookie
     * @param string $path            Path of the cookie
     * @param string $name            Name of the cookie
     * @param bool   $skipDiscardable Set to TRUE to skip cookies with the Discard attribute.
     * @param bool   $skipExpired     Set to FALSE to include expired
     *
     * @return array Returns an array of Cookie objects
     */
    public function all($domain = null, $path = null, $name = null, $skipDiscardable = false, $skipExpired = true);
}
{
    "name": "guzzle/plugin-cookie",
    "description": "Guzzle cookie plugin",
    "homepage": "http://guzzlephp.org/",
    "keywords": ["plugin", "guzzle"],
    "license": "MIT",
    "authors": [
        {
            "name": "Michael Dowling",
            "email": "mtdowling@gmail.com",
            "homepage": "https://github.com/mtdowling"
        }
    ],
    "require": {
        "php": ">=5.3.2",
        "guzzle/http": "self.version"
    },
    "autoload": {
        "psr-0": { "Guzzle\\Plugin\\Cookie": "" }
    },
    "target-dir": "Guzzle/Plugin/Cookie",
    "extra": {
        "branch-alias": {
            "dev-master": "3.7-dev"
        }
    }
}
<?php

namespace Guzzle\Plugin\Cookie;

use Guzzle\Common\ToArrayInterface;

/**
 * Set-Cookie object
 */
class Cookie implements ToArrayInterface
{
    /** @var array Cookie data */
    protected $data;

    /**
     * @var string ASCII codes not valid for for use in a cookie name
     *
     * Cookie names are defined as 'token', according to RFC 2616, Section 2.2
     * A valid token may contain any CHAR except CTLs (ASCII 0 - 31 or 127)
     * or any of the following separators
     */
    protected static $invalidCharString;

    /**
     * Gets an array of invalid cookie characters
     *
     * @return array
     */
    protected static function getInvalidCharacters()
    {
        if (!self::$invalidCharString) {
            self::$invalidCharString = implode('', array_map('chr', array_merge(
                range(0, 32),
                array(34, 40, 41, 44, 47),
                array(58, 59, 60, 61, 62, 63, 64, 91, 92, 93, 123, 125, 127)
            )));
        }

        return self::$invalidCharString;
    }

    /**
     * @param array $data Array of cookie data provided by a Cookie parser
     */
    public function __construct(array $data = array())
    {
        static $defaults = array(
            'name'        => '',
            'value'       => '',
            'domain'      => '',
            'path'        => '/',
            'expires'     => null,
            'max_age'     => 0,
            'comment'     => null,
            'comment_url' => null,
            'port'        => array(),
            'version'     => null,
            'secure'      => false,
            'discard'     => false,
            'http_only'   => false
        );

        $this->data = array_merge($defaults, $data);
        // Extract the expires value and turn it into a UNIX timestamp if needed
        if (!$this->getExpires() && $this->getMaxAge()) {
            // Calculate the expires date
            $this->setExpires(time() + (int) $this->getMaxAge());
        } elseif ($this->getExpires() && !is_numeric($this->getExpires())) {
            $this->setExpires(strtotime($this->getExpires()));
        }
    }

    /**
     * Get the cookie as an array
     *
     * @return array
     */
    public function toArray()
    {
        return $this->data;
    }

    /**
     * Get the cookie name
     *
     * @return string
     */
    public function getName()
    {
        return $this->data['name'];
    }

    /**
     * Set the cookie name
     *
     * @param string $name Cookie name
     *
     * @return Cookie
     */
    public function setName($name)
    {
        return $this->setData('name', $name);
    }

    /**
     * Get the cookie value
     *
     * @return string
     */
    public function getValue()
    {
        return $this->data['value'];
    }

    /**
     * Set the cookie value
     *
     * @param string $value Cookie value
     *
     * @return Cookie
     */
    public function setValue($value)
    {
        return $this->setData('value', $value);
    }

    /**
     * Get the domain
     *
     * @return string|null
     */
    public function getDomain()
    {
        return $this->data['domain'];
    }

    /**
     * Set the domain of the cookie
     *
     * @param string $domain
     *
     * @return Cookie
     */
    public function setDomain($domain)
    {
        return $this->setData('domain', $domain);
    }

    /**
     * Get the path
     *
     * @return string
     */
    public function getPath()
    {
        return $this->data['path'];
    }

    /**
     * Set the path of the cookie
     *
     * @param string $path Path of the cookie
     *
     * @return Cookie
     */
    public function setPath($path)
    {
        return $this->setData('path', $path);
    }

    /**
     * Maximum lifetime of the cookie in seconds
     *
     * @return int|null
     */
    public function getMaxAge()
    {
        return $this->data['max_age'];
    }

    /**
     * Set the max-age of the cookie
     *
     * @param int $maxAge Max age of the cookie in seconds
     *
     * @return Cookie
     */
    public function setMaxAge($maxAge)
    {
        return $this->setData('max_age', $maxAge);
    }

    /**
     * The UNIX timestamp when the cookie expires
     *
     * @return mixed
     */
    public function getExpires()
    {
        return $this->data['expires'];
    }

    /**
     * Set the unix timestamp for which the cookie will expire
     *
     * @param int $timestamp Unix timestamp
     *
     * @return Cookie
     */
    public function setExpires($timestamp)
    {
        return $this->setData('expires', $timestamp);
    }

    /**
     * Version of the cookie specification. RFC 2965 is 1
     *
     * @return mixed
     */
    public function getVersion()
    {
        return $this->data['version'];
    }

    /**
     * Set the cookie version
     *
     * @param string|int $version Version to set
     *
     * @return Cookie
     */
    public function setVersion($version)
    {
        return $this->setData('version', $version);
    }

    /**
     * Get whether or not this is a secure cookie
     *
     * @return null|bool
     */
    public function getSecure()
    {
        return $this->data['secure'];
    }

    /**
     * Set whether or not the cookie is secure
     *
     * @param bool $secure Set to true or false if secure
     *
     * @return Cookie
     */
    public function setSecure($secure)
    {
        return $this->setData('secure', (bool) $secure);
    }

    /**
     * Get whether or not this is a session cookie
     *
     * @return null|bool
     */
    public function getDiscard()
    {
        return $this->data['discard'];
    }

    /**
     * Set whether or not this is a session cookie
     *
     * @param bool $discard Set to true or false if this is a session cookie
     *
     * @return Cookie
     */
    public function setDiscard($discard)
    {
        return $this->setData('discard', $discard);
    }

    /**
     * Get the comment
     *
     * @return string|null
     */
    public function getComment()
    {
        return $this->data['comment'];
    }

    /**
     * Set the comment of the cookie
     *
     * @param string $comment Cookie comment
     *
     * @return Cookie
     */
    public function setComment($comment)
    {
        return $this->setData('comment', $comment);
    }

    /**
     * Get the comment URL of the cookie
     *
     * @return string|null
     */
    public function getCommentUrl()
    {
        return $this->data['comment_url'];
    }

    /**
     * Set the comment URL of the cookie
     *
     * @param string $commentUrl Cookie comment URL for more information
     *
     * @return Cookie
     */
    public function setCommentUrl($commentUrl)
    {
        return $this->setData('comment_url', $commentUrl);
    }

    /**
     * Get an array of acceptable ports this cookie can be used with
     *
     * @return array
     */
    public function getPorts()
    {
        return $this->data['port'];
    }

    /**
     * Set a list of acceptable ports this cookie can be used with
     *
     * @param array $ports Array of acceptable ports
     *
     * @return Cookie
     */
    public function setPorts(array $ports)
    {
        return $this->setData('port', $ports);
    }

    /**
     * Get whether or not this is an HTTP only cookie
     *
     * @return bool
     */
    public function getHttpOnly()
    {
        return $this->data['http_only'];
    }

    /**
     * Set whether or not this is an HTTP only cookie
     *
     * @param bool $httpOnly Set to true or false if this is HTTP only
     *
     * @return Cookie
     */
    public function setHttpOnly($httpOnly)
    {
        return $this->setData('http_only', $httpOnly);
    }

    /**
     * Get an array of extra cookie data
     *
     * @return array
     */
    public function getAttributes()
    {
        return $this->data['data'];
    }

    /**
     * Get a specific data point from the extra cookie data
     *
     * @param string $name Name of the data point to retrieve
     *
     * @return null|string
     */
    public function getAttribute($name)
    {
        return array_key_exists($name, $this->data['data']) ? $this->data['data'][$name] : null;
    }

    /**
     * Set a cookie data attribute
     *
     * @param string $name  Name of the attribute to set
     * @param string $value Value to set
     *
     * @return Cookie
     */
    public function setAttribute($name, $value)
    {
        $this->data['data'][$name] = $value;

        return $this;
    }

    /**
     * Check if the cookie matches a path value
     *
     * @param string $path Path to check against
     *
     * @return bool
     */
    public function matchesPath($path)
    {
        // RFC6265 http://tools.ietf.org/search/rfc6265#section-5.1.4
        // A request-path path-matches a given cookie-path if at least one of
        // the following conditions holds:

        // o  The cookie-path and the request-path are identical.
        if ($path == $this->getPath()) {
            return true;
        }

        $pos = stripos($path, $this->getPath());
        if ($pos === 0) {
            // o  The cookie-path is a prefix of the request-path, and the last
            // character of the cookie-path is %x2F ("/").
            if (substr($this->getPath(), -1, 1) === "/") {
                return true;
            }

            // o  The cookie-path is a prefix of the request-path, and the first
            // character of the request-path that is not included in the cookie-
            // path is a %x2F ("/") character.
            if (substr($path, strlen($this->getPath()), 1) === "/") {
                return true;
            }
        }

        return false;
    }

    /**
     * Check if the cookie matches a domain value
     *
     * @param string $domain Domain to check against
     *
     * @return bool
     */
    public function matchesDomain($domain)
    {
        // Remove the leading '.' as per spec in RFC 6265: http://tools.ietf.org/html/rfc6265#section-5.2.3
        $cookieDomain = ltrim($this->getDomain(), '.');

        // Domain not set or exact match.
        if (!$cookieDomain || !strcasecmp($domain, $cookieDomain)) {
            return true;
        }

        // Matching the subdomain according to RFC 6265: http://tools.ietf.org/html/rfc6265#section-5.1.3
        if (filter_var($domain, FILTER_VALIDATE_IP)) {
            return false;
        }

        return (bool) preg_match('/\.' . preg_quote($cookieDomain, '/') . '$/i', $domain);
    }

    /**
     * Check if the cookie is compatible with a specific port
     *
     * @param int $port Port to check
     *
     * @return bool
     */
    public function matchesPort($port)
    {
        return count($this->getPorts()) == 0 || in_array($port, $this->getPorts());
    }

    /**
     * Check if the cookie is expired
     *
     * @return bool
     */
    public function isExpired()
    {
        return $this->getExpires() && time() > $this->getExpires();
    }

    /**
     * Check if the cookie is valid according to RFC 6265
     *
     * @return bool|string Returns true if valid or an error message if invalid
     */
    public function validate()
    {
        // Names must not be empty, but can be 0
        $name = $this->getName();
        if (empty($name) && !is_numeric($name)) {
            return 'The cookie name must not be empty';
        }

        // Check if any of the invalid characters are present in the cookie name
        if (strpbrk($name, self::getInvalidCharacters()) !== false) {
            return 'The cookie name must not contain invalid characters: ' . $name;
        }

        // Value must not be empty, but can be 0
        $value = $this->getValue();
        if (empty($value) && !is_numeric($value)) {
            return 'The cookie value must not be empty';
        }

        // Domains must not be empty, but can be 0
        // A "0" is not a valid internet domain, but may be used as server name in a private network
        $domain = $this->getDomain();
        if (empty($domain) && !is_numeric($domain)) {
            return 'The cookie domain must not be empty';
        }

        return true;
    }

    /**
     * Set a value and return the cookie object
     *
     * @param string $key   Key to set
     * @param string $value Value to set
     *
     * @return Cookie
     */
    private function setData($key, $value)
    {
        $this->data[$key] = $value;

        return $this;
    }
}
{
    "name": "guzzle/plugin-md5",
    "description": "Guzzle MD5 plugins",
    "homepage": "http://guzzlephp.org/",
    "keywords": ["plugin", "guzzle"],
    "license": "MIT",
    "authors": [
        {
            "name": "Michael Dowling",
            "email": "mtdowling@gmail.com",
            "homepage": "https://github.com/mtdowling"
        }
    ],
    "require": {
        "php": ">=5.3.2",
        "guzzle/http": "self.version"
    },
    "autoload": {
        "psr-0": { "Guzzle\\Plugin\\Md5": "" }
    },
    "target-dir": "Guzzle/Plugin/Md5",
    "extra": {
        "branch-alias": {
            "dev-master": "3.7-dev"
        }
    }
}
<?php

namespace Guzzle\Plugin\Md5;

use Guzzle\Common\Event;
use Guzzle\Http\Message\EntityEnclosingRequestInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Listener used to add a ContentMD5 header to the body of a command and adds ContentMD5 validation if the
 * ValidateMD5 option is not set to false on a command
 */
class CommandContentMd5Plugin  implements EventSubscriberInterface
{
    /** @var string Parameter used to check if the ContentMD5 value is being added */
    protected $contentMd5Param;

    /** @var string Parameter used to check if validation should occur on the response */
    protected $validateMd5Param;

    /**
     * @param string $contentMd5Param  Parameter used to check if the ContentMD5 value is being added
     * @param string $validateMd5Param Parameter used to check if validation should occur on the response
     */
    public function __construct($contentMd5Param = 'ContentMD5', $validateMd5Param = 'ValidateMD5')
    {
        $this->contentMd5Param = $contentMd5Param;
        $this->validateMd5Param = $validateMd5Param;
    }

    public static function getSubscribedEvents()
    {
        return array('command.before_send' => array('onCommandBeforeSend', -255));
    }

    public function onCommandBeforeSend(Event $event)
    {
        $command = $event['command'];
        $request = $command->getRequest();

        // Only add an MD5 is there is a MD5 option on the operation and it has a payload
        if ($request instanceof EntityEnclosingRequestInterface && $request->getBody()
            && $command->getOperation()->hasParam($this->contentMd5Param)) {
            // Check if an MD5 checksum value should be passed along to the request
            if ($command[$this->contentMd5Param] === true) {
                if (false !== ($md5 = $request->getBody()->getContentMd5(true, true))) {
                    $request->setHeader('Content-MD5', $md5);
                }
            }
        }

        // Check if MD5 validation should be used with the response
        if ($command[$this->validateMd5Param] === true) {
            $request->addSubscriber(new Md5ValidatorPlugin(true, false));
        }
    }
}
<?php

namespace Guzzle\Plugin\Md5;

use Guzzle\Common\Event;
use Guzzle\Common\Exception\UnexpectedValueException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Ensures that an the MD5 hash of an entity body matches the Content-MD5
 * header (if set) of an HTTP response.  An exception is thrown if the
 * calculated MD5 does not match the expected MD5.
 */
class Md5ValidatorPlugin implements EventSubscriberInterface
{
    /** @var int Maximum Content-Length in bytes to validate */
    protected $contentLengthCutoff;

    /** @var bool Whether or not to compare when a Content-Encoding is present */
    protected $contentEncoded;

    /**
     * @param bool     $contentEncoded      Calculating the MD5 hash of an entity body where a Content-Encoding was
     *                                      applied is a more expensive comparison because the entity body will need to
     *                                      be compressed in order to get the correct hash.  Set to FALSE to not
     *                                      validate the MD5 hash of an entity body with an applied Content-Encoding.
     * @param bool|int $contentLengthCutoff Maximum Content-Length (bytes) in which a MD5 hash will be validated. Any
     *                                      response with a Content-Length greater than this value will not be validated
     *                                      because it will be deemed too memory intensive.
     */
    public function __construct($contentEncoded = true, $contentLengthCutoff = false)
    {
        $this->contentLengthCutoff = $contentLengthCutoff;
        $this->contentEncoded = $contentEncoded;
    }

    public static function getSubscribedEvents()
    {
        return array('request.complete' => array('onRequestComplete', 255));
    }

    /**
     * {@inheritdoc}
     * @throws UnexpectedValueException
     */
    public function onRequestComplete(Event $event)
    {
        $response = $event['response'];

        if (!$contentMd5 = $response->getContentMd5()) {
            return;
        }

        $contentEncoding = $response->getContentEncoding();
        if ($contentEncoding && !$this->contentEncoded) {
            return false;
        }

        // Make sure that the size of the request is under the cutoff size
        if ($this->contentLengthCutoff) {
            $size = $response->getContentLength() ?: $response->getBody()->getSize();
            if (!$size || $size > $this->contentLengthCutoff) {
                return;
            }
        }

        if (!$contentEncoding) {
            $hash = $response->getBody()->getContentMd5();
        } elseif ($contentEncoding == 'gzip') {
            $response->getBody()->compress('zlib.deflate');
            $hash = $response->getBody()->getContentMd5();
            $response->getBody()->uncompress();
        } elseif ($contentEncoding == 'compress') {
            $response->getBody()->compress('bzip2.compress');
            $hash = $response->getBody()->getContentMd5();
            $response->getBody()->uncompress();
        } else {
            return;
        }

        if ($contentMd5 !== $hash) {
            throw new UnexpectedValueException(
                "The response entity body may have been modified over the wire.  The Content-MD5 "
                . "received ({$contentMd5}) did not match the calculated MD5 hash ({$hash})."
            );
        }
    }
}
{
    "name": "guzzle/plugin-async",
    "description": "Guzzle async request plugin",
    "homepage": "http://guzzlephp.org/",
    "keywords": ["plugin", "guzzle"],
    "license": "MIT",
    "authors": [
        {
            "name": "Michael Dowling",
            "email": "mtdowling@gmail.com",
            "homepage": "https://github.com/mtdowling"
        }
    ],
    "require": {
        "php": ">=5.3.2",
        "guzzle/http": "self.version"
    },
    "autoload": {
        "psr-0": { "Guzzle\\Plugin\\Async": "" }
    },
    "target-dir": "Guzzle/Plugin/Async",
    "extra": {
        "branch-alias": {
            "dev-master": "3.7-dev"
        }
    }
}
<?php

namespace Guzzle\Plugin\Async;

use Guzzle\Common\Event;
use Guzzle\Http\Message\Response;
use Guzzle\Http\Exception\CurlException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Sends requests but does not wait for the response
 */
class AsyncPlugin implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return array(
            'request.before_send'    => 'onBeforeSend',
            'request.exception'      => 'onRequestTimeout',
            'request.sent'           => 'onRequestSent',
            'curl.callback.progress' => 'onCurlProgress'
        );
    }

    /**
     * Event used to ensure that progress callback are emitted from the curl handle's request mediator.
     *
     * @param Event $event
     */
    public function onBeforeSend(Event $event)
    {
        // Ensure that progress callbacks are dispatched
        $event['request']->getCurlOptions()->set('progress', true);
    }

    /**
     * Event emitted when a curl progress function is called. When the amount of data uploaded == the amount of data to
     * upload OR any bytes have been downloaded, then time the request out after 1ms because we're done with
     * transmitting the request, and tell curl not download a body.
     *
     * @param Event $event
     */
    public function onCurlProgress(Event $event)
    {
        if ($event['handle'] &&
            ($event['downloaded'] || (isset($event['uploaded']) && $event['upload_size'] === $event['uploaded']))
        ) {
            // Timeout after 1ms
            curl_setopt($event['handle'], CURLOPT_TIMEOUT_MS, 1);
            // Even if the response is quick, tell curl not to download the body.
            // - Note that we can only perform this shortcut if the request transmitted a body so as to ensure that the
            //   request method is not converted to a HEAD request before the request was sent via curl.
            if ($event['uploaded']) {
                curl_setopt($event['handle'], CURLOPT_NOBODY, true);
            }
        }
    }

    /**
     * Event emitted when a curl exception occurs. Ignore the exception and set a mock response.
     *
     * @param Event $event
     */
    public function onRequestTimeout(Event $event)
    {
        if ($event['exception'] instanceof CurlException) {
            $event['request']->setResponse(new Response(200, array(
                'X-Guzzle-Async' => 'Did not wait for the response'
            )));
        }
    }

    /**
     * Event emitted when a request completes because it took less than 1ms. Add an X-Guzzle-Async header to notify the
     * caller that there is no body in the message.
     *
     * @param Event $event
     */
    public function onRequestSent(Event $event)
    {
        // Let the caller know this was meant to be async
        $event['request']->getResponse()->setHeader('X-Guzzle-Async', 'Did not wait for the response');
    }
}
<?php

namespace Guzzle\Plugin\ErrorResponse;

use Guzzle\Service\Command\CommandInterface;
use Guzzle\Http\Message\Response;

/**
 * Interface used to create an exception from an error response
 */
interface ErrorResponseExceptionInterface
{
    /**
     * Create an exception for a command based on a command and an error response definition
     *
     * @param CommandInterface $command  Command that was sent
     * @param Response         $response The error response
     *
     * @return self
     */
    public static function fromCommand(CommandInterface $command, Response $response);
}
<?php

namespace Guzzle\Plugin\ErrorResponse;

use Guzzle\Common\Event;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Service\Command\CommandInterface;
use Guzzle\Service\Description\Operation;
use Guzzle\Plugin\ErrorResponse\Exception\ErrorResponseException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Converts generic Guzzle response exceptions into errorResponse exceptions
 */
class ErrorResponsePlugin implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return array('command.before_send' => array('onCommandBeforeSend', -1));
    }

    /**
     * Adds a listener to requests before they sent from a command
     *
     * @param Event $event Event emitted
     */
    public function onCommandBeforeSend(Event $event)
    {
        $command = $event['command'];
        if ($operation = $command->getOperation()) {
            if ($operation->getErrorResponses()) {
                $request = $command->getRequest();
                $request->getEventDispatcher()
                    ->addListener('request.complete', $this->getErrorClosure($request, $command, $operation));
            }
        }
    }

    /**
     * @param RequestInterface $request   Request that received an error
     * @param CommandInterface $command   Command that created the request
     * @param Operation        $operation Operation that defines the request and errors
     *
     * @return \Closure Returns a closure
     * @throws ErrorResponseException
     */
    protected function getErrorClosure(RequestInterface $request, CommandInterface $command, Operation $operation)
    {
        return function (Event $event) use ($request, $command, $operation) {
            $response = $event['response'];
            foreach ($operation->getErrorResponses() as $error) {
                if (!isset($error['class'])) {
                    continue;
                }
                if (isset($error['code']) && $response->getStatusCode() != $error['code']) {
                    continue;
                }
                if (isset($error['reason']) && $response->getReasonPhrase() != $error['reason']) {
                    continue;
                }
                $className = $error['class'];
                $errorClassInterface = __NAMESPACE__ . '\\ErrorResponseExceptionInterface';
                if (!class_exists($className)) {
                    throw new ErrorResponseException("{$className} does not exist");
                } elseif (!(in_array($errorClassInterface, class_implements($className)))) {
                    throw new ErrorResponseException("{$className} must implement {$errorClassInterface}");
                }
                throw $className::fromCommand($command, $response);
            }
        };
    }
}
<?php

namespace Guzzle\Plugin\ErrorResponse\Exception;

use Guzzle\Common\Exception\RuntimeException;

class ErrorResponseException extends RuntimeException {}
{
    "name": "guzzle/plugin-error-response",
    "description": "Guzzle errorResponse plugin for creating error exceptions based on a service description",
    "homepage": "http://guzzlephp.org/",
    "keywords": ["plugin", "guzzle"],
    "license": "MIT",
    "authors": [
        {
            "name": "Michael Dowling",
            "email": "mtdowling@gmail.com",
            "homepage": "https://github.com/mtdowling"
        }
    ],
    "require": {
        "php": ">=5.3.2",
        "guzzle/service": "self.version"
    },
    "autoload": {
        "psr-0": { "Guzzle\\Plugin\\ErrorResponse": "" }
    },
    "target-dir": "Guzzle/Plugin/ErrorResponse",
    "extra": {
        "branch-alias": {
            "dev-master": "3.7-dev"
        }
    }
}
{
    "name": "guzzle/plugin-curlauth",
    "description": "Guzzle cURL authorization plugin",
    "homepage": "http://guzzlephp.org/",
    "keywords": ["plugin", "curl", "guzzle"],
    "license": "MIT",
    "authors": [
        {
            "name": "Michael Dowling",
            "email": "mtdowling@gmail.com",
            "homepage": "https://github.com/mtdowling"
        }
    ],
    "require": {
        "php": ">=5.3.2",
        "guzzle/http": "self.version"
    },
    "autoload": {
        "psr-0": { "Guzzle\\Plugin\\CurlAuth": "" }
    },
    "target-dir": "Guzzle/Plugin/CurlAuth",
    "extra": {
        "branch-alias": {
            "dev-master": "3.7-dev"
        }
    }
}
<?php

namespace Guzzle\Plugin\CurlAuth;

use Guzzle\Common\Event;
use Guzzle\Common\Version;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Adds specified curl auth to all requests sent from a client. Defaults to CURLAUTH_BASIC if none supplied.
 * @deprecated Use $client->getConfig()->setPath('request.options/auth', array('user', 'pass', 'Basic|Digest');
 */
class CurlAuthPlugin implements EventSubscriberInterface
{
    private $username;
    private $password;
    private $scheme;

    /**
     * @param string $username HTTP basic auth username
     * @param string $password Password
     * @param int    $scheme   Curl auth scheme
     */
    public function __construct($username, $password, $scheme=CURLAUTH_BASIC)
    {
        Version::warn(__CLASS__ . " is deprecated. Use \$client->getConfig()->setPath('request.options/auth', array('user', 'pass', 'Basic|Digest');");
        $this->username = $username;
        $this->password = $password;
        $this->scheme = $scheme;
    }

    public static function getSubscribedEvents()
    {
        return array('client.create_request' => array('onRequestCreate', 255));
    }

    /**
     * Add basic auth
     *
     * @param Event $event
     */
    public function onRequestCreate(Event $event)
    {
        $event['request']->setAuth($this->username, $this->password, $this->scheme);
    }
}
<?php

namespace Guzzle\Plugin\Backoff;

use Guzzle\Common\Event;
use Guzzle\Common\AbstractHasDispatcher;
use Guzzle\Http\Message\EntityEnclosingRequestInterface;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Curl\CurlMultiInterface;
use Guzzle\Http\Exception\CurlException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Plugin to automatically retry failed HTTP requests using a backoff strategy
 */
class BackoffPlugin extends AbstractHasDispatcher implements EventSubscriberInterface
{
    const DELAY_PARAM = CurlMultiInterface::BLOCKING;
    const RETRY_PARAM = 'plugins.backoff.retry_count';
    const RETRY_EVENT = 'plugins.backoff.retry';

    /** @var BackoffStrategyInterface Backoff strategy */
    protected $strategy;

    /**
     * @param BackoffStrategyInterface $strategy The backoff strategy used to determine whether or not to retry and
     *                                           the amount of delay between retries.
     */
    public function __construct(BackoffStrategyInterface $strategy = null)
    {
        $this->strategy = $strategy;
    }

    /**
     * Retrieve a basic truncated exponential backoff plugin that will retry HTTP errors and cURL errors
     *
     * @param int   $maxRetries Maximum number of retries
     * @param array $httpCodes  HTTP response codes to retry
     * @param array $curlCodes  cURL error codes to retry
     *
     * @return self
     */
    public static function getExponentialBackoff(
        $maxRetries = 3,
        array $httpCodes = null,
        array $curlCodes = null
    ) {
        return new self(new TruncatedBackoffStrategy($maxRetries,
            new HttpBackoffStrategy($httpCodes,
                new CurlBackoffStrategy($curlCodes,
                    new ExponentialBackoffStrategy()
                )
            )
        ));
    }

    public static function getAllEvents()
    {
        return array(self::RETRY_EVENT);
    }

    public static function getSubscribedEvents()
    {
        return array(
            'request.sent'      => 'onRequestSent',
            'request.exception' => 'onRequestSent',
            CurlMultiInterface::POLLING_REQUEST => 'onRequestPoll'
        );
    }

    /**
     * Called when a request has been sent  and isn't finished processing
     *
     * @param Event $event
     */
    public function onRequestSent(Event $event)
    {
        $request = $event['request'];
        $response = $event['response'];
        $exception = $event['exception'];

        $params = $request->getParams();
        $retries = (int) $params->get(self::RETRY_PARAM);
        $delay = $this->strategy->getBackoffPeriod($retries, $request, $response, $exception);

        if ($delay !== false) {
            // Calculate how long to wait until the request should be retried
            $params->set(self::RETRY_PARAM, ++$retries)
                ->set(self::DELAY_PARAM, microtime(true) + $delay);
            // Send the request again
            $request->setState(RequestInterface::STATE_TRANSFER);
            $this->dispatch(self::RETRY_EVENT, array(
                'request'  => $request,
                'response' => $response,
                'handle'   => ($exception && $exception instanceof CurlException) ? $exception->getCurlHandle() : null,
                'retries'  => $retries,
                'delay'    => $delay
            ));
        }
    }

    /**
     * Called when a request is polling in the curl multi object
     *
     * @param Event $event
     */
    public function onRequestPoll(Event $event)
    {
        $request = $event['request'];
        $delay = $request->getParams()->get(self::DELAY_PARAM);

        // If the duration of the delay has passed, retry the request using the pool
        if (null !== $delay && microtime(true) >= $delay) {
            // Remove the request from the pool and then add it back again. This is required for cURL to know that we
            // want to retry sending the easy handle.
            $request->getParams()->remove(self::DELAY_PARAM);
            // Rewind the request body if possible
            if ($request instanceof EntityEnclosingRequestInterface && $request->getBody()) {
                $request->getBody()->seek(0);
            }
            $multi = $event['curl_multi'];
            $multi->remove($request);
            $multi->add($request);
        }
    }
}
{
    "name": "guzzle/plugin-backoff",
    "description": "Guzzle backoff retry plugins",
    "homepage": "http://guzzlephp.org/",
    "keywords": ["plugin", "guzzle"],
    "license": "MIT",
    "authors": [
        {
            "name": "Michael Dowling",
            "email": "mtdowling@gmail.com",
            "homepage": "https://github.com/mtdowling"
        }
    ],
    "require": {
        "php": ">=5.3.2",
        "guzzle/http": "self.version",
        "guzzle/log": "self.version"
    },
    "autoload": {
        "psr-0": { "Guzzle\\Plugin\\Backoff": "" }
    },
    "target-dir": "Guzzle/Plugin/Backoff",
    "extra": {
        "branch-alias": {
            "dev-master": "3.7-dev"
        }
    }
}
<?php

namespace Guzzle\Plugin\Backoff;

/**
 * Strategy used to retry when certain error codes are encountered
 */
abstract class AbstractErrorCodeBackoffStrategy extends AbstractBackoffStrategy
{
    /** @var array Default cURL errors to retry */
    protected static $defaultErrorCodes = array();

    /** @var array Error codes that can be retried */
    protected $errorCodes;

    /**
     * @param array                    $codes Array of codes that should be retried
     * @param BackoffStrategyInterface $next  The optional next strategy
     */
    public function __construct(array $codes = null, BackoffStrategyInterface $next = null)
    {
        $this->errorCodes = array_fill_keys($codes ?: static::$defaultErrorCodes, 1);
        $this->next = $next;
    }

    /**
     * Get the default failure codes to retry
     *
     * @return array
     */
    public static function getDefaultFailureCodes()
    {
        return static::$defaultErrorCodes;
    }

    public function makesDecision()
    {
        return true;
    }
}
<?php

namespace Guzzle\Plugin\Backoff;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response;
use Guzzle\Http\Exception\HttpException;

/**
 * Strategy that will not retry more than a certain number of times.
 */
class TruncatedBackoffStrategy extends AbstractBackoffStrategy
{
    /** @var int Maximum number of retries per request */
    protected $max;

    /**
     * @param int                      $maxRetries Maximum number of retries per request
     * @param BackoffStrategyInterface $next The optional next strategy
     */
    public function __construct($maxRetries, BackoffStrategyInterface $next = null)
    {
        $this->max = $maxRetries;
        $this->next = $next;
    }

    public function makesDecision()
    {
        return true;
    }

    protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
    {
        return $retries < $this->max ? null : false;
    }
}
<?php

namespace Guzzle\Plugin\Backoff;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response;
use Guzzle\Http\Exception\HttpException;

/**
 * Will retry the request using the same amount of delay for each retry.
 *
 * Warning: If no decision making strategies precede this strategy in the the chain, then all requests will be retried
 */
class ConstantBackoffStrategy extends AbstractBackoffStrategy
{
    /** @var int Amount of time for each delay */
    protected $delay;

    /** @param int $delay Amount of time to delay between each additional backoff */
    public function __construct($delay)
    {
        $this->delay = $delay;
    }

    public function makesDecision()
    {
        return false;
    }

    protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
    {
        return $this->delay;
    }
}
<?php

namespace Guzzle\Plugin\Backoff;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response;
use Guzzle\Http\Exception\HttpException;

/**
 * Strategy to determine if a request should be retried and how long to delay between retries
 */
interface BackoffStrategyInterface
{
    /**
     * Get the amount of time to delay in seconds before retrying a request
     *
     * @param int              $retries  Number of retries of the request
     * @param RequestInterface $request  Request that was sent
     * @param Response         $response Response that was received. Note that there may not be a response
     * @param HttpException    $e        Exception that was encountered if any
     *
     * @return bool|int Returns false to not retry or the number of seconds to delay between retries
     */
    public function getBackoffPeriod(
        $retries,
        RequestInterface $request,
        Response $response = null,
        HttpException $e = null
    );
}
<?php

namespace Guzzle\Plugin\Backoff;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response;
use Guzzle\Http\Exception\HttpException;

/**
 * Strategy used to retry HTTP requests when the response's reason phrase matches one of the registered phrases.
 */
class ReasonPhraseBackoffStrategy extends AbstractErrorCodeBackoffStrategy
{
    public function makesDecision()
    {
        return true;
    }

    protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
    {
        if ($response) {
            return isset($this->errorCodes[$response->getReasonPhrase()]) ? true : null;
        }
    }
}
<?php

namespace Guzzle\Plugin\Backoff;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response;
use Guzzle\Http\Exception\HttpException;

/**
 * Strategy used to retry HTTP requests based on the response code.
 *
 * Retries 500 and 503 error by default.
 */
class HttpBackoffStrategy extends AbstractErrorCodeBackoffStrategy
{
    /** @var array Default cURL errors to retry */
    protected static $defaultErrorCodes = array(500, 503);

    protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
    {
        if ($response) {
            //Short circuit the rest of the checks if it was successful
            if ($response->isSuccessful()) {
                return false;
            } else {
                return isset($this->errorCodes[$response->getStatusCode()]) ? true : null;
            }
        }
    }
}
<?php

namespace Guzzle\Plugin\Backoff;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response;
use Guzzle\Http\Exception\HttpException;

/**
 * Implements an exponential backoff retry strategy.
 *
 * Warning: If no decision making strategies precede this strategy in the the chain, then all requests will be retried
 */
class ExponentialBackoffStrategy extends AbstractBackoffStrategy
{
    public function makesDecision()
    {
        return false;
    }

    protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
    {
        return (int) pow(2, $retries);
    }
}
<?php

namespace Guzzle\Plugin\Backoff;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response;
use Guzzle\Http\Exception\HttpException;

/**
 * Implements a linear backoff retry strategy.
 *
 * Warning: If no decision making strategies precede this strategy in the the chain, then all requests will be retried
 */
class LinearBackoffStrategy extends AbstractBackoffStrategy
{
    /** @var int Amount of time to progress each delay */
    protected $step;

    /**
     * @param int $step Amount of time to increase the delay each additional backoff
     */
    public function __construct($step = 1)
    {
        $this->step = $step;
    }

    public function makesDecision()
    {
        return false;
    }

    protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
    {
        return $retries * $this->step;
    }
}
<?php

namespace Guzzle\Plugin\Backoff;

use Guzzle\Common\Event;
use Guzzle\Log\LogAdapterInterface;
use Guzzle\Log\MessageFormatter;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Logs backoff retries triggered from the BackoffPlugin
 *
 * Format your log messages using a template that can contain template substitutions found in {@see MessageFormatter}.
 * In addition to the default template substitutions, there is also:
 *
 * - retries: The number of times the request has been retried
 * - delay:   The amount of time the request is being delayed
 */
class BackoffLogger implements EventSubscriberInterface
{
    /** @var string Default log message template */
    const DEFAULT_FORMAT = '[{ts}] {method} {url} - {code} {phrase} - Retries: {retries}, Delay: {delay}, Time: {connect_time}, {total_time}, cURL: {curl_code} {curl_error}';

    /** @var LogAdapterInterface Logger used to log retries */
    protected $logger;

    /** @var MessageFormatter Formatter used to format log messages */
    protected $formatter;

    /**
     * @param LogAdapterInterface $logger    Logger used to log the retries
     * @param MessageFormatter    $formatter Formatter used to format log messages
     */
    public function __construct(LogAdapterInterface $logger, MessageFormatter $formatter = null)
    {
        $this->logger = $logger;
        $this->formatter = $formatter ?: new MessageFormatter(self::DEFAULT_FORMAT);
    }

    public static function getSubscribedEvents()
    {
        return array(BackoffPlugin::RETRY_EVENT => 'onRequestRetry');
    }

    /**
     * Set the template to use for logging
     *
     * @param string $template Log message template
     *
     * @return self
     */
    public function setTemplate($template)
    {
        $this->formatter->setTemplate($template);

        return $this;
    }

    /**
     * Called when a request is being retried
     *
     * @param Event $event Event emitted
     */
    public function onRequestRetry(Event $event)
    {
        $this->logger->log($this->formatter->format(
            $event['request'],
            $event['response'],
            $event['handle'],
            array(
                'retries' => $event['retries'],
                'delay'   => $event['delay']
            )
        ));
    }
}
<?php

namespace Guzzle\Plugin\Backoff;

use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response;
use Guzzle\Http\Exception\HttpException;

/**
 * Strategy that will invoke a closure to determine whether or not to retry with a delay
 */
class CallbackBackoffStrategy extends AbstractBackoffStrategy
{
    /** @var \Closure|array|mixed Callable method to invoke */
    protected $callback;

    /** @var bool Whether or not this strategy makes a retry decision */
    protected $decision;

    /**
     * @param \Closure|array|mixed     $callback Callable method to invoke
     * @param bool                     $decision Set to true if this strategy makes a backoff decision
     * @param BackoffStrategyInterface $next     The optional next strategy
     *
     * @throws InvalidArgumentException
     */
    public function __construct($callback, $decision, BackoffStrategyInterface $next = null)
    {
        if (!is_callable($callback)) {
            throw new InvalidArgumentException('The callback must be callable');
        }
        $this->callback = $callback;
        $this->decision = (bool) $decision;
        $this->next = $next;
    }

    public function makesDecision()
    {
        return $this->decision;
    }

    protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
    {
        return call_user_func($this->callback, $retries, $request, $response, $e);
    }
}
<?php

namespace Guzzle\Plugin\Backoff;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response;
use Guzzle\Http\Exception\HttpException;

/**
 * Abstract backoff strategy that allows for a chain of responsibility
 */
abstract class AbstractBackoffStrategy implements BackoffStrategyInterface
{
    /** @var AbstractBackoffStrategy Next strategy in the chain */
    protected $next;

    /** @param AbstractBackoffStrategy $next Next strategy in the chain */
    public function setNext(AbstractBackoffStrategy $next)
    {
        $this->next = $next;
    }

    /**
     * Get the next backoff strategy in the chain
     *
     * @return AbstractBackoffStrategy|null
     */
    public function getNext()
    {
        return $this->next;
    }

    public function getBackoffPeriod(
        $retries,
        RequestInterface $request,
        Response $response = null,
        HttpException $e = null
    ) {
        $delay = $this->getDelay($retries, $request, $response, $e);
        if ($delay === false) {
            // The strategy knows that this must not be retried
            return false;
        } elseif ($delay === null) {
            // If the strategy is deferring a decision and the next strategy will not make a decision then return false
            return !$this->next || !$this->next->makesDecision()
                ? false
                : $this->next->getBackoffPeriod($retries, $request, $response, $e);
        } elseif ($delay === true) {
            // if the strategy knows that it must retry but is deferring to the next to determine the delay
            if (!$this->next) {
                return 0;
            } else {
                $next = $this->next;
                while ($next->makesDecision() && $next->getNext()) {
                    $next = $next->getNext();
                }
                return !$next->makesDecision() ? $next->getBackoffPeriod($retries, $request, $response, $e) : 0;
            }
        } else {
            return $delay;
        }
    }

    /**
     * Check if the strategy does filtering and makes decisions on whether or not to retry.
     *
     * Strategies that return false will never retry if all of the previous strategies in a chain defer on a backoff
     * decision.
     *
     * @return bool
     */
    abstract public function makesDecision();

    /**
     * Implement the concrete strategy
     *
     * @param int              $retries  Number of retries of the request
     * @param RequestInterface $request  Request that was sent
     * @param Response         $response Response that was received. Note that there may not be a response
     * @param HttpException    $e        Exception that was encountered if any
     *
     * @return bool|int|null Returns false to not retry or the number of seconds to delay between retries. Return true
     *                       or null to defer to the next strategy if available, and if not, return 0.
     */
    abstract protected function getDelay(
        $retries,
        RequestInterface $request,
        Response $response = null,
        HttpException $e = null
    );
}
<?php

namespace Guzzle\Plugin\Backoff;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response;
use Guzzle\Http\Exception\HttpException;
use Guzzle\Http\Exception\CurlException;

/**
 * Strategy used to retry when certain cURL error codes are encountered.
 */
class CurlBackoffStrategy extends AbstractErrorCodeBackoffStrategy
{
    /** @var array Default cURL errors to retry */
    protected static $defaultErrorCodes = array(
        CURLE_COULDNT_RESOLVE_HOST, CURLE_COULDNT_CONNECT, CURLE_PARTIAL_FILE, CURLE_WRITE_ERROR, CURLE_READ_ERROR,
        CURLE_OPERATION_TIMEOUTED, CURLE_SSL_CONNECT_ERROR, CURLE_HTTP_PORT_FAILED, CURLE_GOT_NOTHING,
        CURLE_SEND_ERROR, CURLE_RECV_ERROR
    );

    protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
    {
        if ($e && $e instanceof CurlException) {
            return isset($this->errorCodes[$e->getErrorNo()]) ? true : null;
        }
    }
}
<?php

namespace Guzzle\Common;

use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Common\Exception\RuntimeException;

/**
 * Key value pair collection object
 */
class Collection implements \ArrayAccess, \IteratorAggregate, \Countable, ToArrayInterface
{
    /** @var array Data associated with the object. */
    protected $data;

    /**
     * @param array $data Associative array of data to set
     */
    public function __construct(array $data = array())
    {
        $this->data = $data;
    }

    /**
     * Create a new collection from an array, validate the keys, and add default values where missing
     *
     * @param array $config   Configuration values to apply.
     * @param array $defaults Default parameters
     * @param array $required Required parameter names
     *
     * @return self
     * @throws InvalidArgumentException if a parameter is missing
     */
    public static function fromConfig(array $config = array(), array $defaults = array(), array $required = array())
    {
        $data = $config + $defaults;

        if ($missing = array_diff($required, array_keys($data))) {
            throw new InvalidArgumentException('Config is missing the following keys: ' . implode(', ', $missing));
        }

        return new self($data);
    }

    public function count()
    {
        return count($this->data);
    }

    public function getIterator()
    {
        return new \ArrayIterator($this->data);
    }

    public function toArray()
    {
        return $this->data;
    }

    /**
     * Removes all key value pairs
     *
     * @return Collection
     */
    public function clear()
    {
        $this->data = array();

        return $this;
    }

    /**
     * Get all or a subset of matching key value pairs
     *
     * @param array $keys Pass an array of keys to retrieve only a subset of key value pairs
     *
     * @return array Returns an array of all matching key value pairs
     */
    public function getAll(array $keys = null)
    {
        return $keys ? array_intersect_key($this->data, array_flip($keys)) : $this->data;
    }

    /**
     * Get a specific key value.
     *
     * @param string $key Key to retrieve.
     *
     * @return mixed|null Value of the key or NULL
     */
    public function get($key)
    {
        return isset($this->data[$key]) ? $this->data[$key] : null;
    }

    /**
     * Set a key value pair
     *
     * @param string $key   Key to set
     * @param mixed  $value Value to set
     *
     * @return Collection Returns a reference to the object
     */
    public function set($key, $value)
    {
        $this->data[$key] = $value;

        return $this;
    }

    /**
     * Add a value to a key.  If a key of the same name has already been added, the key value will be converted into an
     * array and the new value will be pushed to the end of the array.
     *
     * @param string $key   Key to add
     * @param mixed  $value Value to add to the key
     *
     * @return Collection Returns a reference to the object.
     */
    public function add($key, $value)
    {
        if (!array_key_exists($key, $this->data)) {
            $this->data[$key] = $value;
        } elseif (is_array($this->data[$key])) {
            $this->data[$key][] = $value;
        } else {
            $this->data[$key] = array($this->data[$key], $value);
        }

        return $this;
    }

    /**
     * Remove a specific key value pair
     *
     * @param string $key A key to remove
     *
     * @return Collection
     */
    public function remove($key)
    {
        unset($this->data[$key]);

        return $this;
    }

    /**
     * Get all keys in the collection
     *
     * @return array
     */
    public function getKeys()
    {
        return array_keys($this->data);
    }

    /**
     * Returns whether or not the specified key is present.
     *
     * @param string $key The key for which to check the existence.
     *
     * @return bool
     */
    public function hasKey($key)
    {
        return array_key_exists($key, $this->data);
    }

    /**
     * Case insensitive search the keys in the collection
     *
     * @param string $key Key to search for
     *
     * @return bool|string Returns false if not found, otherwise returns the key
     */
    public function keySearch($key)
    {
        foreach (array_keys($this->data) as $k) {
            if (!strcasecmp($k, $key)) {
                return $k;
            }
        }

        return false;
    }

    /**
     * Checks if any keys contains a certain value
     *
     * @param string $value Value to search for
     *
     * @return mixed Returns the key if the value was found FALSE if the value was not found.
     */
    public function hasValue($value)
    {
        return array_search($value, $this->data);
    }

    /**
     * Replace the data of the object with the value of an array
     *
     * @param array $data Associative array of data
     *
     * @return Collection Returns a reference to the object
     */
    public function replace(array $data)
    {
        $this->data = $data;

        return $this;
    }

    /**
     * Add and merge in a Collection or array of key value pair data.
     *
     * @param Collection|array $data Associative array of key value pair data
     *
     * @return Collection Returns a reference to the object.
     */
    public function merge($data)
    {
        foreach ($data as $key => $value) {
            $this->add($key, $value);
        }

        return $this;
    }

    /**
     * Over write key value pairs in this collection with all of the data from an array or collection.
     *
     * @param array|\Traversable $data Values to override over this config
     *
     * @return self
     */
    public function overwriteWith($data)
    {
        if (is_array($data)) {
            $this->data = $data + $this->data;
        } elseif ($data instanceof Collection) {
            $this->data = $data->toArray() + $this->data;
        } else {
            foreach ($data as $key => $value) {
                $this->data[$key] = $value;
            }
        }

        return $this;
    }

    /**
     * Returns a Collection containing all the elements of the collection after applying the callback function to each
     * one. The Closure should accept three parameters: (string) $key, (string) $value, (array) $context and return a
     * modified value
     *
     * @param \Closure $closure Closure to apply
     * @param array    $context Context to pass to the closure
     * @param bool     $static  Set to TRUE to use the same class as the return rather than returning a Collection
     *
     * @return Collection
     */
    public function map(\Closure $closure, array $context = array(), $static = true)
    {
        $collection = $static ? new static() : new self();
        foreach ($this as $key => $value) {
            $collection->add($key, $closure($key, $value, $context));
        }

        return $collection;
    }

    /**
     * Iterates over each key value pair in the collection passing them to the Closure. If the  Closure function returns
     * true, the current value from input is returned into the result Collection.  The Closure must accept three
     * parameters: (string) $key, (string) $value and return Boolean TRUE or FALSE for each value.
     *
     * @param \Closure $closure Closure evaluation function
     * @param bool     $static  Set to TRUE to use the same class as the return rather than returning a Collection
     *
     * @return Collection
     */
    public function filter(\Closure $closure, $static = true)
    {
        $collection = ($static) ? new static() : new self();
        foreach ($this->data as $key => $value) {
            if ($closure($key, $value)) {
                $collection->add($key, $value);
            }
        }

        return $collection;
    }

    public function offsetExists($offset)
    {
        return isset($this->data[$offset]);
    }

    public function offsetGet($offset)
    {
        return isset($this->data[$offset]) ? $this->data[$offset] : null;
    }

    public function offsetSet($offset, $value)
    {
        $this->data[$offset] = $value;
    }

    public function offsetUnset($offset)
    {
        unset($this->data[$offset]);
    }

    /**
     * Set a value into a nested array key. Keys will be created as needed to set the value.
     *
     * @param string $path  Path to set
     * @param mixed  $value Value to set at the key
     *
     * @return self
     * @throws RuntimeException when trying to setPath using a nested path that travels through a scalar value
     */
    public function setPath($path, $value)
    {
        $current =& $this->data;
        $queue = explode('/', $path);
        while (null !== ($key = array_shift($queue))) {
            if (!is_array($current)) {
                throw new RuntimeException("Trying to setPath {$path}, but {$key} is set and is not an array");
            } elseif (!$queue) {
                $current[$key] = $value;
            } elseif (isset($current[$key])) {
                $current =& $current[$key];
            } else {
                $current[$key] = array();
                $current =& $current[$key];
            }
        }

        return $this;
    }

    /**
     * Gets a value from the collection using an array path (e.g. foo/baz/bar would retrieve bar from two nested arrays)
     * Allows for wildcard searches which recursively combine matches up to the level at which the wildcard occurs. This
     * can be useful for accepting any key of a sub-array and combining matching keys from each diverging path.
     *
     * @param string $path      Path to traverse and retrieve a value from
     * @param string $separator Character used to add depth to the search
     * @param mixed  $data      Optional data to descend into (used when wildcards are encountered)
     *
     * @return mixed|null
     */
    public function getPath($path, $separator = '/', $data = null)
    {
        if ($data === null) {
            $data =& $this->data;
        }

        $path = is_array($path) ? $path : explode($separator, $path);
        while (null !== ($part = array_shift($path))) {
            if (!is_array($data)) {
                return null;
            } elseif (isset($data[$part])) {
                $data =& $data[$part];
            } elseif ($part != '*') {
                return null;
            } else {
                // Perform a wildcard search by diverging and merging paths
                $result = array();
                foreach ($data as $value) {
                    if (!$path) {
                        $result = array_merge_recursive($result, (array) $value);
                    } elseif (null !== ($test = $this->getPath($path, $separator, $value))) {
                        $result = array_merge_recursive($result, (array) $test);
                    }
                }
                return $result;
            }
        }

        return $data;
    }

    /**
     * Inject configuration settings into an input string
     *
     * @param string $input Input to inject
     *
     * @return string
     * @deprecated
     */
    public function inject($input)
    {
        Version::warn(__METHOD__ . ' is deprecated');
        $replace = array();
        foreach ($this->data as $key => $val) {
            $replace['{' . $key . '}'] = $val;
        }

        return strtr($input, $replace);
    }
}
<?php

namespace Guzzle\Common;

use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Holds an event dispatcher
 */
interface HasDispatcherInterface
{
    /**
     * Get a list of all of the events emitted from the class
     *
     * @return array
     */
    public static function getAllEvents();

    /**
     * Set the EventDispatcher of the request
     *
     * @param EventDispatcherInterface $eventDispatcher
     *
     * @return self
     */
    public function setEventDispatcher(EventDispatcherInterface $eventDispatcher);

    /**
     * Get the EventDispatcher of the request
     *
     * @return EventDispatcherInterface
     */
    public function getEventDispatcher();

    /**
     * Helper to dispatch Guzzle events and set the event name on the event
     *
     * @param string $eventName Name of the event to dispatch
     * @param array  $context   Context of the event
     *
     * @return Event Returns the created event object
     */
    public function dispatch($eventName, array $context = array());

    /**
     * Add an event subscriber to the dispatcher
     *
     * @param EventSubscriberInterface $subscriber Event subscriber
     *
     * @return self
     */
    public function addSubscriber(EventSubscriberInterface $subscriber);
}
<?php

namespace Guzzle\Common\Exception;

class RuntimeException extends \RuntimeException implements GuzzleException {}
<?php

namespace Guzzle\Common\Exception;

class UnexpectedValueException extends \UnexpectedValueException implements GuzzleException {}
<?php

namespace Guzzle\Common\Exception;

class BadMethodCallException extends \BadMethodCallException implements GuzzleException {}
<?php

namespace Guzzle\Common\Exception;

/**
 * Guzzle exception
 */
interface GuzzleException {}
<?php

namespace Guzzle\Common\Exception;

class InvalidArgumentException extends \InvalidArgumentException implements GuzzleException {}
<?php

namespace Guzzle\Common\Exception;

/**
 * Collection of exceptions
 */
class ExceptionCollection extends \Exception implements GuzzleException, \IteratorAggregate, \Countable
{
    /** @var array Array of Exceptions */
    protected $exceptions = array();

    /** @var string Succinct exception message not including sub-exceptions */
    private $shortMessage;

    public function __construct($message = '', $code = 0, \Exception $previous = null)
    {
        parent::__construct($message, $code, $previous);
        $this->shortMessage = $message;
    }

    /**
     * Set all of the exceptions
     *
     * @param array $exceptions Array of exceptions
     *
     * @return self
     */
    public function setExceptions(array $exceptions)
    {
        $this->exceptions = array();
        foreach ($exceptions as $exception) {
            $this->add($exception);
        }

        return $this;
    }

    /**
     * Add exceptions to the collection
     *
     * @param ExceptionCollection|\Exception $e Exception to add
     *
     * @return ExceptionCollection;
     */
    public function add($e)
    {
        $this->exceptions[] = $e;
        if ($this->message) {
            $this->message .= "\n";
        }

        $this->message .= $this->getExceptionMessage($e, 0);

        return $this;
    }

    /**
     * Get the total number of request exceptions
     *
     * @return int
     */
    public function count()
    {
        return count($this->exceptions);
    }

    /**
     * Allows array-like iteration over the request exceptions
     *
     * @return \ArrayIterator
     */
    public function getIterator()
    {
        return new \ArrayIterator($this->exceptions);
    }

    /**
     * Get the first exception in the collection
     *
     * @return \Exception
     */
    public function getFirst()
    {
        return $this->exceptions ? $this->exceptions[0] : null;
    }

    private function getExceptionMessage(\Exception $e, $depth = 0)
    {
        static $sp = '    ';
        $prefix = $depth ? str_repeat($sp, $depth) : '';
        $message = "{$prefix}(" . get_class($e) . ') ' . $e->getFile() . ' line ' . $e->getLine() . "\n";

        if ($e instanceof self) {
            if ($e->shortMessage) {
                $message .= "\n{$prefix}{$sp}" . str_replace("\n", "\n{$prefix}{$sp}", $e->shortMessage) . "\n";
            }
            foreach ($e as $ee) {
                $message .= "\n" . $this->getExceptionMessage($ee, $depth + 1);
            }
        }  else {
            $message .= "\n{$prefix}{$sp}" . str_replace("\n", "\n{$prefix}{$sp}", $e->getMessage()) . "\n";
            $message .= "\n{$prefix}{$sp}" . str_replace("\n", "\n{$prefix}{$sp}", $e->getTraceAsString()) . "\n";
        }

        return str_replace(getcwd(), '.', $message);
    }
}
{
    "name": "guzzle/common",
    "homepage": "http://guzzlephp.org/",
    "description": "Common libraries used by Guzzle",
    "keywords": ["common", "event", "exception", "collection"],
    "license": "MIT",
    "require": {
        "php": ">=5.3.2",
        "symfony/event-dispatcher": ">=2.1"
    },
    "autoload": {
        "psr-0": { "Guzzle\\Common": "" }
    },
    "target-dir": "Guzzle/Common",
    "extra": {
        "branch-alias": {
            "dev-master": "3.7-dev"
        }
    }
}
<?php

namespace Guzzle\Common;

/**
 * Guzzle version information
 */
class Version
{
    const VERSION = '3.9.3';

    /**
     * @var bool Set this value to true to enable warnings for deprecated functionality use. This should be on in your
     *           unit tests, but probably not in production.
     */
    public static $emitWarnings = false;

    /**
     * Emit a deprecation warning
     *
     * @param string $message Warning message
     */
    public static function warn($message)
    {
        if (self::$emitWarnings) {
            trigger_error('Deprecation warning: ' . $message, E_USER_DEPRECATED);
        }
    }
}
<?php

namespace Guzzle\Common;

use Symfony\Component\EventDispatcher\Event as SymfonyEvent;

/**
 * Default event for Guzzle notifications
 */
class Event extends SymfonyEvent implements ToArrayInterface, \ArrayAccess, \IteratorAggregate
{
    /** @var array */
    private $context;

    /**
     * @param array $context Contextual information
     */
    public function __construct(array $context = array())
    {
        $this->context = $context;
    }

    public function getIterator()
    {
        return new \ArrayIterator($this->context);
    }

    public function offsetGet($offset)
    {
        return isset($this->context[$offset]) ? $this->context[$offset] : null;
    }

    public function offsetSet($offset, $value)
    {
        $this->context[$offset] = $value;
    }

    public function offsetExists($offset)
    {
        return isset($this->context[$offset]);
    }

    public function offsetUnset($offset)
    {
        unset($this->context[$offset]);
    }

    public function toArray()
    {
        return $this->context;
    }
}
<?php

namespace Guzzle\Common;

use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Class that holds an event dispatcher
 */
class AbstractHasDispatcher implements HasDispatcherInterface
{
    /** @var EventDispatcherInterface */
    protected $eventDispatcher;

    public static function getAllEvents()
    {
        return array();
    }

    public function setEventDispatcher(EventDispatcherInterface $eventDispatcher)
    {
        $this->eventDispatcher = $eventDispatcher;

        return $this;
    }

    public function getEventDispatcher()
    {
        if (!$this->eventDispatcher) {
            $this->eventDispatcher = new EventDispatcher();
        }

        return $this->eventDispatcher;
    }

    public function dispatch($eventName, array $context = array())
    {
        return $this->getEventDispatcher()->dispatch($eventName, new Event($context));
    }

    public function addSubscriber(EventSubscriberInterface $subscriber)
    {
        $this->getEventDispatcher()->addSubscriber($subscriber);

        return $this;
    }
}
<?php

namespace Guzzle\Common;

/**
 * An object that can be represented as an array
 */
interface ToArrayInterface
{
    /**
     * Get the array representation of an object
     *
     * @return array
     */
    public function toArray();
}
<?php

namespace Guzzle\Common;

/**
 * Interfaces that adds a factory method which is used to instantiate a class from an array of configuration options.
 */
interface FromConfigInterface
{
    /**
     * Static factory method used to turn an array or collection of configuration data into an instantiated object.
     *
     * @param array|Collection $config Configuration data
     *
     * @return FromConfigInterface
     */
    public static function factory($config = array());
}
<?php

namespace Guzzle\Stream;

use Guzzle\Common\Exception\InvalidArgumentException;

/**
 * PHP stream implementation
 */
class Stream implements StreamInterface
{
    const STREAM_TYPE = 'stream_type';
    const WRAPPER_TYPE = 'wrapper_type';
    const IS_LOCAL = 'is_local';
    const IS_READABLE = 'is_readable';
    const IS_WRITABLE = 'is_writable';
    const SEEKABLE = 'seekable';

    /** @var resource Stream resource */
    protected $stream;

    /** @var int Size of the stream contents in bytes */
    protected $size;

    /** @var array Stream cached data */
    protected $cache = array();

    /** @var array Custom stream data */
    protected $customData = array();

    /** @var array Hash table of readable and writeable stream types for fast lookups */
    protected static $readWriteHash = array(
        'read' => array(
            'r' => true, 'w+' => true, 'r+' => true, 'x+' => true, 'c+' => true,
            'rb' => true, 'w+b' => true, 'r+b' => true, 'x+b' => true, 'c+b' => true,
            'rt' => true, 'w+t' => true, 'r+t' => true, 'x+t' => true, 'c+t' => true, 'a+' => true
        ),
        'write' => array(
            'w' => true, 'w+' => true, 'rw' => true, 'r+' => true, 'x+' => true, 'c+' => true,
            'wb' => true, 'w+b' => true, 'r+b' => true, 'x+b' => true, 'c+b' => true,
            'w+t' => true, 'r+t' => true, 'x+t' => true, 'c+t' => true, 'a' => true, 'a+' => true
        )
    );

    /**
     * @param resource $stream Stream resource to wrap
     * @param int      $size   Size of the stream in bytes. Only pass if the size cannot be obtained from the stream.
     *
     * @throws InvalidArgumentException if the stream is not a stream resource
     */
    public function __construct($stream, $size = null)
    {
        $this->setStream($stream, $size);
    }

    /**
     * Closes the stream when the helper is destructed
     */
    public function __destruct()
    {
        $this->close();
    }

    public function __toString()
    {
        if (!$this->isReadable() || (!$this->isSeekable() && $this->isConsumed())) {
            return '';
        }

        $originalPos = $this->ftell();
        $body = stream_get_contents($this->stream, -1, 0);
        $this->seek($originalPos);

        return $body;
    }

    public function close()
    {
        if (is_resource($this->stream)) {
            fclose($this->stream);
        }
        $this->cache[self::IS_READABLE] = false;
        $this->cache[self::IS_WRITABLE] = false;
    }

    /**
     * Calculate a hash of a Stream
     *
     * @param StreamInterface $stream    Stream to calculate the hash for
     * @param string          $algo      Hash algorithm (e.g. md5, crc32, etc)
     * @param bool            $rawOutput Whether or not to use raw output
     *
     * @return bool|string Returns false on failure or a hash string on success
     */
    public static function getHash(StreamInterface $stream, $algo, $rawOutput = false)
    {
        $pos = $stream->ftell();
        if (!$stream->seek(0)) {
            return false;
        }

        $ctx = hash_init($algo);
        while (!$stream->feof()) {
            hash_update($ctx, $stream->read(8192));
        }

        $out = hash_final($ctx, (bool) $rawOutput);
        $stream->seek($pos);

        return $out;
    }

    public function getMetaData($key = null)
    {
        $meta = stream_get_meta_data($this->stream);

        return !$key ? $meta : (array_key_exists($key, $meta) ? $meta[$key] : null);
    }

    public function getStream()
    {
        return $this->stream;
    }

    public function setStream($stream, $size = null)
    {
        if (!is_resource($stream)) {
            throw new InvalidArgumentException('Stream must be a resource');
        }

        $this->size = $size;
        $this->stream = $stream;
        $this->rebuildCache();

        return $this;
    }

    public function detachStream()
    {
        $this->stream = null;

        return $this;
    }

    public function getWrapper()
    {
        return $this->cache[self::WRAPPER_TYPE];
    }

    public function getWrapperData()
    {
        return $this->getMetaData('wrapper_data') ?: array();
    }

    public function getStreamType()
    {
        return $this->cache[self::STREAM_TYPE];
    }

    public function getUri()
    {
        return $this->cache['uri'];
    }

    public function getSize()
    {
        if ($this->size !== null) {
            return $this->size;
        }

        // If the stream is a file based stream and local, then use fstat
        clearstatcache(true, $this->cache['uri']);
        $stats = fstat($this->stream);
        if (isset($stats['size'])) {
            $this->size = $stats['size'];
            return $this->size;
        } elseif ($this->cache[self::IS_READABLE] && $this->cache[self::SEEKABLE]) {
            // Only get the size based on the content if the the stream is readable and seekable
            $pos = $this->ftell();
            $this->size = strlen((string) $this);
            $this->seek($pos);
            return $this->size;
        }

        return false;
    }

    public function isReadable()
    {
        return $this->cache[self::IS_READABLE];
    }

    public function isRepeatable()
    {
        return $this->cache[self::IS_READABLE] && $this->cache[self::SEEKABLE];
    }

    public function isWritable()
    {
        return $this->cache[self::IS_WRITABLE];
    }

    public function isConsumed()
    {
        return feof($this->stream);
    }

    public function feof()
    {
        return $this->isConsumed();
    }

    public function isLocal()
    {
        return $this->cache[self::IS_LOCAL];
    }

    public function isSeekable()
    {
        return $this->cache[self::SEEKABLE];
    }

    public function setSize($size)
    {
        $this->size = $size;

        return $this;
    }

    public function seek($offset, $whence = SEEK_SET)
    {
        return $this->cache[self::SEEKABLE] ? fseek($this->stream, $offset, $whence) === 0 : false;
    }

    public function read($length)
    {
        return fread($this->stream, $length);
    }

    public function write($string)
    {
        // We can't know the size after writing anything
        $this->size = null;

        return fwrite($this->stream, $string);
    }

    public function ftell()
    {
        return ftell($this->stream);
    }

    public function rewind()
    {
        return $this->seek(0);
    }

    public function readLine($maxLength = null)
    {
        if (!$this->cache[self::IS_READABLE]) {
            return false;
        } else {
            return $maxLength ? fgets($this->getStream(), $maxLength) : fgets($this->getStream());
        }
    }

    public function setCustomData($key, $value)
    {
        $this->customData[$key] = $value;

        return $this;
    }

    public function getCustomData($key)
    {
        return isset($this->customData[$key]) ? $this->customData[$key] : null;
    }

    /**
     * Reprocess stream metadata
     */
    protected function rebuildCache()
    {
        $this->cache = stream_get_meta_data($this->stream);
        $this->cache[self::IS_LOCAL] = stream_is_local($this->stream);
        $this->cache[self::IS_READABLE] = isset(self::$readWriteHash['read'][$this->cache['mode']]);
        $this->cache[self::IS_WRITABLE] = isset(self::$readWriteHash['write'][$this->cache['mode']]);
    }
}
{
    "name": "guzzle/stream",
    "description": "Guzzle stream wrapper component",
    "homepage": "http://guzzlephp.org/",
    "keywords": ["stream", "component", "guzzle"],
    "license": "MIT",
    "authors": [
        {
            "name": "Michael Dowling",
            "email": "mtdowling@gmail.com",
            "homepage": "https://github.com/mtdowling"
        }
    ],
    "require": {
        "php": ">=5.3.2",
        "guzzle/common": "self.version"
    },
    "suggest": {
        "guzzle/http": "To convert Guzzle request objects to PHP streams"
    },
    "autoload": {
        "psr-0": { "Guzzle\\Stream": "" }
    },
    "target-dir": "Guzzle/Stream",
    "extra": {
        "branch-alias": {
            "dev-master": "3.7-dev"
        }
    }
}
<?php

namespace Guzzle\Stream;

use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Common\Exception\RuntimeException;
use Guzzle\Http\Message\EntityEnclosingRequestInterface;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Url;

/**
 * Factory used to create fopen streams using PHP's http and https stream wrappers
 *
 * Note: PHP's http stream wrapper only supports streaming downloads. It does not support streaming uploads.
 */
class PhpStreamRequestFactory implements StreamRequestFactoryInterface
{
    /** @var resource Stream context options */
    protected $context;

    /** @var array Stream context */
    protected $contextOptions;

    /** @var Url Stream URL */
    protected $url;

    /** @var array Last response headers received by the HTTP request */
    protected $lastResponseHeaders;

    /**
     * {@inheritdoc}
     *
     * The $params array can contain the following custom keys specific to the PhpStreamRequestFactory:
     * - stream_class: The name of a class to create instead of a Guzzle\Stream\Stream object
     */
    public function fromRequest(RequestInterface $request, $context = array(), array $params = array())
    {
        if (is_resource($context)) {
            $this->contextOptions = stream_context_get_options($context);
            $this->context = $context;
        } elseif (is_array($context) || !$context) {
            $this->contextOptions = $context;
            $this->createContext($params);
        } elseif ($context) {
            throw new InvalidArgumentException('$context must be an array or resource');
        }

        // Dispatch the before send event
        $request->dispatch('request.before_send', array(
            'request'         => $request,
            'context'         => $this->context,
            'context_options' => $this->contextOptions
        ));

        $this->setUrl($request);
        $this->addDefaultContextOptions($request);
        $this->addSslOptions($request);
        $this->addBodyOptions($request);
        $this->addProxyOptions($request);

        // Create the file handle but silence errors
        return $this->createStream($params)
            ->setCustomData('request', $request)
            ->setCustomData('response_headers', $this->getLastResponseHeaders());
    }

    /**
     * Set an option on the context and the internal options array
     *
     * @param string $wrapper   Stream wrapper name of http
     * @param string $name      Context name
     * @param mixed  $value     Context value
     * @param bool   $overwrite Set to true to overwrite an existing value
     */
    protected function setContextValue($wrapper, $name, $value, $overwrite = false)
    {
        if (!isset($this->contextOptions[$wrapper])) {
            $this->contextOptions[$wrapper] = array($name => $value);
        } elseif (!$overwrite && isset($this->contextOptions[$wrapper][$name])) {
            return;
        }
        $this->contextOptions[$wrapper][$name] = $value;
        stream_context_set_option($this->context, $wrapper, $name, $value);
    }

    /**
     * Create a stream context
     *
     * @param array $params Parameter array
     */
    protected function createContext(array $params)
    {
        $options = $this->contextOptions;
        $this->context = $this->createResource(function () use ($params, $options) {
            return stream_context_create($options, $params);
        });
    }

    /**
     * Get the last response headers received by the HTTP request
     *
     * @return array
     */
    public function getLastResponseHeaders()
    {
        return $this->lastResponseHeaders;
    }

    /**
     * Adds the default context options to the stream context options
     *
     * @param RequestInterface $request Request
     */
    protected function addDefaultContextOptions(RequestInterface $request)
    {
        $this->setContextValue('http', 'method', $request->getMethod());
        $headers = $request->getHeaderLines();

        // "Connection: close" is required to get streams to work in HTTP 1.1
        if (!$request->hasHeader('Connection')) {
            $headers[] = 'Connection: close';
        }

        $this->setContextValue('http', 'header', $headers);
        $this->setContextValue('http', 'protocol_version', $request->getProtocolVersion());
        $this->setContextValue('http', 'ignore_errors', true);
    }

    /**
     * Set the URL to use with the factory
     *
     * @param RequestInterface $request Request that owns the URL
     */
    protected function setUrl(RequestInterface $request)
    {
        $this->url = $request->getUrl(true);

        // Check for basic Auth username
        if ($request->getUsername()) {
            $this->url->setUsername($request->getUsername());
        }

        // Check for basic Auth password
        if ($request->getPassword()) {
            $this->url->setPassword($request->getPassword());
        }
    }

    /**
     * Add SSL options to the stream context
     *
     * @param RequestInterface $request Request
     */
    protected function addSslOptions(RequestInterface $request)
    {
        if ($request->getCurlOptions()->get(CURLOPT_SSL_VERIFYPEER)) {
            $this->setContextValue('ssl', 'verify_peer', true, true);
            if ($cafile = $request->getCurlOptions()->get(CURLOPT_CAINFO)) {
                $this->setContextValue('ssl', 'cafile', $cafile, true);
            }
        } else {
            $this->setContextValue('ssl', 'verify_peer', false, true);
        }
    }

    /**
     * Add body (content) specific options to the context options
     *
     * @param RequestInterface $request
     */
    protected function addBodyOptions(RequestInterface $request)
    {
        // Add the content for the request if needed
        if (!($request instanceof EntityEnclosingRequestInterface)) {
            return;
        }

        if (count($request->getPostFields())) {
            $this->setContextValue('http', 'content', (string) $request->getPostFields(), true);
        } elseif ($request->getBody()) {
            $this->setContextValue('http', 'content', (string) $request->getBody(), true);
        }

        // Always ensure a content-length header is sent
        if (isset($this->contextOptions['http']['content'])) {
            $headers = isset($this->contextOptions['http']['header']) ? $this->contextOptions['http']['header'] : array();
            $headers[] = 'Content-Length: ' . strlen($this->contextOptions['http']['content']);
            $this->setContextValue('http', 'header', $headers, true);
        }
    }

    /**
     * Add proxy parameters to the context if needed
     *
     * @param RequestInterface $request Request
     */
    protected function addProxyOptions(RequestInterface $request)
    {
        if ($proxy = $request->getCurlOptions()->get(CURLOPT_PROXY)) {
            $this->setContextValue('http', 'proxy', $proxy);
        }
    }

    /**
     * Create the stream for the request with the context options
     *
     * @param array $params Parameters of the stream
     *
     * @return StreamInterface
     */
    protected function createStream(array $params)
    {
        $http_response_header = null;
        $url = $this->url;
        $context = $this->context;
        $fp = $this->createResource(function () use ($context, $url, &$http_response_header) {
            return fopen((string) $url, 'r', false, $context);
        });

        // Determine the class to instantiate
        $className = isset($params['stream_class']) ? $params['stream_class'] : __NAMESPACE__ . '\\Stream';

        /** @var $stream StreamInterface */
        $stream = new $className($fp);

        // Track the response headers of the request
        if (isset($http_response_header)) {
            $this->lastResponseHeaders = $http_response_header;
            $this->processResponseHeaders($stream);
        }

        return $stream;
    }

    /**
     * Process response headers
     *
     * @param StreamInterface $stream
     */
    protected function processResponseHeaders(StreamInterface $stream)
    {
        // Set the size on the stream if it was returned in the response
        foreach ($this->lastResponseHeaders as $header) {
            if ((stripos($header, 'Content-Length:')) === 0) {
                $stream->setSize(trim(substr($header, 15)));
            }
        }
    }

    /**
     * Create a resource and check to ensure it was created successfully
     *
     * @param callable $callback Closure to invoke that must return a valid resource
     *
     * @return resource
     * @throws RuntimeException on error
     */
    protected function createResource($callback)
    {
        $errors = null;
        set_error_handler(function ($_, $msg, $file, $line) use (&$errors) {
            $errors[] = array(
                'message' => $msg,
                'file'    => $file,
                'line'    => $line
            );
            return true;
        });
        $resource = call_user_func($callback);
        restore_error_handler();

        if (!$resource) {
            $message = 'Error creating resource. ';
            foreach ($errors as $err) {
                foreach ($err as $key => $value) {
                    $message .= "[$key] $value" . PHP_EOL;
                }
            }
            throw new RuntimeException(trim($message));
        }

        return $resource;
    }
}
<?php

namespace Guzzle\Stream;

use Guzzle\Http\Message\RequestInterface;

/**
 * Interface used for creating streams from requests
 */
interface StreamRequestFactoryInterface
{
    /**
     * Create a stream based on a request object
     *
     * @param RequestInterface $request Base the stream on a request
     * @param array|resource   $context A stream_context_options resource or array of parameters used to create a
     *                                  stream context.
     * @param array            $params  Optional array of parameters specific to the factory
     *
     * @return StreamInterface Returns a stream object
     * @throws \Guzzle\Common\Exception\RuntimeException if the stream cannot be opened or an error occurs
     */
    public function fromRequest(RequestInterface $request, $context = array(), array $params = array());
}
<?php

namespace Guzzle\Stream;

/**
 * OO interface to PHP streams
 */
interface StreamInterface
{
    /**
     * Convert the stream to a string if the stream is readable and the stream is seekable.
     *
     * @return string
     */
    public function __toString();

    /**
     * Close the underlying stream
     */
    public function close();

    /**
     * Get stream metadata
     *
     * @param string $key Specific metadata to retrieve
     *
     * @return array|mixed|null
     */
    public function getMetaData($key = null);

    /**
     * Get the stream resource
     *
     * @return resource
     */
    public function getStream();

    /**
     * Set the stream that is wrapped by the object
     *
     * @param resource $stream Stream resource to wrap
     * @param int      $size   Size of the stream in bytes. Only pass if the size cannot be obtained from the stream.
     *
     * @return self
     */
    public function setStream($stream, $size = null);

    /**
     * Detach the current stream resource
     *
     * @return self
     */
    public function detachStream();

    /**
     * Get the stream wrapper type
     *
     * @return string
     */
    public function getWrapper();

    /**
     * Wrapper specific data attached to this stream.
     *
     * @return array
     */
    public function getWrapperData();

    /**
     * Get a label describing the underlying implementation of the stream
     *
     * @return string
     */
    public function getStreamType();

    /**
     * Get the URI/filename associated with this stream
     *
     * @return string
     */
    public function getUri();

    /**
     * Get the size of the stream if able
     *
     * @return int|bool
     */
    public function getSize();

    /**
     * Check if the stream is readable
     *
     * @return bool
     */
    public function isReadable();

    /**
     * Check if the stream is repeatable
     *
     * @return bool
     */
    public function isRepeatable();

    /**
     * Check if the stream is writable
     *
     * @return bool
     */
    public function isWritable();

    /**
     * Check if the stream has been consumed
     *
     * @return bool
     */
    public function isConsumed();

    /**
     * Alias of isConsumed
     *
     * @return bool
     */
    public function feof();

    /**
     * Check if the stream is a local stream vs a remote stream
     *
     * @return bool
     */
    public function isLocal();

    /**
     * Check if the string is repeatable
     *
     * @return bool
     */
    public function isSeekable();

    /**
     * Specify the size of the stream in bytes
     *
     * @param int $size Size of the stream contents in bytes
     *
     * @return self
     */
    public function setSize($size);

    /**
     * Seek to a position in the stream
     *
     * @param int $offset Stream offset
     * @param int $whence Where the offset is applied
     *
     * @return bool Returns TRUE on success or FALSE on failure
     * @link   http://www.php.net/manual/en/function.fseek.php
     */
    public function seek($offset, $whence = SEEK_SET);

    /**
     * Read data from the stream
     *
     * @param int $length Up to length number of bytes read.
     *
     * @return string|bool Returns the data read from the stream or FALSE on failure or EOF
     */
    public function read($length);

    /**
     * Write data to the stream
     *
     * @param string $string The string that is to be written.
     *
     * @return int|bool Returns the number of bytes written to the stream on success or FALSE on failure.
     */
    public function write($string);

    /**
     * Returns the current position of the file read/write pointer
     *
     * @return int|bool Returns the position of the file pointer or false on error
     */
    public function ftell();

    /**
     * Rewind to the beginning of the stream
     *
     * @return bool Returns true on success or false on failure
     */
    public function rewind();

    /**
     * Read a line from the stream up to the maximum allowed buffer length
     *
     * @param int $maxLength Maximum buffer length
     *
     * @return string|bool
     */
    public function readLine($maxLength = null);

    /**
     * Set custom data on the stream
     *
     * @param string $key   Key to set
     * @param mixed  $value Value to set
     *
     * @return self
     */
    public function setCustomData($key, $value);

    /**
     * Get custom data from the stream
     *
     * @param string $key Key to retrieve
     *
     * @return null|mixed
     */
    public function getCustomData($key);
}
<?php

namespace Guzzle\Log;

/**
 * Stores all log messages in an array
 */
class ArrayLogAdapter implements LogAdapterInterface
{
    protected $logs = array();

    public function log($message, $priority = LOG_INFO, $extras = array())
    {
        $this->logs[] = array('message' => $message, 'priority' => $priority, 'extras' => $extras);
    }

    /**
     * Get logged entries
     *
     * @return array
     */
    public function getLogs()
    {
        return $this->logs;
    }

    /**
     * Clears logged entries
     */
    public function clearLogs()
    {
        $this->logs = array();
    }
}
{
    "name": "guzzle/log",
    "description": "Guzzle log adapter component",
    "homepage": "http://guzzlephp.org/",
    "keywords": ["log", "adapter", "guzzle"],
    "license": "MIT",
    "authors": [
        {
            "name": "Michael Dowling",
            "email": "mtdowling@gmail.com",
            "homepage": "https://github.com/mtdowling"
        }
    ],
    "require": {
        "php": ">=5.3.2"
    },
    "autoload": {
        "psr-0": { "Guzzle\\Log": "" }
    },
    "suggest": {
        "guzzle/http": "self.version"
    },
    "target-dir": "Guzzle/Log",
    "extra": {
        "branch-alias": {
            "dev-master": "3.7-dev"
        }
    }
}
<?php

namespace Guzzle\Log;

/**
 * Adapter class that allows Guzzle to log data using various logging implementations
 */
abstract class AbstractLogAdapter implements LogAdapterInterface
{
    protected $log;

    public function getLogObject()
    {
        return $this->log;
    }
}
<?php

namespace Guzzle\Log;

use Guzzle\Common\Version;

/**
 * Adapts a Zend Framework 1 logger object
 * @deprecated
 * @codeCoverageIgnore
 */
class Zf1LogAdapter extends AbstractLogAdapter
{
    public function __construct(\Zend_Log $logObject)
    {
        $this->log = $logObject;
        Version::warn(__CLASS__ . ' is deprecated');
    }

    public function log($message, $priority = LOG_INFO, $extras = array())
    {
        $this->log->log($message, $priority, $extras);
    }
}
<?php

namespace Guzzle\Log;

use Psr\Log\LogLevel;
use Psr\Log\LoggerInterface;

/**
 * PSR-3 log adapter
 *
 * @link https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md
 */
class PsrLogAdapter extends AbstractLogAdapter
{
    /**
     * syslog to PSR-3 mappings
     */
    private static $mapping = array(
        LOG_DEBUG   => LogLevel::DEBUG,
        LOG_INFO    => LogLevel::INFO,
        LOG_WARNING => LogLevel::WARNING,
        LOG_ERR     => LogLevel::ERROR,
        LOG_CRIT    => LogLevel::CRITICAL,
        LOG_ALERT   => LogLevel::ALERT
    );

    public function __construct(LoggerInterface $logObject)
    {
        $this->log = $logObject;
    }

    public function log($message, $priority = LOG_INFO, $extras = array())
    {
        $this->log->log(self::$mapping[$priority], $message, $extras);
    }
}
<?php

namespace Guzzle\Log;

/**
 * Logs messages using Closures. Closures combined with filtering can trigger application events based on log messages.
 */
class ClosureLogAdapter extends AbstractLogAdapter
{
    public function __construct($logObject)
    {
        if (!is_callable($logObject)) {
            throw new \InvalidArgumentException('Object must be callable');
        }

        $this->log = $logObject;
    }

    public function log($message, $priority = LOG_INFO, $extras = array())
    {
        call_user_func($this->log, $message, $priority, $extras);
    }
}
<?php

namespace Guzzle\Log;

/**
 * Adapter class that allows Guzzle to log data to various logging implementations.
 */
interface LogAdapterInterface
{
    /**
     * Log a message at a priority
     *
     * @param string  $message  Message to log
     * @param integer $priority Priority of message (use the \LOG_* constants of 0 - 7)
     * @param array   $extras   Extra information to log in event
     */
    public function log($message, $priority = LOG_INFO, $extras = array());
}
<?php

namespace Guzzle\Log;

use Zend\Log\Logger;

/**
 * Adapts a Zend Framework 2 logger object
 */
class Zf2LogAdapter extends AbstractLogAdapter
{
    public function __construct(Logger $logObject)
    {
        $this->log = $logObject;
    }

    public function log($message, $priority = LOG_INFO, $extras = array())
    {
        $this->log->log($priority, $message, $extras);
    }
}
<?php

namespace Guzzle\Log;

use Monolog\Logger;

/**
 * @deprecated
 * @codeCoverageIgnore
 */
class MonologLogAdapter extends AbstractLogAdapter
{
    /**
     * syslog to Monolog mappings
     */
    private static $mapping = array(
        LOG_DEBUG   => Logger::DEBUG,
        LOG_INFO    => Logger::INFO,
        LOG_WARNING => Logger::WARNING,
        LOG_ERR     => Logger::ERROR,
        LOG_CRIT    => Logger::CRITICAL,
        LOG_ALERT   => Logger::ALERT
    );

    public function __construct(Logger $logObject)
    {
        $this->log = $logObject;
    }

    public function log($message, $priority = LOG_INFO, $extras = array())
    {
        $this->log->addRecord(self::$mapping[$priority], $message, $extras);
    }
}
<?php

namespace Guzzle\Log;

use Guzzle\Http\Curl\CurlHandle;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\EntityEnclosingRequestInterface;
use Guzzle\Http\Message\Response;

/**
 * Message formatter used in various places in the framework
 *
 * Format messages using a template that can contain the the following variables:
 *
 * - {request}:       Full HTTP request message
 * - {response}:      Full HTTP response message
 * - {ts}:            Timestamp
 * - {host}:          Host of the request
 * - {method}:        Method of the request
 * - {url}:           URL of the request
 * - {host}:          Host of the request
 * - {protocol}:      Request protocol
 * - {version}:       Protocol version
 * - {resource}:      Resource of the request (path + query + fragment)
 * - {port}:          Port of the request
 * - {hostname}:      Hostname of the machine that sent the request
 * - {code}:          Status code of the response (if available)
 * - {phrase}:        Reason phrase of the response  (if available)
 * - {curl_error}:    Curl error message (if available)
 * - {curl_code}:     Curl error code (if available)
 * - {curl_stderr}:   Curl standard error (if available)
 * - {connect_time}:  Time in seconds it took to establish the connection (if available)
 * - {total_time}:    Total transaction time in seconds for last transfer (if available)
 * - {req_header_*}:  Replace `*` with the lowercased name of a request header to add to the message
 * - {res_header_*}:  Replace `*` with the lowercased name of a response header to add to the message
 * - {req_body}:      Request body
 * - {res_body}:      Response body
 */
class MessageFormatter
{
    const DEFAULT_FORMAT = "{hostname} {req_header_User-Agent} - [{ts}] \"{method} {resource} {protocol}/{version}\" {code} {res_header_Content-Length}";
    const DEBUG_FORMAT = ">>>>>>>>\n{request}\n<<<<<<<<\n{response}\n--------\n{curl_stderr}";
    const SHORT_FORMAT = '[{ts}] "{method} {resource} {protocol}/{version}" {code}';

    /**
     * @var string Template used to format log messages
     */
    protected $template;

    /**
     * @param string $template Log message template
     */
    public function __construct($template = self::DEFAULT_FORMAT)
    {
        $this->template = $template ?: self::DEFAULT_FORMAT;
    }

    /**
     * Set the template to use for logging
     *
     * @param string $template Log message template
     *
     * @return self
     */
    public function setTemplate($template)
    {
        $this->template = $template;

        return $this;
    }

    /**
     * Returns a formatted message
     *
     * @param RequestInterface $request    Request that was sent
     * @param Response         $response   Response that was received
     * @param CurlHandle       $handle     Curl handle associated with the message
     * @param array            $customData Associative array of custom template data
     *
     * @return string
     */
    public function format(
        RequestInterface $request,
        Response $response = null,
        CurlHandle $handle = null,
        array $customData = array()
    ) {
        $cache = $customData;

        return preg_replace_callback(
            '/{\s*([A-Za-z_\-\.0-9]+)\s*}/',
            function (array $matches) use ($request, $response, $handle, &$cache) {

                if (array_key_exists($matches[1], $cache)) {
                    return $cache[$matches[1]];
                }

                $result = '';
                switch ($matches[1]) {
                    case 'request':
                        $result = (string) $request;
                        break;
                    case 'response':
                        $result = (string) $response;
                        break;
                    case 'req_body':
                        $result = $request instanceof EntityEnclosingRequestInterface
                            ? (string) $request->getBody() : '';
                        break;
                    case 'res_body':
                        $result = $response ? $response->getBody(true) : '';
                        break;
                    case 'ts':
                        $result = gmdate('c');
                        break;
                    case 'method':
                        $result = $request->getMethod();
                        break;
                    case 'url':
                        $result = (string) $request->getUrl();
                        break;
                    case 'resource':
                        $result = $request->getResource();
                        break;
                    case 'protocol':
                        $result = 'HTTP';
                        break;
                    case 'version':
                        $result = $request->getProtocolVersion();
                        break;
                    case 'host':
                        $result = $request->getHost();
                        break;
                    case 'hostname':
                        $result = gethostname();
                        break;
                    case 'port':
                        $result = $request->getPort();
                        break;
                    case 'code':
                        $result = $response ? $response->getStatusCode() : '';
                        break;
                    case 'phrase':
                        $result = $response ? $response->getReasonPhrase() : '';
                        break;
                    case 'connect_time':
                        $result = $handle && $handle->getInfo(CURLINFO_CONNECT_TIME)
                            ? $handle->getInfo(CURLINFO_CONNECT_TIME)
                            : ($response ? $response->getInfo('connect_time') : '');
                        break;
                    case 'total_time':
                        $result = $handle && $handle->getInfo(CURLINFO_TOTAL_TIME)
                            ? $handle->getInfo(CURLINFO_TOTAL_TIME)
                            : ($response ? $response->getInfo('total_time') : '');
                        break;
                    case 'curl_error':
                        $result = $handle ? $handle->getError() : '';
                        break;
                    case 'curl_code':
                        $result = $handle ? $handle->getErrorNo() : '';
                        break;
                    case 'curl_stderr':
                        $result =  $handle ? $handle->getStderr() : '';
                        break;
                    default:
                        if (strpos($matches[1], 'req_header_') === 0) {
                            $result = $request->getHeader(substr($matches[1], 11));
                        } elseif ($response && strpos($matches[1], 'res_header_') === 0) {
                            $result = $response->getHeader(substr($matches[1], 11));
                        }
                }

                $cache[$matches[1]] = $result;
                return $result;
            },
            $this->template
        );
    }
}
<?php

namespace Guzzle\Http;

use Guzzle\Common\HasDispatcherInterface;
use Guzzle\Common\Collection;
use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Http\Message\EntityEnclosingRequestInterface;
use Guzzle\Http\Message\RequestInterface;

/**
 * Client interface for send HTTP requests
 */
interface ClientInterface extends HasDispatcherInterface
{
    const CREATE_REQUEST = 'client.create_request';

    /** @var string RFC 1123 HTTP-Date */
    const HTTP_DATE = 'D, d M Y H:i:s \G\M\T';

    /**
     * Set the configuration object to use with the client
     *
     * @param array|Collection $config Parameters that define how the client behaves
     *
     * @return self
     */
    public function setConfig($config);

    /**
     * Get a configuration setting or all of the configuration settings. The Collection result of this method can be
     * modified to change the configuration settings of a client.
     *
     * A client should honor the following special values:
     *
     * - request.options: Associative array of default RequestFactory options to apply to each request
     * - request.params: Associative array of request parameters (data values) to apply to each request
     * - curl.options: Associative array of cURL configuration settings to apply to each request
     * - ssl.certificate_authority: Path a CAINFO, CAPATH, true to use strict defaults, or false to disable verification
     * - redirect.disable: Set to true to disable redirects
     *
     * @param bool|string $key Configuration value to retrieve. Set to FALSE to retrieve all values of the client.
     *                         The object return can be modified, and modifications will affect the client's config.
     * @return mixed|Collection
     * @see \Guzzle\Http\Message\RequestFactoryInterface::applyOptions for a full list of request.options options
     */
    public function getConfig($key = false);

    /**
     * Create and return a new {@see RequestInterface} configured for the client.
     *
     * Use an absolute path to override the base path of the client, or a relative path to append to the base path of
     * the client. The URI can contain the query string as well. Use an array to provide a URI template and additional
     * variables to use in the URI template expansion.
     *
     * @param string                                    $method  HTTP method. Defaults to GET
     * @param string|array                              $uri     Resource URI.
     * @param array|Collection                          $headers HTTP headers
     * @param string|resource|array|EntityBodyInterface $body    Entity body of request (POST/PUT) or response (GET)
     * @param array                                     $options Array of options to apply to the request
     *
     * @return RequestInterface
     * @throws InvalidArgumentException if a URI array is passed that does not contain exactly two elements: the URI
     *                                  followed by template variables
     */
    public function createRequest(
        $method = RequestInterface::GET,
        $uri = null,
        $headers = null,
        $body = null,
        array $options = array()
    );

    /**
     * Create a GET request for the client
     *
     * @param string|array     $uri     Resource URI
     * @param array|Collection $headers HTTP headers
     * @param array            $options Options to apply to the request. For BC compatibility, you can also pass a
     *                                  string to tell Guzzle to download the body of the response to a particular
     *                                  location. Use the 'body' option instead for forward compatibility.
     * @return RequestInterface
     * @see    Guzzle\Http\ClientInterface::createRequest()
     */
    public function get($uri = null, $headers = null, $options = array());

    /**
     * Create a HEAD request for the client
     *
     * @param string|array     $uri     Resource URI
     * @param array|Collection $headers HTTP headers
     * @param array            $options Options to apply to the request
     *
     * @return RequestInterface
     * @see    Guzzle\Http\ClientInterface::createRequest()
     */
    public function head($uri = null, $headers = null, array $options = array());

    /**
     * Create a DELETE request for the client
     *
     * @param string|array                        $uri     Resource URI
     * @param array|Collection                    $headers HTTP headers
     * @param string|resource|EntityBodyInterface $body    Body to send in the request
     * @param array                               $options Options to apply to the request
     *
     * @return EntityEnclosingRequestInterface
     * @see    Guzzle\Http\ClientInterface::createRequest()
     */
    public function delete($uri = null, $headers = null, $body = null, array $options = array());

    /**
     * Create a PUT request for the client
     *
     * @param string|array                        $uri     Resource URI
     * @param array|Collection                    $headers HTTP headers
     * @param string|resource|EntityBodyInterface $body    Body to send in the request
     * @param array                               $options Options to apply to the request
     *
     * @return EntityEnclosingRequestInterface
     * @see    Guzzle\Http\ClientInterface::createRequest()
     */
    public function put($uri = null, $headers = null, $body = null, array $options = array());

    /**
     * Create a PATCH request for the client
     *
     * @param string|array                        $uri     Resource URI
     * @param array|Collection                    $headers HTTP headers
     * @param string|resource|EntityBodyInterface $body    Body to send in the request
     * @param array                               $options Options to apply to the request
     *
     * @return EntityEnclosingRequestInterface
     * @see    Guzzle\Http\ClientInterface::createRequest()
     */
    public function patch($uri = null, $headers = null, $body = null, array $options = array());

    /**
     * Create a POST request for the client
     *
     * @param string|array                                $uri      Resource URI
     * @param array|Collection                            $headers  HTTP headers
     * @param array|Collection|string|EntityBodyInterface $postBody POST body. Can be a string, EntityBody, or
     *                                                    associative array of POST fields to send in the body of the
     *                                                    request. Prefix a value in the array with the @ symbol to
     *                                                    reference a file.
     * @param array                                       $options Options to apply to the request
     *
     * @return EntityEnclosingRequestInterface
     * @see    Guzzle\Http\ClientInterface::createRequest()
     */
    public function post($uri = null, $headers = null, $postBody = null, array $options = array());

    /**
     * Create an OPTIONS request for the client
     *
     * @param string|array $uri     Resource URI
     * @param array        $options Options to apply to the request
     *
     * @return RequestInterface
     * @see    Guzzle\Http\ClientInterface::createRequest()
     */
    public function options($uri = null, array $options = array());

    /**
     * Sends a single request or an array of requests in parallel
     *
     * @param array|RequestInterface $requests One or more RequestInterface objects to send
     *
     * @return \Guzzle\Http\Message\Response|array Returns a single Response or an array of Response objects
     */
    public function send($requests);

    /**
     * Get the client's base URL as either an expanded or raw URI template
     *
     * @param bool $expand Set to FALSE to get the raw base URL without URI template expansion
     *
     * @return string|null
     */
    public function getBaseUrl($expand = true);

    /**
     * Set the base URL of the client
     *
     * @param string $url The base service endpoint URL of the webservice
     *
     * @return self
     */
    public function setBaseUrl($url);

    /**
     * Set the User-Agent header to be used on all requests from the client
     *
     * @param string $userAgent      User agent string
     * @param bool   $includeDefault Set to true to prepend the value to Guzzle's default user agent string
     *
     * @return self
     */
    public function setUserAgent($userAgent, $includeDefault = false);

    /**
     * Set SSL verification options.
     *
     * Setting $certificateAuthority to TRUE will result in the bundled cacert.pem being used to verify against the
     * remote host.
     *
     * Alternate certificates to verify against can be specified with the $certificateAuthority option set to the full
     * path to a certificate file, or the path to a directory containing certificates.
     *
     * Setting $certificateAuthority to FALSE will turn off peer verification, unset the bundled cacert.pem, and
     * disable host verification. Please don't do this unless you really know what you're doing, and why you're doing
     * it.
     *
     * @param string|bool $certificateAuthority bool, file path, or directory path
     * @param bool        $verifyPeer           FALSE to stop from verifying the peer's certificate.
     * @param int         $verifyHost           Set to 1 to check the existence of a common name in the SSL peer
     *                                          certificate. 2 to check the existence of a common name and also verify
     *                                          that it matches the hostname provided.
     * @return self
     */
    public function setSslVerification($certificateAuthority = true, $verifyPeer = true, $verifyHost = 2);
}
<?php

namespace Guzzle\Http;

use Guzzle\Stream\StreamInterface;

/**
 * EntityBody decorator used to return only a subset of an entity body
 */
class ReadLimitEntityBody extends AbstractEntityBodyDecorator
{
    /** @var int Limit the number of bytes that can be read */
    protected $limit;

    /** @var int Offset to start reading from */
    protected $offset;

    /**
     * @param EntityBodyInterface $body   Body to wrap
     * @param int                 $limit  Total number of bytes to allow to be read from the stream
     * @param int                 $offset Position to seek to before reading (only works on seekable streams)
     */
    public function __construct(EntityBodyInterface $body, $limit, $offset = 0)
    {
        parent::__construct($body);
        $this->setLimit($limit)->setOffset($offset);
    }

    /**
     * Returns only a subset of the decorated entity body when cast as a string
     * {@inheritdoc}
     */
    public function __toString()
    {
        if (!$this->body->isReadable() ||
            (!$this->body->isSeekable() && $this->body->isConsumed())
        ) {
            return '';
        }

        $originalPos = $this->body->ftell();
        $this->body->seek($this->offset);
        $data = '';
        while (!$this->feof()) {
            $data .= $this->read(1048576);
        }
        $this->body->seek($originalPos);

        return (string) $data ?: '';
    }

    public function isConsumed()
    {
        return $this->body->isConsumed() ||
            ($this->body->ftell() >= $this->offset + $this->limit);
    }

    /**
     * Returns the Content-Length of the limited subset of data
     * {@inheritdoc}
     */
    public function getContentLength()
    {
        $length = $this->body->getContentLength();

        return $length === false
            ? $this->limit
            : min($this->limit, min($length, $this->offset + $this->limit) - $this->offset);
    }

    /**
     * Allow for a bounded seek on the read limited entity body
     * {@inheritdoc}
     */
    public function seek($offset, $whence = SEEK_SET)
    {
        return $whence === SEEK_SET
            ? $this->body->seek(max($this->offset, min($this->offset + $this->limit, $offset)))
            : false;
    }

    /**
     * Set the offset to start limiting from
     *
     * @param int $offset Offset to seek to and begin byte limiting from
     *
     * @return self
     */
    public function setOffset($offset)
    {
        $this->body->seek($offset);
        $this->offset = $offset;

        return $this;
    }

    /**
     * Set the limit of bytes that the decorator allows to be read from the stream
     *
     * @param int $limit Total number of bytes to allow to be read from the stream
     *
     * @return self
     */
    public function setLimit($limit)
    {
        $this->limit = $limit;

        return $this;
    }

    public function read($length)
    {
        // Check if the current position is less than the total allowed bytes + original offset
        $remaining = ($this->offset + $this->limit) - $this->body->ftell();
        if ($remaining > 0) {
            // Only return the amount of requested data, ensuring that the byte limit is not exceeded
            return $this->body->read(min($remaining, $length));
        } else {
            return false;
        }
    }
}
<?php

namespace Guzzle\Http\Message;

use Guzzle\Common\Exception\InvalidArgumentException;

/**
 * POST file upload
 */
interface PostFileInterface
{
    /**
     * Set the name of the field
     *
     * @param string $name Field name
     *
     * @return self
     */
    public function setFieldName($name);

    /**
     * Get the name of the field
     *
     * @return string
     */
    public function getFieldName();

    /**
     * Set the path to the file
     *
     * @param string $path Full path to the file
     *
     * @return self
     * @throws InvalidArgumentException if the file cannot be read
     */
    public function setFilename($path);

    /**
     * Set the post name of the file
     *
     * @param string $name The new name of the file
     *
     * @return self
     */
    public function setPostname($name);

    /**
     * Get the full path to the file
     *
     * @return string
     */
    public function getFilename();

    /**
     * Get the post name of the file
     *
     * @return string
     */
    public function getPostname();

    /**
     * Set the Content-Type of the file
     *
     * @param string $type Content type
     *
     * @return self
     */
    public function setContentType($type);

    /**
     * Get the Content-Type of the file
     *
     * @return string
     */
    public function getContentType();

    /**
     * Get a cURL ready string or CurlFile object for the upload
     *
     * @return string
     */
    public function getCurlValue();
}
<?php

namespace Guzzle\Http\Message;

use Guzzle\Common\Version;
use Guzzle\Common\ToArrayInterface;
use Guzzle\Common\Exception\RuntimeException;
use Guzzle\Http\EntityBodyInterface;
use Guzzle\Http\EntityBody;
use Guzzle\Http\Exception\BadResponseException;
use Guzzle\Http\RedirectPlugin;
use Guzzle\Parser\ParserRegistry;

/**
 * Guzzle HTTP response object
 */
class Response extends AbstractMessage implements \Serializable
{
    /**
     * @var array Array of reason phrases and their corresponding status codes
     */
    private static $statusTexts = array(
        100 => 'Continue',
        101 => 'Switching Protocols',
        102 => 'Processing',
        200 => 'OK',
        201 => 'Created',
        202 => 'Accepted',
        203 => 'Non-Authoritative Information',
        204 => 'No Content',
        205 => 'Reset Content',
        206 => 'Partial Content',
        207 => 'Multi-Status',
        208 => 'Already Reported',
        226 => 'IM Used',
        300 => 'Multiple Choices',
        301 => 'Moved Permanently',
        302 => 'Found',
        303 => 'See Other',
        304 => 'Not Modified',
        305 => 'Use Proxy',
        307 => 'Temporary Redirect',
        308 => 'Permanent Redirect',
        400 => 'Bad Request',
        401 => 'Unauthorized',
        402 => 'Payment Required',
        403 => 'Forbidden',
        404 => 'Not Found',
        405 => 'Method Not Allowed',
        406 => 'Not Acceptable',
        407 => 'Proxy Authentication Required',
        408 => 'Request Timeout',
        409 => 'Conflict',
        410 => 'Gone',
        411 => 'Length Required',
        412 => 'Precondition Failed',
        413 => 'Request Entity Too Large',
        414 => 'Request-URI Too Long',
        415 => 'Unsupported Media Type',
        416 => 'Requested Range Not Satisfiable',
        417 => 'Expectation Failed',
        422 => 'Unprocessable Entity',
        423 => 'Locked',
        424 => 'Failed Dependency',
        425 => 'Reserved for WebDAV advanced collections expired proposal',
        426 => 'Upgrade required',
        428 => 'Precondition Required',
        429 => 'Too Many Requests',
        431 => 'Request Header Fields Too Large',
        500 => 'Internal Server Error',
        501 => 'Not Implemented',
        502 => 'Bad Gateway',
        503 => 'Service Unavailable',
        504 => 'Gateway Timeout',
        505 => 'HTTP Version Not Supported',
        506 => 'Variant Also Negotiates (Experimental)',
        507 => 'Insufficient Storage',
        508 => 'Loop Detected',
        510 => 'Not Extended',
        511 => 'Network Authentication Required',
    );

    /** @var EntityBodyInterface The response body */
    protected $body;

    /** @var string The reason phrase of the response (human readable code) */
    protected $reasonPhrase;

    /** @var string The status code of the response */
    protected $statusCode;

    /** @var array Information about the request */
    protected $info = array();

    /** @var string The effective URL that returned this response */
    protected $effectiveUrl;

    /** @var array Cacheable response codes (see RFC 2616:13.4) */
    protected static $cacheResponseCodes = array(200, 203, 206, 300, 301, 410);

    /**
     * Create a new Response based on a raw response message
     *
     * @param string $message Response message
     *
     * @return self|bool Returns false on error
     */
    public static function fromMessage($message)
    {
        $data = ParserRegistry::getInstance()->getParser('message')->parseResponse($message);
        if (!$data) {
            return false;
        }

        $response = new static($data['code'], $data['headers'], $data['body']);
        $response->setProtocol($data['protocol'], $data['version'])
                 ->setStatus($data['code'], $data['reason_phrase']);

        // Set the appropriate Content-Length if the one set is inaccurate (e.g. setting to X)
        $contentLength = (string) $response->getHeader('Content-Length');
        $actualLength = strlen($data['body']);
        if (strlen($data['body']) > 0 && $contentLength != $actualLength) {
            $response->setHeader('Content-Length', $actualLength);
        }

        return $response;
    }

    /**
     * Construct the response
     *
     * @param string                              $statusCode The response status code (e.g. 200, 404, etc)
     * @param ToArrayInterface|array              $headers    The response headers
     * @param string|resource|EntityBodyInterface $body       The body of the response
     *
     * @throws BadResponseException if an invalid response code is given
     */
    public function __construct($statusCode, $headers = null, $body = null)
    {
        parent::__construct();
        $this->setStatus($statusCode);
        $this->body = EntityBody::factory($body !== null ? $body : '');

        if ($headers) {
            if (is_array($headers)) {
                $this->setHeaders($headers);
            } elseif ($headers instanceof ToArrayInterface) {
                $this->setHeaders($headers->toArray());
            } else {
                throw new BadResponseException('Invalid headers argument received');
            }
        }
    }

    /**
     * @return string
     */
    public function __toString()
    {
        return $this->getMessage();
    }

    public function serialize()
    {
        return json_encode(array(
            'status'  => $this->statusCode,
            'body'    => (string) $this->body,
            'headers' => $this->headers->toArray()
        ));
    }

    public function unserialize($serialize)
    {
        $data = json_decode($serialize, true);
        $this->__construct($data['status'], $data['headers'], $data['body']);
    }

    /**
     * Get the response entity body
     *
     * @param bool $asString Set to TRUE to return a string of the body rather than a full body object
     *
     * @return EntityBodyInterface|string
     */
    public function getBody($asString = false)
    {
        return $asString ? (string) $this->body : $this->body;
    }

    /**
     * Set the response entity body
     *
     * @param EntityBodyInterface|string $body Body to set
     *
     * @return self
     */
    public function setBody($body)
    {
        $this->body = EntityBody::factory($body);

        return $this;
    }

    /**
     * Set the protocol and protocol version of the response
     *
     * @param string $protocol Response protocol
     * @param string $version  Protocol version
     *
     * @return self
     */
    public function setProtocol($protocol, $version)
    {
        $this->protocol = $protocol;
        $this->protocolVersion = $version;

        return $this;
    }

    /**
     * Get the protocol used for the response (e.g. HTTP)
     *
     * @return string
     */
    public function getProtocol()
    {
        return $this->protocol;
    }

    /**
     * Get the HTTP protocol version
     *
     * @return string
     */
    public function getProtocolVersion()
    {
        return $this->protocolVersion;
    }

    /**
     * Get a cURL transfer information
     *
     * @param string $key A single statistic to check
     *
     * @return array|string|null Returns all stats if no key is set, a single stat if a key is set, or null if a key
     *                           is set and not found
     * @link http://www.php.net/manual/en/function.curl-getinfo.php
     */
    public function getInfo($key = null)
    {
        if ($key === null) {
            return $this->info;
        } elseif (array_key_exists($key, $this->info)) {
            return $this->info[$key];
        } else {
            return null;
        }
    }

    /**
     * Set the transfer information
     *
     * @param array $info Array of cURL transfer stats
     *
     * @return self
     */
    public function setInfo(array $info)
    {
        $this->info = $info;

        return $this;
    }

    /**
     * Set the response status
     *
     * @param int    $statusCode   Response status code to set
     * @param string $reasonPhrase Response reason phrase
     *
     * @return self
     * @throws BadResponseException when an invalid response code is received
     */
    public function setStatus($statusCode, $reasonPhrase = '')
    {
        $this->statusCode = (int) $statusCode;

        if (!$reasonPhrase && isset(self::$statusTexts[$this->statusCode])) {
            $this->reasonPhrase = self::$statusTexts[$this->statusCode];
        } else {
            $this->reasonPhrase = $reasonPhrase;
        }

        return $this;
    }

    /**
     * Get the response status code
     *
     * @return integer
     */
    public function getStatusCode()
    {
        return $this->statusCode;
    }

    /**
     * Get the entire response as a string
     *
     * @return string
     */
    public function getMessage()
    {
        $message = $this->getRawHeaders();

        // Only include the body in the message if the size is < 2MB
        $size = $this->body->getSize();
        if ($size < 2097152) {
            $message .= (string) $this->body;
        }

        return $message;
    }

    /**
     * Get the the raw message headers as a string
     *
     * @return string
     */
    public function getRawHeaders()
    {
        $headers = 'HTTP/1.1 ' . $this->statusCode . ' ' . $this->reasonPhrase . "\r\n";
        $lines = $this->getHeaderLines();
        if (!empty($lines)) {
            $headers .= implode("\r\n", $lines) . "\r\n";
        }

        return $headers . "\r\n";
    }

    /**
     * Get the response reason phrase- a human readable version of the numeric
     * status code
     *
     * @return string
     */
    public function getReasonPhrase()
    {
        return $this->reasonPhrase;
    }

    /**
     * Get the Accept-Ranges HTTP header
     *
     * @return string Returns what partial content range types this server supports.
     */
    public function getAcceptRanges()
    {
        return (string) $this->getHeader('Accept-Ranges');
    }

    /**
     * Calculate the age of the response
     *
     * @return integer
     */
    public function calculateAge()
    {
        $age = $this->getHeader('Age');

        if ($age === null && $this->getDate()) {
            $age = time() - strtotime($this->getDate());
        }

        return $age === null ? null : (int) (string) $age;
    }

    /**
     * Get the Age HTTP header
     *
     * @return integer|null Returns the age the object has been in a proxy cache in seconds.
     */
    public function getAge()
    {
        return (string) $this->getHeader('Age');
    }

    /**
     * Get the Allow HTTP header
     *
     * @return string|null Returns valid actions for a specified resource. To be used for a 405 Method not allowed.
     */
    public function getAllow()
    {
        return (string) $this->getHeader('Allow');
    }

    /**
     * Check if an HTTP method is allowed by checking the Allow response header
     *
     * @param string $method Method to check
     *
     * @return bool
     */
    public function isMethodAllowed($method)
    {
        $allow = $this->getHeader('Allow');
        if ($allow) {
            foreach (explode(',', $allow) as $allowable) {
                if (!strcasecmp(trim($allowable), $method)) {
                    return true;
                }
            }
        }

        return false;
    }

    /**
     * Get the Cache-Control HTTP header
     *
     * @return string
     */
    public function getCacheControl()
    {
        return (string) $this->getHeader('Cache-Control');
    }

    /**
     * Get the Connection HTTP header
     *
     * @return string
     */
    public function getConnection()
    {
        return (string) $this->getHeader('Connection');
    }

    /**
     * Get the Content-Encoding HTTP header
     *
     * @return string|null
     */
    public function getContentEncoding()
    {
        return (string) $this->getHeader('Content-Encoding');
    }

    /**
     * Get the Content-Language HTTP header
     *
     * @return string|null Returns the language the content is in.
     */
    public function getContentLanguage()
    {
        return (string) $this->getHeader('Content-Language');
    }

    /**
     * Get the Content-Length HTTP header
     *
     * @return integer Returns the length of the response body in bytes
     */
    public function getContentLength()
    {
        return (int) (string) $this->getHeader('Content-Length');
    }

    /**
     * Get the Content-Location HTTP header
     *
     * @return string|null Returns an alternate location for the returned data (e.g /index.htm)
     */
    public function getContentLocation()
    {
        return (string) $this->getHeader('Content-Location');
    }

    /**
     * Get the Content-Disposition HTTP header
     *
     * @return string|null Returns the Content-Disposition header
     */
    public function getContentDisposition()
    {
        return (string) $this->getHeader('Content-Disposition');
    }

    /**
     * Get the Content-MD5 HTTP header
     *
     * @return string|null Returns a Base64-encoded binary MD5 sum of the content of the response.
     */
    public function getContentMd5()
    {
        return (string) $this->getHeader('Content-MD5');
    }

    /**
     * Get the Content-Range HTTP header
     *
     * @return string Returns where in a full body message this partial message belongs (e.g. bytes 21010-47021/47022).
     */
    public function getContentRange()
    {
        return (string) $this->getHeader('Content-Range');
    }

    /**
     * Get the Content-Type HTTP header
     *
     * @return string Returns the mime type of this content.
     */
    public function getContentType()
    {
        return (string) $this->getHeader('Content-Type');
    }

    /**
     * Checks if the Content-Type is of a certain type.  This is useful if the
     * Content-Type header contains charset information and you need to know if
     * the Content-Type matches a particular type.
     *
     * @param string $type Content type to check against
     *
     * @return bool
     */
    public function isContentType($type)
    {
        return stripos($this->getHeader('Content-Type'), $type) !== false;
    }

    /**
     * Get the Date HTTP header
     *
     * @return string|null Returns the date and time that the message was sent.
     */
    public function getDate()
    {
        return (string) $this->getHeader('Date');
    }

    /**
     * Get the ETag HTTP header
     *
     * @return string|null Returns an identifier for a specific version of a resource, often a Message digest.
     */
    public function getEtag()
    {
        return (string) $this->getHeader('ETag');
    }

    /**
     * Get the Expires HTTP header
     *
     * @return string|null Returns the date/time after which the response is considered stale.
     */
    public function getExpires()
    {
        return (string) $this->getHeader('Expires');
    }

    /**
     * Get the Last-Modified HTTP header
     *
     * @return string|null Returns the last modified date for the requested object, in RFC 2822 format
     *                     (e.g. Tue, 15 Nov 1994 12:45:26 GMT)
     */
    public function getLastModified()
    {
        return (string) $this->getHeader('Last-Modified');
    }

    /**
     * Get the Location HTTP header
     *
     * @return string|null Used in redirection, or when a new resource has been created.
     */
    public function getLocation()
    {
        return (string) $this->getHeader('Location');
    }

    /**
     * Get the Pragma HTTP header
     *
     * @return Header|null Returns the implementation-specific headers that may have various effects anywhere along
     *                     the request-response chain.
     */
    public function getPragma()
    {
        return (string) $this->getHeader('Pragma');
    }

    /**
     * Get the Proxy-Authenticate HTTP header
     *
     * @return string|null Authentication to access the proxy (e.g. Basic)
     */
    public function getProxyAuthenticate()
    {
        return (string) $this->getHeader('Proxy-Authenticate');
    }

    /**
     * Get the Retry-After HTTP header
     *
     * @return int|null If an entity is temporarily unavailable, this instructs the client to try again after a
     *                  specified period of time.
     */
    public function getRetryAfter()
    {
        return (string) $this->getHeader('Retry-After');
    }

    /**
     * Get the Server HTTP header
     *
     * @return string|null A name for the server
     */
    public function getServer()
    {
        return (string)  $this->getHeader('Server');
    }

    /**
     * Get the Set-Cookie HTTP header
     *
     * @return string|null An HTTP cookie.
     */
    public function getSetCookie()
    {
        return (string) $this->getHeader('Set-Cookie');
    }

    /**
     * Get the Trailer HTTP header
     *
     * @return string|null The Trailer general field value indicates that the given set of header fields is present in
     *                     the trailer of a message encoded with chunked transfer-coding.
     */
    public function getTrailer()
    {
        return (string) $this->getHeader('Trailer');
    }

    /**
     * Get the Transfer-Encoding HTTP header
     *
     * @return string|null The form of encoding used to safely transfer the entity to the user
     */
    public function getTransferEncoding()
    {
        return (string) $this->getHeader('Transfer-Encoding');
    }

    /**
     * Get the Vary HTTP header
     *
     * @return string|null Tells downstream proxies how to match future request headers to decide whether the cached
     *                     response can be used rather than requesting a fresh one from the origin server.
     */
    public function getVary()
    {
        return (string) $this->getHeader('Vary');
    }

    /**
     * Get the Via HTTP header
     *
     * @return string|null Informs the client of proxies through which the response was sent.
     */
    public function getVia()
    {
        return (string) $this->getHeader('Via');
    }

    /**
     * Get the Warning HTTP header
     *
     * @return string|null A general warning about possible problems with the entity body
     */
    public function getWarning()
    {
        return (string) $this->getHeader('Warning');
    }

    /**
     * Get the WWW-Authenticate HTTP header
     *
     * @return string|null Indicates the authentication scheme that should be used to access the requested entity
     */
    public function getWwwAuthenticate()
    {
        return (string) $this->getHeader('WWW-Authenticate');
    }

    /**
     * Checks if HTTP Status code is a Client Error (4xx)
     *
     * @return bool
     */
    public function isClientError()
    {
        return $this->statusCode >= 400 && $this->statusCode < 500;
    }

    /**
     * Checks if HTTP Status code is Server OR Client Error (4xx or 5xx)
     *
     * @return boolean
     */
    public function isError()
    {
        return $this->isClientError() || $this->isServerError();
    }

    /**
     * Checks if HTTP Status code is Information (1xx)
     *
     * @return bool
     */
    public function isInformational()
    {
        return $this->statusCode < 200;
    }

    /**
     * Checks if HTTP Status code is a Redirect (3xx)
     *
     * @return bool
     */
    public function isRedirect()
    {
        return $this->statusCode >= 300 && $this->statusCode < 400;
    }

    /**
     * Checks if HTTP Status code is Server Error (5xx)
     *
     * @return bool
     */
    public function isServerError()
    {
        return $this->statusCode >= 500 && $this->statusCode < 600;
    }

    /**
     * Checks if HTTP Status code is Successful (2xx | 304)
     *
     * @return bool
     */
    public function isSuccessful()
    {
        return ($this->statusCode >= 200 && $this->statusCode < 300) || $this->statusCode == 304;
    }

    /**
     * Check if the response can be cached based on the response headers
     *
     * @return bool Returns TRUE if the response can be cached or false if not
     */
    public function canCache()
    {
        // Check if the response is cacheable based on the code
        if (!in_array((int) $this->getStatusCode(), self::$cacheResponseCodes)) {
            return false;
        }

        // Make sure a valid body was returned and can be cached
        if ((!$this->getBody()->isReadable() || !$this->getBody()->isSeekable())
            && ($this->getContentLength() > 0 || $this->getTransferEncoding() == 'chunked')) {
            return false;
        }

        // Never cache no-store resources (this is a private cache, so private
        // can be cached)
        if ($this->getHeader('Cache-Control') && $this->getHeader('Cache-Control')->hasDirective('no-store')) {
            return false;
        }

        return $this->isFresh() || $this->getFreshness() === null || $this->canValidate();
    }

    /**
     * Gets the number of seconds from the current time in which this response is still considered fresh
     *
     * @return int|null Returns the number of seconds
     */
    public function getMaxAge()
    {
        if ($header = $this->getHeader('Cache-Control')) {
            // s-max-age, then max-age, then Expires
            if ($age = $header->getDirective('s-maxage')) {
                return $age;
            }
            if ($age = $header->getDirective('max-age')) {
                return $age;
            }
        }

        if ($this->getHeader('Expires')) {
            return strtotime($this->getExpires()) - time();
        }

        return null;
    }

    /**
     * Check if the response is considered fresh.
     *
     * A response is considered fresh when its age is less than or equal to the freshness lifetime (maximum age) of the
     * response.
     *
     * @return bool|null
     */
    public function isFresh()
    {
        $fresh = $this->getFreshness();

        return $fresh === null ? null : $fresh >= 0;
    }

    /**
     * Check if the response can be validated against the origin server using a conditional GET request.
     *
     * @return bool
     */
    public function canValidate()
    {
        return $this->getEtag() || $this->getLastModified();
    }

    /**
     * Get the freshness of the response by returning the difference of the maximum lifetime of the response and the
     * age of the response (max-age - age).
     *
     * Freshness values less than 0 mean that the response is no longer fresh and is ABS(freshness) seconds expired.
     * Freshness values of greater than zero is the number of seconds until the response is no longer fresh. A NULL
     * result means that no freshness information is available.
     *
     * @return int
     */
    public function getFreshness()
    {
        $maxAge = $this->getMaxAge();
        $age = $this->calculateAge();

        return $maxAge && $age ? ($maxAge - $age) : null;
    }

    /**
     * Parse the JSON response body and return an array
     *
     * @return array|string|int|bool|float
     * @throws RuntimeException if the response body is not in JSON format
     */
    public function json()
    {
        $data = json_decode((string) $this->body, true);
        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new RuntimeException('Unable to parse response body into JSON: ' . json_last_error());
        }

        return $data === null ? array() : $data;
    }

    /**
     * Parse the XML response body and return a \SimpleXMLElement.
     *
     * In order to prevent XXE attacks, this method disables loading external
     * entities. If you rely on external entities, then you must parse the
     * XML response manually by accessing the response body directly.
     *
     * @return \SimpleXMLElement
     * @throws RuntimeException if the response body is not in XML format
     * @link http://websec.io/2012/08/27/Preventing-XXE-in-PHP.html
     */
    public function xml()
    {
        $errorMessage = null;
        $internalErrors = libxml_use_internal_errors(true);
        $disableEntities = libxml_disable_entity_loader(true);
        libxml_clear_errors();

        try {
            $xml = new \SimpleXMLElement((string) $this->body ?: '<root />', LIBXML_NONET);
            if ($error = libxml_get_last_error()) {
                $errorMessage = $error->message;
            }
        } catch (\Exception $e) {
            $errorMessage = $e->getMessage();
        }

        libxml_clear_errors();
        libxml_use_internal_errors($internalErrors);
        libxml_disable_entity_loader($disableEntities);

        if ($errorMessage) {
            throw new RuntimeException('Unable to parse response body into XML: ' . $errorMessage);
        }

        return $xml;
    }

    /**
     * Get the redirect count of this response
     *
     * @return int
     */
    public function getRedirectCount()
    {
        return (int) $this->params->get(RedirectPlugin::REDIRECT_COUNT);
    }

    /**
     * Set the effective URL that resulted in this response (e.g. the last redirect URL)
     *
     * @param string $url The effective URL
     *
     * @return self
     */
    public function setEffectiveUrl($url)
    {
        $this->effectiveUrl = $url;

        return $this;
    }

    /**
     * Get the effective URL that resulted in this response (e.g. the last redirect URL)
     *
     * @return string
     */
    public function getEffectiveUrl()
    {
        return $this->effectiveUrl;
    }

    /**
     * @deprecated
     * @codeCoverageIgnore
     */
    public function getPreviousResponse()
    {
        Version::warn(__METHOD__ . ' is deprecated. Use the HistoryPlugin.');
        return null;
    }

    /**
     * @deprecated
     * @codeCoverageIgnore
     */
    public function setRequest($request)
    {
        Version::warn(__METHOD__ . ' is deprecated');
        return $this;
    }

    /**
     * @deprecated
     * @codeCoverageIgnore
     */
    public function getRequest()
    {
        Version::warn(__METHOD__ . ' is deprecated');
        return null;
    }
}
<?php

namespace Guzzle\Http\Message;

/**
 * Request and response message interface
 */
interface MessageInterface
{
    /**
     * Get application and plugin specific parameters set on the message.
     *
     * @return \Guzzle\Common\Collection
     */
    public function getParams();

    /**
     * Add a header to an existing collection of headers.
     *
     * @param string $header Header name to add
     * @param string $value  Value of the header
     *
     * @return self
     */
    public function addHeader($header, $value);

    /**
     * Add and merge in an array of HTTP headers.
     *
     * @param array $headers Associative array of header data.
     *
     * @return self
     */
    public function addHeaders(array $headers);

    /**
     * Retrieve an HTTP header by name. Performs a case-insensitive search of all headers.
     *
     * @param string $header Header to retrieve.
     *
     * @return Header|null
     */
    public function getHeader($header);

    /**
     * Get all headers as a collection
     *
     * @return \Guzzle\Http\Message\Header\HeaderCollection
     */
    public function getHeaders();

    /**
     * Check if the specified header is present.
     *
     * @param string $header The header to check.
     *
     * @return bool
     */
    public function hasHeader($header);

    /**
     * Remove a specific HTTP header.
     *
     * @param string $header HTTP header to remove.
     *
     * @return self
     */
    public function removeHeader($header);

    /**
     * Set an HTTP header and overwrite any existing value for the header
     *
     * @param string $header Name of the header to set.
     * @param mixed  $value  Value to set.
     *
     * @return self
     */
    public function setHeader($header, $value);

    /**
     * Overwrite all HTTP headers with the supplied array of headers
     *
     * @param array $headers Associative array of header data.
     *
     * @return self
     */
    public function setHeaders(array $headers);

    /**
     * Get an array of message header lines (e.g. ["Host: example.com", ...])
     *
     * @return array
     */
    public function getHeaderLines();

    /**
     * Get the raw message headers as a string
     *
     * @return string
     */
    public function getRawHeaders();
}
<?php

namespace Guzzle\Http\Message;

use Guzzle\Common\Version;
use Guzzle\Common\Collection;
use Guzzle\Http\Message\Header\HeaderCollection;
use Guzzle\Http\Message\Header\HeaderFactory;
use Guzzle\Http\Message\Header\HeaderFactoryInterface;
use Guzzle\Http\Message\Header\HeaderInterface;

/**
 * Abstract HTTP request/response message
 */
abstract class AbstractMessage implements MessageInterface
{
    /** @var array HTTP header collection */
    protected $headers;

    /** @var HeaderFactoryInterface $headerFactory */
    protected $headerFactory;

    /** @var Collection Custom message parameters that are extendable by plugins */
    protected $params;

    /** @var string Message protocol */
    protected $protocol = 'HTTP';

    /** @var string HTTP protocol version of the message */
    protected $protocolVersion = '1.1';

    public function __construct()
    {
        $this->params = new Collection();
        $this->headerFactory = new HeaderFactory();
        $this->headers = new HeaderCollection();
    }

    /**
     * Set the header factory to use to create headers
     *
     * @param HeaderFactoryInterface $factory
     *
     * @return self
     */
    public function setHeaderFactory(HeaderFactoryInterface $factory)
    {
        $this->headerFactory = $factory;

        return $this;
    }

    public function getParams()
    {
        return $this->params;
    }

    public function addHeader($header, $value)
    {
        if (isset($this->headers[$header])) {
            $this->headers[$header]->add($value);
        } elseif ($value instanceof HeaderInterface) {
            $this->headers[$header] = $value;
        } else {
            $this->headers[$header] = $this->headerFactory->createHeader($header, $value);
        }

        return $this;
    }

    public function addHeaders(array $headers)
    {
        foreach ($headers as $key => $value) {
            $this->addHeader($key, $value);
        }

        return $this;
    }

    public function getHeader($header)
    {
        return $this->headers[$header];
    }

    public function getHeaders()
    {
        return $this->headers;
    }

    public function getHeaderLines()
    {
        $headers = array();
        foreach ($this->headers as $value) {
            $headers[] = $value->getName() . ': ' . $value;
        }

        return $headers;
    }

    public function setHeader($header, $value)
    {
        unset($this->headers[$header]);
        $this->addHeader($header, $value);

        return $this;
    }

    public function setHeaders(array $headers)
    {
        $this->headers->clear();
        foreach ($headers as $key => $value) {
            $this->addHeader($key, $value);
        }

        return $this;
    }

    public function hasHeader($header)
    {
        return isset($this->headers[$header]);
    }

    public function removeHeader($header)
    {
        unset($this->headers[$header]);

        return $this;
    }

    /**
     * @deprecated Use $message->getHeader()->parseParams()
     * @codeCoverageIgnore
     */
    public function getTokenizedHeader($header, $token = ';')
    {
        Version::warn(__METHOD__ . ' is deprecated. Use $message->getHeader()->parseParams()');
        if ($this->hasHeader($header)) {
            $data = new Collection();
            foreach ($this->getHeader($header)->parseParams() as $values) {
                foreach ($values as $key => $value) {
                    if ($value === '') {
                        $data->set($data->count(), $key);
                    } else {
                        $data->add($key, $value);
                    }
                }
            }
            return $data;
        }
    }

    /**
     * @deprecated
     * @codeCoverageIgnore
     */
    public function setTokenizedHeader($header, $data, $token = ';')
    {
        Version::warn(__METHOD__ . ' is deprecated.');
        return $this;
    }

    /**
     * @deprecated
     * @codeCoverageIgnore
     */
    public function getCacheControlDirective($directive)
    {
        Version::warn(__METHOD__ . ' is deprecated. Use $message->getHeader(\'Cache-Control\')->getDirective()');
        if (!($header = $this->getHeader('Cache-Control'))) {
            return null;
        }

        return $header->getDirective($directive);
    }

    /**
     * @deprecated
     * @codeCoverageIgnore
     */
    public function hasCacheControlDirective($directive)
    {
        Version::warn(__METHOD__ . ' is deprecated. Use $message->getHeader(\'Cache-Control\')->hasDirective()');
        if ($header = $this->getHeader('Cache-Control')) {
            return $header->hasDirective($directive);
        } else {
            return false;
        }
    }

    /**
     * @deprecated
     * @codeCoverageIgnore
     */
    public function addCacheControlDirective($directive, $value = true)
    {
        Version::warn(__METHOD__ . ' is deprecated. Use $message->getHeader(\'Cache-Control\')->addDirective()');
        if (!($header = $this->getHeader('Cache-Control'))) {
            $this->addHeader('Cache-Control', '');
            $header = $this->getHeader('Cache-Control');
        }

        $header->addDirective($directive, $value);

        return $this;
    }

    /**
     * @deprecated
     * @codeCoverageIgnore
     */
    public function removeCacheControlDirective($directive)
    {
        Version::warn(__METHOD__ . ' is deprecated. Use $message->getHeader(\'Cache-Control\')->removeDirective()');
        if ($header = $this->getHeader('Cache-Control')) {
            $header->removeDirective($directive);
        }

        return $this;
    }
}
<?php

namespace Guzzle\Http\Message;

use Guzzle\Common\Collection;
use Guzzle\Common\HasDispatcherInterface;
use Guzzle\Http\Exception\RequestException;
use Guzzle\Http\ClientInterface;
use Guzzle\Http\EntityBodyInterface;
use Guzzle\Http\Url;
use Guzzle\Http\QueryString;

/**
 * Generic HTTP request interface
 */
interface RequestInterface extends MessageInterface, HasDispatcherInterface
{
    const STATE_NEW = 'new';
    const STATE_COMPLETE = 'complete';
    const STATE_TRANSFER = 'transfer';
    const STATE_ERROR = 'error';

    const GET = 'GET';
    const PUT = 'PUT';
    const POST = 'POST';
    const DELETE = 'DELETE';
    const HEAD = 'HEAD';
    const CONNECT = 'CONNECT';
    const OPTIONS = 'OPTIONS';
    const TRACE = 'TRACE';
    const PATCH = 'PATCH';

    /**
     * @return string
     */
    public function __toString();

    /**
     * Send the request
     *
     * @return Response
     * @throws RequestException on a request error
     */
    public function send();

    /**
     * Set the client used to transport the request
     *
     * @param ClientInterface $client
     *
     * @return self
     */
    public function setClient(ClientInterface $client);

    /**
     * Get the client used to transport the request
     *
     * @return ClientInterface $client
     */
    public function getClient();

    /**
     * Set the URL of the request
     *
     * @param string $url|Url Full URL to set including query string
     *
     * @return self
     */
    public function setUrl($url);

    /**
     * Get the full URL of the request (e.g. 'http://www.guzzle-project.com/')
     *
     * @param bool $asObject Set to TRUE to retrieve the URL as a clone of the URL object owned by the request.
     *
     * @return string|Url
     */
    public function getUrl($asObject = false);

    /**
     * Get the resource part of the the request, including the path, query string, and fragment
     *
     * @return string
     */
    public function getResource();

    /**
     * Get the collection of key value pairs that will be used as the query string in the request
     *
     * @return QueryString
     */
    public function getQuery();

    /**
     * Get the HTTP method of the request
     *
     * @return string
     */
    public function getMethod();

    /**
     * Get the URI scheme of the request (http, https, ftp, etc)
     *
     * @return string
     */
    public function getScheme();

    /**
     * Set the URI scheme of the request (http, https, ftp, etc)
     *
     * @param string $scheme Scheme to set
     *
     * @return self
     */
    public function setScheme($scheme);

    /**
     * Get the host of the request
     *
     * @return string
     */
    public function getHost();

    /**
     * Set the host of the request. Including a port in the host will modify the port of the request.
     *
     * @param string $host Host to set (e.g. www.yahoo.com, www.yahoo.com:80)
     *
     * @return self
     */
    public function setHost($host);

    /**
     * Get the path of the request (e.g. '/', '/index.html')
     *
     * @return string
     */
    public function getPath();

    /**
     * Set the path of the request (e.g. '/', '/index.html')
     *
     * @param string|array $path Path to set or array of segments to implode
     *
     * @return self
     */
    public function setPath($path);

    /**
     * Get the port that the request will be sent on if it has been set
     *
     * @return int|null
     */
    public function getPort();

    /**
     * Set the port that the request will be sent on
     *
     * @param int $port Port number to set
     *
     * @return self
     */
    public function setPort($port);

    /**
     * Get the username to pass in the URL if set
     *
     * @return string|null
     */
    public function getUsername();

    /**
     * Get the password to pass in the URL if set
     *
     * @return string|null
     */
    public function getPassword();

    /**
     * Set HTTP authorization parameters
     *
     * @param string|bool $user     User name or false disable authentication
     * @param string      $password Password
     * @param string      $scheme   Authentication scheme ('Basic', 'Digest', or a CURLAUTH_* constant (deprecated))
     *
     * @return self
     * @link http://www.ietf.org/rfc/rfc2617.txt
     * @link http://php.net/manual/en/function.curl-setopt.php See the available options for CURLOPT_HTTPAUTH
     * @throws RequestException
     */
    public function setAuth($user, $password = '', $scheme = 'Basic');

    /**
     * Get the HTTP protocol version of the request
     *
     * @return string
     */
    public function getProtocolVersion();

    /**
     * Set the HTTP protocol version of the request (e.g. 1.1 or 1.0)
     *
     * @param string $protocol HTTP protocol version to use with the request
     *
     * @return self
     */
    public function setProtocolVersion($protocol);

    /**
     * Get the previously received {@see Response} or NULL if the request has not been sent
     *
     * @return Response|null
     */
    public function getResponse();

    /**
     * Manually set a response for the request.
     *
     * This method is useful for specifying a mock response for the request or setting the response using a cache.
     * Manually setting a response will bypass the actual sending of a request.
     *
     * @param Response $response Response object to set
     * @param bool     $queued   Set to TRUE to keep the request in a state of not having been sent, but queue the
     *                           response for send()
     *
     * @return self Returns a reference to the object.
     */
    public function setResponse(Response $response, $queued = false);

    /**
     * The start of a response has been received for a request and the request is still in progress
     *
     * @param Response $response Response that has been received so far
     *
     * @return self
     */
    public function startResponse(Response $response);

    /**
     * Set the EntityBody that will hold a successful response message's entity body.
     *
     * This method should be invoked when you need to send the response's entity body somewhere other than the normal
     * php://temp buffer. For example, you can send the entity body to a socket, file, or some other custom stream.
     *
     * @param EntityBodyInterface|string|resource $body Response body object. Pass a string to attempt to store the
     *                                                  response body in a local file.
     * @return Request
     */
    public function setResponseBody($body);

    /**
     * Get the EntityBody that will hold the resulting response message's entity body. This response body will only
     * be used for successful responses. Intermediate responses (e.g. redirects) will not use the targeted response
     * body.
     *
     * @return EntityBodyInterface
     */
    public function getResponseBody();

    /**
     * Get the state of the request. One of 'complete', 'transfer', 'new', 'error'
     *
     * @return string
     */
    public function getState();

    /**
     * Set the state of the request
     *
     * @param string $state   State of the request ('complete', 'transfer', 'new', 'error')
     * @param array  $context Contextual information about the state change
     *
     * @return string Returns the current state of the request (which may have changed due to events being fired)
     */
    public function setState($state, array $context = array());

    /**
     * Get the cURL options that will be applied when the cURL handle is created
     *
     * @return Collection
     */
    public function getCurlOptions();

    /**
     * Get an array of Cookies
     *
     * @return array
     */
    public function getCookies();

    /**
     * Get a cookie value by name
     *
     * @param string $name Cookie to retrieve
     *
     * @return null|string
     */
    public function getCookie($name);

    /**
     * Add a Cookie value by name to the Cookie header
     *
     * @param string $name  Name of the cookie to add
     * @param string $value Value to set
     *
     * @return self
     */
    public function addCookie($name, $value);

    /**
     * Remove a specific cookie value by name
     *
     * @param string $name Cookie to remove by name
     *
     * @return self
     */
    public function removeCookie($name);
}
<?php

namespace Guzzle\Http\Message;

use Guzzle\Common\Collection;
use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Http\RedirectPlugin;
use Guzzle\Http\Url;
use Guzzle\Parser\ParserRegistry;

/**
 * Default HTTP request factory used to create the default {@see Request} and {@see EntityEnclosingRequest} objects.
 */
class RequestFactory implements RequestFactoryInterface
{
    /** @var RequestFactory Singleton instance of the default request factory */
    protected static $instance;

    /** @var array Hash of methods available to the class (provides fast isset() lookups) */
    protected $methods;

    /** @var string Class to instantiate for requests with no body */
    protected $requestClass = 'Guzzle\\Http\\Message\\Request';

    /** @var string Class to instantiate for requests with a body */
    protected $entityEnclosingRequestClass = 'Guzzle\\Http\\Message\\EntityEnclosingRequest';

    /**
     * Get a cached instance of the default request factory
     *
     * @return RequestFactory
     */
    public static function getInstance()
    {
        // @codeCoverageIgnoreStart
        if (!static::$instance) {
            static::$instance = new static();
        }
        // @codeCoverageIgnoreEnd

        return static::$instance;
    }

    public function __construct()
    {
        $this->methods = array_flip(get_class_methods(__CLASS__));
    }

    public function fromMessage($message)
    {
        $parsed = ParserRegistry::getInstance()->getParser('message')->parseRequest($message);

        if (!$parsed) {
            return false;
        }

        $request = $this->fromParts($parsed['method'], $parsed['request_url'],
            $parsed['headers'], $parsed['body'], $parsed['protocol'],
            $parsed['version']);

        // EntityEnclosingRequest adds an "Expect: 100-Continue" header when using a raw request body for PUT or POST
        // requests. This factory method should accurately reflect the message, so here we are removing the Expect
        // header if one was not supplied in the message.
        if (!isset($parsed['headers']['Expect']) && !isset($parsed['headers']['expect'])) {
            $request->removeHeader('Expect');
        }

        return $request;
    }

    public function fromParts(
        $method,
        array $urlParts,
        $headers = null,
        $body = null,
        $protocol = 'HTTP',
        $protocolVersion = '1.1'
    ) {
        return $this->create($method, Url::buildUrl($urlParts), $headers, $body)
                    ->setProtocolVersion($protocolVersion);
    }

    public function create($method, $url, $headers = null, $body = null, array $options = array())
    {
        $method = strtoupper($method);

        if ($method == 'GET' || $method == 'HEAD' || $method == 'TRACE') {
            // Handle non-entity-enclosing request methods
            $request = new $this->requestClass($method, $url, $headers);
            if ($body) {
                // The body is where the response body will be stored
                $type = gettype($body);
                if ($type == 'string' || $type == 'resource' || $type == 'object') {
                    $request->setResponseBody($body);
                }
            }
        } else {
            // Create an entity enclosing request by default
            $request = new $this->entityEnclosingRequestClass($method, $url, $headers);
            if ($body || $body === '0') {
                // Add POST fields and files to an entity enclosing request if an array is used
                if (is_array($body) || $body instanceof Collection) {
                    // Normalize PHP style cURL uploads with a leading '@' symbol
                    foreach ($body as $key => $value) {
                        if (is_string($value) && substr($value, 0, 1) == '@') {
                            $request->addPostFile($key, $value);
                            unset($body[$key]);
                        }
                    }
                    // Add the fields if they are still present and not all files
                    $request->addPostFields($body);
                } else {
                    // Add a raw entity body body to the request
                    $request->setBody($body, (string) $request->getHeader('Content-Type'));
                    if ((string) $request->getHeader('Transfer-Encoding') == 'chunked') {
                        $request->removeHeader('Content-Length');
                    }
                }
            }
        }

        if ($options) {
            $this->applyOptions($request, $options);
        }

        return $request;
    }

    /**
     * Clone a request while changing the method. Emulates the behavior of
     * {@see Guzzle\Http\Message\Request::clone}, but can change the HTTP method.
     *
     * @param RequestInterface $request Request to clone
     * @param string           $method  Method to set
     *
     * @return RequestInterface
     */
    public function cloneRequestWithMethod(RequestInterface $request, $method)
    {
        // Create the request with the same client if possible
        if ($request->getClient()) {
            $cloned = $request->getClient()->createRequest($method, $request->getUrl(), $request->getHeaders());
        } else {
            $cloned = $this->create($method, $request->getUrl(), $request->getHeaders());
        }

        $cloned->getCurlOptions()->replace($request->getCurlOptions()->toArray());
        $cloned->setEventDispatcher(clone $request->getEventDispatcher());
        // Ensure that that the Content-Length header is not copied if changing to GET or HEAD
        if (!($cloned instanceof EntityEnclosingRequestInterface)) {
            $cloned->removeHeader('Content-Length');
        } elseif ($request instanceof EntityEnclosingRequestInterface) {
            $cloned->setBody($request->getBody());
        }
        $cloned->getParams()->replace($request->getParams()->toArray());
        $cloned->dispatch('request.clone', array('request' => $cloned));

        return $cloned;
    }

    public function applyOptions(RequestInterface $request, array $options = array(), $flags = self::OPTIONS_NONE)
    {
        // Iterate over each key value pair and attempt to apply a config using function visitors
        foreach ($options as $key => $value) {
            $method = "visit_{$key}";
            if (isset($this->methods[$method])) {
                $this->{$method}($request, $value, $flags);
            }
        }
    }

    protected function visit_headers(RequestInterface $request, $value, $flags)
    {
        if (!is_array($value)) {
            throw new InvalidArgumentException('headers value must be an array');
        }

        if ($flags & self::OPTIONS_AS_DEFAULTS) {
            // Merge headers in but do not overwrite existing values
            foreach ($value as $key => $header) {
                if (!$request->hasHeader($key)) {
                    $request->setHeader($key, $header);
                }
            }
        } else {
            $request->addHeaders($value);
        }
    }

    protected function visit_body(RequestInterface $request, $value, $flags)
    {
        if ($request instanceof EntityEnclosingRequestInterface) {
            $request->setBody($value);
        } else {
            throw new InvalidArgumentException('Attempting to set a body on a non-entity-enclosing request');
        }
    }

    protected function visit_allow_redirects(RequestInterface $request, $value, $flags)
    {
        if ($value === false) {
            $request->getParams()->set(RedirectPlugin::DISABLE, true);
        }
    }

    protected function visit_auth(RequestInterface $request, $value, $flags)
    {
        if (!is_array($value)) {
            throw new InvalidArgumentException('auth value must be an array');
        }

        $request->setAuth($value[0], isset($value[1]) ? $value[1] : null, isset($value[2]) ? $value[2] : 'basic');
    }

    protected function visit_query(RequestInterface $request, $value, $flags)
    {
        if (!is_array($value)) {
            throw new InvalidArgumentException('query value must be an array');
        }

        if ($flags & self::OPTIONS_AS_DEFAULTS) {
            // Merge query string values in but do not overwrite existing values
            $query = $request->getQuery();
            $query->overwriteWith(array_diff_key($value, $query->toArray()));
        } else {
            $request->getQuery()->overwriteWith($value);
        }
    }

    protected function visit_cookies(RequestInterface $request, $value, $flags)
    {
        if (!is_array($value)) {
            throw new InvalidArgumentException('cookies value must be an array');
        }

        foreach ($value as $name => $v) {
            $request->addCookie($name, $v);
        }
    }

    protected function visit_events(RequestInterface $request, $value, $flags)
    {
        if (!is_array($value)) {
            throw new InvalidArgumentException('events value must be an array');
        }

        foreach ($value as $name => $method) {
            if (is_array($method)) {
                $request->getEventDispatcher()->addListener($name, $method[0], $method[1]);
            } else {
                $request->getEventDispatcher()->addListener($name, $method);
            }
        }
    }

    protected function visit_plugins(RequestInterface $request, $value, $flags)
    {
        if (!is_array($value)) {
            throw new InvalidArgumentException('plugins value must be an array');
        }

        foreach ($value as $plugin) {
            $request->addSubscriber($plugin);
        }
    }

    protected function visit_exceptions(RequestInterface $request, $value, $flags)
    {
        if ($value === false || $value === 0) {
            $dispatcher = $request->getEventDispatcher();
            foreach ($dispatcher->getListeners('request.error') as $listener) {
                if (is_array($listener) && $listener[0] == 'Guzzle\Http\Message\Request' && $listener[1] = 'onRequestError') {
                    $dispatcher->removeListener('request.error', $listener);
                    break;
                }
            }
        }
    }

    protected function visit_save_to(RequestInterface $request, $value, $flags)
    {
        $request->setResponseBody($value);
    }

    protected function visit_params(RequestInterface $request, $value, $flags)
    {
        if (!is_array($value)) {
            throw new InvalidArgumentException('params value must be an array');
        }

        $request->getParams()->overwriteWith($value);
    }

    protected function visit_timeout(RequestInterface $request, $value, $flags)
    {
        if (defined('CURLOPT_TIMEOUT_MS')) {
            $request->getCurlOptions()->set(CURLOPT_TIMEOUT_MS, $value * 1000);
        } else {
            $request->getCurlOptions()->set(CURLOPT_TIMEOUT, $value);
        }
    }

    protected function visit_connect_timeout(RequestInterface $request, $value, $flags)
    {
        if (defined('CURLOPT_CONNECTTIMEOUT_MS')) {
            $request->getCurlOptions()->set(CURLOPT_CONNECTTIMEOUT_MS, $value * 1000);
        } else {
            $request->getCurlOptions()->set(CURLOPT_CONNECTTIMEOUT, $value);
        }
    }

    protected function visit_debug(RequestInterface $request, $value, $flags)
    {
        if ($value) {
            $request->getCurlOptions()->set(CURLOPT_VERBOSE, true);
        }
    }

    protected function visit_verify(RequestInterface $request, $value, $flags)
    {
        $curl = $request->getCurlOptions();
        if ($value === true || is_string($value)) {
            $curl[CURLOPT_SSL_VERIFYHOST] = 2;
            $curl[CURLOPT_SSL_VERIFYPEER] = true;
            if ($value !== true) {
                $curl[CURLOPT_CAINFO] = $value;
            }
        } elseif ($value === false) {
            unset($curl[CURLOPT_CAINFO]);
            $curl[CURLOPT_SSL_VERIFYHOST] = 0;
            $curl[CURLOPT_SSL_VERIFYPEER] = false;
        }
    }

    protected function visit_proxy(RequestInterface $request, $value, $flags)
    {
        $request->getCurlOptions()->set(CURLOPT_PROXY, $value, $flags);
    }

    protected function visit_cert(RequestInterface $request, $value, $flags)
    {
        if (is_array($value)) {
            $request->getCurlOptions()->set(CURLOPT_SSLCERT, $value[0]);
            $request->getCurlOptions()->set(CURLOPT_SSLCERTPASSWD, $value[1]);
        } else {
            $request->getCurlOptions()->set(CURLOPT_SSLCERT, $value);
        }
    }

    protected function visit_ssl_key(RequestInterface $request, $value, $flags)
    {
        if (is_array($value)) {
            $request->getCurlOptions()->set(CURLOPT_SSLKEY, $value[0]);
            $request->getCurlOptions()->set(CURLOPT_SSLKEYPASSWD, $value[1]);
        } else {
            $request->getCurlOptions()->set(CURLOPT_SSLKEY, $value);
        }
    }
}
<?php

namespace Guzzle\Http\Message;

use Guzzle\Common\Version;
use Guzzle\Http\Message\Header\HeaderInterface;

/**
 * Represents a header and all of the values stored by that header
 */
class Header implements HeaderInterface
{
    protected $values = array();
    protected $header;
    protected $glue;

    /**
     * @param string       $header Name of the header
     * @param array|string $values Values of the header as an array or a scalar
     * @param string       $glue   Glue used to combine multiple values into a string
     */
    public function __construct($header, $values = array(), $glue = ',')
    {
        $this->header = trim($header);
        $this->glue = $glue;

        foreach ((array) $values as $value) {
            foreach ((array) $value as $v) {
                $this->values[] = $v;
            }
        }
    }

    public function __toString()
    {
        return implode($this->glue . ' ', $this->toArray());
    }

    public function add($value)
    {
        $this->values[] = $value;

        return $this;
    }

    public function getName()
    {
        return $this->header;
    }

    public function setName($name)
    {
        $this->header = $name;

        return $this;
    }

    public function setGlue($glue)
    {
        $this->glue = $glue;

        return $this;
    }

    public function getGlue()
    {
        return $this->glue;
    }

    /**
     * Normalize the header to be a single header with an array of values.
     *
     * If any values of the header contains the glue string value (e.g. ","), then the value will be exploded into
     * multiple entries in the header.
     *
     * @return self
     */
    public function normalize()
    {
        $values = $this->toArray();

        for ($i = 0, $total = count($values); $i < $total; $i++) {
            if (strpos($values[$i], $this->glue) !== false) {
                // Explode on glue when the glue is not inside of a comma
                foreach (preg_split('/' . preg_quote($this->glue) . '(?=([^"]*"[^"]*")*[^"]*$)/', $values[$i]) as $v) {
                    $values[] = trim($v);
                }
                unset($values[$i]);
            }
        }

        $this->values = array_values($values);

        return $this;
    }

    public function hasValue($searchValue)
    {
        return in_array($searchValue, $this->toArray());
    }

    public function removeValue($searchValue)
    {
        $this->values = array_values(array_filter($this->values, function ($value) use ($searchValue) {
            return $value != $searchValue;
        }));

        return $this;
    }

    public function toArray()
    {
        return $this->values;
    }

    public function count()
    {
        return count($this->toArray());
    }

    public function getIterator()
    {
        return new \ArrayIterator($this->toArray());
    }

    public function parseParams()
    {
        $params = $matches = array();
        $callback = array($this, 'trimHeader');

        // Normalize the header into a single array and iterate over all values
        foreach ($this->normalize()->toArray() as $val) {
            $part = array();
            foreach (preg_split('/;(?=([^"]*"[^"]*")*[^"]*$)/', $val) as $kvp) {
                if (!preg_match_all('/<[^>]+>|[^=]+/', $kvp, $matches)) {
                    continue;
                }
                $pieces = array_map($callback, $matches[0]);
                $part[$pieces[0]] = isset($pieces[1]) ? $pieces[1] : '';
            }
            if ($part) {
                $params[] = $part;
            }
        }

        return $params;
    }

    /**
     * @deprecated
     * @codeCoverageIgnore
     */
    public function hasExactHeader($header)
    {
        Version::warn(__METHOD__ . ' is deprecated');
        return $this->header == $header;
    }

    /**
     * @deprecated
     * @codeCoverageIgnore
     */
    public function raw()
    {
        Version::warn(__METHOD__ . ' is deprecated. Use toArray()');
        return $this->toArray();
    }

    /**
     * Trim a header by removing excess spaces and wrapping quotes
     *
     * @param $str
     *
     * @return string
     */
    protected function trimHeader($str)
    {
        static $trimmed = "\"'  \n\t";

        return trim($str, $trimmed);
    }
}
<?php

namespace Guzzle\Http\Message;

use Guzzle\Http\Exception\RequestException;
use Guzzle\Http\EntityBodyInterface;
use Guzzle\Http\QueryString;

/**
 * HTTP request that sends an entity-body in the request message (POST, PUT)
 */
interface EntityEnclosingRequestInterface extends RequestInterface
{
    const URL_ENCODED = 'application/x-www-form-urlencoded; charset=utf-8';
    const MULTIPART = 'multipart/form-data';

    /**
     * Set the body of the request
     *
     * @param string|resource|EntityBodyInterface $body        Body to use in the entity body of the request
     * @param string                              $contentType Content-Type to set. Leave null to use an existing
     *                                                         Content-Type or to guess the Content-Type
     * @return self
     * @throws RequestException if the protocol is < 1.1 and Content-Length can not be determined
     */
    public function setBody($body, $contentType = null);

    /**
     * Get the body of the request if set
     *
     * @return EntityBodyInterface|null
     */
    public function getBody();

    /**
     * Get a POST field from the request
     *
     * @param string $field Field to retrieve
     *
     * @return mixed|null
     */
    public function getPostField($field);

    /**
     * Get the post fields that will be used in the request
     *
     * @return QueryString
     */
    public function getPostFields();

    /**
     * Set a POST field value
     *
     * @param string $key   Key to set
     * @param string $value Value to set
     *
     * @return self
     */
    public function setPostField($key, $value);

    /**
     * Add POST fields to use in the request
     *
     * @param QueryString|array $fields POST fields
     *
     * @return self
     */
    public function addPostFields($fields);

    /**
     * Remove a POST field or file by name
     *
     * @param string $field Name of the POST field or file to remove
     *
     * @return self
     */
    public function removePostField($field);

    /**
     * Returns an associative array of POST field names to PostFileInterface objects
     *
     * @return array
     */
    public function getPostFiles();

    /**
     * Get a POST file from the request
     *
     * @param string $fieldName POST fields to retrieve
     *
     * @return array|null Returns an array wrapping an array of PostFileInterface objects
     */
    public function getPostFile($fieldName);

    /**
     * Remove a POST file from the request
     *
     * @param string $fieldName POST file field name to remove
     *
     * @return self
     */
    public function removePostFile($fieldName);

    /**
     * Add a POST file to the upload
     *
     * @param string $field       POST field to use (e.g. file). Used to reference content from the server.
     * @param string $filename    Full path to the file. Do not include the @ symbol.
     * @param string $contentType Optional Content-Type to add to the Content-Disposition.
     *                            Default behavior is to guess. Set to false to not specify.
     * @param string $postname    The name of the file, when posted. (e.g. rename the file)
     * @return self
     */
    public function addPostFile($field, $filename = null, $contentType = null, $postname = null);

    /**
     * Add POST files to use in the upload
     *
     * @param array $files An array of POST fields => filenames where filename can be a string or PostFileInterface
     *
     * @return self
     */
    public function addPostFiles(array $files);

    /**
     * Configure how redirects are handled for the request
     *
     * @param bool $strict       Set to true to follow strict RFC compliance when redirecting POST requests. Most
     *                           browsers with follow a 301-302 redirect for a POST request with a GET request. This is
     *                           the default behavior of Guzzle. Enable strict redirects to redirect these responses
     *                           with a POST rather than a GET request.
     * @param int  $maxRedirects Specify the maximum number of allowed redirects. Set to 0 to disable redirects.
     *
     * @return self
     */
    public function configureRedirects($strict = false, $maxRedirects = 5);
}
<?php

namespace Guzzle\Http\Message;

use Guzzle\Common\Version;
use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Http\Mimetypes;

/**
 * POST file upload
 */
class PostFile implements PostFileInterface
{
    protected $fieldName;
    protected $contentType;
    protected $filename;
    protected $postname;

    /**
     * @param string $fieldName   Name of the field
     * @param string $filename    Local path to the file
     * @param string $postname    Remote post file name
     * @param string $contentType Content-Type of the upload
     */
    public function __construct($fieldName, $filename, $contentType = null, $postname = null)
    {
        $this->fieldName = $fieldName;
        $this->setFilename($filename);
        $this->postname = $postname ? $postname : basename($filename);
        $this->contentType = $contentType ?: $this->guessContentType();
    }

    public function setFieldName($name)
    {
        $this->fieldName = $name;

        return $this;
    }

    public function getFieldName()
    {
        return $this->fieldName;
    }

    public function setFilename($filename)
    {
        // Remove leading @ symbol
        if (strpos($filename, '@') === 0) {
            $filename = substr($filename, 1);
        }

        if (!is_readable($filename)) {
            throw new InvalidArgumentException("Unable to open {$filename} for reading");
        }

        $this->filename = $filename;

        return $this;
    }

    public function setPostname($postname)
    {
        $this->postname = $postname;

        return $this;
    }

    public function getFilename()
    {
        return $this->filename;
    }

    public function getPostname()
    {
        return $this->postname;
    }

    public function setContentType($type)
    {
        $this->contentType = $type;

        return $this;
    }

    public function getContentType()
    {
        return $this->contentType;
    }

    public function getCurlValue()
    {
        // PHP 5.5 introduced a CurlFile object that deprecates the old @filename syntax
        // See: https://wiki.php.net/rfc/curl-file-upload
        if (function_exists('curl_file_create')) {
            return curl_file_create($this->filename, $this->contentType, $this->postname);
        }

        // Use the old style if using an older version of PHP
        $value = "@{$this->filename};filename=" . $this->postname;
        if ($this->contentType) {
            $value .= ';type=' . $this->contentType;
        }

        return $value;
    }

    /**
     * @deprecated
     * @codeCoverageIgnore
     */
    public function getCurlString()
    {
        Version::warn(__METHOD__ . ' is deprecated. Use getCurlValue()');
        return $this->getCurlValue();
    }

    /**
     * Determine the Content-Type of the file
     */
    protected function guessContentType()
    {
        return Mimetypes::getInstance()->fromFilename($this->filename) ?: 'application/octet-stream';
    }
}
<?php

namespace Guzzle\Http\Message;

use Guzzle\Http\EntityBody;
use Guzzle\Http\EntityBodyInterface;
use Guzzle\Http\QueryString;
use Guzzle\Http\RedirectPlugin;
use Guzzle\Http\Exception\RequestException;

/**
 * HTTP request that sends an entity-body in the request message (POST, PUT, PATCH, DELETE)
 */
class EntityEnclosingRequest extends Request implements EntityEnclosingRequestInterface
{
    /** @var int When the size of the body is greater than 1MB, then send Expect: 100-Continue */
    protected $expectCutoff = 1048576;

    /** @var EntityBodyInterface $body Body of the request */
    protected $body;

    /** @var QueryString POST fields to use in the EntityBody */
    protected $postFields;

    /** @var array POST files to send with the request */
    protected $postFiles = array();

    public function __construct($method, $url, $headers = array())
    {
        $this->postFields = new QueryString();
        parent::__construct($method, $url, $headers);
    }

    /**
     * @return string
     */
    public function __toString()
    {
        // Only attempt to include the POST data if it's only fields
        if (count($this->postFields) && empty($this->postFiles)) {
            return parent::__toString() . (string) $this->postFields;
        }

        return parent::__toString() . $this->body;
    }

    public function setState($state, array $context = array())
    {
        parent::setState($state, $context);
        if ($state == self::STATE_TRANSFER && !$this->body && !count($this->postFields) && !count($this->postFiles)) {
            $this->setHeader('Content-Length', 0)->removeHeader('Transfer-Encoding');
        }

        return $this->state;
    }

    public function setBody($body, $contentType = null)
    {
        $this->body = EntityBody::factory($body);

        // Auto detect the Content-Type from the path of the request if possible
        if ($contentType === null && !$this->hasHeader('Content-Type')) {
            $contentType = $this->body->getContentType();
        }

        if ($contentType) {
            $this->setHeader('Content-Type', $contentType);
        }

        // Always add the Expect 100-Continue header if the body cannot be rewound. This helps with redirects.
        if (!$this->body->isSeekable() && $this->expectCutoff !== false) {
            $this->setHeader('Expect', '100-Continue');
        }

        // Set the Content-Length header if it can be determined
        $size = $this->body->getContentLength();
        if ($size !== null && $size !== false) {
            $this->setHeader('Content-Length', $size);
            if ($size > $this->expectCutoff) {
                $this->setHeader('Expect', '100-Continue');
            }
        } elseif (!$this->hasHeader('Content-Length')) {
            if ('1.1' == $this->protocolVersion) {
                $this->setHeader('Transfer-Encoding', 'chunked');
            } else {
                throw new RequestException(
                    'Cannot determine Content-Length and cannot use chunked Transfer-Encoding when using HTTP/1.0'
                );
            }
        }

        return $this;
    }

    public function getBody()
    {
        return $this->body;
    }

    /**
     * Set the size that the entity body of the request must exceed before adding the Expect: 100-Continue header.
     *
     * @param int|bool $size Cutoff in bytes. Set to false to never send the expect header (even with non-seekable data)
     *
     * @return self
     */
    public function setExpectHeaderCutoff($size)
    {
        $this->expectCutoff = $size;
        if ($size === false || !$this->body) {
            $this->removeHeader('Expect');
        } elseif ($this->body && $this->body->getSize() && $this->body->getSize() > $size) {
            $this->setHeader('Expect', '100-Continue');
        }

        return $this;
    }

    public function configureRedirects($strict = false, $maxRedirects = 5)
    {
        $this->getParams()->set(RedirectPlugin::STRICT_REDIRECTS, $strict);
        if ($maxRedirects == 0) {
            $this->getParams()->set(RedirectPlugin::DISABLE, true);
        } else {
            $this->getParams()->set(RedirectPlugin::MAX_REDIRECTS, $maxRedirects);
        }

        return $this;
    }

    public function getPostField($field)
    {
        return $this->postFields->get($field);
    }

    public function getPostFields()
    {
        return $this->postFields;
    }

    public function setPostField($key, $value)
    {
        $this->postFields->set($key, $value);
        $this->processPostFields();

        return $this;
    }

    public function addPostFields($fields)
    {
        $this->postFields->merge($fields);
        $this->processPostFields();

        return $this;
    }

    public function removePostField($field)
    {
        $this->postFields->remove($field);
        $this->processPostFields();

        return $this;
    }

    public function getPostFiles()
    {
        return $this->postFiles;
    }

    public function getPostFile($fieldName)
    {
        return isset($this->postFiles[$fieldName]) ? $this->postFiles[$fieldName] : null;
    }

    public function removePostFile($fieldName)
    {
        unset($this->postFiles[$fieldName]);
        $this->processPostFields();

        return $this;
    }

    public function addPostFile($field, $filename = null, $contentType = null, $postname = null)
    {
        $data = null;

        if ($field instanceof PostFileInterface) {
            $data = $field;
        } elseif (is_array($filename)) {
            // Allow multiple values to be set in a single key
            foreach ($filename as $file) {
                $this->addPostFile($field, $file, $contentType);
            }
            return $this;
        } elseif (!is_string($filename)) {
            throw new RequestException('The path to a file must be a string');
        } elseif (!empty($filename)) {
            // Adding an empty file will cause cURL to error out
            $data = new PostFile($field, $filename, $contentType, $postname);
        }

        if ($data) {
            if (!isset($this->postFiles[$data->getFieldName()])) {
                $this->postFiles[$data->getFieldName()] = array($data);
            } else {
                $this->postFiles[$data->getFieldName()][] = $data;
            }
            $this->processPostFields();
        }

        return $this;
    }

    public function addPostFiles(array $files)
    {
        foreach ($files as $key => $file) {
            if ($file instanceof PostFileInterface) {
                $this->addPostFile($file, null, null, false);
            } elseif (is_string($file)) {
                // Convert non-associative array keys into 'file'
                if (is_numeric($key)) {
                    $key = 'file';
                }
                $this->addPostFile($key, $file, null, false);
            } else {
                throw new RequestException('File must be a string or instance of PostFileInterface');
            }
        }

        return $this;
    }

    /**
     * Determine what type of request should be sent based on post fields
     */
    protected function processPostFields()
    {
        if (!$this->postFiles) {
            $this->removeHeader('Expect')->setHeader('Content-Type', self::URL_ENCODED);
        } else {
            $this->setHeader('Content-Type', self::MULTIPART);
            if ($this->expectCutoff !== false) {
                $this->setHeader('Expect', '100-Continue');
            }
        }
    }
}
<?php

namespace Guzzle\Http\Message\Header;

use Guzzle\Common\ToArrayInterface;

/**
 * Provides a case-insensitive collection of headers
 */
class HeaderCollection implements \IteratorAggregate, \Countable, \ArrayAccess, ToArrayInterface
{
    /** @var array */
    protected $headers;

    public function __construct($headers = array())
    {
        $this->headers = $headers;
    }

    public function __clone()
    {
        foreach ($this->headers as &$header) {
            $header = clone $header;
        }
    }

    /**
     * Clears the header collection
     */
    public function clear()
    {
        $this->headers = array();
    }

    /**
     * Set a header on the collection
     *
     * @param HeaderInterface $header Header to add
     *
     * @return self
     */
    public function add(HeaderInterface $header)
    {
        $this->headers[strtolower($header->getName())] = $header;

        return $this;
    }

    /**
     * Get an array of header objects
     *
     * @return array
     */
    public function getAll()
    {
        return $this->headers;
    }

    /**
     * Alias of offsetGet
     */
    public function get($key)
    {
        return $this->offsetGet($key);
    }

    public function count()
    {
        return count($this->headers);
    }

    public function offsetExists($offset)
    {
        return isset($this->headers[strtolower($offset)]);
    }

    public function offsetGet($offset)
    {
        $l = strtolower($offset);

        return isset($this->headers[$l]) ? $this->headers[$l] : null;
    }

    public function offsetSet($offset, $value)
    {
        $this->add($value);
    }

    public function offsetUnset($offset)
    {
        unset($this->headers[strtolower($offset)]);
    }

    public function getIterator()
    {
        return new \ArrayIterator($this->headers);
    }

    public function toArray()
    {
        $result = array();
        foreach ($this->headers as $header) {
            $result[$header->getName()] = $header->toArray();
        }

        return $result;
    }
}
<?php

namespace Guzzle\Http\Message\Header;

use Guzzle\Http\Message\Header;

/**
 * Default header factory implementation
 */
class HeaderFactory implements HeaderFactoryInterface
{
    /** @var array */
    protected $mapping = array(
        'cache-control' => 'Guzzle\Http\Message\Header\CacheControl',
        'link'          => 'Guzzle\Http\Message\Header\Link',
    );

    public function createHeader($header, $value = null)
    {
        $lowercase = strtolower($header);

        return isset($this->mapping[$lowercase])
            ? new $this->mapping[$lowercase]($header, $value)
            : new Header($header, $value);
    }
}
<?php

namespace Guzzle\Http\Message\Header;

use Guzzle\Common\ToArrayInterface;

interface HeaderInterface extends ToArrayInterface, \Countable, \IteratorAggregate
{
    /**
     * Convert the header to a string
     *
     * @return string
     */
    public function __toString();

    /**
     * Add a value to the list of header values
     *
     * @param string $value Value to add to the header
     *
     * @return self
     */
    public function add($value);

    /**
     * Get the name of the header
     *
     * @return string
     */
    public function getName();

    /**
     * Change the name of the header
     *
     * @param string $name Name to change to
     *
     * @return self
     */
    public function setName($name);

    /**
     * Change the glue used to implode the values
     *
     * @param string $glue Glue used to implode multiple values
     *
     * @return self
     */
    public function setGlue($glue);

    /**
     * Get the glue used to implode multiple values into a string
     *
     * @return string
     */
    public function getGlue();

    /**
     * Check if the collection of headers has a particular value
     *
     * @param string $searchValue Value to search for
     *
     * @return bool
     */
    public function hasValue($searchValue);

    /**
     * Remove a specific value from the header
     *
     * @param string $searchValue Value to remove
     *
     * @return self
     */
    public function removeValue($searchValue);

    /**
     * Parse a header containing ";" separated data into an array of associative arrays representing the header
     * key value pair data of the header. When a parameter does not contain a value, but just contains a key, this
     * function will inject a key with a '' string value.
     *
     * @return array
     */
    public function parseParams();
}
<?php

namespace Guzzle\Http\Message\Header;

use Guzzle\Http\Message\Header;

/**
 * Provides helpful functionality for link headers
 */
class Link extends Header
{
    /**
     * Add a link to the header
     *
     * @param string $url    Link URL
     * @param string $rel    Link rel
     * @param array  $params Other link parameters
     *
     * @return self
     */
    public function addLink($url, $rel, array $params = array())
    {
        $values = array("<{$url}>", "rel=\"{$rel}\"");

        foreach ($params as $k => $v) {
            $values[] = "{$k}=\"{$v}\"";
        }

        return $this->add(implode('; ', $values));
    }

    /**
     * Check if a specific link exists for a given rel attribute
     *
     * @param string $rel rel value
     *
     * @return bool
     */
    public function hasLink($rel)
    {
        return $this->getLink($rel) !== null;
    }

    /**
     * Get a specific link for a given rel attribute
     *
     * @param string $rel Rel value
     *
     * @return array|null
     */
    public function getLink($rel)
    {
        foreach ($this->getLinks() as $link) {
            if (isset($link['rel']) && $link['rel'] == $rel) {
                return $link;
            }
        }

        return null;
    }

    /**
     * Get an associative array of links
     *
     * For example:
     * Link: <http:/.../front.jpeg>; rel=front; type="image/jpeg", <http://.../back.jpeg>; rel=back; type="image/jpeg"
     *
     * <code>
     * var_export($response->getLinks());
     * array(
     *     array(
     *         'url' => 'http:/.../front.jpeg',
     *         'rel' => 'back',
     *         'type' => 'image/jpeg',
     *     )
     * )
     * </code>
     *
     * @return array
     */
    public function getLinks()
    {
        $links = $this->parseParams();

        foreach ($links as &$link) {
            $key = key($link);
            unset($link[$key]);
            $link['url'] = trim($key, '<> ');
        }

        return $links;
    }
}
<?php

namespace Guzzle\Http\Message\Header;

/**
 * Interface for creating headers
 */
interface HeaderFactoryInterface
{
    /**
     * Create a header from a header name and a single value
     *
     * @param string $header Name of the header to create
     * @param string $value  Value to set on the header
     *
     * @return HeaderInterface
     */
    public function createHeader($header, $value = null);
}
<?php

namespace Guzzle\Http\Message\Header;

use Guzzle\Http\Message\Header;

/**
 * Provides helpful functionality for Cache-Control headers
 */
class CacheControl extends Header
{
    /** @var array */
    protected $directives;

    public function add($value)
    {
        parent::add($value);
        $this->directives = null;
    }

    public function removeValue($searchValue)
    {
        parent::removeValue($searchValue);
        $this->directives = null;
    }

    /**
     * Check if a specific cache control directive exists
     *
     * @param string $param Directive to retrieve
     *
     * @return bool
     */
    public function hasDirective($param)
    {
        $directives = $this->getDirectives();

        return isset($directives[$param]);
    }

    /**
     * Get a specific cache control directive
     *
     * @param string $param Directive to retrieve
     *
     * @return string|bool|null
     */
    public function getDirective($param)
    {
        $directives = $this->getDirectives();

        return isset($directives[$param]) ? $directives[$param] : null;
    }

    /**
     * Add a cache control directive
     *
     * @param string $param Directive to add
     * @param string $value Value to set
     *
     * @return self
     */
    public function addDirective($param, $value)
    {
        $directives = $this->getDirectives();
        $directives[$param] = $value;
        $this->updateFromDirectives($directives);

        return $this;
    }

    /**
     * Remove a cache control directive by name
     *
     * @param string $param Directive to remove
     *
     * @return self
     */
    public function removeDirective($param)
    {
        $directives = $this->getDirectives();
        unset($directives[$param]);
        $this->updateFromDirectives($directives);

        return $this;
    }

    /**
     * Get an associative array of cache control directives
     *
     * @return array
     */
    public function getDirectives()
    {
        if ($this->directives === null) {
            $this->directives = array();
            foreach ($this->parseParams() as $collection) {
                foreach ($collection as $key => $value) {
                    $this->directives[$key] = $value === '' ? true : $value;
                }
            }
        }

        return $this->directives;
    }

    /**
     * Updates the header value based on the parsed directives
     *
     * @param array $directives Array of cache control directives
     */
    protected function updateFromDirectives(array $directives)
    {
        $this->directives = $directives;
        $this->values = array();

        foreach ($directives as $key => $value) {
            $this->values[] = $value === true ? $key : "{$key}={$value}";
        }
    }
}
<?php

namespace Guzzle\Http\Message;

use Guzzle\Common\Version;
use Guzzle\Common\Event;
use Guzzle\Common\Collection;
use Guzzle\Common\Exception\RuntimeException;
use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Http\Exception\RequestException;
use Guzzle\Http\Exception\BadResponseException;
use Guzzle\Http\ClientInterface;
use Guzzle\Http\EntityBody;
use Guzzle\Http\EntityBodyInterface;
use Guzzle\Http\Message\Header\HeaderInterface;
use Guzzle\Http\Url;
use Guzzle\Parser\ParserRegistry;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * HTTP request class to send requests
 */
class Request extends AbstractMessage implements RequestInterface
{
    /** @var EventDispatcherInterface */
    protected $eventDispatcher;

    /** @var Url HTTP Url */
    protected $url;

    /** @var string HTTP method (GET, PUT, POST, DELETE, HEAD, OPTIONS, TRACE) */
    protected $method;

    /** @var ClientInterface */
    protected $client;

    /** @var Response Response of the request */
    protected $response;

    /** @var EntityBodyInterface Response body */
    protected $responseBody;

    /** @var string State of the request object */
    protected $state;

    /** @var string Authentication username */
    protected $username;

    /** @var string Auth password */
    protected $password;

    /** @var Collection cURL specific transfer options */
    protected $curlOptions;

    /** @var bool */
    protected $isRedirect = false;

    public static function getAllEvents()
    {
        return array(
            // Called when receiving or uploading data through cURL
            'curl.callback.read', 'curl.callback.write', 'curl.callback.progress',
            // Cloning a request
            'request.clone',
            // About to send the request, sent request, completed transaction
            'request.before_send', 'request.sent', 'request.complete',
            // A request received a successful response
            'request.success',
            // A request received an unsuccessful response
            'request.error',
            // An exception is being thrown because of an unsuccessful response
            'request.exception',
            // Received response status line
            'request.receive.status_line'
        );
    }

    /**
     * @param string           $method  HTTP method
     * @param string|Url       $url     HTTP URL to connect to. The URI scheme, host header, and URI are parsed from the
     *                                  full URL. If query string parameters are present they will be parsed as well.
     * @param array|Collection $headers HTTP headers
     */
    public function __construct($method, $url, $headers = array())
    {
        parent::__construct();
        $this->method = strtoupper($method);
        $this->curlOptions = new Collection();
        $this->setUrl($url);

        if ($headers) {
            // Special handling for multi-value headers
            foreach ($headers as $key => $value) {
                // Deal with collisions with Host and Authorization
                if ($key == 'host' || $key == 'Host') {
                    $this->setHeader($key, $value);
                } elseif ($value instanceof HeaderInterface) {
                    $this->addHeader($key, $value);
                } else {
                    foreach ((array) $value as $v) {
                        $this->addHeader($key, $v);
                    }
                }
            }
        }

        $this->setState(self::STATE_NEW);
    }

    public function __clone()
    {
        if ($this->eventDispatcher) {
            $this->eventDispatcher = clone $this->eventDispatcher;
        }
        $this->curlOptions = clone $this->curlOptions;
        $this->params = clone $this->params;
        $this->url = clone $this->url;
        $this->response = $this->responseBody = null;
        $this->headers = clone $this->headers;

        $this->setState(RequestInterface::STATE_NEW);
        $this->dispatch('request.clone', array('request' => $this));
    }

    /**
     * Get the HTTP request as a string
     *
     * @return string
     */
    public function __toString()
    {
        return $this->getRawHeaders() . "\r\n\r\n";
    }

    /**
     * Default method that will throw exceptions if an unsuccessful response is received.
     *
     * @param Event $event Received
     * @throws BadResponseException if the response is not successful
     */
    public static function onRequestError(Event $event)
    {
        $e = BadResponseException::factory($event['request'], $event['response']);
        $event['request']->setState(self::STATE_ERROR, array('exception' => $e) + $event->toArray());
        throw $e;
    }

    public function setClient(ClientInterface $client)
    {
        $this->client = $client;

        return $this;
    }

    public function getClient()
    {
        return $this->client;
    }

    public function getRawHeaders()
    {
        $protocolVersion = $this->protocolVersion ?: '1.1';

        return trim($this->method . ' ' . $this->getResource()) . ' '
            . strtoupper(str_replace('https', 'http', $this->url->getScheme()))
            . '/' . $protocolVersion . "\r\n" . implode("\r\n", $this->getHeaderLines());
    }

    public function setUrl($url)
    {
        if ($url instanceof Url) {
            $this->url = $url;
        } else {
            $this->url = Url::factory($url);
        }

        // Update the port and host header
        $this->setPort($this->url->getPort());

        if ($this->url->getUsername() || $this->url->getPassword()) {
            $this->setAuth($this->url->getUsername(), $this->url->getPassword());
            // Remove the auth info from the URL
            $this->url->setUsername(null);
            $this->url->setPassword(null);
        }

        return $this;
    }

    public function send()
    {
        if (!$this->client) {
            throw new RuntimeException('A client must be set on the request');
        }

        return $this->client->send($this);
    }

    public function getResponse()
    {
        return $this->response;
    }

    public function getQuery($asString = false)
    {
        return $asString
            ? (string) $this->url->getQuery()
            : $this->url->getQuery();
    }

    public function getMethod()
    {
        return $this->method;
    }

    public function getScheme()
    {
        return $this->url->getScheme();
    }

    public function setScheme($scheme)
    {
        $this->url->setScheme($scheme);

        return $this;
    }

    public function getHost()
    {
        return $this->url->getHost();
    }

    public function setHost($host)
    {
        $this->url->setHost($host);
        $this->setPort($this->url->getPort());

        return $this;
    }

    public function getProtocolVersion()
    {
        return $this->protocolVersion;
    }

    public function setProtocolVersion($protocol)
    {
        $this->protocolVersion = $protocol;

        return $this;
    }

    public function getPath()
    {
        return '/' . ltrim($this->url->getPath(), '/');
    }

    public function setPath($path)
    {
        $this->url->setPath($path);

        return $this;
    }

    public function getPort()
    {
        return $this->url->getPort();
    }

    public function setPort($port)
    {
        $this->url->setPort($port);

        // Include the port in the Host header if it is not the default port for the scheme of the URL
        $scheme = $this->url->getScheme();
        if ($port && (($scheme == 'http' && $port != 80) || ($scheme == 'https' && $port != 443))) {
            $this->headers['host'] = $this->headerFactory->createHeader('Host', $this->url->getHost() . ':' . $port);
        } else {
            $this->headers['host'] = $this->headerFactory->createHeader('Host', $this->url->getHost());
        }

        return $this;
    }

    public function getUsername()
    {
        return $this->username;
    }

    public function getPassword()
    {
        return $this->password;
    }

    public function setAuth($user, $password = '', $scheme = CURLAUTH_BASIC)
    {
        static $authMap = array(
            'basic'  => CURLAUTH_BASIC,
            'digest' => CURLAUTH_DIGEST,
            'ntlm'   => CURLAUTH_NTLM,
            'any'    => CURLAUTH_ANY
        );

        // If we got false or null, disable authentication
        if (!$user) {
            $this->password = $this->username = null;
            $this->removeHeader('Authorization');
            $this->getCurlOptions()->remove(CURLOPT_HTTPAUTH);
            return $this;
        }

        if (!is_numeric($scheme)) {
            $scheme = strtolower($scheme);
            if (!isset($authMap[$scheme])) {
                throw new InvalidArgumentException($scheme . ' is not a valid authentication type');
            }
            $scheme = $authMap[$scheme];
        }

        $this->username = $user;
        $this->password = $password;

        // Bypass CURL when using basic auth to promote connection reuse
        if ($scheme == CURLAUTH_BASIC) {
            $this->getCurlOptions()->remove(CURLOPT_HTTPAUTH);
            $this->setHeader('Authorization', 'Basic ' . base64_encode($this->username . ':' . $this->password));
        } else {
            $this->getCurlOptions()
                ->set(CURLOPT_HTTPAUTH, $scheme)
                ->set(CURLOPT_USERPWD, $this->username . ':' . $this->password);
        }

        return $this;
    }

    public function getResource()
    {
        $resource = $this->getPath();
        if ($query = (string) $this->url->getQuery()) {
            $resource .= '?' . $query;
        }

        return $resource;
    }

    public function getUrl($asObject = false)
    {
        return $asObject ? clone $this->url : (string) $this->url;
    }

    public function getState()
    {
        return $this->state;
    }

    public function setState($state, array $context = array())
    {
        $oldState = $this->state;
        $this->state = $state;

        switch ($state) {
            case self::STATE_NEW:
                $this->response = null;
                break;
            case self::STATE_TRANSFER:
                if ($oldState !== $state) {
                    // Fix Content-Length and Transfer-Encoding collisions
                    if ($this->hasHeader('Transfer-Encoding') && $this->hasHeader('Content-Length')) {
                        $this->removeHeader('Transfer-Encoding');
                    }
                    $this->dispatch('request.before_send', array('request' => $this));
                }
                break;
            case self::STATE_COMPLETE:
                if ($oldState !== $state) {
                    $this->processResponse($context);
                    $this->responseBody = null;
                }
                break;
            case self::STATE_ERROR:
                if (isset($context['exception'])) {
                    $this->dispatch('request.exception', array(
                        'request'   => $this,
                        'response'  => isset($context['response']) ? $context['response'] : $this->response,
                        'exception' => isset($context['exception']) ? $context['exception'] : null
                    ));
                }
        }

        return $this->state;
    }

    public function getCurlOptions()
    {
        return $this->curlOptions;
    }

    public function startResponse(Response $response)
    {
        $this->state = self::STATE_TRANSFER;
        $response->setEffectiveUrl((string) $this->getUrl());
        $this->response = $response;

        return $this;
    }

    public function setResponse(Response $response, $queued = false)
    {
        $response->setEffectiveUrl((string) $this->url);

        if ($queued) {
            $ed = $this->getEventDispatcher();
            $ed->addListener('request.before_send', $f = function ($e) use ($response, &$f, $ed) {
                $e['request']->setResponse($response);
                $ed->removeListener('request.before_send', $f);
            }, -9999);
        } else {
            $this->response = $response;
            // If a specific response body is specified, then use it instead of the response's body
            if ($this->responseBody && !$this->responseBody->getCustomData('default') && !$response->isRedirect()) {
                $this->getResponseBody()->write((string) $this->response->getBody());
            } else {
                $this->responseBody = $this->response->getBody();
            }
            $this->setState(self::STATE_COMPLETE);
        }

        return $this;
    }

    public function setResponseBody($body)
    {
        // Attempt to open a file for writing if a string was passed
        if (is_string($body)) {
            // @codeCoverageIgnoreStart
            if (!($body = fopen($body, 'w+'))) {
                throw new InvalidArgumentException('Could not open ' . $body . ' for writing');
            }
            // @codeCoverageIgnoreEnd
        }

        $this->responseBody = EntityBody::factory($body);

        return $this;
    }

    public function getResponseBody()
    {
        if ($this->responseBody === null) {
            $this->responseBody = EntityBody::factory()->setCustomData('default', true);
        }

        return $this->responseBody;
    }

    /**
     * Determine if the response body is repeatable (readable + seekable)
     *
     * @return bool
     * @deprecated Use getResponseBody()->isSeekable()
     * @codeCoverageIgnore
     */
    public function isResponseBodyRepeatable()
    {
        Version::warn(__METHOD__ . ' is deprecated. Use $request->getResponseBody()->isRepeatable()');
        return !$this->responseBody ? true : $this->responseBody->isRepeatable();
    }

    public function getCookies()
    {
        if ($cookie = $this->getHeader('Cookie')) {
            $data = ParserRegistry::getInstance()->getParser('cookie')->parseCookie($cookie);
            return $data['cookies'];
        }

        return array();
    }

    public function getCookie($name)
    {
        $cookies = $this->getCookies();

        return isset($cookies[$name]) ? $cookies[$name] : null;
    }

    public function addCookie($name, $value)
    {
        if (!$this->hasHeader('Cookie')) {
            $this->setHeader('Cookie', "{$name}={$value}");
        } else {
            $this->getHeader('Cookie')->add("{$name}={$value}");
        }

        // Always use semicolons to separate multiple cookie headers
        $this->getHeader('Cookie')->setGlue(';');

        return $this;
    }

    public function removeCookie($name)
    {
        if ($cookie = $this->getHeader('Cookie')) {
            foreach ($cookie as $cookieValue) {
                if (strpos($cookieValue, $name . '=') === 0) {
                    $cookie->removeValue($cookieValue);
                }
            }
        }

        return $this;
    }

    public function setEventDispatcher(EventDispatcherInterface $eventDispatcher)
    {
        $this->eventDispatcher = $eventDispatcher;
        $this->eventDispatcher->addListener('request.error', array(__CLASS__, 'onRequestError'), -255);

        return $this;
    }

    public function getEventDispatcher()
    {
        if (!$this->eventDispatcher) {
            $this->setEventDispatcher(new EventDispatcher());
        }

        return $this->eventDispatcher;
    }

    public function dispatch($eventName, array $context = array())
    {
        $context['request'] = $this;

        return $this->getEventDispatcher()->dispatch($eventName, new Event($context));
    }

    public function addSubscriber(EventSubscriberInterface $subscriber)
    {
        $this->getEventDispatcher()->addSubscriber($subscriber);

        return $this;
    }

    /**
     * Get an array containing the request and response for event notifications
     *
     * @return array
     */
    protected function getEventArray()
    {
        return array(
            'request'  => $this,
            'response' => $this->response
        );
    }

    /**
     * Process a received response
     *
     * @param array $context Contextual information
     * @throws RequestException|BadResponseException on unsuccessful responses
     */
    protected function processResponse(array $context = array())
    {
        if (!$this->response) {
            // If no response, then processResponse shouldn't have been called
            $e = new RequestException('Error completing request');
            $e->setRequest($this);
            throw $e;
        }

        $this->state = self::STATE_COMPLETE;

        // A request was sent, but we don't know if we'll send more or if the final response will be successful
        $this->dispatch('request.sent', $this->getEventArray() + $context);

        // Some response processors will remove the response or reset the state (example: ExponentialBackoffPlugin)
        if ($this->state == RequestInterface::STATE_COMPLETE) {

            // The request completed, so the HTTP transaction is complete
            $this->dispatch('request.complete', $this->getEventArray());

            // If the response is bad, allow listeners to modify it or throw exceptions. You can change the response by
            // modifying the Event object in your listeners or calling setResponse() on the request
            if ($this->response->isError()) {
                $event = new Event($this->getEventArray());
                $this->getEventDispatcher()->dispatch('request.error', $event);
                // Allow events of request.error to quietly change the response
                if ($event['response'] !== $this->response) {
                    $this->response = $event['response'];
                }
            }

            // If a successful response was received, dispatch an event
            if ($this->response->isSuccessful()) {
                $this->dispatch('request.success', $this->getEventArray());
            }
        }
    }

    /**
     * @deprecated Use Guzzle\Plugin\Cache\DefaultCanCacheStrategy
     * @codeCoverageIgnore
     */
    public function canCache()
    {
        Version::warn(__METHOD__ . ' is deprecated. Use Guzzle\Plugin\Cache\DefaultCanCacheStrategy.');
        if (class_exists('Guzzle\Plugin\Cache\DefaultCanCacheStrategy')) {
            $canCache = new \Guzzle\Plugin\Cache\DefaultCanCacheStrategy();
            return $canCache->canCacheRequest($this);
        } else {
            return false;
        }
    }

    /**
     * @deprecated Use the history plugin (not emitting a warning as this is built-into the RedirectPlugin for now)
     * @codeCoverageIgnore
     */
    public function setIsRedirect($isRedirect)
    {
        $this->isRedirect = $isRedirect;

        return $this;
    }

    /**
     * @deprecated Use the history plugin
     * @codeCoverageIgnore
     */
    public function isRedirect()
    {
        Version::warn(__METHOD__ . ' is deprecated. Use the HistoryPlugin to track this.');
        return $this->isRedirect;
    }
}
<?php

namespace Guzzle\Http\Message;

use Guzzle\Common\Collection;
use Guzzle\Http\EntityBodyInterface;
use Guzzle\Http\Url;

/**
 * Request factory used to create HTTP requests
 */
interface RequestFactoryInterface
{
    const OPTIONS_NONE = 0;
    const OPTIONS_AS_DEFAULTS = 1;

    /**
     * Create a new request based on an HTTP message
     *
     * @param string $message HTTP message as a string
     *
     * @return RequestInterface
     */
    public function fromMessage($message);

    /**
     * Create a request from URL parts as returned from parse_url()
     *
     * @param string $method HTTP method (GET, POST, PUT, HEAD, DELETE, etc)
     *
     * @param array $urlParts URL parts containing the same keys as parse_url()
     *     - scheme: e.g. http
     *     - host:   e.g. www.guzzle-project.com
     *     - port:   e.g. 80
     *     - user:   e.g. michael
     *     - pass:   e.g. rocks
     *     - path:   e.g. / OR /index.html
     *     - query:  after the question mark ?
     * @param array|Collection                          $headers         HTTP headers
     * @param string|resource|array|EntityBodyInterface $body            Body to send in the request
     * @param string                                    $protocol        Protocol (HTTP, SPYDY, etc)
     * @param string                                    $protocolVersion 1.0, 1.1, etc
     *
     * @return RequestInterface
     */
    public function fromParts(
        $method,
        array $urlParts,
        $headers = null,
        $body = null,
        $protocol = 'HTTP',
        $protocolVersion = '1.1'
    );

    /**
     * Create a new request based on the HTTP method
     *
     * @param string                                    $method  HTTP method (GET, POST, PUT, PATCH, HEAD, DELETE, ...)
     * @param string|Url                                $url     HTTP URL to connect to
     * @param array|Collection                          $headers HTTP headers
     * @param string|resource|array|EntityBodyInterface $body    Body to send in the request
     * @param array                                     $options Array of options to apply to the request
     *
     * @return RequestInterface
     */
    public function create($method, $url, $headers = null, $body = null, array $options = array());

    /**
     * Apply an associative array of options to the request
     *
     * @param RequestInterface $request Request to update
     * @param array            $options Options to use with the request. Available options are:
     *        "headers": Associative array of headers
     *        "query": Associative array of query string values to add to the request
     *        "body": Body of a request, including an EntityBody, string, or array when sending POST requests.
     *        "auth": Array of HTTP authentication parameters to use with the request. The array must contain the
     *            username in index [0], the password in index [2], and can optionally contain the authentication type
     *            in index [3]. The authentication types are: "Basic", "Digest", "NTLM", "Any" (defaults to "Basic").
     *        "cookies": Associative array of cookies
     *        "allow_redirects": Set to false to disable redirects
     *        "save_to": String, fopen resource, or EntityBody object used to store the body of the response
     *        "events": Associative array mapping event names to a closure or array of (priority, closure)
     *        "plugins": Array of plugins to add to the request
     *        "exceptions": Set to false to disable throwing exceptions on an HTTP level error (e.g. 404, 500, etc)
     *        "params": Set custom request data parameters on a request. (Note: these are not query string parameters)
     *        "timeout": Float describing the timeout of the request in seconds
     *        "connect_timeout": Float describing the number of seconds to wait while trying to connect. Use 0 to wait
     *            indefinitely.
     *        "verify": Set to true to enable SSL cert validation (the default), false to disable, or supply the path
     *            to a CA bundle to enable verification using a custom certificate.
     *        "cert": Set to a string to specify the path to a file containing a PEM formatted certificate. If a
     *            password is required, then set an array containing the path to the PEM file followed by the the
     *            password required for the certificate.
     *        "ssl_key": Specify the path to a file containing a private SSL key in PEM format. If a password is
     *            required, then set an array containing the path to the SSL key followed by the password required for
     *            the certificate.
     *        "proxy": Specify an HTTP proxy (e.g. "http://username:password@192.168.16.1:10")
     *        "debug": Set to true to display all data sent over the wire
     * @param int $flags Bitwise flags to apply when applying the options to the request. Defaults to no special
     *                   options. `1` (OPTIONS_AS_DEFAULTS): When specified, options will only update a request when
     *                   the value does not already exist on the request. This is only supported by "query" and
     *                   "headers". Other bitwise options may be added in the future.
     */
    public function applyOptions(RequestInterface $request, array $options = array(), $flags = self::OPTIONS_NONE);
}
##
## Bundle of CA Root Certificates
##
## Certificate data from Mozilla downloaded on: Wed Aug 13 21:49:32 2014
##
## This is a bundle of X.509 certificates of public Certificate Authorities
## (CA). These were automatically extracted from Mozilla's root certificates
## file (certdata.txt).  This file can be found in the mozilla source tree:
## http://hg.mozilla.org/releases/mozilla-release/raw-file/default/security/nss/lib/ckfw/builtins/certdata.txt
##
## It contains the certificates in PEM format and therefore
## can be directly used with curl / libcurl / php_curl, or with
## an Apache+mod_ssl webserver for SSL client authentication.
## Just configure this file as the SSLCACertificateFile.
##
## Conversion done with mk-ca-bundle.pl verison 1.22.
## SHA1: bf2c15b3019e696660321d2227d942936dc50aa7
##


GTE CyberTrust Global Root
==========================
-----BEGIN CERTIFICATE-----
MIICWjCCAcMCAgGlMA0GCSqGSIb3DQEBBAUAMHUxCzAJBgNVBAYTAlVTMRgwFgYDVQQKEw9HVEUg
Q29ycG9yYXRpb24xJzAlBgNVBAsTHkdURSBDeWJlclRydXN0IFNvbHV0aW9ucywgSW5jLjEjMCEG
A1UEAxMaR1RFIEN5YmVyVHJ1c3QgR2xvYmFsIFJvb3QwHhcNOTgwODEzMDAyOTAwWhcNMTgwODEz
MjM1OTAwWjB1MQswCQYDVQQGEwJVUzEYMBYGA1UEChMPR1RFIENvcnBvcmF0aW9uMScwJQYDVQQL
Ex5HVEUgQ3liZXJUcnVzdCBTb2x1dGlvbnMsIEluYy4xIzAhBgNVBAMTGkdURSBDeWJlclRydXN0
I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Q+XarfCaCMczE1ZMKxRHjuvK9buY0V7xdlfUNLjUA86iOe/FP3gx7kCAwEAAaOCAQkwggEFMHAG
A1UdHwRpMGcwZaBjoGGkXzBdMQswCQYDVQQGEwJVUzEQMA4GA1UEChMHRXF1aWZheDEtMCsGA1UE
CxMkRXF1aWZheCBTZWN1cmUgQ2VydGlmaWNhdGUgQXV0aG9yaXR5MQ0wCwYDVQQDEwRDUkwxMBoG
A1UdEAQTMBGBDzIwMTgwODIyMTY0MTUxWjALBgNVHQ8EBAMCAQYwHwYDVR0jBBgwFoAUSOZo+SvS
spXXR9gjIBBPM5iQn9QwHQYDVR0OBBYEFEjmaPkr0rKV10fYIyAQTzOYkJ/UMAwGA1UdEwQFMAMB
Af8wGgYJKoZIhvZ9B0EABA0wCxsFVjMuMGMDAgbAMA0GCSqGSIb3DQEBBQUAA4GBAFjOKer89961
zgK5F7WF0bnj4JXMJTENAKaSbn+2kmOeUJXRmm/kEd5jhW6Y7qj/WsjTVbJmcVfewCHrPSqnI0kB
BIZCe/zuf6IWUrVnZ9NA2zsmWLIodz2uFHdh1voqZiegDfqnc1zqcPGUIWVEX/r87yloqaKHee95
70+sB3c4
-----END CERTIFICATE-----

Verisign Class 3 Public Primary Certification Authority
=======================================================
-----BEGIN CERTIFICATE-----
MIICPDCCAaUCEHC65B0Q2Sk0tjjKewPMur8wDQYJKoZIhvcNAQECBQAwXzELMAkGA1UEBhMCVVMx
FzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAzIFB1YmxpYyBQcmltYXJ5
IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk2MDEyOTAwMDAwMFoXDTI4MDgwMTIzNTk1OVow
XzELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAz
IFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGfMA0GCSqGSIb3DQEBAQUA
A4GNADCBiQKBgQDJXFme8huKARS0EN8EQNvjV69qRUCPhAwL0TPZ2RHP7gJYHyX3KqhEBarsAx94
f56TuZoAqiN91qyFomNFx3InzPRMxnVx0jnvT0Lwdd8KkMaOIG+YD/isI19wKTakyYbnsZogy1Ol
hec9vn2a/iRFM9x2Fe0PonFkTGUugWhFpwIDAQABMA0GCSqGSIb3DQEBAgUAA4GBALtMEivPLCYA
TxQT3ab7/AoRhIzzKBxnki98tsX63/Dolbwdj2wsqFHMc9ikwFPwTtYmwHYBV4GSXiHx0bH/59Ah
WM1pF+NEHJwZRDmJXNycAA9WjQKZ7aKQRUzkuxCkPfAyAw7xzvjoyVGM5mKf5p/AfbdynMk2Omuf
Tqj/ZA1k
-----END CERTIFICATE-----

Verisign Class 3 Public Primary Certification Authority - G2
============================================================
-----BEGIN CERTIFICATE-----
MIIDAjCCAmsCEH3Z/gfPqB63EHln+6eJNMYwDQYJKoZIhvcNAQEFBQAwgcExCzAJBgNVBAYTAlVT
MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE8MDoGA1UECxMzQ2xhc3MgMyBQdWJsaWMgUHJpbWFy
eSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSAtIEcyMTowOAYDVQQLEzEoYykgMTk5OCBWZXJpU2ln
biwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MR8wHQYDVQQLExZWZXJpU2lnbiBUcnVz
dCBOZXR3b3JrMB4XDTk4MDUxODAwMDAwMFoXDTI4MDgwMTIzNTk1OVowgcExCzAJBgNVBAYTAlVT
MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE8MDoGA1UECxMzQ2xhc3MgMyBQdWJsaWMgUHJpbWFy
eSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSAtIEcyMTowOAYDVQQLEzEoYykgMTk5OCBWZXJpU2ln
biwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MR8wHQYDVQQLEx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VmFsaUNlcnQsIEluYy4xNTAzBgNVBAsTLFZhbGlDZXJ0IENs
YXNzIDMgUG9saWN5IFZhbGlkYXRpb24gQXV0aG9yaXR5MSEwHwYDVQQDExhodHRwOi8vd3d3LnZh
bGljZXJ0LmNvbS8xIDAeBgkqhkiG9w0BCQEWEWluZm9AdmFsaWNlcnQuY29tMB4XDTk5MDYyNjAw
MjIzM1oXDTE5MDYyNjAwMjIzM1owgbsxJDAiBgNVBAcTG1ZhbGlDZXJ0IFZhbGlkYXRpb24gTmV0
d29yazEXMBUGA1UEChMOVmFsaUNlcnQsIEluYy4xNTAzBgNVBAsTLFZhbGlDZXJ0IENsYXNzIDMg
UG9saWN5IFZhbGlkYXRpb24gQXV0aG9yaXR5MSEwHwYDVQQDExhodHRwOi8vd3d3LnZhbGljZXJ0
LmNvbS8xIDAeBgkqhkiG9w0BCQEWEWluZm9AdmFsaWNlcnQuY29tMIGfMA0GCSqGSIb3DQEBAQUA
A4GNADCBiQKBgQDjmFGWHOjVsQaBalfDcnWTq8+epvzzFlLWLU2fNUSoLgRNB0mKOCn1dzfnt6td
3zZxFJmP3MKS8edgkpfs2Ejcv8ECIMYkpChMMFp2bbFc893enhBxoYjHW5tBbcqwuI4V7q0zK89H
BFx1cQqYJJgpp0lZpd34t0NiYfPT4tBVPwIDAQABMA0GCSqGSIb3DQEBBQUAA4GBAFa7AliEZwgs
3x/be0kz9dNnnfS0ChCzycUs4pJqcXgn8nCDQtM+z6lU9PHYkhaM0QTLS6vJn0WuPIqpsHEzXcjF
V9+vqDWzf4mH6eglkrh/hXqu1rweN1gqZ8mRzyqBPu3GOd/APhmcGcwTTYJBtYze4D1gCCAPRX5r
on+jjBXu
-----END CERTIFICATE-----

Verisign Class 3 Public Primary Certification Authority - G3
============================================================
-----BEGIN CERTIFICATE-----
MIIEGjCCAwICEQCbfgZJoz5iudXukEhxKe9XMA0GCSqGSIb3DQEBBQUAMIHKMQswCQYDVQQGEwJV
UzEXMBUGA1UEChMOVmVya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BvtcC1IyIuBwvLqXTLR7sdwdela8wv0kL9Sd2nic9TutoAWii/gt/4uhMdUIaC
/Y4wjylGsB49Ndo4YhYYSq3mtlFs3q9i6wHQHiT+eo8SGhJouPtmmRQURVyu565pF4ErWjfJXir0
xuKhXFSbplQAz/DxwceYMBo7Nhbbo27q/a2ywtrvAkcTisDxszGtTxzhT5yvDwyd93gN2PQ1VoDa
t20Xj50egWTh/sVFuq1ruQp6Tk9LhO5L8X3dEQ==
-----END CERTIFICATE-----

Verisign Class 4 Public Primary Certification Authority - G3
============================================================
-----BEGIN CERTIFICATE-----
MIIEGjCCAwICEQDsoKeLbnVqAc/EfMwvlF7XMA0GCSqGSIb3DQEBBQUAMIHKMQswCQYDVQQGEwJV
UzEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xHzAdBgNVBAsTFlZlcmlTaWduIFRydXN0IE5ldHdv
cmsxOjA4BgNVBAsTMShjKSAxOTk5IFZlcmlTaWduLCBJbmMuIC0gRm9yIGF1dGhvcml6ZWQgdXNl
IG9ubHkxRTBDBgNVBAMTPFZlcmlTaWduIENsYXNzIDQgUHVibGljIFByaW1hcnkgQ2VydGlmaWNh
dGlvbiBBdXRob3JpdHkgLSBHMzAeFw05OTEwMDEwMDAwMDBaFw0zNjA3MTYyMzU5NTlaMIHKMQsw
CQYDVQQGEwJVUzEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xHzAdBgNVBAsTFlZlcmlTaWduIFRy
dXN0IE5ldHdvcmsxOjA4BgNVBAsTMShjKSAxOTk5IFZlcmlTaWduLCBJbmMuIC0gRm9yIGF1dGhv
cml6ZWQgdXNlIG9ubHkxRTBDBgNVBAMTPFZlcmlTaWduIENsYXNzIDQgUHVibGljIFByaW1hcnkg
Q2VydGlmaWNhdGlvbiBBdXRob3JpdHkgLSBHMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
ggEBAK3LpRFpxlmr8Y+1GQ9Wzsy1HyDkniYlS+BzZYlZ3tCD5PUPtbut8XzoIfzk6AzufEUiGXaS
tBO3IFsJ+mGuqPKljYXCKtbeZjbSmwL0qJJgfJxptI8kHtCGUvYynEFYHiK9zUVilQhu0GbdU6LM
8BDcVHOLBKFGMzNcF0C5nk3T875Vg+ixiY5afJqWIpA7iCXy0lOIAgwLePLmNxdLMEYH5IBtptiW
Lugs+BGzOA1mppvqySNb247i8xOOGlktqgLw7KSHZtzBP/XYufTsgsbSPZUd5cBPhMnZo0QoBmrX
Razwa2rvTl/4EYIeOGM0ZlDUPpNz+jDDZq3/ky2X7wMCAwEAATANBgkqhkiG9w0BAQUFAAOCAQEA
j/ola09b5KROJ1WrIhVZPMq1CtRK26vdoV9TxaBXOcLORyu+OshWv8LZJxA6sQU8wHcxuzrTBXtt
mhwwjIDLk5Mqg6sFUYICABFna/OIYUdfA5PVWw3g8dShMjWFsjrbsIKr0csKvE+MW8VLADsfKoKm
fjaF3H48ZwC15DtS4KjrXRX5xm3wrR0OhbepmnMUWluPQSjA1egtTaRezarZ7c7c2NU8Qh0XwRJd
RTjDOPP8hS6DRkiy1yBfkjaP53kPmF6Z6PDQpLv1U70qzlmwr25/bLvSHgCwIe34QWKCudiyxLtG
UPMxxY8BqHTr9Xgn2uf3ZkPznoM+IKrDNWCRzg==
-----END CERTIFICATE-----

Entrust.net Secure Server CA
============================
-----BEGIN CERTIFICATE-----
MIIE2DCCBEGgAwIBAgIEN0rSQzANBgkqhkiG9w0BAQUFADCBwzELMAkGA1UEBhMCVVMxFDASBgNV
BAoTC0VudHJ1c3QubmV0MTswOQYDVQQLEzJ3d3cuZW50cnVzdC5uZXQvQ1BTIGluY29ycC4gYnkg
cmVmLiAobGltaXRzIGxpYWIuKTElMCMGA1UECxMcKGMpIDE5OTkgRW50cnVzdC5uZXQgTGltaXRl
ZDE6MDgGA1UEAxMxRW50cnVzdC5uZXQgU2VjdXJlIFNlcnZlciBDZXJ0aWZpY2F0aW9uIEF1dGhv
cml0eTAeFw05OTA1MjUxNjA5NDBaFw0xOTA1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VPbP/CgBr+1CEl/PtYtAaMAwGA1UdEwQFMAMBAf8wGQYJKoZIhvZ9B0EA
BAwwChsEVjQuMAMCBJAwDQYJKoZIhvcNAQEFBQADgYEAkNwwAvpkdMKnCqV8IY00F6j7Rw7/JXyN
Ewr75Ji174z4xRAN95K+8cPV1ZVqBLssziY2ZcgxxufuP+NXdYR6Ee9GTxj005i7qIcyunL2POI9
n9cd2cNgQ4xYDiKWL2KjLB+6rQXvqzJ4h6BUcxm1XAX5Uj5tLUUL9wqT6u0G+bI=
-----END CERTIFICATE-----

Entrust.net Premium 2048 Secure Server CA
=========================================
-----BEGIN CERTIFICATE-----
MIIEKjCCAxKgAwIBAgIEOGPe+DANBgkqhkiG9w0BAQUFADCBtDEUMBIGA1UEChMLRW50cnVzdC5u
ZXQxQDA+BgNVBAsUN3d3dy5lbnRydXN0Lm5ldC9DUFNfMjA0OCBpbmNvcnAuIGJ5IHJlZi4gKGxp
bWl0cyBsaWFiLikxJTAjBgNVBAsTHChjKSAxOTk5IEVudHJ1c3QubmV0IExpbWl0ZWQxMzAxBgNV
BAMTKkVudHJ1c3QubmV0IENlcnRpZmljYXRpb24gQXV0aG9yaXR5ICgyMDQ4KTAeFw05OTEyMjQx
NzUwNTFaFw0yOTA3MjQxNDE1MTJaMIG0MRQwEgYDVQQKEwtFbnRydXN0Lm5ldDFAMD4GA1UECxQ3
d3d3LmVudHJ1c3QubmV0L0NQU18yMDQ4IGluY29ycC4gYnkgcmVmLiAobGltaXRzIGxpYWIuKTEl
MCMGA1UECxMcKGMpIDE5OTkgRW50cnVzdC5uZXQgTGltaXRlZDEzMDEGA1UEAxMqRW50cnVzdC5u
ZXQgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkgKDIwNDgpMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A
MIIBCgKCAQEArU1LqRKGsuqjIAcVFmQqK0vRvwtKTY7tgHalZ7d4QMBzQshowNtTK91euHaYNZOL
Gp18EzoOH1u3Hs/lJBQesYGpjX24zGtLA/ECDNyrpUAkAH90lKGdCCmziAv1h3edVc3kw37XamSr
hRSGlVuXMlBvPci6Zgzj/L24ScF2iUkZ/cCovYmjZy/Gn7xxGWC4LeksyZB2ZnuU4q941mVTXTzW
nLLPKQP5L6RQstRIzgUyVYr9smRMDuSYB3Xbf9+5CFVghTAp+XtIpGmG4zU/HoZdenoVve8AjhUi
VBcAkCaTvA5JaJG/+EfTnZVCwQ5N328mz8MYIWJmQ3DW1cAH4QIDAQABo0IwQDAOBgNVHQ8BAf8E
BAMCAQYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUVeSB0RGAvtiJuQijMfmhJAkWuXAwDQYJ
KoZIhvcNAQEFBQADggEBADubj1abMOdTmXx6eadNl9cZlZD7Bh/KM3xGY4+WZiT6QBshJ8rmcnPy
T/4xmf3IDExoU8aAghOY+rat2l098c5u9hURlIIM7j+VrxGrD9cv3h8Dj1csHsm7mhpElesYT6Yf
zX1XEC+bBAlahLVu2B064dae0Wx5XnkcFMXj0EyTO2U87d89vqbllRrDtRnDvV5bu/8j72gZyxKT
J1wDLW8w0B62GqzeWvfRqqgnpv55gcR5mTNXuhKwqeBCbJPKVt7+bYQLCIt+jerXmCHG8+c8eS9e
nNFMFY3h7CI3zJpDC5fcgJCNs2ebb0gIFVbPv/ErfF6adulZkMV8gzURZVE=
-----END CERTIFICATE-----

Baltimore CyberTrust Root
=========================
-----BEGIN CERTIFICATE-----
MIIDdzCCAl+gAwIBAgIEAgAAuTANBgkqhkiG9w0BAQUFADBaMQswCQYDVQQGEwJJRTESMBAGA1UE
ChMJQmFsdGltb3JlMRMwEQYDVQQLEwpDeWJlclRydXN0MSIwIAYDVQQDExlCYWx0aW1vcmUgQ3li
ZXJUcnVzdCBSb290MB4XDTAwMDUxMjE4NDYwMFoXDTI1MDUxMjIzNTkwMFowWjELMAkGA1UEBhMC
SUUxEjAQBgNVBAoTCUJhbHRpbW9yZTETMBEGA1UECxMKQ3liZXJUcnVzdDEiMCAGA1UEAxMZQmFs
dGltb3JlIEN5YmVyVHJ1c3QgUm9vdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKME
uyKrmD1X6CZymrV51Cni4eiVgLGw41uOKymaZN+hXe2wCQVt2yguzmKiYv60iNoS6zjrIZ3AQSsB
UnuId9Mcj8e6uYi1agnnc+gRQKfRzMpijS3ljwumUNKoUMMo6vWrJYeKmpYcqWe4PwzV9/lSEy/C
G9VwcPCPwBLKBsua4dnKM3p31vjsufFoREJIE9LAwqSuXmD+tqYF/LTdB1kC1FkYmGP1pWPgkAx9
XbIGevOF6uvUA65ehD5f/xXtabz5OTZydc93Uk3zyZAsuT3lySNTPx8kmCFcB5kpvcY67Oduhjpr
l3RjM71oGDHweI12v/yejl0qhqdNkNwnGjkCAwEAAaNFMEMwHQYDVR0OBBYEFOWdWTCCR1jMrPoI
VDaGezq1BE3wMBIGA1UdEwEB/wQIMAYBAf8CAQMwDgYDVR0PAQH/BAQDAgEGMA0GCSqGSIb3DQEB
BQUAA4IBAQCFDF2O5G9RaEIFoN27TyclhAO992T9Ldcw46QQF+vaKSm2eT929hkTI7gQCvlYpNRh
cL0EYWoSihfVCr3FvDB81ukMJY2GQE/szKN+OMY3EU/t3WgxjkzSswF07r51XgdIGn9w/xZchMB5
hbgF/X++ZRGjD8ACtPhSNzkE1akxehi/oCr0Epn3o0WC4zxe9Z2etciefC7IpJ5OCBRLbf1wbWsa
Y71k5h+3zvDyny67G7fyUIhzksLi4xaNmjICq44Y3ekQEe5+NauQrz4wlHrQMz2nZQ/1/I6eYs9H
RCwBXbsdtTLSR9I4LtD+gdwyah617jzV/OeBHRnDJELqYzmp
-----END CERTIFICATE-----

Equifax Secure Global eBusiness CA
==================================
-----BEGIN CERTIFICATE-----
MIICkDCCAfmgAwIBAgIBATANBgkqhkiG9w0BAQQFADBaMQswCQYDVQQGEwJVUzEcMBoGA1UEChMT
RXF1aWZheCBTZWN1cmUgSW5jLjEtMCsGA1UEAxMkRXF1aWZheCBTZWN1cmUgR2xvYmFsIGVCdXNp
bmVzcyBDQS0xMB4XDTk5MDYyMTA0MDAwMFoXDTIwMDYyMTA0MDAwMFowWjELMAkGA1UEBhMCVVMx
HDAaBgNVBAoTE0VxdWlmYXggU2VjdXJlIEluYy4xLTArBgNVBAMTJEVxdWlmYXggU2VjdXJlIEds
b2JhbCBlQnVzaW5lc3MgQ0EtMTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAuucXkAJlsTRV
PEnCUdXfp9E3j9HngXNBUmCbnaEXJnitx7HoJpQytd4zjTov2/KaelpzmKNc6fuKcxtc58O/gGzN
qfTWK8D3+ZmqY6KxRwIP1ORROhI8bIpaVIRw28HFkM9yRcuoWcDNM50/o5brhTMhHD4ePmBudpxn
hcXIw2ECAwEAAaNmMGQwEQYJYIZIAYb4QgEBBAQDAgAHMA8GA1UdEwEB/wQFMAMBAf8wHwYDVR0j
BBgwFoAUvqigdHJQa0S3ySPY+6j/s1draGwwHQYDVR0OBBYEFL6ooHRyUGtEt8kj2Puo/7NXa2hs
MA0GCSqGSIb3DQEBBAUAA4GBADDiAVGqx+pf2rnQZQ8w1j7aDRRJbpGTJxQx78T3LUX47Me/okEN
I7SS+RkAZ70Br83gcfxaz2TE4JaY0KNA4gGK7ycH8WUBikQtBmV1UsCGECAhX2xrD2yuCRyv8qIY
NMR1pHMc8Y3c7635s3a0kr/clRAevsvIO1qEYBlWlKlV
-----END CERTIFICATE-----

Equifax Secure eBusiness CA 1
=============================
-----BEGIN CERTIFICATE-----
MIICgjCCAeugAwIBAgIBBDANBgkqhkiG9w0BAQQFADBTMQswCQYDVQQGEwJVUzEcMBoGA1UEChMT
RXF1aWZheCBTZWN1cmUgSW5jLjEmMCQGA1UEAxMdRXF1aWZheCBTZWN1cmUgZUJ1c2luZXNzIENB
LTEwHhcNOTkwNjIxMDQwMDAwWhcNMjAwNjIxMDQwMDAwWjBTMQswCQYDVQQGEwJVUzEcMBoGA1UE
ChMTRXF1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QIE5ldHdvcmsxIjAgBgNVBAMTGUFkZFRydXN0IEV4dGVybmFsIENB
IFJvb3SCAQEwDQYJKoZIhvcNAQEFBQADggEBALCb4IUlwtYj4g+WBpKdQZic2YR5gdkeWxQHIzZl
j7DYd7usQWxHYINRsPkyPef89iYTx4AWpb9a/IfPeHmJIZriTAcKhjW88t5RxNKWt9x+Tu5w/Rw5
6wwCURQtjr0W4MHfRnXnJK3s9EK0hZNwEGe6nQY1ShjTK3rMUUKhemPR5ruhxSvCNr4TDea9Y355
e6cJDUCrat2PisP29owaQgVR1EX1n6diIWgVIEM8med8vSTYqZEXc4g/VhsxOBi0cQ+azcgOno4u
G+GMmIPLHzHxREzGBHNJdmAPx/i9F4BrLunMTA5amnkPIAou1Z5jJh5VkpTYghdae9C8x49OhgQ=
-----END CERTIFICATE-----

AddTrust Public Services Root
=============================
-----BEGIN CERTIFICATE-----
MIIEFTCCAv2gAwIBAgIBATANBgkqhkiG9w0BAQUFADBkMQswCQYDVQQGEwJTRTEUMBIGA1UEChML
QWRkVHJ1c3QgQUIxHTAbBgNVBAsTFEFkZFRydXN0IFRUUCBOZXR3b3JrMSAwHgYDVQQDExdBZGRU
cnVzdCBQdWJsaWMgQ0EgUm9vdDAeFw0wMDA1MzAxMDQxNTBaFw0yMDA1MzAxMDQxNTBaMGQxCzAJ
BgNVBAYTAlNFMRQwEgYDVQQKEwtBZGRUcnVzdCBBQjEdMBsGA1UECxMUQWRkVHJ1c3QgVFRQIE5l
dHdvcmsxIDAeBgNVBAMTF0FkZFRydXN0IFB1YmxpYyBDQSBSb290MIIBIjANBgkqhkiG9w0BAQEF
AAOCAQ8AMIIBCgKCAQEA6Rowj4OIFMEg2Dybjxt+A3S72mnTRqX4jsIMEZBRpS9mVEBV6tsfSlbu
nyNu9DnLoblv8n75XYcmYZ4c+OLspoH4IcUkzBEMP9smcnrHAZcHF/nXGCwwfQ56HmIexkvA/X1i
d9NEHif2P0tEs7c42TkfYNVRknMDtABp4/MUTu7R3AnPdzRGULD4EfL+OHn3Bzn+UZKXC1sIXzSG
Aa2Il+tmzV7R/9x98oTaunet3IAIx6eH1lWfl2royBFkuucZKT8Rs3iQhCBSWxHveNCD9tVIkNAw
HM+A+WD+eeSI8t0A65RF62WUaUC6wNW0uLp9BBGo6zEFlpROWCGOn9Bg/QIDAQABo4HRMIHOMB0G
A1UdDgQWBBSBPjfYkrAfd59ctKtzquf2NGAv+jALBgNVHQ8EBAMCAQYwDwYDVR0TAQH/BAUwAwEB
/zCBjgYDVR0jBIGGMIGDgBSBPjfYkrAfd59ctKtzquf2NGAv+qFopGYwZDELMAkGA1UEBhMCU0Ux
FDASBgNVBAoTC0FkZFRydXN0IEFCMR0wGwYDVQQLExRBZGRUcnVzdCBUVFAgTmV0d29yazEgMB4G
A1UEAxMXQWRkVHJ1c3QgUHVibGljIENBIFJvb3SCAQEwDQYJKoZIhvcNAQEFBQADggEBAAP3FUr4
JNojVhaTdt02KLmuG7jD8WS6IBh4lSknVwW8fCr0uVFV2ocC3g8WFzH4qnkuCRO7r7IgGRLlk/lL
+YPoRNWyQSW/iHVv/xD8SlTQX/D67zZzfRs2RcYhbbQVuE7PnFylPVoAjgbjPGsye/Kf8Lb93/Ao
GEjwxrzQvzSAlsJKsW2Ox5BF3i9nrEUEo3rcVZLJR2bYGozH7ZxOmuASu7VqTITh4SINhwBk/ox9
Yjllpu9CtoAlEmEBqCQTcAARJl/6NVDFSMwGR+gn2HCNX2TmoUQmXiLsks3/QppEIW1cxeMiHV9H
EufOX1362KqxMy3ZdvJOOjMMK7MtkAY=
-----END CERTIFICATE-----

AddTrust Qualified Certificates Root
====================================
-----BEGIN CERTIFICATE-----
MIIEHjCCAwagAwIBAgIBATANBgkqhkiG9w0BAQUFADBnMQswCQYDVQQGEwJTRTEUMBIGA1UEChML
QWRkVHJ1c3QgQUIxHTAbBgNVBAsTFEFkZFRydXN0IFRUUCBOZXR3b3JrMSMwIQYDVQQDExpBZGRU
cnVzdCBRdWFsaWZpZWQgQ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n0J6X
dgWTP5XHAeZpVTh/EGGZyeNfpso+gmNIquIISD6q8rKFYqa0p9m9N5xotS1WfbC3P6CxB9bpT9ze
RXEwMn8bLgn5v1Kh7sKAPgZcLlVAwRv1cEWw3F369nJad9Jjzc9YiQBCYz95OdBEsIJuQRno3eDB
iFrRHnGTHyQwdOUeqN48Jzd/g66ed8/wMLH/S5noxqE=
-----END CERTIFICATE-----

Entrust Root Certification Authority
====================================
-----BEGIN CERTIFICATE-----
MIIEkTCCA3mgAwIBAgIERWtQVDANBgkqhkiG9w0BAQUFADCBsDELMAkGA1UEBhMCVVMxFjAUBgNV
BAoTDUVudHJ1c3QsIEluYy4xOTA3BgNVBAsTMHd3dy5lbnRydXN0Lm5ldC9DUFMgaXMgaW5jb3Jw
b3JhdGVkIGJ5IHJlZmVyZW5jZTEfMB0GA1UECxMWKGMpIDIwMDYgRW50cnVzdCwgSW5jLjEtMCsG
A1UEAxMkRW50cnVzdCBSb290IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTA2MTEyNzIwMjM0
MloXDTI2MTEyNzIwNTM0MlowgbAxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1FbnRydXN0LCBJbmMu
MTkwNwYDVQQLEzB3d3cuZW50cnVzdC5uZXQvQ1BTIGlzIGluY29ycG9yYXRlZCBieSByZWZlcmVu
Y2UxHzAdBgNVBAsTFihjKSAyMDA2IEVudHJ1c3QsIEluYy4xLTArBgNVBAMTJEVudHJ1c3QgUm9v
dCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
ALaVtkNC+sZtKm9I35RMOVcF7sN5EUFoNu3s/poBj6E4KPz3EEZmLk0eGrEaTsbRwJWIsMn/MYsz
A9u3g3s+IIRe7bJWKKf44LlAcTfFy0cOlypowCKVYhXbR9n10Cv/gkvJrT7eTNuQgFA/CYqEAOww
Cj0Yzfv9KlmaI5UXLEWeH25DeW0MXJj+SKfFI0d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wYTAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBR281Xh+qQ2
+/CfXGJx7Tz0RzgQKzAfBgNVHSMEGDAWgBR281Xh+qQ2+/CfXGJx7Tz0RzgQKzAOBgNVHQ8BAf8E
BAMCAYYwDQYJKoZIhvcNAQEFBQADggIBAGbBxiPz2eAubl/oz66wsCVNK/g7WJtAJDday6sWSf+z
dXkzoS9tcBc0kf5nfo/sm+VegqlVHy/c1FEHEv6sFj4sNcZj/NwQ6w2jqtB8zNHQL1EuxBRa3ugZ
4T7GzKQp5y6EqgYweHZUcyiYWTjgAA1i00J9IZ+uPTqM1fp3DRgrFg5fNuH8KrUwJM/gYwx7WBr+
mbpCErGR9Hxo4sjoryzqyX6uuyo9DRXcNJW2GHSoag/HtPQTxORb7QrSpJdMKu0vbBKJPfEncKpq
A1Ihn0CoZ1Dy81of398j9tx4TuaYT1U6U+Pv8vSfx3zYWK8pIpe44L2RLrB27FcRz+8pRPPphXpg
Y+RdM4kX2TGq2tbzGDVyz4crL2MjhF2EjD9XoIj8mZEoJmmZ1I+XRL6O1UixpCgp8RW04eWe3fiP
pm8m1wk8OhwRDqZsN/etRIcsKMfYdIKz0G9KV7s1KSegi+ghp4dkNl3M2Basx7InQJJVOCiNUW7d
FGdTbHFcJoRNdVq2fmBWqU2t+5sel/MN2dKXVHfaPRK34B7vCAas+YWH6aLcr34YEoP9VhdBLtUp
gn2Z9DH2canPLAEnpQW5qrJITirvn5NSUZU8UnOOVkwXQMAJKOSLakhT2+zNVVXxxvjpoixMptEm
X36vWkzaH6byHCx+rgIW0lbQL1dTR+iS
-----END CERTIFICATE-----

America Online Root Certification Authority 1
=============================================
-----BEGIN CERTIFICATE-----
MIIDpDCCAoygAwIBAgIBATANBgkqhkiG9w0BAQUFADBjMQswCQYDVQQGEwJVUzEcMBoGA1UEChMT
QW1lcmljYSBPbmxpbmUgSW5jLjE2MDQGA1UEAxMtQW1lcmljYSBPbmxpbmUgUm9vdCBDZXJ0aWZp
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6ds
sPmuujz9dLQR6FgNgLzTqIA6me11zEZ7
-----END CERTIFICATE-----

America Online Root Certification Authority 2
=============================================
-----BEGIN CERTIFICATE-----
MIIFpDCCA4ygAwIBAgIBATANBgkqhkiG9w0BAQUFADBjMQswCQYDVQQGEwJVUzEcMBoGA1UEChMT
QW1lcmljYSBPbmxpbmUgSW5jLjE2MDQGA1UEAxMtQW1lcmljYSBPbmxpbmUgUm9vdCBDZXJ0aWZp
Y2F0aW9uIEF1dGhvcml0eSAyMB4XDTAyMDUyODA2MDAwMFoXDTM3MDkyOTE0MDgwMFowYzELMAkG
A1UEBhMCVVMxHDAaBgNVBAoTE0FtZXJpY2EgT25saW5lIEluYy4xNjA0BgNVBAMTLUFtZXJpY2Eg
T25saW5lIFJvb3QgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkgMjCCAiIwDQYJKoZIhvcNAQEBBQAD
ggIPADCCAgoCggIBAMxBRR3pPU0Q9oyxQcngXssNt79Hc9PwVU3dxgz6sWYFas14tNwC206B89en
fHG8dWOgXeMHDEjsJcQDIPT/DjsS/5uN4cbVG7RtIuOx238hZK+GvFciKtZHgVdEglZTvYYUAQv8
f3SkWq7xuhG1m1hagLQ3eAkzfDJHA1zEpYNI9FdWboE2JxhP7JsowtS013wMPgwr38oE18aO6lhO
qKSlGBxsRZijQdEt0sdtjRnxrXm3gT+9BoInLRBYBbV4Bbkv2wxrkJB+FFk4u5QkE+XRnRTf04JN
RvCAOVIyD+OEsnpD8l7eXz8d3eOyG6ChKiMDbi4BFYdcpnV1x5dhvt6G3NRI270qv0pV2uh9UPu0
gBe4lL8BPeraunzgWGcXuVjgiIZGZ2ydEEdYMtA1fHkqkKJaEBEjNa0vzORKW6fIJ/KD3l67Xnfn
6KVuY8INXWHQjNJsWiEOyiijzirplcdIz5ZvHZIlyMbGwcEMBawmxNJ10uEqZ8A9W6Wa6897Gqid
FEXlD6CaZd4vKL3Ob5Rmg0gp2OpljK+T2WSfVVcmv2/LNzGZo2C7HK2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eauan5Hb/qmZJhlv8BzaFfDbxxvA6sCx1H
RR3B7Hzs/Sk=
-----END CERTIFICATE-----

Comodo Trusted Services root
============================
-----BEGIN CERTIFICATE-----
MIIEQzCCAyugAwIBAgIBATANBgkqhkiG9w0BAQUFADB/MQswCQYDVQQGEwJHQjEbMBkGA1UECAwS
R3JlYXRlciBNYW5jaGVzdGVyMRAwDgYDVQQHDAdTYWxmb3JkMRowGAYDVQQKDBFDb21vZG8gQ0Eg
TGltaXRlZDElMCMGA1UEAwwcVHJ1c3RlZCBDZXJ0aWZpY2F0ZSBTZXJ2aWNlczAeFw0wNDAxMDEw
MDAwMDBaFw0yODEyMzEyMzU5NTlaMH8xCzAJBgNVBAYTAkdCMRswGQYDVQQIDBJHcmVhdGVyIE1h
bmNoZXN0ZXIxEDAOBgNVBAcMB1NhbGZvcmQxGjAYBgNVBAoMEUNvbW9kbyBDQSBMaW1pdGVkMSUw
IwYDVQQDDBxUcnVzdGVkIENlcnRpZmljYXRlIFNlcnZpY2VzMIIBIjANBgkqhkiG9w0BAQEFAAOC
AQ8AMIIBCgKCAQEA33FvNlhTWvI2VFeAxHQIIO0Yfyod5jWaHiWsnOWWfnJSoBVC21ndZHoa0Lh7
3TkVvFVIxO06AOoxEbrycXQaZ7jPM8yoMa+j49d/vzMtTGo87IvDktJTdyR0nAducPy9C1t2ul/y
/9c3S0pgePfw+spwtOpZqqPOSC+pw7ILfhdyFgymBwwbOM/JYrc/oJOlh0Hyt3BAd9i+FHzjqMB6
juljatEPmsbS9Is6FARW1O24zG71++IsWL1/T2sr92AkWCTOJu80kTrV44HQsvAEAtdbtz6SrGsS
ivnkBbA7kUlcsutT6vifR4buv5XAwAaf0lteERv0xwQ1KdJVXOTt6wIDAQABo4HJMIHGMB0GA1Ud
DgQWBBTFe1i97doladL3WRaoszLAeydb9DAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/BAUwAwEB
/zCBgwYDVR0fBHwwejA8oDqgOIY2aHR0cDovL2NybC5j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n1pVWQvVDVJIxa6f8i+AxeoyUDUSly7B4f/xI4hROJ/yZlZ25w9Rl6VSDE1JUZU2
Pb+iSwwQHYaZTKrzchGT5Or2m9qoXadNt54CrnMAyNojA+j56hl0YgCUyyIgvpSnWbWCar6ZeXqp
8kokUvd0/bpO5qgdAm6xDYBEwa7TIzdfu4V8K5Iu6H6li92Z4b8nby1dqnuH/grdS/yO9SbkbnBC
bjPsMZ57k8HkyWkaPcBrTiJt7qtYTcbQQcEr6k8Sh17rRdhs9ZgC06DYVYoGmRmioHfRMJ6szHXu
g/WwYjnPbFfiTNKRCw51KBuav/0aQ/HKd/s7j2G4aSgWQgRecCocIdiP4b0jWy10QJLZYxkNc91p
vGJHvOB0K7Lrfb5BG7XARsWhIstfTsEokt4YutUqKLsRixeTmJlglFwjz1onl14LBQaTNx47aTbr
qZ5hHY8y2o4M1nQ+ewkk2gF3R8Q7zTSMmfXK4SVhM7JZG+Ju1zdXtg2pEto=
-----END CERTIFICATE-----

Security Communication Root CA
==============================
-----BEGIN CERTIFICATE-----
MIIDWjCCAkKgAwIBAgIBADANBgkqhkiG9w0BAQUFADBQMQswCQYDVQQGEwJKUDEYMBYGA1UEChMP
U0VDT00gVHJ1c3QubmV0MScwJQYDVQQLEx5TZWN1cml0eSBDb21tdW5pY2F0aW9uIFJvb3RDQTEw
HhcNMDMwOTMwMDQyMDQ5WhcNMjMwOTMwMDQyMDQ5WjBQMQswCQYDVQQGEwJKUDEYMBYGA1UEChMP
U0VDT00gVHJ1c3QubmV0MScwJQYDVQQLEx5TZWN1cml0eSBDb21tdW5pY2F0aW9uIFJvb3RDQTEw
ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCzs/5/022x7xZ8V6UMbXaKL0u/ZPtM7orw
8yl89f/uKuDp6bpbZCKamm8sOiZpUQWZJtzVHGpxxpp9Hp3dfGzGjGdnSj74cbAZJ6kJDKaVv0uM
DPpVmDvY6CKhS3E4eayXkmmziX7qIWgGmBSWh9JhN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Js+gXGM2RX/uJ4+q/Tl18GybT
dXnt5oTjV+WtKcT0OijnpXuENmmz/V52vaMtmdOQTiMofRhj8VQ7Jp12W5dCsv+u8E7s3TmVToMG
f+dJQMjFAbJUWmYdPfz56TwKnoG4cPABi+QjVHzIrviQHgCWctRUz2EjvOr7nQKV0ba5cTppCD8P
tOFCx4j1P5iop7oc4HFx71hXgVB6XGt0Rg6DA5jDjqhu8nYybieDwnPz3BjotJPqdURrBGAgcVeH
nfO+oJAjPYok4doh28MCAwEAAaMzMDEwDwYDVR0TAQH/BAUwAwEB/zARBgNVHQ4ECgQISqCqWITT
XjwwCwYDVR0PBAQDAgEGMA0GCSqGSIb3DQEBBQUAA4IBAQBazof5FnIVV0sd2ZvnoiYw7JNn39Yt
0jSv9zilzqsWuasvfDXLrNAPtEwr/IDva4yRXzZ299uzGxnq9LIR/WFxRL8oszodv7ND6J+/3DEI
cbCdjdY0RzKQxmUk96BKfARzjzlvF4xytb1LyHr4e4PDKE6cCepnP7JnBBvDFNr450kkkdAdavph
Oe9r5yF1BgfYErQhIHBCcYHaPJo2vqZbDWpsmh+Re/n570K6Tk6ezAyNlNzZRZxe7EJQY670XcSx
EtzKO6gunRRaBXW37Ndj4ro1tgQIkejanZz2ZrUYrAqmVCY0M9IbwdR/GjqOC6oybtv8TyWf2TLH
llpwrN9M
-----END CERTIFICATE-----

Staat der Nederlanden Root CA
=============================
-----BEGIN CERTIFICATE-----
MIIDujCCAqKgAwIBAgIEAJiWijANBgkqhkiG9w0BAQUFADBVMQswCQYDVQQGEwJOTDEeMBwGA1UE
ChMVU3RhYXQgZGVyIE5lZGVybGFuZGVuMSYwJAYDVQQDEx1TdGFhdCBkZXIgTmVkZXJsYW5kZW4g
Um9vdCBDQTAeFw0wMjEyMTcwOTIzNDlaFw0xNTEyMTYwOTE1MzhaMFUxCzAJBgNVBAYTAk5MMR4w
HAYDVQQKExVTdGFhdCBkZXIgTmVkZXJsYW5kZW4xJjAkBgNVBAMTHVN0YWF0IG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0/Ww5y0vpQZY/KmEQrrU0icvvIpOxboGqBMpsn0GFlo
wHDyUwDAXlCCpVZvNvlK4ESGoE1O1kduSUrLZ9emxAW5jh70/P/N5zbgnAVssjMiFdC04MwXwLLA
9P4yPykqlXvY8qdOD1R8oQ2AswkDwf9c3V6aPryuvEeKaq5xyh+xKrhfQgUL7EYw0XILyulWbfXv
33i+Ybqypa4ETLyorGkVl73v67SMvzX41MPRKA5cOp9wGDMgd8SirwIDAQABo4GrMIGoMAsGA1Ud
DwQEAwIBxjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBRTMtGzz3/64PGgXYVOktKeRR20TzA9
BgNVHR8ENjA0MDKgMKAuhixodHRwOi8vY3JsLnVzZXJ0cnVzdC5jb20vVVROLURBVEFDb3JwU0dD
LmNybDAqBgNVHSUEIzAhBggrBgEFBQcDAQYKKwYBBAGCNwoDAwYJYIZIAYb4QgQBMA0GCSqGSIb3
DQEBBQUAA4IBAQAnNZcAiosovcYzMB4p/OL31ZjUQLtgyr+rFywJNn9Q+kHcrpY6CiM+iVnJowft
Gzet/Hy+UUla3joKVAgWRcKZsYfNjGjgaQPpxE6YsjuMFrMOoAyYUJuTqXAJyCyjj98C5OBxOvG0
I3KgqgHf35g+FFCgMSa9KOlaMCZ1+XtgHI3zzVAmbQQnmt/VDUVHKWss5nbZqSl9Mt3JNjy9rjXx
EZ4du5A/EkdOjtd+D2JzHVImOBwYSf0wdJrE5SIv2MCN7ZF6TACPcn9d2t0bi0Vr591pl6jFVkwP
DPafepE39peC4N1xaf92P2BNPM/3mfnGV/TJVTl4uix5yaaIK/QI
-----END CERTIFICATE-----

UTN USERFirst Hardware Root CA
==============================
-----BEGIN CERTIFICATE-----
MIIEdDCCA1ygAwIBAgIQRL4Mi1AAJLQR0zYq/mUK/TANBgkqhkiG9w0BAQUFADCBlzELMAkGA1UE
BhMCVVMxCzAJBgNVBAgTAlVUMRcwFQYDVQQHEw5TYWx0IExha2UgQ2l0eTEeMBwGA1UECh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xkP3nTGmZev/K0oXnWO6y1n7k57K9cM
//bey1WiCuFMVGWTYGufEpytXoMs61quwOQt9ABjHbjAbPLPSbtNk28GpgoiskliCE7/yMgUsogW
XecB5BKV5UU0s4tpvc+0hY91UZ59Ojg6FEgSxvunOxqNDYJAB+gECJChicsZUN/KHAG8HQQZexB2
lzvukJDKxA4fFm517zP4029bHpbj4HR3dHuKom4t3XbWOTCC8KucUvIqx69JXn7HaOWCgchqJ/kn
iCrVWFCVH/A7HFe7fRQ5YiuayZSSKqMiDP+JJn1fIytH1xUdqWqeUQ0qUZ6B+dQ7XnASfxAynB67
nfhmqA==
-----END CERTIFICATE-----

Camerfirma Chambers of Commerce Root
====================================
-----BEGIN CERTIFICATE-----
MIIEvTCCA6WgAwIBAgIBADANBgkqhkiG9w0BAQUFADB/MQswCQYDVQQGEwJFVTEnMCUGA1UEChMe
QUMgQ2FtZXJmaXJtYSBTQSBDSUYgQTgyNzQzMjg3MSMwIQYDVQQLExpodHRwOi8vd3d3LmNoYW1i
ZXJzaWduLm9yZzEiMCAGA1UEAxMZQ2hhbWJlcnMgb2YgQ29tbWVyY2UgUm9vdDAeFw0wMzA5MzAx
NjEzNDNaFw0zNzA5MzAxNjEzNDRaMH8xCzAJBgNVBAYTAkVVMScwJQYDVQQKEx5BQyBDYW1lcmZp
cm1hIFNBIENJRiBBODI3NDMyODcxIzAhBgNVBAsTGmh0dHA6Ly93d3cuY2hhbWJlcnNpZ24ub3Jn
MSIwIAYDVQQDExlDaGFtYmVycyBvZiBDb21tZXJjZSBSb290MIIBIDANBgkqhkiG9w0BAQEFAAOC
AQ0AMIIBCAKCAQEAtzZV5aVdGDDg2olUkfzIx1L4L1DZ77F1c2VHfRtbunXF/KGIJPov7coISjlU
xFF6tdpg6jg8gbLL8bvZkSM/SAFwdakFKq0fcfPJVD0dBmpAPrMMhe5cG3nCYsS4No41XQEMIwRH
NaqbYE6gZj3LJgqcQKH0XZi/caulAGgq7YN6D6IUtdQis4CwPAxaUWktWBiP7Zme8a7ileb2R6jW
DA+wWFjbw2Y3npuRVDM30pQcakjJyfKl2qUMI/cjDpwyVV5xnIQFUZot/eZOKjRa3spAN2cMVCFV
d9oKDMyXroDclDZK9D7ONhMeU+SsTjoF7Nuucpw4i9A5O4kKPnf+dQIBA6OCAUQwggFAMBIGA1Ud
EwEB/wQIMAYBAf8CAQwwPAYDVR0fBDUwMzAxoC+gLYYraHR0cDovL2NybC5jaGFtYmVyc2lnbi5v
cmcvY2hhbWJlcnNyb290LmNybDAdBgNVHQ4EFgQU45T1sU3p26EpW1eLTXYGduHRooowDgYDVR0P
AQH/BAQDAgEGMBEGCWCGSAGG+EIBAQQEAwIABzAnBgNVHREEIDAegRxjaGFtYmVyc3Jvb3RAY2hh
bWJlcnNpZ24ub3JnMCcGA1UdEgQgMB6BHGNoYW1iZXJzcm9vdEBjaGFtYmVyc2lnbi5vcmcwWAYD
VR0gBFEwTzBNBgsrBgEEAYGHLgoDATA+MDwGCCsGAQUFBwIBFjBodHRwOi8vY3BzLmNoYW1iZXJz
aWduLm9yZy9jcHMvY2hhbWJlcnNyb290Lmh0bWwwDQYJKoZIhvcNAQEFBQADggEBAAxBl8IahsAi
fJ/7kPMa0QOx7xP5IV8EnNrJpY0nbJaHkb5BkAFyk+cefV/2icZdp0AJPaxJRUXcLo0waLIJuvvD
L8y6C98/d3tGfToSJI6WjzwFCm/SlCgdbQzALogi1djPHRPH8EjX1wWnz8dHnjs8NMiAT9QUu/wN
UPf6s+xCX6ndbcj0dc97wXImsQEcXCz9ek60AcUFV7nnPKoF2YjpB0ZBzu9Bga5Y34OirsrXdx/n
ADydb47kMgkdTXg0eDQ8lJsm7U9xxhl6vSAiSFr+S30Dt+dYvsYyTnQeaN2oaFuzPu5ifdmA6Ap1
erfutGWaIZDgqtCYvDi1czyL+Nw=
-----END CERTIFICATE-----

Camerfirma Global Chambersign Root
==================================
-----BEGIN CERTIFICATE-----
MIIExTCCA62gAwIBAgIBADANBgkqhkiG9w0BAQUFADB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i5vcmcwKgYDVR0SBCMwIYEfY2hhbWJlcnNpZ25yb290QGNoYW1iZXJzaWduLm9y
ZzBbBgNVHSAEVDBSMFAGCysGAQQBgYcuCgEBMEEwPwYIKwYBBQUHAgEWM2h0dHA6Ly9jcHMuY2hh
bWJlcnNpZ24ub3JnL2Nwcy9jaGFtYmVyc2lnbnJvb3QuaHRtbDANBgkqhkiG9w0BAQUFAAOCAQEA
PDtwkfkEVCeR4e3t/mh/YV3lQWVPMvEYBZRqHN4fcNs+ezICNLUMbKGKfKX0j//U2K0X1S0E0T9Y
gOKBWYi+wONGkyT+kL0mojAt6JcmVzWJdJYY9hXiryQZVgICsroPFOrGimbBhkVVi76SvpykBMdJ
PJ7oKXqJ1/6v/2j1pReQvayZzKWGVwlnRtvWFsJG8eSpUPWP0ZIV018+xgBJOm5YstHRJw0lyDL4
IBHNfTIzSJRUTN3cecQwn+uOuFW114hcxWokPbLTBQNRxgfvzBRydD1ucs4YKIxKoHflCStFREes
t2d/AYoFWpO+ocH/+OcOZ6RHSXZddZAa9SaP8A==
-----END CERTIFICATE-----

NetLock Notary (Class A) Root
=============================
-----BEGIN CERTIFICATE-----
MIIGfTCCBWWgAwIBAgICAQMwDQYJKoZIhvcNAQEEBQAwga8xCzAJBgNVBAYTAkhVMRAwDgYDVQQI
EwdIdW5nYXJ5MREwDwYDVQQHEwhCdWRhcGVzdDEnMCUGA1UEChMeTmV0TG9jayBIYWxvemF0Yml6
dG9uc2FnaSBLZnQuMRowGAYDVQQLExFUYW51c2l0dmFueWtpYWRvazE2MDQGA1UEAxMtTmV0TG9j
ayBLb3pqZWd5em9pIChDbGFzcyBBKSBUYW51c2l0dmFueWtpYWRvMB4XDTk5MDIyNDIzMTQ0N1oX
DTE5MDIxOTIzMTQ0N1owga8xCzAJBgNVBAYTAkhVMRAwDgYDVQQIEwdIdW5nYXJ5MREwDwYDVQQH
EwhCdWRhcGVzdDEnMCUGA1UEChMeTmV0TG9jayBIYWxvemF0Yml6dG9uc2Fn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jayBLZnQuIEludGVybmV0IGhvbmxhcGphbiBh
IGh0dHBzOi8vd3d3Lm5ldGxvY2submV0L2RvY3MgY2ltZW4gdmFneSBrZXJoZXRvIGF6IGVsbGVu
b3J6ZXNAbmV0bG9jay5uZXQgZS1tYWlsIGNpbWVuLiBJTVBPUlRBTlQhIFRoZSBpc3N1YW5jZSBh
bmQgdGhlIHVzZSBvZiB0aGlzIGNlcnRpZmljYXRlIGlzIHN1YmplY3QgdG8gdGhlIE5ldExvY2sg
Q1BTIGF2YWlsYWJsZSBhdCBodHRwczovL3d3dy5uZXRsb2NrLm5ldC9kb2NzIG9yIGJ5IGUtbWFp
bCBhdCBjcHNAbmV0bG9jay5uZXQuMA0GCSqGSIb3DQEBBAUAA4IBAQBIJEb3ulZv+sgoA0BO5TE5
ayZrU3/b39/zcT0mwBQOxmd7I6gMc90Bu8bKbjc5VdXHjFYgDigKDtIqpLBJUsY4B/6+CgmM0ZjP
ytoUMaFP0jn8DxEsQ8Pdq5PHVT5HfBgaANzze9jyf1JsIPQLX2lS9O74silg6+NJMSEN1rUQQeJB
CWziGppWS3cC9qCbmieH6FUpccKQn0V4GuEVZD3QDtigdp+uxdAu6tYPVuxkf1qbFFgBJ34TUMdr
KuZoPL9coAob4Q566eKAw+np9v1sEZ7Q5SgnK1QyQhSCdeZK8CtmdWOMovsEPoMOmzbwGOQmIMOM
8CgHrTwXZoi1/baI
-----END CERTIFICATE-----

NetLock Business (Class B) Root
===============================
-----BEGIN CERTIFICATE-----
MIIFSzCCBLSgAwIBAgIBaTANBgkqhkiG9w0BAQQFADCBmTELMAkGA1UEBhMCSFUxETAPBgNVBAcT
CEJ1ZGFwZXN0MScwJQYDVQQKEx5OZXRMb2NrIEhhbG96YXRiaXp0b25zYWdpIEtmdC4xGjAYBgNV
BAsTEVRhbnVzaXR2YW55a2lhZG9rMTIwMAYDVQQDEylOZXRMb2NrIFV6bGV0aSAoQ2xhc3MgQikg
VGFudXNpdHZhbnlraWFkbzAeFw05OTA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ldGxvY2submV0L2RvY3MgY2ltZW4gdmFneSBrZXJoZXRvIGF6IGVsbGVub3J6ZXNA
bmV0bG9jay5uZXQgZS1tYWlsIGNpbWVuLiBJTVBPUlRBTlQhIFRoZSBpc3N1YW5jZSBhbmQgdGhl
IHVzZSBvZiB0aGlzIGNlcnRpZmljYXRlIGlzIHN1YmplY3QgdG8gdGhlIE5ldExvY2sgQ1BTIGF2
YWlsYWJsZSBhdCBodHRwczovL3d3dy5uZXRsb2NrLm5ldC9kb2NzIG9yIGJ5IGUtbWFpbCBhdCBj
cHNAbmV0bG9jay5uZXQuMA0GCSqGSIb3DQEBBAUAA4GBAATbrowXr/gOkDFOzT4JwG06sPgzTEdM
43WIEJessDgVkcYplswhwG08pXTP2IKlOcNl40JwuyKQ433bNXbhoLXan3BukxowOR0w2y7jfLKR
stE3Kfq51hdcR0/jHTjrn9V7lagonhVK0dHQKwCXoOKSNitjrFgBazMpUIaD8QFI
-----END CERTIFICATE-----

NetLock Express (Class C) Root
==============================
-----BEGIN CERTIFICATE-----
MIIFTzCCBLigAwIBAgIBaDANBgkqhkiG9w0BAQQFADCBmzELMAkGA1UEBhMCSFUxETAPBgNVBAcT
CEJ1ZGFwZXN0MScwJQYDVQQKEx5OZXRMb2NrIEhhbG96YXRiaXp0b25zYWdpIEtmdC4xGjAYBgNV
BAsTEVRhbnVzaXR2YW55a2lhZG9rMTQwMgYDVQQDEytOZXRMb2NrIEV4cHJlc3N6IChDbGFzcyBD
KSBUYW51c2l0dmFueWtpYWRvMB4XDTk5MDIyNTE0MDgxMVoXDTE5MDIyMDE0MDgxMVowgZsxCzAJ
BgNVBAYTAkhVMREwDwYDVQQHEwhCdWRhcGVzdDEnMCUGA1UEChMeTmV0TG9jayBIYWxvemF0Yml6
dG9uc2FnaSBLZnQuMRowGAYDVQQLExFUYW51c2l0dmFueWtpYWRvazE0MDIGA1UEAxMrTmV0TG9j
ayBFeHByZXNzeiAoQ2xhc3MgQykgVGFudXNpdHZhbnlraWFk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NnyicsbkqWletNw+vHX/b
vZ8=
-----END CERTIFICATE-----

Starfield Class 2 CA
====================
-----BEGIN CERTIFICATE-----
MIIEDzCCAvegAwIBAgIBADANBgkqhkiG9w0BAQUFADBoMQswCQYDVQQGEwJVUzElMCMGA1UEChMc
U3RhcmZpZWxkIFRlY2hub2xvZ2llcywgSW5jLjEyMDAGA1UECxMpU3RhcmZpZWxkIENsYXNzIDIg
Q2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMDQwNjI5MTczOTE2WhcNMzQwNjI5MTczOTE2WjBo
MQswCQYDVQQGEwJVUzElMCMGA1UEChMcU3RhcmZpZWxkIFRlY2hub2xvZ2llcywgSW5jLjEyMDAG
A1UECxMpU3RhcmZpZWxkIENsYXNzIDIgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwggEgMA0GCSqG
SIb3DQEBAQUAA4IBDQAwggEIAoIBAQC3Msj+6XGmBIWtDBFk385N78gDGIc/oav7PKaf8MOh2tTY
bitTkPskpD6E8J7oX+zlJ0T1KKY/e97gKvDIr1MvnsoFAZMej2YcOadN+lq2cwQlZut3f+dZxkqZ
JRRU6ybH838Z1TBwj6+wRir/resp7defqgSHo9T5iaU0X9tDkYI22WY8sbi5gv2cOj4QyDvvBmVm
epsZGD3/cVE8MC5fvj13c7JdBmzDI1aaK4UmkhynArPkPw2vCHmCuDY96pzTNbO8acr1zJ3o/WSN
F4Azbl5KXZnJHoe0nRrA1W4TNSNe35tfPe/W93bC6j67eA0cQmdrBNj41tpvi/JEoAGrAgEDo4HF
MIHCMB0GA1UdDgQWBBS/X7fRzt0fhvRbVazc1xDCDqmI5zCBkgYDVR0jBIGKMIGHgBS/X7fRzt0f
hvRbVazc1xDCDqmI56FspGowaDELMAkGA1UEBhMCVVMxJTAjBgNVBAoTHFN0YXJmaWVsZCBUZWNo
bm9sb2dpZXMsIEluYy4xMjAwBgNVBAsTKVN0YXJmaWVsZCBDbGFzcyAyIENlcnRpZmljYXRpb24g
QXV0aG9yaXR5ggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAAWdP4id0ckaVaGs
afPzWdqbAYcaT1epoXkJKtv3L7IezMdeatiDh6GX70k1PncGQVhiv45YuApnP+yz3SFmH8lU+nLM
PUxA2IGvd56Deruix/U0F47ZEUD0/CwqTRV/p2JdLiXTAAsgGh1o+Re49L2L7ShZ3U0WixeDyLJl
xy16paq8U4Zt3VekyvggQQto8PT7dL5WXXp59fkdheMtlb71cZBDzI0fmgAKhynpVSJYACPq4xJD
KVtHCN2MQWplBqjlIapBtJUhlbl90TSrE9atvNziPTnNvT51cKEYWQPJIrSPnNVeKtelttQKbfi3
QBFGmh95DmK/D5fs4C8fF5Q=
-----END CERTIFICATE-----

StartCom Certification Authority
================================
-----BEGIN CERTIFICATE-----
MIIHyTCCBbGgAwIBAgIBATANBgkqhkiG9w0BAQUFADB9MQswCQYDVQQGEwJJTDEWMBQGA1UEChMN
U3RhcnRDb20gTHRkLjErMCkGA1UECxMiU2VjdXJlIERpZ2l0YWwgQ2VydGlmaWNhdGUgU2lnbmlu
ZzEpMCcGA1UEAxMgU3RhcnRDb20gQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMDYwOTE3MTk0
NjM2WhcNMzYwOTE3MTk0NjM2WjB9MQswCQYDVQQGEwJJTDEWMBQGA1UEChMNU3RhcnRDb20gTHRk
LjErMCkGA1UECxMiU2VjdXJlIERpZ2l0YWwgQ2VydGlmaWNhdGUgU2lnbmluZzEpMCcGA1UEAxMg
U3RhcnRDb20gQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAw
ggIKAoICAQDBiNsJvGxGfHiflXu1M5DycmLWwTYgIiRezul38kMKogZkpMyONvg45iPwbm2xPN1y
o4UcodM9tDMr0y+v/uqwQVlntsQGfQqedIXWeUyAN3rfOQVSWff0G0ZDpNKFhdLDcfN1YjS6LIp/
Ho/u7TTQEceWzVI9ujPW3U3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BjfIt
tep3Sp+dWOIrWcBAI+0tKIJFPnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886
UAb3LujEV0lsYSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk
CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=
-----END CERTIFICATE-----

DigiCert High Assurance EV Root CA
==================================
-----BEGIN CERTIFICATE-----
MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBsMQswCQYDVQQG
EwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQuY29tMSsw
KQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5jZSBFViBSb290IENBMB4XDTA2MTExMDAwMDAw
MFoXDTMxMTExMDAwMDAwMFowbDELMAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZ
MBcGA1UECxMQd3d3LmRpZ2ljZXJ0LmNvbTErMCkGA1UEAxMiRGlnaUNlcnQgSGlnaCBBc3N1cmFu
Y2UgRVYgUm9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbM5XPm+9S75S0t
Mqbf5YE/yc0lSbZxKsPVlDRnogocsF9ppkCxxLeyj9CYpKlBWTrT3JTWPNt0OKRKzE0lgvdKpVMS
OO7zSW1xkX5jtqumX8OkhPhPYlG++MXs2ziS4wblCJEMxChBVfvLWokVfnHoNb9Ncgk9vjo4UFt3
MRuNs8ckRZqnrG0AFFoEt7oT61EKmEFBIk5lYYeBQVCmeVyJ3hlKV9Uu5l0cUyx+mM0aBhakaHPQ
NAQTXKFx01p8VdteZOE3hzBWBOURtCmAEvF5OYiiAhF8J2a3iLd48soKqDirCmTCv2ZdlYTBoSUe
h10aUAsgEsxBu24LUTi4S8sCAwEAAaNjMGEwD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Zg9p8d2/6eMyi/rgwYZNcjwu2JN4Cir42NInPRmJX1p7ijvMDNpRrscL9yuwNwXs
vFcj4jjSm2jzVhKIT0J8uDHEtdvkyCE06UgRNe76x5JXxZ805Mf29w4LTJxoeHtxMcfrHuBnQfO3
oKfN5XozNmr6mis=
-----END CERTIFICATE-----

TURKTRUST Certificate Services Provider Root 1
==============================================
-----BEGIN CERTIFICATE-----
MIID+zCCAuOgAwIBAgIBATANBgkqhkiG9w0BAQUFADCBtzE/MD0GA1UEAww2VMOcUktUUlVTVCBF
bGVrdHJvbmlrIFNlcnRpZmlrYSBIaXptZXQgU2HEn2xhecSxY8Sxc8SxMQswCQYDVQQGDAJUUjEP
MA0GA1UEBwwGQU5LQVJBMVYwVAYDVQQKDE0oYykgMjAwNSBUw5xSS1RSVVNUIEJpbGdpIMSwbGV0
acWfaW0gdmUgQmlsacWfaW0gR8O8dmVubGnEn2kgSGl6bWV0bGVyaSBBLsWeLjAeFw0wNTA1MTMx
MDI3MTdaFw0xNTAzMjIxMDI3MTdaMIG3MT8wPQYDVQQDDDZUw5xSS1RSVVNUIEVsZWt0cm9uaWsg
U2VydGlmaWthIEhpem1ldCBTYcSfbGF5xLFjxLFzxLExCzAJBgNVBAYMAlRSMQ8wDQYDVQQHDAZB
TktBUkExVjBUBgNVBAoMTShjKSAyMDA1IFTDnFJLVFJVU1QgQmlsZ2kgxLBsZXRpxZ9pbSB2ZSBC
aWxpxZ9pbSBHw7x2ZW5sacSfaSBIaXptZXRsZXJpIEEuxZ4uMIIBIjANBgkqhkiG9w0BAQEFAAOC
AQ8AMIIBCgKCAQEAylIF1mMD2Bxf3dJ7XfIMYGFbazt0K3gNfUW9InTojAPBxhEqPZW8qZSwu5GX
yGl8hMW0kWxsE2qkVa2kheiVfrMArwDCBRj1cJ02i67L5BuBf5OI+2pVu32Fks66WJ/bMsW9Xe8i
Si9BB35JYbOG7E6mQW6EvAPs9TscyB/C7qju6hJKjRTP8wrgUDn5CDX4EVmt5yLqS8oUBt5CurKZ
8y1UiBAG6uEaPj1nH/vO+3yC6BFdSsG5FOpU2WabfIl9BJpiyelSPJ6c79L1JuTm5Rh8i27fbMx4
W09ysstcP4wFjdFMjK2Sx+F4f2VsSQZQLJ4ywtdKxnWKWU51b0dewQIDAQABoxAwDjAMBgNVHRME
BTADAQH/MA0GCSqGSIb3DQEBBQUAA4IBAQAV9VX/N5aAWSGk/KEVTCD21F/aAyT8z5Aa9CEKmu46
sWrv7/hg0Uw2ZkUd82YCdAR7kjCo3gp2D++Vbr3JN+YaDayJSFvMgzbC9UZcWYJWtNX+I7TYVBxE
q8Sn5RTOPEFhfEPmzcSBCYsk+1Ql1haolgxnB2+zUEfjHCQo3SqYpGH+2+oSN7wBGjSFvW5P55Fy
B0SFHljKVETd96y5y4khctuPwGkplyqjrhgjlxxBKot8KsF8kOipKMDTkcatKIdAaLX/7KfS0zgY
nNN9aV3wxqUeJBujR/xpB2jn5Jq07Q+hh4cCzofSSE7hvP/L8XKSRGQDJereW26fyfJOrN3H
-----END CERTIFICATE-----

TURKTRUST Certificate Services Provider Root 2
==============================================
-----BEGIN CERTIFICATE-----
MIIEPDCCAySgAwIBAgIBATANBgkqhkiG9w0BAQUFADCBvjE/MD0GA1UEAww2VMOcUktUUlVTVCBF
bGVrdHJvbmlrIFNlcnRpZmlrYSBIaXptZXQgU2HEn2xhecSxY8Sxc8SxMQswCQYDVQQGEwJUUjEP
MA0GA1UEBwwGQW5rYXJhMV0wWwYDVQQKDFRUw5xSS1RSVVNUIEJpbGdpIMSwbGV0acWfaW0gdmUg
QmlsacWfaW0gR8O8dmVubGnEn2kgSGl6bWV0bGVyaSBBLsWeLiAoYykgS2FzxLFtIDIwMDUwHhcN
MDUxMTA3MTAwNzU3WhcNMTUwOTE2MTAwNzU3WjCBvjE/MD0GA1UEAww2VMOcUktUUlVTVCBFbGVr
dHJvbmlrIFNlcnRpZmlrYSBIaXptZXQgU2HEn2xhecSxY8Sxc8SxMQswCQYDVQQGEwJUUjEPM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AQH/BAUw
AwEB/zAdBgNVHQ4EFgQUWyV7lqRlUX64OfPAeGZe6Drn8O4wHwYDVR0jBBgwFoAUWyV7lqRlUX64
OfPAeGZe6Drn8O4wRgYDVR0gBD8wPTA7BglghXQBWQECAQEwLjAsBggrBgEFBQcCARYgaHR0cDov
L3JlcG9zaXRvcnkuc3dpc3NzaWduLmNvbS8wDQYJKoZIhvcNAQEFBQADggIBACe645R88a7A3hfm
5djV9VSwg/S7zV4Fe0+fdWavPOhWfvxyeDgD2StiGwC5+OlgzczOUYrHUDFu4Up+GC9pWbY9ZIEr
44OE5iKHjn3g7gKZYbge9LgriBIWhMIxkziWMaa5O1M/wySTVltpkuzFwbs4AOPsF6m43Md8AYOf
Mke6UiI0HTJ6CVanfCU2qT1L2sCCbwq7EsiHSycR+R4tx5M/nttfJmtS2S6K8RTGRI0Vqbe/vd6m
Gu6uLftIdxf+u+yvGPUqUfA5hJeVbG4bwyvEdGB5JbAKJ9/fXtI5z0V9QkvfsywexcZdylU6oJxp
mo/a77KwPJ+HbBIrZXAVUjEaJM9vMSNQH4xPjyPDdEFjHFWoFN0+4FFQz/EbMFYOkrCChdiDyyJk
vC24JdVUorgG6q2SpCSgwYa1ShNqR88uC1aVVMvOmttqtKay20EIhid392qgQmwLOM7XdVAyksLf
KzAiSNDVQTglXaTpXZ/GlHXQRf0wl0OPkKsKx4ZzYEppLd6leNcG2mqeSz53OiATIgHQv2ieY2Br
NU0LbbqhPcCT4H8js1WtciVORvnSFu+wZMEBnunKoGqYDs/YYPIvSbjkQuE4NRb0yG5P94FW6Lqj
viOvrv1vA+ACOzB2+httQc8Bsem4yWb02ybzOqR08kkkW8mw0FfB+j564ZfJ
-----END CERTIFICATE-----

SwissSign Silver CA - G2
========================
-----BEGIN CERTIFICATE-----
MIIFvTCCA6WgAwIBAgIITxvUL1S7L0swDQYJKoZIhvcNAQEFBQAwRzELMAkGA1UEBhMCQ0gxFTAT
BgNVBAoTDFN3aXNzU2lnbiBBRzEhMB8G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gBD8wPTA7BglghXQBWQEDAQEwLjAsBggrBgEFBQcCARYgaHR0
cDovL3JlcG9zaXRvcnkuc3dpc3NzaWduLmNvbS8wDQYJKoZIhvcNAQEFBQADggIBAHPGgeAn0i0P
4JUw4ppBf1AsX19iYamGamkYDHRJ1l2E6kFSGG9YrVBWIGrGvShpWJHckRE1qTodvBqlYJ7YH39F
kWnZfrt4csEGDyrOj4VwYaygzQu4OSlWhDJOhrs9xCrZ1x9y7v5RoSJBsXECYxqCsGKrXlcSH9/L
3XWgwF15kIwb4FDm3jH+mHtwX6WQ2K34ArZv02DdQEsixT2tOnqfGhpHkXkzuoLcMmkDlm4fS/Bx
/uNncqCxv1yL5PqZIseEuRuNI5c/7SXgz2W79WEE790eslpBIlqhn10s6FvJbakMDHiqYMZWjwFa
DGi8aRl5xB9+lwW/xekkUV7U1UtT7dkjWjYDZaPBA61BMPNGG4WQr2W11bHkFlt4dR2Xem1ZqSqP
e97Dh4kQmUlzeMg9vVE1dCrV8X5pGyq7O70luJpaPXJhkGaH7gzWTdQRdAtq/gsD/KNVV4n+Ssuu
WxcFyPKNIzFTONItaj+CuY0IavdeQXRuwxF+B6wpYJE/OMpXEA29MC/HpeZBoNquBYeaoKRlbEwJ
DIm6uNO5wJOKMPqN5ZprFQFOZ6raYlY+hAhm0sQ2fac+EPyI4NSA5QC9qvNOBqN6avlicuMJT+ub
DgEj8Z+7fNzcbBGXJbLytGMU0gYqZ4yD9c7qB9iaah7s5Aq7KkzrCWA5zspi2C5u
-----END CERTIFICATE-----

GeoTrust Primary Certification Authority
========================================
-----BEGIN CERTIFICATE-----
MIIDfDCCAmSgAwIBAgIQGKy1av1pthU6Y2yv2vrEoTANBgkqhkiG9w0BAQUFADBYMQswCQYDVQQG
EwJVUzEWMBQGA1UEChMNR2VvVHJ1c3QgSW5jLjExMC8GA1UEAxMoR2VvVHJ1c3QgUHJpbWFyeSBD
ZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw0wNjExMjcwMDAw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kiG9w0BAQUF
AAOCAQEAeRHAS7ORtvzw6WfUDW5FvlXok9LOAz/t2iWwHVfLHjp2oEzsUHboZHIMpKnxuIvW1oeE
uzLlQRHAd9mzYJ3rG9XRbkREqaYB7FViHXe4XI5ISXycO1cRrK1zN44veFyQaEfZYGDm/Ac9IiAX
xPcW6cTYcvnIc3zfFi8VqT79aie2oetaupgf1eNNZAqdE8hhuvU5HIe6uL17In/2/qxAeeWsEG89
jxt5dovEN7MhGITlNgDrYyCZuen+MwS7QcjBAvlEYyCegc5C09Y/LHbTY5xZ3Y+m4Q6gLkH3LpVH
z7z9M/P2C2F+fpErgUfCJzDupxBdN49cOSvkBPB7jVaMaA==
-----END CERTIFICATE-----

VeriSign Class 3 Public Primary Certification Authority - G5
============================================================
-----BEGIN CERTIFICATE-----
MIIE0zCCA7ugAwIBAgIQGNrRniZ96LtKIVjNzGs7SjANBgkqhkiG9w0BAQUFADCByjELMAkGA1UE
BhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZWZXJpU2lnbiBUcnVzdCBO
ZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJpU2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVk
IHVzZSBvbmx5MUUwQwYDVQQDEzxWZXJpU2lnbiBDbGFzcyAzIFB1YmxpYyBQcmltYXJ5IENlcnRp
ZmljYXRpb24gQXV0aG9yaXR5IC0gRzUwHhcNMDYxMTA4MDAwMDAwWhcNMzYwNzE2MjM1OTU5WjCB
yjELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZWZXJpU2ln
biBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJpU2lnbiwgSW5jLiAtIEZvciBh
dXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxWZXJpU2lnbiBDbGFzcyAzIFB1YmxpYyBQcmlt
YXJ5IENlcnRpZmljY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0PBAQDAgGGMA8GA1Ud
EwEB/wQFMAMBAf8wHQYDVR0OBBYEFK9EBMJBfkiD2045AuzshHrmzsmkMDQGA1UdHwQtMCswKaAn
oCWGI2h0dHA6Ly9jcmwuc2VjdXJldHJ1c3QuY29tL1NHQ0EuY3JsMBAGCSsGAQQBgjcVAQQDAgEA
MA0GCSqGSIb3DQEBBQUAA4IBAQBjGghAfaReUw132HquHw0LURYD7xh8yOOvaliTFGCRsoTciE6+
OYo68+aCiV0BN7OrJKQVDpI1WkpEXk5X+nXOH0jOZvQ8QCaSmGwb7iRGDBezUqXbpZGRzzfTb+cn
CDpOGR86p1hcF895P4vkp9MmI50mD1hp/Ed+stCNi5O/KU9DaXR2Z0vPB4zmAve14bRDtUstFJ/5
3CYNv6ZHdAbYiNE6KTCEztI5gGIbqMdXSbxqVVFnFUq+NQfk1XWYN3kwFNspnWzFacxHVaIw98xc
f8LDmBxrThaA63p4ZUWiABqvDA1VZDRIuJK58bRQKfJPIx/abKwfROHdI3hRW8cW
-----END CERTIFICATE-----

COMODO Certification Authority
==============================
-----BEGIN CERTIFICATE-----
MIIEHTCCAwWgAwIBAgIQToEtioJl4AsC7j41AkblPTANBgkqhkiG9w0BAQUFADCBgTELMAkGA1UE
BhMCR0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UEBxMHU2FsZm9yZDEaMBgG
A1UEChMRQ09NT0RPIENBIExpbWl0ZWQxJzAlBgNVBAMTHkNPTU9ETyBDZXJ0aWZpY2F0aW9uIEF1
dGhvcml0eTAeFw0wNjEyMDEwMDAwMDBaFw0yOTEyMzEyMzU5NTlaMIGBMQswCQYDVQQGEwJHQjEb
MBkGA1UECBMSR3JlYXRlciBNYW5jaGVzdGVyMRAwDgYDVQQHEwdTYWxmb3JkMRowGAYDVQQKExFD
T01PRE8gQ0EgTGltaXRlZDEnMCUGA1UEAxMeQ09NT0RPIENlcnRpZmljYXRpb24gQXV0aG9yaXR5
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0ECLi3LjkRv3UcEbVASY06m/weaKXTuH
+7uIzg3jLz8GlvCiKVCZrts7oVewdFFxze1CkU1B/qnI2GqGd0S7WWaXUF601CxwRM/aN5VCaTww
xHGzUvAhTaHYujl8HJ6jJJ3ygxaYqhZ8Q5sVW7euNJH+1GImGEaaP+vB+fGQV+useg2L23IwambV
4EajcNxo2f8ESIl33rXp+2dtQem8Ob0y2WIC8bGoPW43nOIv4tOiJovGuFVDiOEjPqXSJDlqR6sA
1KGzqSX+DT+nHbrTUcELpNqsOO9VUCQFZUaTNE8tja3G1CEZ0o7KBWFxB3NH5YoZEr0ETc5OnKVI
rLsm9wIDAQABo4GOMIGLMB0GA1UdDgQWBBQLWOWLxkwVN6RAqTCpIb5HNlpW/zAOBgNVHQ8BAf8E
BAMCAQYwDwYDVR0TAQH/BAUwAwEB/zBJBgNVHR8EQjBAMD6gPKA6hjhodHRwOi8vY3JsLmNvbW9k
b2NhLmNvbS9DT01PRE9DZXJ0aWZpY2F0aW9uQXV0aG9yaXR5LmNybDANBgkqhkiG9w0BAQUFAAOC
AQEAPpiem/Yb6dc5t3iuHXIYSdOH5EOC6z/JqvWote9VfCFSZfnVDeFs9D6Mk3ORLgLETgdxb8CP
OGEIqB6BCsAvIC9Bi5HcSEW88cbeunZrM8gALTFGTO3nnc+IlP8zwFboJIYmuNg4ON8qa90SzMc/
RxdMosIGlgnW2/4/PEZB31jiVg88O8EckzXZOFKs7sjsLjBOlDW0JB9LeGna8gI4zJVSk/BwJVmc
IGfE7vmLV2H0knZ9P4SNVbfo5azV8fUZVqZa+5Acr5Pr5RzUZ5ddBA6+C4OmF4O5MBKgxTMVBbkN
+8cFduPYSo38NBejxiEovjBFMR7HeL5YYTisO+IBZQ==
-----END CERTIFICATE-----

Network Solutions Certificate Authority
=======================================
-----BEGIN CERTIFICATE-----
MIID5jCCAs6gAwIBAgIQV8szb8JcFuZHFhfjkDFo4DANBgkqhkiG9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Lj4DKAv6ALR8jDMe+ZZzKATxcheQxpXN5eNK4CtSbqUN9/
GGUsyfJj4akH/nxxH2szJGoeBfcFaMBqEssuXmHLrijTfsK0ZpEmXzwuJF/LWA/rKOyvEZbz3Htv
wKeI8lN3s2Berq4o2jUsbzRF0ybh3uxbTydrFny9RAQYgrOJeRcQcT16ohZO9QHNpGxlaKFJdlxD
ydi8NmdspZS11My5vWo1ViHe2MPr+8ukYEywVaCge1ey
-----END CERTIFICATE-----

WellsSecure Public Root Certificate Authority
=============================================
-----BEGIN CERTIFICATE-----
MIIEvTCCA6WgAwIBAgIBATANBgkqhkiG9w0BAQUFADCBhTELMAkGA1UEBhMCVVMxIDAeBgNVBAoM
F1dlbGxzIEZhcmdvIFdlbGxzU2VjdXJlMRwwGgYDVQQLDBNXZWxscyBGYXJnbyBCYW5rIE5BMTYw
NAYDVQQDDC1XZWxsc1NlY3VyZSBQdWJsaWMgUm9vdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwHhcN
MDcxMjEzMTcwNzU0WhcNMjIxMjE0MDAwNzU0WjCBhTELMAkGA1UEBhMCVVMxIDAeBgNVBAoMF1dl
bGxzIEZhcmdvIFdlbGxzU2VjdXJlMRwwGgYDVQQLDBNXZWxscyBGYXJnbyBCYW5rIE5BMTYwNAYD
VQQDDC1XZWxsc1NlY3VyZSBQdWJsaWMgUm9vdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkwggEiMA0G
CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDub7S9eeKPCCGeOARBJe+rWxxTkqxtnt3CxC5FlAM1
iGd0V+PfjLindo8796jE2yljDpFoNoqXjopxaAkH5OjUDk/41itMpBb570OYj7OeUt9tkTmPOL13
i0Nj67eT/DBMHAGTthP796EfvyXhdDcsHqRePGj4S78NuR4uNuip5Kf4D8uCdXw1LSLWwr8L87T8
bJVhHlfXBIEyg1J55oNjz7fLY4sR4r1e6/aN7ZVyKLSsEmLpSjPmgzKuBXWVvYSV2ypcm44uDLiB
K0HmOFafSZtsdvqKXfcBeYF8wYNABf5x/Qw/zE5gCQ5lRxAvAcAFP4/4s0HvWkJ+We/SlwxlAgMB
AAGjggE0MIIBMDAPBgNVHRMBAf8EBTADAQH/MDkGA1UdHwQyMDAwLqAsoCqGKGh0dHA6Ly9jcmwu
cGtpLndlbGxzZmFyZ28uY29tL3dzcHJjYS5jcmwwDgYDVR0PAQH/BAQDAgHGMB0GA1UdDgQWBBQm
lRkQ2eihl5H/3BnZtQQ+0nMKajCBsgYDVR0jBIGqMIGngBQmlRkQ2eihl5H/3BnZtQQ+0nMKaqGB
i6SBiDCBhTELMAkGA1UEBhMCVVMxIDAeBgNVBAoMF1dlbGxzIEZhcmdvIFdlbGxzU2VjdXJlMRww
GgYDVQQLDBNXZWxscyBGYXJnbyBCYW5rIE5BMTYwNAYDVQQDDC1XZWxsc1NlY3VyZSBQdWJsaWMg
Um9vdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHmCAQEwDQYJKoZIhvcNAQEFBQADggEBALkVsUSRzCPI
K0134/iaeycNzXK7mQDKfGYZUMbVmO2rvwNa5U3lHshPcZeG1eMd/ZDJPHV3V3p9+N701NX3leZ0
bh08rnyd2wIDBSxxSyU+B+NemvVmFymIGjifz6pBA4SXa5M4esowRBskRDPQ5NHcKDj0E0M1NSlj
qHyita04pO2t/caaH/+Xc/77szWnk4bGdpEA5qxRFsQnMlzbc9qlk1eOPm01JghZ1edE13YgY+es
E2fDbbFwRnzVlhE9iW9dqKHrjQrawx0zbKPqZxmamX9LPYNRKh3KL4YMon4QLSvUFpULB6ouFJJJ
tylv2G0xffX8oRAHh84vWdw+WNs=
-----END CERTIFICATE-----

COMODO ECC Certification Authority
==================================
-----BEGIN CERTIFICATE-----
MIICiTCCAg+gAwIBAgIQH0evqmIAcFBUTAGem2OZKjAKBggqhkjOPQQDAzCBhTELMAkGA1UEBhMC
R0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UE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aTFR+FwNI
lQgRHAdvhQh+XU3Endv7rs6y0bO4g2wdsrN58dhwmX7wEwLOXt1R0982gaEbeC9xs/FZTEYYKKuF
0mBWWg==
-----END CERTIFICATE-----

Security Communication EV RootCA1
=================================
-----BEGIN CERTIFICATE-----
MIIDfTCCAmWgAwIBAgIBADANBgkqhkiG9w0BAQUFADBgMQswCQYDVQQGEwJKUDElMCMGA1UEChMc
U0VDT00gVHJ1c3QgU3lzdGVtcyBDTy4sTFRELjEqMCgGA1UECxMhU2VjdXJpdHkgQ29tbXVuaWNh
dGlvbiBFViBSb290Q0ExMB4XDTA3MDYwNjAyMTIzMloXDTM3MDYwNjAyMTIzMlowYDELMAkGA1UE
BhMCSlAxJTAjBgNVBAoTHFNFQ09NIFRydXN0IFN5c3RlbXMgQ08uLExURC4xKjAoBgNVBAsTIVNl
Y3VyaXR5IENvbW11bmljYXRpb24gRVYgUm9vdENBMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC
AQoCggEBALx/7FebJOD+nLpCeamIivqA4PUHKUPqjgo0No0c+qe1OXj/l3X3L+SqawSERMqm4miO
/VVQYg+kcQ7OBzgtQoVQrTyWb4vVog7P3kmJPdZkLjjlHmy1V4qe70gOzXppFodEtZDkBp2uoQSX
WHnvIEqCa4wiv+wfD+mEce3xDuS4GBPMVjZd0ZoeUWs5bmB2iDQL87PRsJ3KYeJkHcFGB7hj3R4z
ZbOOCVVSPbW9/wfrrWFVGCypaZhKqkDFMxRldAD5kd6vA0jFQFTcD4SQaCDFkpbcLuUCRarAX1T4
bepJz11sS6/vmsJWXMY1VkJqMF/Cq/biPT+zyRGPMUzXn0kCAwEAAaNCMEAwHQYDVR0OBBYEFDVK
9U2vP9eCOKyrcWUXdYydVZPmMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMBAf8EBTADAQH/MA0GCSqG
SIb3DQEBBQUAA4IBAQCoh+ns+EBnXcPBZsdAS5f8hxOQWsTvoMpfi7ent/HWtWS3irO4G8za+6xm
iEHO6Pzk2x6Ipu0nUBsCMCRGef4Eh3CXQHPRwMFXGZpppSeZq51ihPZRwSzJIxXYKLerJRO1RuGG
Av8mjMSIkh1W/hln8lXkgKNrnKt34VFxDSDbEJrbvXZ5B3eZKK2aXtqxT0QsNY6llsf9g/BYxnnW
mHyojf6GPgcWkuF75x3sM3Z+Qi5KhfmRiWiEA4Glm5q+4zfFVKtWOxgtQaQM+ELbmaDgcm+7XeEW
T1MKZPlO9L9OVL14bIjqv5wTJMJwaaJ/D8g8rQjJsJhAoyrniIPtd490
-----END CERTIFICATE-----

OISTE WISeKey Global Root GA CA
===============================
-----BEGIN CERTIFICATE-----
MIID8TCCAtmgAwIBAgIQQT1yx/RrH4FDffHSKFTfmjANBgkqhkiG9w0BAQUFADCBijELMAkGA1UE
BhMCQ0gxEDAOBgNVBAoTB1dJU2VLZXkxGzAZBgNVBAsTEkNvcHlyaWdodCAoYykgMjAwNTEiMCAG
A1UECxMZT0lTVEUgRm91bmRhdGlvbiBFbmRvcnNlZDEoMCYGA1UEAxMfT0lTVEUgV0lTZUtleSBH
bG9iYWwgUm9vdCBHQSBDQTAeFw0wNTEyMTExNjAzNDRaFw0zNzEyMTExNjA5NTFaMIGKMQswCQYD
VQQGEwJDSDEQMA4GA1UEChMHV0lTZUtleTEbMBkGA1UECxMSQ29weXJpZ2h0IChjKSAyMDA1MSIw
IAYDVQQLExlPSVNURSBGb3VuZGF0aW9uIEVuZG9yc2VkMSgwJgYDVQQDEx9PSVNURSBXSVNlS2V5
IEdsb2JhbCBSb290IEdBIENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAy0+zAJs9
Nt350UlqaxBJH+zYK7LG+DKBKUOVTJoZIyEVRd7jyBxRVVuuk+g3/ytr6dTqvirdqFEr12bDYVxg
Asj1znJ7O7jyTmUIms2kahnBAbtzptf2w93NvKSLtZlhuAGio9RN1AU9ka34tAhxZK9w8RxrfvbD
d50kc3vkDIzh2TbhmYsFmQvtRTEJysIA2/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Aek0CSnwPIA1DCB
7QYDVR0fBIHlMIHiMIHfoIHcoIHZhjVodHRwOi8vd3d3LnRydXN0Y2VudGVyLmRlL2NybC92Mi90
Y19jbGFzc18zX2NhX0lJLmNybIaBn2xkYXA6Ly93d3cudHJ1c3RjZW50ZXIuZGUvQ049VEMlMjBU
cnVzdENlbnRlciUyMENsYXNzJTIwMyUyMENBJTIwSUksTz1UQyUyMFRydXN0Q2VudGVyJTIwR21i
SCxPVT1yb290Y2VydHMsREM9dHJ1c3RjZW50ZXIsREM9ZGU/Y2VydGlmaWNhdGVSZXZvY2F0aW9u
TGlzdD9iYXNlPzANBgkqhkiG9w0BAQUFAAOCAQEANmDkcPcGIEPZIxpC8vijsrlNirTzwppVMXzE
O2eatN9NDoqTSheLG43KieHPOh6sHfGcMrSOWXaiQYUlN6AT0PV8TtXqluJucsG7Kv5sbviRmEb8
yRtXW+rIGjs/sFGYPAfaLFkB2otE6OF0/ado3VS6g0bsyEa1+K+XwDsJHI/OcpY9M1ZwvJbL2NV9
IJqDnxrcOfHFcqMRA/07QlIp2+gB95tejNaNhk4Z+rwcvsUhpYeeeC422wlxo3I0+GzjBgnyXlal
092Y+tTmBvTwtiBjS+opvaqCZh77gaqnN60TGOaSw4HBM7uIHqHn4rS9MWwOUT1v+5ZWgOI2F9Hc
5A==
-----END CERTIFICATE-----

TC TrustCenter Universal CA I
=============================
-----BEGIN CERTIFICATE-----
MIID3TCCAsWgAwIBAgIOHaIAAQAC7LdggHiNtgYwDQYJKoZIhvcNAQEFBQAweTELMAkGA1UEBhMC
REUxHDAaBgNVBAoTE1RDIFRydXN0Q2VudGVyIEdtYkgxJDAiBgNVBAsTG1RDIFRydXN0Q2VudGVy
IFVuaXZlcnNhbCBDQTEmMCQGA1UEAxMdVEMgVHJ1c3RDZW50ZXIgVW5pdmVyc2FsIENBIEkwHhcN
MDYwMzIyMTU1NDI4WhcNMjUxMjMxMjI1OTU5WjB5MQswCQYDVQQGEwJERTEcMBoGA1UEChMTVEM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eBLoR9lYGxMqXnmbnwoqZ6YlPwZpVnPDimZI+ymBV3QGypzq
KOg4ZyYr8dW1P2WT+DZdjo2NQCCHGervJ8A9tDkPJXtoUHRVnAxZfVo9QZQlUgjgRywVMRnVvwdV
xrsStZf0X4OFunHB2WyBEXYKCrC/gpf36j36+uwtqSiUO1bd0lEursC9CBWMd1I0ltabrNMdjmEP
NXubrjlpC2JgQCA2j6/7Nu4tCEoduL+bXPjqpRugc6bY+G7gMwRfaKonh+3ZwZCc7b3jajWvY9+r
GNm65ulK6lCKD2GTHuItGeIwlDWSXQ62B68ZgI9HkFFLLk3dheLSClIKF5r8GrBQAuUBo2M3IUxE
xJtRmREOc5wGj1QupyheRDmHVi03vYVElOEMSyycw5KFNGHLD7ibSkNS/jQ6fbjpKdx2qcgw+BRx
gMYeNkh0IkFch4LoGHGLQYlE535YW6i4jRPpp2zDR+2zGp1iro2C6pSe3VkQw63d4k3jMdXH7Ojy
sP6SHhYKGvzZ8/gntsm+HbRsZJB/9OTEW9c3rkIO3aQab3yIVMUWbuF6aC74Or8NpDyJO3inTmOD
BCEIZ43ygknQW/2xzQ+DhNQ+IIX3Sj0rnP0qCglN6oH4EZw=
-----END CERTIFICATE-----

T\xc3\x9c\x42\xC4\xB0TAK UEKAE K\xC3\xB6k Sertifika Hizmet Sa\xC4\x9Flay\xc4\xb1\x63\xc4\xb1s\xc4\xb1 - S\xC3\xBCr\xC3\xBCm 3
=============================================================================================================================
-----BEGIN CERTIFICATE-----
MIIFFzCCA/+gAwIBAgIBETANBgkqhkiG9w0BAQUFADCCASsxCzAJBgNVBAYTAlRSMRgwFgYDVQQH
DA9HZWJ6ZSAtIEtvY2FlbGkxRzBFBgNVBAoMPlTDvHJraXllIEJpbGltc2VsIHZlIFRla25vbG9q
aWsgQXJhxZ90xLFybWEgS3VydW11IC0gVMOcQsSwVEFLMUgwRgYDVQQLDD9VbHVzYWwgRWxla3Ry
b25payB2ZSBLcmlwdG9sb2ppIEFyYcWfdMSxcm1h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5JW3SROjvi6K//zNIqeKNc0
n6wv1g/xpC+9UrJJhW05NfBEMJNGJPO251P7vGGvqaMU+8IXF4Rs4HyI+MkcVyzwPX6UvCWThOia
AJpFBUJXgPROztmuOfbIUxAMZTpHe2DC1vqRycZxbL2RhzyRhkmr8w+gbCZ2Xhysm3HljbybIR6c
1jh+JIAVMYKWsUnTYjdbiAwKYjT+p0h+mbEwi5A3lRyoH6UsjfRVyNvdWQrCrXig9IsCAwEAAaNC
MEAwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUOBTmyPCppAP0Tj4io1vy1uCtQHQwDgYDVR0P
AQH/BAQDAgEGMA0GCSqGSIb3DQEBBQUAA4IBAQABZ6OMySU9E2NdFm/soT4JXJEVKirZgCFPBdy7
pYmrEzMqnji3jG8CcmPHc3ceCQa6Oyh7pEfJYWsICCD8igWKH7y6xsL+z27sEzNxZy5p+qksP2bA
EllNC1QCkoS72xLvg3BweMhT+t/Gxv/ciC8HwEmdMldg0/L2mSlf56oBzKwzqBwKu5HEA6BvtjT5
htOzdlSY9EqBs1OdTUDs5XcTRa9bqh/YL0yCe/4qxFi7T/ye/QNlGioOw6UgFpRreaaiErS7GqQj
el/wroQk5PMr+4okoyeYZdowdXb8GZHo2+ubPzK/QJcHJrrM85SFSnonk8+QQtS4Wxam58tAA915
-----END CERTIFICATE-----

EBG Elektronik Sertifika Hizmet Sa\xC4\x9Flay\xc4\xb1\x63\xc4\xb1s\xc4\xb1
==========================================================================
-----BEGIN CERTIFICATE-----
MIIF5zCCA8+gAwIBAgIITK9zQhyOdAIwDQYJKoZIhvcNAQEFBQAwgYAxODA2BgNVBAMML0VCRyBF
bGVrdHJvbmlrIFNlcnRpZmlrYSBIaXptZXQgU2HEn2xhecSxY8Sxc8SxMTcwNQYDVQQKDC5FQkcg
QmlsacWfaW0gVGVrbm9sb2ppbGVyaSB2ZSBIaXptZXRsZXJpIEEuxZ4uMQswCQYDVQQGEwJUUjAe
Fw0wNjA4MTcwMDIx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OSUMxEzARBgNVBAMTCkNOTklDIFJPT1Qw
ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDTNfc/c3et6FtzF8LRb+1VvG7q6KR5smzD
o+/hn7E7SIX1mlwhIhAsxYLO2uOabjfhhyzcuQxauohV3/2q2x8x6gHx3zkBwRP9SFIhxFXf2tiz
VHa6dLG3fdfA6PZZxU3Iva0fFNrfWEQlMhkqx35+jq44sDB7R3IJMfAw28Mbdim7aXZOV/kbZKKT
VrdvmW7bCgScEeOAH8tjlBAKqeFkgjH5jCftppkA9nCTGPihNIaj3XrCGHn2emU1z5DrvTOTn1Or
czvmmzQgLx3vqR1jGqCA2wMv+SYahtKNu6m+UjqHZ0gNv7Sg2Ca+I19zN38m5pIEo3/PIKe38zrK
y5nLAgMBAAGjczBxMBEGCWCGSAGG+EIBAQQEAwIABzAfBgNVHSMEGDAWgBRl8jGtKvf33VKWCscC
wQ7vptU7ETAPBgNVHRMBAf8EBTADAQH/MAsGA1UdDwQEAwIB/jAdBgNVHQ4EFgQUZfIxrSr3991S
lgrHAsEO76bVOxEwDQYJKoZIhvcNAQEFBQADggEBAEs17szkrr/Dbq2flTtLP1se31cpolnKOOK5
Gv+e5m4y3R6u6jW39ZORTtpC4cMXYFDy0VwmuYK36m3knITnA3kXr5g9lNvHugDnuL8BV8F3RTIM
O/G0HAiw/VGgod2aHRM2mm23xzy54cXZF/qD1T0VoDy7HgviyJA/qIYM/PmLXoXLT1tLYhFHxUV8
BS9BsZ4QaRuZluBVeftOhpm4lNqGOGqTo+fLbuXf6iFViZx9fX+Y9QCJ7uOEwFyWtcVG6kbghVW2
G8kS1sHNzYDzAgE8yGnLRUhj2JTQ7IUOO04RZfSCjKY9ri4ilAnIXOo8gV0WKgOXFlUJ24pBgp5m
mxE=
-----END CERTIFICATE-----

ApplicationCA - Japanese Government
===================================
-----BEGIN CERTIFICATE-----
MIIDoDCCAoigAwIBAgIBMTANBgkqhkiG9w0BAQUFADBDMQswCQYDVQ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KZ+tJIX/COUgb1up8WMwusRRdv4QcmW
dupwX3kSa+SjB1oF7ydJzyGfikwJcGapJsErEU4z0g781mzSDjJkaP+tBXhfAx2o45CsJOAPQKdL
rosot4LKGAfmt1t06SAZf7IbiVQ=
-----END CERTIFICATE-----

GeoTrust Primary Certification Authority - G3
=============================================
-----BEGIN CERTIFICATE-----
MIID/jCCAuagAwIBAgIQFaxulBmyeUtB9iepwxgPHzANBgkqhkiG9w0BAQsFADCBmDELMAkGA1UE
BhMCVVMxFjAUBgNVBAoTDUdlb1RydXN0IEluYy4xOTA3BgNVBAsTMChjKSAyMDA4IEdlb1RydXN0
IEluYy4gLSBGb3IgYXV0aG9yaXplZCB1c2Ugb25seTE2MDQGA1UEAxMtR2VvVHJ1c3QgUHJpbWFy
eSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSAtIEczMB4XDTA4MDQwMjAwMDAwMFoXDTM3MTIwMTIz
NTk1OVowgZgxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1HZW9UcnVzdCBJbmMuMTkwNwYDVQQLEzAo
YykgMjAwOCBHZW9UcnVzdCBJbmMuIC0gRm9yIGF1dGhvcml6ZWQgdXNlIG9ubHkxNjA0BgNVBAMT
LUdlb1RydXN0IFByaW1hcnkgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkgLSBHMzCCASIwDQYJKoZI
hvcNAQEBBQADggEPADCCAQoCggEBANziXmJYHTNXOTIz+uvLh4yn1ErdBojqZI4xmKU4kB6Yzy5j
K/BGvESyiaHAKAxJcCGVn2TAppMSAmUmhsalifD614SgcK9PGpc/BkTVyetyEH3kMSj7HGHmKAdE
c5IiaacDiGydY8hS2pgn5whMcD60yRLBxWeDXTPzAxHsatBT4tG6NmCUgLthY2xbF37fQJQeqw3C
IShwiP/WJmxsYAQlTlV+fe+/lEjetx3dcI0FX4ilm/LC7urRQEFtYjgdVgbFA0dRIBn8exALDmKu
dlW/X3e+PkkBUz2YJQN2JFodtNuJ6nnltrM7P7pMKEF/BqxqjsHQ9gUdfeZChuOl1UcCAwEAAaNC
MEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMR5yo6hTgMdHNxr
2zFblD4/MH8tMA0GCSqGSIb3DQEBCwUAA4IBAQAtxRPPVoB7eni9n64smefv2t+UXglpp+duaIy9
cr5HqQ6XErhK8WTTOd8lNNTBzU6B8A8ExCSzNJbGpqow32hhc9f5joWJ7w5elShKKiePEI4ufIbE
Ap7aDHdlDkQNkv39sxY2+hENHYwOB4lqKVb3cvTdFZx3NWZXqxNT2I7BQMXXExZacse3aQHEerGD
AWh9jUGhlBjBJVz88P6DAod8DQ3PLghcSkANPuyBYeYk28rgDi0Hsj5W3I31QYUHSJsMC8tJP33s
t/3LjWeJGqvtux6jAAgIFyqCXDFdRootD4abdNlF+9RAsXqqaC2Gspki4cErx5z481+oghLrGREt
-----END CERTIFICATE-----

thawte Primary Root CA - G2
===========================
-----BEGIN CERTIFICATE-----
MIICiDCCAg2gAwIBAgIQNfwmXNmET8k9Jj1Xm67XVjAKBggqhkjOPQQDAzCBhDELMAkGA1UEBhMC
VVMxFTATBgNVBAoTDHRoYXd0ZSwgSW5jLjE4MDYGA1UECxMvKGMpIDIwMDcgdGhhd3RlLCBJbmMu
IC0gRm9yIGF1dGhvcml6ZWQgdXNlIG9ubHkxJDAiBgNVBAMTG3RoYXd0ZSBQcmltYXJ5IFJvb3Qg
Q0EgLSBHMjAeFw0wNzExMDUwMDAwMDBaFw0zODAxMTgyMzU5NTlaMIGEMQswCQYDVQQGEwJVUzEV
MBMGA1UEChMMdGhhd3RlLCBJbmMuMTgwNgYDVQQLEy8oYykgMjAwNyB0aGF3dGUsIEluYy4gLSBG
b3IgYXV0aG9yaXplZCB1c2Ugb25seTEkMCIGA1UEAxMbdGhhd3RlIFByaW1hcnkgUm9vdCBDQSAt
IEcyMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEotWcgnuVnfFSeIf+iha/B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Hsbnndmgcs+vHyu86YnmjSjaDFxODNi5PNxZnmxqWWjpYvVj2At
P0LMqmsywCPLLEHd5N/8YZzic7IilRFDGF/Eth9XbAoFWCLINkw6fKXRz4aviKdEAhN0cXMKQlkC
+BsUa0Lfb1+6a4KinVvnSr0eAXLbS3ToO39/fR8EtCab4LRarEc9VbjXsCZSKAExQGbY2SS99irY
7CFJXJv2eul/VTV+lmuNk5Mny5K76qxAwJ/C+IDPXfRa3M50hqY+bAtTyr2SzhkGcuYMXDhpxwTW
vGzOW/b3aJzcJRVIiKHpqfiYnODz1TEoYRFsZ5aNOZnLwkUkOQIDAQABo0IwQDAPBgNVHRMBAf8E
BTADAQH/MA4GA1UdDwEB/wQEAwIBBjAdBgNVHQ4EFgQUrWyqlGCc7eT/+j4KdCtjA/e2Wb8wDQYJ
KoZIhvcNAQELBQADggEBABpA2JVlrAmSicY59BDlqQ5mU1143vokkbvnRFHfxhY0Cu9qRFHqKweK
A3rD6z8KLFIWoCtDuSWQP3CpMyVtRRooOyfPqsMpQhvfO0zAMzRbQYi/aytlryjvsvXDqmbOe1bu
t8jLZ8HJnBoYuMTDSQPxYA5QzUbF83d597YV4Djbxy8ooAw/dyZ02SUS2jHaGh7cKUGRIjxpp7sC
8rZcJwOJ9Abqm+RyguOhCcHpABnTPtRwa7pxpqpYrvS76Wy274fMm7v/OeZWYdMKp8RcTGB7BXcm
er/YB1IsYvdwY9k5vG8cwnncdimvzsUsZAReiDZuMdRAGmI0Nj81Aa6sY6A=
-----END CERTIFICATE-----

GeoTrust Primary Certification Authority - G2
=============================================
-----BEGIN CERTIFICATE-----
MIICrjCCAjWgAwIBAgIQPLL0SAoA4v7rJDteYD7DazAKBggqhkjOPQQDAzCBmDELMAkGA1UEBhMC
VVMxFjAUBgNVBAoTDUdlb1RydXN0IEluYy4xOTA3BgNVBAsTMChjKSAyMDA3IEdlb1RydXN0IElu
Yy4gLSBGb3IgYXV0aG9yaXplZCB1c2Ugb25seTE2MDQGA1UEAxMtR2VvVHJ1c3QgUHJpbWFyeSBD
ZXJ0aWZpY2F0aW9uIEF1dGhvcml0eSAtIEcyMB4XDTA3MTEwNTAwMDAwMFoXDTM4MDExODIzNTk1
OVowgZgxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1HZW9UcnVzdCBJbmMuMTkwNwYDVQQLEzAoYykg
MjAwNyBHZW9UcnVzdCBJbmMuIC0gRm9yIGF1dGhvcml6ZWQgdXNlIG9ubHkxNjA0BgNVBAMTLUdl
b1RydXN0IFByaW1hcnkgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkgLSBHMjB2MBAGByqGSM49AgEG
BSuBBAAiA2IABBWx6P0DFUPlrOuHNxFi79KDNlJ9RVcLSo17VDs6bl8VAsBQps8lL33KSLjHUGMc
KiEIfJo22Av+0SbFWDEwKCXzXV2juLaltJLtbCyf691DiaI8S0iRHVDsJt/WYC69IaNCMEAwDwYD
VR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFBVfNVdRVfslsq0DafwBo/q+
EVXVMAoGCCqGSM49BAMDA2cAMGQCMGSWWaboCd6LuvpaiIjwH5HTRqjySkwCY/tsXzjbLkGTqQ7m
ndwxHLKgpxgceeHHNgIwOlavmnRs9vuD4DPTCF+hnMJbn0bWtsuRBmOiBuczrD6ogRLQy7rQkgu2
npaqBA+K
-----END CERTIFICATE-----

VeriSign Universal Root Certification Authority
===============================================
-----BEGIN CERTIFICATE-----
MIIEuTCCA6GgAwIBAgIQQBrEZCGzEyEDDrvkEhrFHTANBgkqhkiG9w0BAQsFADCBvTELMAkGA1UE
BhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZWZXJpU2lnbiBUcnVzdCBO
ZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwOCBWZXJpU2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVk
IHVzZSBvbmx5MTgwNgYDVQQDEy9WZXJpU2lnbiBVbml2ZXJ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jEedO2Pzmvl2MpWRsXe8rJq+seQxIcaBlVZaDrHC1LGmWazx
Y8u4TB1ZkErvkBYoH1quEPuBUDgMbMzxPcP1Y+Oz4yHJJDnp/RVmRvQbEdBNc6N9Rvk97ahfYtTx
P/jgdFcrGJ2BtMQo2pSXpXDrrB2+BxHw1dvd5Yzw1TKwg+ZX4o+/vqGqvz0dtdQ46tewXDpPaj+P
wGZsY6rp2aQW9IHRlRQOfc2VNNnSj3BzgXucfr2YYdhFh5iQxeuGMMY1v/D/w1WIg0vvBZIGcfK4
mJO37M2CYfE45k+XmCpajQ==
-----END CERTIFICATE-----

VeriSign Class 3 Public Primary Certification Authority - G4
============================================================
-----BEGIN CERTIFICATE-----
MIIDhDCCAwqgAwIBAgIQL4D+I4wOIg9IZxIokYesszAKBggqhkjOPQQDAzCByjELMAkGA1UEBhMC
VVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZWZXJpU2lnbiBUcnVzdCBOZXR3
b3JrMTowOAYDVQQLEzEoYykgMjAwNyBWZXJpU2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVz
ZSBvbmx5MUUwQwYDVQQDEzxWZXJpU2lnbiBDbGFzcyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmlj
YXRpb24gQXV0aG9yaXR5IC0gRzQwHhcNMDcxMTA1MDAwMDAwWhcNMzgwMTE4MjM1OTU5WjCByjEL
MAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZWZXJpU2lnbiBU
cnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNyBWZXJpU2lnbiwgSW5jLiAtIEZvciBhdXRo
b3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxWZXJpU2lnbiBDbGFzcyAzIFB1YmxpYyBQcmltYXJ5
IENlcnRpZmljYXRpb24gQXV0aG9yaXR5IC0gRzQwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAASnVnp8
Utpkmw4tXNherJI9/gHmGUo9FANL+mAnINmDiWn6VMaaGF5VKmTeBvaNSjutEDxlPZCIBIngMGGz
rl0Bp3vefLK+ymVhAIau2o970ImtTR1ZmkGxvEeA3J5iw/mjgbIwga8wDwYDVR0TAQH/BAUwAwEB
/zAOBgNVHQ8BAf8EBAMCAQYwbQYIKwYBBQUHAQwEYTBfoV2gWzBZMFcwVRYJaW1hZ2UvZ2lmMCEw
HzAHBgUrDgMCGgQUj+XTGoasjY5rw8+AatRIGCx7GS4wJRYjaHR0cDovL2xvZ28udmVyaXNpZ24u
Y29tL3ZzbG9nby5naWYwHQYDVR0OBBYEFLMWkf3upm7ktS5Jj4d4gYDs5bG1MAoGCCqGSM49BAMD
A2gAMGUCMGYhDBgmYFo4e1ZC4Kf8NoRRkSAsdk1DPcQdhCPQrNZ8NQbOzWm9kA3bbEhCHQ6qQgIx
AJw9SDkjOVgaFRJZap7v1VmyHVIsmXHNxynfGyphe3HR3vPA5Q06Sqotp9iGKt0uEA==
-----END CERTIFICATE-----

NetLock Arany (Class Gold) Főtanúsítvány
============================================
-----BEGIN CERTIFICATE-----
MIIEFTCCAv2gAwIBAgIGSUEs5AAQMA0GCSqGSIb3DQEBCwUAMIGnMQswCQYDVQQGEwJIVTERMA8G
A1UEBwwIQnVkYXBlc3QxFTATBgNVBAoMDE5ldExvY2sgS2Z0LjE3MDUGA1UECwwuVGFuw7pzw610
dsOhbnlraWFkw7NrIChDZXJ0aWZpY2F0aW9uIFNlcnZpY2VzKTE1MDMGA1UEAwwsTmV0TG9jayBB
cmFueSAoQ2xhc3MgR29sZCkgRsWRdGFuw7pzw610dsOhbnkwHhcNMDgxMjExMTUwODIxWhcNMjgx
MjA2MTUwODIxWjCBpzELMAkGA1UEBhMCSFUxETAPBgNVBAcMCEJ1ZGFwZXN0MRUwEwYDVQQKDAxO
ZXRMb2NrIEtmdC4xNzA1BgNVBAsMLlRhbsO6c8OtdHbDoW55a2lhZMOzayAoQ2VydG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gUm9vdCBDQSAxMB4XDTAzMDUx
NTA1MTMxNFoXDTIzMDUxNTA0NTIyOVowRzELMAkGA1UEBhMCSEsxFjAUBgNVBAoTDUhvbmdrb25n
IFBvc3QxIDAeBgNVBAMTF0hvbmdrb25nIFBvc3QgUm9vdCBDQSAxMIIBIjANBgkqhkiG9w0BAQEF
AAOCAQ8AMIIBCgKCAQEArP84tulmAknjorThkPlAj3n54r15/gK97iSSHSL22oVyaf7XPwnU3ZG1
ApzQjVrhVcNQhrkpJsLj2aDxaQMoIIBFIi1WpztUlVYiWR8o3x8gPW2iNr4joLFutbEnPzlTCeqr
auh0ssJlXI6/fMN4hM2eFvz1Lk8gKgifd/PFHsSaUmYeSF7jEAaPIpjhZY4bXSNmO7ilMlHIhqqh
qZ5/dpTCpmy3QfDVyAY45tQM4vM7TG1QjMSDJ8EThFk9nnV0ttgCXjqQesBCNnLsak3c78QA3xMY
V18meMjWCnl3v/evt3a5pQuEF10Q6m/hq5URX208o1xNg1vysxmKgIsLhwIDAQABoyYwJDASBgNV
HRMBAf8ECDAGAQH/AgEDMA4GA1UdDwEB/wQEAwIBxjANBgkqhkiG9w0BAQUFAAOCAQEADkbVPK7i
h9legYsCmEEIjEy82tvuJxuC52pF7BaLT4Wg87JwvVqWuspube5Gi27nKi6Wsxkz67SfqLI37pio
l7Yutmcn1KZJ/RyTZXaeQi/cImyaT/JaFTmxcdcrUehtHJjA2Sr0oYJ71clBoiMBdDhViw+5Lmei
IAQ32pwL0xch4I+XeTRvhEgCIDMb5jREn5Fw9IBehEPCKdJsEhTkYY2sEJCehFC78JZvRZ+K88ps
T/oROhUVRsPNH4NbLUES7VBnQRM9IauUiqpOfMGx+6fWtScvl6tu4B3i0RwsH0Ti/L6RoZz71ilT
c4afU9hDDl3WY4JxHYB0yvbiAmvZWg==
-----END CERTIFICATE-----

SecureSign RootCA11
===================
-----BEGIN CERTIFICATE-----
MIIDbTCCAlWgAwIBAgIBATANBgkqhkiG9w0BAQUFADBYMQswCQY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IXXwkkwp9y+cAS7+UEaeZAwUswdbxcJzbPEHXEUkFDWug/Fq
TYl6+rPYLWbwNof1K1MCAwEAAaOBqjCBpzAPBgNVHRMBAf8EBTADAQH/MB8GA1UdIwQYMBaAFKaz
4SsrSbbXc6GqlPUB53NlTKxQMA4GA1UdDwEB/wQEAwIBhjAdBgNVHQ4EFgQUprPhKytJttdzoaqU
9QHnc2VMrFAwRAYDVR0gBD0wOzA5BgRVHSAAMDEwLwYIKwYBBQUHAgEWI2h0dHA6Ly9hY2VkaWNv
bS5lZGljb21ncm91cC5jb20vZG9jMA0GCSqGSIb3DQEBBQUAA4ICAQDOLAtSUWImfQwng4/F9tqg
aHtPkl7qpHMyEVNEskTLnewPeUKzEKbHDZ3Ltvo/Onzqv4hTGzz3gvoFNTPhNahXwOf9jU8/kzJP
eGYDdwdY6ZXIfj7QeQCM8htRM5u8lOk6e25SLTKeI6RF+7YuE7CLGLHdztUdp0J/Vb77W7tH1Pwk
zQSulgUV1qzOMPPKC8W64iLgpq0i5ALudBF/TP94HTXa5gI06xgSYXcGCRZj6hitoocf8seACQl1
ThCojz2GuHURwCRiipZ7SkXp7FnFvmuD5uHorLUwHv4FB4D54SMNUI8FmP8sX+g7tq3PgbUhh8oI
KiMnMCArz+2UW6yyetLHKKGKC5tNSixthT8Jcjxn4tncB7rrZXtaAWPWkFtPF2Y9fwsZo5NjEFIq
nxQWWOLcpfShFosOkYuByptZ+thrkQdlVV9SH686+5DdaaVbnG0OLLb6zqylfDJKZ0DcMDQj3dcE
I2bw/FWAp/tmGYI1Z2JwOV5vx+qQQEQIHriy1tvuWacNGHk0vFQYXlPKNFHtRQrmjseCNj6nOGOp
MCwXEGCSn1WHElkQwg9naRHMTh5+Spqtr0CodaxWkHS4oJyleW/c6RrIaQXpuvoDs3zk4E7Czp3o
tkYNbn5XOmeUwssfnHdKZ05phkOTOPu220+DkdRgfks+KzgHVZhepA==
-----END CERTIFICATE-----

Verisign Class 3 Public Primary Certification Authority
=======================================================
-----BEGIN CERTIFICATE-----
MIICPDCCAaUCEDyRMcsf9tAbDpq40ES/Er4wDQYJKoZIhvcNAQEFBQAwXzELMAkGA1UEBhMCVVMx
FzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAzIFB1YmxpYyBQcmltYXJ5
IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk2MDEyOTAwMDAwMFoXDTI4MDgwMjIzNTk1OVow
XzELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAz
IFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGfMA0GCSqGSIb3DQEBAQUA
A4GNADCBiQKBgQDJXFme8huKARS0EN8EQNvjV69qRUCPhAwL0TPZ2RHP7gJYHyX3KqhEBarsAx94
f56TuZoAqiN91qyFomNFx3InzPRMxnVx0jnvT0Lwdd8KkMaOIG+YD/isI19wKTakyYbnsZogy1Ol
hec9vn2a/iRFM9x2Fe0PonFkTGUugWhFpwIDAQABMA0GCSqGSIb3DQEBBQUAA4GBABByUqkFFBky
CEHwxWsKzH4PIRnN5GfcX6kb5sroc50i2JhucwNhkcV8sEVAbkSdjbCxlnRhLQ2pRdKkkirWmnWX
bj9T/UWZYB2oK0z5XqcJ2HUw19JlYD1n1khVdWk/kfVIC0dpImmClr7JyDiGSnoscxlIaU5rfGW/
D/xwzoiQ
-----END CERTIFICATE-----

Microsec e-Szigno Root CA 2009
==============================
-----BEGIN CERTIFICATE-----
MIIECjCCAvKgAwIBAgIJAMJ+QwRORz8ZMA0GCSqGSIb3DQEBCwUAMIGCMQswCQYDVQQGEwJIVTER
MA8GA1UEBwwIQnVkYXBlc3QxFjAUBgNVBAoMDU1pY3Jvc2VjIEx0ZC4xJzAlBgNVBAMMHk1pY3Jv
c2VjIGUtU3ppZ25vIFJvb3QgQ0EgMjAwOTEfMB0GCSqGSIb3DQEJARYQ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OofyK/FFh+U9rNHHV4S9a67c2Pm2G2JwCz02
yULyMtd6YebS2z3PyKnJm9zbWETXbzivf3jTo60adbocwTZ8jx5tHMN1Rq41Bab2XD0h7lbwyYIi
LXpUq3DDfSJlgnCW
-----END CERTIFICATE-----

E-Guven Kok Elektronik Sertifika Hizmet Saglayicisi
===================================================
-----BEGIN CERTIFICATE-----
MIIDtjCCAp6gAwIBAgIQRJmNPMADJ72cdpW56tustTANBgkqhkiG9w0BAQUFADB1MQswCQYDVQQG
EwJUUjEoMCYGA1UEChMfRWxla3Ryb25payBCaWxnaSBHdXZlbmxpZ2kgQS5TLjE8MDoGA1UEAxMz
ZS1HdXZlbiBLb2sgRWxla3Ryb25payBTZXJ0aWZpa2EgSGl6bWV0IFNhZ2xheWljaXNpMB4XDTA3
MDEwNDExMzI0OFoXDTE3MDEwNDExMzI0OFowdTELMAkGA1UEBhMCVFIxKDAmBgNVBAoTH0VsZWt0
cm9uaWsgQmlsZ2kgR3V2ZW5saWdpIEEuUy4xPDA6BgNVBAMTM2UtR3V2ZW4gS29rIEVsZWt0cm9u
aWsgU2VydGlmaWthIEhpem1ldCBTYWdsYXlpY2lzaTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC
AQoCggEBAMMSIJ6wXgBljU5Gu4Bc6SwGl9XzcslwuedLZYDBS75+PNdUMZTe1RK6UxYC6lhj71vY
8+0qGqpxSKPcEC1fX+tcS5yWCEIlKBHMilpiAVDV6wlTL/jDj/6z/P2douNffb7tC+Bg62nsM+3Y
jfsSSYMAyYuXjDtzKjKzEve5TfL0TW3H5tYmNwjy2f1rXKPlSFxYvEK+A1qBuhw1DADT9SN+cTAI
JjjcJRFHLfO6IxClv7wC90Nex/6wN1CZew+TzuZDLMN+DfIcQ2Zgy2ExR4ejT669VmxMvLz4Bcpk
9Ok0oSy1c+HCPujIyTQlCFzz7abHlJ+tiEMl1+E5YP6sOVkCAwEAAaNCMEAwDgYDVR0PAQH/BAQD
AgEGMA8GA1UdEwEB/w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dQQ4gOsC0p6Hpsk+QLjJg6VfLuQSSaGjl
OCZgdbKfd/+RFO+uIEn8rUAVSNECMWEZXriX7613t2Saer9fwRPvm2L7DWzgVGkWqQPabumDk3F2
xmmFghcCAwEAAaNCMEAwDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYE
FI/wS3+oLkUkrk1Q+mOai97i3Ru8MA0GCSqGSIb3DQEBCwUAA4IBAQBLQNvAUKr+yAzv95ZURUm7
lgAJQayzE4aGKAczymvmdLm6AC2upArT9fHxD4q/c2dKg8dEe3jgr25sbwMpjjM5RcOO5LlXbKr8
EpbsU8Yt5CRsuZRj+9xTaGdWPoO4zzUhw8lo/s7awlOqzJCK6fBdRoyV3XpYKBovHd7NADdBj+1E
bddTKJd+82cEHhXXipa0095MJ6RMG3NzdvQXmcIfeg7jLQitChws/zyrVQ4PkX4268NXSb7hLi18
YIvDQVETI53O9zJrlAGomecsMx86OyXShkDOOyyGeMlhLxS67ttVb9+E7gUJTb0o2HLO02JQZR7r
kpeDMdmztcpHWD9f
-----END CERTIFICATE-----

Autoridad de Certificacion Firmaprofesional CIF A62634068
=========================================================
-----BEGIN CERTIFICATE-----
MIIGFDCCA/ygAwIBAgIIU+w77vuySF8wDQYJKoZIhvcNAQEFBQAwUTELMAkGA1UEBhMCRVMxQjBA
BgNVBAMMOUF1dG9yaWRhZCBkZSBDZXJ0aWZpY2FjaW9uIEZpcm1hcHJvZmVzaW9uYWwgQ0lGIEE2
MjYzNDA2ODAeFw0wOTA1MjAwODM4MTVaFw0zMDEyMzEwODM4MTVaMFExCzAJBgNVBAYTAkVTMUIw
QAYDVQQDDDlBdXRvcmlkYWQgZGUgQ2VydGlmaWNhY2lvbiBGaXJtYXByb2Zlc2lvbmFsIENJRiBB
NjI2MzQwNjgwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDKlmuO6vj78aI14H9M2uDD
Utd9thDIAl6zQyrET2qyyhxdKJp4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56awmqxinuaElnMIAkejEWOVt+8Rwu3WwJrfIxwYJOubv5vr8q
hT/AQKM6WfxZSzwoJNu0FXWuDYi6LnPAvViH5ULy617uHjAimcs30cQhbIHsvm0m5hzkQiCeR7Cs
g1lwLDXWrzY0tM07+DKo7+N4ifuNRSzanLh+QBxh5z6ikixL8s36mLYp//Pye6kfLqCTVyvehQP5
aTfLnnhqBbTFMXiJ7HqnheG5ezzevh55hM6fcA5ZwjUukCox2eRFekGkLhObNA5me0mrZJfQRsN5
nXJQY6aYWwa9SG3YOYNw6DXwBdGqvOPbyALqfP2C2sJbUjWumDqtujWTI6cfSN01RpiyEGjkpTHC
ClguGYEQyVB1/OpaFs4R1+7vUIgtYf8/QnMFlEPVjjxOAToZpR9GTnfQXeWBIiGH/pR9hNiTrdZo
Q0iy2+tzJOeRf1SktoA+naM8THLCV8Sg1Mw4J87VBp6iSNnpn86CcDaTmjvfliHjWbcM2pE38P1Z
WrOZyGlsQyYBNWNgVYkDOnXYukrZVP/u3oDYLdE41V4tC5h9Pmzb/CaIxw==
-----END CERTIFICATE-----

Chambers of Commerce Root - 2008
================================
-----BEGIN CERTIFICATE-----
MIIHTzCCBTegAwIBAgIJAKPaQn6ksa7aMA0GCSqGSIb3DQEBBQUAMIGuMQswCQYDVQQGEwJFVTFD
MEEGA1UEBxM6TWFkcmlkIChzZWUgY3VycmVudCBhZGRyZXNzIGF0IHd3dy5jYW1lcmZpcm1hLmNv
bS9hZGRyZXNzKTESMBAGA1UEBRMJQTgyNzQzMjg3MRswGQYDVQQKExJBQyBDYW1lcmZpcm1hIFMu
QS4xKTAnBgNVBAMTIENoYW1iZXJzIG9mIENvbW1lcmNlIFJvb3QgLSAyMDA4MB4XDTA4MDgwMTEy
Mjk1MFoXDTM4MDczMTEyMjk1MFowga4xCzAJBgNVBAYTAkVVMUMwQQYDVQQHEzpNYWRyaWQgKHNl
ZSBjdXJyZW50IGFkZHJlc3MgYXQgd3d3LmNhbWVyZmlybWEuY29tL2FkZHJl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JyZW50IGFkZHJlc3MgYXQgd3d3LmNh
bWVyZmlybWEuY29tL2FkZHJlc3MpMRIwEAYDVQQFEwlBODI3NDMyODcxGzAZBgNVBAoTEkFDIENh
bWVyZmlybWEgUy5BLjEpMCcGA1UEAxMgQ2hhbWJlcnMgb2YgQ29tbWVyY2UgUm9vdCAtIDIwMDiC
CQCj2kJ+pLGu2jAOBgNVHQ8BAf8EBAMCAQYwPQYDVR0gBDYwNDAyBgRVHSAAMCowKAYIKwYBBQUH
AgEWHGh0dHA6Ly9wb2xpY3kuY2FtZXJmaXJtYS5jb20wDQYJKoZIhvcNAQEFBQADggIBAJASryI1
wqM58C7e6bXpeHxIvj99RZJe6dqxGfwWPJ+0W2aeaufDuV2I6A+tzyMP3iU6XsxPpcG1Lawk0lgH
3qLPaYRgM+gQDROpI9CF5Y57pp49chNyM/WqfcZjHwj0/gF/JM8rLFQJ3uIrbZLGOU8W6jx+ekbU
RWpGqOt1glanq6B8aBMz9p0w8G8nOSQjKpD9kCk18pPfNKXG9/jvjA9iSnyu0/VU+I22mlaHFoI6
M6taIgj3grrqLuBHmrS1RaMFO9ncLkVAO+rcf+g769HsJtg1pDDFOqxXnrN2pSB7+R5KBWIBpih1
YJeSDW4+TTdDDZIVnBgizVGZoCkaPF+KMjNbMMeJL0eYD6MDxvbxrN8y8NmBGuScvfaAFPDRLLmF
9dijscilIeUcE5fuDr3fKanvNFNb0+RqE4QGtjICxFKuItLcsiFCGtpA8CnJ7AoMXOLQusxI0zcK
zBIKinmwPQN/aUv0NCB9szTqjktk9T79syNnFQ0EuPAtwQlRPLJsFfClI9eDdOTlLsn+mCdCxqvG
nrDQWzilm1DefhiYtUU79nm06PcaewaD+9CL2rvHvRirCG88gGtAPxkZumWK5r7VXNM21+9AUiRg
OGcEMeyP84LG3rlV8zsxkVrctQgVrXYlCg17LofiDKYGvCYQbTed7N14jHyAxfDZd0jQ
-----END CERTIFICATE-----

Global Chambersign Root - 2008
==============================
-----BEGIN CERTIFICATE-----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kK9yydYhz2rXzdpjEetrHH
foUm+qRqtdpjMNHvkzeyZi99Bffnt0uYlDXA2TopwZ2yUDMdSqlapskD7+3056huirRXhOukP9Du
qqqHW2Pok+JrqNS4cnhrG+055F3Lm6qH1U9OAP7Zap88MQ8oAgF9mOinsKJknnn4SPIVqczmyETr
P3iZ8ntxPjzxmKfFGBI/5rsoM0LpRQp8bfKGeS/Fghl9CYl8slR2iK7ewfPM4W7bMdaTrpmg7yVq
c5iJWzouE4gev8CSlDQb4ye3ix5vQv/n6TebUB0tovkC7stYWDpxvGjjqsGvHCgfotwjZT+B6q6Z
09gwzxMNTxXJhLynSC34MCN32EZLeW32jO06f2ARePTpm67VVMB0gNELQp/B
-----END CERTIFICATE-----

Go Daddy Root Certificate Authority - G2
========================================
-----BEGIN CERTIFICATE-----
MIIDxTCCAq2gAwIBAgIBADANBgkqhkiG9w0BAQsFADCBgzELMAkGA1UEBhMCVVMxEDAOBgNVBAgT
B0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxGjAYBgNVBAoTEUdvRGFkZHkuY29tLCBJbmMu
MTEwLwYDVQQDEyhHbyBEYWRkeSBSb290IENlcnRpZmljYXRlIEF1dGhvcml0eSAtIEcyMB4XDTA5
MDkwMTAwMDAwMFoXDTM3MTIzMTIzNTk1OVowgYMxCzAJBgNVBAYTAlVTMRAwDgYDVQQIEwdBcml6
b25hMRMwEQYDVQQHEwpTY290dHNkYWxlMRowGAYDVQQKExFHb0RhZGR5LmNvbSwgSW5jLjExMC8G
A1UEAxMoR28gRGFkZHkgUm9vdCBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkgLSBHMjCCASIwDQYJKoZI
hvcNAQEBBQADggEPADCCAQoCggEBAL9xYgjx+lk09xvJGKP3gElY6SKDE6bFIEMBO4Tx5oVJnyfq
9oQbTqC023CYxzIBsQU+B07u9PpPL1kwIuerGVZr4oAH/PMWdYA5UXvl+TW2dE6pjYIT5LY/qQOD
+qK+ihVqf94Lw7YZFAXK6sOoBJQ7RnwyDfMAZiLIjWltNowRGLfTshxgtDj6AozO091GB94KPutd
fMh8+7ArU6SSYmlRJQVhGkSBjCypQ5Yj36w6gZoOKcUcqeldHraenjAKOc7xiID7S13MMuyFYkMl
NAJWJwGRtDtwKj9useiciAF9n9T521NtYJ2/LOdYq7hfRvzOxBsDPAnrSTFcaUaz4EcCAwEAAaNC
MEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFDqahQcQZyi27/a9
BUFuIMGU2g/eMA0GCSqGSIb3DQEBCwUAA4IBAQCZ21151fmXWWcDYfF+OwYxdS2hII5PZYe096ac
vNjpL9DbWu7PdIxztDhC2gV7+AJ1uP2lsdeu9tfeE8tTEH6KRtGX+rcuKxGrkLAngPnon1rpN5+r
5N9ss4UXnT3ZJE95kTXWXwTrgIOrmgIttRD02JDHBHNA7XIloKmf7J6raBKZV8aPEjoJpL1E/QYV
N8Gb5DKj7Tjo2GTzLH4U/ALqn83/B2gX2yKQOC16jdFU8WnjXzPKej17CuPKf1855eJ1usV2GDPO
LPAvTK33sefOT6jEm0pUBsV/fdUID+Ic/n4XuKxe9tQWskMJDE32p2u0mYRlynqI4uJEvlz36hz1
-----END CERTIFICATE-----

Starfield Root Certificate Authority - G2
=========================================
-----BEGIN CERTIFICATE-----
MIID3TCCAsWgAwIBAgIBADANBgkqhkiG9w0BAQsFADCBjzELMAkGA1UEBhMCVVMxEDAOBgNVBAgT
B0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxJTAjBgNVBAoTHFN0YXJmaWVsZCBUZWNobm9s
b2dpZXMsIEluYy4xMjAwBgNVBAMTKVN0YXJmaWVsZCBSb290IENlcnRpZmljYXRlIEF1dGhvcml0
eSAtIEcyMB4XDTA5MDkwMTAwMDAwMFoXDTM3MTIzMTIzNTk1OVowgY8xCzAJBgNVBAYTAlVTMRAw
DgYDVQQIEwdBcml6b25hMRMwEQYDVQQHEwpTY290dHNkYWxlMSUwIwYDVQQKExxTdGFyZmllbGQg
VGVjaG5vbG9naWVzLCBJbmMuMTIwMAYDVQQDEylTdGFyZmllbGQgUm9vdCBDZXJ0aWZpY2F0ZSBB
dXRob3JpdHkgLSBHMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAL3twQP89o/8ArFv
W59I2Z154qK3A2FWGMNHttfKPTUuiUP3oWmb3ooa/RMgnLRJdzIpVv257IzdIvpy3Cdhl+72WoTs
bhm5iSzchFvVdPtrX8WJpRBSiUZV9Lh1HOZ/5FSuS/hVclcCGfgXcVnrHigHdMWdSL5stPSksPNk
N3mSwOxGXn/hbVNMYq/NHwtjuzqd+/x5AJhhdM8mgkBj87JyahkNmcrUDnXMN/uLicFZ8WJ/X7Nf
ZTD4p7dNdloedl40wOiWVpmKs/B/pM293DIxfJHP4F8R+GuqSVzRmZTRouNjWwl2tVZi4Ut0HZbU
JtQIBFnQmA4O5t78w+wfkPECAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMC
AQYwHQYDVR0OBBYEFHwMMh+n2TB/xH1oo2Kooc6rB1snMA0GCSqGSIb3DQEBCwUAA4IBAQARWfol
TwNvlJk7mh+ChTnUdgWUXuEok21iXQnCoKjUsHU48TRqneSfioYmUeYs0cYtbpUgSpIB7LiKZ3sx
4mcujJUDJi5DnUox9g61DLu34jd/IroAow57UvtruzvE03lRTs2Q9GcHGcg8RnoNAX3FWOdt5oUw
F5okxBDgBPfg8n/Uqgr/Qh037ZTlZFkSIHc40zI+OIF1lnP6aI+xy84fxez6nH7PfrHxBy22/L/K
pL/QlwVKvOoYKAKQvVR4CSFx09F9HdkWsKlhPdAKACL8x3vLCWRFCztAgfd9fDL1mMpYjn0q7pBZ
c2T5NnReJaH1ZgUufzkVqSr7UIuOhWn0
-----END CERTIFICATE-----

Starfield Services Root Certificate Authority - G2
==================================================
-----BEGIN CERTIFICATE-----
MIID7zCCAtegAwIBAgIBADANBgkqhkiG9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4+e0BQ5v1VwSJlXMbSc7kqYA5YwH2AG7hsj/oFg
IxpHYoWlzBk0gG+zrBrjn/B7SK3VAdlntqlyk+otZrWyuOQ9PLLvTIzq6we/qzWaVYa8GKa1qF60
g2xraUDTn9zxw2lrueFtCfTxqlB2Cnp9ehehVZZCmTEJ3WARjQUwfuaORtGdFNrHF+QFlozEJLUb
zxQHskD4o55BhrwE0GuWyCqANP2/7waj3VjFhT0+j/6eKeC2uAloGRwYQw==
-----END CERTIFICATE-----

AffirmTrust Premium ECC
=======================
-----BEGIN CERTIFICATE-----
MIIB/jCCAYWgAwIBAgIIdJclisc/elQwCgYIKoZIzj0EAwMwRTELMAkGA1UEBhMCVVMxFDASBgNV
BAoMC0FmZmlybVRydXN0MSAwHgYDVQQDDBdBZmZpcm1UcnVzdCBQcmVtaXVtIEVDQzAeFw0xMDAx
MjkxNDIwMjRaFw00MDEyMzExNDIwMjRaMEUxCzAJBgNVBAYTAlVTMRQwEgYDVQQKDAtBZmZpcm1U
cnVzdDEgMB4GA1UEAwwXQWZmaXJtVHJ1c3QgUHJlbWl1bSBFQ0MwdjAQBgcqhkjOPQIBBgUrgQQA
IgNiAAQNMF4bFZ0D0KF5Nbc6PJJ6yhUczWLznCZcBz3lVPqj1swS6vQUX+iOGasvLkjmrBhDeKzQ
N8O9ss0s5kfiGuZjuD0uL3jET9v0D6RoTFVya5UdThhClXjMNzyR4ptlKymjQjBAMB0GA1UdDgQW
BBSaryl6wBE1NSZRMADDav5A1a7WPDAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBBjAK
BggqhkjOPQQDAwNnADBkAjAXCfOHiFBar8jAQr9HX/VsaobgxCd05DhT1wV/GzTjxi+zygk8N53X
57hG8f2h4nECMEJZh0PUUd+60wkyWs6Iflc9nF9Ca/UHLbXwgpP5WW+uZPpY5Yse42O+tYHNbwKM
eQ==
-----END CERTIFICATE-----

Certum Trusted Network CA
=========================
-----BEGIN CERTIFICATE-----
MIIDuzCCAqO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EauFddE
wk01+dIL8hf2rGbVJLJP0RyZwG71fet0BLj5TXcJ17TPBzAJ8bgAVtkXFhYKK4bfjwEZGuW7gmP/
vgt2Fl43N+bYdJeimUV5
-----END CERTIFICATE-----

Root CA Generalitat Valenciana
==============================
-----BEGIN CERTIFICATE-----
MIIGizCCBXOgAwIBAgIEO0XlaDANBgkqhkiG9w0BAQUFADBoMQswCQYDVQQGEwJFUzEfMB0GA1UE
ChMWR2VuZXJhbGl0YXQgVmFsZW5jaWFuYTEPMA0GA1UECxMGUEtJR1ZBMScwJQYDVQQDEx5Sb290
IENBIEdlbmVyYWxpdGF0IFZhbGVuY2lhbmEwHhcNMDEwNzA2MTYyMjQ3WhcNMjEwNzAxMTUyMjQ3
WjBoMQswCQYDVQQGEwJFUzEfMB0GA1UEChMWR2VuZXJhbGl0YXQgVmFsZW5jaWFuYTEPMA0GA1UE
CxMGUEtJR1ZBMScwJQYDVQQDEx5Sb290IENBIEdlbmVyYWxpdGF0IFZhbGVuY2lhbmEwggEiMA0G
CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDGKqtXETcvIorKA3Qdyu0togu8M1JAJke+WmmmO3I2
F0zo37i7L3bhQEZ0ZQKQUgi0/6iMweDHiVYQOTPvaLRfX9ptI6GJXiKjSgbwJ/BXufjpTjJ3Cj9B
ZPPrZe52/lSqfR0grvPXdMIKX/UIKFIIzFVd0g/bmoGlu6GzwZTNVOAydTGRGmKy3nXiz0+J2ZGQ
D0EbtFpKd71ng+CT516nDOeB0/RSrFOyA8dEJvt55cs0YFAQexvba9dHq198aMpunUEDEO5rmXte
JajCq+TA81yc477OMUxkHl6AovWDfgzWyoxVjr7gvkkHD6MkQXpYHYTqWBLI4bft75PelAgxAgMB
AAGjggM7MIIDNzAyBggrBgEFBQcBAQQmMCQwIgYIKwYBBQUHMAGGFmh0dHA6Ly9vY3NwLnBraS5n
dmEuZXMwEgYDVR0TAQH/BAgwBgEB/wIBAjCCAjQGA1UdIASCAiswggInMIICIwY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DO6w8dB3F/GaswADm0yqLaHNgBid5seHzTLkDx4
iHQF63n1k3Flyp3HaxgtPVxO59X4PzF9j4fsCiIvI+n+u33J4PTs63zEsMMtYrWacdaxaujs2e3V
cuy+VwHOBVWf3tFgiBCzAgMBAAGjNjA0MA8GA1UdEwEB/wQFMAMBAf8wEQYDVR0OBAoECERqlWdV
eRFPMA4GA1UdDwEB/wQEAwIBBjANBgkqhkiG9w0BAQUFAAOCAQEAVdRU0VlIXLOThaq/Yy/kgM40
ozRiPvbY7meIMQQDbwvUB/tOdQ/TLtPAF8fGKOwGDREkDg6lXb+MshOWcdzUzg4NCmgybLlBMRmr
sQd7TZjTXLDR8KdCoLXEjq/+8T/0709GAHbrAvv5ndJAlseIOrifEXnzgGWovR/TeIGgUUw3tKZd
JXDRZslo+S4RFGjxVJgIrCaSD96JntT6s3kr0qN51OyLrIdTaEJMUVF0HhsnLuP1Hyl0Te2v9+GS
mYHovjrHF1D2t8b8m7CKa9aIA5GPBnc6hQLdmNVDeD/GMBWsm2vLV7eJUYs66MmEDNuxUCAKGkq6
ahq97BvIxYSazQ==
-----END CERTIFICATE-----

TWCA Root Certification Authority
=================================
-----BEGIN CERTIFICATE-----
MIIDezCCAmOgAwIBAgIBATANBgkqhkiG9w0BAQUFADBfMQswCQYDVQQGEwJUVzESMBAGA1UECgwJ
VEFJV0FOLUNBMRAwDgYDVQQLDAdSb290IENBMSowKAYDVQQDDCFUV0NBIFJvb3QgQ2VydGlmaWNh
dGlvbiBBdXRob3JpdHkwHhcNMDgwODI4MDcyNDMzWhcNMzAxMjMxMTU1OTU5WjBfMQswCQYDVQQG
EwJUVzESMBAGA1UECgwJVEFJV0FOLUNBMRAwDgYDVQQLDAdSb290IENBMSowKAYDVQQDDCFUV0NB
IFJvb3QgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK
AoIBAQCwfnK4pAOU5qfeCTiRShFAh6d8WWQUe7UREN3+v9XAu1bihSX0NXIP+FPQQeFEAcK0HMMx
QhZHhTMidrIKbw/lJVBPhYa+v5guEGcevhEFhgWQxFnQfHgQsIBct+HHK3XLfJ+utdGdIzdjp9xC
oi2SBBtQwXu4PhvJVgSLL1KbralW6cH/ralYhzC2gfeXRfwZVzsrb+RH9JlF/h3x+JejiB03HFyP
4HYlmlD4oFT/RJB2I9IyxsOrBr/8+7/zrX2SYgJbKdM1o5OaQ2RgXbL6Mv87BK9NQGr5x+PvI/1r
y+UPizgN7gr8/g+YnzAx3WxSZfmLgb4i4RxYA7qRG4kHAgMBAAGjQjBAMA4GA1UdDwEB/wQEAwIB
BjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBRqOFsmjd6LWvJPelSDGRjjCDWmujANBgkqhkiG
9w0BAQUFAAOCAQEAPNV3PdrfibqHDAhUaiBQkr6wQT25JmSDCi/oQMCXKCeCMErJk/9q56YAf4lC
mtYR5VPOL8zy2gXE/uJQxDqGfczafhAJO5I1KlOy/usrBdlsXebQ79NqZp4VKIV66IIArB6nCWlW
QtNoURi+VJq/REG6Sb4gumlc7rh3zc5sH62Dlhh9DrUUOYTxKOkto557HnpyWoOzeW/vtPzQCqVY
T0bf+215WfKEIlKuD8z7fDvnaspHYcN6+NOSBB+4IIThNlQWx0DeO4pz3N/GCUzf7Nr/1FNCocny
Yh0igzyXxfkZYiesZSLX0zzG5Y6yU8xJzrww/nsOM5D77dIUkR8Hrw==
-----END CERTIFICATE-----

Security Communication RootCA2
==============================
-----BEGIN CERTIFICATE-----
MIIDdzCCAl+gAwIBAgIBADANBgkqhkiG9w0BAQsFADBdMQswCQYDVQQGEwJKUDElMCMGA1UEChMc
U0VDT00gVHJ1c3QgU3lzdGVtcyBDTy4sTFRELjEnMCUGA1UECxMeU2VjdXJpdHkgQ29tbXVuaWNh
dGlvbiBSb290Q0EyMB4XDTA5MDUyOTA1MDAzOVoXDTI5MDUyOTA1MDAzOVowXTELMAkGA1UEBhMC
SlAxJTAjBgNVB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sg0qBIimAy4E5S2S+zw
0JDnJwIDAQABo4HjMIHgMB0GA1UdEQQWMBSBEmVjX2FjY0BjYXRjZXJ0Lm5ldDAPBgNVHRMBAf8E
BTADAQH/MA4GA1UdDwEB/wQEAwIBBjAdBgNVHQ4EFgQUoMOLRKo3pUW/l4Ba0fF4opvpXY0wfwYD
VR0gBHgwdjB0BgsrBgEEAfV4AQMBCjBlMCwGCCsGAQUFBwIBFiBodHRwczovL3d3dy5jYXRjZXJ0
Lm5ldC92ZXJhcnJlbDA1BggrBgEFBQcCAjApGidWZWdldSBodHRwczovL3d3dy5jYXRjZXJ0Lm5l
dC92ZXJhcnJlbCAwDQYJKoZIhvcNAQEFBQADggEBAKBIW4IB9k1IuDlVNZyAelOZ1Vr/sXE7zDkJ
lF7W2u++AVtd0x7Y/X1PzaBB4DSTv8vihpw3kpBWHNzrKQXlxJ7HNd+KDM3FIUPpqojlNcAZQmNa
Al6kSBg6hW/cnbw/nZzBh7h6YQjpdwt/cKt63dmXLGQehb+8dJahw3oS7AwaboMMPOhyRp/7SNVe
l+axofjk70YllJyJ22k4vuxcDlbHZVHlUIiIv0LVKz3l+bqeLrPK9HOSAgu+TGbrIP65y7WZf+a2
E/rKS03Z7lNGBjvGTq2TWoF+bCpLagVFjPIhpDGQh2xlnJ2lYJU6Un/10asIbvPuW/mIPX64b24D
5EI=
-----END CERTIFICATE-----

Hellenic Academic and Research Institutions RootCA 2011
=======================================================
-----BEGIN CERTIFICATE-----
MIIEMTCCAxmgAwIBAgIBADANBgkqhkiG9w0BAQUFADCBlTELMAkGA1UEBhMCR1IxRDBCBgNVBAoT
O0hlbGxlbmljIEFjYWRlbWljIGFuZCBSZXNlYXJjaCBJbnN0aXR1dGlvbnMgQ2VydC4gQXV0aG9y
aXR5MUAwPgYDVQQDEzdIZWxsZW5pYyBBY2FkZW1pYyBhbmQgUmVzZWFyY2ggSW5zdGl0dXRpb25z
IFJvb3RDQSAyMDExMB4XDTExMTIwNjEzNDk1MloXDTMx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qy5V8AcysNnq/onN694/BtZqhFLKPM58N
7yLcZnuEvUUXBj08yrl3NI/K6s8/MT7jiOOASSXIl7WdmplNsDz4SgCbZN2fOUvRJ9e4
-----END CERTIFICATE-----

Actalis Authentication Root CA
==============================
-----BEGIN CERTIFICATE-----
MIIFuzCCA6OgAwIBAgIIVwoRl0LE48wwDQYJKoZIhvcNAQELBQAwazELMAkGA1UEBhMCSVQxDjAM
BgNVBAcMBU1pbGFuMSMwIQYDVQQKDBpBY3RhbGlzIFMucC5BLi8wMzM1ODUyMDk2NzEnMCUGA1UE
AwweQWN0YWxpcyBBdXRoZW50aWNhdGlvbiBSb290IENBMB4XDTExMDkyMjExMjIwMloXDTMwMDky
MjExMjIwMlowazELMAkGA1UEBhMCSVQxDjAMBgNVBAcMBU1pbGFuMSMwIQYDVQQKDBpBY3RhbGlz
IFMucC5BLi8wMzM1ODUyMDk2NzEnMCUGA1UEAwweQWN0YWxpcyBBdXRoZW50aWNhdGlvbiBSb290
IENBMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAp8bEpSmkLO/lGMWwUKNvUTufClrJ
wkg4CsIcoBh/kbWHuUA/3R1oHwiD1S0eiKD4j1aPbZkCkpAW1V8IbInX4ay8IMKx4INRimlNAJZa
by/ARH6jDuSRzVju3PvHHkVH3Se5CAGfpiEd9UEtL0z9KK3giq0itFZljoZUj5NDKd45RnijMCO6
zfB9E1fAXdKDa0hMxKufgFpbOr3JpyI/gCczWw63igxdBzcIy2zSekciRDXFzMwujt0q7bd9Zg1f
YVEiVRvjRuPjPdA1YprbrxTIW6HMiRvhMCb8oJsfgadHHwTrozmSBp+Z07/T6k9QnBn+locePGX2
oxgkg4YQ51Q+qDp2JE+BIcXjDwL4k5RHILv+1A7TaLndxHqEguNTVHnd25zS8gebLra8Pu2Fbe8l
EfKXGkJh90qX6IuxEAf6ZYGyojnP9zz/GPvG8VqLWeICrHuS0E4UT1lF9gxeKF+w6D9Fz8+vm2/7
hNN3WpVvr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cZEf1T1o+CP8HxVIo8ptoGj4W1OLBuAZ+ytIJ8MYmHV
l/9D7S3B2l0pKoU/rGXuhg8FjZBf3+6f9L/uHfuY5H+QK4R4EA5sSVPvFVtlRkpdr7r7OnIdzfYl
iB6XzCGcKQENZetX2fNXlrtIzYE=
-----END CERTIFICATE-----

StartCom Certification Authority
================================
-----BEGIN CERTIFICATE-----
MIIHhzCCBW+gAwIBAgIBLTANBgkqhkiG9w0BAQsFADB9MQswCQYDVQQGEwJJTDEWMBQGA1UEChMN
U3RhcnRDb20gTHRkLjErMCkGA1UECxMiU2VjdXJlIERpZ2l0YWwgQ2VydGlmaWNhdGUgU2lnbmlu
ZzEpMCcGA1UEAxMgU3RhcnRDb20gQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMDYwOTE3MTk0
NjM3WhcNMzYwOTE3MTk0NjM2WjB9MQswCQYDVQQGEwJJTDEWMBQGA1UEChMNU3RhcnRDb20gTHRk
LjErMCkGA1UECxMiU2VjdXJlIERpZ2l0YWwgQ2VydGlmaWNhdGUgU2lnbmluZzEpMCcGA1UEAxMg
U3RhcnRDb20gQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAw
ggIKAoICAQDBiNsJvGxGfHiflXu1M5DycmLWwTYgIiRezul38kMKogZkpMyONvg45iPwbm2xPN1y
o4UcodM9tDMr0y+v/uqwQVlntsQGfQqedIXWeUyAN3rfOQVSWff0G0ZDpNKFhdLDcfN1YjS6LIp/
Ho/u7TTQEceWzVI9ujPW3U3eCztKS5/CJi/6tRYccjV3yjxd5srhJosaNnZcAdt0FCX+7bWgiA/d
eMotHweXMAEtcnn6RtYTKqi5pquDSR3l8u/d5AGOGAqPY1MWhWKpDhk6zLVmpsJrdAfkK+F2PrRt
2PZE4XNiHzvEvqBTViVsUQn3qqvKv3b9bZvzndu/PWa8DFaqr5hIlTpL36dYUNk4dalb6kMMAv+Z
6+hsTXBbKWWc3apdzK8BM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R5
fPGFf59Jb2vKXfuM/gTFwWLRfUKKvFO3lANmMD+x5wqnUCBVJX92ehQN6wQOQOY+2IirByeDqXWm
N3PH/UvSTa0XQMhGvjt/UfzDtgUx3M2FIk5xt/JxXrAaxrqTi3iSSoX4eA+D/i+tLPfkpLst0OcN
Org+zvZ49q5HJMqjNTbOx8aHmNrs++myziebiMMEofYLWWivydsQD032ZGNcpRJvkrKTlMeIFw6T
tn5ii5B/q06f/ON1FE8qMt9bDeD1e5MNq6HPh+GlBEXoPBKlCcWw0bdT82AUuoVpaiF8H3VhFyAX
e2w7QSlc4axa0c2Mm+tgHRns9+Ww2vl5GKVFP0lDV9LdJNUso/2RjSe15esUBppMeyG7Oq0wBhjA
2MFrLH9ZXF2RsXAiV+uKa0hK1Q8p7MZAwC+ITGgBF3f0JBlPvfrhsiAhS90a2Cl9qrjeVOwhVYBs
HvUwyKMQ5bLmKhQxw4UtjJixhlpPiVktucf3HMiKf8CdBUrmQk9io20ppB+Fq9vlgcitKj1MXVuE
JnHEhV5xJMqlG2zYYdMa4FTbzrqpMrUi9nNBCV24F10OD5mQ1kfabwo6YigUZ4LZ8dCAWZvLMdib
D4x3TrVoivJs9iQOLWxwxXPR3hTQcY+203sC9uO41Alua551hDnmfyWl8kgAwKQB2j8=
-----END CERTIFICATE-----

StartCom Certification Authority G2
===================================
-----BEGIN CERTIFICATE-----
MIIFYzCCA0ugAwIBAgIBOzANBgkqhkiG9w0BAQsFADBTMQswCQYDVQQGEwJJTDEWMBQGA1UEChMN
U3RhcnRDb20gTHRkLjEsMCoGA1UEAxMjU3RhcnRDb20gQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkg
RzIwHhcNMTAwMTAxMDEwMDAxWhcNMzkxMjMxMjM1OTAxWjBTMQswCQYDVQQGEwJJTDEWMBQGA1UE
ChMNU3RhcnRDb20gTHRkLjEsMCoGA1UEAxMjU3RhcnRDb20gQ2VydGlmaWNhdGlvbiBBdXRob3Jp
dHkgRzIwggIiMA0GCSqG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QFesa1lQ2aOZ4W7+jQF5JyMV3pKdewlNWudLSDBaGOYKbeaP4NK75t98biGC
wWg5TbSYWGZizEqQXsP6JwSxeRV0mcy+rSDeJmAc61ZRpqPq5KM/p/9h3PFaTWwyI0PurKju7koS
CTxdccK+efrCh2gdC/1cacwG0Jp9VJkqyTkaGa9LKkPzY11aWOIv4x3kqdbQCtCev9eBCfHJxyYN
rJgWVqA=
-----END CERTIFICATE-----

Buypass Class 3 Root CA
=======================
-----BEGIN CERTIFICATE-----
MIIFWTCCA0GgAwIBAgIBAjANBgkqhkiG9w0BAQsFADBOMQswCQYDVQQGEwJOTzEdMBsGA1UECgwU
QnV5cGFzcyBBUy05ODMxNjMzMjcxIDAeBgNVBAMMF0J1eXBhc3MgQ2xhc3MgMyBSb290IENBMB4X
DTEwMTAyNjA4Mjg1OFoXDTQwMTAyNjA4Mjg1OFowTjELMAkGA1UEBhMCTk8xHTAbBgNVBAoMFEJ1
eXBhc3MgQVMtOTgzMTYzMzI3MSAwHgYDVQQDDBdCdXlwYXNzIENsYXNzIDMgUm9vdCBDQTCCAiIw
DQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAKXaCpUWUOOV8l6ddjEGMnqb8RB2uACatVI2zSRH
sJ8YZLya9vrVediQYkwiL944PdbgqOkcLNt4EemOaFEVcsfzM4fkoF0LXOBXByow9c3EN3coTRiR
5r/VUv1xLXA+58bEiuPwKAv0dpihi4dVsjoT/Lc+JzeOIuOoTyrvYLs9tznDDgFHmV0ST9tD+leh
7fmdvhFHJlsTmKtdFoqwNxxXnUX/iJY2v7vKB3tvh2PX0DJq1l1sDPGzbjniazEuOQAnFN44wOwZ
ZoYS6J1yFhNkUsepNxz9gjDthBgd9K5c/3ATAOux9TN6S9ZV+AWNS2mw9bMoNlwUxFFzTWsL8TQH
2xc519woe2v1n/MuwU8XKhDzzMro6/1rqy6any2CbgTUUgGTLT2G/H783+9CHaZr77kgxve9oKeV
/afmiSTYzIw0bOIjL9kSGiG5VZFvC5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J85cp4IaH3gRZD/FZ1GSFS5mvJQQeyUapl96Cshtwn5z2r3Ex3XsFpSzT
ucpH9sry9uetuUg/vBa3wW306gmv7PO15wWeph6KU1HWk4HMdJP2udqmJQV0eVp+QD6CSyYRMG7h
P0HHRwA11fXT91Q+gT3aSWqas+8QPebrb9HIIkfLzM8BMZLZGOMivgkeGj5asuRrDFR6fUNOuIml
e9eiPZaGzPImNC1qkp2aGtAw4l1OBLBfiyB+d8E9lYLRRpo7PHi4b6HQDWSieB4pTpPDpFQUWw==
-----END CERTIFICATE-----

EE Certification Centre Root CA
===============================
-----BEGIN CERTIFICATE-----
MIIEAzCCAuugAwIBAgIQVID5oHPtPwBMyonY43HmSjANBgkqhkiG9w0BAQUFADB1MQswCQYDVQQG
EwJFRTEiMCAGA1UECgwZQVMgU2VydGlmaXRzZWVyaW1pc2tlc2t1czEoMCYGA1UEAwwfRUUgQ2Vy
dGlmaWNhdGlvbiBDZW50cmUgUm9vdCBDQTEYMBYGCSqGSIb3DQEJARYJcGtpQHNrLmVlMCIYDzIw
MTAxMDMwMTAxMDMwWhgPMjAzMDEyMTcyMzU5NTlaMHUxCzAJBgNVBAYTAkVFMSIwIAYDVQQKDBlB
UyBTZXJ0aWZpdHNlZXJpbWlza2Vza3VzMSgwJgYDVQQDDB9FRSBDZXJ0aWZpY2F0aW9uIENlbnRy
ZSBSb290IENBMRgwFgYJKoZIhvcNAQkBFglwa2lAc2suZWUwggEiMA0GCSqGSIb3DQEBAQUAA4IB
DwAwggEKAoIBAQDIIMDs4MVLqwd4lfNE7vsLDP90jmG7sWLqI9iroWUyeuuOF0+W2Ap7kaJjbMeM
TC55v6kF/GlclY1i+blw7cNRfdCT5mzrMEvhvH2/UpvObntl8jixwKIy72KyaOBhU8E2lf/slLo2
rpwcpzIP5Xy0xm90/XsY6KxX7QYgSzIwWFv9zajmofxwvI6Sc9uXp3whrj3B9UiHbCe9nyV0gVWw
93X2PaRka9ZP585ArQ/dMtO8ihJTmMmJ+xAdTX7Nfh9WDSFwhfYggx/2uh8Ej+p3iDXE/+pOoYtN
P2MbRMNE1CV2yreN1x5KZmTNXMWcg+HCCIia7E6j8T4cLNlsHaFLAgMBAAGjgYowgYcwDwYDVR0T
AQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFBLyWj7qVhy/zQas8fElyalL1BSZ
MEUGA1UdJQQ+MDwGCCsGAQUFBwMCBggrBgEFBQcDAQYIKwYBBQUHAwMGCCsGAQUFBwMEBggrBgEF
BQcDCAYIKwYBBQUHAwkwDQYJKoZIhvcNAQEFBQADggEBAHv25MANqhlHt01Xo/6tu7Fq1Q+e2+Rj
xY6hUFaTlrg4wCQiZrxTFGGVv9DHKpY5P30osxBAIWrEr7BSdxjhlthWXePdNl4dp1BUoMUq5KqM
lIpPnTX/dqQGE5Gion0ARD9V04I8GtVbvFZMIi5GQ4okQC3zErg7cBqklrkar4dBGmoYDQZPxz5u
uSlNDUmJEYcyW+ZLBMjkXOZ0c5RdFpgTlf7727FE5TpwrDdr5rMzcijJs1eg9gIWiAYLtqZLICjU
3j2LrTcFU3T+bsy8QxdxXvnFzBqpYe73dgzzcvRyrc9yAjYHR8/vGVCJYMzpJJUPwssd8m92kMfM
dcGWxZ0=
-----END CERTIFICATE-----

TURKTRUST Certificate Services Provider Root 2007
=================================================
-----BEGIN CERTIFICATE-----
MIIEPTCCAyWgAwIBAgIBATANBgkqhkiG9w0BAQUFADCBvzE/MD0GA1UEAww2VMOcUktUUlVTVCBF
bGVrdHJvbmlrIFNlcnRpZmlrYSBIaXptZXQgU2HEn2xhecSxY8Sxc8SxMQswCQYDVQQGEwJUUjEP
MA0GA1UEBwwGQW5rYXJhMV4wXAYDVQQKDFVUw5xSS1RSVVNUIEJpbGdpIMSwbGV0acWfaW0gdmUg
QmlsacWfaW0gR8O8dmVubGnEn2kgSGl6bWV0bGVyaSBBLsWeLiAoYykgQXJhbMSxayAyMDA3MB4X
DTA3MTIyNTE4MzcxOVoXDT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Wo9F7/snXUMrqNvWtMvmDb08PUZqxFdyKbjKlhqQgnDvZImZjINXQhVdP+MmNAK
poRq0Tl9
-----END CERTIFICATE-----

D-TRUST Root Class 3 CA 2 2009
==============================
-----BEGIN CERTIFICATE-----
MIIEMzCCAxugAwIBAgIDCYPzMA0GCSqGSIb3DQEBCwUAME0xCzAJBgNVBAYTAkRFMRUwEwYDVQQK
DAxELVRydXN0IEdtYkgxJzAlBgNVBAMMHkQtVFJVU1QgUm9vdCBDbGFzcyAzIENBIDIgMjAwOTAe
Fw0wOTExMDUwODM1NThaFw0yOTExMDUwODM1NThaME0xCzAJBgNVBAYTAkRFMRUwEwYDVQQKDAxE
LVRydXN0IEdtYkgxJzAlBgNVBAMMHkQtVFJVU1QgUm9vdCBDbGFzcyAzIENBIDIgMjAwOTCCASIw
DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANOySs96R+91myP6Oi/WUEWJNTrGa9v+2wBoqOAD
ER03UAifTUpolDWzU9GUY6cgVq/eUXjsKj3zSEhQPgrfRlWLJ23DEE0NkVJD2IfgXU42tSHKXzlA
BF9bfsyjxiupQB7ZNoTWSPOSHjRGICTBpFGOShrvUD9pXRl/RcPHAY9RySPocq60vFYJfxLLHLGv
KZAKyVXMD9O0Gu1HNVpK7ZxzBCHQqr0ME7UAyiZsxGsMlFqVlNpQmvH/pStmMaTJOKDfHR+4CS7z
p+hnUquVH+BGPtikw8paxTGA6Eian5Rp/hnd2HN8gcqW3o7tszIFZYQ05ub9VxC1X3a/L7AQDcUC
AwEAAaOCARowggEWMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFP3aFMSfMN4hvR5COfyrYyNJ
4PGEMA4GA1UdDwEB/wQEAwIBBjCB0wYDVR0fBIHLMIHIMIGAoH6gfIZ6bGRhcDovL2RpcmVjdG9y
eS5kLXRydXN0Lm5ldC9DTj1ELVRSVVNUJTIwUm9vdCUyMENsYXNzJTIwMyUyMENBJTIwMiUyMDIw
MDksTz1ELVRydXN0JTIwR21iSCxDPURFP2NlcnRpZmljYXRlcmV2b2NhdGlvbmxpc3QwQ6BBoD+G
PWh0dHA6Ly93d3cuZC10cnVzdC5uZXQvY3JsL2QtdHJ1c3Rfcm9vdF9jbGFzc18zX2NhXzJfMjAw
OS5jcmwwDQYJKoZIhvcNAQELBQADggEBAH+X2zDI36ScfSF6gHDOFBJpiBSVYEQBrLLpME+bUMJm
2H6NMLVwMeniacfzcNsgFYbQDfC+rAF1hM5+n02/t2A7nPPKHeJeaNijnZflQGDSNiH+0LS4F9p0
o3/U37CYAqxva2ssJSRyoWXuJVrl5jLn8t+rSfrzkGkj2wTZ51xY/GXUl77M/C4KzCUqNQT4YJEV
dT1B/yMfGchs64JTBKbkTCJNjYy6zltz7GRUUG3RnFX7acM2w4y8PIWmawomDeCTmGCufsYkl4ph
X5GOZpIJhzbNi5stPvZR1FDUWSi9g/LMKHtThm3YJohw1+qRzT65ysCQblrGXnRl11z+o+I=
-----END CERTIFICATE-----

D-TRUST Root Class 3 CA 2 EV 2009
=================================
-----BEGIN CERTIFICATE-----
MIIEQzCCAyugAwIBAgIDCYP0MA0GCSqGSIb3DQEBCwUAMFAxCzAJBgNVBAYTAkRFMRUwEwYDVQQK
DAxELVRydXN0IEdtYkgxKjAoBgNVBAMMIUQtVFJVU1QgUm9vdCBDbGFzcyAzIENBIDIgRVYgMjAw
OTAeFw0wOTExMDUwODUwNDZaFw0yOTExMDUwODUwNDZaMFAxCzAJBgNVBAYTAkRFMRUwEwYDVQQK
DAxELVRydXN0IEdtYkgxKjAoBgNVBAMMIUQtVFJVU1QgUm9vdCBDbGFzcyAzIENBIDIgRVYgMjAw
OTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJnxhDRwui+3MKCOvXwEz75ivJn9gpfS
egpnljgJ9hBOlSJzmY3aFS3nBfwZcyK3jpgAvDw9rKFs+9Z5JUut8Mxk2og+KbgPCdM03TP1YtHh
zRnp7hhPTFiu4h7WDFsVWtg6uMQYZB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OWj3Y
eMLEYC/HYvBhkdI4sPaeVdtAgAUSM84dkpvRabP/v/GSCmE1P93+hvS84Bpxs2Km
-----END CERTIFICATE-----

China Internet Network Information Center EV Certificates Root
==============================================================
-----BEGIN CERTIFICATE-----
MIID9zCCAt+gAwIBAgIESJ8AATANBgkqhkiG9w0BAQUFADCBijELMAkGA1UEBhMCQ04xMjAwBgNV
BAoMKUNoaW5hIEludGVybmV0IE5ldHdvcmsgSW5mb3JtYXRpb24gQ2VudGVyMUcwRQYDVQQDDD5D
aGluYSBJbnRlcm5ldCBOZXR3b3JrIEluZm9ybWF0aW9uIENlbnRlciBFViBDZXJ0aWZpY2F0ZXMg
Um9vdDAeFw0xMDA4MzEwNzExMjVaFw0zMDA4MzEwNzExMjVaMIGKMQswCQYDVQQGEwJDTjEyMDAG
A1UECgwpQ2hpbmEgSW50ZXJuZXQgTmV0d29yayBJbmZvcm1hdGlvbiBDZW50ZXIxRzBFBgNVBAMM
PkNoaW5hIEludGVybmV0IE5ldHdvcmsgSW5mb3JtYXRpb24gQ2VudGVyIEVWIENlcnRpZmljYXRl
cyBSb290MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAm35z7r07eKpkQ0H1UN+U8i6y
jUqORlTSIRLIOTJCBumD1Z9S7eVnAztUwYyZmczpwA//DdmEEbK40ctb3B75aDFk4Zv6dOtouSCV
98YPjUesWgbdYavi7NifFy2cyjw1l1VxzUOFsUcW9SxTgHbP0wBkvUCZ3czY28Sf1hNfQYOL+Q2H
klY0bBoQCxfVWhyXWIQ8hBouXJE0bhlffxdpxWXvayHG1VA6v2G5BY3vbzQ6sm8UY78WO5upKv23
KzhmBsUs4qpnHkWnjQRmQvaPK++IIGmPMowUc9orhpFjIpryp9vOiYurXccUwVswah+xt54ugQEC
7c+WXmPbqOY4twIDAQABo2MwYTAfBgNVHSMEGDAWgBR8cks5x8DbYqVPm6oYNJKiyoOCWTAPBgNV
HRMBAf8EBTADAQH/MA4GA1UdDwEB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XZZNp1D5SDgPTJghSJRt8czu90VL6R4pgd7
gUY2BIbdeTXHlSw7sKMXNeVzH7RcWe/a6hBle3rQf5+ztCo3O3CLm1u5K7fsslESl1MpWtTwEhDc
TwK7EpIvYtQ/aUN8Ddb8WHUBiJ1YFkveupD/RwGJBmr2X7KQarMCpgKIv7NHfirZ1fpoeDVNAgMB
AAGjPzA9MA8GA1UdEwEB/wQFMAMBAf8wCwYDVR0PBAQDAgEGMB0GA1UdDgQWBBTwj1k4ALP1j5qW
DNXr+nuqF+gTEjANBgkqhkiG9w0BAQUFAAOCAgEAvuRcYk4k9AwI//DTDGjkk0kiP0Qnb7tt3oNm
zqjMDfz1mgbldxSR651Be5kqhOX//CHBXfDkH1e3damhXwIm/9fH907eT/j3HEbAek9ALCI18Bmx
0GtnLLCo4MBANzX2hFxc469CeP6nyQ1Q6g2EdvZR74NTxnr/DlZJLo961gzmJ1TjTQpgcmLNkQfW
pb/ImWvtxBnmq0wROMVvMeJuScg/doAmAyYp4Db29iBT4xdwNBedY2gea+zDTYa4EzAvXUYNR0PV
G6pZDrlcjQZIrXSHX8f8MVRBE+LHIQ6e4B4N4cB7Q4WQxYpYxmUKeFfyxiMPAdkgS94P+5KFdSpc
c41teyWRyu5FrgZLAMzTsVlQ2jqIOylDRl6XK1TOU2+NSueW+r9xDkKLfP0ooNBIytrEgUy7onOT
JsjrDNYmiLbAJM+7vVvrdX3pCI6GMyx5dwlppYn8s3CQh3aP0yK7Qs69cwsgJirQmz1wHiRszYd2
qReWt88NkvuOGKmYSdGe/mBEciG5Ge3C9THxOUiIkCR1VBatzvT4aRRkOfujuLpwQMcnHL/EVlP6
Y2XQ8xwOFvVrhlhNGNTkDY6lnVuR3HYkUD/GKvvZt5y11ubQ2egZixVxSK236thZiNSQvxaz2ems
WWFUyBy6ysHK4bkgTI86k4mloMy/0/Z1pHWWbVY=
-----END CERTIFICATE-----

E-Tugra Certification Authority
===============================
-----BEGIN CERTIFICATE-----
MIIGSzCCBDOgAwIB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fdOhyNsZt+U2e+iKo4YFWz827n+qrkRk4
r6p8FU3ztqONpfSO9kSpp+ghla0+AGIWiPACuvxhI+YzmzB6azZie60EI4RYZeLbK4rnJVM3YlNf
vNoBYimipidx5joifsFvHZVwIEoHNN/q/xWA5brXethbdXwFeilHfkCoMRN3zUA7tFFHei4R40cR
3p1m0IvVVGb6g1XqfMIpiRvpb7PO4gWEyS8+eIVibslfwXhjdFjASBgMmTnrpMwatXlajRWc2BQN
9noHV8cigwUtPJslJj0Ys6lDfMjIq2SPDqO/nBudMNva0Bkuqjzx+zOAduTNrRlPBSeOE6Fuwg==
-----END CERTIFICATE-----

Atos TrustedRoot 2011
=====================
-----BEGIN CERTIFICATE-----
MIIDdzCCAl+gAwIBAgIIXDPLYixfszIwDQYJKoZIhvcNAQELBQAwPDEeMBwGA1UEAwwVQXRvcyBU
cnVzdGVkUm9vdCAyMDExMQ0wCwYDVQQKDARBdG9zMQswCQYDVQQGEwJERTAeFw0xMTA3MDcxNDU4
MzBaFw0zMDEyMzEyMzU5NTlaMDwxHjAcBgNVBAMMFUF0b3MgVHJ1c3RlZFJvb3QgMjAxMTENMAsG
A1UECgwEQXRvczELMAkGA1UEBhMCREUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCV
hTuXbyo7LjvPpvMpNb7PGKw+qtn4TaA+Gke5vJrf8v7MPkfoepbCJI419KkM/IL9bcFyYie96mvr
54rMVD6QUM+A1JX76LWC1BTFtqlVJVfbsVD2sGBkWXppzwO3bw2+yj5vdHLqqjAqc2K+SZFhyBH+
DgMq92og3AIVDV4VavzjgsG1xZ1kCWyjWZgHJ8cblithdHFsQ/H3NYkQ4J7sVaE3IqKHBAUsR320
HLliKWYoyrfhk/WklAOZuXCFteZI6o1Q/NnezG8HDt0Lcp2AMBYHlT8oDv3FdU9T1nSatCQujgKR
z3bFmx5VdJx4IbHwLfELn8LVlhgf8FQieowHAgMBAAGjfTB7MB0GA1UdDgQWBBSnpQaxLKYJYO7R
l+lwrrw7GWzbITAPBgNVHRMBAf8EBTADAQH/MB8GA1UdIwQYMBaAFKelBrEspglg7tGX6XCuvDsZ
bNshMBgGA1UdIAQRMA8wDQYLKwYBBAGwLQMEAQEwDgYDVR0PAQH/BAQDAgGGMA0GCSqGSIb3DQEB
CwUAA4IBAQAmdzTblEiGKkGdLD4GkGDEjKwLVLgfuXvTBznk+j57sj1O7Z8jvZfza1zv7v1Apt+h
k6EKhqzvINB5Ab149xnYJDE0BAGmuhWawyfc2E8PzBhj/5kPDpFrdRbhIfzYJsdHt6bPWHJxfrrh
TZVHO8mvbaG0weyJ9rQPOLXiZNwlz6bb65pcmaHFCN795trV1lpFDMS3wrUU77QR/w4VtfX128a9
61qn8FYiqTxlVMYVqL2Gns2Dlmh6cYGJ4Qvh6hEbaAjMaZ7snkGeRDImeuKHCnE96+RapNLbxc3G
3mB/ufNPRJLvKrcYPqcZ2Qt9sTdBQrC6YB3y/gkRsPCHe6ed
-----END CERTIFICATE-----

<?php

namespace Guzzle\Http\QueryAggregator;

use Guzzle\Http\QueryString;

/**
 * Aggregates nested query string variables using commas
 */
class CommaAggregator implements QueryAggregatorInterface
{
    public function aggregate($key, $value, QueryString $query)
    {
        if ($query->isUrlEncoding()) {
            return array($query->encodeValue($key) => implode(',', array_map(array($query, 'encodeValue'), $value)));
        } else {
            return array($key => implode(',', $value));
        }
    }
}
<?php

namespace Guzzle\Http\QueryAggregator;

use Guzzle\Http\QueryString;

/**
 * Interface used for aggregating nested query string variables into a flattened array of key value pairs
 */
interface QueryAggregatorInterface
{
    /**
     * Aggregate multi-valued parameters into a flattened associative array
     *
     * @param string      $key   The name of the query string parameter
     * @param array       $value The values of the parameter
     * @param QueryString $query The query string that is being aggregated
     *
     * @return array Returns an array of the combined values
     */
    public function aggregate($key, $value, QueryString $query);
}
<?php

namespace Guzzle\Http\QueryAggregator;

use Guzzle\Http\QueryString;

/**
 * Aggregates nested query string variables using PHP style []
 */
class PhpAggregator implements QueryAggregatorInterface
{
    public function aggregate($key, $value, QueryString $query)
    {
        $ret = array();

        foreach ($value as $k => $v) {
            $k = "{$key}[{$k}]";
            if (is_array($v)) {
                $ret = array_merge($ret, self::aggregate($k, $v, $query));
            } else {
                $ret[$query->encodeValue($k)] = $query->encodeValue($v);
            }
        }

        return $ret;
    }
}
<?php

namespace Guzzle\Http\QueryAggregator;

use Guzzle\Http\QueryString;

/**
 * Does not aggregate nested query string values and allows duplicates in the resulting array
 *
 * Example: http://test.com?q=1&q=2
 */
class DuplicateAggregator implements QueryAggregatorInterface
{
    public function aggregate($key, $value, QueryString $query)
    {
        if ($query->isUrlEncoding()) {
            return array($query->encodeValue($key) => array_map(array($query, 'encodeValue'), $value));
        } else {
            return array($key => $value);
        }
    }
}
<?php

namespace Guzzle\Http\Exception;

use Guzzle\Http\Curl\CurlHandle;

/**
 * cURL request exception
 */
class CurlException extends RequestException
{
    private $curlError;
    private $curlErrorNo;
    private $handle;
    private $curlInfo = array();

    /**
     * Set the cURL error message
     *
     * @param string $error  Curl error
     * @param int    $number Curl error number
     *
     * @return self
     */
    public function setError($error, $number)
    {
        $this->curlError = $error;
        $this->curlErrorNo = $number;

        return $this;
    }

    /**
     * Set the associated curl handle
     *
     * @param CurlHandle $handle Curl handle
     *
     * @return self
     */
    public function setCurlHandle(CurlHandle $handle)
    {
        $this->handle = $handle;

        return $this;
    }

    /**
     * Get the associated cURL handle
     *
     * @return CurlHandle|null
     */
    public function getCurlHandle()
    {
        return $this->handle;
    }

    /**
     * Get the associated cURL error message
     *
     * @return string|null
     */
    public function getError()
    {
        return $this->curlError;
    }

    /**
     * Get the associated cURL error number
     *
     * @return int|null
     */
    public function getErrorNo()
    {
        return $this->curlErrorNo;
    }

    /**
     * Returns curl information about the transfer
     *
     * @return array
     */
    public function getCurlInfo()
    {
        return $this->curlInfo;
    }

    /**
     * Set curl transfer information
     *
     * @param array $info Array of curl transfer information
     *
     * @return self
     * @link http://php.net/manual/en/function.curl-getinfo.php
     */
    public function setCurlInfo(array $info)
    {
        $this->curlInfo = $info;

        return $this;
    }
}
<?php

namespace Guzzle\Http\Exception;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\Response;

/**
 * Http request exception thrown when a bad response is received
 */
class BadResponseException extends RequestException
{
    /** @var Response */
    private $response;

    /**
     * Factory method to create a new response exception based on the response code.
     *
     * @param RequestInterface $request  Request
     * @param Response         $response Response received
     *
     * @return BadResponseException
     */
    public static function factory(RequestInterface $request, Response $response)
    {
        if ($response->isClientError()) {
            $label = 'Client error response';
            $class = __NAMESPACE__ . '\\ClientErrorResponseException';
        } elseif ($response->isServerError()) {
            $label = 'Server error response';
            $class = __NAMESPACE__ . '\\ServerErrorResponseException';
        } else {
            $label = 'Unsuccessful response';
            $class = __CLASS__;
        }

        $message = $label . PHP_EOL . implode(PHP_EOL, array(
            '[status code] ' . $response->getStatusCode(),
            '[reason phrase] ' . $response->getReasonPhrase(),
            '[url] ' . $request->getUrl(),
        ));

        $e = new $class($message);
        $e->setResponse($response);
        $e->setRequest($request);

        return $e;
    }

    /**
     * Set the response that caused the exception
     *
     * @param Response $response Response to set
     */
    public function setResponse(Response $response)
    {
        $this->response = $response;
    }

    /**
     * Get the response that caused the exception
     *
     * @return Response
     */
    public function getResponse()
    {
        return $this->response;
    }
}
<?php

namespace Guzzle\Http\Exception;

use Guzzle\Common\Exception\GuzzleException;

/**
 * Http exception interface
 */
interface HttpException extends GuzzleException {}
<?php

namespace Guzzle\Http\Exception;

/**
 * Exception when a server error is encountered (5xx codes)
 */
class ServerErrorResponseException extends BadResponseException {}
<?php

namespace Guzzle\Http\Exception;

use Guzzle\Common\Exception\ExceptionCollection;
use Guzzle\Http\Message\RequestInterface;

/**
 * Exception encountered during a multi transfer
 */
class MultiTransferException extends ExceptionCollection
{
    protected $successfulRequests = array();
    protected $failedRequests = array();
    protected $exceptionForRequest = array();

    /**
     * Get all of the requests in the transfer
     *
     * @return array
     */
    public function getAllRequests()
    {
        return array_merge($this->successfulRequests, $this->failedRequests);
    }

    /**
     * Add to the array of successful requests
     *
     * @param RequestInterface $request Successful request
     *
     * @return self
     */
    public function addSuccessfulRequest(RequestInterface $request)
    {
        $this->successfulRequests[] = $request;

        return $this;
    }

    /**
     * Add to the array of failed requests
     *
     * @param RequestInterface $request Failed request
     *
     * @return self
     */
    public function addFailedRequest(RequestInterface $request)
    {
        $this->failedRequests[] = $request;

        return $this;
    }

    /**
     * Add to the array of failed requests and associate with exceptions
     *
     * @param RequestInterface $request   Failed request
     * @param \Exception       $exception Exception to add and associate with
     *
     * @return self
     */
    public function addFailedRequestWithException(RequestInterface $request, \Exception $exception)
    {
        $this->add($exception)
             ->addFailedRequest($request)
             ->exceptionForRequest[spl_object_hash($request)] = $exception;

        return $this;
    }

    /**
     * Get the Exception that caused the given $request to fail
     *
     * @param RequestInterface $request Failed command
     *
     * @return \Exception|null
     */
    public function getExceptionForFailedRequest(RequestInterface $request)
    {
        $oid = spl_object_hash($request);

        return isset($this->exceptionForRequest[$oid]) ? $this->exceptionForRequest[$oid] : null;
    }

    /**
     * Set all of the successful requests
     *
     * @param array Array of requests
     *
     * @return self
     */
    public function setSuccessfulRequests(array $requests)
    {
        $this->successfulRequests = $requests;

        return $this;
    }

    /**
     * Set all of the failed requests
     *
     * @param array Array of requests
     *
     * @return self
     */
    public function setFailedRequests(array $requests)
    {
        $this->failedRequests = $requests;

        return $this;
    }

    /**
     * Get an array of successful requests sent in the multi transfer
     *
     * @return array
     */
    public function getSuccessfulRequests()
    {
        return $this->successfulRequests;
    }

    /**
     * Get an array of failed requests sent in the multi transfer
     *
     * @return array
     */
    public function getFailedRequests()
    {
        return $this->failedRequests;
    }

    /**
     * Check if the exception object contains a request
     *
     * @param RequestInterface $request Request to check
     *
     * @return bool
     */
    public function containsRequest(RequestInterface $request)
    {
        return in_array($request, $this->failedRequests, true) || in_array($request, $this->successfulRequests, true);
    }
}
<?php

namespace Guzzle\Http\Exception;

use Guzzle\Common\Exception\RuntimeException;
use Guzzle\Http\Message\RequestInterface;

/**
 * Http request exception
 */
class RequestException extends RuntimeException implements HttpException
{
    /** @var RequestInterface */
    protected $request;

    /**
     * Set the request that caused the exception
     *
     * @param RequestInterface $request Request to set
     *
     * @return RequestException
     */
    public function setRequest(RequestInterface $request)
    {
        $this->request = $request;

        return $this;
    }

    /**
     * Get the request that caused the exception
     *
     * @return RequestInterface
     */
    public function getRequest()
    {
        return $this->request;
    }
}
<?php

namespace Guzzle\Http\Exception;

class TooManyRedirectsException extends BadResponseException {}
<?php

namespace Guzzle\Http\Exception;

/**
 * Exception when a client error is encountered (4xx codes)
 */
class ClientErrorResponseException extends BadResponseException {}
<?php

namespace Guzzle\Http\Exception;

use Guzzle\Common\Exception\RuntimeException;

class CouldNotRewindStreamException extends RuntimeException implements HttpException {}
{
    "name": "guzzle/http",
    "description": "HTTP libraries used by Guzzle",
    "homepage": "http://guzzlephp.org/",
    "keywords": ["http client", "http", "client", "Guzzle", "curl"],
    "license": "MIT",
    "authors": [
        {
            "name": "Michael Dowling",
            "email": "mtdowling@gmail.com",
            "homepage": "https://github.com/mtdowling"
        }
    ],
    "require": {
        "php": ">=5.3.2",
        "guzzle/common": "self.version",
        "guzzle/parser": "self.version",
        "guzzle/stream": "self.version"
    },
    "suggest": {
        "ext-curl": "*"
    },
    "autoload": {
        "psr-0": { "Guzzle\\Http": "" }
    },
    "target-dir": "Guzzle/Http",
    "extra": {
        "branch-alias": {
            "dev-master": "3.7-dev"
        }
    }
}
<?php

namespace Guzzle\Http;

use Guzzle\Common\Collection;
use Guzzle\Common\AbstractHasDispatcher;
use Guzzle\Common\Exception\ExceptionCollection;
use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Common\Exception\RuntimeException;
use Guzzle\Common\Version;
use Guzzle\Parser\ParserRegistry;
use Guzzle\Parser\UriTemplate\UriTemplateInterface;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\RequestFactory;
use Guzzle\Http\Message\RequestFactoryInterface;
use Guzzle\Http\Curl\CurlMultiInterface;
use Guzzle\Http\Curl\CurlMultiProxy;
use Guzzle\Http\Curl\CurlHandle;
use Guzzle\Http\Curl\CurlVersion;

/**
 * HTTP client
 */
class Client extends AbstractHasDispatcher implements ClientInterface
{
    /** @deprecated Use [request.options][params] */
    const REQUEST_PARAMS = 'request.params';

    const REQUEST_OPTIONS = 'request.options';
    const CURL_OPTIONS = 'curl.options';
    const SSL_CERT_AUTHORITY = 'ssl.certificate_authority';
    const DISABLE_REDIRECTS = RedirectPlugin::DISABLE;
    const DEFAULT_SELECT_TIMEOUT = 1.0;
    const MAX_HANDLES = 3;

    /** @var Collection Default HTTP headers to set on each request */
    protected $defaultHeaders;

    /** @var string The user agent string to set on each request */
    protected $userAgent;

    /** @var Collection Parameter object holding configuration data */
    private $config;

    /** @var Url Base URL of the client */
    private $baseUrl;

    /** @var CurlMultiInterface CurlMulti object used internally */
    private $curlMulti;

    /** @var UriTemplateInterface URI template owned by the client */
    private $uriTemplate;

    /** @var RequestFactoryInterface Request factory used by the client */
    protected $requestFactory;

    public static function getAllEvents()
    {
        return array(self::CREATE_REQUEST);
    }

    /**
     * @param string           $baseUrl Base URL of the web service
     * @param array|Collection $config  Configuration settings
     *
     * @throws RuntimeException if cURL is not installed
     */
    public function __construct($baseUrl = '', $config = null)
    {
        if (!extension_loaded('curl')) {
            // @codeCoverageIgnoreStart
            throw new RuntimeException('The PHP cURL extension must be installed to use Guzzle.');
            // @codeCoverageIgnoreEnd
        }
        $this->setConfig($config ?: new Collection());
        $this->initSsl();
        $this->setBaseUrl($baseUrl);
        $this->defaultHeaders = new Collection();
        $this->setRequestFactory(RequestFactory::getInstance());
        $this->userAgent = $this->getDefaultUserAgent();
        if (!$this->config[self::DISABLE_REDIRECTS]) {
            $this->addSubscriber(new RedirectPlugin());
        }
    }

    final public function setConfig($config)
    {
        if ($config instanceof Collection) {
            $this->config = $config;
        } elseif (is_array($config)) {
            $this->config = new Collection($config);
        } else {
            throw new InvalidArgumentException('Config must be an array or Collection');
        }

        return $this;
    }

    final public function getConfig($key = false)
    {
        return $key ? $this->config[$key] : $this->config;
    }

    /**
     * Set a default request option on the client that will be used as a default for each request
     *
     * @param string $keyOrPath request.options key (e.g. allow_redirects) or path to a nested key (e.g. headers/foo)
     * @param mixed  $value     Value to set
     *
     * @return $this
     */
    public function setDefaultOption($keyOrPath, $value)
    {
        $keyOrPath = self::REQUEST_OPTIONS . '/' . $keyOrPath;
        $this->config->setPath($keyOrPath, $value);

        return $this;
    }

    /**
     * Retrieve a default request option from the client
     *
     * @param string $keyOrPath request.options key (e.g. allow_redirects) or path to a nested key (e.g. headers/foo)
     *
     * @return mixed|null
     */
    public function getDefaultOption($keyOrPath)
    {
        $keyOrPath = self::REQUEST_OPTIONS . '/' . $keyOrPath;

        return $this->config->getPath($keyOrPath);
    }

    final public function setSslVerification($certificateAuthority = true, $verifyPeer = true, $verifyHost = 2)
    {
        $opts = $this->config[self::CURL_OPTIONS] ?: array();

        if ($certificateAuthority === true) {
            // use bundled CA bundle, set secure defaults
            $opts[CURLOPT_CAINFO] = __DIR__ . '/Resources/cacert.pem';
            $opts[CURLOPT_SSL_VERIFYPEER] = true;
            $opts[CURLOPT_SSL_VERIFYHOST] = 2;
        } elseif ($certificateAuthority === false) {
            unset($opts[CURLOPT_CAINFO]);
            $opts[CURLOPT_SSL_VERIFYPEER] = false;
            $opts[CURLOPT_SSL_VERIFYHOST] = 0;
        } elseif ($verifyPeer !== true && $verifyPeer !== false && $verifyPeer !== 1 && $verifyPeer !== 0) {
            throw new InvalidArgumentException('verifyPeer must be 1, 0 or boolean');
        } elseif ($verifyHost !== 0 && $verifyHost !== 1 && $verifyHost !== 2) {
            throw new InvalidArgumentException('verifyHost must be 0, 1 or 2');
        } else {
            $opts[CURLOPT_SSL_VERIFYPEER] = $verifyPeer;
            $opts[CURLOPT_SSL_VERIFYHOST] = $verifyHost;
            if (is_file($certificateAuthority)) {
                unset($opts[CURLOPT_CAPATH]);
                $opts[CURLOPT_CAINFO] = $certificateAuthority;
            } elseif (is_dir($certificateAuthority)) {
                unset($opts[CURLOPT_CAINFO]);
                $opts[CURLOPT_CAPATH] = $certificateAuthority;
            } else {
                throw new RuntimeException(
                    'Invalid option passed to ' . self::SSL_CERT_AUTHORITY . ': ' . $certificateAuthority
                );
            }
        }

        $this->config->set(self::CURL_OPTIONS, $opts);

        return $this;
    }

    public function createRequest($method = 'GET', $uri = null, $headers = null, $body = null, array $options = array())
    {
        if (!$uri) {
            $url = $this->getBaseUrl();
        } else {
            if (!is_array($uri)) {
                $templateVars = null;
            } else {
                list($uri, $templateVars) = $uri;
            }
            if (strpos($uri, '://')) {
                // Use absolute URLs as-is
                $url = $this->expandTemplate($uri, $templateVars);
            } else {
                $url = Url::factory($this->getBaseUrl())->combine($this->expandTemplate($uri, $templateVars));
            }
        }

        // If default headers are provided, then merge them under any explicitly provided headers for the request
        if (count($this->defaultHeaders)) {
            if (!$headers) {
                $headers = $this->defaultHeaders->toArray();
            } elseif (is_array($headers)) {
                $headers += $this->defaultHeaders->toArray();
            } elseif ($headers instanceof Collection) {
                $headers = $headers->toArray() + $this->defaultHeaders->toArray();
            }
        }

        return $this->prepareRequest($this->requestFactory->create($method, (string) $url, $headers, $body), $options);
    }

    public function getBaseUrl($expand = true)
    {
        return $expand ? $this->expandTemplate($this->baseUrl) : $this->baseUrl;
    }

    public function setBaseUrl($url)
    {
        $this->baseUrl = $url;

        return $this;
    }

    public function setUserAgent($userAgent, $includeDefault = false)
    {
        if ($includeDefault) {
            $userAgent .= ' ' . $this->getDefaultUserAgent();
        }
        $this->userAgent = $userAgent;

        return $this;
    }

    /**
     * Get the default User-Agent string to use with Guzzle
     *
     * @return string
     */
    public function getDefaultUserAgent()
    {
        return 'Guzzle/' . Version::VERSION
            . ' curl/' . CurlVersion::getInstance()->get('version')
            . ' PHP/' . PHP_VERSION;
    }

    public function get($uri = null, $headers = null, $options = array())
    {
        // BC compat: $options can be a string, resource, etc to specify where the response body is downloaded
        return is_array($options)
            ? $this->createRequest('GET', $uri, $headers, null, $options)
            : $this->createRequest('GET', $uri, $headers, $options);
    }

    public function head($uri = null, $headers = null, array $options = array())
    {
        return $this->createRequest('HEAD', $uri, $headers, null, $options);
    }

    public function delete($uri = null, $headers = null, $body = null, array $options = array())
    {
        return $this->createRequest('DELETE', $uri, $headers, $body, $options);
    }

    public function put($uri = null, $headers = null, $body = null, array $options = array())
    {
        return $this->createRequest('PUT', $uri, $headers, $body, $options);
    }

    public function patch($uri = null, $headers = null, $body = null, array $options = array())
    {
        return $this->createRequest('PATCH', $uri, $headers, $body, $options);
    }

    public function post($uri = null, $headers = null, $postBody = null, array $options = array())
    {
        return $this->createRequest('POST', $uri, $headers, $postBody, $options);
    }

    public function options($uri = null, array $options = array())
    {
        return $this->createRequest('OPTIONS', $uri, $options);
    }

    public function send($requests)
    {
        if (!($requests instanceof RequestInterface)) {
            return $this->sendMultiple($requests);
        }

        try {
            /** @var $requests RequestInterface  */
            $this->getCurlMulti()->add($requests)->send();
            return $requests->getResponse();
        } catch (ExceptionCollection $e) {
            throw $e->getFirst();
        }
    }

    /**
     * Set a curl multi object to be used internally by the client for transferring requests.
     *
     * @param CurlMultiInterface $curlMulti Multi object
     *
     * @return self
     */
    public function setCurlMulti(CurlMultiInterface $curlMulti)
    {
        $this->curlMulti = $curlMulti;

        return $this;
    }

    /**
     * @return CurlMultiInterface|CurlMultiProxy
     */
    public function getCurlMulti()
    {
        if (!$this->curlMulti) {
            $this->curlMulti = new CurlMultiProxy(
                self::MAX_HANDLES,
                $this->getConfig('select_timeout') ?: self::DEFAULT_SELECT_TIMEOUT
            );
        }

        return $this->curlMulti;
    }

    public function setRequestFactory(RequestFactoryInterface $factory)
    {
        $this->requestFactory = $factory;

        return $this;
    }

    /**
     * Set the URI template expander to use with the client
     *
     * @param UriTemplateInterface $uriTemplate URI template expander
     *
     * @return self
     */
    public function setUriTemplate(UriTemplateInterface $uriTemplate)
    {
        $this->uriTemplate = $uriTemplate;

        return $this;
    }

    /**
     * Expand a URI template while merging client config settings into the template variables
     *
     * @param string $template  Template to expand
     * @param array  $variables Variables to inject
     *
     * @return string
     */
    protected function expandTemplate($template, array $variables = null)
    {
        $expansionVars = $this->getConfig()->toArray();
        if ($variables) {
            $expansionVars = $variables + $expansionVars;
        }

        return $this->getUriTemplate()->expand($template, $expansionVars);
    }

    /**
     * Get the URI template expander used by the client
     *
     * @return UriTemplateInterface
     */
    protected function getUriTemplate()
    {
        if (!$this->uriTemplate) {
            $this->uriTemplate = ParserRegistry::getInstance()->getParser('uri_template');
        }

        return $this->uriTemplate;
    }

    /**
     * Send multiple requests in parallel
     *
     * @param array $requests Array of RequestInterface objects
     *
     * @return array Returns an array of Response objects
     */
    protected function sendMultiple(array $requests)
    {
        $curlMulti = $this->getCurlMulti();
        foreach ($requests as $request) {
            $curlMulti->add($request);
        }
        $curlMulti->send();

        /** @var $request RequestInterface */
        $result = array();
        foreach ($requests as $request) {
            $result[] = $request->getResponse();
        }

        return $result;
    }

    /**
     * Prepare a request to be sent from the Client by adding client specific behaviors and properties to the request.
     *
     * @param RequestInterface $request Request to prepare for the client
     * @param array            $options Options to apply to the request
     *
     * @return RequestInterface
     */
    protected function prepareRequest(RequestInterface $request, array $options = array())
    {
        $request->setClient($this)->setEventDispatcher(clone $this->getEventDispatcher());

        if ($curl = $this->config[self::CURL_OPTIONS]) {
            $request->getCurlOptions()->overwriteWith(CurlHandle::parseCurlConfig($curl));
        }

        if ($params = $this->config[self::REQUEST_PARAMS]) {
            Version::warn('request.params is deprecated. Use request.options to add default request options.');
            $request->getParams()->overwriteWith($params);
        }

        if ($this->userAgent && !$request->hasHeader('User-Agent')) {
            $request->setHeader('User-Agent', $this->userAgent);
        }

        if ($defaults = $this->config[self::REQUEST_OPTIONS]) {
            $this->requestFactory->applyOptions($request, $defaults, RequestFactoryInterface::OPTIONS_AS_DEFAULTS);
        }

        if ($options) {
            $this->requestFactory->applyOptions($request, $options);
        }

        $this->dispatch('client.create_request', array('client' => $this, 'request' => $request));

        return $request;
    }

    /**
     * Initializes SSL settings
     */
    protected function initSsl()
    {
        $authority = $this->config[self::SSL_CERT_AUTHORITY];

        if ($authority === 'system') {
            return;
        }

        if ($authority === null) {
            $authority = true;
        }

        if ($authority === true && substr(__FILE__, 0, 7) == 'phar://') {
            $authority = self::extractPharCacert(__DIR__ . '/Resources/cacert.pem');
        }

        $this->setSslVerification($authority);
    }

    /**
     * @deprecated
     */
    public function getDefaultHeaders()
    {
        Version::warn(__METHOD__ . ' is deprecated. Use the request.options array to retrieve default request options');
        return $this->defaultHeaders;
    }

    /**
     * @deprecated
     */
    public function setDefaultHeaders($headers)
    {
        Version::warn(__METHOD__ . ' is deprecated. Use the request.options array to specify default request options');
        if ($headers instanceof Collection) {
            $this->defaultHeaders = $headers;
        } elseif (is_array($headers)) {
            $this->defaultHeaders = new Collection($headers);
        } else {
            throw new InvalidArgumentException('Headers must be an array or Collection');
        }

        return $this;
    }

    /**
     * @deprecated
     */
    public function preparePharCacert($md5Check = true)
    {
        return sys_get_temp_dir() . '/guzzle-cacert.pem';
    }

    /**
     * Copies the phar cacert from a phar into the temp directory.
     *
     * @param string $pharCacertPath Path to the phar cacert. For example:
     *                               'phar://aws.phar/Guzzle/Http/Resources/cacert.pem'
     *
     * @return string Returns the path to the extracted cacert file.
     * @throws \RuntimeException Throws if the phar cacert cannot be found or
     *                           the file cannot be copied to the temp dir.
     */
    public static function extractPharCacert($pharCacertPath)
    {
        // Copy the cacert.pem file from the phar if it is not in the temp
        // folder.
        $certFile = sys_get_temp_dir() . '/guzzle-cacert.pem';

        if (!file_exists($pharCacertPath)) {
            throw new \RuntimeException("Could not find $pharCacertPath");
        }

        if (!file_exists($certFile) ||
            filesize($certFile) != filesize($pharCacertPath)
        ) {
            if (!copy($pharCacertPath, $certFile)) {
                throw new \RuntimeException(
                    "Could not copy {$pharCacertPath} to {$certFile}: "
                    . var_export(error_get_last(), true)
                );
            }
        }

        return $certFile;
    }
}
<?php

namespace Guzzle\Http;

use Guzzle\Common\Event;
use Guzzle\Common\HasDispatcherInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
 * EntityBody decorator that emits events for read and write methods
 */
class IoEmittingEntityBody extends AbstractEntityBodyDecorator implements HasDispatcherInterface
{
    /** @var EventDispatcherInterface */
    protected $eventDispatcher;

    public static function getAllEvents()
    {
        return array('body.read', 'body.write');
    }

    /**
     * {@inheritdoc}
     * @codeCoverageIgnore
     */
    public function setEventDispatcher(EventDispatcherInterface $eventDispatcher)
    {
        $this->eventDispatcher = $eventDispatcher;

        return $this;
    }

    public function getEventDispatcher()
    {
        if (!$this->eventDispatcher) {
            $this->eventDispatcher = new EventDispatcher();
        }

        return $this->eventDispatcher;
    }

    public function dispatch($eventName, array $context = array())
    {
        return $this->getEventDispatcher()->dispatch($eventName, new Event($context));
    }

    /**
     * {@inheritdoc}
     * @codeCoverageIgnore
     */
    public function addSubscriber(EventSubscriberInterface $subscriber)
    {
        $this->getEventDispatcher()->addSubscriber($subscriber);

        return $this;
    }

    public function read($length)
    {
        $event = array(
            'body'   => $this,
            'length' => $length,
            'read'   => $this->body->read($length)
        );
        $this->dispatch('body.read', $event);

        return $event['read'];
    }

    public function write($string)
    {
        $event = array(
            'body'   => $this,
            'write'  => $string,
            'result' => $this->body->write($string)
        );
        $this->dispatch('body.write', $event);

        return $event['result'];
    }
}
<?php

namespace Guzzle\Http;

use Guzzle\Stream\StreamInterface;

/**
 * Entity body used with an HTTP request or response
 */
interface EntityBodyInterface extends StreamInterface
{
    /**
     * Specify a custom callback used to rewind a non-seekable stream. This can be useful entity enclosing requests
     * that are redirected.
     *
     * @param mixed $callable Callable to invoke to rewind a non-seekable stream. The callback must accept an
     *                        EntityBodyInterface object, perform the rewind if possible, and return a boolean
     *                        representing whether or not the rewind was successful.
     * @return self
     */
    public function setRewindFunction($callable);

    /**
     * If the stream is readable, compress the data in the stream using deflate compression. The uncompressed stream is
     * then closed, and the compressed stream then becomes the wrapped stream.
     *
     * @param string $filter Compression filter
     *
     * @return bool Returns TRUE on success or FALSE on failure
     */
    public function compress($filter = 'zlib.deflate');

    /**
     * Decompress a deflated string. Once uncompressed, the uncompressed string is then used as the wrapped stream.
     *
     * @param string $filter De-compression filter
     *
     * @return bool Returns TRUE on success or FALSE on failure
     */
    public function uncompress($filter = 'zlib.inflate');

    /**
     * Get the Content-Length of the entity body if possible (alias of getSize)
     *
     * @return int|bool Returns the Content-Length or false on failure
     */
    public function getContentLength();

    /**
     * Guess the Content-Type of a local stream
     *
     * @return string|null
     * @see http://www.php.net/manual/en/function.finfo-open.php
     */
    public function getContentType();

    /**
     * Get an MD5 checksum of the stream's contents
     *
     * @param bool $rawOutput    Whether or not to use raw output
     * @param bool $base64Encode Whether or not to base64 encode raw output (only if raw output is true)
     *
     * @return bool|string Returns an MD5 string on success or FALSE on failure
     */
    public function getContentMd5($rawOutput = false, $base64Encode = false);

    /**
     * Get the Content-Encoding of the EntityBody
     *
     * @return bool|string
     */
    public function getContentEncoding();
}
<?php

namespace Guzzle\Http;

/**
 * Provides mappings of file extensions to mimetypes
 * @link http://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x/conf/mime.types
 */
class Mimetypes
{
    /** @var self */
    protected static $instance;

    /** @var array Mapping of extension to mimetype */
    protected $mimetypes = array(
        '3dml' => 'text/vnd.in3d.3dml',
        '3g2' => 'video/3gpp2',
        '3gp' => 'video/3gpp',
        '7z' => 'application/x-7z-compressed',
        'aab' => 'application/x-authorware-bin',
        'aac' => 'audio/x-aac',
        'aam' => 'application/x-authorware-map',
        'aas' => 'application/x-authorware-seg',
        'abw' => 'application/x-abiword',
        'ac' => 'application/pkix-attr-cert',
        'acc' => 'application/vnd.americandynamics.acc',
        'ace' => 'application/x-ace-compressed',
        'acu' => 'application/vnd.acucobol',
        'acutc' => 'application/vnd.acucorp',
        'adp' => 'audio/adpcm',
        'aep' => 'application/vnd.audiograph',
        'afm' => 'application/x-font-type1',
        'afp' => 'application/vnd.ibm.modcap',
        'ahead' => 'application/vnd.ahead.space',
        'ai' => 'application/postscript',
        'aif' => 'audio/x-aiff',
        'aifc' => 'audio/x-aiff',
        'aiff' => 'audio/x-aiff',
        'air' => 'application/vnd.adobe.air-application-installer-package+zip',
        'ait' => 'application/vnd.dvb.ait',
        'ami' => 'application/vnd.amiga.ami',
        'apk' => 'application/vnd.android.package-archive',
        'application' => 'application/x-ms-application',
        'apr' => 'application/vnd.lotus-approach',
        'asa' => 'text/plain',
        'asax' => 'application/octet-stream',
        'asc' => 'application/pgp-signature',
        'ascx' => 'text/plain',
        'asf' => 'video/x-ms-asf',
        'ashx' => 'text/plain',
        'asm' => 'text/x-asm',
        'asmx' => 'text/plain',
        'aso' => 'application/vnd.accpac.simply.aso',
        'asp' => 'text/plain',
        'aspx' => 'text/plain',
        'asx' => 'video/x-ms-asf',
        'atc' => 'application/vnd.acucorp',
        'atom' => 'application/atom+xml',
        'atomcat' => 'application/atomcat+xml',
        'atomsvc' => 'application/atomsvc+xml',
        'atx' => 'application/vnd.antix.game-component',
        'au' => 'audio/basic',
        'avi' => 'video/x-msvideo',
        'aw' => 'application/applixware',
        'axd' => 'text/plain',
        'azf' => 'application/vnd.airzip.filesecure.azf',
        'azs' => 'application/vnd.airzip.filesecure.azs',
        'azw' => 'application/vnd.amazon.ebook',
        'bat' => 'application/x-msdownload',
        'bcpio' => 'application/x-bcpio',
        'bdf' => 'application/x-font-bdf',
        'bdm' => 'application/vnd.syncml.dm+wbxml',
        'bed' => 'application/vnd.realvnc.bed',
        'bh2' => 'application/vnd.fujitsu.oasysprs',
        'bin' => 'application/octet-stream',
        'bmi' => 'application/vnd.bmi',
        'bmp' => 'image/bmp',
        'book' => 'application/vnd.framemaker',
        'box' => 'application/vnd.previewsystems.box',
        'boz' => 'application/x-bzip2',
        'bpk' => 'application/octet-stream',
        'btif' => 'image/prs.btif',
        'bz' => 'application/x-bzip',
        'bz2' => 'application/x-bzip2',
        'c' => 'text/x-c',
        'c11amc' => 'application/vnd.cluetrust.cartomobile-config',
        'c11amz' => 'application/vnd.cluetrust.cartomobile-config-pkg',
        'c4d' => 'application/vnd.clonk.c4group',
        'c4f' => 'application/vnd.clonk.c4group',
        'c4g' => 'application/vnd.clonk.c4group',
        'c4p' => 'application/vnd.clonk.c4group',
        'c4u' => 'application/vnd.clonk.c4group',
        'cab' => 'application/vnd.ms-cab-compressed',
        'car' => 'application/vnd.curl.car',
        'cat' => 'application/vnd.ms-pki.seccat',
        'cc' => 'text/x-c',
        'cct' => 'application/x-director',
        'ccxml' => 'application/ccxml+xml',
        'cdbcmsg' => 'application/vnd.contact.cmsg',
        'cdf' => 'application/x-netcdf',
        'cdkey' => 'application/vnd.mediastation.cdkey',
        'cdmia' => 'application/cdmi-capability',
        'cdmic' => 'application/cdmi-container',
        'cdmid' => 'application/cdmi-domain',
        'cdmio' => 'application/cdmi-object',
        'cdmiq' => 'application/cdmi-queue',
        'cdx' => 'chemical/x-cdx',
        'cdxml' => 'application/vnd.chemdraw+xml',
        'cdy' => 'application/vnd.cinderella',
        'cer' => 'application/pkix-cert',
        'cfc' => 'application/x-coldfusion',
        'cfm' => 'application/x-coldfusion',
        'cgm' => 'image/cgm',
        'chat' => 'application/x-chat',
        'chm' => 'application/vnd.ms-htmlhelp',
        'chrt' => 'application/vnd.kde.kchart',
        'cif' => 'chemical/x-cif',
        'cii' => 'application/vnd.anser-web-certificate-issue-initiation',
        'cil' => 'application/vnd.ms-artgalry',
        'cla' => 'application/vnd.claymore',
        'class' => 'application/java-vm',
        'clkk' => 'application/vnd.crick.clicker.keyboard',
        'clkp' => 'application/vnd.crick.clicker.palette',
        'clkt' => 'application/vnd.crick.clicker.template',
        'clkw' => 'application/vnd.crick.clicker.wordbank',
        'clkx' => 'application/vnd.crick.clicker',
        'clp' => 'application/x-msclip',
        'cmc' => 'application/vnd.cosmocaller',
        'cmdf' => 'chemical/x-cmdf',
        'cml' => 'chemical/x-cml',
        'cmp' => 'application/vnd.yellowriver-custom-menu',
        'cmx' => 'image/x-cmx',
        'cod' => 'application/vnd.rim.cod',
        'com' => 'application/x-msdownload',
        'conf' => 'text/plain',
        'cpio' => 'application/x-cpio',
        'cpp' => 'text/x-c',
        'cpt' => 'application/mac-compactpro',
        'crd' => 'application/x-mscardfile',
        'crl' => 'application/pkix-crl',
        'crt' => 'application/x-x509-ca-cert',
        'cryptonote' => 'application/vnd.rig.cryptonote',
        'cs' => 'text/plain',
        'csh' => 'application/x-csh',
        'csml' => 'chemical/x-csml',
        'csp' => 'application/vnd.commonspace',
        'css' => 'text/css',
        'cst' => 'application/x-director',
        'csv' => 'text/csv',
        'cu' => 'application/cu-seeme',
        'curl' => 'text/vnd.curl',
        'cww' => 'application/prs.cww',
        'cxt' => 'application/x-director',
        'cxx' => 'text/x-c',
        'dae' => 'model/vnd.collada+xml',
        'daf' => 'application/vnd.mobius.daf',
        'dataless' => 'application/vnd.fdsn.seed',
        'davmount' => 'application/davmount+xml',
        'dcr' => 'application/x-director',
        'dcurl' => 'text/vnd.curl.dcurl',
        'dd2' => 'application/vnd.oma.dd2+xml',
        'ddd' => 'application/vnd.fujixerox.ddd',
        'deb' => 'application/x-debian-package',
        'def' => 'text/plain',
        'deploy' => 'application/octet-stream',
        'der' => 'application/x-x509-ca-cert',
        'dfac' => 'application/vnd.dreamfactory',
        'dic' => 'text/x-c',
        'dir' => 'application/x-director',
        'dis' => 'application/vnd.mobius.dis',
        'dist' => 'application/octet-stream',
        'distz' => 'application/octet-stream',
        'djv' => 'image/vnd.djvu',
        'djvu' => 'image/vnd.djvu',
        'dll' => 'application/x-msdownload',
        'dmg' => 'application/octet-stream',
        'dms' => 'application/octet-stream',
        'dna' => 'application/vnd.dna',
        'doc' => 'application/msword',
        'docm' => 'application/vnd.ms-word.document.macroenabled.12',
        'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
        'dot' => 'application/msword',
        'dotm' => 'application/vnd.ms-word.template.macroenabled.12',
        'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
        'dp' => 'application/vnd.osgi.dp',
        'dpg' => 'application/vnd.dpgraph',
        'dra' => 'audio/vnd.dra',
        'dsc' => 'text/prs.lines.tag',
        'dssc' => 'application/dssc+der',
        'dtb' => 'application/x-dtbook+xml',
        'dtd' => 'application/xml-dtd',
        'dts' => 'audio/vnd.dts',
        'dtshd' => 'audio/vnd.dts.hd',
        'dump' => 'application/octet-stream',
        'dvi' => 'application/x-dvi',
        'dwf' => 'model/vnd.dwf',
        'dwg' => 'image/vnd.dwg',
        'dxf' => 'image/vnd.dxf',
        'dxp' => 'application/vnd.spotfire.dxp',
        'dxr' => 'application/x-director',
        'ecelp4800' => 'audio/vnd.nuera.ecelp4800',
        'ecelp7470' => 'audio/vnd.nuera.ecelp7470',
        'ecelp9600' => 'audio/vnd.nuera.ecelp9600',
        'ecma' => 'application/ecmascript',
        'edm' => 'application/vnd.novadigm.edm',
        'edx' => 'application/vnd.novadigm.edx',
        'efif' => 'application/vnd.picsel',
        'ei6' => 'application/vnd.pg.osasli',
        'elc' => 'application/octet-stream',
        'eml' => 'message/rfc822',
        'emma' => 'application/emma+xml',
        'eol' => 'audio/vnd.digital-winds',
        'eot' => 'application/vnd.ms-fontobject',
        'eps' => 'application/postscript',
        'epub' => 'application/epub+zip',
        'es3' => 'application/vnd.eszigno3+xml',
        'esf' => 'application/vnd.epson.esf',
        'et3' => 'application/vnd.eszigno3+xml',
        'etx' => 'text/x-setext',
        'exe' => 'application/x-msdownload',
        'exi' => 'application/exi',
        'ext' => 'application/vnd.novadigm.ext',
        'ez' => 'application/andrew-inset',
        'ez2' => 'application/vnd.ezpix-album',
        'ez3' => 'application/vnd.ezpix-package',
        'f' => 'text/x-fortran',
        'f4v' => 'video/x-f4v',
        'f77' => 'text/x-fortran',
        'f90' => 'text/x-fortran',
        'fbs' => 'image/vnd.fastbidsheet',
        'fcs' => 'application/vnd.isac.fcs',
        'fdf' => 'application/vnd.fdf',
        'fe_launch' => 'application/vnd.denovo.fcselayout-link',
        'fg5' => 'application/vnd.fujitsu.oasysgp',
        'fgd' => 'application/x-director',
        'fh' => 'image/x-freehand',
        'fh4' => 'image/x-freehand',
        'fh5' => 'image/x-freehand',
        'fh7' => 'image/x-freehand',
        'fhc' => 'image/x-freehand',
        'fig' => 'application/x-xfig',
        'fli' => 'video/x-fli',
        'flo' => 'application/vnd.micrografx.flo',
        'flv' => 'video/x-flv',
        'flw' => 'application/vnd.kde.kivio',
        'flx' => 'text/vnd.fmi.flexstor',
        'fly' => 'text/vnd.fly',
        'fm' => 'application/vnd.framemaker',
        'fnc' => 'application/vnd.frogans.fnc',
        'for' => 'text/x-fortran',
        'fpx' => 'image/vnd.fpx',
        'frame' => 'application/vnd.framemaker',
        'fsc' => 'application/vnd.fsc.weblaunch',
        'fst' => 'image/vnd.fst',
        'ftc' => 'application/vnd.fluxtime.clip',
        'fti' => 'application/vnd.anser-web-funds-transfer-initiation',
        'fvt' => 'video/vnd.fvt',
        'fxp' => 'application/vnd.adobe.fxp',
        'fxpl' => 'application/vnd.adobe.fxp',
        'fzs' => 'application/vnd.fuzzysheet',
        'g2w' => 'application/vnd.geoplan',
        'g3' => 'image/g3fax',
        'g3w' => 'application/vnd.geospace',
        'gac' => 'application/vnd.groove-account',
        'gdl' => 'model/vnd.gdl',
        'geo' => 'application/vnd.dynageo',
        'gex' => 'application/vnd.geometry-explorer',
        'ggb' => 'application/vnd.geogebra.file',
        'ggt' => 'application/vnd.geogebra.tool',
        'ghf' => 'application/vnd.groove-help',
        'gif' => 'image/gif',
        'gim' => 'application/vnd.groove-identity-message',
        'gmx' => 'application/vnd.gmx',
        'gnumeric' => 'application/x-gnumeric',
        'gph' => 'application/vnd.flographit',
        'gqf' => 'application/vnd.grafeq',
        'gqs' => 'application/vnd.grafeq',
        'gram' => 'application/srgs',
        'gre' => 'application/vnd.geometry-explorer',
        'grv' => 'application/vnd.groove-injector',
        'grxml' => 'application/srgs+xml',
        'gsf' => 'application/x-font-ghostscript',
        'gtar' => 'application/x-gtar',
        'gtm' => 'application/vnd.groove-tool-message',
        'gtw' => 'model/vnd.gtw',
        'gv' => 'text/vnd.graphviz',
        'gxt' => 'application/vnd.geonext',
        'h' => 'text/x-c',
        'h261' => 'video/h261',
        'h263' => 'video/h263',
        'h264' => 'video/h264',
        'hal' => 'application/vnd.hal+xml',
        'hbci' => 'application/vnd.hbci',
        'hdf' => 'application/x-hdf',
        'hh' => 'text/x-c',
        'hlp' => 'application/winhlp',
        'hpgl' => 'application/vnd.hp-hpgl',
        'hpid' => 'application/vnd.hp-hpid',
        'hps' => 'application/vnd.hp-hps',
        'hqx' => 'application/mac-binhex40',
        'hta' => 'application/octet-stream',
        'htc' => 'text/html',
        'htke' => 'application/vnd.kenameaapp',
        'htm' => 'text/html',
        'html' => 'text/html',
        'hvd' => 'application/vnd.yamaha.hv-dic',
        'hvp' => 'application/vnd.yamaha.hv-voice',
        'hvs' => 'application/vnd.yamaha.hv-script',
        'i2g' => 'application/vnd.intergeo',
        'icc' => 'application/vnd.iccprofile',
        'ice' => 'x-conference/x-cooltalk',
        'icm' => 'application/vnd.iccprofile',
        'ico' => 'image/x-icon',
        'ics' => 'text/calendar',
        'ief' => 'image/ief',
        'ifb' => 'text/calendar',
        'ifm' => 'application/vnd.shana.informed.formdata',
        'iges' => 'model/iges',
        'igl' => 'application/vnd.igloader',
        'igm' => 'application/vnd.insors.igm',
        'igs' => 'model/iges',
        'igx' => 'application/vnd.micrografx.igx',
        'iif' => 'application/vnd.shana.informed.interchange',
        'imp' => 'application/vnd.accpac.simply.imp',
        'ims' => 'application/vnd.ms-ims',
        'in' => 'text/plain',
        'ini' => 'text/plain',
        'ipfix' => 'application/ipfix',
        'ipk' => 'application/vnd.shana.informed.package',
        'irm' => 'application/vnd.ibm.rights-management',
        'irp' => 'application/vnd.irepository.package+xml',
        'iso' => 'application/octet-stream',
        'itp' => 'application/vnd.shana.informed.formtemplate',
        'ivp' => 'application/vnd.immervision-ivp',
        'ivu' => 'application/vnd.immervision-ivu',
        'jad' => 'text/vnd.sun.j2me.app-descriptor',
        'jam' => 'application/vnd.jam',
        'jar' => 'application/java-archive',
        'java' => 'text/x-java-source',
        'jisp' => 'application/vnd.jisp',
        'jlt' => 'application/vnd.hp-jlyt',
        'jnlp' => 'application/x-java-jnlp-file',
        'joda' => 'application/vnd.joost.joda-archive',
        'jpe' => 'image/jpeg',
        'jpeg' => 'image/jpeg',
        'jpg' => 'image/jpeg',
        'jpgm' => 'video/jpm',
        'jpgv' => 'video/jpeg',
        'jpm' => 'video/jpm',
        'js' => 'text/javascript',
        'json' => 'application/json',
        'kar' => 'audio/midi',
        'karbon' => 'application/vnd.kde.karbon',
        'kfo' => 'application/vnd.kde.kformula',
        'kia' => 'application/vnd.kidspiration',
        'kml' => 'application/vnd.google-earth.kml+xml',
        'kmz' => 'application/vnd.google-earth.kmz',
        'kne' => 'application/vnd.kinar',
        'knp' => 'application/vnd.kinar',
        'kon' => 'application/vnd.kde.kontour',
        'kpr' => 'application/vnd.kde.kpresenter',
        'kpt' => 'application/vnd.kde.kpresenter',
        'ksp' => 'application/vnd.kde.kspread',
        'ktr' => 'application/vnd.kahootz',
        'ktx' => 'image/ktx',
        'ktz' => 'application/vnd.kahootz',
        'kwd' => 'application/vnd.kde.kword',
        'kwt' => 'application/vnd.kde.kword',
        'lasxml' => 'application/vnd.las.las+xml',
        'latex' => 'application/x-latex',
        'lbd' => 'application/vnd.llamagraphics.life-balance.desktop',
        'lbe' => 'application/vnd.llamagraphics.life-balance.exchange+xml',
        'les' => 'application/vnd.hhe.lesson-player',
        'lha' => 'application/octet-stream',
        'link66' => 'application/vnd.route66.link66+xml',
        'list' => 'text/plain',
        'list3820' => 'application/vnd.ibm.modcap',
        'listafp' => 'application/vnd.ibm.modcap',
        'log' => 'text/plain',
        'lostxml' => 'application/lost+xml',
        'lrf' => 'application/octet-stream',
        'lrm' => 'application/vnd.ms-lrm',
        'ltf' => 'application/vnd.frogans.ltf',
        'lvp' => 'audio/vnd.lucent.voice',
        'lwp' => 'application/vnd.lotus-wordpro',
        'lzh' => 'application/octet-stream',
        'm13' => 'application/x-msmediaview',
        'm14' => 'application/x-msmediaview',
        'm1v' => 'video/mpeg',
        'm21' => 'application/mp21',
        'm2a' => 'audio/mpeg',
        'm2v' => 'video/mpeg',
        'm3a' => 'audio/mpeg',
        'm3u' => 'audio/x-mpegurl',
        'm3u8' => 'application/vnd.apple.mpegurl',
        'm4a' => 'audio/mp4',
        'm4u' => 'video/vnd.mpegurl',
        'm4v' => 'video/mp4',
        'ma' => 'application/mathematica',
        'mads' => 'application/mads+xml',
        'mag' => 'application/vnd.ecowin.chart',
        'maker' => 'application/vnd.framemaker',
        'man' => 'text/troff',
        'mathml' => 'application/mathml+xml',
        'mb' => 'application/mathematica',
        'mbk' => 'application/vnd.mobius.mbk',
        'mbox' => 'application/mbox',
        'mc1' => 'application/vnd.medcalcdata',
        'mcd' => 'application/vnd.mcd',
        'mcurl' => 'text/vnd.curl.mcurl',
        'mdb' => 'application/x-msaccess',
        'mdi' => 'image/vnd.ms-modi',
        'me' => 'text/troff',
        'mesh' => 'model/mesh',
        'meta4' => 'application/metalink4+xml',
        'mets' => 'application/mets+xml',
        'mfm' => 'application/vnd.mfmp',
        'mgp' => 'application/vnd.osgeo.mapguide.package',
        'mgz' => 'application/vnd.proteus.magazine',
        'mid' => 'audio/midi',
        'midi' => 'audio/midi',
        'mif' => 'application/vnd.mif',
        'mime' => 'message/rfc822',
        'mj2' => 'video/mj2',
        'mjp2' => 'video/mj2',
        'mlp' => 'application/vnd.dolby.mlp',
        'mmd' => 'application/vnd.chipnuts.karaoke-mmd',
        'mmf' => 'application/vnd.smaf',
        'mmr' => 'image/vnd.fujixerox.edmics-mmr',
        'mny' => 'application/x-msmoney',
        'mobi' => 'application/x-mobipocket-ebook',
        'mods' => 'application/mods+xml',
        'mov' => 'video/quicktime',
        'movie' => 'video/x-sgi-movie',
        'mp2' => 'audio/mpeg',
        'mp21' => 'application/mp21',
        'mp2a' => 'audio/mpeg',
        'mp3' => 'audio/mpeg',
        'mp4' => 'video/mp4',
        'mp4a' => 'audio/mp4',
        'mp4s' => 'application/mp4',
        'mp4v' => 'video/mp4',
        'mpc' => 'application/vnd.mophun.certificate',
        'mpe' => 'video/mpeg',
        'mpeg' => 'video/mpeg',
        'mpg' => 'video/mpeg',
        'mpg4' => 'video/mp4',
        'mpga' => 'audio/mpeg',
        'mpkg' => 'application/vnd.apple.installer+xml',
        'mpm' => 'application/vnd.blueice.multipass',
        'mpn' => 'application/vnd.mophun.application',
        'mpp' => 'application/vnd.ms-project',
        'mpt' => 'application/vnd.ms-project',
        'mpy' => 'application/vnd.ibm.minipay',
        'mqy' => 'application/vnd.mobius.mqy',
        'mrc' => 'application/marc',
        'mrcx' => 'application/marcxml+xml',
        'ms' => 'text/troff',
        'mscml' => 'application/mediaservercontrol+xml',
        'mseed' => 'application/vnd.fdsn.mseed',
        'mseq' => 'application/vnd.mseq',
        'msf' => 'application/vnd.epson.msf',
        'msh' => 'model/mesh',
        'msi' => 'application/x-msdownload',
        'msl' => 'application/vnd.mobius.msl',
        'msty' => 'application/vnd.muvee.style',
        'mts' => 'model/vnd.mts',
        'mus' => 'application/vnd.musician',
        'musicxml' => 'application/vnd.recordare.musicxml+xml',
        'mvb' => 'application/x-msmediaview',
        'mwf' => 'application/vnd.mfer',
        'mxf' => 'application/mxf',
        'mxl' => 'application/vnd.recordare.musicxml',
        'mxml' => 'application/xv+xml',
        'mxs' => 'application/vnd.triscape.mxs',
        'mxu' => 'video/vnd.mpegurl',
        'n-gage' => 'application/vnd.nokia.n-gage.symbian.install',
        'n3' => 'text/n3',
        'nb' => 'application/mathematica',
        'nbp' => 'application/vnd.wolfram.player',
        'nc' => 'application/x-netcdf',
        'ncx' => 'application/x-dtbncx+xml',
        'ngdat' => 'application/vnd.nokia.n-gage.data',
        'nlu' => 'application/vnd.neurolanguage.nlu',
        'nml' => 'application/vnd.enliven',
        'nnd' => 'application/vnd.noblenet-directory',
        'nns' => 'application/vnd.noblenet-sealer',
        'nnw' => 'application/vnd.noblenet-web',
        'npx' => 'image/vnd.net-fpx',
        'nsf' => 'application/vnd.lotus-notes',
        'oa2' => 'application/vnd.fujitsu.oasys2',
        'oa3' => 'application/vnd.fujitsu.oasys3',
        'oas' => 'application/vnd.fujitsu.oasys',
        'obd' => 'application/x-msbinder',
        'oda' => 'application/oda',
        'odb' => 'application/vnd.oasis.opendocument.database',
        'odc' => 'application/vnd.oasis.opendocument.chart',
        'odf' => 'application/vnd.oasis.opendocument.formula',
        'odft' => 'application/vnd.oasis.opendocument.formula-template',
        'odg' => 'application/vnd.oasis.opendocument.graphics',
        'odi' => 'application/vnd.oasis.opendocument.image',
        'odm' => 'application/vnd.oasis.opendocument.text-master',
        'odp' => 'application/vnd.oasis.opendocument.presentation',
        'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
        'odt' => 'application/vnd.oasis.opendocument.text',
        'oga' => 'audio/ogg',
        'ogg' => 'audio/ogg',
        'ogv' => 'video/ogg',
        'ogx' => 'application/ogg',
        'onepkg' => 'application/onenote',
        'onetmp' => 'application/onenote',
        'onetoc' => 'application/onenote',
        'onetoc2' => 'application/onenote',
        'opf' => 'application/oebps-package+xml',
        'oprc' => 'application/vnd.palm',
        'org' => 'application/vnd.lotus-organizer',
        'osf' => 'application/vnd.yamaha.openscoreformat',
        'osfpvg' => 'application/vnd.yamaha.openscoreformat.osfpvg+xml',
        'otc' => 'application/vnd.oasis.opendocument.chart-template',
        'otf' => 'application/x-font-otf',
        'otg' => 'application/vnd.oasis.opendocument.graphics-template',
        'oth' => 'application/vnd.oasis.opendocument.text-web',
        'oti' => 'application/vnd.oasis.opendocument.image-template',
        'otp' => 'application/vnd.oasis.opendocument.presentation-template',
        'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
        'ott' => 'application/vnd.oasis.opendocument.text-template',
        'oxt' => 'application/vnd.openofficeorg.extension',
        'p' => 'text/x-pascal',
        'p10' => 'application/pkcs10',
        'p12' => 'application/x-pkcs12',
        'p7b' => 'application/x-pkcs7-certificates',
        'p7c' => 'application/pkcs7-mime',
        'p7m' => 'application/pkcs7-mime',
        'p7r' => 'application/x-pkcs7-certreqresp',
        'p7s' => 'application/pkcs7-signature',
        'p8' => 'application/pkcs8',
        'pas' => 'text/x-pascal',
        'paw' => 'application/vnd.pawaafile',
        'pbd' => 'application/vnd.powerbuilder6',
        'pbm' => 'image/x-portable-bitmap',
        'pcf' => 'application/x-font-pcf',
        'pcl' => 'application/vnd.hp-pcl',
        'pclxl' => 'application/vnd.hp-pclxl',
        'pct' => 'image/x-pict',
        'pcurl' => 'application/vnd.curl.pcurl',
        'pcx' => 'image/x-pcx',
        'pdb' => 'application/vnd.palm',
        'pdf' => 'application/pdf',
        'pfa' => 'application/x-font-type1',
        'pfb' => 'application/x-font-type1',
        'pfm' => 'application/x-font-type1',
        'pfr' => 'application/font-tdpfr',
        'pfx' => 'application/x-pkcs12',
        'pgm' => 'image/x-portable-graymap',
        'pgn' => 'application/x-chess-pgn',
        'pgp' => 'application/pgp-encrypted',
        'php' => 'text/x-php',
        'phps' => 'application/x-httpd-phps',
        'pic' => 'image/x-pict',
        'pkg' => 'application/octet-stream',
        'pki' => 'application/pkixcmp',
        'pkipath' => 'application/pkix-pkipath',
        'plb' => 'application/vnd.3gpp.pic-bw-large',
        'plc' => 'application/vnd.mobius.plc',
        'plf' => 'application/vnd.pocketlearn',
        'pls' => 'application/pls+xml',
        'pml' => 'application/vnd.ctc-posml',
        'png' => 'image/png',
        'pnm' => 'image/x-portable-anymap',
        'portpkg' => 'application/vnd.macports.portpkg',
        'pot' => 'application/vnd.ms-powerpoint',
        'potm' => 'application/vnd.ms-powerpoint.template.macroenabled.12',
        'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
        'ppam' => 'application/vnd.ms-powerpoint.addin.macroenabled.12',
        'ppd' => 'application/vnd.cups-ppd',
        'ppm' => 'image/x-portable-pixmap',
        'pps' => 'application/vnd.ms-powerpoint',
        'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroenabled.12',
        'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
        'ppt' => 'application/vnd.ms-powerpoint',
        'pptm' => 'application/vnd.ms-powerpoint.presentation.macroenabled.12',
        'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
        'pqa' => 'application/vnd.palm',
        'prc' => 'application/x-mobipocket-ebook',
        'pre' => 'application/vnd.lotus-freelance',
        'prf' => 'application/pics-rules',
        'ps' => 'application/postscript',
        'psb' => 'application/vnd.3gpp.pic-bw-small',
        'psd' => 'image/vnd.adobe.photoshop',
        'psf' => 'application/x-font-linux-psf',
        'pskcxml' => 'application/pskc+xml',
        'ptid' => 'application/vnd.pvi.ptid1',
        'pub' => 'application/x-mspublisher',
        'pvb' => 'application/vnd.3gpp.pic-bw-var',
        'pwn' => 'application/vnd.3m.post-it-notes',
        'pya' => 'audio/vnd.ms-playready.media.pya',
        'pyv' => 'video/vnd.ms-playready.media.pyv',
        'qam' => 'application/vnd.epson.quickanime',
        'qbo' => 'application/vnd.intu.qbo',
        'qfx' => 'application/vnd.intu.qfx',
        'qps' => 'application/vnd.publishare-delta-tree',
        'qt' => 'video/quicktime',
        'qwd' => 'application/vnd.quark.quarkxpress',
        'qwt' => 'application/vnd.quark.quarkxpress',
        'qxb' => 'application/vnd.quark.quarkxpress',
        'qxd' => 'application/vnd.quark.quarkxpress',
        'qxl' => 'application/vnd.quark.quarkxpress',
        'qxt' => 'application/vnd.quark.quarkxpress',
        'ra' => 'audio/x-pn-realaudio',
        'ram' => 'audio/x-pn-realaudio',
        'rar' => 'application/x-rar-compressed',
        'ras' => 'image/x-cmu-raster',
        'rb' => 'text/plain',
        'rcprofile' => 'application/vnd.ipunplugged.rcprofile',
        'rdf' => 'application/rdf+xml',
        'rdz' => 'application/vnd.data-vision.rdz',
        'rep' => 'application/vnd.businessobjects',
        'res' => 'application/x-dtbresource+xml',
        'resx' => 'text/xml',
        'rgb' => 'image/x-rgb',
        'rif' => 'application/reginfo+xml',
        'rip' => 'audio/vnd.rip',
        'rl' => 'application/resource-lists+xml',
        'rlc' => 'image/vnd.fujixerox.edmics-rlc',
        'rld' => 'application/resource-lists-diff+xml',
        'rm' => 'application/vnd.rn-realmedia',
        'rmi' => 'audio/midi',
        'rmp' => 'audio/x-pn-realaudio-plugin',
        'rms' => 'application/vnd.jcp.javame.midlet-rms',
        'rnc' => 'application/relax-ng-compact-syntax',
        'roff' => 'text/troff',
        'rp9' => 'application/vnd.cloanto.rp9',
        'rpss' => 'application/vnd.nokia.radio-presets',
        'rpst' => 'application/vnd.nokia.radio-preset',
        'rq' => 'application/sparql-query',
        'rs' => 'application/rls-services+xml',
        'rsd' => 'application/rsd+xml',
        'rss' => 'application/rss+xml',
        'rtf' => 'application/rtf',
        'rtx' => 'text/richtext',
        's' => 'text/x-asm',
        'saf' => 'application/vnd.yamaha.smaf-audio',
        'sbml' => 'application/sbml+xml',
        'sc' => 'application/vnd.ibm.secure-container',
        'scd' => 'application/x-msschedule',
        'scm' => 'application/vnd.lotus-screencam',
        'scq' => 'application/scvp-cv-request',
        'scs' => 'application/scvp-cv-response',
        'scurl' => 'text/vnd.curl.scurl',
        'sda' => 'application/vnd.stardivision.draw',
        'sdc' => 'application/vnd.stardivision.calc',
        'sdd' => 'application/vnd.stardivision.impress',
        'sdkd' => 'application/vnd.solent.sdkm+xml',
        'sdkm' => 'application/vnd.solent.sdkm+xml',
        'sdp' => 'application/sdp',
        'sdw' => 'application/vnd.stardivision.writer',
        'see' => 'application/vnd.seemail',
        'seed' => 'application/vnd.fdsn.seed',
        'sema' => 'application/vnd.sema',
        'semd' => 'application/vnd.semd',
        'semf' => 'application/vnd.semf',
        'ser' => 'application/java-serialized-object',
        'setpay' => 'application/set-payment-initiation',
        'setreg' => 'application/set-registration-initiation',
        'sfd-hdstx' => 'application/vnd.hydrostatix.sof-data',
        'sfs' => 'application/vnd.spotfire.sfs',
        'sgl' => 'application/vnd.stardivision.writer-global',
        'sgm' => 'text/sgml',
        'sgml' => 'text/sgml',
        'sh' => 'application/x-sh',
        'shar' => 'application/x-shar',
        'shf' => 'application/shf+xml',
        'sig' => 'application/pgp-signature',
        'silo' => 'model/mesh',
        'sis' => 'application/vnd.symbian.install',
        'sisx' => 'application/vnd.symbian.install',
        'sit' => 'application/x-stuffit',
        'sitx' => 'application/x-stuffitx',
        'skd' => 'application/vnd.koan',
        'skm' => 'application/vnd.koan',
        'skp' => 'application/vnd.koan',
        'skt' => 'application/vnd.koan',
        'sldm' => 'application/vnd.ms-powerpoint.slide.macroenabled.12',
        'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
        'slt' => 'application/vnd.epson.salt',
        'sm' => 'application/vnd.stepmania.stepchart',
        'smf' => 'application/vnd.stardivision.math',
        'smi' => 'application/smil+xml',
        'smil' => 'application/smil+xml',
        'snd' => 'audio/basic',
        'snf' => 'application/x-font-snf',
        'so' => 'application/octet-stream',
        'spc' => 'application/x-pkcs7-certificates',
        'spf' => 'application/vnd.yamaha.smaf-phrase',
        'spl' => 'application/x-futuresplash',
        'spot' => 'text/vnd.in3d.spot',
        'spp' => 'application/scvp-vp-response',
        'spq' => 'application/scvp-vp-request',
        'spx' => 'audio/ogg',
        'src' => 'application/x-wais-source',
        'sru' => 'application/sru+xml',
        'srx' => 'application/sparql-results+xml',
        'sse' => 'application/vnd.kodak-descriptor',
        'ssf' => 'application/vnd.epson.ssf',
        'ssml' => 'application/ssml+xml',
        'st' => 'application/vnd.sailingtracker.track',
        'stc' => 'application/vnd.sun.xml.calc.template',
        'std' => 'application/vnd.sun.xml.draw.template',
        'stf' => 'application/vnd.wt.stf',
        'sti' => 'application/vnd.sun.xml.impress.template',
        'stk' => 'application/hyperstudio',
        'stl' => 'application/vnd.ms-pki.stl',
        'str' => 'application/vnd.pg.format',
        'stw' => 'application/vnd.sun.xml.writer.template',
        'sub' => 'image/vnd.dvb.subtitle',
        'sus' => 'application/vnd.sus-calendar',
        'susp' => 'application/vnd.sus-calendar',
        'sv4cpio' => 'application/x-sv4cpio',
        'sv4crc' => 'application/x-sv4crc',
        'svc' => 'application/vnd.dvb.service',
        'svd' => 'application/vnd.svd',
        'svg' => 'image/svg+xml',
        'svgz' => 'image/svg+xml',
        'swa' => 'application/x-director',
        'swf' => 'application/x-shockwave-flash',
        'swi' => 'application/vnd.aristanetworks.swi',
        'sxc' => 'application/vnd.sun.xml.calc',
        'sxd' => 'application/vnd.sun.xml.draw',
        'sxg' => 'application/vnd.sun.xml.writer.global',
        'sxi' => 'application/vnd.sun.xml.impress',
        'sxm' => 'application/vnd.sun.xml.math',
        'sxw' => 'application/vnd.sun.xml.writer',
        't' => 'text/troff',
        'tao' => 'application/vnd.tao.intent-module-archive',
        'tar' => 'application/x-tar',
        'tcap' => 'application/vnd.3gpp2.tcap',
        'tcl' => 'application/x-tcl',
        'teacher' => 'application/vnd.smart.teacher',
        'tei' => 'application/tei+xml',
        'teicorpus' => 'application/tei+xml',
        'tex' => 'application/x-tex',
        'texi' => 'application/x-texinfo',
        'texinfo' => 'application/x-texinfo',
        'text' => 'text/plain',
        'tfi' => 'application/thraud+xml',
        'tfm' => 'application/x-tex-tfm',
        'thmx' => 'application/vnd.ms-officetheme',
        'tif' => 'image/tiff',
        'tiff' => 'image/tiff',
        'tmo' => 'application/vnd.tmobile-livetv',
        'torrent' => 'application/x-bittorrent',
        'tpl' => 'application/vnd.groove-tool-template',
        'tpt' => 'application/vnd.trid.tpt',
        'tr' => 'text/troff',
        'tra' => 'application/vnd.trueapp',
        'trm' => 'application/x-msterminal',
        'tsd' => 'application/timestamped-data',
        'tsv' => 'text/tab-separated-values',
        'ttc' => 'application/x-font-ttf',
        'ttf' => 'application/x-font-ttf',
        'ttl' => 'text/turtle',
        'twd' => 'application/vnd.simtech-mindmapper',
        'twds' => 'application/vnd.simtech-mindmapper',
        'txd' => 'application/vnd.genomatix.tuxedo',
        'txf' => 'application/vnd.mobius.txf',
        'txt' => 'text/plain',
        'u32' => 'application/x-authorware-bin',
        'udeb' => 'application/x-debian-package',
        'ufd' => 'application/vnd.ufdl',
        'ufdl' => 'application/vnd.ufdl',
        'umj' => 'application/vnd.umajin',
        'unityweb' => 'application/vnd.unity',
        'uoml' => 'application/vnd.uoml+xml',
        'uri' => 'text/uri-list',
        'uris' => 'text/uri-list',
        'urls' => 'text/uri-list',
        'ustar' => 'application/x-ustar',
        'utz' => 'application/vnd.uiq.theme',
        'uu' => 'text/x-uuencode',
        'uva' => 'audio/vnd.dece.audio',
        'uvd' => 'application/vnd.dece.data',
        'uvf' => 'application/vnd.dece.data',
        'uvg' => 'image/vnd.dece.graphic',
        'uvh' => 'video/vnd.dece.hd',
        'uvi' => 'image/vnd.dece.graphic',
        'uvm' => 'video/vnd.dece.mobile',
        'uvp' => 'video/vnd.dece.pd',
        'uvs' => 'video/vnd.dece.sd',
        'uvt' => 'application/vnd.dece.ttml+xml',
        'uvu' => 'video/vnd.uvvu.mp4',
        'uvv' => 'video/vnd.dece.video',
        'uvva' => 'audio/vnd.dece.audio',
        'uvvd' => 'application/vnd.dece.data',
        'uvvf' => 'application/vnd.dece.data',
        'uvvg' => 'image/vnd.dece.graphic',
        'uvvh' => 'video/vnd.dece.hd',
        'uvvi' => 'image/vnd.dece.graphic',
        'uvvm' => 'video/vnd.dece.mobile',
        'uvvp' => 'video/vnd.dece.pd',
        'uvvs' => 'video/vnd.dece.sd',
        'uvvt' => 'application/vnd.dece.ttml+xml',
        'uvvu' => 'video/vnd.uvvu.mp4',
        'uvvv' => 'video/vnd.dece.video',
        'uvvx' => 'application/vnd.dece.unspecified',
        'uvx' => 'application/vnd.dece.unspecified',
        'vcd' => 'application/x-cdlink',
        'vcf' => 'text/x-vcard',
        'vcg' => 'application/vnd.groove-vcard',
        'vcs' => 'text/x-vcalendar',
        'vcx' => 'application/vnd.vcx',
        'vis' => 'application/vnd.visionary',
        'viv' => 'video/vnd.vivo',
        'vor' => 'application/vnd.stardivision.writer',
        'vox' => 'application/x-authorware-bin',
        'vrml' => 'model/vrml',
        'vsd' => 'application/vnd.visio',
        'vsf' => 'application/vnd.vsf',
        'vss' => 'application/vnd.visio',
        'vst' => 'application/vnd.visio',
        'vsw' => 'application/vnd.visio',
        'vtu' => 'model/vnd.vtu',
        'vxml' => 'application/voicexml+xml',
        'w3d' => 'application/x-director',
        'wad' => 'application/x-doom',
        'wav' => 'audio/x-wav',
        'wax' => 'audio/x-ms-wax',
        'wbmp' => 'image/vnd.wap.wbmp',
        'wbs' => 'application/vnd.criticaltools.wbs+xml',
        'wbxml' => 'application/vnd.wap.wbxml',
        'wcm' => 'application/vnd.ms-works',
        'wdb' => 'application/vnd.ms-works',
        'weba' => 'audio/webm',
        'webm' => 'video/webm',
        'webp' => 'image/webp',
        'wg' => 'application/vnd.pmi.widget',
        'wgt' => 'application/widget',
        'wks' => 'application/vnd.ms-works',
        'wm' => 'video/x-ms-wm',
        'wma' => 'audio/x-ms-wma',
        'wmd' => 'application/x-ms-wmd',
        'wmf' => 'application/x-msmetafile',
        'wml' => 'text/vnd.wap.wml',
        'wmlc' => 'application/vnd.wap.wmlc',
        'wmls' => 'text/vnd.wap.wmlscript',
        'wmlsc' => 'application/vnd.wap.wmlscriptc',
        'wmv' => 'video/x-ms-wmv',
        'wmx' => 'video/x-ms-wmx',
        'wmz' => 'application/x-ms-wmz',
        'woff' => 'application/x-font-woff',
        'wpd' => 'application/vnd.wordperfect',
        'wpl' => 'application/vnd.ms-wpl',
        'wps' => 'application/vnd.ms-works',
        'wqd' => 'application/vnd.wqd',
        'wri' => 'application/x-mswrite',
        'wrl' => 'model/vrml',
        'wsdl' => 'application/wsdl+xml',
        'wspolicy' => 'application/wspolicy+xml',
        'wtb' => 'application/vnd.webturbo',
        'wvx' => 'video/x-ms-wvx',
        'x32' => 'application/x-authorware-bin',
        'x3d' => 'application/vnd.hzn-3d-crossword',
        'xap' => 'application/x-silverlight-app',
        'xar' => 'application/vnd.xara',
        'xbap' => 'application/x-ms-xbap',
        'xbd' => 'application/vnd.fujixerox.docuworks.binder',
        'xbm' => 'image/x-xbitmap',
        'xdf' => 'application/xcap-diff+xml',
        'xdm' => 'application/vnd.syncml.dm+xml',
        'xdp' => 'application/vnd.adobe.xdp+xml',
        'xdssc' => 'application/dssc+xml',
        'xdw' => 'application/vnd.fujixerox.docuworks',
        'xenc' => 'application/xenc+xml',
        'xer' => 'application/patch-ops-error+xml',
        'xfdf' => 'application/vnd.adobe.xfdf',
        'xfdl' => 'application/vnd.xfdl',
        'xht' => 'application/xhtml+xml',
        'xhtml' => 'application/xhtml+xml',
        'xhvml' => 'application/xv+xml',
        'xif' => 'image/vnd.xiff',
        'xla' => 'application/vnd.ms-excel',
        'xlam' => 'application/vnd.ms-excel.addin.macroenabled.12',
        'xlc' => 'application/vnd.ms-excel',
        'xlm' => 'application/vnd.ms-excel',
        'xls' => 'application/vnd.ms-excel',
        'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroenabled.12',
        'xlsm' => 'application/vnd.ms-excel.sheet.macroenabled.12',
        'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        'xlt' => 'application/vnd.ms-excel',
        'xltm' => 'application/vnd.ms-excel.template.macroenabled.12',
        'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
        'xlw' => 'application/vnd.ms-excel',
        'xml' => 'application/xml',
        'xo' => 'application/vnd.olpc-sugar',
        'xop' => 'application/xop+xml',
        'xpi' => 'application/x-xpinstall',
        'xpm' => 'image/x-xpixmap',
        'xpr' => 'application/vnd.is-xpr',
        'xps' => 'application/vnd.ms-xpsdocument',
        'xpw' => 'application/vnd.intercon.formnet',
        'xpx' => 'application/vnd.intercon.formnet',
        'xsl' => 'application/xml',
        'xslt' => 'application/xslt+xml',
        'xsm' => 'application/vnd.syncml+xml',
        'xspf' => 'application/xspf+xml',
        'xul' => 'application/vnd.mozilla.xul+xml',
        'xvm' => 'application/xv+xml',
        'xvml' => 'application/xv+xml',
        'xwd' => 'image/x-xwindowdump',
        'xyz' => 'chemical/x-xyz',
        'yaml' => 'text/yaml',
        'yang' => 'application/yang',
        'yin' => 'application/yin+xml',
        'yml' => 'text/yaml',
        'zaz' => 'application/vnd.zzazz.deck+xml',
        'zip' => 'application/zip',
        'zir' => 'application/vnd.zul',
        'zirz' => 'application/vnd.zul',
        'zmm' => 'application/vnd.handheld-entertainment+xml'
    );

    /**
     * Get a singleton instance of the class
     *
     * @return self
     * @codeCoverageIgnore
     */
    public static function getInstance()
    {
        if (!self::$instance) {
            self::$instance = new self();
        }

        return self::$instance;
    }

    /**
     * Get a mimetype value from a file extension
     *
     * @param string $extension File extension
     *
     * @return string|null
     *
     */
    public function fromExtension($extension)
    {
        $extension = strtolower($extension);

        return isset($this->mimetypes[$extension]) ? $this->mimetypes[$extension] : null;
    }

    /**
     * Get a mimetype from a filename
     *
     * @param string $filename Filename to generate a mimetype from
     *
     * @return string|null
     */
    public function fromFilename($filename)
    {
        return $this->fromExtension(pathinfo($filename, PATHINFO_EXTENSION));
    }
}
<?php

namespace Guzzle\Http;

use Guzzle\Stream\Stream;

/**
 * Abstract decorator used to wrap entity bodies
 */
class AbstractEntityBodyDecorator implements EntityBodyInterface
{
    /** @var EntityBodyInterface Decorated entity body */
    protected $body;

    /**
     * @param EntityBodyInterface $body Entity body to decorate
     */
    public function __construct(EntityBodyInterface $body)
    {
        $this->body = $body;
    }

    public function __toString()
    {
        return (string) $this->body;
    }

    /**
     * Allow decorators to implement custom methods
     *
     * @param string $method Missing method name
     * @param array  $args   Method arguments
     *
     * @return mixed
     */
    public function __call($method, array $args)
    {
        return call_user_func_array(array($this->body, $method), $args);
    }

    public function close()
    {
        return $this->body->close();
    }

    public function setRewindFunction($callable)
    {
        $this->body->setRewindFunction($callable);

        return $this;
    }

    public function rewind()
    {
        return $this->body->rewind();
    }

    public function compress($filter = 'zlib.deflate')
    {
        return $this->body->compress($filter);
    }

    public function uncompress($filter = 'zlib.inflate')
    {
        return $this->body->uncompress($filter);
    }

    public function getContentLength()
    {
        return $this->getSize();
    }

    public function getContentType()
    {
        return $this->body->getContentType();
    }

    public function getContentMd5($rawOutput = false, $base64Encode = false)
    {
        $hash = Stream::getHash($this, 'md5', $rawOutput);

        return $hash && $base64Encode ? base64_encode($hash) : $hash;
    }

    public function getContentEncoding()
    {
        return $this->body->getContentEncoding();
    }

    public function getMetaData($key = null)
    {
        return $this->body->getMetaData($key);
    }

    public function getStream()
    {
        return $this->body->getStream();
    }

    public function setStream($stream, $size = 0)
    {
        $this->body->setStream($stream, $size);

        return $this;
    }

    public function detachStream()
    {
        $this->body->detachStream();

        return $this;
    }

    public function getWrapper()
    {
        return $this->body->getWrapper();
    }

    public function getWrapperData()
    {
        return $this->body->getWrapperData();
    }

    public function getStreamType()
    {
        return $this->body->getStreamType();
    }

    public function getUri()
    {
        return $this->body->getUri();
    }

    public function getSize()
    {
        return $this->body->getSize();
    }

    public function isReadable()
    {
        return $this->body->isReadable();
    }

    public function isRepeatable()
    {
        return $this->isSeekable() && $this->isReadable();
    }

    public function isWritable()
    {
        return $this->body->isWritable();
    }

    public function isConsumed()
    {
        return $this->body->isConsumed();
    }

    /**
     * Alias of isConsumed()
     * {@inheritdoc}
     */
    public function feof()
    {
        return $this->isConsumed();
    }

    public function isLocal()
    {
        return $this->body->isLocal();
    }

    public function isSeekable()
    {
        return $this->body->isSeekable();
    }

    public function setSize($size)
    {
        $this->body->setSize($size);

        return $this;
    }

    public function seek($offset, $whence = SEEK_SET)
    {
        return $this->body->seek($offset, $whence);
    }

    public function read($length)
    {
        return $this->body->read($length);
    }

    public function write($string)
    {
        return $this->body->write($string);
    }

    public function readLine($maxLength = null)
    {
        return $this->body->readLine($maxLength);
    }

    public function ftell()
    {
        return $this->body->ftell();
    }

    public function getCustomData($key)
    {
        return $this->body->getCustomData($key);
    }

    public function setCustomData($key, $value)
    {
        $this->body->setCustomData($key, $value);

        return $this;
    }
}
<?php

namespace Guzzle\Http;

use Guzzle\Http\Client;
use Guzzle\Http\ClientInterface;
use Guzzle\Stream\StreamRequestFactoryInterface;
use Guzzle\Stream\PhpStreamRequestFactory;

/**
 * Simplified interface to Guzzle that does not require a class to be instantiated
 */
final class StaticClient
{
    /** @var Client Guzzle client */
    private static $client;

    /**
     * Mount the client to a simpler class name for a specific client
     *
     * @param string          $className Class name to use to mount
     * @param ClientInterface $client    Client used to send requests
     */
    public static function mount($className = 'Guzzle', ClientInterface $client = null)
    {
        class_alias(__CLASS__, $className);
        if ($client) {
            self::$client = $client;
        }
    }

    /**
     * @param  string $method  HTTP request method (GET, POST, HEAD, DELETE, PUT, etc)
     * @param  string $url     URL of the request
     * @param  array  $options Options to use with the request. See: Guzzle\Http\Message\RequestFactory::applyOptions()
     * @return \Guzzle\Http\Message\Response|\Guzzle\Stream\Stream
     */
    public static function request($method, $url, $options = array())
    {
        // @codeCoverageIgnoreStart
        if (!self::$client) {
            self::$client = new Client();
        }
        // @codeCoverageIgnoreEnd

        $request = self::$client->createRequest($method, $url, null, null, $options);

        if (isset($options['stream'])) {
            if ($options['stream'] instanceof StreamRequestFactoryInterface) {
                return $options['stream']->fromRequest($request);
            } elseif ($options['stream'] == true) {
                $streamFactory = new PhpStreamRequestFactory();
                return $streamFactory->fromRequest($request);
            }
        }

        return $request->send();
    }

    /**
     * Send a GET request
     *
     * @param string $url     URL of the request
     * @param array  $options Array of request options
     *
     * @return \Guzzle\Http\Message\Response
     * @see Guzzle::request for a list of available options
     */
    public static function get($url, $options = array())
    {
        return self::request('GET', $url, $options);
    }

    /**
     * Send a HEAD request
     *
     * @param string $url     URL of the request
     * @param array  $options Array of request options
     *
     * @return \Guzzle\Http\Message\Response
     * @see Guzzle::request for a list of available options
     */
    public static function head($url, $options = array())
    {
        return self::request('HEAD', $url, $options);
    }

    /**
     * Send a DELETE request
     *
     * @param string $url     URL of the request
     * @param array  $options Array of request options
     *
     * @return \Guzzle\Http\Message\Response
     * @see Guzzle::request for a list of available options
     */
    public static function delete($url, $options = array())
    {
        return self::request('DELETE', $url, $options);
    }

    /**
     * Send a POST request
     *
     * @param string $url     URL of the request
     * @param array  $options Array of request options
     *
     * @return \Guzzle\Http\Message\Response
     * @see Guzzle::request for a list of available options
     */
    public static function post($url, $options = array())
    {
        return self::request('POST', $url, $options);
    }

    /**
     * Send a PUT request
     *
     * @param string $url     URL of the request
     * @param array  $options Array of request options
     *
     * @return \Guzzle\Http\Message\Response
     * @see Guzzle::request for a list of available options
     */
    public static function put($url, $options = array())
    {
        return self::request('PUT', $url, $options);
    }

    /**
     * Send a PATCH request
     *
     * @param string $url     URL of the request
     * @param array  $options Array of request options
     *
     * @return \Guzzle\Http\Message\Response
     * @see Guzzle::request for a list of available options
     */
    public static function patch($url, $options = array())
    {
        return self::request('PATCH', $url, $options);
    }

    /**
     * Send an OPTIONS request
     *
     * @param string $url     URL of the request
     * @param array  $options Array of request options
     *
     * @return \Guzzle\Http\Message\Response
     * @see Guzzle::request for a list of available options
     */
    public static function options($url, $options = array())
    {
        return self::request('OPTIONS', $url, $options);
    }
}
<?php

namespace Guzzle\Http;

use Guzzle\Common\Collection;
use Guzzle\Common\Exception\RuntimeException;
use Guzzle\Http\QueryAggregator\DuplicateAggregator;
use Guzzle\Http\QueryAggregator\QueryAggregatorInterface;
use Guzzle\Http\QueryAggregator\PhpAggregator;

/**
 * Query string object to handle managing query string parameters and aggregating those parameters together as a string.
 */
class QueryString extends Collection
{
    /** @var string Used to URL encode with rawurlencode */
    const RFC_3986 = 'RFC 3986';

    /** @var string Used to encode with urlencode */
    const FORM_URLENCODED = 'application/x-www-form-urlencoded';

    /** @var string Constant used to create blank query string values (e.g. ?foo) */
    const BLANK = "_guzzle_blank_";

    /** @var string The query string field separator (e.g. '&') */
    protected $fieldSeparator = '&';

    /** @var string The query string value separator (e.g. '=') */
    protected $valueSeparator = '=';

    /** @var bool URL encode fields and values */
    protected $urlEncode = 'RFC 3986';

    /** @var QueryAggregatorInterface */
    protected $aggregator;

    /** @var array Cached PHP aggregator */
    private static $defaultAggregator = null;

    /**
     * Parse a query string into a QueryString object
     *
     * @param string $query Query string to parse
     *
     * @return self
     */
    public static function fromString($query)
    {
        $q = new static();
        if ($query === '') {
            return $q;
        }

        $foundDuplicates = $foundPhpStyle = false;

        foreach (explode('&', $query) as $kvp) {
            $parts = explode('=', $kvp, 2);
            $key = rawurldecode($parts[0]);
            if ($paramIsPhpStyleArray = substr($key, -2) == '[]') {
                $foundPhpStyle = true;
                $key = substr($key, 0, -2);
            }
            if (isset($parts[1])) {
                $value = rawurldecode(str_replace('+', '%20', $parts[1]));
                if (isset($q[$key])) {
                    $q->add($key, $value);
                    $foundDuplicates = true;
                } elseif ($paramIsPhpStyleArray) {
                    $q[$key] = array($value);
                } else {
                    $q[$key] = $value;
                }
            } else {
                // Uses false by default to represent keys with no trailing "=" sign.
                $q->add($key, false);
            }
        }

        // Use the duplicate aggregator if duplicates were found and not using PHP style arrays
        if ($foundDuplicates && !$foundPhpStyle) {
            $q->setAggregator(new DuplicateAggregator());
        }

        return $q;
    }

    /**
     * Convert the query string parameters to a query string string
     *
     * @return string
     * @throws RuntimeException
     */
    public function __toString()
    {
        if (!$this->data) {
            return '';
        }

        $queryList = array();
        foreach ($this->prepareData($this->data) as $name => $value) {
            $queryList[] = $this->convertKvp($name, $value);
        }

        return implode($this->fieldSeparator, $queryList);
    }

    /**
     * Get the query string field separator
     *
     * @return string
     */
    public function getFieldSeparator()
    {
        return $this->fieldSeparator;
    }

    /**
     * Get the query string value separator
     *
     * @return string
     */
    public function getValueSeparator()
    {
        return $this->valueSeparator;
    }

    /**
     * Returns the type of URL encoding used by the query string
     *
     * One of: false, "RFC 3986", or "application/x-www-form-urlencoded"
     *
     * @return bool|string
     */
    public function getUrlEncoding()
    {
        return $this->urlEncode;
    }

    /**
     * Returns true or false if using URL encoding
     *
     * @return bool
     */
    public function isUrlEncoding()
    {
        return $this->urlEncode !== false;
    }

    /**
     * Provide a function for combining multi-valued query string parameters into a single or multiple fields
     *
     * @param null|QueryAggregatorInterface $aggregator Pass in a QueryAggregatorInterface object to handle converting
     *                                                  deeply nested query string variables into a flattened array.
     *                                                  Pass null to use the default PHP style aggregator. For legacy
     *                                                  reasons, this function accepts a callable that must accepts a
     *                                                  $key, $value, and query object.
     * @return self
     * @see \Guzzle\Http\QueryString::aggregateUsingComma()
     */
    public function setAggregator(QueryAggregatorInterface $aggregator = null)
    {
        // Use the default aggregator if none was set
        if (!$aggregator) {
            if (!self::$defaultAggregator) {
                self::$defaultAggregator = new PhpAggregator();
            }
            $aggregator = self::$defaultAggregator;
        }

        $this->aggregator = $aggregator;

        return $this;
    }

    /**
     * Set whether or not field names and values should be rawurlencoded
     *
     * @param bool|string $encode Set to TRUE to use RFC 3986 encoding (rawurlencode), false to disable encoding, or
     *                            form_urlencoding to use application/x-www-form-urlencoded encoding (urlencode)
     * @return self
     */
    public function useUrlEncoding($encode)
    {
        $this->urlEncode = ($encode === true) ? self::RFC_3986 : $encode;

        return $this;
    }

    /**
     * Set the query string separator
     *
     * @param string $separator The query string separator that will separate fields
     *
     * @return self
     */
    public function setFieldSeparator($separator)
    {
        $this->fieldSeparator = $separator;

        return $this;
    }

    /**
     * Set the query string value separator
     *
     * @param string $separator The query string separator that will separate values from fields
     *
     * @return self
     */
    public function setValueSeparator($separator)
    {
        $this->valueSeparator = $separator;

        return $this;
    }

    /**
     * Returns an array of url encoded field names and values
     *
     * @return array
     */
    public function urlEncode()
    {
        return $this->prepareData($this->data);
    }

    /**
     * URL encodes a value based on the url encoding type of the query string object
     *
     * @param string $value Value to encode
     *
     * @return string
     */
    public function encodeValue($value)
    {
        if ($this->urlEncode == self::RFC_3986) {
            return rawurlencode($value);
        } elseif ($this->urlEncode == self::FORM_URLENCODED) {
            return urlencode($value);
        } else {
            return (string) $value;
        }
    }

    /**
     * Url encode parameter data and convert nested query strings into a flattened hash.
     *
     * @param array $data The data to encode
     *
     * @return array Returns an array of encoded values and keys
     */
    protected function prepareData(array $data)
    {
        // If no aggregator is present then set the default
        if (!$this->aggregator) {
            $this->setAggregator(null);
        }

        $temp = array();
        foreach ($data as $key => $value) {
            if ($value === false || $value === null) {
                // False and null will not include the "=". Use an empty string to include the "=".
                $temp[$this->encodeValue($key)] = $value;
            } elseif (is_array($value)) {
                $temp = array_merge($temp, $this->aggregator->aggregate($key, $value, $this));
            } else {
                $temp[$this->encodeValue($key)] = $this->encodeValue($value);
            }
        }

        return $temp;
    }

    /**
     * Converts a key value pair that can contain strings, nulls, false, or arrays
     * into a single string.
     *
     * @param string $name  Name of the field
     * @param mixed  $value Value of the field
     * @return string
     */
    private function convertKvp($name, $value)
    {
        if ($value === self::BLANK || $value === null || $value === false) {
            return $name;
        } elseif (!is_array($value)) {
            return $name . $this->valueSeparator . $value;
        }

        $result = '';
        foreach ($value as $v) {
            $result .= $this->convertKvp($name, $v) . $this->fieldSeparator;
        }

        return rtrim($result, $this->fieldSeparator);
    }
}
<?php

namespace Guzzle\Http\Curl;

use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Common\Exception\RuntimeException;
use Guzzle\Common\Collection;
use Guzzle\Http\Message\EntityEnclosingRequest;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Parser\ParserRegistry;
use Guzzle\Http\Url;

/**
 * Immutable wrapper for a cURL handle
 */
class CurlHandle
{
    const BODY_AS_STRING = 'body_as_string';
    const PROGRESS = 'progress';
    const DEBUG = 'debug';

    /** @var Collection Curl options */
    protected $options;

    /** @var resource Curl resource handle */
    protected $handle;

    /** @var int CURLE_* error */
    protected $errorNo = CURLE_OK;

    /**
     * Factory method to create a new curl handle based on an HTTP request.
     *
     * There are some helpful options you can set to enable specific behavior:
     * - debug:    Set to true to enable cURL debug functionality to track the actual headers sent over the wire.
     * - progress: Set to true to enable progress function callbacks.
     *
     * @param RequestInterface $request Request
     *
     * @return CurlHandle
     * @throws RuntimeException
     */
    public static function factory(RequestInterface $request)
    {
        $requestCurlOptions = $request->getCurlOptions();
        $mediator = new RequestMediator($request, $requestCurlOptions->get('emit_io'));
        $tempContentLength = null;
        $method = $request->getMethod();
        $bodyAsString = $requestCurlOptions->get(self::BODY_AS_STRING);

        // Prepare url
        $url = (string)$request->getUrl();
        if(($pos = strpos($url, '#')) !== false ){
            // strip fragment from url
            $url = substr($url, 0, $pos);
        }

        // Array of default cURL options.
        $curlOptions = array(
            CURLOPT_URL            => $url,
            CURLOPT_CONNECTTIMEOUT => 150,
            CURLOPT_RETURNTRANSFER => false,
            CURLOPT_HEADER         => false,
            CURLOPT_PORT           => $request->getPort(),
            CURLOPT_HTTPHEADER     => array(),
            CURLOPT_WRITEFUNCTION  => array($mediator, 'writeResponseBody'),
            CURLOPT_HEADERFUNCTION => array($mediator, 'receiveResponseHeader'),
            CURLOPT_HTTP_VERSION   => $request->getProtocolVersion() === '1.0'
                ? CURL_HTTP_VERSION_1_0 : CURL_HTTP_VERSION_1_1,
            // Verifies the authenticity of the peer's certificate
            CURLOPT_SSL_VERIFYPEER => 1,
            // Certificate must indicate that the server is the server to which you meant to connect
            CURLOPT_SSL_VERIFYHOST => 2
        );

        if (defined('CURLOPT_PROTOCOLS')) {
            // Allow only HTTP and HTTPS protocols
            $curlOptions[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
        }

        // Add CURLOPT_ENCODING if Accept-Encoding header is provided
        if ($acceptEncodingHeader = $request->getHeader('Accept-Encoding')) {
            $curlOptions[CURLOPT_ENCODING] = (string) $acceptEncodingHeader;
            // Let cURL set the Accept-Encoding header, prevents duplicate values
            $request->removeHeader('Accept-Encoding');
        }

        // Enable curl debug information if the 'debug' param was set
        if ($requestCurlOptions->get('debug')) {
            $curlOptions[CURLOPT_STDERR] = fopen('php://temp', 'r+');
            // @codeCoverageIgnoreStart
            if (false === $curlOptions[CURLOPT_STDERR]) {
                throw new RuntimeException('Unable to create a stream for CURLOPT_STDERR');
            }
            // @codeCoverageIgnoreEnd
            $curlOptions[CURLOPT_VERBOSE] = true;
        }

        // Specify settings according to the HTTP method
        if ($method == 'GET') {
            $curlOptions[CURLOPT_HTTPGET] = true;
        } elseif ($method == 'HEAD') {
            $curlOptions[CURLOPT_NOBODY] = true;
            // HEAD requests do not use a write function
            unset($curlOptions[CURLOPT_WRITEFUNCTION]);
        } elseif (!($request instanceof EntityEnclosingRequest)) {
            $curlOptions[CURLOPT_CUSTOMREQUEST] = $method;
        } else {

            $curlOptions[CURLOPT_CUSTOMREQUEST] = $method;

            // Handle sending raw bodies in a request
            if ($request->getBody()) {
                // You can send the body as a string using curl's CURLOPT_POSTFIELDS
                if ($bodyAsString) {
                    $curlOptions[CURLOPT_POSTFIELDS] = (string) $request->getBody();
                    // Allow curl to add the Content-Length for us to account for the times when
                    // POST redirects are followed by GET requests
                    if ($tempContentLength = $request->getHeader('Content-Length')) {
                        $tempContentLength = (int) (string) $tempContentLength;
                    }
                    // Remove the curl generated Content-Type header if none was set manually
                    if (!$request->hasHeader('Content-Type')) {
                        $curlOptions[CURLOPT_HTTPHEADER][] = 'Content-Type:';
                    }
                } else {
                    $curlOptions[CURLOPT_UPLOAD] = true;
                    // Let cURL handle setting the Content-Length header
                    if ($tempContentLength = $request->getHeader('Content-Length')) {
                        $tempContentLength = (int) (string) $tempContentLength;
                        $curlOptions[CURLOPT_INFILESIZE] = $tempContentLength;
                    }
                    // Add a callback for curl to read data to send with the request only if a body was specified
                    $curlOptions[CURLOPT_READFUNCTION] = array($mediator, 'readRequestBody');
                    // Attempt to seek to the start of the stream
                    $request->getBody()->seek(0);
                }

            } else {

                // Special handling for POST specific fields and files
                $postFields = false;
                if (count($request->getPostFiles())) {
                    $postFields = $request->getPostFields()->useUrlEncoding(false)->urlEncode();
                    foreach ($request->getPostFiles() as $key => $data) {
                        $prefixKeys = count($data) > 1;
                        foreach ($data as $index => $file) {
                            // Allow multiple files in the same key
                            $fieldKey = $prefixKeys ? "{$key}[{$index}]" : $key;
                            $postFields[$fieldKey] = $file->getCurlValue();
                        }
                    }
                } elseif (count($request->getPostFields())) {
                    $postFields = (string) $request->getPostFields()->useUrlEncoding(true);
                }

                if ($postFields !== false) {
                    if ($method == 'POST') {
                        unset($curlOptions[CURLOPT_CUSTOMREQUEST]);
                        $curlOptions[CURLOPT_POST] = true;
                    }
                    $curlOptions[CURLOPT_POSTFIELDS] = $postFields;
                    $request->removeHeader('Content-Length');
                }
            }

            // If the Expect header is not present, prevent curl from adding it
            if (!$request->hasHeader('Expect')) {
                $curlOptions[CURLOPT_HTTPHEADER][] = 'Expect:';
            }
        }

        // If a Content-Length header was specified but we want to allow curl to set one for us
        if (null !== $tempContentLength) {
            $request->removeHeader('Content-Length');
        }

        // Set custom cURL options
        foreach ($requestCurlOptions->toArray() as $key => $value) {
            if (is_numeric($key)) {
                $curlOptions[$key] = $value;
            }
        }

        // Do not set an Accept header by default
        if (!isset($curlOptions[CURLOPT_ENCODING])) {
            $curlOptions[CURLOPT_HTTPHEADER][] = 'Accept:';
        }

        // Add any custom headers to the request. Empty headers will cause curl to not send the header at all.
        foreach ($request->getHeaderLines() as $line) {
            $curlOptions[CURLOPT_HTTPHEADER][] = $line;
        }

        // Add the content-length header back if it was temporarily removed
        if (null !== $tempContentLength) {
            $request->setHeader('Content-Length', $tempContentLength);
        }

        // Apply the options to a new cURL handle.
        $handle = curl_init();

        // Enable the progress function if the 'progress' param was set
        if ($requestCurlOptions->get('progress')) {
            // Wrap the function in a function that provides the curl handle to the mediator's progress function
            // Using this rather than injecting the handle into the mediator prevents a circular reference
            $curlOptions[CURLOPT_PROGRESSFUNCTION] = function () use ($mediator, $handle) {
                $args = func_get_args();
                $args[] = $handle;

                // PHP 5.5 pushed the handle onto the start of the args
                if (is_resource($args[0])) {
                    array_shift($args);
                }

                call_user_func_array(array($mediator, 'progress'), $args);
            };
            $curlOptions[CURLOPT_NOPROGRESS] = false;
        }

        curl_setopt_array($handle, $curlOptions);

        return new static($handle, $curlOptions);
    }

    /**
     * Construct a new CurlHandle object that wraps a cURL handle
     *
     * @param resource         $handle  Configured cURL handle resource
     * @param Collection|array $options Curl options to use with the handle
     *
     * @throws InvalidArgumentException
     */
    public function __construct($handle, $options)
    {
        if (!is_resource($handle)) {
            throw new InvalidArgumentException('Invalid handle provided');
        }
        if (is_array($options)) {
            $this->options = new Collection($options);
        } elseif ($options instanceof Collection) {
            $this->options = $options;
        } else {
            throw new InvalidArgumentException('Expected array or Collection');
        }
        $this->handle = $handle;
    }

    /**
     * Destructor
     */
    public function __destruct()
    {
        $this->close();
    }

    /**
     * Close the curl handle
     */
    public function close()
    {
        if (is_resource($this->handle)) {
            curl_close($this->handle);
        }
        $this->handle = null;
    }

    /**
     * Check if the handle is available and still OK
     *
     * @return bool
     */
    public function isAvailable()
    {
        return is_resource($this->handle);
    }

    /**
     * Get the last error that occurred on the cURL handle
     *
     * @return string
     */
    public function getError()
    {
        return $this->isAvailable() ? curl_error($this->handle) : '';
    }

    /**
     * Get the last error number that occurred on the cURL handle
     *
     * @return int
     */
    public function getErrorNo()
    {
        if ($this->errorNo) {
            return $this->errorNo;
        }

        return $this->isAvailable() ? curl_errno($this->handle) : CURLE_OK;
    }

    /**
     * Set the curl error number
     *
     * @param int $error Error number to set
     *
     * @return CurlHandle
     */
    public function setErrorNo($error)
    {
        $this->errorNo = $error;

        return $this;
    }

    /**
     * Get cURL curl_getinfo data
     *
     * @param int $option Option to retrieve. Pass null to retrieve all data as an array.
     *
     * @return array|mixed
     */
    public function getInfo($option = null)
    {
        if (!is_resource($this->handle)) {
            return null;
        }

        if (null !== $option) {
            return curl_getinfo($this->handle, $option) ?: null;
        }

        return curl_getinfo($this->handle) ?: array();
    }

    /**
     * Get the stderr output
     *
     * @param bool $asResource Set to TRUE to get an fopen resource
     *
     * @return string|resource|null
     */
    public function getStderr($asResource = false)
    {
        $stderr = $this->getOptions()->get(CURLOPT_STDERR);
        if (!$stderr) {
            return null;
        }

        if ($asResource) {
            return $stderr;
        }

        fseek($stderr, 0);
        $e = stream_get_contents($stderr);
        fseek($stderr, 0, SEEK_END);

        return $e;
    }

    /**
     * Get the URL that this handle is connecting to
     *
     * @return Url
     */
    public function getUrl()
    {
        return Url::factory($this->options->get(CURLOPT_URL));
    }

    /**
     * Get the wrapped curl handle
     *
     * @return resource|null Returns the cURL handle or null if it was closed
     */
    public function getHandle()
    {
        return $this->isAvailable() ? $this->handle : null;
    }

    /**
     * Get the cURL setopt options of the handle. Changing values in the return object will have no effect on the curl
     * handle after it is created.
     *
     * @return Collection
     */
    public function getOptions()
    {
        return $this->options;
    }

    /**
     * Update a request based on the log messages of the CurlHandle
     *
     * @param RequestInterface $request Request to update
     */
    public function updateRequestFromTransfer(RequestInterface $request)
    {
        if (!$request->getResponse()) {
            return;
        }

        // Update the transfer stats of the response
        $request->getResponse()->setInfo($this->getInfo());

        if (!$log = $this->getStderr(true)) {
            return;
        }

        // Parse the cURL stderr output for outgoing requests
        $headers = '';
        fseek($log, 0);
        while (($line = fgets($log)) !== false) {
            if ($line && $line[0] == '>') {
                $headers = substr(trim($line), 2) . "\r\n";
                while (($line = fgets($log)) !== false) {
                    if ($line[0] == '*' || $line[0] == '<') {
                        break;
                    } else {
                        $headers .= trim($line) . "\r\n";
                    }
                }
            }
        }

        // Add request headers to the request exactly as they were sent
        if ($headers) {
            $parsed = ParserRegistry::getInstance()->getParser('message')->parseRequest($headers);
            if (!empty($parsed['headers'])) {
                $request->setHeaders(array());
                foreach ($parsed['headers'] as $name => $value) {
                    $request->setHeader($name, $value);
                }
            }
            if (!empty($parsed['version'])) {
                $request->setProtocolVersion($parsed['version']);
            }
        }
    }

    /**
     * Parse the config and replace curl.* configurators into the constant based values so it can be used elsewhere
     *
     * @param array|Collection $config The configuration we want to parse
     *
     * @return array
     */
    public static function parseCurlConfig($config)
    {
        $curlOptions = array();
        foreach ($config as $key => $value) {
            if (is_string($key) && defined($key)) {
                // Convert constants represented as string to constant int values
                $key = constant($key);
            }
            if (is_string($value) && defined($value)) {
                $value = constant($value);
            }
            $curlOptions[$key] = $value;
        }

        return $curlOptions;
    }
}
<?php

namespace Guzzle\Http\Curl;

use Guzzle\Common\HasDispatcherInterface;
use Guzzle\Common\Exception\ExceptionCollection;
use Guzzle\Http\Message\RequestInterface;

/**
 * Interface for sending a pool of {@see RequestInterface} objects in parallel
 */
interface CurlMultiInterface extends \Countable, HasDispatcherInterface
{
    const POLLING_REQUEST = 'curl_multi.polling_request';
    const ADD_REQUEST = 'curl_multi.add_request';
    const REMOVE_REQUEST = 'curl_multi.remove_request';
    const MULTI_EXCEPTION = 'curl_multi.exception';
    const BLOCKING = 'curl_multi.blocking';

    /**
     * Add a request to the pool.
     *
     * @param RequestInterface $request Request to add
     *
     * @return CurlMultiInterface
     */
    public function add(RequestInterface $request);

    /**
     * Get an array of attached {@see RequestInterface} objects
     *
     * @return array
     */
    public function all();

    /**
     * Remove a request from the pool.
     *
     * @param RequestInterface $request Request to remove
     *
     * @return bool Returns true on success or false on failure
     */
    public function remove(RequestInterface $request);

    /**
     * Reset the state and remove any attached RequestInterface objects
     *
     * @param bool $hard Set to true to close and reopen any open multi handles
     */
    public function reset($hard = false);

    /**
     * Send a pool of {@see RequestInterface} requests.
     *
     * @throws ExceptionCollection if any requests threw exceptions during the transfer.
     */
    public function send();
}
<?php

namespace Guzzle\Http\Curl;

use Guzzle\Common\AbstractHasDispatcher;
use Guzzle\Common\Event;
use Guzzle\Http\Exception\MultiTransferException;
use Guzzle\Http\Exception\CurlException;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\EntityEnclosingRequestInterface;
use Guzzle\Http\Exception\RequestException;

/**
 * Send {@see RequestInterface} objects in parallel using curl_multi
 */
class CurlMulti extends AbstractHasDispatcher implements CurlMultiInterface
{
    /** @var resource cURL multi handle. */
    protected $multiHandle;

    /** @var array Attached {@see RequestInterface} objects. */
    protected $requests;

    /** @var \SplObjectStorage RequestInterface to CurlHandle hash */
    protected $handles;

    /** @var array Hash mapping curl handle resource IDs to request objects */
    protected $resourceHash;

    /** @var array Queued exceptions */
    protected $exceptions = array();

    /** @var array Requests that succeeded */
    protected $successful = array();

    /** @var array cURL multi error values and codes */
    protected $multiErrors = array(
        CURLM_BAD_HANDLE      => array('CURLM_BAD_HANDLE', 'The passed-in handle is not a valid CURLM handle.'),
        CURLM_BAD_EASY_HANDLE => array('CURLM_BAD_EASY_HANDLE', "An easy handle was not good/valid. It could mean that it isn't an easy handle at all, or possibly that the handle already is in used by this or another multi handle."),
        CURLM_OUT_OF_MEMORY   => array('CURLM_OUT_OF_MEMORY', 'You are doomed.'),
        CURLM_INTERNAL_ERROR  => array('CURLM_INTERNAL_ERROR', 'This can only be returned if libcurl bugs. Please report it to us!')
    );

    /** @var float */
    protected $selectTimeout;

    public function __construct($selectTimeout = 1.0)
    {
        $this->selectTimeout = $selectTimeout;
        $this->multiHandle = curl_multi_init();
        // @codeCoverageIgnoreStart
        if ($this->multiHandle === false) {
            throw new CurlException('Unable to create multi handle');
        }
        // @codeCoverageIgnoreEnd
        $this->reset();
    }

    public function __destruct()
    {
        if (is_resource($this->multiHandle)) {
            curl_multi_close($this->multiHandle);
        }
    }

    public function add(RequestInterface $request)
    {
        $this->requests[] = $request;
        // If requests are currently transferring and this is async, then the
        // request must be prepared now as the send() method is not called.
        $this->beforeSend($request);
        $this->dispatch(self::ADD_REQUEST, array('request' => $request));

        return $this;
    }

    public function all()
    {
        return $this->requests;
    }

    public function remove(RequestInterface $request)
    {
        $this->removeHandle($request);
        if (($index = array_search($request, $this->requests, true)) !== false) {
            $request = $this->requests[$index];
            unset($this->requests[$index]);
            $this->requests = array_values($this->requests);
            $this->dispatch(self::REMOVE_REQUEST, array('request' => $request));
            return true;
        }

        return false;
    }

    public function reset($hard = false)
    {
        // Remove each request
        if ($this->requests) {
            foreach ($this->requests as $request) {
                $this->remove($request);
            }
        }

        $this->handles = new \SplObjectStorage();
        $this->requests = $this->resourceHash = $this->exceptions = $this->successful = array();
    }

    public function send()
    {
        $this->perform();
        $exceptions = $this->exceptions;
        $successful = $this->successful;
        $this->reset();

        if ($exceptions) {
            $this->throwMultiException($exceptions, $successful);
        }
    }

    public function count()
    {
        return count($this->requests);
    }

    /**
     * Build and throw a MultiTransferException
     *
     * @param array $exceptions Exceptions encountered
     * @param array $successful Successful requests
     * @throws MultiTransferException
     */
    protected function throwMultiException(array $exceptions, array $successful)
    {
        $multiException = new MultiTransferException('Errors during multi transfer');

        while ($e = array_shift($exceptions)) {
            $multiException->addFailedRequestWithException($e['request'], $e['exception']);
        }

        // Add successful requests
        foreach ($successful as $request) {
            if (!$multiException->containsRequest($request)) {
                $multiException->addSuccessfulRequest($request);
            }
        }

        throw $multiException;
    }

    /**
     * Prepare for sending
     *
     * @param RequestInterface $request Request to prepare
     * @throws \Exception on error preparing the request
     */
    protected function beforeSend(RequestInterface $request)
    {
        try {
            $state = $request->setState(RequestInterface::STATE_TRANSFER);
            if ($state == RequestInterface::STATE_TRANSFER) {
                $this->addHandle($request);
            } else {
                // Requests might decide they don't need to be sent just before
                // transfer (e.g. CachePlugin)
                $this->remove($request);
                if ($state == RequestInterface::STATE_COMPLETE) {
                    $this->successful[] = $request;
                }
            }
        } catch (\Exception $e) {
            // Queue the exception to be thrown when sent
            $this->removeErroredRequest($request, $e);
        }
    }

    private function addHandle(RequestInterface $request)
    {
        $handle = $this->createCurlHandle($request)->getHandle();
        $this->checkCurlResult(
            curl_multi_add_handle($this->multiHandle, $handle)
        );
    }

    /**
     * Create a curl handle for a request
     *
     * @param RequestInterface $request Request
     *
     * @return CurlHandle
     */
    protected function createCurlHandle(RequestInterface $request)
    {
        $wrapper = CurlHandle::factory($request);
        $this->handles[$request] = $wrapper;
        $this->resourceHash[(int) $wrapper->getHandle()] = $request;

        return $wrapper;
    }

    /**
     * Get the data from the multi handle
     */
    protected function perform()
    {
        $event = new Event(array('curl_multi' => $this));

        while ($this->requests) {
            // Notify each request as polling
            $blocking = $total = 0;
            foreach ($this->requests as $request) {
                ++$total;
                $event['request'] = $request;
                $request->getEventDispatcher()->dispatch(self::POLLING_REQUEST, $event);
                // The blocking variable just has to be non-falsey to block the loop
                if ($request->getParams()->hasKey(self::BLOCKING)) {
                    ++$blocking;
                }
            }
            if ($blocking == $total) {
                // Sleep to prevent eating CPU because no requests are actually pending a select call
                usleep(500);
            } else {
                $this->executeHandles();
            }
        }
    }

    /**
     * Execute and select curl handles
     */
    private function executeHandles()
    {
        // The first curl_multi_select often times out no matter what, but is usually required for fast transfers
        $selectTimeout = 0.001;
        $active = false;
        do {
            while (($mrc = curl_multi_exec($this->multiHandle, $active)) == CURLM_CALL_MULTI_PERFORM);
            $this->checkCurlResult($mrc);
            $this->processMessages();
            if ($active && curl_multi_select($this->multiHandle, $selectTimeout) === -1) {
                // Perform a usleep if a select returns -1: https://bugs.php.net/bug.php?id=61141
                usleep(150);
            }
            $selectTimeout = $this->selectTimeout;
        } while ($active);
    }

    /**
     * Process any received curl multi messages
     */
    private function processMessages()
    {
        while ($done = curl_multi_info_read($this->multiHandle)) {
            $request = $this->resourceHash[(int) $done['handle']];
            try {
                $this->processResponse($request, $this->handles[$request], $done);
                $this->successful[] = $request;
            } catch (\Exception $e) {
                $this->removeErroredRequest($request, $e);
            }
        }
    }

    /**
     * Remove a request that encountered an exception
     *
     * @param RequestInterface $request Request to remove
     * @param \Exception       $e       Exception encountered
     */
    protected function removeErroredRequest(RequestInterface $request, \Exception $e = null)
    {
        $this->exceptions[] = array('request' => $request, 'exception' => $e);
        $this->remove($request);
        $this->dispatch(self::MULTI_EXCEPTION, array('exception' => $e, 'all_exceptions' => $this->exceptions));
    }

    /**
     * Check for errors and fix headers of a request based on a curl response
     *
     * @param RequestInterface $request Request to process
     * @param CurlHandle       $handle  Curl handle object
     * @param array            $curl    Array returned from curl_multi_info_read
     *
     * @throws CurlException on Curl error
     */
    protected function processResponse(RequestInterface $request, CurlHandle $handle, array $curl)
    {
        // Set the transfer stats on the response
        $handle->updateRequestFromTransfer($request);
        // Check if a cURL exception occurred, and if so, notify things
        $curlException = $this->isCurlException($request, $handle, $curl);

        // Always remove completed curl handles.  They can be added back again
        // via events if needed (e.g. ExponentialBackoffPlugin)
        $this->removeHandle($request);

        if (!$curlException) {
            if ($this->validateResponseWasSet($request)) {
                $state = $request->setState(
                    RequestInterface::STATE_COMPLETE,
                    array('handle' => $handle)
                );
                // Only remove the request if it wasn't resent as a result of
                // the state change
                if ($state != RequestInterface::STATE_TRANSFER) {
                    $this->remove($request);
                }
            }
            return;
        }

        // Set the state of the request to an error
        $state = $request->setState(RequestInterface::STATE_ERROR, array('exception' => $curlException));
        // Allow things to ignore the error if possible
        if ($state != RequestInterface::STATE_TRANSFER) {
            $this->remove($request);
        }

        // The error was not handled, so fail
        if ($state == RequestInterface::STATE_ERROR) {
            /** @var CurlException $curlException */
            throw $curlException;
        }
    }

    /**
     * Remove a curl handle from the curl multi object
     *
     * @param RequestInterface $request Request that owns the handle
     */
    protected function removeHandle(RequestInterface $request)
    {
        if (isset($this->handles[$request])) {
            $handle = $this->handles[$request];
            curl_multi_remove_handle($this->multiHandle, $handle->getHandle());
            unset($this->handles[$request]);
            unset($this->resourceHash[(int) $handle->getHandle()]);
            $handle->close();
        }
    }

    /**
     * Check if a cURL transfer resulted in what should be an exception
     *
     * @param RequestInterface $request Request to check
     * @param CurlHandle       $handle  Curl handle object
     * @param array            $curl    Array returned from curl_multi_info_read
     *
     * @return CurlException|bool
     */
    private function isCurlException(RequestInterface $request, CurlHandle $handle, array $curl)
    {
        if (CURLM_OK == $curl['result'] || CURLM_CALL_MULTI_PERFORM == $curl['result']) {
            return false;
        }

        $handle->setErrorNo($curl['result']);
        $e = new CurlException(sprintf('[curl] %s: %s [url] %s',
            $handle->getErrorNo(), $handle->getError(), $handle->getUrl()));
        $e->setCurlHandle($handle)
            ->setRequest($request)
            ->setCurlInfo($handle->getInfo())
            ->setError($handle->getError(), $handle->getErrorNo());

        return $e;
    }

    /**
     * Throw an exception for a cURL multi response if needed
     *
     * @param int $code Curl response code
     * @throws CurlException
     */
    private function checkCurlResult($code)
    {
        if ($code != CURLM_OK && $code != CURLM_CALL_MULTI_PERFORM) {
            throw new CurlException(isset($this->multiErrors[$code])
                ? "cURL error: {$code} ({$this->multiErrors[$code][0]}): cURL message: {$this->multiErrors[$code][1]}"
                : 'Unexpected cURL error: ' . $code
            );
        }
    }

    /**
     * @link https://github.com/guzzle/guzzle/issues/710
     */
    private function validateResponseWasSet(RequestInterface $request)
    {
        if ($request->getResponse()) {
            return true;
        }

        $body = $request instanceof EntityEnclosingRequestInterface
            ? $request->getBody()
            : null;

        if (!$body) {
            $rex = new RequestException(
                'No response was received for a request with no body. This'
                . ' could mean that you are saturating your network.'
            );
            $rex->setRequest($request);
            $this->removeErroredRequest($request, $rex);
        } elseif (!$body->isSeekable() || !$body->seek(0)) {
            // Nothing we can do with this. Sorry!
            $rex = new RequestException(
                'The connection was unexpectedly closed. The request would'
                . ' have been retried, but attempting to rewind the'
                . ' request body failed.'
            );
            $rex->setRequest($request);
            $this->removeErroredRequest($request, $rex);
        } else {
            $this->remove($request);
            // Add the request back to the batch to retry automatically.
            $this->requests[] = $request;
            $this->addHandle($request);
        }

        return false;
    }
}
<?php

namespace Guzzle\Http\Curl;

use Guzzle\Common\AbstractHasDispatcher;
use Guzzle\Http\Message\RequestInterface;

/**
 * Proxies requests and connections to a pool of internal curl_multi handles. Each recursive call will add requests
 * to the next available CurlMulti handle.
 */
class CurlMultiProxy extends AbstractHasDispatcher implements CurlMultiInterface
{
    protected $handles = array();
    protected $groups = array();
    protected $queued = array();
    protected $maxHandles;
    protected $selectTimeout;

    /**
     * @param int   $maxHandles The maximum number of idle CurlMulti handles to allow to remain open
     * @param float $selectTimeout timeout for curl_multi_select
     */
    public function __construct($maxHandles = 3, $selectTimeout = 1.0)
    {
        $this->maxHandles = $maxHandles;
        $this->selectTimeout = $selectTimeout;
        // You can get some weird "Too many open files" errors when sending a large amount of requests in parallel.
        // These two statements autoload classes before a system runs out of file descriptors so that you can get back
        // valuable error messages if you run out.
        class_exists('Guzzle\Http\Message\Response');
        class_exists('Guzzle\Http\Exception\CurlException');
    }

    public function add(RequestInterface $request)
    {
        $this->queued[] = $request;

        return $this;
    }

    public function all()
    {
        $requests = $this->queued;
        foreach ($this->handles as $handle) {
            $requests = array_merge($requests, $handle->all());
        }

        return $requests;
    }

    public function remove(RequestInterface $request)
    {
        foreach ($this->queued as $i => $r) {
            if ($request === $r) {
                unset($this->queued[$i]);
                return true;
            }
        }

        foreach ($this->handles as $handle) {
            if ($handle->remove($request)) {
                return true;
            }
        }

        return false;
    }

    public function reset($hard = false)
    {
        $this->queued = array();
        $this->groups = array();
        foreach ($this->handles as $handle) {
            $handle->reset();
        }
        if ($hard) {
            $this->handles = array();
        }

        return $this;
    }

    public function send()
    {
        if ($this->queued) {
            $group = $this->getAvailableHandle();
            // Add this handle to a list of handles than is claimed
            $this->groups[] = $group;
            while ($request = array_shift($this->queued)) {
                $group->add($request);
            }
            try {
                $group->send();
                array_pop($this->groups);
                $this->cleanupHandles();
            } catch (\Exception $e) {
                // Remove the group and cleanup if an exception was encountered and no more requests in group
                if (!$group->count()) {
                    array_pop($this->groups);
                    $this->cleanupHandles();
                }
                throw $e;
            }
        }
    }

    public function count()
    {
        return count($this->all());
    }

    /**
     * Get an existing available CurlMulti handle or create a new one
     *
     * @return CurlMulti
     */
    protected function getAvailableHandle()
    {
        // Grab a handle that is not claimed
        foreach ($this->handles as $h) {
            if (!in_array($h, $this->groups, true)) {
                return $h;
            }
        }

        // All are claimed, so create one
        $handle = new CurlMulti($this->selectTimeout);
        $handle->setEventDispatcher($this->getEventDispatcher());
        $this->handles[] = $handle;

        return $handle;
    }

    /**
     * Trims down unused CurlMulti handles to limit the number of open connections
     */
    protected function cleanupHandles()
    {
        if ($diff = max(0, count($this->handles) - $this->maxHandles)) {
            for ($i = count($this->handles) - 1; $i > 0 && $diff > 0; $i--) {
                if (!count($this->handles[$i])) {
                    unset($this->handles[$i]);
                    $diff--;
                }
            }
            $this->handles = array_values($this->handles);
        }
    }
}
<?php

namespace Guzzle\Http\Curl;

/**
 * Class used for querying curl_version data
 */
class CurlVersion
{
    /** @var array curl_version() information */
    protected $version;

    /** @var CurlVersion */
    protected static $instance;

    /** @var string Default user agent */
    protected $userAgent;

    /**
     * @return CurlVersion
     */
    public static function getInstance()
    {
        if (!self::$instance) {
            self::$instance = new self();
        }

        return self::$instance;
    }

    /**
     * Get all of the curl_version() data
     *
     * @return array
     */
    public function getAll()
    {
        if (!$this->version) {
            $this->version = curl_version();
        }

        return $this->version;
    }

    /**
     * Get a specific type of curl information
     *
     * @param string $type Version information to retrieve. This value is one of:
     *     - version_number:     cURL 24 bit version number
     *     - version:            cURL version number, as a string
     *     - ssl_version_number: OpenSSL 24 bit version number
     *     - ssl_version:        OpenSSL version number, as a string
     *     - libz_version:       zlib version number, as a string
     *     - host:               Information about the host where cURL was built
     *     - features:           A bitmask of the CURL_VERSION_XXX constants
     *     - protocols:          An array of protocols names supported by cURL
     *
     * @return string|float|bool if the $type is found, and false if not found
     */
    public function get($type)
    {
        $version = $this->getAll();

        return isset($version[$type]) ? $version[$type] : false;
    }
}
<?php

namespace Guzzle\Http\Curl;

use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\EntityBody;
use Guzzle\Http\Message\Response;

/**
 * Mediator between curl handles and request objects
 */
class RequestMediator
{
    /** @var RequestInterface */
    protected $request;

    /** @var bool Whether or not to emit read/write events */
    protected $emitIo;

    /**
     * @param RequestInterface $request Request to mediate
     * @param bool             $emitIo  Set to true to dispatch events on input and output
     */
    public function __construct(RequestInterface $request, $emitIo = false)
    {
        $this->request = $request;
        $this->emitIo = $emitIo;
    }

    /**
     * Receive a response header from curl
     *
     * @param resource $curl   Curl handle
     * @param string   $header Received header
     *
     * @return int
     */
    public function receiveResponseHeader($curl, $header)
    {
        static $normalize = array("\r", "\n");
        $length = strlen($header);
        $header = str_replace($normalize, '', $header);

        if (strpos($header, 'HTTP/') === 0) {

            $startLine = explode(' ', $header, 3);
            $code = $startLine[1];
            $status = isset($startLine[2]) ? $startLine[2] : '';

            // Only download the body of the response to the specified response
            // body when a successful response is received.
            if ($code >= 200 && $code < 300) {
                $body = $this->request->getResponseBody();
            } else {
                $body = EntityBody::factory();
            }

            $response = new Response($code, null, $body);
            $response->setStatus($code, $status);
            $this->request->startResponse($response);

            $this->request->dispatch('request.receive.status_line', array(
                'request'       => $this,
                'line'          => $header,
                'status_code'   => $code,
                'reason_phrase' => $status
            ));

        } elseif ($pos = strpos($header, ':')) {
            $this->request->getResponse()->addHeader(
                trim(substr($header, 0, $pos)),
                trim(substr($header, $pos + 1))
            );
        }

        return $length;
    }

    /**
     * Received a progress notification
     *
     * @param int        $downloadSize Total download size
     * @param int        $downloaded   Amount of bytes downloaded
     * @param int        $uploadSize   Total upload size
     * @param int        $uploaded     Amount of bytes uploaded
     * @param resource   $handle       CurlHandle object
     */
    public function progress($downloadSize, $downloaded, $uploadSize, $uploaded, $handle = null)
    {
        $this->request->dispatch('curl.callback.progress', array(
            'request'       => $this->request,
            'handle'        => $handle,
            'download_size' => $downloadSize,
            'downloaded'    => $downloaded,
            'upload_size'   => $uploadSize,
            'uploaded'      => $uploaded
        ));
    }

    /**
     * Write data to the response body of a request
     *
     * @param resource $curl  Curl handle
     * @param string   $write Data that was received
     *
     * @return int
     */
    public function writeResponseBody($curl, $write)
    {
        if ($this->emitIo) {
            $this->request->dispatch('curl.callback.write', array(
                'request' => $this->request,
                'write'   => $write
            ));
        }

        if ($response = $this->request->getResponse()) {
            return $response->getBody()->write($write);
        } else {
            // Unexpected data received before response headers - abort transfer
            return 0;
        }
    }

    /**
     * Read data from the request body and send it to curl
     *
     * @param resource $ch     Curl handle
     * @param resource $fd     File descriptor
     * @param int      $length Amount of data to read
     *
     * @return string
     */
    public function readRequestBody($ch, $fd, $length)
    {
        if (!($body = $this->request->getBody())) {
            return '';
        }

        $read = (string) $body->read($length);
        if ($this->emitIo) {
            $this->request->dispatch('curl.callback.read', array('request' => $this->request, 'read' => $read));
        }

        return $read;
    }
}
<?php

namespace Guzzle\Http;

use Guzzle\Common\Exception\RuntimeException;

/**
 * EntityBody decorator that can cache previously read bytes from a sequentially read tstream
 */
class CachingEntityBody extends AbstractEntityBodyDecorator
{
    /** @var EntityBody Remote stream used to actually pull data onto the buffer */
    protected $remoteStream;

    /** @var int The number of bytes to skip reading due to a write on the temporary buffer */
    protected $skipReadBytes = 0;

    /**
     * We will treat the buffer object as the body of the entity body
     * {@inheritdoc}
     */
    public function __construct(EntityBodyInterface $body)
    {
        $this->remoteStream = $body;
        $this->body = new EntityBody(fopen('php://temp', 'r+'));
    }

    /**
     * Will give the contents of the buffer followed by the exhausted remote stream.
     *
     * Warning: Loads the entire stream into memory
     *
     * @return string
     */
    public function __toString()
    {
        $pos = $this->ftell();
        $this->rewind();

        $str = '';
        while (!$this->isConsumed()) {
            $str .= $this->read(16384);
        }

        $this->seek($pos);

        return $str;
    }

    public function getSize()
    {
        return max($this->body->getSize(), $this->remoteStream->getSize());
    }

    /**
     * {@inheritdoc}
     * @throws RuntimeException When seeking with SEEK_END or when seeking past the total size of the buffer stream
     */
    public function seek($offset, $whence = SEEK_SET)
    {
        if ($whence == SEEK_SET) {
            $byte = $offset;
        } elseif ($whence == SEEK_CUR) {
            $byte = $offset + $this->ftell();
        } else {
            throw new RuntimeException(__CLASS__ . ' supports only SEEK_SET and SEEK_CUR seek operations');
        }

        // You cannot skip ahead past where you've read from the remote stream
        if ($byte > $this->body->getSize()) {
            throw new RuntimeException(
                "Cannot seek to byte {$byte} when the buffered stream only contains {$this->body->getSize()} bytes"
            );
        }

        return $this->body->seek($byte);
    }

    public function rewind()
    {
        return $this->seek(0);
    }

    /**
     * Does not support custom rewind functions
     *
     * @throws RuntimeException
     */
    public function setRewindFunction($callable)
    {
        throw new RuntimeException(__CLASS__ . ' does not support custom stream rewind functions');
    }

    public function read($length)
    {
        // Perform a regular read on any previously read data from the buffer
        $data = $this->body->read($length);
        $remaining = $length - strlen($data);

        // More data was requested so read from the remote stream
        if ($remaining) {
            // If data was written to the buffer in a position that would have been filled from the remote stream,
            // then we must skip bytes on the remote stream to emulate overwriting bytes from that position. This
            // mimics the behavior of other PHP stream wrappers.
            $remoteData = $this->remoteStream->read($remaining + $this->skipReadBytes);

            if ($this->skipReadBytes) {
                $len = strlen($remoteData);
                $remoteData = substr($remoteData, $this->skipReadBytes);
                $this->skipReadBytes = max(0, $this->skipReadBytes - $len);
            }

            $data .= $remoteData;
            $this->body->write($remoteData);
        }

        return $data;
    }

    public function write($string)
    {
        // When appending to the end of the currently read stream, you'll want to skip bytes from being read from
        // the remote stream to emulate other stream wrappers. Basically replacing bytes of data of a fixed length.
        $overflow = (strlen($string) + $this->ftell()) - $this->remoteStream->ftell();
        if ($overflow > 0) {
            $this->skipReadBytes += $overflow;
        }

        return $this->body->write($string);
    }

    /**
     * {@inheritdoc}
     * @link http://php.net/manual/en/function.fgets.php
     */
    public function readLine($maxLength = null)
    {
        $buffer = '';
        $size = 0;
        while (!$this->isConsumed()) {
            $byte = $this->read(1);
            $buffer .= $byte;
            // Break when a new line is found or the max length - 1 is reached
            if ($byte == PHP_EOL || ++$size == $maxLength - 1) {
                break;
            }
        }

        return $buffer;
    }

    public function isConsumed()
    {
        return $this->body->isConsumed() && $this->remoteStream->isConsumed();
    }

    /**
     * Close both the remote stream and buffer stream
     */
    public function close()
    {
        return $this->remoteStream->close() && $this->body->close();
    }

    public function setStream($stream, $size = 0)
    {
        $this->remoteStream->setStream($stream, $size);
    }

    public function getContentType()
    {
        return $this->remoteStream->getContentType();
    }

    public function getContentEncoding()
    {
        return $this->remoteStream->getContentEncoding();
    }

    public function getMetaData($key = null)
    {
        return $this->remoteStream->getMetaData($key);
    }

    public function getStream()
    {
        return $this->remoteStream->getStream();
    }

    public function getWrapper()
    {
        return $this->remoteStream->getWrapper();
    }

    public function getWrapperData()
    {
        return $this->remoteStream->getWrapperData();
    }

    public function getStreamType()
    {
        return $this->remoteStream->getStreamType();
    }

    public function getUri()
    {
        return $this->remoteStream->getUri();
    }

    /**
     * Always retrieve custom data from the remote stream
     * {@inheritdoc}
     */
    public function getCustomData($key)
    {
        return $this->remoteStream->getCustomData($key);
    }

    /**
     * Always set custom data on the remote stream
     * {@inheritdoc}
     */
    public function setCustomData($key, $value)
    {
        $this->remoteStream->setCustomData($key, $value);

        return $this;
    }
}
<?php

namespace Guzzle\Http;

use Guzzle\Common\Exception\InvalidArgumentException;

/**
 * Parses and generates URLs based on URL parts. In favor of performance, URL parts are not validated.
 */
class Url
{
    protected $scheme;
    protected $host;
    protected $port;
    protected $username;
    protected $password;
    protected $path = '';
    protected $fragment;

    /** @var QueryString Query part of the URL */
    protected $query;

    /**
     * Factory method to create a new URL from a URL string
     *
     * @param string $url Full URL used to create a Url object
     *
     * @return Url
     * @throws InvalidArgumentException
     */
    public static function factory($url)
    {
        static $defaults = array('scheme' => null, 'host' => null, 'path' => null, 'port' => null, 'query' => null,
            'user' => null, 'pass' => null, 'fragment' => null);

        if (false === ($parts = parse_url($url))) {
            throw new InvalidArgumentException('Was unable to parse malformed url: ' . $url);
        }

        $parts += $defaults;

        // Convert the query string into a QueryString object
        if ($parts['query'] || 0 !== strlen($parts['query'])) {
            $parts['query'] = QueryString::fromString($parts['query']);
        }

        return new static($parts['scheme'], $parts['host'], $parts['user'],
            $parts['pass'], $parts['port'], $parts['path'], $parts['query'],
            $parts['fragment']);
    }

    /**
     * Build a URL from parse_url parts. The generated URL will be a relative URL if a scheme or host are not provided.
     *
     * @param array $parts Array of parse_url parts
     *
     * @return string
     */
    public static function buildUrl(array $parts)
    {
        $url = $scheme = '';

        if (isset($parts['scheme'])) {
            $scheme = $parts['scheme'];
            $url .= $scheme . ':';
        }

        if (isset($parts['host'])) {
            $url .= '//';
            if (isset($parts['user'])) {
                $url .= $parts['user'];
                if (isset($parts['pass'])) {
                    $url .= ':' . $parts['pass'];
                }
                $url .=  '@';
            }

            $url .= $parts['host'];

            // Only include the port if it is not the default port of the scheme
            if (isset($parts['port'])
                && !(($scheme == 'http' && $parts['port'] == 80) || ($scheme == 'https' && $parts['port'] == 443))
            ) {
                $url .= ':' . $parts['port'];
            }
        }

        // Add the path component if present
        if (isset($parts['path']) && 0 !== strlen($parts['path'])) {
            // Always ensure that the path begins with '/' if set and something is before the path
            if ($url && $parts['path'][0] != '/' && substr($url, -1)  != '/') {
                $url .= '/';
            }
            $url .= $parts['path'];
        }

        // Add the query string if present
        if (isset($parts['query'])) {
            $url .= '?' . $parts['query'];
        }

        // Ensure that # is only added to the url if fragment contains anything.
        if (isset($parts['fragment'])) {
            $url .= '#' . $parts['fragment'];
        }

        return $url;
    }

    /**
     * Create a new URL from URL parts
     *
     * @param string                   $scheme   Scheme of the URL
     * @param string                   $host     Host of the URL
     * @param string                   $username Username of the URL
     * @param string                   $password Password of the URL
     * @param int                      $port     Port of the URL
     * @param string                   $path     Path of the URL
     * @param QueryString|array|string $query    Query string of the URL
     * @param string                   $fragment Fragment of the URL
     */
    public function __construct($scheme, $host, $username = null, $password = null, $port = null, $path = null, QueryString $query = null, $fragment = null)
    {
        $this->scheme = $scheme;
        $this->host = $host;
        $this->port = $port;
        $this->username = $username;
        $this->password = $password;
        $this->fragment = $fragment;
        if (!$query) {
            $this->query = new QueryString();
        } else {
            $this->setQuery($query);
        }
        $this->setPath($path);
    }

    /**
     * Clone the URL
     */
    public function __clone()
    {
        $this->query = clone $this->query;
    }

    /**
     * Returns the URL as a URL string
     *
     * @return string
     */
    public function __toString()
    {
        return self::buildUrl($this->getParts());
    }

    /**
     * Get the parts of the URL as an array
     *
     * @return array
     */
    public function getParts()
    {
        $query = (string) $this->query;

        return array(
            'scheme' => $this->scheme,
            'user' => $this->username,
            'pass' => $this->password,
            'host' => $this->host,
            'port' => $this->port,
            'path' => $this->getPath(),
            'query' => $query !== '' ? $query : null,
            'fragment' => $this->fragment,
        );
    }

    /**
     * Set the host of the request.
     *
     * @param string $host Host to set (e.g. www.yahoo.com, yahoo.com)
     *
     * @return Url
     */
    public function setHost($host)
    {
        if (strpos($host, ':') === false) {
            $this->host = $host;
        } else {
            list($host, $port) = explode(':', $host);
            $this->host = $host;
            $this->setPort($port);
        }

        return $this;
    }

    /**
     * Get the host part of the URL
     *
     * @return string
     */
    public function getHost()
    {
        return $this->host;
    }

    /**
     * Set the scheme part of the URL (http, https, ftp, etc)
     *
     * @param string $scheme Scheme to set
     *
     * @return Url
     */
    public function setScheme($scheme)
    {
        if ($this->scheme == 'http' && $this->port == 80) {
            $this->port = null;
        } elseif ($this->scheme == 'https' && $this->port == 443) {
            $this->port = null;
        }

        $this->scheme = $scheme;

        return $this;
    }

    /**
     * Get the scheme part of the URL
     *
     * @return string
     */
    public function getScheme()
    {
        return $this->scheme;
    }

    /**
     * Set the port part of the URL
     *
     * @param int $port Port to set
     *
     * @return Url
     */
    public function setPort($port)
    {
        $this->port = $port;

        return $this;
    }

    /**
     * Get the port part of the URl. Will return the default port for a given scheme if no port has been set.
     *
     * @return int|null
     */
    public function getPort()
    {
        if ($this->port) {
            return $this->port;
        } elseif ($this->scheme == 'http') {
            return 80;
        } elseif ($this->scheme == 'https') {
            return 443;
        }

        return null;
    }

    /**
     * Set the path part of the URL
     *
     * @param array|string $path Path string or array of path segments
     *
     * @return Url
     */
    public function setPath($path)
    {
        static $pathReplace = array(' ' => '%20', '?' => '%3F');
        if (is_array($path)) {
            $path = '/' . implode('/', $path);
        }

        $this->path = strtr($path, $pathReplace);

        return $this;
    }

    /**
     * Normalize the URL so that double slashes and relative paths are removed
     *
     * @return Url
     */
    public function normalizePath()
    {
        if (!$this->path || $this->path == '/' || $this->path == '*') {
            return $this;
        }

        $results = array();
        $segments = $this->getPathSegments();
        foreach ($segments as $segment) {
            if ($segment == '..') {
                array_pop($results);
            } elseif ($segment != '.' && $segment != '') {
                $results[] = $segment;
            }
        }

        // Combine the normalized parts and add the leading slash if needed
        $this->path = ($this->path[0] == '/' ? '/' : '') . implode('/', $results);

        // Add the trailing slash if necessary
        if ($this->path != '/' && end($segments) == '') {
            $this->path .= '/';
        }

        return $this;
    }

    /**
     * Add a relative path to the currently set path.
     *
     * @param string $relativePath Relative path to add
     *
     * @return Url
     */
    public function addPath($relativePath)
    {
        if ($relativePath != '/' && is_string($relativePath) && strlen($relativePath) > 0) {
            // Add a leading slash if needed
            if ($relativePath[0] != '/') {
                $relativePath = '/' . $relativePath;
            }
            $this->setPath(str_replace('//', '/', $this->path . $relativePath));
        }

        return $this;
    }

    /**
     * Get the path part of the URL
     *
     * @return string
     */
    public function getPath()
    {
        return $this->path;
    }

    /**
     * Get the path segments of the URL as an array
     *
     * @return array
     */
    public function getPathSegments()
    {
        return array_slice(explode('/', $this->getPath()), 1);
    }

    /**
     * Set the password part of the URL
     *
     * @param string $password Password to set
     *
     * @return Url
     */
    public function setPassword($password)
    {
        $this->password = $password;

        return $this;
    }

    /**
     * Get the password part of the URL
     *
     * @return null|string
     */
    public function getPassword()
    {
        return $this->password;
    }

    /**
     * Set the username part of the URL
     *
     * @param string $username Username to set
     *
     * @return Url
     */
    public function setUsername($username)
    {
        $this->username = $username;

        return $this;
    }

    /**
     * Get the username part of the URl
     *
     * @return null|string
     */
    public function getUsername()
    {
        return $this->username;
    }

    /**
     * Get the query part of the URL as a QueryString object
     *
     * @return QueryString
     */
    public function getQuery()
    {
        return $this->query;
    }

    /**
     * Set the query part of the URL
     *
     * @param QueryString|string|array $query Query to set
     *
     * @return Url
     */
    public function setQuery($query)
    {
        if (is_string($query)) {
            $output = null;
            parse_str($query, $output);
            $this->query = new QueryString($output);
        } elseif (is_array($query)) {
            $this->query = new QueryString($query);
        } elseif ($query instanceof QueryString) {
            $this->query = $query;
        }

        return $this;
    }

    /**
     * Get the fragment part of the URL
     *
     * @return null|string
     */
    public function getFragment()
    {
        return $this->fragment;
    }

    /**
     * Set the fragment part of the URL
     *
     * @param string $fragment Fragment to set
     *
     * @return Url
     */
    public function setFragment($fragment)
    {
        $this->fragment = $fragment;

        return $this;
    }

    /**
     * Check if this is an absolute URL
     *
     * @return bool
     */
    public function isAbsolute()
    {
        return $this->scheme && $this->host;
    }

    /**
     * Combine the URL with another URL. Follows the rules specific in RFC 3986 section 5.4.
     *
     * @param string $url           Relative URL to combine with
     * @param bool   $strictRfc3986 Set to true to use strict RFC 3986 compliance when merging paths. When first
     *                              released, Guzzle used an incorrect algorithm for combining relative URL paths. In
     *                              order to not break users, we introduced this flag to allow the merging of URLs based
     *                              on strict RFC 3986 section 5.4.1. This means that "http://a.com/foo/baz" merged with
     *                              "bar" would become "http://a.com/foo/bar". When this value is set to false, it would
     *                              become "http://a.com/foo/baz/bar".
     * @return Url
     * @throws InvalidArgumentException
     * @link http://tools.ietf.org/html/rfc3986#section-5.4
     */
    public function combine($url, $strictRfc3986 = false)
    {
        $url = self::factory($url);

        // Use the more absolute URL as the base URL
        if (!$this->isAbsolute() && $url->isAbsolute()) {
            $url = $url->combine($this);
        }

        // Passing a URL with a scheme overrides everything
        if ($buffer = $url->getScheme()) {
            $this->scheme = $buffer;
            $this->host = $url->getHost();
            $this->port = $url->getPort();
            $this->username = $url->getUsername();
            $this->password = $url->getPassword();
            $this->path = $url->getPath();
            $this->query = $url->getQuery();
            $this->fragment = $url->getFragment();
            return $this;
        }

        // Setting a host overrides the entire rest of the URL
        if ($buffer = $url->getHost()) {
            $this->host = $buffer;
            $this->port = $url->getPort();
            $this->username = $url->getUsername();
            $this->password = $url->getPassword();
            $this->path = $url->getPath();
            $this->query = $url->getQuery();
            $this->fragment = $url->getFragment();
            return $this;
        }

        $path = $url->getPath();
        $query = $url->getQuery();

        if (!$path) {
            if (count($query)) {
                $this->addQuery($query, $strictRfc3986);
            }
        } else {
            if ($path[0] == '/') {
                $this->path = $path;
            } elseif ($strictRfc3986) {
                $this->path .= '/../' . $path;
            } else {
                $this->path .= '/' . $path;
            }
            $this->normalizePath();
            $this->addQuery($query, $strictRfc3986);
        }

        $this->fragment = $url->getFragment();

        return $this;
    }

    private function addQuery(QueryString $new, $strictRfc386)
    {
        if (!$strictRfc386) {
            $new->merge($this->query);
        }

        $this->query = $new;
    }
}
<?php

namespace Guzzle\Http;

use Guzzle\Common\Event;
use Guzzle\Http\Exception\BadResponseException;
use Guzzle\Http\Url;
use Guzzle\Http\Message\Response;
use Guzzle\Http\Message\RequestInterface;
use Guzzle\Http\Message\RequestFactory;
use Guzzle\Http\Message\EntityEnclosingRequestInterface;
use Guzzle\Http\Exception\TooManyRedirectsException;
use Guzzle\Http\Exception\CouldNotRewindStreamException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Plugin to implement HTTP redirects. Can redirect like a web browser or using strict RFC 2616 compliance
 */
class RedirectPlugin implements EventSubscriberInterface
{
    const REDIRECT_COUNT = 'redirect.count';
    const MAX_REDIRECTS = 'redirect.max';
    const STRICT_REDIRECTS = 'redirect.strict';
    const PARENT_REQUEST = 'redirect.parent_request';
    const DISABLE = 'redirect.disable';

    /**
     * @var int Default number of redirects allowed when no setting is supplied by a request
     */
    protected $defaultMaxRedirects = 5;

    public static function getSubscribedEvents()
    {
        return array(
            'request.sent'        => array('onRequestSent', 100),
            'request.clone'       => 'cleanupRequest',
            'request.before_send' => 'cleanupRequest'
        );
    }

    /**
     * Clean up the parameters of a request when it is cloned
     *
     * @param Event $event Event emitted
     */
    public function cleanupRequest(Event $event)
    {
        $params = $event['request']->getParams();
        unset($params[self::REDIRECT_COUNT]);
        unset($params[self::PARENT_REQUEST]);
    }

    /**
     * Called when a request receives a redirect response
     *
     * @param Event $event Event emitted
     */
    public function onRequestSent(Event $event)
    {
        $response = $event['response'];
        $request = $event['request'];

        // Only act on redirect requests with Location headers
        if (!$response || $request->getParams()->get(self::DISABLE)) {
            return;
        }

        // Trace the original request based on parameter history
        $original = $this->getOriginalRequest($request);

        // Terminating condition to set the effective response on the original request
        if (!$response->isRedirect() || !$response->hasHeader('Location')) {
            if ($request !== $original) {
                // This is a terminating redirect response, so set it on the original request
                $response->getParams()->set(self::REDIRECT_COUNT, $original->getParams()->get(self::REDIRECT_COUNT));
                $original->setResponse($response);
                $response->setEffectiveUrl($request->getUrl());
            }
            return;
        }

        $this->sendRedirectRequest($original, $request, $response);
    }

    /**
     * Get the original request that initiated a series of redirects
     *
     * @param RequestInterface $request Request to get the original request from
     *
     * @return RequestInterface
     */
    protected function getOriginalRequest(RequestInterface $request)
    {
        $original = $request;
        // The number of redirects is held on the original request, so determine which request that is
        while ($parent = $original->getParams()->get(self::PARENT_REQUEST)) {
            $original = $parent;
        }

        return $original;
    }

    /**
     * Create a redirect request for a specific request object
     *
     * Takes into account strict RFC compliant redirection (e.g. redirect POST with POST) vs doing what most clients do
     * (e.g. redirect POST with GET).
     *
     * @param RequestInterface $request    Request being redirected
     * @param RequestInterface $original   Original request
     * @param int              $statusCode Status code of the redirect
     * @param string           $location   Location header of the redirect
     *
     * @return RequestInterface Returns a new redirect request
     * @throws CouldNotRewindStreamException If the body needs to be rewound but cannot
     */
    protected function createRedirectRequest(
        RequestInterface $request,
        $statusCode,
        $location,
        RequestInterface $original
    ) {
        $redirectRequest = null;
        $strict = $original->getParams()->get(self::STRICT_REDIRECTS);

        // Switch method to GET for 303 redirects.  301 and 302 redirects also switch to GET unless we are forcing RFC
        // compliance to emulate what most browsers do.  NOTE: IE only switches methods on 301/302 when coming from a POST.
        if ($request instanceof EntityEnclosingRequestInterface && ($statusCode == 303 || (!$strict && $statusCode <= 302))) {
            $redirectRequest = RequestFactory::getInstance()->cloneRequestWithMethod($request, 'GET');
        } else {
            $redirectRequest = clone $request;
        }

        $redirectRequest->setIsRedirect(true);
        // Always use the same response body when redirecting
        $redirectRequest->setResponseBody($request->getResponseBody());

        $location = Url::factory($location);
        // If the location is not absolute, then combine it with the original URL
        if (!$location->isAbsolute()) {
            $originalUrl = $redirectRequest->getUrl(true);
            // Remove query string parameters and just take what is present on the redirect Location header
            $originalUrl->getQuery()->clear();
            $location = $originalUrl->combine((string) $location, true);
        }

        $redirectRequest->setUrl($location);

        // Add the parent request to the request before it sends (make sure it's before the onRequestClone event too)
        $redirectRequest->getEventDispatcher()->addListener(
            'request.before_send',
            $func = function ($e) use (&$func, $request, $redirectRequest) {
                $redirectRequest->getEventDispatcher()->removeListener('request.before_send', $func);
                $e['request']->getParams()->set(RedirectPlugin::PARENT_REQUEST, $request);
            }
        );

        // Rewind the entity body of the request if needed
        if ($redirectRequest instanceof EntityEnclosingRequestInterface && $redirectRequest->getBody()) {
            $body = $redirectRequest->getBody();
            // Only rewind the body if some of it has been read already, and throw an exception if the rewind fails
            if ($body->ftell() && !$body->rewind()) {
                throw new CouldNotRewindStreamException(
                    'Unable to rewind the non-seekable entity body of the request after redirecting. cURL probably '
                    . 'sent part of body before the redirect occurred. Try adding acustom rewind function using on the '
                    . 'entity body of the request using setRewindFunction().'
                );
            }
        }

        return $redirectRequest;
    }

    /**
     * Prepare the request for redirection and enforce the maximum number of allowed redirects per client
     *
     * @param RequestInterface $original  Original request
     * @param RequestInterface $request   Request to prepare and validate
     * @param Response         $response  The current response
     *
     * @return RequestInterface
     */
    protected function prepareRedirection(RequestInterface $original, RequestInterface $request, Response $response)
    {
        $params = $original->getParams();
        // This is a new redirect, so increment the redirect counter
        $current = $params[self::REDIRECT_COUNT] + 1;
        $params[self::REDIRECT_COUNT] = $current;
        // Use a provided maximum value or default to a max redirect count of 5
        $max = isset($params[self::MAX_REDIRECTS]) ? $params[self::MAX_REDIRECTS] : $this->defaultMaxRedirects;

        // Throw an exception if the redirect count is exceeded
        if ($current > $max) {
            $this->throwTooManyRedirectsException($original, $max);
            return false;
        } else {
            // Create a redirect request based on the redirect rules set on the request
            return $this->createRedirectRequest(
                $request,
                $response->getStatusCode(),
                trim($response->getLocation()),
                $original
            );
        }
    }

    /**
     * Send a redirect request and handle any errors
     *
     * @param RequestInterface $original The originating request
     * @param RequestInterface $request  The current request being redirected
     * @param Response         $response The response of the current request
     *
     * @throws BadResponseException|\Exception
     */
    protected function sendRedirectRequest(RequestInterface $original, RequestInterface $request, Response $response)
    {
        // Validate and create a redirect request based on the original request and current response
        if ($redirectRequest = $this->prepareRedirection($original, $request, $response)) {
            try {
                $redirectRequest->send();
            } catch (BadResponseException $e) {
                $e->getResponse();
                if (!$e->getResponse()) {
                    throw $e;
                }
            }
        }
    }

    /**
     * Throw a too many redirects exception for a request
     *
     * @param RequestInterface $original Request
     * @param int              $max      Max allowed redirects
     *
     * @throws TooManyRedirectsException when too many redirects have been issued
     */
    protected function throwTooManyRedirectsException(RequestInterface $original, $max)
    {
        $original->getEventDispatcher()->addListener(
            'request.complete',
            $func = function ($e) use (&$func, $original, $max) {
                $original->getEventDispatcher()->removeListener('request.complete', $func);
                $str = "{$max} redirects were issued for this request:\n" . $e['request']->getRawHeaders();
                throw new TooManyRedirectsException($str);
            }
        );
    }
}
<?php

namespace Guzzle\Http;

use Guzzle\Common\Version;
use Guzzle\Stream\Stream;
use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Http\Mimetypes;

/**
 * Entity body used with an HTTP request or response
 */
class EntityBody extends Stream implements EntityBodyInterface
{
    /** @var bool Content-Encoding of the entity body if known */
    protected $contentEncoding = false;

    /** @var callable Method to invoke for rewinding a stream */
    protected $rewindFunction;

    /**
     * Create a new EntityBody based on the input type
     *
     * @param resource|string|EntityBody $resource Entity body data
     * @param int                        $size     Size of the data contained in the resource
     *
     * @return EntityBody
     * @throws InvalidArgumentException if the $resource arg is not a resource or string
     */
    public static function factory($resource = '', $size = null)
    {
        if ($resource instanceof EntityBodyInterface) {
            return $resource;
        }

        switch (gettype($resource)) {
            case 'string':
                return self::fromString($resource);
            case 'resource':
                return new static($resource, $size);
            case 'object':
                if (method_exists($resource, '__toString')) {
                    return self::fromString((string) $resource);
                }
                break;
            case 'array':
                return self::fromString(http_build_query($resource));
        }

        throw new InvalidArgumentException('Invalid resource type');
    }

    public function setRewindFunction($callable)
    {
        if (!is_callable($callable)) {
            throw new InvalidArgumentException('Must specify a callable');
        }

        $this->rewindFunction = $callable;

        return $this;
    }

    public function rewind()
    {
        return $this->rewindFunction ? call_user_func($this->rewindFunction, $this) : parent::rewind();
    }

    /**
     * Create a new EntityBody from a string
     *
     * @param string $string String of data
     *
     * @return EntityBody
     */
    public static function fromString($string)
    {
        $stream = fopen('php://temp', 'r+');
        if ($string !== '') {
            fwrite($stream, $string);
            rewind($stream);
        }

        return new static($stream);
    }

    public function compress($filter = 'zlib.deflate')
    {
        $result = $this->handleCompression($filter);
        $this->contentEncoding = $result ? $filter : false;

        return $result;
    }

    public function uncompress($filter = 'zlib.inflate')
    {
        $offsetStart = 0;

        // When inflating gzipped data, the first 10 bytes must be stripped
        // if a gzip header is present
        if ($filter == 'zlib.inflate') {
            // @codeCoverageIgnoreStart
            if (!$this->isReadable() || ($this->isConsumed() && !$this->isSeekable())) {
                return false;
            }
            // @codeCoverageIgnoreEnd
            if (stream_get_contents($this->stream, 3, 0) === "\x1f\x8b\x08") {
                $offsetStart = 10;
            }
        }

        $this->contentEncoding = false;

        return $this->handleCompression($filter, $offsetStart);
    }

    public function getContentLength()
    {
        return $this->getSize();
    }

    public function getContentType()
    {
        return $this->getUri() ? Mimetypes::getInstance()->fromFilename($this->getUri()) : null;
    }

    public function getContentMd5($rawOutput = false, $base64Encode = false)
    {
        if ($hash = self::getHash($this, 'md5', $rawOutput)) {
            return $hash && $base64Encode ? base64_encode($hash) : $hash;
        } else {
            return false;
        }
    }

    /**
     * Calculate the MD5 hash of an entity body
     *
     * @param EntityBodyInterface $body         Entity body to calculate the hash for
     * @param bool                $rawOutput    Whether or not to use raw output
     * @param bool                $base64Encode Whether or not to base64 encode raw output (only if raw output is true)
     *
     * @return bool|string Returns an MD5 string on success or FALSE on failure
     * @deprecated This will be deprecated soon
     * @codeCoverageIgnore
     */
    public static function calculateMd5(EntityBodyInterface $body, $rawOutput = false, $base64Encode = false)
    {
        Version::warn(__CLASS__ . ' is deprecated. Use getContentMd5()');
        return $body->getContentMd5($rawOutput, $base64Encode);
    }

    public function setStreamFilterContentEncoding($streamFilterContentEncoding)
    {
        $this->contentEncoding = $streamFilterContentEncoding;

        return $this;
    }

    public function getContentEncoding()
    {
        return strtr($this->contentEncoding, array(
            'zlib.deflate' => 'gzip',
            'bzip2.compress' => 'compress'
        )) ?: false;
    }

    protected function handleCompression($filter, $offsetStart = 0)
    {
        // @codeCoverageIgnoreStart
        if (!$this->isReadable() || ($this->isConsumed() && !$this->isSeekable())) {
            return false;
        }
        // @codeCoverageIgnoreEnd

        $handle = fopen('php://temp', 'r+');
        $filter = @stream_filter_append($handle, $filter, STREAM_FILTER_WRITE);
        if (!$filter) {
            return false;
        }

        // Seek to the offset start if possible
        $this->seek($offsetStart);
        while ($data = fread($this->stream, 8096)) {
            fwrite($handle, $data);
        }

        fclose($this->stream);
        $this->stream = $handle;
        stream_filter_remove($filter);
        $stat = fstat($this->stream);
        $this->size = $stat['size'];
        $this->rebuildCache();
        $this->seek(0);

        // Remove any existing rewind function as the underlying stream has been replaced
        $this->rewindFunction = null;

        return true;
    }
}
<?php

namespace Guzzle\Batch;

/**
 * Interface for efficiently transferring items in a queue using batches
 */
interface BatchInterface
{
    /**
     * Add an item to the queue
     *
     * @param mixed $item Item to add
     *
     * @return self
     */
    public function add($item);

    /**
     * Flush the batch and transfer the items
     *
     * @return array Returns an array flushed items
     */
    public function flush();

    /**
     * Check if the batch is empty and has further items to transfer
     *
     * @return bool
     */
    public function isEmpty();
}
<?php

namespace Guzzle\Batch;

/**
 * Divides batches into smaller batches under a certain size
 */
class BatchSizeDivisor implements BatchDivisorInterface
{
    /** @var int Size of each batch */
    protected $size;

    /** @param int $size Size of each batch */
    public function __construct($size)
    {
        $this->size = $size;
    }

    /**
     * Set the size of each batch
     *
     * @param int $size Size of each batch
     *
     * @return BatchSizeDivisor
     */
    public function setSize($size)
    {
        $this->size = $size;

        return $this;
    }

    /**
     * Get the size of each batch
     *
     * @return int
     */
    public function getSize()
    {
        return $this->size;
    }

    public function createBatches(\SplQueue $queue)
    {
        return array_chunk(iterator_to_array($queue, false), $this->size);
    }
}
<?php

namespace Guzzle\Batch\Exception;

use Guzzle\Common\Exception\GuzzleException;
use Guzzle\Batch\BatchTransferInterface as TransferStrategy;
use Guzzle\Batch\BatchDivisorInterface as DivisorStrategy;

/**
 * Exception thrown during a batch transfer
 */
class BatchTransferException extends \Exception implements GuzzleException
{
    /** @var array The batch being sent when the exception occurred */
    protected $batch;

    /** @var TransferStrategy The transfer strategy in use when the exception occurred */
    protected $transferStrategy;

    /** @var DivisorStrategy The divisor strategy in use when the exception occurred */
    protected $divisorStrategy;

    /** @var array Items transferred at the point in which the exception was encountered */
    protected $transferredItems;

    /**
     * @param array            $batch            The batch being sent when the exception occurred
     * @param array            $transferredItems Items transferred at the point in which the exception was encountered
     * @param \Exception       $exception        Exception encountered
     * @param TransferStrategy $transferStrategy The transfer strategy in use when the exception occurred
     * @param DivisorStrategy  $divisorStrategy  The divisor strategy in use when the exception occurred
     */
    public function __construct(
        array $batch,
        array $transferredItems,
        \Exception $exception,
        TransferStrategy $transferStrategy = null,
        DivisorStrategy $divisorStrategy = null
    ) {
        $this->batch = $batch;
        $this->transferredItems = $transferredItems;
        $this->transferStrategy = $transferStrategy;
        $this->divisorStrategy = $divisorStrategy;
        parent::__construct(
            'Exception encountered while transferring batch: ' . $exception->getMessage(),
            $exception->getCode(),
            $exception
        );
    }

    /**
     * Get the batch that we being sent when the exception occurred
     *
     * @return array
     */
    public function getBatch()
    {
        return $this->batch;
    }

    /**
     * Get the items transferred at the point in which the exception was encountered
     *
     * @return array
     */
    public function getTransferredItems()
    {
        return $this->transferredItems;
    }

    /**
     * Get the transfer strategy
     *
     * @return TransferStrategy
     */
    public function getTransferStrategy()
    {
        return $this->transferStrategy;
    }

    /**
     * Get the divisor strategy
     *
     * @return DivisorStrategy
     */
    public function getDivisorStrategy()
    {
        return $this->divisorStrategy;
    }
}
{
    "name": "guzzle/batch",
    "description": "Guzzle batch component for batching requests, commands, or custom transfers",
    "homepage": "http://guzzlephp.org/",
    "keywords": ["batch", "HTTP", "REST", "guzzle"],
    "license": "MIT",
    "authors": [
        {
            "name": "Michael Dowling",
            "email": "mtdowling@gmail.com",
            "homepage": "https://github.com/mtdowling"
        }
    ],
    "require": {
        "php": ">=5.3.2",
        "guzzle/common": "self.version"
    },
    "autoload": {
        "psr-0": { "Guzzle\\Batch": "" }
    },
    "suggest": {
        "guzzle/http": "self.version",
        "guzzle/service": "self.version"
    },
    "target-dir": "Guzzle/Batch",
    "extra": {
        "branch-alias": {
            "dev-master": "3.7-dev"
        }
    }
}
<?php

namespace Guzzle\Batch;

/**
 * BatchInterface decorator used to keep a history of items that were added to the batch.  You must clear the history
 * manually to remove items from the history.
 */
class HistoryBatch extends AbstractBatchDecorator
{
    /** @var array Items in the history */
    protected $history = array();

    public function add($item)
    {
        $this->history[] = $item;
        $this->decoratedBatch->add($item);

        return $this;
    }

    /**
     * Get the batch history
     *
     * @return array
     */
    public function getHistory()
    {
        return $this->history;
    }

    /**
     * Clear the batch history
     */
    public function clearHistory()
    {
        $this->history = array();
    }
}
<?php

namespace Guzzle\Batch;

use Guzzle\Batch\BatchTransferInterface;
use Guzzle\Batch\BatchDivisorInterface;
use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Service\Command\CommandInterface;
use Guzzle\Service\Exception\InconsistentClientTransferException;

/**
 * Efficiently transfers multiple commands in parallel per client
 * This class is to be used with {@see Guzzle\Batch\BatchInterface}
 */
class BatchCommandTransfer implements BatchTransferInterface, BatchDivisorInterface
{
    /** @var int Size of each command batch */
    protected $batchSize;

    /**
     * @param int $batchSize Size of each batch
     */
    public function __construct($batchSize = 50)
    {
        $this->batchSize = $batchSize;
    }

    /**
     * Creates batches by grouping commands by their associated client
     * {@inheritdoc}
     */
    public function createBatches(\SplQueue $queue)
    {
        $groups = new \SplObjectStorage();
        foreach ($queue as $item) {
            if (!$item instanceof CommandInterface) {
                throw new InvalidArgumentException('All items must implement Guzzle\Service\Command\CommandInterface');
            }
            $client = $item->getClient();
            if (!$groups->contains($client)) {
                $groups->attach($client, new \ArrayObject(array($item)));
            } else {
                $groups[$client]->append($item);
            }
        }

        $batches = array();
        foreach ($groups as $batch) {
            $batches = array_merge($batches, array_chunk($groups[$batch]->getArrayCopy(), $this->batchSize));
        }

        return $batches;
    }

    public function transfer(array $batch)
    {
        if (empty($batch)) {
            return;
        }

        // Get the client of the first found command
        $client = reset($batch)->getClient();

        // Keep a list of all commands with invalid clients
        $invalid = array_filter($batch, function ($command) use ($client) {
            return $command->getClient() !== $client;
        });

        if (!empty($invalid)) {
            throw new InconsistentClientTransferException($invalid);
        }

        $client->execute($batch);
    }
}
<?php

namespace Guzzle\Batch;

use Guzzle\Common\Exception\InvalidArgumentException;

/**
 * Divides batches using a callable
 */
class BatchClosureDivisor implements BatchDivisorInterface
{
    /** @var callable Method used to divide the batches */
    protected $callable;

    /** @var mixed $context Context passed to the callable */
    protected $context;

    /**
     * @param callable $callable Method used to divide the batches. The method must accept an \SplQueue and return an
     *                           array of arrays containing the divided items.
     * @param mixed    $context  Optional context to pass to the batch divisor
     *
     * @throws InvalidArgumentException if the callable is not callable
     */
    public function __construct($callable, $context = null)
    {
        if (!is_callable($callable)) {
            throw new InvalidArgumentException('Must pass a callable');
        }

        $this->callable = $callable;
        $this->context = $context;
    }

    public function createBatches(\SplQueue $queue)
    {
        return call_user_func($this->callable, $queue, $this->context);
    }
}
<?php

namespace Guzzle\Batch;

use Guzzle\Batch\Exception\BatchTransferException;

/**
 * BatchInterface decorator used to buffer exceptions encountered during a transfer.  The exceptions can then later be
 * processed after a batch flush has completed.
 */
class ExceptionBufferingBatch extends AbstractBatchDecorator
{
    /** @var array Array of BatchTransferException exceptions */
    protected $exceptions = array();

    public function flush()
    {
        $items = array();

        while (!$this->decoratedBatch->isEmpty()) {
            try {
                $transferredItems = $this->decoratedBatch->flush();
            } catch (BatchTransferException $e) {
                $this->exceptions[] = $e;
                $transferredItems = $e->getTransferredItems();
            }
            $items = array_merge($items, $transferredItems);
        }

        return $items;
    }

    /**
     * Get the buffered exceptions
     *
     * @return array Array of BatchTransferException objects
     */
    public function getExceptions()
    {
        return $this->exceptions;
    }

    /**
     * Clear the buffered exceptions
     */
    public function clearExceptions()
    {
        $this->exceptions = array();
    }
}
<?php

namespace Guzzle\Batch;

use Guzzle\Batch\Exception\BatchTransferException;

/**
 * Default batch implementation used to convert queued items into smaller chunks of batches using a
 * {@see BatchDivisorIterface} and transfers each batch using a {@see BatchTransferInterface}.
 *
 * Any exception encountered during a flush operation will throw a {@see BatchTransferException} object containing the
 * batch that failed. After an exception is encountered, you can flush the batch again to attempt to finish transferring
 * any previously created batches or queued items.
 */
class Batch implements BatchInterface
{
    /** @var \SplQueue Queue of items in the queue */
    protected $queue;

    /** @var array Divided batches to be transferred */
    protected $dividedBatches;

    /** @var BatchTransferInterface */
    protected $transferStrategy;

    /** @var BatchDivisorInterface */
    protected $divisionStrategy;

    /**
     * @param BatchTransferInterface $transferStrategy Strategy used to transfer items
     * @param BatchDivisorInterface  $divisionStrategy Divisor used to create batches
     */
    public function __construct(BatchTransferInterface $transferStrategy, BatchDivisorInterface $divisionStrategy)
    {
        $this->transferStrategy = $transferStrategy;
        $this->divisionStrategy = $divisionStrategy;
        $this->queue = new \SplQueue();
        $this->queue->setIteratorMode(\SplQueue::IT_MODE_DELETE);
        $this->dividedBatches = array();
    }

    public function add($item)
    {
        $this->queue->enqueue($item);

        return $this;
    }

    public function flush()
    {
        $this->createBatches();

        $items = array();
        foreach ($this->dividedBatches as $batchIndex => $dividedBatch) {
            while ($dividedBatch->valid()) {
                $batch = $dividedBatch->current();
                $dividedBatch->next();
                try {
                    $this->transferStrategy->transfer($batch);
                    $items = array_merge($items, $batch);
                } catch (\Exception $e) {
                    throw new BatchTransferException($batch, $items, $e, $this->transferStrategy, $this->divisionStrategy);
                }
            }
            // Keep the divided batch down to a minimum in case of a later exception
            unset($this->dividedBatches[$batchIndex]);
        }

        return $items;
    }

    public function isEmpty()
    {
        return count($this->queue) == 0 && count($this->dividedBatches) == 0;
    }

    /**
     * Create batches for any queued items
     */
    protected function createBatches()
    {
        if (count($this->queue)) {
            if ($batches = $this->divisionStrategy->createBatches($this->queue)) {
                // Convert arrays into iterators
                if (is_array($batches)) {
                    $batches = new \ArrayIterator($batches);
                }
                $this->dividedBatches[] = $batches;
            }
        }
    }
}
<?php

namespace Guzzle\Batch;

use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Common\Exception\RuntimeException;

/**
 * Builder used to create custom batch objects
 */
class BatchBuilder
{
    /** @var bool Whether or not the batch should automatically flush*/
    protected $autoFlush = false;

    /** @var bool Whether or not to maintain a batch history */
    protected $history = false;

    /** @var bool Whether or not to buffer exceptions encountered in transfer */
    protected $exceptionBuffering = false;

    /** @var mixed Callable to invoke each time a flush completes */
    protected $afterFlush;

    /** @var BatchTransferInterface Object used to transfer items in the queue */
    protected $transferStrategy;

    /** @var BatchDivisorInterface Object used to divide the queue into batches */
    protected $divisorStrategy;

    /** @var array of Mapped transfer strategies by handle name */
    protected static $mapping = array(
        'request' => 'Guzzle\Batch\BatchRequestTransfer',
        'command' => 'Guzzle\Batch\BatchCommandTransfer'
    );

    /**
     * Create a new instance of the BatchBuilder
     *
     * @return BatchBuilder
     */
    public static function factory()
    {
        return new self();
    }

    /**
     * Automatically flush the batch when the size of the queue reaches a certain threshold. Adds {@see FlushingBatch}.
     *
     * @param $threshold Number of items to allow in the queue before a flush
     *
     * @return BatchBuilder
     */
    public function autoFlushAt($threshold)
    {
        $this->autoFlush = $threshold;

        return $this;
    }

    /**
     * Maintain a history of all items that have been transferred using the batch. Adds {@see HistoryBatch}.
     *
     * @return BatchBuilder
     */
    public function keepHistory()
    {
        $this->history = true;

        return $this;
    }

    /**
     * Buffer exceptions thrown during transfer so that you can transfer as much as possible, and after a transfer
     * completes, inspect each exception that was thrown. Enables the {@see ExceptionBufferingBatch} decorator.
     *
     * @return BatchBuilder
     */
    public function bufferExceptions()
    {
        $this->exceptionBuffering = true;

        return $this;
    }

    /**
     * Notify a callable each time a batch flush completes. Enables the {@see NotifyingBatch} decorator.
     *
     * @param mixed $callable Callable function to notify
     *
     * @return BatchBuilder
     * @throws InvalidArgumentException if the argument is not callable
     */
    public function notify($callable)
    {
        $this->afterFlush = $callable;

        return $this;
    }

    /**
     * Configures the batch to transfer batches of requests. Associates a {@see \Guzzle\Http\BatchRequestTransfer}
     * object as both the transfer and divisor strategy.
     *
     * @param int $batchSize Batch size for each batch of requests
     *
     * @return BatchBuilder
     */
    public function transferRequests($batchSize = 50)
    {
        $className = self::$mapping['request'];
        $this->transferStrategy = new $className($batchSize);
        $this->divisorStrategy = $this->transferStrategy;

        return $this;
    }

    /**
     * Configures the batch to transfer batches commands. Associates as
     * {@see \Guzzle\Service\Command\BatchCommandTransfer} as both the transfer and divisor strategy.
     *
     * @param int $batchSize Batch size for each batch of commands
     *
     * @return BatchBuilder
     */
    public function transferCommands($batchSize = 50)
    {
        $className = self::$mapping['command'];
        $this->transferStrategy = new $className($batchSize);
        $this->divisorStrategy = $this->transferStrategy;

        return $this;
    }

    /**
     * Specify the strategy used to divide the queue into an array of batches
     *
     * @param BatchDivisorInterface $divisorStrategy Strategy used to divide a batch queue into batches
     *
     * @return BatchBuilder
     */
    public function createBatchesWith(BatchDivisorInterface $divisorStrategy)
    {
        $this->divisorStrategy = $divisorStrategy;

        return $this;
    }

    /**
     * Specify the strategy used to transport the items when flush is called
     *
     * @param BatchTransferInterface $transferStrategy How items are transferred
     *
     * @return BatchBuilder
     */
    public function transferWith(BatchTransferInterface $transferStrategy)
    {
        $this->transferStrategy = $transferStrategy;

        return $this;
    }

    /**
     * Create and return the instantiated batch
     *
     * @return BatchInterface
     * @throws RuntimeException if no transfer strategy has been specified
     */
    public function build()
    {
        if (!$this->transferStrategy) {
            throw new RuntimeException('No transfer strategy has been specified');
        }

        if (!$this->divisorStrategy) {
            throw new RuntimeException('No divisor strategy has been specified');
        }

        $batch = new Batch($this->transferStrategy, $this->divisorStrategy);

        if ($this->exceptionBuffering) {
            $batch = new ExceptionBufferingBatch($batch);
        }

        if ($this->afterFlush) {
            $batch = new NotifyingBatch($batch, $this->afterFlush);
        }

        if ($this->autoFlush) {
            $batch = new FlushingBatch($batch, $this->autoFlush);
        }

        if ($this->history) {
            $batch = new HistoryBatch($batch);
        }

        return $batch;
    }
}
<?php

namespace Guzzle\Batch;

/**
 * Interface used for dividing a queue of items into an array of batches
 */
interface BatchDivisorInterface
{
    /**
     * Divide a queue of items into an array batches
     *
     * @param \SplQueue $queue Queue of items to divide into batches. Items are removed as they are iterated.
     *
     * @return array|\Traversable Returns an array or Traversable object that contains arrays of items to transfer
     */
    public function createBatches(\SplQueue $queue);
}
<?php

namespace Guzzle\Batch;

use Guzzle\Common\Exception\InvalidArgumentException;

/**
 * BatchInterface decorator used to call a method each time flush is called
 */
class NotifyingBatch extends AbstractBatchDecorator
{
    /** @var mixed Callable to call */
    protected $callable;

    /**
     * @param BatchInterface $decoratedBatch Batch object to decorate
     * @param mixed          $callable       Callable to call
     *
     * @throws InvalidArgumentException
     */
    public function __construct(BatchInterface $decoratedBatch, $callable)
    {
        if (!is_callable($callable)) {
            throw new InvalidArgumentException('The passed argument is not callable');
        }

        $this->callable = $callable;
        parent::__construct($decoratedBatch);
    }

    public function flush()
    {
        $items = $this->decoratedBatch->flush();
        call_user_func($this->callable, $items);

        return $items;
    }
}
<?php

namespace Guzzle\Batch;

/**
 * Interface used for transferring batches of items
 */
interface BatchTransferInterface
{
    /**
     * Transfer an array of items
     *
     * @param array $batch Array of items to transfer
     */
    public function transfer(array $batch);
}
<?php

namespace Guzzle\Batch;

use Guzzle\Common\Exception\InvalidArgumentException;

/**
 * Batch transfer strategy where transfer logic can be defined via a Closure.
 * This class is to be used with {@see Guzzle\Batch\BatchInterface}
 */
class BatchClosureTransfer implements BatchTransferInterface
{
    /** @var callable A closure that performs the transfer */
    protected $callable;

    /** @var mixed $context Context passed to the callable */
    protected $context;

    /**
     * @param mixed $callable Callable that performs the transfer. This function should accept two arguments:
     *                        (array $batch, mixed $context).
     * @param mixed $context  Optional context to pass to the batch divisor
     *
     * @throws InvalidArgumentException
     */
    public function __construct($callable, $context = null)
    {
        if (!is_callable($callable)) {
            throw new InvalidArgumentException('Argument must be callable');
        }

        $this->callable = $callable;
        $this->context = $context;
    }

    public function transfer(array $batch)
    {
        return empty($batch) ? null : call_user_func($this->callable, $batch, $this->context);
    }
}
<?php

namespace Guzzle\Batch;

/**
 * BatchInterface decorator used to add automatic flushing of the queue when the size of the queue reaches a threshold.
 */
class FlushingBatch extends AbstractBatchDecorator
{
    /** @var int The threshold for which to automatically flush */
    protected $threshold;

    /** @var int Current number of items known to be in the queue */
    protected $currentTotal = 0;

    /**
     * @param BatchInterface $decoratedBatch  BatchInterface that is being decorated
     * @param int            $threshold       Flush when the number in queue matches the threshold
     */
    public function __construct(BatchInterface $decoratedBatch, $threshold)
    {
        $this->threshold = $threshold;
        parent::__construct($decoratedBatch);
    }

    /**
     * Set the auto-flush threshold
     *
     * @param int $threshold The auto-flush threshold
     *
     * @return FlushingBatch
     */
    public function setThreshold($threshold)
    {
        $this->threshold = $threshold;

        return $this;
    }

    /**
     * Get the auto-flush threshold
     *
     * @return int
     */
    public function getThreshold()
    {
        return $this->threshold;
    }

    public function add($item)
    {
        $this->decoratedBatch->add($item);
        if (++$this->currentTotal >= $this->threshold) {
            $this->currentTotal = 0;
            $this->decoratedBatch->flush();
        }

        return $this;
    }
}
<?php

namespace Guzzle\Batch;

/**
 * Abstract decorator used when decorating a BatchInterface
 */
abstract class AbstractBatchDecorator implements BatchInterface
{
    /** @var BatchInterface Decorated batch object */
    protected $decoratedBatch;

    /**
     * @param BatchInterface $decoratedBatch  BatchInterface that is being decorated
     */
    public function __construct(BatchInterface $decoratedBatch)
    {
        $this->decoratedBatch = $decoratedBatch;
    }

    /**
     * Allow decorators to implement custom methods
     *
     * @param string $method Missing method name
     * @param array  $args   Method arguments
     *
     * @return mixed
     * @codeCoverageIgnore
     */
    public function __call($method, array $args)
    {
        return call_user_func_array(array($this->decoratedBatch, $method), $args);
    }

    public function add($item)
    {
        $this->decoratedBatch->add($item);

        return $this;
    }

    public function flush()
    {
        return $this->decoratedBatch->flush();
    }

    public function isEmpty()
    {
        return $this->decoratedBatch->isEmpty();
    }

    /**
     * Trace the decorators associated with the batch
     *
     * @return array
     */
    public function getDecorators()
    {
        $found = array($this);
        if (method_exists($this->decoratedBatch, 'getDecorators')) {
            $found = array_merge($found, $this->decoratedBatch->getDecorators());
        }

        return $found;
    }
}
<?php

namespace Guzzle\Batch;

use Guzzle\Batch\BatchTransferInterface;
use Guzzle\Batch\BatchDivisorInterface;
use Guzzle\Common\Exception\InvalidArgumentException;
use Guzzle\Http\Message\RequestInterface;

/**
 * Batch transfer strategy used to efficiently transfer a batch of requests.
 * This class is to be used with {@see Guzzle\Batch\BatchInterface}
 */
class BatchRequestTransfer implements BatchTransferInterface, BatchDivisorInterface
{
    /** @var int Size of each command batch */
    protected $batchSize;

    /**
     * Constructor used to specify how large each batch should be
     *
     * @param int $batchSize Size of each batch
     */
    public function __construct($batchSize = 50)
    {
        $this->batchSize = $batchSize;
    }

    /**
     * Creates batches of requests by grouping requests by their associated curl multi object.
     * {@inheritdoc}
     */
    public function createBatches(\SplQueue $queue)
    {
        // Create batches by client objects
        $groups = new \SplObjectStorage();
        foreach ($queue as $item) {
            if (!$item instanceof RequestInterface) {
                throw new InvalidArgumentException('All items must implement Guzzle\Http\Message\RequestInterface');
            }
            $client = $item->getClient();
            if (!$groups->contains($client)) {
                $groups->attach($client, array($item));
            } else {
                $current = $groups[$client];
                $current[] = $item;
                $groups[$client] = $current;
            }
        }

        $batches = array();
        foreach ($groups as $batch) {
            $batches = array_merge($batches, array_chunk($groups[$batch], $this->batchSize));
        }

        return $batches;
    }

    public function transfer(array $batch)
    {
        if ($batch) {
            reset($batch)->getClient()->send($batch);
        }
    }
}
{
    "name": "guzzle/iterator",
    "description": "Provides helpful iterators and iterator decorators",
    "keywords": ["iterator", "guzzle"],
    "homepage": "http://guzzlephp.org/",
    "license": "MIT",
    "authors": [
        {
            "name": "Michael Dowling",
            "email": "mtdowling@gmail.com",
            "homepage": "https://github.com/mtdowling"
        }
    ],
    "require": {
        "php": ">=5.3.2",
        "guzzle/common": ">=2.8.0"
    },
    "autoload": {
        "psr-0": { "Guzzle\\Iterator": "/" }
    },
    "target-dir": "Guzzle/Iterator",
    "extra": {
        "branch-alias": {
            "dev-master": "3.7-dev"
        }
    }
}
<?php

namespace Guzzle\Iterator;

/**
 * AppendIterator that is not affected by https://bugs.php.net/bug.php?id=49104
 */
class AppendIterator extends \AppendIterator
{
    /**
     * Works around the bug in which PHP calls rewind() and next() when appending
     *
     * @param \Iterator $iterator Iterator to append
     */
    public function append(\Iterator $iterator)
    {
        $this->getArrayIterator()->append($iterator);
    }
}
<?php

namespace Guzzle\Iterator;

use Guzzle\Common\Exception\InvalidArgumentException;

/**
 * Filters values using a callback
 *
 * Used when PHP 5.4's {@see \CallbackFilterIterator} is not available
 */
class FilterIterator extends \FilterIterator
{
    /** @var mixed Callback used for filtering */
    protected $callback;

    /**
     * @param \Iterator      $iterator Traversable iterator
     * @param array|\Closure $callback Callback used for filtering. Return true to keep or false to filter.
     *
     * @throws InvalidArgumentException if the callback if not callable
     */
    public function __construct(\Iterator $iterator, $callback)
    {
        parent::__construct($iterator);
        if (!is_callable($callback)) {
            throw new InvalidArgumentException('The callback must be callable');
        }
        $this->callback = $callback;
    }

    public function accept()
    {
        return call_user_func($this->callback, $this->current());
    }
}
<?php

namespace Guzzle\Iterator;

use Guzzle\Common\Exception\InvalidArgumentException;

/**
 * Maps values before yielding
 */
class MapIterator extends \IteratorIterator
{
    /** @var mixed Callback */
    protected $callback;

    /**
     * @param \Traversable   $iterator Traversable iterator
     * @param array|\Closure $callback Callback used for iterating
     *
     * @throws InvalidArgumentException if the callback if not callable
     */
    public function __construct(\Traversable $iterator, $callback)
    {
        parent::__construct($iterator);
        if (!is_callable($callback)) {
            throw new InvalidArgumentException('The callback must be callable');
        }
        $this->callback = $callback;
    }

    public function current()
    {
        return call_user_func($this->callback, parent::current());
    }
}
<?php

namespace Guzzle\Iterator;

/**
 * Proxies missing method calls to the innermost iterator
 */
class MethodProxyIterator extends \IteratorIterator
{
    /**
     * Proxy method calls to the wrapped iterator
     *
     * @param string $name Name of the method
     * @param array  $args Arguments to proxy
     *
     * @return mixed
     */
    public function __call($name, array $args)
    {
        $i = $this->getInnerIterator();
        while ($i instanceof \OuterIterator) {
            $i = $i->getInnerIterator();
        }

        return call_user_func_array(array($i, $name), $args);
    }
}
Guzzle Iterator
===============

Provides useful Iterators and Iterator decorators

- ChunkedIterator: Pulls out chunks from an inner iterator and yields the chunks as arrays
- FilterIterator: Used when PHP 5.4's CallbackFilterIterator is not available
- MapIterator: Maps values before yielding
- MethodProxyIterator: Proxies missing method calls to the innermost iterator

### Installing via Composer

```bash
# Install Composer
curl -sS https://getcomposer.org/installer | php

# Add Guzzle as a dependency
php composer.phar require guzzle/iterator:~3.0
```

After installing, you need to require Composer's autoloader:

```php
require 'vendor/autoload.php';
```
<?php

namespace Guzzle\Iterator;

/**
 * Pulls out chunks from an inner iterator and yields the chunks as arrays
 */
class ChunkedIterator extends \IteratorIterator
{
    /** @var int Size of each chunk */
    protected $chunkSize;

    /** @var array Current chunk */
    protected $chunk;

    /**
     * @param \Traversable $iterator  Traversable iterator
     * @param int          $chunkSize Size to make each chunk
     * @throws \InvalidArgumentException
     */
    public function __construct(\Traversable $iterator, $chunkSize)
    {
        $chunkSize = (int) $chunkSize;
        if ($chunkSize < 0 ) {
            throw new \InvalidArgumentException("The chunk size must be equal or greater than zero; $chunkSize given");
        }

        parent::__construct($iterator);
        $this->chunkSize = $chunkSize;
    }

    public function rewind()
    {
        parent::rewind();
        $this->next();
    }

    public function next()
    {
        $this->chunk = array();
        for ($i = 0; $i < $this->chunkSize && parent::valid(); $i++) {
            $this->chunk[] = parent::current();
            parent::next();
        }
    }

    public function current()
    {
        return $this->chunk;
    }

    public function valid()
    {
        return (bool) $this->chunk;
    }
}
<?php

namespace Guzzle\Inflection;

/**
 * Decorator used to add memoization to previously inflected words
 */
class MemoizingInflector implements InflectorInterface
{
    /** @var array Array of cached inflections */
    protected $cache = array(
        'snake' => array(),
        'camel' => array()
    );

    /** @var int Max entries per cache */
    protected $maxCacheSize;

    /** @var InflectorInterface Decorated inflector */
    protected $decoratedInflector;

    /**
     * @param InflectorInterface $inflector    Inflector being decorated
     * @param int                $maxCacheSize Maximum number of cached items to hold per cache
     */
    public function __construct(InflectorInterface $inflector, $maxCacheSize = 500)
    {
        $this->decoratedInflector = $inflector;
        $this->maxCacheSize = $maxCacheSize;
    }

    public function snake($word)
    {
        if (!isset($this->cache['snake'][$word])) {
            $this->pruneCache('snake');
            $this->cache['snake'][$word] = $this->decoratedInflector->snake($word);
        }

        return $this->cache['snake'][$word];
    }

    /**
     * Converts strings from snake_case to upper CamelCase
     *
     * @param string $word Value to convert into upper CamelCase
     *
     * @return string
     */
    public function camel($word)
    {
        if (!isset($this->cache['camel'][$word])) {
            $this->pruneCache('camel');
            $this->cache['camel'][$word] = $this->decoratedInflector->camel($word);
        }

        return $this->cache['camel'][$word];
    }

    /**
     * Prune one of the named caches by removing 20% of the cache if it is full
     *
     * @param string $cache Type of cache to prune
     */
    protected function pruneCache($cache)
    {
        if (count($this->cache[$cache]) == $this->maxCacheSize) {
            $this->cache[$cache] = array_slice($this->cache[$cache], $this->maxCacheSize * 0.2);
        }
    }
}
{
    "name": "guzzle/inflection",
    "description": "Guzzle inflection component",
    "homepage": "http://guzzlephp.org/",
    "keywords": ["inflection", "guzzle"],
    "license": "MIT",
    "authors": [
        {
            "name": "Michael Dowling",
            "email": "mtdowling@gmail.com",
            "homepage": "https://github.com/mtdowling"
        }
    ],
    "require": {
        "php": ">=5.3.2"
    },
    "autoload": {
        "psr-0": { "Guzzle\\Inflection": "" }
    },
    "target-dir": "Guzzle/Inflection",
    "extra": {
        "branch-alias": {
            "dev-master": "3.7-dev"
        }
    }
}
<?php

namespace Guzzle\Inflection;

/**
 * Decorator used to add pre-computed inflection mappings to an inflector
 */
class PreComputedInflector implements InflectorInterface
{
    /** @var array Array of pre-computed inflections */
    protected $mapping = array(
        'snake' => array(),
        'camel' => array()
    );

    /** @var InflectorInterface Decorated inflector */
    protected $decoratedInflector;

    /**
     * @param InflectorInterface $inflector Inflector being decorated
     * @param array              $snake     Hash of pre-computed camel to snake
     * @param array              $camel     Hash of pre-computed snake to camel
     * @param bool               $mirror    Mirror snake and camel reflections
     */
    public function __construct(InflectorInterface $inflector, array $snake = array(), array $camel = array(), $mirror = false)
    {
        if ($mirror) {
            $camel = array_merge(array_flip($snake), $camel);
            $snake = array_merge(array_flip($camel), $snake);
        }

        $this->decoratedInflector = $inflector;
        $this->mapping = array(
            'snake' => $snake,
            'camel' => $camel
        );
    }

    public function snake($word)
    {
        return isset($this->mapping['snake'][$word])
            ? $this->mapping['snake'][$word]
            : $this->decoratedInflector->snake($word);
    }

    /**
     * Converts strings from snake_case to upper CamelCase
     *
     * @param string $word Value to convert into upper CamelCase
     *
     * @return string
     */
    public function camel($word)
    {
        return isset($this->mapping['camel'][$word])
            ? $this->mapping['camel'][$word]
            : $this->decoratedInflector->camel($word);
    }
}
<?php

namespace Guzzle\Inflection;

/**
 * Default inflection implementation
 */
class Inflector implements InflectorInterface
{
    /** @var InflectorInterface */
    protected static $default;

    /**
     * Get the default inflector object that has support for caching
     *
     * @return MemoizingInflector
     */
    public static function getDefault()
    {
        // @codeCoverageIgnoreStart
        if (!self::$default) {
            self::$default = new MemoizingInflector(new self());
        }
        // @codeCoverageIgnoreEnd

        return self::$default;
    }

    public function snake($word)
    {
        return ctype_lower($word) ? $word : strtolower(preg_replace('/(.)([A-Z])/', "$1_$2", $word));
    }

    public function camel($word)
    {
        return str_replace(' ', '', ucwords(strtr($word, '_-', '  ')));
    }
}
<?php

namespace Guzzle\Inflection;

/**
 * Inflector interface used to convert the casing of words
 */
interface InflectorInterface
{
    /**
     * Converts strings from camel case to snake case (e.g. CamelCase camel_case).
     *
     * @param string $word Word to convert to snake case
     *
     * @return string
     */
    public function snake($word);

    /**
     * Converts strings from snake_case to upper CamelCase
     *
     * @param string $word Value to convert into upper CamelCase
     *
     * @return string
     */
    public function camel($word);
}
<?php

namespace Guzzle\Parser\Url;

use Guzzle\Common\Version;

/**
 * Parses URLs into parts using PHP's built-in parse_url() function
 * @deprecated Just use parse_url. UTF-8 characters should be percent encoded anyways.
 * @codeCoverageIgnore
 */
class UrlParser implements UrlParserInterface
{
    /** @var bool Whether or not to work with UTF-8 strings */
    protected $utf8 = false;

    /**
     * Set whether or not to attempt to handle UTF-8 strings (still WIP)
     *
     * @param bool $utf8 Set to TRUE to handle UTF string
     */
    public function setUtf8Support($utf8)
    {
        $this->utf8 = $utf8;
    }

    public function parseUrl($url)
    {
        Version::warn(__CLASS__ . ' is deprecated. Just use parse_url()');

        static $defaults = array('scheme' => null, 'host' => null, 'path' => null, 'port' => null, 'query' => null,
            'user' => null, 'pass' => null, 'fragment' => null);

        $parts = parse_url($url);

        // Need to handle query parsing specially for UTF-8 requirements
        if ($this->utf8 && isset($parts['query'])) {
            $queryPos = strpos($url, '?');
            if (isset($parts['fragment'])) {
                $parts['query'] = substr($url, $queryPos + 1, strpos($url, '#') - $queryPos - 1);
            } else {
                $parts['query'] = substr($url, $queryPos + 1);
            }
        }

        return $parts + $defaults;
    }
}
<?php

namespace Guzzle\Parser\Url;

/**
 * URL parser interface
 */
interface UrlParserInterface
{
    /**
     * Parse a URL using special handling for a subset of UTF-8 characters in the query string if needed.
     *
     * @param string $url URL to parse
     *
     * @return array Returns an array identical to what is returned from parse_url().  When an array key is missing from
     *               this array, you must fill it in with NULL to avoid warnings in calling code.
     */
    public function parseUrl($url);
}
<?php

namespace Guzzle\Parser\Message;

/**
 * Default request and response parser used by Guzzle. Optimized for speed.
 */
class MessageParser extends AbstractMessageParser
{
    public function parseRequest($message)
    {
        if (!$message) {
            return false;
        }

        $parts = $this->parseMessage($message);

        // Parse the protocol and protocol version
        if (isset($parts['start_line'][2])) {
            $startParts = explode('/', $parts['start_line'][2]);
            $protocol = strtoupper($startParts[0]);
            $version = isset($startParts[1]) ? $startParts[1] : '1.1';
        } else {
            $protocol = 'HTTP';
            $version = '1.1';
        }

        $parsed = array(
            'method'   => strtoupper($parts['start_line'][0]),
            'protocol' => $protocol,
            'version'  => $version,
            'headers'  => $parts['headers'],
            'body'     => $parts['body']
        );

        $parsed['request_url'] = $this->getUrlPartsFromMessage(isset($parts['start_line'][1]) ? $parts['start_line'][1] : '' , $parsed);

        return $parsed;
    }

    public function parseResponse($message)
    {
        if (!$message) {
            return false;
        }

        $parts = $this->parseMessage($message);
        list($protocol, $version) = explode('/', trim($parts['start_line'][0]));

        return array(
            'protocol'      => $protocol,
            'version'       => $version,
            'code'          => $parts['start_line'][1],
            'reason_phrase' => isset($parts['start_line'][2]) ? $parts['start_line'][2] : '',
            'headers'       => $parts['headers'],
            'body'          => $parts['body']
        );
    }

    /**
     * Parse a message into parts
     *
     * @param string $message Message to parse
     *
     * @return array
     */
    protected function parseMessage($message)
    {
        $startLine = null;
        $headers = array();
        $body = '';

        // Iterate over each line in the message, accounting for line endings
        $lines = preg_split('/(\\r?\\n)/', $message, -1, PREG_SPLIT_DELIM_CAPTURE);
        for ($i = 0, $totalLines = count($lines); $i < $totalLines; $i += 2) {

            $line = $lines[$i];

            // If two line breaks were encountered, then this is the end of body
            if (empty($line)) {
                if ($i < $totalLines - 1) {
                    $body = implode('', array_slice($lines, $i + 2));
                }
                break;
            }

            // Parse message headers
            if (!$startLine) {
                $startLine = explode(' ', $line, 3);
            } elseif (strpos($line, ':')) {
                $parts = explode(':', $line, 2);
                $key = trim($parts[0]);
                $value = isset($parts[1]) ? trim($parts[1]) : '';
                if (!isset($headers[$key])) {
                    $headers[$key] = $value;
                } elseif (!is_array($headers[$key])) {
                    $headers[$key] = array($headers[$key], $value);
                } else {
                    $headers[$key][] = $value;
                }
            }
        }

        return array(
            'start_line' => $startLine,
            'headers'    => $headers,
            'body'       => $body
        );
    }
}
<?php

namespace Guzzle\Parser\Message;

/**
 * HTTP message parser interface used to parse HTTP messages into an array
 */
interface MessageParserInterface
{
    /**
     * Parse an HTTP request message into an associative array of parts.
     *
     * @param string $message HTTP request to parse
     *
     * @return array|bool Returns false if the message is invalid
     */
    public function parseRequest($message);

    /**
     * Parse an HTTP response message into an associative array of parts.
     *
     * @param string $message HTTP response to parse
     *
     * @return array|bool Returns false if the message is invalid
     */
    public function parseResponse($message);
}
<?php

namespace Guzzle\Parser\Message;

/**
 * Pecl HTTP message parser
 */
class PeclHttpMessageParser extends AbstractMessageParser
{
    public function parseRequest($message)
    {
        if (!$message) {
            return false;
        }

        $parts = http_parse_message($message);

        $parsed = array(
            'method'   => $parts->requestMethod,
            'protocol' => 'HTTP',
            'version'  => number_format($parts->httpVersion, 1),
            'headers'  => $parts->headers,
            'body'     => $parts->body
        );

        $parsed['request_url'] = $this->getUrlPartsFromMessage($parts->requestUrl, $parsed);

        return $parsed;
    }

    public function parseResponse($message)
    {
        if (!$message) {
            return false;
        }

        $parts = http_parse_message($message);

        return array(
            'protocol'      => 'HTTP',
            'version'       => number_format($parts->httpVersion, 1),
            'code'          => $parts->responseCode,
            'reason_phrase' => $parts->responseStatus,
            'headers'       => $parts->headers,
            'body'          => $parts->body
        );
    }
}
<?php

namespace Guzzle\Parser\Message;

/**
 * Implements shared message parsing functionality
 */
abstract class AbstractMessageParser implements MessageParserInterface
{
    /**
     * Create URL parts from HTTP message parts
     *
     * @param string $requestUrl Associated URL
     * @param array  $parts      HTTP message parts
     *
     * @return array
     */
    protected function getUrlPartsFromMessage($requestUrl, array $parts)
    {
        // Parse the URL information from the message
        $urlParts = array(
            'path'   => $requestUrl,
            'scheme' => 'http'
        );

        // Check for the Host header
        if (isset($parts['headers']['Host'])) {
            $urlParts['host'] = $parts['headers']['Host'];
        } elseif (isset($parts['headers']['host'])) {
            $urlParts['host'] = $parts['headers']['host'];
        } else {
            $urlParts['host'] = null;
        }

        if (false === strpos($urlParts['host'], ':')) {
            $urlParts['port'] = '';
        } else {
            $hostParts = explode(':', $urlParts['host']);
            $urlParts['host'] = trim($hostParts[0]);
            $urlParts['port'] = (int) trim($hostParts[1]);
            if ($urlParts['port'] == 443) {
                $urlParts['scheme'] = 'https';
            }
        }

        // Check if a query is present
        $path = $urlParts['path'];
        $qpos = strpos($path, '?');
        if ($qpos) {
            $urlParts['query'] = substr($path, $qpos + 1);
            $urlParts['path'] = substr($path, 0, $qpos);
        } else {
            $urlParts['query'] = '';
        }

        return $urlParts;
    }
}
{
    "name": "guzzle/parser",
    "homepage": "http://guzzlephp.org/",
    "description": "Interchangeable parsers used by Guzzle",
    "keywords": ["HTTP", "message", "cookie", "URL", "URI Template"],
    "license": "MIT",
    "require": {
        "php": ">=5.3.2"
    },
    "autoload": {
        "psr-0": { "Guzzle\\Parser": "" }
    },
    "target-dir": "Guzzle/Parser",
    "extra": {
        "branch-alias": {
            "dev-master": "3.7-dev"
        }
    }
}
<?php

namespace Guzzle\Parser\UriTemplate;

/**
 * Expands URI templates using an array of variables
 *
 * @link http://tools.ietf.org/html/rfc6570
 */
interface UriTemplateInterface
{
    /**
     * Expand the URI template using the supplied variables
     *
     * @param string $template  URI Template to expand
     * @param array  $variables Variables to use with the expansion
     *
     * @return string Returns the expanded template
     */
    public function expand($template, array $variables);
}
<?php

namespace Guzzle\Parser\UriTemplate;

use Guzzle\Common\Exception\RuntimeException;

/**
 * Expands URI templates using the uri_template pecl extension (pecl install uri_template-beta)
 *
 * @link http://pecl.php.net/package/uri_template
 * @link https://github.com/ioseb/uri-template
 */
class PeclUriTemplate implements UriTemplateInterface
{
    public function __construct()
    {
        if (!extension_loaded('uri_template')) {
            throw new RuntimeException('uri_template PECL extension must be installed to use PeclUriTemplate');
        }
    }

    public function expand($template, array $variables)
    {
        return uri_template($template, $variables);
    }
}
<?php

namespace Guzzle\Parser\UriTemplate;

/**
 * Expands URI templates using an array of variables
 *
 * @link http://tools.ietf.org/html/draft-gregorio-uritemplate-08
 */
class UriTemplate implements UriTemplateInterface
{
    const DEFAULT_PATTERN = '/\{([^\}]+)\}/';

    /** @var string URI template */
    private $template;

    /** @var array Variables to use in the template expansion */
    private $variables;

    /** @var string Regex used to parse expressions */
    private $regex = self::DEFAULT_PATTERN;

    /** @var array Hash for quick operator lookups */
    private static $operatorHash = array(
        '+' => true, '#' => true, '.' => true, '/' => true, ';' => true, '?' => true, '&' => true
    );

    /** @var array Delimiters */
    private static $delims = array(
        ':', '/', '?', '#', '[', ']', '@', '!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '='
    );

    /** @var array Percent encoded delimiters */
    private static $delimsPct = array(
        '%3A', '%2F', '%3F', '%23', '%5B', '%5D', '%40', '%21', '%24', '%26', '%27', '%28', '%29', '%2A', '%2B', '%2C',
        '%3B', '%3D'
    );

    public function expand($template, array $variables)
    {
        if ($this->regex == self::DEFAULT_PATTERN && false === strpos($template, '{')) {
            return $template;
        }

        $this->template = $template;
        $this->variables = $variables;

        return preg_replace_callback($this->regex, array($this, 'expandMatch'), $this->template);
    }

    /**
     * Set the regex patten used to expand URI templates
     *
     * @param string $regexPattern
     */
    public function setRegex($regexPattern)
    {
        $this->regex = $regexPattern;
    }

    /**
     * Parse an expression into parts
     *
     * @param string $expression Expression to parse
     *
     * @return array Returns an associative array of parts
     */
    private function parseExpression($expression)
    {
        // Check for URI operators
        $operator = '';

        if (isset(self::$operatorHash[$expression[0]])) {
            $operator = $expression[0];
            $expression = substr($expression, 1);
        }

        $values = explode(',', $expression);
        foreach ($values as &$value) {
            $value = trim($value);
            $varspec = array();
            $substrPos = strpos($value, ':');
            if ($substrPos) {
                $varspec['value'] = substr($value, 0, $substrPos);
                $varspec['modifier'] = ':';
                $varspec['position'] = (int) substr($value, $substrPos + 1);
            } elseif (substr($value, -1) == '*') {
                $varspec['modifier'] = '*';
                $varspec['value'] = substr($value, 0, -1);
            } else {
                $varspec['value'] = (string) $value;
                $varspec['modifier'] = '';
            }
            $value = $varspec;
        }

        return array(
            'operator' => $operator,
            'values'   => $values
        );
    }

    /**
     * Process an expansion
     *
     * @param array $matches Matches met in the preg_replace_callback
     *
     * @return string Returns the replacement string
     */
    private function expandMatch(array $matches)
    {
        static $rfc1738to3986 = array(
            '+'   => '%20',
            '%7e' => '~'
        );

        $parsed = self::parseExpression($matches[1]);
        $replacements = array();

        $prefix = $parsed['operator'];
        $joiner = $parsed['operator'];
        $useQueryString = false;
        if ($parsed['operator'] == '?') {
            $joiner = '&';
            $useQueryString = true;
        } elseif ($parsed['operator'] == '&') {
            $useQueryString = true;
        } elseif ($parsed['operator'] == '#') {
            $joiner = ',';
        } elseif ($parsed['operator'] == ';') {
            $useQueryString = true;
        } elseif ($parsed['operator'] == '' || $parsed['operator'] == '+') {
            $joiner = ',';
            $prefix = '';
        }

        foreach ($parsed['values'] as $value) {

            if (!array_key_exists($value['value'], $this->variables) || $this->variables[$value['value']] === null) {
                continue;
            }

            $variable = $this->variables[$value['value']];
            $actuallyUseQueryString = $useQueryString;
            $expanded = '';

            if (is_array($variable)) {

                $isAssoc = $this->isAssoc($variable);
                $kvp = array();
                foreach ($variable as $key => $var) {

                    if ($isAssoc) {
                        $key = rawurlencode($key);
                        $isNestedArray = is_array($var);
                    } else {
                        $isNestedArray = false;
                    }

                    if (!$isNestedArray) {
                        $var = rawurlencode($var);
                        if ($parsed['operator'] == '+' || $parsed['operator'] == '#') {
                            $var = $this->decodeReserved($var);
                        }
                    }

                    if ($value['modifier'] == '*') {
                        if ($isAssoc) {
                            if ($isNestedArray) {
                                // Nested arrays must allow for deeply nested structures
                                $var = strtr(http_build_query(array($key => $var)), $rfc1738to3986);
                            } else {
                                $var = $key . '=' . $var;
                            }
                        } elseif ($key > 0 && $actuallyUseQueryString) {
                            $var = $value['value'] . '=' . $var;
                        }
                    }

                    $kvp[$key] = $var;
                }

                if (empty($variable)) {
                    $actuallyUseQueryString = false;
                } elseif ($value['modifier'] == '*') {
                    $expanded = implode($joiner, $kvp);
                    if ($isAssoc) {
                        // Don't prepend the value name when using the explode modifier with an associative array
                        $actuallyUseQueryString = false;
                    }
                } else {
                    if ($isAssoc) {
                        // When an associative array is encountered and the explode modifier is not set, then the
                        // result must be a comma separated list of keys followed by their respective values.
                        foreach ($kvp as $k => &$v) {
                            $v = $k . ',' . $v;
                        }
                    }
                    $expanded = implode(',', $kvp);
                }

            } else {
                if ($value['modifier'] == ':') {
                    $variable = substr($variable, 0, $value['position']);
                }
                $expanded = rawurlencode($variable);
                if ($parsed['operator'] == '+' || $parsed['operator'] == '#') {
                    $expanded = $this->decodeReserved($expanded);
                }
            }

            if ($actuallyUseQueryString) {
                if (!$expanded && $joiner != '&') {
                    $expanded = $value['value'];
                } else {
                    $expanded = $value['value'] . '=' . $expanded;
                }
            }

            $replacements[] = $expanded;
        }

        $ret = implode($joiner, $replacements);
        if ($ret && $prefix) {
            return $prefix . $ret;
        }

        return $ret;
    }

    /**
     * Determines if an array is associative
     *
     * @param array $array Array to check
     *
     * @return bool
     */
    private function isAssoc(array $array)
    {
        return (bool) count(array_filter(array_keys($array), 'is_string'));
    }

    /**
     * Removes percent encoding on reserved characters (used with + and # modifiers)
     *
     * @param string $string String to fix
     *
     * @return string
     */
    private function decodeReserved($string)
    {
        return str_replace(self::$delimsPct, self::$delims, $string);
    }
}
<?php

namespace Guzzle\Parser;

/**
 * Registry of parsers used by the application
 */
class ParserRegistry
{
    /** @var ParserRegistry Singleton instance */
    protected static $instance;

    /** @var array Array of parser instances */
    protected $instances = array();

    /** @var array Mapping of parser name to default class */
    protected $mapping = array(
        'message'      => 'Guzzle\\Parser\\Message\\MessageParser',
        'cookie'       => 'Guzzle\\Parser\\Cookie\\CookieParser',
        'url'          => 'Guzzle\\Parser\\Url\\UrlParser',
        'uri_template' => 'Guzzle\\Parser\\UriTemplate\\UriTemplate',
    );

    /**
     * @return self
     * @codeCoverageIgnore
     */
    public static function getInstance()
    {
        if (!self::$instance) {
            self::$instance = new static;
        }

        return self::$instance;
    }

    public function __construct()
    {
        // Use the PECL URI template parser if available
        if (extension_loaded('uri_template')) {
            $this->mapping['uri_template'] = 'Guzzle\\Parser\\UriTemplate\\PeclUriTemplate';
        }
    }

    /**
     * Get a parser by name from an instance
     *
     * @param string $name Name of the parser to retrieve
     *
     * @return mixed|null
     */
    public function getParser($name)
    {
        if (!isset($this->instances[$name])) {
            if (!isset($this->mapping[$name])) {
                return null;
            }
            $class = $this->mapping[$name];
            $this->instances[$name] = new $class();
        }

        return $this->instances[$name];
    }

    /**
     * Register a custom parser by name with the register
     *
     * @param string $name   Name or handle of the parser to register
     * @param mixed  $parser Instantiated parser to register
     */
    public function registerParser($name, $parser)
    {
        $this->instances[$name] = $parser;
    }
}
<?php

namespace Guzzle\Parser\Cookie;

/**
 * Default Guzzle implementation of a Cookie parser
 */
class CookieParser implements CookieParserInterface
{
    /** @var array Cookie part names to snake_case array values */
    protected static $cookieParts = array(
        'domain'      => 'Domain',
        'path'        => 'Path',
        'max_age'     => 'Max-Age',
        'expires'     => 'Expires',
        'version'     => 'Version',
        'secure'      => 'Secure',
        'port'        => 'Port',
        'discard'     => 'Discard',
        'comment'     => 'Comment',
        'comment_url' => 'Comment-Url',
        'http_only'   => 'HttpOnly'
    );

    public function parseCookie($cookie, $host = null, $path = null, $decode = false)
    {
        // Explode the cookie string using a series of semicolons
        $pieces = array_filter(array_map('trim', explode(';', $cookie)));

        // The name of the cookie (first kvp) must include an equal sign.
        if (empty($pieces) || !strpos($pieces[0], '=')) {
            return false;
        }

        // Create the default return array
        $data = array_merge(array_fill_keys(array_keys(self::$cookieParts), null), array(
            'cookies'   => array(),
            'data'      => array(),
            'path'      => null,
            'http_only' => false,
            'discard'   => false,
            'domain'    => $host
        ));
        $foundNonCookies = 0;

        // Add the cookie pieces into the parsed data array
        foreach ($pieces as $part) {

            $cookieParts = explode('=', $part, 2);
            $key = trim($cookieParts[0]);

            if (count($cookieParts) == 1) {
                // Can be a single value (e.g. secure, httpOnly)
                $value = true;
            } else {
                // Be sure to strip wrapping quotes
                $value = trim($cookieParts[1], " \n\r\t\0\x0B\"");
                if ($decode) {
                    $value = urldecode($value);
                }
            }

            // Only check for non-cookies when cookies have been found
            if (!empty($data['cookies'])) {
                foreach (self::$cookieParts as $mapValue => $search) {
                    if (!strcasecmp($search, $key)) {
                        $data[$mapValue] = $mapValue == 'port' ? array_map('trim', explode(',', $value)) : $value;
                        $foundNonCookies++;
                        continue 2;
                    }
                }
            }

            // If cookies have not yet been retrieved, or this value was not found in the pieces array, treat it as a
            // cookie. IF non-cookies have been parsed, then this isn't a cookie, it's cookie data. Cookies then data.
            $data[$foundNonCookies ? 'data' : 'cookies'][$key] = $value;
        }

        // Calculate the expires date
        if (!$data['expires'] && $data['max_age']) {
            $data['expires'] = time() + (int) $data['max_age'];
        }

        // Check path attribute according RFC6265 http://tools.ietf.org/search/rfc6265#section-5.2.4
        // "If the attribute-value is empty or if the first character of the
        // attribute-value is not %x2F ("/"):
        //   Let cookie-path be the default-path.
        // Otherwise:
        //   Let cookie-path be the attribute-value."
        if (!$data['path'] || substr($data['path'], 0, 1) !== '/') {
            $data['path'] = $this->getDefaultPath($path);
        }

        return $data;
    }

    /**
     * Get default cookie path according to RFC 6265
     * http://tools.ietf.org/search/rfc6265#section-5.1.4 Paths and Path-Match
     *
     * @param string $path Request uri-path
     *
     * @return string
     */
    protected function getDefaultPath($path) {
        // "The user agent MUST use an algorithm equivalent to the following algorithm
        // to compute the default-path of a cookie:"

        // "2. If the uri-path is empty or if the first character of the uri-path is not
        // a %x2F ("/") character, output %x2F ("/") and skip the remaining steps.
        if (empty($path) || substr($path, 0, 1) !== '/') {
            return '/';
        }

        // "3. If the uri-path contains no more than one %x2F ("/") character, output
        // %x2F ("/") and skip the remaining step."
        if ($path === "/") {
            return $path;
        }

        $rightSlashPos = strrpos($path, '/');
        if ($rightSlashPos === 0) {
            return "/";
        }

        // "4. Output the characters of the uri-path from the first character up to,
        // but not including, the right-most %x2F ("/")."
        return substr($path, 0, $rightSlashPos);

    }
}
<?php

namespace Guzzle\Parser\Cookie;

/**
 * Cookie parser interface
 */
interface CookieParserInterface
{
    /**
     * Parse a cookie string as set in a Set-Cookie HTTP header and return an associative array of data.
     *
     * @param string $cookie Cookie header value to parse
     * @param string $host   Host of an associated request
     * @param string $path   Path of an associated request
     * @param bool   $decode Set to TRUE to urldecode cookie values
     *
     * @return array|bool Returns FALSE on failure or returns an array of arrays, with each of the sub arrays including:
     *     - domain  (string) - Domain of the cookie
     *     - path    (string) - Path of the cookie
     *     - cookies (array)  - Associative array of cookie names and values
     *     - max_age (int)    - Lifetime of the cookie in seconds
     *     - version (int)    - Version of the cookie specification. RFC 2965 is 1
     *     - secure  (bool)   - Whether or not this is a secure cookie
     *     - discard (bool)   - Whether or not this is a discardable cookie
     *     - custom (string)  - Custom cookie data array
     *     - comment (string) - How the cookie is intended to be used
     *     - comment_url (str)- URL that contains info on how it will be used
     *     - port (array|str) - Array of ports or null
     *     - http_only (bool) - HTTP only cookie
     */
    public function parseCookie($cookie, $host = null, $path = null, $decode = false);
}
Copyright (c) 2013-2015 KNP Labs

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
<?php

namespace Packagist\Api\Result;

use Doctrine\Common\Inflector\Inflector;

abstract class AbstractResult
{
    /**
     * @param array $data
     */
    public function fromArray(array $data)
    {
        foreach ($data as $key => $value) {
            $property = Inflector::camelize($key);
            $this->$property = $value;
        }
    }
}
<?php

namespace Packagist\Api\Result\Package;

class Dist extends Source
{
    /**
     * @var string
     */
    protected $shasum;

    /**
     * @var string
     */
    protected $type;

    /**
     * @var string
     */
    protected $url;

    /**
     * @var string
     */
    protected $reference;

    /**
     * @return string
     */
    public function getShasum()
    {
        return $this->shasum;
    }

    /**
     * @return string
     */
    public function getType()
    {
        return $this->type;
    }

    /**
     * @return string
     */
    public function getUrl()
    {
        return $this->url;
    }

    /**
     * @return string
     */
    public function getReference()
    {
        return $this->reference;
    }
}
<?php

namespace Packagist\Api\Result\Package;

class Author extends Maintainer
{
    /**
     * @var string
     */
    protected $role;

    /**
     * @return string
     */
    public function getRole()
    {
        return $this->role;
    }

}
<?php

namespace Packagist\Api\Result\Package;

use Packagist\Api\Result\AbstractResult;

class Source extends AbstractResult
{
    /**
     * @var string
     */
    protected $type;

    /**
     * @var string
     */
    protected $url;

    /**
     * @var string
     */
    protected $reference;

    /**
     * @return string
     */
    public function getType()
    {
        return $this->type;
    }

    /**
     * @return string
     */
    public function getUrl()
    {
        return $this->url;
    }

    /**
     * @return string
     */
    public function getReference()
    {
        return $this->reference;
    }
}
<?php

namespace Packagist\Api\Result\Package;

use Packagist\Api\Result\AbstractResult;

class Version extends AbstractResult
{
    /**
     * @var string
     */
    protected $name;

    /**
     * @var string
     */
    protected $description;

    /**
     * @var string
     */
    protected $keywords;

    /**
     * @var string
     */
    protected $homepage;

    /**
     * @var string
     */
    protected $version;

    /**
     * @var string
     */
    protected $versionNormalized;

    /**
     * @var string
     */
    protected $license;

    /**
     * @var array
     */
    protected $authors;

    /**
     * @var Source
     */
    protected $source;

    /**
     * @var Dist
     */
    protected $dist;

    /**
     * @var string
     */
    protected $type;

    /**
     * @var string
     */
    protected $time;

    /**
     * @var array
     */
    protected $autoload;

    /**
     * @var array
     */
    protected $extra;

    /**
     * @var array
     */
    protected $require;

    /**
     * @var array
     */
    protected $requireDev;

    /**
     * @var string
     */
    protected $conflict;

    /**
     * @var string
     */
    protected $provide;

    /**
     * @var string
     */
    protected $replace;

    /**
     * @var string
     */
    protected $bin;

    /**
     * @var array
     */
    protected $suggest;

    /**
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @return string
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * @return string
     */
    public function getKeywords()
    {
        return $this->keywords;
    }

    /**
     * @return string
     */
    public function getHomepage()
    {
        return $this->homepage;
    }

    /**
     * @return string
     */
    public function getVersion()
    {
        return $this->version;
    }

    /**
     * @return string
     */
    public function getVersionNormalized()
    {
        return $this->versionNormalized;
    }

    /**
     * @return string
     */
    public function getLicense()
    {
        return $this->license;
    }

    /**
     * @return array
     */
    public function getAuthors()
    {
        return $this->authors;
    }

    /**
     * @return Source
     */
    public function getSource()
    {
        return $this->source;
    }

    /**
     * @return Dist
     */
    public function getDist()
    {
        return $this->dist;
    }

    /**
     * @return string
     */
    public function getType()
    {
        return $this->type;
    }

    /**
     * @return string
     */
    public function getTime()
    {
        return $this->time;
    }

    /**
     * @return array
     */
    public function getAutoload()
    {
        return $this->autoload;
    }

    /**
     * @return array
     */
    public function getExtra()
    {
        return $this->extra;
    }

    /**
     * @return array
     */
    public function getRequire()
    {
        return $this->require;
    }

    /**
     * @return array
     */
    public function getRequireDev()
    {
        return $this->requireDev;
    }

    /**
     * @return string
     */
    public function getConflict()
    {
        return $this->conflict;
    }

    /**
     * @return string
     */
    public function getProvide()
    {
        return $this->provide;
    }

    /**
     * @return string
     */
    public function getReplace()
    {
        return $this->replace;
    }

    /**
     * @return string
     */
    public function getBin()
    {
        return $this->bin;
    }

    /**
     * @return array
     */
    public function getSuggest()
    {
        return $this->suggest;
    }
}
<?php

namespace Packagist\Api\Result\Package;

use Packagist\Api\Result\AbstractResult;

class Downloads extends AbstractResult
{
    /**
     * @var integer
     */
    protected $total;

    /**
     * @var integer
     */
    protected $monthly;

    /**
     * @var integer
     */
    protected $daily;

    /**
     * @param integer $total
     */
    public function setTotal($total)
    {
        $this->total = $total;
    }

    /**
     * @param integer $monthly
     */
    public function setMonthly($monthly)
    {
        $this->monthly = $monthly;
    }

    /**
     * @param integer $daily
     */
    public function setDaily($daily)
    {
        $this->daily = $daily;
    }

    /**
     * @return integer
     */
    public function getTotal()
    {
        return $this->total;
    }

    /**
     * @return integer
     */
    public function getMonthly()
    {
        return $this->monthly;
    }

    /**
     * @return integer
     */
    public function getDaily()
    {
        return $this->daily;
    }
}
<?php

namespace Packagist\Api\Result\Package;

use Packagist\Api\Result\AbstractResult;

class Maintainer extends AbstractResult
{
    /**
     * @var string
     */
    protected $name;

    /**
     * @var string
     */
    protected $email;

    /**
     * @var string
     */
    protected $homepage;

    /**
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @return string
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * @return string
     */
    public function getHomepage()
    {
        return $this->homepage;
    }
}
<?php

namespace Packagist\Api\Result;

class Package extends AbstractResult
{
    /**
     * @var string
     */
    protected $name;

    /**
     * @var string
     */
    protected $description;

    /**
     * @var string
     */
    protected $time;

    /**
     * @var Package\Maintainer
     */
    protected $maintainers;

    /**
     * @var Package\Version[]
     */
    protected $versions;

    /**
     * @var string
     */
    protected $type;

    /**
     * @var string
     */
    protected $repository;

    /**
     * @var Package\Downloads
     */
    protected $downloads;

    /**
     * @var string
     */
    protected $favers;

    /**
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @return string
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * @return string
     */
    public function getTime()
    {
        return $this->time;
    }

    /**
     * @return Package\Maintainer
     */
    public function getMaintainers()
    {
        return $this->maintainers;
    }

    /**
     * @return Package\Version
     */
    public function getVersions()
    {
        return $this->versions;
    }

    /**
     * @return string
     */
    public function getType()
    {
        return $this->type;
    }

    /**
     * @return string
     */
    public function getRepository()
    {
        return $this->repository;
    }

    /**
     * @return Package\Downloads
     */
    public function getDownloads()
    {
        return $this->downloads;
    }

    /**
     * @return string
     */
    public function getFavers()
    {
        return $this->favers;
    }
}
<?php

namespace Packagist\Api\Result;

class Result extends AbstractResult
{
    /**
     * @var string
     */
    protected $name;

    /**
     * @var string
     */
    protected $description;

    /**
     * @var string
     */
    protected $url;

    /**
     * @var string
     */
    protected $downloads;

    /**
     * @var string
     */
    protected $favers;

    /**
     * @var string
     */
    protected $repository;

    /**
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @return string
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * @return string
     */
    public function getUrl()
    {
        return $this->url;
    }

    /**
     * @return string
     */
    public function getDownloads()
    {
        return $this->downloads;
    }

    /**
     * @return string
     */
    public function getFavers()
    {
        return $this->favers;
    }

    /**
     * @return string
     */
    public function getRepository()
    {
        return $this->repository;
    }
}
<?php

namespace Packagist\Api\Result;

use InvalidArgumentException;

/**
 * Map raw data from website api to has a know type
 *
 * @since 1.0
 */
class Factory
{
    /**
     * Analyse the data and transform to a known type
     *
     * @param array $data
     * @throws InvalidArgumentException
     *
     * @return array|Package
     */
    public function create(array $data)
    {
        if (isset($data['results'])) {
            return $this->createSearchResults($data['results']);
        } elseif (isset($data['packages'])) {
            return $this->createSearchResults($data['packages']);
        } elseif (isset($data['package'])) {
            return $this->createPackageResults($data['package']);
        } elseif (isset($data['packageNames'])) {
            return $data['packageNames'];
        }

        throw new InvalidArgumentException('Invalid input data.');
    }

    /**
     * Create a collection of \Packagist\Api\Result\Result

     * @param array $results
     *
     * @return array
     */
    public function createSearchResults(array $results)
    {
        $created = array();
        foreach ($results as $key => $result) {
            $created[$key] = $this->createResult('Packagist\Api\Result\Result', $result);
        }

        return $created;
    }

    /**
     * Parse array to \Packagist\Api\Result\Result

     * @param array $package
     *
     * @return Package
     */
    public function createPackageResults(array $package)
    {
        $created = array();

        if (isset($package['maintainers']) && $package['maintainers']) {
            foreach ($package['maintainers'] as $key => $maintainer) {
                $package['maintainers'][$key] = $this->createResult('Packagist\Api\Result\Package\Maintainer', $maintainer);
            }
        }

        if (isset($package['downloads']) && $package['downloads']) {
            $package['downloads'] = $this->createResult('Packagist\Api\Result\Package\Downloads', $package['downloads']);
        }

        foreach ($package['versions'] as $branch => $version) {
            if (isset($version['authors']) && $version['authors']) {
                foreach ($version['authors'] as $key => $author) {
                    $version['authors'][$key] = $this->createResult('Packagist\Api\Result\Package\Author', $author);
                }
            }
            $version['source'] = $this->createResult('Packagist\Api\Result\Package\Source', $version['source']);
            if (isset($version['dist']) && $version['dist']) {
                $version['dist'] = $this->createResult('Packagist\Api\Result\Package\Dist', $version['dist']);
            }

            $package['versions'][$branch] = $this->createResult('Packagist\Api\Result\Package\Version', $version);
        }

        $created = new Package();
        $created->fromArray($package);

        return $created;
    }

    /**
     * Dynamically create DataObject of type $class and hydrate
     *
     * @param string $class DataObject class
     * @param array  $data Array of data
     *
     * @return mixed DataObject $class hydrated
     */
    protected function createResult($class, array $data)
    {
        $result = new $class();
        $result->fromArray($data);

        return $result;
    }
}
<?php

namespace Packagist\Api;

use Guzzle\Http\Client as HttpClient;
use Guzzle\Http\ClientInterface;
use Packagist\Api\Result\Factory;

/**
 * Packagist Api
 *
 * @since 1.0
 * @api
 */
class Client
{
    /**
     * HTTP client
     *
     * @var ClientInterface
     */
    protected $httpClient;

    /**
     * DataObject Factory
     *
     * @var Factory
     */
    protected $resultFactory;

    /**
     * Packagist url
     *
     * @var string
     */
    protected $packagistUrl;

    /**
     * Constructor.
     *
     * @since 1.1 Added the $packagistUrl argument
     * @since 1.0
     *
     * @param ClientInterface|null $httpClient    HTTP client
     * @param Factory|null         $resultFactory DataObject Factory
     * @param string|null          $packagistUrl  Packagist url
     */
    public function __construct(ClientInterface $httpClient = null, Factory $resultFactory = null, $packagistUrl = "https://packagist.org")
    {
        $this->httpClient = $httpClient;
        $this->resultFactory = $resultFactory;
        $this->packagistUrl = $packagistUrl;
    }

    /**
     * Search packages
     *
     * Available filters :
     *
     *    * vendor: vendor of package (require or require-dev in composer.json)
     *    * type:   type of package (type in composer.json)
     *    * tags:   tags of package (keywords in composer.json)
     *
     * @since 1.0
     *
     * @param string $query   Name of package
     * @param array  $filters An array of filters
     *
     * @return array The results
     */
    public function search($query, array $filters = array())
    {
        $results = $response = array();
        $filters['q'] = $query;
        $url = '/search.json?' . http_build_query($filters);
        $response['next'] = $this->url($url);

        do {
            $response = $this->request($response['next']);
            $response = $this->parse($response);
            $results = array_merge($results, $this->create($response));
        } while (isset($response['next']));

        return $results;
    }

    /**
     * Retrieve full package informations
     *
     * @since 1.0
     *
     * @param string $package Full qualified name ex : myname/mypackage
     *
     * @return \Packagist\Api\Result\Package A package instance
     */
    public function get($package)
    {
        return $this->respond(sprintf($this->url('/packages/%s.json'), $package));
    }

    /**
     * Search packages
     *
     * Available filters :
     *
     *    * vendor: vendor of package (require or require-dev in composer.json)
     *    * type:   type of package (type in composer.json)
     *    * tags:   tags of package (keywords in composer.json)
     *
     * @since 1.0
     *
     * @param array  $filters An array of filters
     *
     * @return array The results
     */
    public function all(array $filters = array())
    {
        $url = '/packages/list.json';
        if ($filters) {
            $url .= '?'.http_build_query($filters);
        }

        return $this->respond($this->url($url));
    }

    /**
     * Popular packages
     *
     * @since 1.3
     *
     * @param $total
     * @return array The results
     */
    public function popular($total)
    {
        $results = $response = array();
        $url = '/explore/popular.json?' . http_build_query(array('page' => 1));
        $response['next'] = $this->url($url);

        do {
            $response = $this->request($response['next']);
            $response = $this->parse($response);
            $results = array_merge($results, $this->create($response));
        } while (count($results) < $total && isset($response['next']));

        return array_slice($results, 0, $total);
    }

    /**
     * Assemble the packagist URL with the route
     *
     * @param string $route API Route that we want to achieve
     *
     * @return string Fully qualified URL
     */
    protected function url($route)
    {
        return $this->packagistUrl.$route;
    }

    /**
     * Execute the url request and parse the response
     *
     * @param string $url
     *
     * @return array|\Packagist\Api\Result\Package
     */
    protected function respond($url)
    {
        $response = $this->request($url);
        $response = $this->parse($response);

        return $this->create($response);
    }

    /**
     * Execute the url request
     *
     * @param string $url
     *
     * @return \Guzzle\Http\EntityBodyInterface|string
     */
    protected function request($url)
    {
        if (null === $this->httpClient) {
            $this->httpClient = new HttpClient();
        }

        return $this->httpClient
            ->get($url)
            ->send()
            ->getBody(true)
        ;
    }

    /**
     * Decode json
     *
     * @param string $data Json string
     *
     * @return array Json decode
     */
    protected function parse($data)
    {
        return json_decode($data, true);
    }

    /**
     * Hydrate the knowing type depending on passed data
     *
     * @param array $data
     *
     * @return array|Packagist\Api\Result\Package
     */
    protected function create(array $data)
    {
        if (null === $this->resultFactory) {
            $this->resultFactory = new Factory();
        }

        return $this->resultFactory->create($data);
    }

    /**
     * Change the packagist URL
     *
     * @since 1.1
     *
     * @param string $packagistUrl URL
     */
    public function setPackagistUrl($packagistUrl)
    {
        $this->packagistUrl = $packagistUrl;
    }

    /**
     * Return the actual packagist URL
     *
     * @since 1.1
     *
     * @return string URL
     */
    public function getPackagistUrl()
    {
        return $this->packagistUrl;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Helper;

use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\NullOutput;

/**
 * Provides helpers to display table output.
 *
 * @author Саша Стаменковић <umpirsky@gmail.com>
 * @author Fabien Potencier <fabien@symfony.com>
 *
 * @deprecated Deprecated since 2.5, to be removed in 3.0; use Table instead.
 */
class TableHelper extends Helper
{
    const LAYOUT_DEFAULT = 0;
    const LAYOUT_BORDERLESS = 1;
    const LAYOUT_COMPACT = 2;

    /**
     * @var Table
     */
    private $table;

    public function __construct()
    {
        $this->table = new Table(new NullOutput());
    }

    /**
     * Sets table layout type.
     *
     * @param int $layout self::LAYOUT_*
     *
     * @return TableHelper
     *
     * @throws \InvalidArgumentException when the table layout is not known
     */
    public function setLayout($layout)
    {
        switch ($layout) {
            case self::LAYOUT_BORDERLESS:
                $this->table->setStyle('borderless');
                break;

            case self::LAYOUT_COMPACT:
                $this->table->setStyle('compact');
                break;

            case self::LAYOUT_DEFAULT:
                $this->table->setStyle('default');
                break;

            default:
                throw new \InvalidArgumentException(sprintf('Invalid table layout "%s".', $layout));
        };

        return $this;
    }

    public function setHeaders(array $headers)
    {
        $this->table->setHeaders($headers);

        return $this;
    }

    public function setRows(array $rows)
    {
        $this->table->setRows($rows);

        return $this;
    }

    public function addRows(array $rows)
    {
        $this->table->addRows($rows);

        return $this;
    }

    public function addRow(array $row)
    {
        $this->table->addRow($row);

        return $this;
    }

    public function setRow($column, array $row)
    {
        $this->table->setRow($column, $row);

        return $this;
    }

    /**
     * Sets padding character, used for cell padding.
     *
     * @param string $paddingChar
     *
     * @return TableHelper
     */
    public function setPaddingChar($paddingChar)
    {
        $this->table->getStyle()->setPaddingChar($paddingChar);

        return $this;
    }

    /**
     * Sets horizontal border character.
     *
     * @param string $horizontalBorderChar
     *
     * @return TableHelper
     */
    public function setHorizontalBorderChar($horizontalBorderChar)
    {
        $this->table->getStyle()->setHorizontalBorderChar($horizontalBorderChar);

        return $this;
    }

    /**
     * Sets vertical border character.
     *
     * @param string $verticalBorderChar
     *
     * @return TableHelper
     */
    public function setVerticalBorderChar($verticalBorderChar)
    {
        $this->table->getStyle()->setVerticalBorderChar($verticalBorderChar);

        return $this;
    }

    /**
     * Sets crossing character.
     *
     * @param string $crossingChar
     *
     * @return TableHelper
     */
    public function setCrossingChar($crossingChar)
    {
        $this->table->getStyle()->setCrossingChar($crossingChar);

        return $this;
    }

    /**
     * Sets header cell format.
     *
     * @param string $cellHeaderFormat
     *
     * @return TableHelper
     */
    public function setCellHeaderFormat($cellHeaderFormat)
    {
        $this->table->getStyle()->setCellHeaderFormat($cellHeaderFormat);

        return $this;
    }

    /**
     * Sets row cell format.
     *
     * @param string $cellRowFormat
     *
     * @return TableHelper
     */
    public function setCellRowFormat($cellRowFormat)
    {
        $this->table->getStyle()->setCellHeaderFormat($cellRowFormat);

        return $this;
    }

    /**
     * Sets row cell content format.
     *
     * @param string $cellRowContentFormat
     *
     * @return TableHelper
     */
    public function setCellRowContentFormat($cellRowContentFormat)
    {
        $this->table->getStyle()->setCellRowContentFormat($cellRowContentFormat);

        return $this;
    }

    /**
     * Sets table border format.
     *
     * @param string $borderFormat
     *
     * @return TableHelper
     */
    public function setBorderFormat($borderFormat)
    {
        $this->table->getStyle()->setBorderFormat($borderFormat);

        return $this;
    }

    /**
     * Sets cell padding type.
     *
     * @param int $padType STR_PAD_*
     *
     * @return TableHelper
     */
    public function setPadType($padType)
    {
        $this->table->getStyle()->setPadType($padType);

        return $this;
    }

    /**
     * Renders table to output.
     *
     * Example:
     * +---------------+-----------------------+------------------+
     * | ISBN          | Title                 | Author           |
     * +---------------+-----------------------+------------------+
     * | 99921-58-10-7 | Divine Comedy         | Dante Alighieri  |
     * | 9971-5-0210-0 | A Tale of Two Cities  | Charles Dickens  |
     * | 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien |
     * +---------------+-----------------------+------------------+
     *
     * @param OutputInterface $output
     */
    public function render(OutputInterface $output)
    {
        $p = new \ReflectionProperty($this->table, 'output');
        $p->setAccessible(true);
        $p->setValue($this->table, $output);

        $this->table->render();
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'table';
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Helper;

/**
 * Defines the styles for a Table.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 * @author Саша Стаменковић <umpirsky@gmail.com>
 */
class TableStyle
{
    private $paddingChar = ' ';
    private $horizontalBorderChar = '-';
    private $verticalBorderChar = '|';
    private $crossingChar = '+';
    private $cellHeaderFormat = '<info>%s</info>';
    private $cellRowFormat = '%s';
    private $cellRowContentFormat = ' %s ';
    private $borderFormat = '%s';
    private $padType = STR_PAD_RIGHT;

    /**
     * Sets padding character, used for cell padding.
     *
     * @param string $paddingChar
     *
     * @return TableStyle
     */
    public function setPaddingChar($paddingChar)
    {
        if (!$paddingChar) {
            throw new \LogicException('The padding char must not be empty');
        }

        $this->paddingChar = $paddingChar;

        return $this;
    }

    /**
     * Gets padding character, used for cell padding.
     *
     * @return string
     */
    public function getPaddingChar()
    {
        return $this->paddingChar;
    }

    /**
     * Sets horizontal border character.
     *
     * @param string $horizontalBorderChar
     *
     * @return TableStyle
     */
    public function setHorizontalBorderChar($horizontalBorderChar)
    {
        $this->horizontalBorderChar = $horizontalBorderChar;

        return $this;
    }

    /**
     * Gets horizontal border character.
     *
     * @return string
     */
    public function getHorizontalBorderChar()
    {
        return $this->horizontalBorderChar;
    }

    /**
     * Sets vertical border character.
     *
     * @param string $verticalBorderChar
     *
     * @return TableStyle
     */
    public function setVerticalBorderChar($verticalBorderChar)
    {
        $this->verticalBorderChar = $verticalBorderChar;

        return $this;
    }

    /**
     * Gets vertical border character.
     *
     * @return string
     */
    public function getVerticalBorderChar()
    {
        return $this->verticalBorderChar;
    }

    /**
     * Sets crossing character.
     *
     * @param string $crossingChar
     *
     * @return TableStyle
     */
    public function setCrossingChar($crossingChar)
    {
        $this->crossingChar = $crossingChar;

        return $this;
    }

    /**
     * Gets crossing character.
     *
     * @return string $crossingChar
     */
    public function getCrossingChar()
    {
        return $this->crossingChar;
    }

    /**
     * Sets header cell format.
     *
     * @param string $cellHeaderFormat
     *
     * @return TableStyle
     */
    public function setCellHeaderFormat($cellHeaderFormat)
    {
        $this->cellHeaderFormat = $cellHeaderFormat;

        return $this;
    }

    /**
     * Gets header cell format.
     *
     * @return string
     */
    public function getCellHeaderFormat()
    {
        return $this->cellHeaderFormat;
    }

    /**
     * Sets row cell format.
     *
     * @param string $cellRowFormat
     *
     * @return TableStyle
     */
    public function setCellRowFormat($cellRowFormat)
    {
        $this->cellRowFormat = $cellRowFormat;

        return $this;
    }

    /**
     * Gets row cell format.
     *
     * @return string
     */
    public function getCellRowFormat()
    {
        return $this->cellRowFormat;
    }

    /**
     * Sets row cell content format.
     *
     * @param string $cellRowContentFormat
     *
     * @return TableStyle
     */
    public function setCellRowContentFormat($cellRowContentFormat)
    {
        $this->cellRowContentFormat = $cellRowContentFormat;

        return $this;
    }

    /**
     * Gets row cell content format.
     *
     * @return string
     */
    public function getCellRowContentFormat()
    {
        return $this->cellRowContentFormat;
    }

    /**
     * Sets table border format.
     *
     * @param string $borderFormat
     *
     * @return TableStyle
     */
    public function setBorderFormat($borderFormat)
    {
        $this->borderFormat = $borderFormat;

        return $this;
    }

    /**
     * Gets table border format.
     *
     * @return string
     */
    public function getBorderFormat()
    {
        return $this->borderFormat;
    }

    /**
     * Sets cell padding type.
     *
     * @param int $padType STR_PAD_*
     *
     * @return TableStyle
     */
    public function setPadType($padType)
    {
        $this->padType = $padType;

        return $this;
    }

    /**
     * Gets cell padding type.
     *
     * @return int
     */
    public function getPadType()
    {
        return $this->padType;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Helper;

use Symfony\Component\Console\Formatter\OutputFormatterInterface;

/**
 * Helper is the base class for all helper classes.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
abstract class Helper implements HelperInterface
{
    protected $helperSet = null;

    /**
     * Sets the helper set associated with this helper.
     *
     * @param HelperSet $helperSet A HelperSet instance
     */
    public function setHelperSet(HelperSet $helperSet = null)
    {
        $this->helperSet = $helperSet;
    }

    /**
     * Gets the helper set associated with this helper.
     *
     * @return HelperSet A HelperSet instance
     */
    public function getHelperSet()
    {
        return $this->helperSet;
    }

    /**
     * Returns the length of a string, using mb_strwidth if it is available.
     *
     * @param string $string The string to check its length
     *
     * @return int The length of the string
     */
    public static function strlen($string)
    {
        if (!function_exists('mb_strwidth')) {
            return strlen($string);
        }

        if (false === $encoding = mb_detect_encoding($string)) {
            return strlen($string);
        }

        return mb_strwidth($string, $encoding);
    }

    public static function formatTime($secs)
    {
        static $timeFormats = array(
            array(0, '< 1 sec'),
            array(2, '1 sec'),
            array(59, 'secs', 1),
            array(60, '1 min'),
            array(3600, 'mins', 60),
            array(5400, '1 hr'),
            array(86400, 'hrs', 3600),
            array(129600, '1 day'),
            array(604800, 'days', 86400),
        );

        foreach ($timeFormats as $format) {
            if ($secs >= $format[0]) {
                continue;
            }

            if (2 == count($format)) {
                return $format[1];
            }

            return ceil($secs / $format[2]).' '.$format[1];
        }
    }

    public static function formatMemory($memory)
    {
        if ($memory >= 1024 * 1024 * 1024) {
            return sprintf('%.1f GiB', $memory / 1024 / 1024 / 1024);
        }

        if ($memory >= 1024 * 1024) {
            return sprintf('%.1f MiB', $memory / 1024 / 1024);
        }

        if ($memory >= 1024) {
            return sprintf('%d KiB', $memory / 1024);
        }

        return sprintf('%d B', $memory);
    }

    public static function strlenWithoutDecoration(OutputFormatterInterface $formatter, $string)
    {
        $isDecorated = $formatter->isDecorated();
        $formatter->setDecorated(false);
        // remove <...> formatting
        $string = $formatter->format($string);
        // remove already formatted characters
        $string = preg_replace("/\033\[[^m]*m/", '', $string);
        $formatter->setDecorated($isDecorated);

        return self::strlen($string);
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Helper;

use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\ProcessBuilder;

/**
 * The ProcessHelper class provides helpers to run external processes.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class ProcessHelper extends Helper
{
    /**
     * Runs an external process.
     *
     * @param OutputInterface      $output    An OutputInterface instance
     * @param string|array|Process $cmd       An instance of Process or an array of arguments to escape and run or a command to run
     * @param string|null          $error     An error message that must be displayed if something went wrong
     * @param callable|null        $callback  A PHP callback to run whenever there is some
     *                                        output available on STDOUT or STDERR
     * @param int                  $verbosity The threshold for verbosity
     *
     * @return Process The process that ran
     */
    public function run(OutputInterface $output, $cmd, $error = null, $callback = null, $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE)
    {
        $formatter = $this->getHelperSet()->get('debug_formatter');

        if (is_array($cmd)) {
            $process = ProcessBuilder::create($cmd)->getProcess();
        } elseif ($cmd instanceof Process) {
            $process = $cmd;
        } else {
            $process = new Process($cmd);
        }

        if ($verbosity <= $output->getVerbosity()) {
            $output->write($formatter->start(spl_object_hash($process), $this->escapeString($process->getCommandLine())));
        }

        if ($output->isDebug()) {
            $callback = $this->wrapCallback($output, $process, $callback);
        }

        $process->run($callback);

        if ($verbosity <= $output->getVerbosity()) {
            $message = $process->isSuccessful() ? 'Command ran successfully' : sprintf('%s Command did not run successfully', $process->getExitCode());
            $output->write($formatter->stop(spl_object_hash($process), $message, $process->isSuccessful()));
        }

        if (!$process->isSuccessful() && null !== $error) {
            $output->writeln(sprintf('<error>%s</error>', $this->escapeString($error)));
        }

        return $process;
    }

    /**
     * Runs the process.
     *
     * This is identical to run() except that an exception is thrown if the process
     * exits with a non-zero exit code.
     *
     * @param OutputInterface $output   An OutputInterface instance
     * @param string|Process  $cmd      An instance of Process or a command to run
     * @param string|null     $error    An error message that must be displayed if something went wrong
     * @param callable|null   $callback A PHP callback to run whenever there is some
     *                                  output available on STDOUT or STDERR
     *
     * @return Process The process that ran
     *
     * @throws ProcessFailedException
     *
     * @see run()
     */
    public function mustRun(OutputInterface $output, $cmd, $error = null, $callback = null)
    {
        $process = $this->run($output, $cmd, $error, $callback);

        if (!$process->isSuccessful()) {
            throw new ProcessFailedException($process);
        }

        return $process;
    }

    /**
     * Wraps a Process callback to add debugging output.
     *
     * @param OutputInterface $output   An OutputInterface interface
     * @param Process         $process  The Process
     * @param callable|null   $callback A PHP callable
     *
     * @return callable
     */
    public function wrapCallback(OutputInterface $output, Process $process, $callback = null)
    {
        $formatter = $this->getHelperSet()->get('debug_formatter');

        $that = $this;

        return function ($type, $buffer) use ($output, $process, $callback, $formatter, $that) {
            $output->write($formatter->progress(spl_object_hash($process), $that->escapeString($buffer), Process::ERR === $type));

            if (null !== $callback) {
                call_user_func($callback, $type, $buffer);
            }
        };
    }

    /**
     * This method is public for PHP 5.3 compatibility, it should be private.
     *
     * @internal
     */
    public function escapeString($str)
    {
        return str_replace('<', '\\<', $str);
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'process';
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Helper;

use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * The Progress class provides helpers to display progress output.
 *
 * @author Chris Jones <leeked@gmail.com>
 * @author Fabien Potencier <fabien@symfony.com>
 *
 * @deprecated Deprecated since 2.5, to be removed in 3.0; use ProgressBar instead.
 */
class ProgressHelper extends Helper
{
    const FORMAT_QUIET = ' %percent%%';
    const FORMAT_NORMAL = ' %current%/%max% [%bar%] %percent%%';
    const FORMAT_VERBOSE = ' %current%/%max% [%bar%] %percent%% Elapsed: %elapsed%';
    const FORMAT_QUIET_NOMAX = ' %current%';
    const FORMAT_NORMAL_NOMAX = ' %current% [%bar%]';
    const FORMAT_VERBOSE_NOMAX = ' %current% [%bar%] Elapsed: %elapsed%';

    // options
    private $barWidth = 28;
    private $barChar = '=';
    private $emptyBarChar = '-';
    private $progressChar = '>';
    private $format = null;
    private $redrawFreq = 1;

    private $lastMessagesLength;
    private $barCharOriginal;

    /**
     * @var OutputInterface
     */
    private $output;

    /**
     * Current step.
     *
     * @var int
     */
    private $current;

    /**
     * Maximum number of steps.
     *
     * @var int
     */
    private $max;

    /**
     * Start time of the progress bar.
     *
     * @var int
     */
    private $startTime;

    /**
     * List of formatting variables.
     *
     * @var array
     */
    private $defaultFormatVars = array(
        'current',
        'max',
        'bar',
        'percent',
        'elapsed',
    );

    /**
     * Available formatting variables.
     *
     * @var array
     */
    private $formatVars;

    /**
     * Stored format part widths (used for padding).
     *
     * @var array
     */
    private $widths = array(
        'current' => 4,
        'max' => 4,
        'percent' => 3,
        'elapsed' => 6,
    );

    /**
     * Various time formats.
     *
     * @var array
     */
    private $timeFormats = array(
        array(0, '???'),
        array(2, '1 sec'),
        array(59, 'secs', 1),
        array(60, '1 min'),
        array(3600, 'mins', 60),
        array(5400, '1 hr'),
        array(86400, 'hrs', 3600),
        array(129600, '1 day'),
        array(604800, 'days', 86400),
    );

    /**
     * Sets the progress bar width.
     *
     * @param int $size The progress bar size
     */
    public function setBarWidth($size)
    {
        $this->barWidth = (int) $size;
    }

    /**
     * Sets the bar character.
     *
     * @param string $char A character
     */
    public function setBarCharacter($char)
    {
        $this->barChar = $char;
    }

    /**
     * Sets the empty bar character.
     *
     * @param string $char A character
     */
    public function setEmptyBarCharacter($char)
    {
        $this->emptyBarChar = $char;
    }

    /**
     * Sets the progress bar character.
     *
     * @param string $char A character
     */
    public function setProgressCharacter($char)
    {
        $this->progressChar = $char;
    }

    /**
     * Sets the progress bar format.
     *
     * @param string $format The format
     */
    public function setFormat($format)
    {
        $this->format = $format;
    }

    /**
     * Sets the redraw frequency.
     *
     * @param int $freq The frequency in steps
     */
    public function setRedrawFrequency($freq)
    {
        $this->redrawFreq = (int) $freq;
    }

    /**
     * Starts the progress output.
     *
     * @param OutputInterface $output An Output instance
     * @param int|null        $max    Maximum steps
     */
    public function start(OutputInterface $output, $max = null)
    {
        $this->startTime = time();
        $this->current = 0;
        $this->max = (int) $max;

        // Disabling output when it does not support ANSI codes as it would result in a broken display anyway.
        $this->output = $output->isDecorated() ? $output : new NullOutput();
        $this->lastMessagesLength = 0;
        $this->barCharOriginal = '';

        if (null === $this->format) {
            switch ($output->getVerbosity()) {
                case OutputInterface::VERBOSITY_QUIET:
                    $this->format = self::FORMAT_QUIET_NOMAX;
                    if ($this->max > 0) {
                        $this->format = self::FORMAT_QUIET;
                    }
                    break;
                case OutputInterface::VERBOSITY_VERBOSE:
                case OutputInterface::VERBOSITY_VERY_VERBOSE:
                case OutputInterface::VERBOSITY_DEBUG:
                    $this->format = self::FORMAT_VERBOSE_NOMAX;
                    if ($this->max > 0) {
                        $this->format = self::FORMAT_VERBOSE;
                    }
                    break;
                default:
                    $this->format = self::FORMAT_NORMAL_NOMAX;
                    if ($this->max > 0) {
                        $this->format = self::FORMAT_NORMAL;
                    }
                    break;
            }
        }

        $this->initialize();
    }

    /**
     * Advances the progress output X steps.
     *
     * @param int  $step   Number of steps to advance
     * @param bool $redraw Whether to redraw or not
     *
     * @throws \LogicException
     */
    public function advance($step = 1, $redraw = false)
    {
        $this->setCurrent($this->current + $step, $redraw);
    }

    /**
     * Sets the current progress.
     *
     * @param int  $current The current progress
     * @param bool $redraw  Whether to redraw or not
     *
     * @throws \LogicException
     */
    public function setCurrent($current, $redraw = false)
    {
        if (null === $this->startTime) {
            throw new \LogicException('You must start the progress bar before calling setCurrent().');
        }

        $current = (int) $current;

        if ($current < $this->current) {
            throw new \LogicException('You can\'t regress the progress bar');
        }

        if (0 === $this->current) {
            $redraw = true;
        }

        $prevPeriod = (int) ($this->current / $this->redrawFreq);

        $this->current = $current;

        $currPeriod = (int) ($this->current / $this->redrawFreq);
        if ($redraw || $prevPeriod !== $currPeriod || $this->max === $this->current) {
            $this->display();
        }
    }

    /**
     * Outputs the current progress string.
     *
     * @param bool $finish Forces the end result
     *
     * @throws \LogicException
     */
    public function display($finish = false)
    {
        if (null === $this->startTime) {
            throw new \LogicException('You must start the progress bar before calling display().');
        }

        $message = $this->format;
        foreach ($this->generate($finish) as $name => $value) {
            $message = str_replace("%{$name}%", $value, $message);
        }
        $this->overwrite($this->output, $message);
    }

    /**
     * Removes the progress bar from the current line.
     *
     * This is useful if you wish to write some output
     * while a progress bar is running.
     * Call display() to show the progress bar again.
     */
    public function clear()
    {
        $this->overwrite($this->output, '');
    }

    /**
     * Finishes the progress output.
     */
    public function finish()
    {
        if (null === $this->startTime) {
            throw new \LogicException('You must start the progress bar before calling finish().');
        }

        if (null !== $this->startTime) {
            if (!$this->max) {
                $this->barChar = $this->barCharOriginal;
                $this->display(true);
            }
            $this->startTime = null;
            $this->output->writeln('');
            $this->output = null;
        }
    }

    /**
     * Initializes the progress helper.
     */
    private function initialize()
    {
        $this->formatVars = array();
        foreach ($this->defaultFormatVars as $var) {
            if (false !== strpos($this->format, "%{$var}%")) {
                $this->formatVars[$var] = true;
            }
        }

        if ($this->max > 0) {
            $this->widths['max'] = $this->strlen($this->max);
            $this->widths['current'] = $this->widths['max'];
        } else {
            $this->barCharOriginal = $this->barChar;
            $this->barChar = $this->emptyBarChar;
        }
    }

    /**
     * Generates the array map of format variables to values.
     *
     * @param bool $finish Forces the end result
     *
     * @return array Array of format vars and values
     */
    private function generate($finish = false)
    {
        $vars = array();
        $percent = 0;
        if ($this->max > 0) {
            $percent = (float) $this->current / $this->max;
        }

        if (isset($this->formatVars['bar'])) {
            $completeBars = 0;

            if ($this->max > 0) {
                $completeBars = floor($percent * $this->barWidth);
            } else {
                if (!$finish) {
                    $completeBars = floor($this->current % $this->barWidth);
                } else {
                    $completeBars = $this->barWidth;
                }
            }

            $emptyBars = $this->barWidth - $completeBars - $this->strlen($this->progressChar);
            $bar = str_repeat($this->barChar, $completeBars);
            if ($completeBars < $this->barWidth) {
                $bar .= $this->progressChar;
                $bar .= str_repeat($this->emptyBarChar, $emptyBars);
            }

            $vars['bar'] = $bar;
        }

        if (isset($this->formatVars['elapsed'])) {
            $elapsed = time() - $this->startTime;
            $vars['elapsed'] = str_pad($this->humaneTime($elapsed), $this->widths['elapsed'], ' ', STR_PAD_LEFT);
        }

        if (isset($this->formatVars['current'])) {
            $vars['current'] = str_pad($this->current, $this->widths['current'], ' ', STR_PAD_LEFT);
        }

        if (isset($this->formatVars['max'])) {
            $vars['max'] = $this->max;
        }

        if (isset($this->formatVars['percent'])) {
            $vars['percent'] = str_pad(floor($percent * 100), $this->widths['percent'], ' ', STR_PAD_LEFT);
        }

        return $vars;
    }

    /**
     * Converts seconds into human-readable format.
     *
     * @param int $secs Number of seconds
     *
     * @return string Time in readable format
     */
    private function humaneTime($secs)
    {
        $text = '';
        foreach ($this->timeFormats as $format) {
            if ($secs < $format[0]) {
                if (count($format) == 2) {
                    $text = $format[1];
                    break;
                } else {
                    $text = ceil($secs / $format[2]).' '.$format[1];
                    break;
                }
            }
        }

        return $text;
    }

    /**
     * Overwrites a previous message to the output.
     *
     * @param OutputInterface $output  An Output instance
     * @param string          $message The message
     */
    private function overwrite(OutputInterface $output, $message)
    {
        $length = $this->strlen($message);

        // append whitespace to match the last line's length
        if (null !== $this->lastMessagesLength && $this->lastMessagesLength > $length) {
            $message = str_pad($message, $this->lastMessagesLength, "\x20", STR_PAD_RIGHT);
        }

        // carriage return
        $output->write("\x0D");
        $output->write($message);

        $this->lastMessagesLength = $this->strlen($message);
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'progress';
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Helper;

use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;

/**
 * The Dialog class provides helpers to interact with the user.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 *
 * @deprecated Deprecated since version 2.5, to be removed in 3.0.
 *             Use the question helper instead.
 */
class DialogHelper extends InputAwareHelper
{
    private $inputStream;
    private static $shell;
    private static $stty;

    /**
     * Asks the user to select a value.
     *
     * @param OutputInterface $output       An Output instance
     * @param string|array    $question     The question to ask
     * @param array           $choices      List of choices to pick from
     * @param bool|string     $default      The default answer if the user enters nothing
     * @param bool|int        $attempts     Max number of times to ask before giving up (false by default, which means infinite)
     * @param string          $errorMessage Message which will be shown if invalid value from choice list would be picked
     * @param bool            $multiselect  Select more than one value separated by comma
     *
     * @return int|string|array The selected value or values (the key of the choices array)
     *
     * @throws \InvalidArgumentException
     */
    public function select(OutputInterface $output, $question, $choices, $default = null, $attempts = false, $errorMessage = 'Value "%s" is invalid', $multiselect = false)
    {
        $width = max(array_map('strlen', array_keys($choices)));

        $messages = (array) $question;
        foreach ($choices as $key => $value) {
            $messages[] = sprintf("  [<info>%-${width}s</info>] %s", $key, $value);
        }

        $output->writeln($messages);

        $result = $this->askAndValidate($output, '> ', function ($picked) use ($choices, $errorMessage, $multiselect) {
            // Collapse all spaces.
            $selectedChoices = str_replace(' ', '', $picked);

            if ($multiselect) {
                // Check for a separated comma values
                if (!preg_match('/^[a-zA-Z0-9_-]+(?:,[a-zA-Z0-9_-]+)*$/', $selectedChoices, $matches)) {
                    throw new \InvalidArgumentException(sprintf($errorMessage, $picked));
                }
                $selectedChoices = explode(',', $selectedChoices);
            } else {
                $selectedChoices = array($picked);
            }

            $multiselectChoices = array();

            foreach ($selectedChoices as $value) {
                if (empty($choices[$value])) {
                    throw new \InvalidArgumentException(sprintf($errorMessage, $value));
                }
                $multiselectChoices[] = $value;
            }

            if ($multiselect) {
                return $multiselectChoices;
            }

            return $picked;
        }, $attempts, $default);

        return $result;
    }

    /**
     * Asks a question to the user.
     *
     * @param OutputInterface $output       An Output instance
     * @param string|array    $question     The question to ask
     * @param string          $default      The default answer if none is given by the user
     * @param array           $autocomplete List of values to autocomplete
     *
     * @return string The user answer
     *
     * @throws \RuntimeException If there is no data to read in the input stream
     */
    public function ask(OutputInterface $output, $question, $default = null, array $autocomplete = null)
    {
        if ($this->input && !$this->input->isInteractive()) {
            return $default;
        }

        $output->write($question);

        $inputStream = $this->inputStream ?: STDIN;

        if (null === $autocomplete || !$this->hasSttyAvailable()) {
            $ret = fgets($inputStream, 4096);
            if (false === $ret) {
                throw new \RuntimeException('Aborted');
            }
            $ret = trim($ret);
        } else {
            $ret = '';

            $i = 0;
            $ofs = -1;
            $matches = $autocomplete;
            $numMatches = count($matches);

            $sttyMode = shell_exec('stty -g');

            // Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)
            shell_exec('stty -icanon -echo');

            // Add highlighted text style
            $output->getFormatter()->setStyle('hl', new OutputFormatterStyle('black', 'white'));

            // Read a keypress
            while (!feof($inputStream)) {
                $c = fread($inputStream, 1);

                // Backspace Character
                if ("\177" === $c) {
                    if (0 === $numMatches && 0 !== $i) {
                        --$i;
                        // Move cursor backwards
                        $output->write("\033[1D");
                    }

                    if ($i === 0) {
                        $ofs = -1;
                        $matches = $autocomplete;
                        $numMatches = count($matches);
                    } else {
                        $numMatches = 0;
                    }

                    // Pop the last character off the end of our string
                    $ret = substr($ret, 0, $i);
                } elseif ("\033" === $c) {
                    // Did we read an escape sequence?
                    $c .= fread($inputStream, 2);

                    // A = Up Arrow. B = Down Arrow
                    if (isset($c[2]) && ('A' === $c[2] || 'B' === $c[2])) {
                        if ('A' === $c[2] && -1 === $ofs) {
                            $ofs = 0;
                        }

                        if (0 === $numMatches) {
                            continue;
                        }

                        $ofs += ('A' === $c[2]) ? -1 : 1;
                        $ofs = ($numMatches + $ofs) % $numMatches;
                    }
                } elseif (ord($c) < 32) {
                    if ("\t" === $c || "\n" === $c) {
                        if ($numMatches > 0 && -1 !== $ofs) {
                            $ret = $matches[$ofs];
                            // Echo out remaining chars for current match
                            $output->write(substr($ret, $i));
                            $i = strlen($ret);
                        }

                        if ("\n" === $c) {
                            $output->write($c);
                            break;
                        }

                        $numMatches = 0;
                    }

                    continue;
                } else {
                    $output->write($c);
                    $ret .= $c;
                    ++$i;

                    $numMatches = 0;
                    $ofs = 0;

                    foreach ($autocomplete as $value) {
                        // If typed characters match the beginning chunk of value (e.g. [AcmeDe]moBundle)
                        if (0 === strpos($value, $ret) && $i !== strlen($value)) {
                            $matches[$numMatches++] = $value;
                        }
                    }
                }

                // Erase characters from cursor to end of line
                $output->write("\033[K");

                if ($numMatches > 0 && -1 !== $ofs) {
                    // Save cursor position
                    $output->write("\0337");
                    // Write highlighted text
                    $output->write('<hl>'.substr($matches[$ofs], $i).'</hl>');
                    // Restore cursor position
                    $output->write("\0338");
                }
            }

            // Reset stty so it behaves normally again
            shell_exec(sprintf('stty %s', $sttyMode));
        }

        return strlen($ret) > 0 ? $ret : $default;
    }

    /**
     * Asks a confirmation to the user.
     *
     * The question will be asked until the user answers by nothing, yes, or no.
     *
     * @param OutputInterface $output   An Output instance
     * @param string|array    $question The question to ask
     * @param bool            $default  The default answer if the user enters nothing
     *
     * @return bool true if the user has confirmed, false otherwise
     */
    public function askConfirmation(OutputInterface $output, $question, $default = true)
    {
        $answer = 'z';
        while ($answer && !in_array(strtolower($answer[0]), array('y', 'n'))) {
            $answer = $this->ask($output, $question);
        }

        if (false === $default) {
            return $answer && 'y' == strtolower($answer[0]);
        }

        return !$answer || 'y' == strtolower($answer[0]);
    }

    /**
     * Asks a question to the user, the response is hidden.
     *
     * @param OutputInterface $output   An Output instance
     * @param string|array    $question The question
     * @param bool            $fallback In case the response can not be hidden, whether to fallback on non-hidden question or not
     *
     * @return string The answer
     *
     * @throws \RuntimeException In case the fallback is deactivated and the response can not be hidden
     */
    public function askHiddenResponse(OutputInterface $output, $question, $fallback = true)
    {
        if ('\\' === DIRECTORY_SEPARATOR) {
            $exe = __DIR__.'/../Resources/bin/hiddeninput.exe';

            // handle code running from a phar
            if ('phar:' === substr(__FILE__, 0, 5)) {
                $tmpExe = sys_get_temp_dir().'/hiddeninput.exe';
                copy($exe, $tmpExe);
                $exe = $tmpExe;
            }

            $output->write($question);
            $value = rtrim(shell_exec($exe));
            $output->writeln('');

            if (isset($tmpExe)) {
                unlink($tmpExe);
            }

            return $value;
        }

        if ($this->hasSttyAvailable()) {
            $output->write($question);

            $sttyMode = shell_exec('stty -g');

            shell_exec('stty -echo');
            $value = fgets($this->inputStream ?: STDIN, 4096);
            shell_exec(sprintf('stty %s', $sttyMode));

            if (false === $value) {
                throw new \RuntimeException('Aborted');
            }

            $value = trim($value);
            $output->writeln('');

            return $value;
        }

        if (false !== $shell = $this->getShell()) {
            $output->write($question);
            $readCmd = $shell === 'csh' ? 'set mypassword = $<' : 'read -r mypassword';
            $command = sprintf("/usr/bin/env %s -c 'stty -echo; %s; stty echo; echo \$mypassword'", $shell, $readCmd);
            $value = rtrim(shell_exec($command));
            $output->writeln('');

            return $value;
        }

        if ($fallback) {
            return $this->ask($output, $question);
        }

        throw new \RuntimeException('Unable to hide the response');
    }

    /**
     * Asks for a value and validates the response.
     *
     * The validator receives the data to validate. It must return the
     * validated data when the data is valid and throw an exception
     * otherwise.
     *
     * @param OutputInterface $output       An Output instance
     * @param string|array    $question     The question to ask
     * @param callable        $validator    A PHP callback
     * @param int|false       $attempts     Max number of times to ask before giving up (false by default, which means infinite)
     * @param string          $default      The default answer if none is given by the user
     * @param array           $autocomplete List of values to autocomplete
     *
     * @return mixed
     *
     * @throws \Exception When any of the validators return an error
     */
    public function askAndValidate(OutputInterface $output, $question, $validator, $attempts = false, $default = null, array $autocomplete = null)
    {
        $that = $this;

        $interviewer = function () use ($output, $question, $default, $autocomplete, $that) {
            return $that->ask($output, $question, $default, $autocomplete);
        };

        return $this->validateAttempts($interviewer, $output, $validator, $attempts);
    }

    /**
     * Asks for a value, hide and validates the response.
     *
     * The validator receives the data to validate. It must return the
     * validated data when the data is valid and throw an exception
     * otherwise.
     *
     * @param OutputInterface $output    An Output instance
     * @param string|array    $question  The question to ask
     * @param callable        $validator A PHP callback
     * @param int|false       $attempts  Max number of times to ask before giving up (false by default, which means infinite)
     * @param bool            $fallback  In case the response can not be hidden, whether to fallback on non-hidden question or not
     *
     * @return string The response
     *
     * @throws \Exception        When any of the validators return an error
     * @throws \RuntimeException In case the fallback is deactivated and the response can not be hidden
     */
    public function askHiddenResponseAndValidate(OutputInterface $output, $question, $validator, $attempts = false, $fallback = true)
    {
        $that = $this;

        $interviewer = function () use ($output, $question, $fallback, $that) {
            return $that->askHiddenResponse($output, $question, $fallback);
        };

        return $this->validateAttempts($interviewer, $output, $validator, $attempts);
    }

    /**
     * Sets the input stream to read from when interacting with the user.
     *
     * This is mainly useful for testing purpose.
     *
     * @param resource $stream The input stream
     */
    public function setInputStream($stream)
    {
        $this->inputStream = $stream;
    }

    /**
     * Returns the helper's input stream.
     *
     * @return string
     */
    public function getInputStream()
    {
        return $this->inputStream;
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'dialog';
    }

    /**
     * Return a valid Unix shell.
     *
     * @return string|bool The valid shell name, false in case no valid shell is found
     */
    private function getShell()
    {
        if (null !== self::$shell) {
            return self::$shell;
        }

        self::$shell = false;

        if (file_exists('/usr/bin/env')) {
            // handle other OSs with bash/zsh/ksh/csh if available to hide the answer
            $test = "/usr/bin/env %s -c 'echo OK' 2> /dev/null";
            foreach (array('bash', 'zsh', 'ksh', 'csh') as $sh) {
                if ('OK' === rtrim(shell_exec(sprintf($test, $sh)))) {
                    self::$shell = $sh;
                    break;
                }
            }
        }

        return self::$shell;
    }

    private function hasSttyAvailable()
    {
        if (null !== self::$stty) {
            return self::$stty;
        }

        exec('stty 2>&1', $output, $exitcode);

        return self::$stty = $exitcode === 0;
    }

    /**
     * Validate an attempt.
     *
     * @param callable        $interviewer A callable that will ask for a question and return the result
     * @param OutputInterface $output      An Output instance
     * @param callable        $validator   A PHP callback
     * @param int|false       $attempts    Max number of times to ask before giving up ; false will ask infinitely
     *
     * @return string The validated response
     *
     * @throws \Exception In case the max number of attempts has been reached and no valid response has been given
     */
    private function validateAttempts($interviewer, OutputInterface $output, $validator, $attempts)
    {
        $e = null;
        while (false === $attempts || $attempts--) {
            if (null !== $e) {
                $output->writeln($this->getHelperSet()->get('formatter')->formatBlock($e->getMessage(), 'error'));
            }

            try {
                return call_user_func($validator, $interviewer());
            } catch (\Exception $e) {
            }
        }

        throw $e;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Helper;

use Symfony\Component\Console\Output\OutputInterface;

/**
 * Provides helpers to display a table.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 * @author Саша Стаменковић <umpirsky@gmail.com>
 */
class Table
{
    /**
     * Table headers.
     *
     * @var array
     */
    private $headers = array();

    /**
     * Table rows.
     *
     * @var array
     */
    private $rows = array();

    /**
     * Column widths cache.
     *
     * @var array
     */
    private $columnWidths = array();

    /**
     * Number of columns cache.
     *
     * @var array
     */
    private $numberOfColumns;

    /**
     * @var OutputInterface
     */
    private $output;

    /**
     * @var TableStyle
     */
    private $style;

    private static $styles;

    public function __construct(OutputInterface $output)
    {
        $this->output = $output;

        if (!self::$styles) {
            self::$styles = self::initStyles();
        }

        $this->setStyle('default');
    }

    /**
     * Sets a style definition.
     *
     * @param string     $name  The style name
     * @param TableStyle $style A TableStyle instance
     */
    public static function setStyleDefinition($name, TableStyle $style)
    {
        if (!self::$styles) {
            self::$styles = self::initStyles();
        }

        self::$styles[$name] = $style;
    }

    /**
     * Gets a style definition by name.
     *
     * @param string $name The style name
     *
     * @return TableStyle A TableStyle instance
     */
    public static function getStyleDefinition($name)
    {
        if (!self::$styles) {
            self::$styles = self::initStyles();
        }

        if (!self::$styles[$name]) {
            throw new \InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
        }

        return self::$styles[$name];
    }

    /**
     * Sets table style.
     *
     * @param TableStyle|string $name The style name or a TableStyle instance
     *
     * @return Table
     */
    public function setStyle($name)
    {
        if ($name instanceof TableStyle) {
            $this->style = $name;
        } elseif (isset(self::$styles[$name])) {
            $this->style = self::$styles[$name];
        } else {
            throw new \InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
        }

        return $this;
    }

    /**
     * Gets the current table style.
     *
     * @return TableStyle
     */
    public function getStyle()
    {
        return $this->style;
    }

    public function setHeaders(array $headers)
    {
        $this->headers = array_values($headers);

        return $this;
    }

    public function setRows(array $rows)
    {
        $this->rows = array();

        return $this->addRows($rows);
    }

    public function addRows(array $rows)
    {
        foreach ($rows as $row) {
            $this->addRow($row);
        }

        return $this;
    }

    public function addRow($row)
    {
        if ($row instanceof TableSeparator) {
            $this->rows[] = $row;

            return $this;
        }

        if (!is_array($row)) {
            throw new \InvalidArgumentException('A row must be an array or a TableSeparator instance.');
        }

        $this->rows[] = array_values($row);

        end($this->rows);
        $rowKey = key($this->rows);
        reset($this->rows);

        foreach ($row as $key => $cellValue) {
            if (false === strpos($cellValue, "\n")) {
                continue;
            }

            $lines = explode("\n", $cellValue);
            $this->rows[$rowKey][$key] = $lines[0];
            unset($lines[0]);

            foreach ($lines as $lineKey => $line) {
                $nextRowKey = $rowKey + $lineKey + 1;

                if (isset($this->rows[$nextRowKey])) {
                    $this->rows[$nextRowKey][$key] = $line;
                } else {
                    $this->rows[$nextRowKey] = array($key => $line);
                }
            }
        }

        return $this;
    }

    public function setRow($column, array $row)
    {
        $this->rows[$column] = $row;

        return $this;
    }

    /**
     * Renders table to output.
     *
     * Example:
     * +---------------+-----------------------+------------------+
     * | ISBN          | Title                 | Author           |
     * +---------------+-----------------------+------------------+
     * | 99921-58-10-7 | Divine Comedy         | Dante Alighieri  |
     * | 9971-5-0210-0 | A Tale of Two Cities  | Charles Dickens  |
     * | 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien |
     * +---------------+-----------------------+------------------+
     */
    public function render()
    {
        $this->renderRowSeparator();
        $this->renderRow($this->headers, $this->style->getCellHeaderFormat());
        if (!empty($this->headers)) {
            $this->renderRowSeparator();
        }
        foreach ($this->rows as $row) {
            if ($row instanceof TableSeparator) {
                $this->renderRowSeparator();
            } else {
                $this->renderRow($row, $this->style->getCellRowFormat());
            }
        }
        if (!empty($this->rows)) {
            $this->renderRowSeparator();
        }

        $this->cleanup();
    }

    /**
     * Renders horizontal header separator.
     *
     * Example: +-----+-----------+-------+
     */
    private function renderRowSeparator()
    {
        if (0 === $count = $this->getNumberOfColumns()) {
            return;
        }

        if (!$this->style->getHorizontalBorderChar() && !$this->style->getCrossingChar()) {
            return;
        }

        $markup = $this->style->getCrossingChar();
        for ($column = 0; $column < $count; $column++) {
            $markup .= str_repeat($this->style->getHorizontalBorderChar(), $this->getColumnWidth($column)).$this->style->getCrossingChar();
        }

        $this->output->writeln(sprintf($this->style->getBorderFormat(), $markup));
    }

    /**
     * Renders vertical column separator.
     */
    private function renderColumnSeparator()
    {
        $this->output->write(sprintf($this->style->getBorderFormat(), $this->style->getVerticalBorderChar()));
    }

    /**
     * Renders table row.
     *
     * Example: | 9971-5-0210-0 | A Tale of Two Cities  | Charles Dickens  |
     *
     * @param array  $row
     * @param string $cellFormat
     */
    private function renderRow(array $row, $cellFormat)
    {
        if (empty($row)) {
            return;
        }

        $this->renderColumnSeparator();
        for ($column = 0, $count = $this->getNumberOfColumns(); $column < $count; $column++) {
            $this->renderCell($row, $column, $cellFormat);
            $this->renderColumnSeparator();
        }
        $this->output->writeln('');
    }

    /**
     * Renders table cell with padding.
     *
     * @param array  $row
     * @param int    $column
     * @param string $cellFormat
     */
    private function renderCell(array $row, $column, $cellFormat)
    {
        $cell = isset($row[$column]) ? $row[$column] : '';
        $width = $this->getColumnWidth($column);

        // str_pad won't work properly with multi-byte strings, we need to fix the padding
        if (function_exists('mb_strwidth') && false !== $encoding = mb_detect_encoding($cell)) {
            $width += strlen($cell) - mb_strwidth($cell, $encoding);
        }

        $width += Helper::strlen($cell) - Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);

        $content = sprintf($this->style->getCellRowContentFormat(), $cell);

        $this->output->write(sprintf($cellFormat, str_pad($content, $width, $this->style->getPaddingChar(), $this->style->getPadType())));
    }

    /**
     * Gets number of columns for this table.
     *
     * @return int
     */
    private function getNumberOfColumns()
    {
        if (null !== $this->numberOfColumns) {
            return $this->numberOfColumns;
        }

        $columns = array(count($this->headers));
        foreach ($this->rows as $row) {
            $columns[] = count($row);
        }

        return $this->numberOfColumns = max($columns);
    }

    /**
     * Gets column width.
     *
     * @param int $column
     *
     * @return int
     */
    private function getColumnWidth($column)
    {
        if (isset($this->columnWidths[$column])) {
            return $this->columnWidths[$column];
        }

        $lengths = array($this->getCellWidth($this->headers, $column));
        foreach ($this->rows as $row) {
            if ($row instanceof TableSeparator) {
                continue;
            }

            $lengths[] = $this->getCellWidth($row, $column);
        }

        return $this->columnWidths[$column] = max($lengths) + strlen($this->style->getCellRowContentFormat()) - 2;
    }

    /**
     * Gets cell width.
     *
     * @param array $row
     * @param int   $column
     *
     * @return int
     */
    private function getCellWidth(array $row, $column)
    {
        return isset($row[$column]) ? Helper::strlenWithoutDecoration($this->output->getFormatter(), $row[$column]) : 0;
    }

    /**
     * Called after rendering to cleanup cache data.
     */
    private function cleanup()
    {
        $this->columnWidths = array();
        $this->numberOfColumns = null;
    }

    private static function initStyles()
    {
        $borderless = new TableStyle();
        $borderless
            ->setHorizontalBorderChar('=')
            ->setVerticalBorderChar(' ')
            ->setCrossingChar(' ')
        ;

        $compact = new TableStyle();
        $compact
            ->setHorizontalBorderChar('')
            ->setVerticalBorderChar(' ')
            ->setCrossingChar('')
            ->setCellRowContentFormat('%s')
        ;

        return array(
            'default' => new TableStyle(),
            'borderless' => $borderless,
            'compact' => $compact,
        );
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Helper;

use Symfony\Component\Console\Command\Command;

/**
 * HelperSet represents a set of helpers to be used with a command.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class HelperSet implements \IteratorAggregate
{
    private $helpers = array();
    private $command;

    /**
     * Constructor.
     *
     * @param Helper[] $helpers An array of helper.
     */
    public function __construct(array $helpers = array())
    {
        foreach ($helpers as $alias => $helper) {
            $this->set($helper, is_int($alias) ? null : $alias);
        }
    }

    /**
     * Sets a helper.
     *
     * @param HelperInterface $helper The helper instance
     * @param string          $alias  An alias
     */
    public function set(HelperInterface $helper, $alias = null)
    {
        $this->helpers[$helper->getName()] = $helper;
        if (null !== $alias) {
            $this->helpers[$alias] = $helper;
        }

        $helper->setHelperSet($this);
    }

    /**
     * Returns true if the helper if defined.
     *
     * @param string $name The helper name
     *
     * @return bool true if the helper is defined, false otherwise
     */
    public function has($name)
    {
        return isset($this->helpers[$name]);
    }

    /**
     * Gets a helper value.
     *
     * @param string $name The helper name
     *
     * @return HelperInterface The helper instance
     *
     * @throws \InvalidArgumentException if the helper is not defined
     */
    public function get($name)
    {
        if (!$this->has($name)) {
            throw new \InvalidArgumentException(sprintf('The helper "%s" is not defined.', $name));
        }

        return $this->helpers[$name];
    }

    /**
     * Sets the command associated with this helper set.
     *
     * @param Command $command A Command instance
     */
    public function setCommand(Command $command = null)
    {
        $this->command = $command;
    }

    /**
     * Gets the command associated with this helper set.
     *
     * @return Command A Command instance
     */
    public function getCommand()
    {
        return $this->command;
    }

    public function getIterator()
    {
        return new \ArrayIterator($this->helpers);
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Helper;

/**
 * Marks a row as being a separator.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class TableSeparator
{
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Helper;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Question\ChoiceQuestion;

/**
 * The QuestionHelper class provides helpers to interact with the user.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class QuestionHelper extends Helper
{
    private $inputStream;
    private static $shell;
    private static $stty;

    /**
     * Asks a question to the user.
     *
     * @param InputInterface  $input    An InputInterface instance
     * @param OutputInterface $output   An OutputInterface instance
     * @param Question        $question The question to ask
     *
     * @return string The user answer
     *
     * @throws \RuntimeException If there is no data to read in the input stream
     */
    public function ask(InputInterface $input, OutputInterface $output, Question $question)
    {
        if (!$input->isInteractive()) {
            return $question->getDefault();
        }

        if (!$question->getValidator()) {
            return $this->doAsk($output, $question);
        }

        $that = $this;

        $interviewer = function () use ($output, $question, $that) {
            return $that->doAsk($output, $question);
        };

        return $this->validateAttempts($interviewer, $output, $question);
    }

    /**
     * Sets the input stream to read from when interacting with the user.
     *
     * This is mainly useful for testing purpose.
     *
     * @param resource $stream The input stream
     *
     * @throws \InvalidArgumentException In case the stream is not a resource
     */
    public function setInputStream($stream)
    {
        if (!is_resource($stream)) {
            throw new \InvalidArgumentException('Input stream must be a valid resource.');
        }

        $this->inputStream = $stream;
    }

    /**
     * Returns the helper's input stream
     *
     * @return resource
     */
    public function getInputStream()
    {
        return $this->inputStream;
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'question';
    }

    /**
     * Asks the question to the user.
     *
     * This method is public for PHP 5.3 compatibility, it should be private.
     *
     * @param OutputInterface $output
     * @param Question        $question
     *
     * @return bool|mixed|null|string
     *
     * @throws \Exception
     * @throws \RuntimeException
     */
    public function doAsk(OutputInterface $output, Question $question)
    {
        $inputStream = $this->inputStream ?: STDIN;

        $message = $question->getQuestion();
        if ($question instanceof ChoiceQuestion) {
            $width = max(array_map('strlen', array_keys($question->getChoices())));

            $messages = (array) $question->getQuestion();
            foreach ($question->getChoices() as $key => $value) {
                $messages[] = sprintf("  [<info>%-${width}s</info>] %s", $key, $value);
            }

            $output->writeln($messages);

            $message = $question->getPrompt();
        }

        $output->write($message);

        $autocomplete = $question->getAutocompleterValues();
        if (null === $autocomplete || !$this->hasSttyAvailable()) {
            $ret = false;
            if ($question->isHidden()) {
                try {
                    $ret = trim($this->getHiddenResponse($output, $inputStream));
                } catch (\RuntimeException $e) {
                    if (!$question->isHiddenFallback()) {
                        throw $e;
                    }
                }
            }

            if (false === $ret) {
                $ret = fgets($inputStream, 4096);
                if (false === $ret) {
                    throw new \RuntimeException('Aborted');
                }
                $ret = trim($ret);
            }
        } else {
            $ret = trim($this->autocomplete($output, $question, $inputStream));
        }

        $ret = strlen($ret) > 0 ? $ret : $question->getDefault();

        if ($normalizer = $question->getNormalizer()) {
            return $normalizer($ret);
        }

        return $ret;
    }

    /**
     * Autocompletes a question.
     *
     * @param OutputInterface $output
     * @param Question        $question
     *
     * @return string
     */
    private function autocomplete(OutputInterface $output, Question $question, $inputStream)
    {
        $autocomplete = $question->getAutocompleterValues();
        $ret = '';

        $i = 0;
        $ofs = -1;
        $matches = $autocomplete;
        $numMatches = count($matches);

        $sttyMode = shell_exec('stty -g');

        // Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)
        shell_exec('stty -icanon -echo');

        // Add highlighted text style
        $output->getFormatter()->setStyle('hl', new OutputFormatterStyle('black', 'white'));

        // Read a keypress
        while (!feof($inputStream)) {
            $c = fread($inputStream, 1);

            // Backspace Character
            if ("\177" === $c) {
                if (0 === $numMatches && 0 !== $i) {
                    $i--;
                    // Move cursor backwards
                    $output->write("\033[1D");
                }

                if ($i === 0) {
                    $ofs = -1;
                    $matches = $autocomplete;
                    $numMatches = count($matches);
                } else {
                    $numMatches = 0;
                }

                // Pop the last character off the end of our string
                $ret = substr($ret, 0, $i);
            } elseif ("\033" === $c) {
                // Did we read an escape sequence?
                $c .= fread($inputStream, 2);

                // A = Up Arrow. B = Down Arrow
                if (isset($c[2]) && ('A' === $c[2] || 'B' === $c[2])) {
                    if ('A' === $c[2] && -1 === $ofs) {
                        $ofs = 0;
                    }

                    if (0 === $numMatches) {
                        continue;
                    }

                    $ofs += ('A' === $c[2]) ? -1 : 1;
                    $ofs = ($numMatches + $ofs) % $numMatches;
                }
            } elseif (ord($c) < 32) {
                if ("\t" === $c || "\n" === $c) {
                    if ($numMatches > 0 && -1 !== $ofs) {
                        $ret = $matches[$ofs];
                        // Echo out remaining chars for current match
                        $output->write(substr($ret, $i));
                        $i = strlen($ret);
                    }

                    if ("\n" === $c) {
                        $output->write($c);
                        break;
                    }

                    $numMatches = 0;
                }

                continue;
            } else {
                $output->write($c);
                $ret .= $c;
                $i++;

                $numMatches = 0;
                $ofs = 0;

                foreach ($autocomplete as $value) {
                    // If typed characters match the beginning chunk of value (e.g. [AcmeDe]moBundle)
                    if (0 === strpos($value, $ret) && $i !== strlen($value)) {
                        $matches[$numMatches++] = $value;
                    }
                }
            }

            // Erase characters from cursor to end of line
            $output->write("\033[K");

            if ($numMatches > 0 && -1 !== $ofs) {
                // Save cursor position
                $output->write("\0337");
                // Write highlighted text
                $output->write('<hl>'.substr($matches[$ofs], $i).'</hl>');
                // Restore cursor position
                $output->write("\0338");
            }
        }

        // Reset stty so it behaves normally again
        shell_exec(sprintf('stty %s', $sttyMode));

        return $ret;
    }

    /**
     * Gets a hidden response from user.
     *
     * @param OutputInterface $output An Output instance
     *
     * @return string The answer
     *
     * @throws \RuntimeException In case the fallback is deactivated and the response cannot be hidden
     */
    private function getHiddenResponse(OutputInterface $output, $inputStream)
    {
        if ('\\' === DIRECTORY_SEPARATOR) {
            $exe = __DIR__.'/../Resources/bin/hiddeninput.exe';

            // handle code running from a phar
            if ('phar:' === substr(__FILE__, 0, 5)) {
                $tmpExe = sys_get_temp_dir().'/hiddeninput.exe';
                copy($exe, $tmpExe);
                $exe = $tmpExe;
            }

            $value = rtrim(shell_exec($exe));
            $output->writeln('');

            if (isset($tmpExe)) {
                unlink($tmpExe);
            }

            return $value;
        }

        if ($this->hasSttyAvailable()) {
            $sttyMode = shell_exec('stty -g');

            shell_exec('stty -echo');
            $value = fgets($inputStream, 4096);
            shell_exec(sprintf('stty %s', $sttyMode));

            if (false === $value) {
                throw new \RuntimeException('Aborted');
            }

            $value = trim($value);
            $output->writeln('');

            return $value;
        }

        if (false !== $shell = $this->getShell()) {
            $readCmd = $shell === 'csh' ? 'set mypassword = $<' : 'read -r mypassword';
            $command = sprintf("/usr/bin/env %s -c 'stty -echo; %s; stty echo; echo \$mypassword'", $shell, $readCmd);
            $value = rtrim(shell_exec($command));
            $output->writeln('');

            return $value;
        }

        throw new \RuntimeException('Unable to hide the response.');
    }

    /**
     * Validates an attempt.
     *
     * @param callable        $interviewer A callable that will ask for a question and return the result
     * @param OutputInterface $output      An Output instance
     * @param Question        $question    A Question instance
     *
     * @return string The validated response
     *
     * @throws \Exception In case the max number of attempts has been reached and no valid response has been given
     */
    private function validateAttempts($interviewer, OutputInterface $output, Question $question)
    {
        $error = null;
        $attempts = $question->getMaxAttempts();
        while (null === $attempts || $attempts--) {
            if (null !== $error) {
                if (null !== $this->getHelperSet() && $this->getHelperSet()->has('formatter')) {
                    $message = $this->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error');
                } else {
                    $message = '<error>'.$error->getMessage().'</error>';
                }

                $output->writeln($message);
            }

            try {
                return call_user_func($question->getValidator(), $interviewer());
            } catch (\Exception $error) {
            }
        }

        throw $error;
    }

    /**
     * Returns a valid unix shell.
     *
     * @return string|bool The valid shell name, false in case no valid shell is found
     */
    private function getShell()
    {
        if (null !== self::$shell) {
            return self::$shell;
        }

        self::$shell = false;

        if (file_exists('/usr/bin/env')) {
            // handle other OSs with bash/zsh/ksh/csh if available to hide the answer
            $test = "/usr/bin/env %s -c 'echo OK' 2> /dev/null";
            foreach (array('bash', 'zsh', 'ksh', 'csh') as $sh) {
                if ('OK' === rtrim(shell_exec(sprintf($test, $sh)))) {
                    self::$shell = $sh;
                    break;
                }
            }
        }

        return self::$shell;
    }

    /**
     * Returns whether Stty is available or not.
     *
     * @return bool
     */
    private function hasSttyAvailable()
    {
        if (null !== self::$stty) {
            return self::$stty;
        }

        exec('stty 2>&1', $output, $exitcode);

        return self::$stty = $exitcode === 0;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Helper;

use Symfony\Component\Console\Formatter\OutputFormatter;

/**
 * The Formatter class provides helpers to format messages.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class FormatterHelper extends Helper
{
    /**
     * Formats a message within a section.
     *
     * @param string $section The section name
     * @param string $message The message
     * @param string $style   The style to apply to the section
     *
     * @return string The format section
     */
    public function formatSection($section, $message, $style = 'info')
    {
        return sprintf('<%s>[%s]</%s> %s', $style, $section, $style, $message);
    }

    /**
     * Formats a message as a block of text.
     *
     * @param string|array $messages The message to write in the block
     * @param string       $style    The style to apply to the whole block
     * @param bool         $large    Whether to return a large block
     *
     * @return string The formatter message
     */
    public function formatBlock($messages, $style, $large = false)
    {
        if (!is_array($messages)) {
            $messages = array($messages);
        }

        $len = 0;
        $lines = array();
        foreach ($messages as $message) {
            $message = OutputFormatter::escape($message);
            $lines[] = sprintf($large ? '  %s  ' : ' %s ', $message);
            $len = max($this->strlen($message) + ($large ? 4 : 2), $len);
        }

        $messages = $large ? array(str_repeat(' ', $len)) : array();
        for ($i = 0; isset($lines[$i]); ++$i) {
            $messages[] = $lines[$i].str_repeat(' ', $len - $this->strlen($lines[$i]));
        }
        if ($large) {
            $messages[] = str_repeat(' ', $len);
        }

        for ($i = 0; isset($messages[$i]); ++$i) {
            $messages[$i] = sprintf('<%s>%s</%s>', $style, $messages[$i], $style);
        }

        return implode("\n", $messages);
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'formatter';
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Helper;

/**
 * HelperInterface is the interface all helpers must implement.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 *
 * @api
 */
interface HelperInterface
{
    /**
     * Sets the helper set associated with this helper.
     *
     * @param HelperSet $helperSet A HelperSet instance
     *
     * @api
     */
    public function setHelperSet(HelperSet $helperSet = null);

    /**
     * Gets the helper set associated with this helper.
     *
     * @return HelperSet A HelperSet instance
     *
     * @api
     */
    public function getHelperSet();

    /**
     * Returns the canonical name of this helper.
     *
     * @return string The canonical name
     *
     * @api
     */
    public function getName();
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Helper;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputAwareInterface;

/**
 * An implementation of InputAwareInterface for Helpers.
 *
 * @author Wouter J <waldio.webdesign@gmail.com>
 */
abstract class InputAwareHelper extends Helper implements InputAwareInterface
{
    protected $input;

    /**
     * {@inheritdoc}
     */
    public function setInput(InputInterface $input)
    {
        $this->input = $input;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Helper;

use Symfony\Component\Console\Output\OutputInterface;

/**
 * The ProgressBar provides helpers to display progress output.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 * @author Chris Jones <leeked@gmail.com>
 */
class ProgressBar
{
    // options
    private $barWidth = 28;
    private $barChar;
    private $emptyBarChar = '-';
    private $progressChar = '>';
    private $format = null;
    private $redrawFreq = 1;

    /**
     * @var OutputInterface
     */
    private $output;
    private $step = 0;
    private $max;
    private $startTime;
    private $stepWidth;
    private $percent = 0.0;
    private $lastMessagesLength = 0;
    private $formatLineCount;
    private $messages;
    private $overwrite = true;

    private static $formatters;
    private static $formats;

    /**
     * Constructor.
     *
     * @param OutputInterface $output An OutputInterface instance
     * @param int             $max    Maximum steps (0 if unknown)
     */
    public function __construct(OutputInterface $output, $max = 0)
    {
        $this->output = $output;
        $this->setMaxSteps($max);

        if (!$this->output->isDecorated()) {
            // disable overwrite when output does not support ANSI codes.
            $this->overwrite = false;

            if ($this->max > 10) {
                // set a reasonable redraw frequency so output isn't flooded
                $this->setRedrawFrequency($max / 10);
            }
        }

        $this->setFormat($this->determineBestFormat());

        $this->startTime = time();
    }

    /**
     * Sets a placeholder formatter for a given name.
     *
     * This method also allow you to override an existing placeholder.
     *
     * @param string   $name     The placeholder name (including the delimiter char like %)
     * @param callable $callable A PHP callable
     */
    public static function setPlaceholderFormatterDefinition($name, $callable)
    {
        if (!self::$formatters) {
            self::$formatters = self::initPlaceholderFormatters();
        }

        self::$formatters[$name] = $callable;
    }

    /**
     * Gets the placeholder formatter for a given name.
     *
     * @param string $name The placeholder name (including the delimiter char like %)
     *
     * @return callable|null A PHP callable
     */
    public static function getPlaceholderFormatterDefinition($name)
    {
        if (!self::$formatters) {
            self::$formatters = self::initPlaceholderFormatters();
        }

        return isset(self::$formatters[$name]) ? self::$formatters[$name] : null;
    }

    /**
     * Sets a format for a given name.
     *
     * This method also allow you to override an existing format.
     *
     * @param string $name   The format name
     * @param string $format A format string
     */
    public static function setFormatDefinition($name, $format)
    {
        if (!self::$formats) {
            self::$formats = self::initFormats();
        }

        self::$formats[$name] = $format;
    }

    /**
     * Gets the format for a given name.
     *
     * @param string $name The format name
     *
     * @return string|null A format string
     */
    public static function getFormatDefinition($name)
    {
        if (!self::$formats) {
            self::$formats = self::initFormats();
        }

        return isset(self::$formats[$name]) ? self::$formats[$name] : null;
    }

    public function setMessage($message, $name = 'message')
    {
        $this->messages[$name] = $message;
    }

    public function getMessage($name = 'message')
    {
        return $this->messages[$name];
    }

    /**
     * Gets the progress bar start time.
     *
     * @return int The progress bar start time
     */
    public function getStartTime()
    {
        return $this->startTime;
    }

    /**
     * Gets the progress bar maximal steps.
     *
     * @return int The progress bar max steps
     */
    public function getMaxSteps()
    {
        return $this->max;
    }

    /**
     * Gets the progress bar step.
     *
     * @deprecated since 2.6, to be removed in 3.0. Use {@link getProgress()} instead.
     *
     * @return int The progress bar step
     */
    public function getStep()
    {
        return $this->getProgress();
    }

    /**
     * Gets the current step position.
     *
     * @return int The progress bar step
     */
    public function getProgress()
    {
        return $this->step;
    }

    /**
     * Gets the progress bar step width.
     *
     * @internal This method is public for PHP 5.3 compatibility, it should not be used.
     *
     * @return int The progress bar step width
     */
    public function getStepWidth()
    {
        return $this->stepWidth;
    }

    /**
     * Gets the current progress bar percent.
     *
     * @return float The current progress bar percent
     */
    public function getProgressPercent()
    {
        return $this->percent;
    }

    /**
     * Sets the progress bar width.
     *
     * @param int $size The progress bar size
     */
    public function setBarWidth($size)
    {
        $this->barWidth = (int) $size;
    }

    /**
     * Gets the progress bar width.
     *
     * @return int The progress bar size
     */
    public function getBarWidth()
    {
        return $this->barWidth;
    }

    /**
     * Sets the bar character.
     *
     * @param string $char A character
     */
    public function setBarCharacter($char)
    {
        $this->barChar = $char;
    }

    /**
     * Gets the bar character.
     *
     * @return string A character
     */
    public function getBarCharacter()
    {
        if (null === $this->barChar) {
            return $this->max ? '=' : $this->emptyBarChar;
        }

        return $this->barChar;
    }

    /**
     * Sets the empty bar character.
     *
     * @param string $char A character
     */
    public function setEmptyBarCharacter($char)
    {
        $this->emptyBarChar = $char;
    }

    /**
     * Gets the empty bar character.
     *
     * @return string A character
     */
    public function getEmptyBarCharacter()
    {
        return $this->emptyBarChar;
    }

    /**
     * Sets the progress bar character.
     *
     * @param string $char A character
     */
    public function setProgressCharacter($char)
    {
        $this->progressChar = $char;
    }

    /**
     * Gets the progress bar character.
     *
     * @return string A character
     */
    public function getProgressCharacter()
    {
        return $this->progressChar;
    }

    /**
     * Sets the progress bar format.
     *
     * @param string $format The format
     */
    public function setFormat($format)
    {
        // try to use the _nomax variant if available
        if (!$this->max && null !== self::getFormatDefinition($format.'_nomax')) {
            $this->format = self::getFormatDefinition($format.'_nomax');
        } elseif (null !== self::getFormatDefinition($format)) {
            $this->format = self::getFormatDefinition($format);
        } else {
            $this->format = $format;
        }

        $this->formatLineCount = substr_count($this->format, "\n");
    }

    /**
     * Sets the redraw frequency.
     *
     * @param int $freq The frequency in steps
     */
    public function setRedrawFrequency($freq)
    {
        $this->redrawFreq = (int) $freq;
    }

    /**
     * Starts the progress output.
     *
     * @param int|null $max Number of steps to complete the bar (0 if indeterminate), null to leave unchanged
     */
    public function start($max = null)
    {
        $this->startTime = time();
        $this->step = 0;
        $this->percent = 0.0;

        if (null !== $max) {
            $this->setMaxSteps($max);
        }

        $this->display();
    }

    /**
     * Advances the progress output X steps.
     *
     * @param int $step Number of steps to advance
     *
     * @throws \LogicException
     */
    public function advance($step = 1)
    {
        $this->setProgress($this->step + $step);
    }

    /**
     * Sets the current progress.
     *
     * @deprecated since 2.6, to be removed in 3.0. Use {@link setProgress()} instead.
     *
     * @param int $step The current progress
     *
     * @throws \LogicException
     */
    public function setCurrent($step)
    {
        $this->setProgress($step);
    }

    /**
     * Sets whether to overwrite the progressbar, false for new line.
     *
     * @param bool $overwrite
     */
    public function setOverwrite($overwrite)
    {
        $this->overwrite = (bool) $overwrite;
    }

    /**
     * Sets the current progress.
     *
     * @param int $step The current progress
     *
     * @throws \LogicException
     */
    public function setProgress($step)
    {
        $step = (int) $step;
        if ($step < $this->step) {
            throw new \LogicException('You can\'t regress the progress bar.');
        }

        if ($this->max && $step > $this->max) {
            $this->max = $step;
        }

        $prevPeriod = (int) ($this->step / $this->redrawFreq);
        $currPeriod = (int) ($step / $this->redrawFreq);
        $this->step = $step;
        $this->percent = $this->max ? (float) $this->step / $this->max : 0;
        if ($prevPeriod !== $currPeriod || $this->max === $step) {
            $this->display();
        }
    }

    /**
     * Finishes the progress output.
     */
    public function finish()
    {
        if (!$this->max) {
            $this->max = $this->step;
        }

        if ($this->step === $this->max && !$this->overwrite) {
            // prevent double 100% output
            return;
        }

        $this->setProgress($this->max);
    }

    /**
     * Outputs the current progress string.
     */
    public function display()
    {
        if (OutputInterface::VERBOSITY_QUIET === $this->output->getVerbosity()) {
            return;
        }

        // these 3 variables can be removed in favor of using $this in the closure when support for PHP 5.3 will be dropped.
        $self = $this;
        $output = $this->output;
        $messages = $this->messages;
        $this->overwrite(preg_replace_callback("{%([a-z\-_]+)(?:\:([^%]+))?%}i", function ($matches) use ($self, $output, $messages) {
            if ($formatter = $self::getPlaceholderFormatterDefinition($matches[1])) {
                $text = call_user_func($formatter, $self, $output);
            } elseif (isset($messages[$matches[1]])) {
                $text = $messages[$matches[1]];
            } else {
                return $matches[0];
            }

            if (isset($matches[2])) {
                $text = sprintf('%'.$matches[2], $text);
            }

            return $text;
        }, $this->format));
    }

    /**
     * Removes the progress bar from the current line.
     *
     * This is useful if you wish to write some output
     * while a progress bar is running.
     * Call display() to show the progress bar again.
     */
    public function clear()
    {
        if (!$this->overwrite) {
            return;
        }

        $this->overwrite(str_repeat("\n", $this->formatLineCount));
    }

    /**
     * Sets the progress bar maximal steps.
     *
     * @param int     The progress bar max steps
     */
    private function setMaxSteps($max)
    {
        $this->max = max(0, (int) $max);
        $this->stepWidth = $this->max ? Helper::strlen($this->max) : 4;
    }

    /**
     * Overwrites a previous message to the output.
     *
     * @param string $message The message
     */
    private function overwrite($message)
    {
        $lines = explode("\n", $message);

        // append whitespace to match the line's length
        if (null !== $this->lastMessagesLength) {
            foreach ($lines as $i => $line) {
                if ($this->lastMessagesLength > Helper::strlenWithoutDecoration($this->output->getFormatter(), $line)) {
                    $lines[$i] = str_pad($line, $this->lastMessagesLength, "\x20", STR_PAD_RIGHT);
                }
            }
        }

        if ($this->overwrite) {
            // move back to the beginning of the progress bar before redrawing it
            $this->output->write("\x0D");
        } elseif ($this->step > 0) {
            // move to new line
            $this->output->writeln('');
        }

        if ($this->formatLineCount) {
            $this->output->write(sprintf("\033[%dA", $this->formatLineCount));
        }
        $this->output->write(implode("\n", $lines));

        $this->lastMessagesLength = 0;
        foreach ($lines as $line) {
            $len = Helper::strlenWithoutDecoration($this->output->getFormatter(), $line);
            if ($len > $this->lastMessagesLength) {
                $this->lastMessagesLength = $len;
            }
        }
    }

    private function determineBestFormat()
    {
        switch ($this->output->getVerbosity()) {
            // OutputInterface::VERBOSITY_QUIET: display is disabled anyway
            case OutputInterface::VERBOSITY_VERBOSE:
                return $this->max ? 'verbose' : 'verbose_nomax';
            case OutputInterface::VERBOSITY_VERY_VERBOSE:
                return $this->max ? 'very_verbose' : 'very_verbose_nomax';
            case OutputInterface::VERBOSITY_DEBUG:
                return $this->max ? 'debug' : 'debug_nomax';
            default:
                return $this->max ? 'normal' : 'normal_nomax';
        }
    }

    private static function initPlaceholderFormatters()
    {
        return array(
            'bar' => function (ProgressBar $bar, OutputInterface $output) {
                $completeBars = floor($bar->getMaxSteps() > 0 ? $bar->getProgressPercent() * $bar->getBarWidth() : $bar->getProgress() % $bar->getBarWidth());
                $display = str_repeat($bar->getBarCharacter(), $completeBars);
                if ($completeBars < $bar->getBarWidth()) {
                    $emptyBars = $bar->getBarWidth() - $completeBars - Helper::strlenWithoutDecoration($output->getFormatter(), $bar->getProgressCharacter());
                    $display .= $bar->getProgressCharacter().str_repeat($bar->getEmptyBarCharacter(), $emptyBars);
                }

                return $display;
            },
            'elapsed' => function (ProgressBar $bar) {
                return Helper::formatTime(time() - $bar->getStartTime());
            },
            'remaining' => function (ProgressBar $bar) {
                if (!$bar->getMaxSteps()) {
                    throw new \LogicException('Unable to display the remaining time if the maximum number of steps is not set.');
                }

                if (!$bar->getProgress()) {
                    $remaining = 0;
                } else {
                    $remaining = round((time() - $bar->getStartTime()) / $bar->getProgress() * ($bar->getMaxSteps() - $bar->getProgress()));
                }

                return Helper::formatTime($remaining);
            },
            'estimated' => function (ProgressBar $bar) {
                if (!$bar->getMaxSteps()) {
                    throw new \LogicException('Unable to display the estimated time if the maximum number of steps is not set.');
                }

                if (!$bar->getProgress()) {
                    $estimated = 0;
                } else {
                    $estimated = round((time() - $bar->getStartTime()) / $bar->getProgress() * $bar->getMaxSteps());
                }

                return Helper::formatTime($estimated);
            },
            'memory' => function (ProgressBar $bar) {
                return Helper::formatMemory(memory_get_usage(true));
            },
            'current' => function (ProgressBar $bar) {
                return str_pad($bar->getProgress(), $bar->getStepWidth(), ' ', STR_PAD_LEFT);
            },
            'max' => function (ProgressBar $bar) {
                return $bar->getMaxSteps();
            },
            'percent' => function (ProgressBar $bar) {
                return floor($bar->getProgressPercent() * 100);
            },
        );
    }

    private static function initFormats()
    {
        return array(
            'normal' => ' %current%/%max% [%bar%] %percent:3s%%',
            'normal_nomax' => ' %current% [%bar%]',

            'verbose' => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%',
            'verbose_nomax' => ' %current% [%bar%] %elapsed:6s%',

            'very_verbose' => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s%',
            'very_verbose_nomax' => ' %current% [%bar%] %elapsed:6s%',

            'debug' => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%',
            'debug_nomax' => ' %current% [%bar%] %elapsed:6s% %memory:6s%',
        );
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Helper;

/**
 * Helps outputting debug information when running an external program from a command.
 *
 * An external program can be a Process, an HTTP request, or anything else.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class DebugFormatterHelper extends Helper
{
    private $colors = array('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'default');
    private $started = array();
    private $count = -1;

    /**
     * Starts a debug formatting session
     *
     * @param string $id      The id of the formatting session
     * @param string $message The message to display
     * @param string $prefix  The prefix to use
     *
     * @return string
     */
    public function start($id, $message, $prefix = 'RUN')
    {
        $this->started[$id] = array('border' => ++$this->count % count($this->colors));

        return sprintf("%s<bg=blue;fg=white> %s </> <fg=blue>%s</>\n", $this->getBorder($id), $prefix, $message);
    }

    /**
     * Adds progress to a formatting session
     *
     * @param string $id          The id of the formatting session
     * @param string $buffer      The message to display
     * @param bool   $error       Whether to consider the buffer as error
     * @param string $prefix      The prefix for output
     * @param string $errorPrefix The prefix for error output
     *
     * @return string
     */
    public function progress($id, $buffer, $error = false, $prefix = 'OUT', $errorPrefix = 'ERR')
    {
        $message = '';

        if ($error) {
            if (isset($this->started[$id]['out'])) {
                $message .= "\n";
                unset($this->started[$id]['out']);
            }
            if (!isset($this->started[$id]['err'])) {
                $message .= sprintf("%s<bg=red;fg=white> %s </> ", $this->getBorder($id), $errorPrefix);
                $this->started[$id]['err'] = true;
            }

            $message .= str_replace("\n", sprintf("\n%s<bg=red;fg=white> %s </> ", $this->getBorder($id), $errorPrefix), $buffer);
        } else {
            if (isset($this->started[$id]['err'])) {
                $message .= "\n";
                unset($this->started[$id]['err']);
            }
            if (!isset($this->started[$id]['out'])) {
                $message .= sprintf("%s<bg=green;fg=white> %s </> ", $this->getBorder($id), $prefix);
                $this->started[$id]['out'] = true;
            }

            $message .= str_replace("\n", sprintf("\n%s<bg=green;fg=white> %s </> ", $this->getBorder($id), $prefix), $buffer);
        }

        return $message;
    }

    /**
     * Stops a formatting session
     *
     * @param string $id         The id of the formatting session
     * @param string $message    The message to display
     * @param bool   $successful Whether to consider the result as success
     * @param string $prefix     The prefix for the end output
     *
     * @return string
     */
    public function stop($id, $message, $successful, $prefix = 'RES')
    {
        $trailingEOL = isset($this->started[$id]['out']) || isset($this->started[$id]['err']) ? "\n" : '';

        if ($successful) {
            return sprintf("%s%s<bg=green;fg=white> %s </> <fg=green>%s</>\n", $trailingEOL, $this->getBorder($id), $prefix, $message);
        }

        $message = sprintf("%s%s<bg=red;fg=white> %s </> <fg=red>%s</>\n", $trailingEOL, $this->getBorder($id), $prefix, $message);

        unset($this->started[$id]['out'], $this->started[$id]['err']);

        return $message;
    }

    /**
     * @param string $id The id of the formatting session
     *
     * @return string
     */
    private function getBorder($id)
    {
        return sprintf('<bg=%s> </>', $this->colors[$this->started[$id]['border']]);
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'debug_formatter';
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Helper;

use Symfony\Component\Console\Descriptor\DescriptorInterface;
use Symfony\Component\Console\Descriptor\JsonDescriptor;
use Symfony\Component\Console\Descriptor\MarkdownDescriptor;
use Symfony\Component\Console\Descriptor\TextDescriptor;
use Symfony\Component\Console\Descriptor\XmlDescriptor;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * This class adds helper method to describe objects in various formats.
 *
 * @author Jean-François Simon <contact@jfsimon.fr>
 */
class DescriptorHelper extends Helper
{
    /**
     * @var DescriptorInterface[]
     */
    private $descriptors = array();

    /**
     * Constructor.
     */
    public function __construct()
    {
        $this
            ->register('txt', new TextDescriptor())
            ->register('xml', new XmlDescriptor())
            ->register('json', new JsonDescriptor())
            ->register('md', new MarkdownDescriptor())
        ;
    }

    /**
     * Describes an object if supported.
     *
     * Available options are:
     * * format: string, the output format name
     * * raw_text: boolean, sets output type as raw
     *
     * @param OutputInterface $output
     * @param object          $object
     * @param array           $options
     *
     * @throws \InvalidArgumentException when the given format is not supported
     */
    public function describe(OutputInterface $output, $object, array $options = array())
    {
        $options = array_merge(array(
            'raw_text' => false,
            'format' => 'txt',
        ), $options);

        if (!isset($this->descriptors[$options['format']])) {
            throw new \InvalidArgumentException(sprintf('Unsupported format "%s".', $options['format']));
        }

        $descriptor = $this->descriptors[$options['format']];
        $descriptor->describe($output, $object, $options);
    }

    /**
     * Registers a descriptor.
     *
     * @param string              $format
     * @param DescriptorInterface $descriptor
     *
     * @return DescriptorHelper
     */
    public function register($format, DescriptorInterface $descriptor)
    {
        $this->descriptors[$format] = $descriptor;

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'descriptor';
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Descriptor;

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;

/**
 * Text descriptor.
 *
 * @author Jean-François Simon <contact@jfsimon.fr>
 *
 * @internal
 */
class TextDescriptor extends Descriptor
{
    /**
     * {@inheritdoc}
     */
    protected function describeInputArgument(InputArgument $argument, array $options = array())
    {
        if (null !== $argument->getDefault() && (!is_array($argument->getDefault()) || count($argument->getDefault()))) {
            $default = sprintf('<comment> (default: %s)</comment>', $this->formatDefaultValue($argument->getDefault()));
        } else {
            $default = '';
        }

        $nameWidth = isset($options['name_width']) ? $options['name_width'] : strlen($argument->getName());

        $this->writeText(sprintf(" <info>%-${nameWidth}s</info> %s%s",
            $argument->getName(),
            str_replace("\n", "\n".str_repeat(' ', $nameWidth + 2), $argument->getDescription()),
            $default
        ), $options);
    }

    /**
     * {@inheritdoc}
     */
    protected function describeInputOption(InputOption $option, array $options = array())
    {
        if ($option->acceptValue() && null !== $option->getDefault() && (!is_array($option->getDefault()) || count($option->getDefault()))) {
            $default = sprintf('<comment> (default: %s)</comment>', $this->formatDefaultValue($option->getDefault()));
        } else {
            $default = '';
        }

        $nameWidth = isset($options['name_width']) ? $options['name_width'] : strlen($option->getName());
        $nameWithShortcutWidth = $nameWidth - strlen($option->getName()) - 2;

        $this->writeText(sprintf(" <info>%s</info> %-${nameWithShortcutWidth}s%s%s%s",
            '--'.$option->getName(),
            $option->getShortcut() ? sprintf('(-%s) ', $option->getShortcut()) : '',
            str_replace("\n", "\n".str_repeat(' ', $nameWidth + 2), $option->getDescription()),
            $default,
            $option->isArray() ? '<comment> (multiple values allowed)</comment>' : ''
        ), $options);
    }

    /**
     * {@inheritdoc}
     */
    protected function describeInputDefinition(InputDefinition $definition, array $options = array())
    {
        $nameWidth = 0;
        foreach ($definition->getOptions() as $option) {
            $nameLength = strlen($option->getName()) + 2;
            if ($option->getShortcut()) {
                $nameLength += strlen($option->getShortcut()) + 3;
            }
            $nameWidth = max($nameWidth, $nameLength);
        }
        foreach ($definition->getArguments() as $argument) {
            $nameWidth = max($nameWidth, strlen($argument->getName()));
        }
        ++$nameWidth;

        if ($definition->getArguments()) {
            $this->writeText('<comment>Arguments:</comment>', $options);
            $this->writeText("\n");
            foreach ($definition->getArguments() as $argument) {
                $this->describeInputArgument($argument, array_merge($options, array('name_width' => $nameWidth)));
                $this->writeText("\n");
            }
        }

        if ($definition->getArguments() && $definition->getOptions()) {
            $this->writeText("\n");
        }

        if ($definition->getOptions()) {
            $this->writeText('<comment>Options:</comment>', $options);
            $this->writeText("\n");
            foreach ($definition->getOptions() as $option) {
                $this->describeInputOption($option, array_merge($options, array('name_width' => $nameWidth)));
                $this->writeText("\n");
            }
        }
    }

    /**
     * {@inheritdoc}
     */
    protected function describeCommand(Command $command, array $options = array())
    {
        $command->getSynopsis();
        $command->mergeApplicationDefinition(false);

        $this->writeText('<comment>Usage:</comment>', $options);
        $this->writeText("\n");
        $this->writeText(' '.$command->getSynopsis(), $options);
        $this->writeText("\n");

        if (count($command->getAliases()) > 0) {
            $this->writeText("\n");
            $this->writeText('<comment>Aliases:</comment> <info>'.implode(', ', $command->getAliases()).'</info>', $options);
        }

        if ($definition = $command->getNativeDefinition()) {
            $this->writeText("\n");
            $this->describeInputDefinition($definition, $options);
        }

        $this->writeText("\n");

        if ($help = $command->getProcessedHelp()) {
            $this->writeText('<comment>Help:</comment>', $options);
            $this->writeText("\n");
            $this->writeText(' '.str_replace("\n", "\n ", $help), $options);
            $this->writeText("\n");
        }
    }

    /**
     * {@inheritdoc}
     */
    protected function describeApplication(Application $application, array $options = array())
    {
        $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
        $description = new ApplicationDescription($application, $describedNamespace);

        if (isset($options['raw_text']) && $options['raw_text']) {
            $width = $this->getColumnWidth($description->getCommands());

            foreach ($description->getCommands() as $command) {
                $this->writeText(sprintf("%-${width}s %s", $command->getName(), $command->getDescription()), $options);
                $this->writeText("\n");
            }
        } else {
            if ('' != $help = $application->getHelp()) {
                $this->writeText("$help\n\n", $options);
            }

            $this->writeText("<comment>Usage:</comment>\n", $options);
            $this->writeText(" command [options] [arguments]\n\n", $options);
            $this->writeText('<comment>Options:</comment>', $options);

            $inputOptions = $application->getDefinition()->getOptions();

            $width = 0;
            foreach ($inputOptions as $option) {
                $nameLength = strlen($option->getName()) + 2;
                if ($option->getShortcut()) {
                    $nameLength += strlen($option->getShortcut()) + 3;
                }
                $width = max($width, $nameLength);
            }
            ++$width;

            foreach ($inputOptions as $option) {
                $this->writeText("\n", $options);
                $this->describeInputOption($option, array_merge($options, array('name_width' => $width)));
            }

            $this->writeText("\n\n", $options);

            $width = $this->getColumnWidth($description->getCommands());

            if ($describedNamespace) {
                $this->writeText(sprintf('<comment>Available commands for the "%s" namespace:</comment>', $describedNamespace), $options);
            } else {
                $this->writeText('<comment>Available commands:</comment>', $options);
            }

            // add commands by namespace
            foreach ($description->getNamespaces() as $namespace) {
                if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
                    $this->writeText("\n");
                    $this->writeText('<comment>'.$namespace['id'].'</comment>', $options);
                }

                foreach ($namespace['commands'] as $name) {
                    $this->writeText("\n");
                    $this->writeText(sprintf(" <info>%-${width}s</info> %s", $name, $description->getCommand($name)->getDescription()), $options);
                }
            }

            $this->writeText("\n");
        }
    }

    /**
     * {@inheritdoc}
     */
    private function writeText($content, array $options = array())
    {
        $this->write(
            isset($options['raw_text']) && $options['raw_text'] ? strip_tags($content) : $content,
            isset($options['raw_output']) ? !$options['raw_output'] : true
        );
    }

    /**
     * Formats input option/argument default value.
     *
     * @param mixed $default
     *
     * @return string
     */
    private function formatDefaultValue($default)
    {
        if (PHP_VERSION_ID < 50400) {
            return str_replace('\/', '/', json_encode($default));
        }

        return json_encode($default, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
    }

    /**
     * @param Command[] $commands
     *
     * @return int
     */
    private function getColumnWidth(array $commands)
    {
        $width = 0;
        foreach ($commands as $command) {
            $width = strlen($command->getName()) > $width ? strlen($command->getName()) : $width;
        }

        return $width + 2;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Descriptor;

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;

/**
 * Markdown descriptor.
 *
 * @author Jean-François Simon <contact@jfsimon.fr>
 *
 * @internal
 */
class MarkdownDescriptor extends Descriptor
{
    /**
     * {@inheritdoc}
     */
    protected function describeInputArgument(InputArgument $argument, array $options = array())
    {
        $this->write(
            '**'.$argument->getName().':**'."\n\n"
            .'* Name: '.($argument->getName() ?: '<none>')."\n"
            .'* Is required: '.($argument->isRequired() ? 'yes' : 'no')."\n"
            .'* Is array: '.($argument->isArray() ? 'yes' : 'no')."\n"
            .'* Description: '.($argument->getDescription() ?: '<none>')."\n"
            .'* Default: `'.str_replace("\n", '', var_export($argument->getDefault(), true)).'`'
        );
    }

    /**
     * {@inheritdoc}
     */
    protected function describeInputOption(InputOption $option, array $options = array())
    {
        $this->write(
            '**'.$option->getName().':**'."\n\n"
            .'* Name: `--'.$option->getName().'`'."\n"
            .'* Shortcut: '.($option->getShortcut() ? '`-'.implode('|-', explode('|', $option->getShortcut())).'`' : '<none>')."\n"
            .'* Accept value: '.($option->acceptValue() ? 'yes' : 'no')."\n"
            .'* Is value required: '.($option->isValueRequired() ? 'yes' : 'no')."\n"
            .'* Is multiple: '.($option->isArray() ? 'yes' : 'no')."\n"
            .'* Description: '.($option->getDescription() ?: '<none>')."\n"
            .'* Default: `'.str_replace("\n", '', var_export($option->getDefault(), true)).'`'
        );
    }

    /**
     * {@inheritdoc}
     */
    protected function describeInputDefinition(InputDefinition $definition, array $options = array())
    {
        if ($showArguments = count($definition->getArguments()) > 0) {
            $this->write('### Arguments:');
            foreach ($definition->getArguments() as $argument) {
                $this->write("\n\n");
                $this->write($this->describeInputArgument($argument));
            }
        }

        if (count($definition->getOptions()) > 0) {
            if ($showArguments) {
                $this->write("\n\n");
            }

            $this->write('### Options:');
            foreach ($definition->getOptions() as $option) {
                $this->write("\n\n");
                $this->write($this->describeInputOption($option));
            }
        }
    }

    /**
     * {@inheritdoc}
     */
    protected function describeCommand(Command $command, array $options = array())
    {
        $command->getSynopsis();
        $command->mergeApplicationDefinition(false);

        $this->write(
            $command->getName()."\n"
            .str_repeat('-', strlen($command->getName()))."\n\n"
            .'* Description: '.($command->getDescription() ?: '<none>')."\n"
            .'* Usage: `'.$command->getSynopsis().'`'."\n"
            .'* Aliases: '.(count($command->getAliases()) ? '`'.implode('`, `', $command->getAliases()).'`' : '<none>')
        );

        if ($help = $command->getProcessedHelp()) {
            $this->write("\n\n");
            $this->write($help);
        }

        if ($command->getNativeDefinition()) {
            $this->write("\n\n");
            $this->describeInputDefinition($command->getNativeDefinition());
        }
    }

    /**
     * {@inheritdoc}
     */
    protected function describeApplication(Application $application, array $options = array())
    {
        $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
        $description = new ApplicationDescription($application, $describedNamespace);

        $this->write($application->getName()."\n".str_repeat('=', strlen($application->getName())));

        foreach ($description->getNamespaces() as $namespace) {
            if (ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
                $this->write("\n\n");
                $this->write('**'.$namespace['id'].':**');
            }

            $this->write("\n\n");
            $this->write(implode("\n", array_map(function ($commandName) {
                return '* '.$commandName;
            }, $namespace['commands'])));
        }

        foreach ($description->getCommands() as $command) {
            $this->write("\n\n");
            $this->write($this->describeCommand($command));
        }
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Descriptor;

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
 *
 * @internal
 */
abstract class Descriptor implements DescriptorInterface
{
    /**
     * @var OutputInterface
     */
    private $output;

    /**
     * {@inheritdoc}
     */
    public function describe(OutputInterface $output, $object, array $options = array())
    {
        $this->output = $output;

        switch (true) {
            case $object instanceof InputArgument:
                $this->describeInputArgument($object, $options);
                break;
            case $object instanceof InputOption:
                $this->describeInputOption($object, $options);
                break;
            case $object instanceof InputDefinition:
                $this->describeInputDefinition($object, $options);
                break;
            case $object instanceof Command:
                $this->describeCommand($object, $options);
                break;
            case $object instanceof Application:
                $this->describeApplication($object, $options);
                break;
            default:
                throw new \InvalidArgumentException(sprintf('Object of type "%s" is not describable.', get_class($object)));
        }
    }

    /**
     * Writes content to output.
     *
     * @param string $content
     * @param bool   $decorated
     */
    protected function write($content, $decorated = false)
    {
        $this->output->write($content, false, $decorated ? OutputInterface::OUTPUT_NORMAL : OutputInterface::OUTPUT_RAW);
    }

    /**
     * Describes an InputArgument instance.
     *
     * @param InputArgument $argument
     * @param array         $options
     *
     * @return string|mixed
     */
    abstract protected function describeInputArgument(InputArgument $argument, array $options = array());

    /**
     * Describes an InputOption instance.
     *
     * @param InputOption $option
     * @param array       $options
     *
     * @return string|mixed
     */
    abstract protected function describeInputOption(InputOption $option, array $options = array());

    /**
     * Describes an InputDefinition instance.
     *
     * @param InputDefinition $definition
     * @param array           $options
     *
     * @return string|mixed
     */
    abstract protected function describeInputDefinition(InputDefinition $definition, array $options = array());

    /**
     * Describes a Command instance.
     *
     * @param Command $command
     * @param array   $options
     *
     * @return string|mixed
     */
    abstract protected function describeCommand(Command $command, array $options = array());

    /**
     * Describes an Application instance.
     *
     * @param Application $application
     * @param array       $options
     *
     * @return string|mixed
     */
    abstract protected function describeApplication(Application $application, array $options = array());
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Descriptor;

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;

/**
 * JSON descriptor.
 *
 * @author Jean-François Simon <contact@jfsimon.fr>
 *
 * @internal
 */
class JsonDescriptor extends Descriptor
{
    /**
     * {@inheritdoc}
     */
    protected function describeInputArgument(InputArgument $argument, array $options = array())
    {
        $this->writeData($this->getInputArgumentData($argument), $options);
    }

    /**
     * {@inheritdoc}
     */
    protected function describeInputOption(InputOption $option, array $options = array())
    {
        $this->writeData($this->getInputOptionData($option), $options);
    }

    /**
     * {@inheritdoc}
     */
    protected function describeInputDefinition(InputDefinition $definition, array $options = array())
    {
        $this->writeData($this->getInputDefinitionData($definition), $options);
    }

    /**
     * {@inheritdoc}
     */
    protected function describeCommand(Command $command, array $options = array())
    {
        $this->writeData($this->getCommandData($command), $options);
    }

    /**
     * {@inheritdoc}
     */
    protected function describeApplication(Application $application, array $options = array())
    {
        $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
        $description = new ApplicationDescription($application, $describedNamespace);
        $commands = array();

        foreach ($description->getCommands() as $command) {
            $commands[] = $this->getCommandData($command);
        }

        $data = $describedNamespace
            ? array('commands' => $commands, 'namespace' => $describedNamespace)
            : array('commands' => $commands, 'namespaces' => array_values($description->getNamespaces()));

        $this->writeData($data, $options);
    }

    /**
     * Writes data as json.
     *
     * @param array $data
     * @param array $options
     *
     * @return array|string
     */
    private function writeData(array $data, array $options)
    {
        $this->write(json_encode($data, isset($options['json_encoding']) ? $options['json_encoding'] : 0));
    }

    /**
     * @param InputArgument $argument
     *
     * @return array
     */
    private function getInputArgumentData(InputArgument $argument)
    {
        return array(
            'name' => $argument->getName(),
            'is_required' => $argument->isRequired(),
            'is_array' => $argument->isArray(),
            'description' => $argument->getDescription(),
            'default' => $argument->getDefault(),
        );
    }

    /**
     * @param InputOption $option
     *
     * @return array
     */
    private function getInputOptionData(InputOption $option)
    {
        return array(
            'name' => '--'.$option->getName(),
            'shortcut' => $option->getShortcut() ? '-'.implode('|-', explode('|', $option->getShortcut())) : '',
            'accept_value' => $option->acceptValue(),
            'is_value_required' => $option->isValueRequired(),
            'is_multiple' => $option->isArray(),
            'description' => $option->getDescription(),
            'default' => $option->getDefault(),
        );
    }

    /**
     * @param InputDefinition $definition
     *
     * @return array
     */
    private function getInputDefinitionData(InputDefinition $definition)
    {
        $inputArguments = array();
        foreach ($definition->getArguments() as $name => $argument) {
            $inputArguments[$name] = $this->getInputArgumentData($argument);
        }

        $inputOptions = array();
        foreach ($definition->getOptions() as $name => $option) {
            $inputOptions[$name] = $this->getInputOptionData($option);
        }

        return array('arguments' => $inputArguments, 'options' => $inputOptions);
    }

    /**
     * @param Command $command
     *
     * @return array
     */
    private function getCommandData(Command $command)
    {
        $command->getSynopsis();
        $command->mergeApplicationDefinition(false);

        return array(
            'name' => $command->getName(),
            'usage' => $command->getSynopsis(),
            'description' => $command->getDescription(),
            'help' => $command->getProcessedHelp(),
            'aliases' => $command->getAliases(),
            'definition' => $this->getInputDefinitionData($command->getNativeDefinition()),
        );
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Descriptor;

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;

/**
 * XML descriptor.
 *
 * @author Jean-François Simon <contact@jfsimon.fr>
 *
 * @internal
 */
class XmlDescriptor extends Descriptor
{
    /**
     * @param InputDefinition $definition
     *
     * @return \DOMDocument
     */
    public function getInputDefinitionDocument(InputDefinition $definition)
    {
        $dom = new \DOMDocument('1.0', 'UTF-8');
        $dom->appendChild($definitionXML = $dom->createElement('definition'));

        $definitionXML->appendChild($argumentsXML = $dom->createElement('arguments'));
        foreach ($definition->getArguments() as $argument) {
            $this->appendDocument($argumentsXML, $this->getInputArgumentDocument($argument));
        }

        $definitionXML->appendChild($optionsXML = $dom->createElement('options'));
        foreach ($definition->getOptions() as $option) {
            $this->appendDocument($optionsXML, $this->getInputOptionDocument($option));
        }

        return $dom;
    }

    /**
     * @param Command $command
     *
     * @return \DOMDocument
     */
    public function getCommandDocument(Command $command)
    {
        $dom = new \DOMDocument('1.0', 'UTF-8');
        $dom->appendChild($commandXML = $dom->createElement('command'));

        $command->getSynopsis();
        $command->mergeApplicationDefinition(false);

        $commandXML->setAttribute('id', $command->getName());
        $commandXML->setAttribute('name', $command->getName());

        $commandXML->appendChild($usageXML = $dom->createElement('usage'));
        $usageXML->appendChild($dom->createTextNode(sprintf($command->getSynopsis(), '')));

        $commandXML->appendChild($descriptionXML = $dom->createElement('description'));
        $descriptionXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $command->getDescription())));

        $commandXML->appendChild($helpXML = $dom->createElement('help'));
        $helpXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $command->getProcessedHelp())));

        $commandXML->appendChild($aliasesXML = $dom->createElement('aliases'));
        foreach ($command->getAliases() as $alias) {
            $aliasesXML->appendChild($aliasXML = $dom->createElement('alias'));
            $aliasXML->appendChild($dom->createTextNode($alias));
        }

        $definitionXML = $this->getInputDefinitionDocument($command->getNativeDefinition());
        $this->appendDocument($commandXML, $definitionXML->getElementsByTagName('definition')->item(0));

        return $dom;
    }

    /**
     * @param Application $application
     * @param string|null $namespace
     *
     * @return \DOMDocument
     */
    public function getApplicationDocument(Application $application, $namespace = null)
    {
        $dom = new \DOMDocument('1.0', 'UTF-8');
        $dom->appendChild($rootXml = $dom->createElement('symfony'));

        if ($application->getName() !== 'UNKNOWN') {
            $rootXml->setAttribute('name', $application->getName());
            if ($application->getVersion() !== 'UNKNOWN') {
                $rootXml->setAttribute('version', $application->getVersion());
            }
        }

        $rootXml->appendChild($commandsXML = $dom->createElement('commands'));

        $description = new ApplicationDescription($application, $namespace);

        if ($namespace) {
            $commandsXML->setAttribute('namespace', $namespace);
        }

        foreach ($description->getCommands() as $command) {
            $this->appendDocument($commandsXML, $this->getCommandDocument($command));
        }

        if (!$namespace) {
            $rootXml->appendChild($namespacesXML = $dom->createElement('namespaces'));

            foreach ($description->getNamespaces() as $namespaceDescription) {
                $namespacesXML->appendChild($namespaceArrayXML = $dom->createElement('namespace'));
                $namespaceArrayXML->setAttribute('id', $namespaceDescription['id']);

                foreach ($namespaceDescription['commands'] as $name) {
                    $namespaceArrayXML->appendChild($commandXML = $dom->createElement('command'));
                    $commandXML->appendChild($dom->createTextNode($name));
                }
            }
        }

        return $dom;
    }

    /**
     * {@inheritdoc}
     */
    protected function describeInputArgument(InputArgument $argument, array $options = array())
    {
        $this->writeDocument($this->getInputArgumentDocument($argument));
    }

    /**
     * {@inheritdoc}
     */
    protected function describeInputOption(InputOption $option, array $options = array())
    {
        $this->writeDocument($this->getInputOptionDocument($option));
    }

    /**
     * {@inheritdoc}
     */
    protected function describeInputDefinition(InputDefinition $definition, array $options = array())
    {
        $this->writeDocument($this->getInputDefinitionDocument($definition));
    }

    /**
     * {@inheritdoc}
     */
    protected function describeCommand(Command $command, array $options = array())
    {
        $this->writeDocument($this->getCommandDocument($command));
    }

    /**
     * {@inheritdoc}
     */
    protected function describeApplication(Application $application, array $options = array())
    {
        $this->writeDocument($this->getApplicationDocument($application, isset($options['namespace']) ? $options['namespace'] : null));
    }

    /**
     * Appends document children to parent node.
     *
     * @param \DOMNode $parentNode
     * @param \DOMNode $importedParent
     */
    private function appendDocument(\DOMNode $parentNode, \DOMNode $importedParent)
    {
        foreach ($importedParent->childNodes as $childNode) {
            $parentNode->appendChild($parentNode->ownerDocument->importNode($childNode, true));
        }
    }

    /**
     * Writes DOM document.
     *
     * @param \DOMDocument $dom
     *
     * @return \DOMDocument|string
     */
    private function writeDocument(\DOMDocument $dom)
    {
        $dom->formatOutput = true;
        $this->write($dom->saveXML());
    }

    /**
     * @param InputArgument $argument
     *
     * @return \DOMDocument
     */
    private function getInputArgumentDocument(InputArgument $argument)
    {
        $dom = new \DOMDocument('1.0', 'UTF-8');

        $dom->appendChild($objectXML = $dom->createElement('argument'));
        $objectXML->setAttribute('name', $argument->getName());
        $objectXML->setAttribute('is_required', $argument->isRequired() ? 1 : 0);
        $objectXML->setAttribute('is_array', $argument->isArray() ? 1 : 0);
        $objectXML->appendChild($descriptionXML = $dom->createElement('description'));
        $descriptionXML->appendChild($dom->createTextNode($argument->getDescription()));

        $objectXML->appendChild($defaultsXML = $dom->createElement('defaults'));
        $defaults = is_array($argument->getDefault()) ? $argument->getDefault() : (is_bool($argument->getDefault()) ? array(var_export($argument->getDefault(), true)) : ($argument->getDefault() ? array($argument->getDefault()) : array()));
        foreach ($defaults as $default) {
            $defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
            $defaultXML->appendChild($dom->createTextNode($default));
        }

        return $dom;
    }

    /**
     * @param InputOption $option
     *
     * @return \DOMDocument
     */
    private function getInputOptionDocument(InputOption $option)
    {
        $dom = new \DOMDocument('1.0', 'UTF-8');

        $dom->appendChild($objectXML = $dom->createElement('option'));
        $objectXML->setAttribute('name', '--'.$option->getName());
        $pos = strpos($option->getShortcut(), '|');
        if (false !== $pos) {
            $objectXML->setAttribute('shortcut', '-'.substr($option->getShortcut(), 0, $pos));
            $objectXML->setAttribute('shortcuts', '-'.implode('|-', explode('|', $option->getShortcut())));
        } else {
            $objectXML->setAttribute('shortcut', $option->getShortcut() ? '-'.$option->getShortcut() : '');
        }
        $objectXML->setAttribute('accept_value', $option->acceptValue() ? 1 : 0);
        $objectXML->setAttribute('is_value_required', $option->isValueRequired() ? 1 : 0);
        $objectXML->setAttribute('is_multiple', $option->isArray() ? 1 : 0);
        $objectXML->appendChild($descriptionXML = $dom->createElement('description'));
        $descriptionXML->appendChild($dom->createTextNode($option->getDescription()));

        if ($option->acceptValue()) {
            $defaults = is_array($option->getDefault()) ? $option->getDefault() : (is_bool($option->getDefault()) ? array(var_export($option->getDefault(), true)) : ($option->getDefault() ? array($option->getDefault()) : array()));
            $objectXML->appendChild($defaultsXML = $dom->createElement('defaults'));

            if (!empty($defaults)) {
                foreach ($defaults as $default) {
                    $defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
                    $defaultXML->appendChild($dom->createTextNode($default));
                }
            }
        }

        return $dom;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Descriptor;

use Symfony\Component\Console\Output\OutputInterface;

/**
 * Descriptor interface.
 *
 * @author Jean-François Simon <contact@jfsimon.fr>
 */
interface DescriptorInterface
{
    /**
     * Describes an InputArgument instance.
     *
     * @param OutputInterface $output
     * @param object          $object
     * @param array           $options
     */
    public function describe(OutputInterface $output, $object, array $options = array());
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Descriptor;

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;

/**
 * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
 *
 * @internal
 */
class ApplicationDescription
{
    const GLOBAL_NAMESPACE = '_global';

    /**
     * @var Application
     */
    private $application;

    /**
     * @var null|string
     */
    private $namespace;

    /**
     * @var array
     */
    private $namespaces;

    /**
     * @var Command[]
     */
    private $commands;

    /**
     * @var Command[]
     */
    private $aliases;

    /**
     * Constructor.
     *
     * @param Application $application
     * @param string|null $namespace
     */
    public function __construct(Application $application, $namespace = null)
    {
        $this->application = $application;
        $this->namespace = $namespace;
    }

    /**
     * @return array
     */
    public function getNamespaces()
    {
        if (null === $this->namespaces) {
            $this->inspectApplication();
        }

        return $this->namespaces;
    }

    /**
     * @return Command[]
     */
    public function getCommands()
    {
        if (null === $this->commands) {
            $this->inspectApplication();
        }

        return $this->commands;
    }

    /**
     * @param string $name
     *
     * @return Command
     *
     * @throws \InvalidArgumentException
     */
    public function getCommand($name)
    {
        if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) {
            throw new \InvalidArgumentException(sprintf('Command %s does not exist.', $name));
        }

        return isset($this->commands[$name]) ? $this->commands[$name] : $this->aliases[$name];
    }

    private function inspectApplication()
    {
        $this->commands = array();
        $this->namespaces = array();

        $all = $this->application->all($this->namespace ? $this->application->findNamespace($this->namespace) : null);
        foreach ($this->sortCommands($all) as $namespace => $commands) {
            $names = array();

            /** @var Command $command */
            foreach ($commands as $name => $command) {
                if (!$command->getName()) {
                    continue;
                }

                if ($command->getName() === $name) {
                    $this->commands[$name] = $command;
                } else {
                    $this->aliases[$name] = $command;
                }

                $names[] = $name;
            }

            $this->namespaces[$namespace] = array('id' => $namespace, 'commands' => $names);
        }
    }

    /**
     * @param array $commands
     *
     * @return array
     */
    private function sortCommands(array $commands)
    {
        $namespacedCommands = array();
        foreach ($commands as $name => $command) {
            $key = $this->application->extractNamespace($name, 1);
            if (!$key) {
                $key = '_global';
            }

            $namespacedCommands[$key][$name] = $command;
        }
        ksort($namespacedCommands);

        foreach ($namespacedCommands as &$commandsSet) {
            ksort($commandsSet);
        }
        // unset reference to keep scope clear
        unset($commandsSet);

        return $namespacedCommands;
    }
}
MZ����@���	�!�L�!This program cannot be run in DOS mode.

$�,�;�B�;�B�;�B�2�מ:�B�2��-�B�2�ƞ9�B�2�ў?�B�a9�8�B�;�C��B�2�Ȟ:�B�2�֞:�B�2�Ӟ:�B�Rich;�B�PEL�MoO�	
8 @`?�@��"P@ Pp!8!@ �.text	
 `.rdata�	 
@@.data�0@�.rsrc @@@.reloc�P"@Bj$��@�xj�� @�e���E�PV� @�EЃ�PV� @�M�X @�e��E�P�5H @�L @YY�5\ @�E�P�5` @�D @YY��P @�M���M�T @3��H�;
0@u���h�@��l3@�$40@�5h3@�40@h$0@h(0@h 0@�� @���00@��}j�Y�jh"@�3ۉ]�d��p�]俀3@SVW�0 @;�t;�u3�F�u��h��4 @��3�F�|3@;�u
j�\Y�;�|3@��u,�5|3@h� @h� @�YY��t�E����������5<0@�|3@;�uh� @h� @�lYY�|3@9]�uSW�8 @9�3@th�3@�Y��t
SjS��3@�$0@�
� @��5$0@�5(0@�5 0@�������80@9,0@u7P�� @�E��	�M�PQ�YYËe�E�80@3�9,0@uP�h @9<0@u�� @�E������80@�øMZf9@t3��M�<@��@�8PEu��H��t��uՃ��v�3�9����xtv�3�9������j�,0@�p @j��l @YY��3@��3@�� @�
t3@��� @�
p3@��� @��x3@�V��=0@uh�@�� @Y�g�=0@�u	j��� @Y3���{�����U���(�H1@�
D1@�@1@�<1@�581@�=41@f�`1@f�
T1@f�01@f�,1@f�%(1@f�-$1@��X1@�E�L1@�E�P1@�E�\1@������0@�P1@�L0@�@0@	��D0@�0@������0@������ @��0@j�?Yj�  @h!@�$ @�=�0@uj�Yh	��( @P�, @�Ë�U��E��8csm�u*�xu$�@= �t=!�t="�t=@�u��3�]�hH@�  @3��%� @jh("@�b�5�3@�5� @��Y�E��u�u�� @Y�gj�Y�e��5�3@�։E�5�3@��YY�E�E�P�E�P�u�5l @��YP�U�E�u�֣�3@�u�փ���3@�E������	�E���j�YË�U��u�N��������YH]Ë�V��!@��!@W��;�s���t�Ѓ�;�r�_^Ë�V�"@�"@W��;�s���t�Ѓ�;�r�_^�%� @���̋�U��M�MZf9t3�]ËA<��8PEu�3ҹf9H�‹�]�����������̋�U��E�H<��ASV�q3�W�D��v�}�H;�r	�X�;�r
B��(;�r�3�_^[]������������̋�U��j�hH"@he@d�P��SVW�0@1E�3�P�E�d��e��E�h@�*�������tU�E-@Ph@�P�������t;�@$���Ѓ��E������M�d�
Y_^[��]ËE��3�=��‹�Ëe��E�����3��M�d�
Y_^[��]��%� @�%� @��he@d�5�D$�l$�l$+�SVW�0@1E�3�P�e�u��E��E������E��E�d�ËM�d�
Y__^[��]Q�U��u�u�u�uh�@h0@����]�Vhh3�V������t
VVVVV����^�3��U����0@�e��e�SW�N�@����;�t
��t	�У0@�`V�E�P�< @�u�3u�� @3� @3� @3�E�P� @�E�3E�3�;�u�O�@����u����50@�։50@^_[��%t @�%x @�%| @�%� @�%� @�%� @�%� @�%� @�%� @Pd�5�D$+d$SVW�(��0@3�P�E�u��E������E�d�ËM�d�
Y__^[��]QËM�3���������M�%T @�T$�B�J�3�����J�3�����l"@�s����#�#�#�)r)b)H)4))�(�(�(�(�(�(�)�#�$%�%&d&�&�$('�'�'�'�'(((6(�'H(Z(t(�('''�'�'l'^'R'F'>'>(0'�'�)�@W@�@�MoOl�!�@0@�0@bad allocationH0@�!@RSDSь���J�!���LZc:\users\seld\documents\visual studio 2010\Projects\hiddeninp\Release\hiddeninp.pdbe������������@@�����������:@������������@�@�����@"�d"@�"�# $#�&D H#(h �#�#�#�)r)b)H)4))�(�(�(�(�(�(�)�#�$%�%&d&�&�$('�'�'�'�'(((6(�'H(Z(t(�('''�'�'l'^'R'F'>'>(0'�'�)�GetConsoleMode�SetConsoleMode;GetStdHandleKERNEL32.dll??$?6DU?$char_traits@D@std@@V?$allocator@D@1@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@@Z�?cout@std@@3V?$basic_ostream@DU?$char_traits@D@std@@@1@AJ?cin@std@@3V?$basic_istream@DU?$char_traits@D@std@@@1@A�??$getline@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@YAAAV?$basic_istream@DU?$char_traits@D@std@@@0@AAV10@AAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@@Z??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@P6AAAV01@AAV01@@Z@Z_??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ{??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ�?endl@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@1@AAV21@@ZMSVCP90.dll_amsg_exit�__getmainargs,_cexit|_exitf_XcptFilter�exit�__initenv_initterm_initterm_e<_configthreadlocale�__setusermatherr_adjust_fdiv�__p__commode�__p__fmodej_encode_pointer�__set_app_typeK_crt_debugger_hookC?terminate@@YAXXZMSVCR90.dll�_unlock�__dllonexitv_lock_onexit`_decode_pointers_except_handler4_common_invoke_watson?_controlfp_s�InterlockedExchange!Sleep�InterlockedCompareExchange-TerminateProcess�GetCurrentProcess>UnhandledExceptionFilterSetUnhandledExceptionFilter�IsDebuggerPresentTQueryPerformanceCounterfGetTickCount�GetCurrentThreadId�GetCurrentProcessIdOGetSystemTimeAsFileTimes__CxxFrameHandler3N�@���D������������$!@ �8�P�h�	�	��@(��CV�(4VS_VERSION_INFO���StringFileInfob040904b0�QFileDescriptionReads from stdin without leaking info to the terminal and outputs back to stdout6FileVersion1, 0, 0, 08InternalNamehiddeninputPLegalCopyrightJordi Boggiano - 2012HOriginalFilenamehiddeninput.exe:
ProductNameHidden Input:ProductVersion1, 0, 0, 0DVarFileInfo$Translation	�<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
    </dependentAssembly>
  </dependency>
</assembly>PAPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDINGPADDINGXXPADDING@00!0/080F0L0T0^0d0n0{0�0�0�0�0�0�0�0�0�0�0�0�0�01#1-1@1J1O1T1v1{1�1�1�1�1�1�1�1�1�1�1�1�1�1�12"2*23292A2M2_2j2p2�2�2�2�2�2�2�2�2�2�2�2333%303N3T3Z3`3f3l3s3z3�3�3�3�3�3�3�3�3�3�3�3�3�3�3�3�34444%4;4B4�4�4�4�4�4�4�4�4�4�45!5^5c5�5�5�5H6M6_6}6�6�677
7*7w7|7�7�7�7�78
88=8E8P8V8\8b8h8n8t8z8�8�8�89 $�0�0�01 1t1x12 2@2\2`2h2t200Copyright (c) 2004-2015 Fabien Potencier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Output;

/**
 * ConsoleOutputInterface is the interface implemented by ConsoleOutput class.
 * This adds information about stderr output stream.
 *
 * @author Dariusz Górecki <darek.krk@gmail.com>
 */
interface ConsoleOutputInterface extends OutputInterface
{
    /**
     * Gets the OutputInterface for errors.
     *
     * @return OutputInterface
     */
    public function getErrorOutput();

    /**
     * Sets the OutputInterface used for errors.
     *
     * @param OutputInterface $error
     */
    public function setErrorOutput(OutputInterface $error);
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Output;

use Symfony\Component\Console\Formatter\OutputFormatterInterface;

/**
 * StreamOutput writes the output to a given stream.
 *
 * Usage:
 *
 * $output = new StreamOutput(fopen('php://stdout', 'w'));
 *
 * As `StreamOutput` can use any stream, you can also use a file:
 *
 * $output = new StreamOutput(fopen('/path/to/output.log', 'a', false));
 *
 * @author Fabien Potencier <fabien@symfony.com>
 *
 * @api
 */
class StreamOutput extends Output
{
    private $stream;

    /**
     * Constructor.
     *
     * @param mixed                         $stream    A stream resource
     * @param int                           $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface)
     * @param bool|null                     $decorated Whether to decorate messages (null for auto-guessing)
     * @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter)
     *
     * @throws \InvalidArgumentException When first argument is not a real stream
     *
     * @api
     */
    public function __construct($stream, $verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
    {
        if (!is_resource($stream) || 'stream' !== get_resource_type($stream)) {
            throw new \InvalidArgumentException('The StreamOutput class needs a stream as its first argument.');
        }

        $this->stream = $stream;

        if (null === $decorated) {
            $decorated = $this->hasColorSupport();
        }

        parent::__construct($verbosity, $decorated, $formatter);
    }

    /**
     * Gets the stream attached to this StreamOutput instance.
     *
     * @return resource A stream resource
     */
    public function getStream()
    {
        return $this->stream;
    }

    /**
     * {@inheritdoc}
     */
    protected function doWrite($message, $newline)
    {
        if (false === @fwrite($this->stream, $message.($newline ? PHP_EOL : ''))) {
            // should never happen
            throw new \RuntimeException('Unable to write output.');
        }

        fflush($this->stream);
    }

    /**
     * Returns true if the stream supports colorization.
     *
     * Colorization is disabled if not supported by the stream:
     *
     *  -  Windows without Ansicon and ConEmu
     *  -  non tty consoles
     *
     * @return bool true if the stream supports colorization, false otherwise
     */
    protected function hasColorSupport()
    {
        if (DIRECTORY_SEPARATOR === '\\') {
            return false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI');
        }

        return function_exists('posix_isatty') && @posix_isatty($this->stream);
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Output;

use Symfony\Component\Console\Formatter\OutputFormatterInterface;

/**
 * OutputInterface is the interface implemented by all Output classes.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 *
 * @api
 */
interface OutputInterface
{
    const VERBOSITY_QUIET = 0;
    const VERBOSITY_NORMAL = 1;
    const VERBOSITY_VERBOSE = 2;
    const VERBOSITY_VERY_VERBOSE = 3;
    const VERBOSITY_DEBUG = 4;

    const OUTPUT_NORMAL = 0;
    const OUTPUT_RAW = 1;
    const OUTPUT_PLAIN = 2;

    /**
     * Writes a message to the output.
     *
     * @param string|array $messages The message as an array of lines or a single string
     * @param bool         $newline  Whether to add a newline
     * @param int          $type     The type of output (one of the OUTPUT constants)
     *
     * @throws \InvalidArgumentException When unknown output type is given
     *
     * @api
     */
    public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL);

    /**
     * Writes a message to the output and adds a newline at the end.
     *
     * @param string|array $messages The message as an array of lines of a single string
     * @param int          $type     The type of output (one of the OUTPUT constants)
     *
     * @throws \InvalidArgumentException When unknown output type is given
     *
     * @api
     */
    public function writeln($messages, $type = self::OUTPUT_NORMAL);

    /**
     * Sets the verbosity of the output.
     *
     * @param int $level The level of verbosity (one of the VERBOSITY constants)
     *
     * @api
     */
    public function setVerbosity($level);

    /**
     * Gets the current verbosity of the output.
     *
     * @return int The current level of verbosity (one of the VERBOSITY constants)
     *
     * @api
     */
    public function getVerbosity();

    /**
     * Sets the decorated flag.
     *
     * @param bool $decorated Whether to decorate the messages
     *
     * @api
     */
    public function setDecorated($decorated);

    /**
     * Gets the decorated flag.
     *
     * @return bool true if the output will decorate messages, false otherwise
     *
     * @api
     */
    public function isDecorated();

    /**
     * Sets output formatter.
     *
     * @param OutputFormatterInterface $formatter
     *
     * @api
     */
    public function setFormatter(OutputFormatterInterface $formatter);

    /**
     * Returns current output formatter instance.
     *
     * @return OutputFormatterInterface
     *
     * @api
     */
    public function getFormatter();
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Output;

use Symfony\Component\Console\Formatter\OutputFormatterInterface;
use Symfony\Component\Console\Formatter\OutputFormatter;

/**
 * Base class for output classes.
 *
 * There are five levels of verbosity:
 *
 *  * normal: no option passed (normal output)
 *  * verbose: -v (more output)
 *  * very verbose: -vv (highly extended output)
 *  * debug: -vvv (all debug output)
 *  * quiet: -q (no output)
 *
 * @author Fabien Potencier <fabien@symfony.com>
 *
 * @api
 */
abstract class Output implements OutputInterface
{
    private $verbosity;
    private $formatter;

    /**
     * Constructor.
     *
     * @param int                           $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface)
     * @param bool                          $decorated Whether to decorate messages
     * @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter)
     *
     * @api
     */
    public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = false, OutputFormatterInterface $formatter = null)
    {
        $this->verbosity = null === $verbosity ? self::VERBOSITY_NORMAL : $verbosity;
        $this->formatter = $formatter ?: new OutputFormatter();
        $this->formatter->setDecorated($decorated);
    }

    /**
     * {@inheritdoc}
     */
    public function setFormatter(OutputFormatterInterface $formatter)
    {
        $this->formatter = $formatter;
    }

    /**
     * {@inheritdoc}
     */
    public function getFormatter()
    {
        return $this->formatter;
    }

    /**
     * {@inheritdoc}
     */
    public function setDecorated($decorated)
    {
        $this->formatter->setDecorated($decorated);
    }

    /**
     * {@inheritdoc}
     */
    public function isDecorated()
    {
        return $this->formatter->isDecorated();
    }

    /**
     * {@inheritdoc}
     */
    public function setVerbosity($level)
    {
        $this->verbosity = (int) $level;
    }

    /**
     * {@inheritdoc}
     */
    public function getVerbosity()
    {
        return $this->verbosity;
    }

    public function isQuiet()
    {
        return self::VERBOSITY_QUIET === $this->verbosity;
    }

    public function isVerbose()
    {
        return self::VERBOSITY_VERBOSE <= $this->verbosity;
    }

    public function isVeryVerbose()
    {
        return self::VERBOSITY_VERY_VERBOSE <= $this->verbosity;
    }

    public function isDebug()
    {
        return self::VERBOSITY_DEBUG <= $this->verbosity;
    }

    /**
     * {@inheritdoc}
     */
    public function writeln($messages, $type = self::OUTPUT_NORMAL)
    {
        $this->write($messages, true, $type);
    }

    /**
     * {@inheritdoc}
     */
    public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL)
    {
        if (self::VERBOSITY_QUIET === $this->verbosity) {
            return;
        }

        $messages = (array) $messages;

        foreach ($messages as $message) {
            switch ($type) {
                case OutputInterface::OUTPUT_NORMAL:
                    $message = $this->formatter->format($message);
                    break;
                case OutputInterface::OUTPUT_RAW:
                    break;
                case OutputInterface::OUTPUT_PLAIN:
                    $message = strip_tags($this->formatter->format($message));
                    break;
                default:
                    throw new \InvalidArgumentException(sprintf('Unknown output type given (%s)', $type));
            }

            $this->doWrite($message, $newline);
        }
    }

    /**
     * Writes a message to the output.
     *
     * @param string $message A message to write to the output
     * @param bool   $newline Whether to add a newline or not
     */
    abstract protected function doWrite($message, $newline);
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Output;

use Symfony\Component\Console\Formatter\OutputFormatterInterface;

/**
 * ConsoleOutput is the default class for all CLI output. It uses STDOUT.
 *
 * This class is a convenient wrapper around `StreamOutput`.
 *
 *     $output = new ConsoleOutput();
 *
 * This is equivalent to:
 *
 *     $output = new StreamOutput(fopen('php://stdout', 'w'));
 *
 * @author Fabien Potencier <fabien@symfony.com>
 *
 * @api
 */
class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
{
    /**
     * @var StreamOutput
     */
    private $stderr;

    /**
     * Constructor.
     *
     * @param int                           $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface)
     * @param bool|null                     $decorated Whether to decorate messages (null for auto-guessing)
     * @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter)
     *
     * @api
     */
    public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
    {
        parent::__construct($this->openOutputStream(), $verbosity, $decorated, $formatter);

        $this->stderr = new StreamOutput($this->openErrorStream(), $verbosity, $decorated, $this->getFormatter());
    }

    /**
     * {@inheritdoc}
     */
    public function setDecorated($decorated)
    {
        parent::setDecorated($decorated);
        $this->stderr->setDecorated($decorated);
    }

    /**
     * {@inheritdoc}
     */
    public function setFormatter(OutputFormatterInterface $formatter)
    {
        parent::setFormatter($formatter);
        $this->stderr->setFormatter($formatter);
    }

    /**
     * {@inheritdoc}
     */
    public function setVerbosity($level)
    {
        parent::setVerbosity($level);
        $this->stderr->setVerbosity($level);
    }

    /**
     * {@inheritdoc}
     */
    public function getErrorOutput()
    {
        return $this->stderr;
    }

    /**
     * {@inheritdoc}
     */
    public function setErrorOutput(OutputInterface $error)
    {
        $this->stderr = $error;
    }

    /**
     * Returns true if current environment supports writing console output to
     * STDOUT.
     *
     * @return bool
     */
    protected function hasStdoutSupport()
    {
        return false === $this->isRunningOS400();
    }

    /**
     * Returns true if current environment supports writing console output to
     * STDERR.
     *
     * @return bool
     */
    protected function hasStderrSupport()
    {
        return false === $this->isRunningOS400();
    }

    /**
     * Checks if current executing environment is IBM iSeries (OS400), which
     * doesn't properly convert character-encodings between ASCII to EBCDIC.
     *
     * @return bool
     */
    private function isRunningOS400()
    {
        return 'OS400' === php_uname('s');
    }

    /**
     * @return resource
     */
    private function openOutputStream()
    {
        $outputStream = $this->hasStdoutSupport() ? 'php://stdout' : 'php://output';

        return @fopen($outputStream, 'w') ?: fopen('php://output', 'w');
    }

    /**
     * @return resource
     */
    private function openErrorStream()
    {
        $errorStream = $this->hasStderrSupport() ? 'php://stderr' : 'php://output';

        return fopen($errorStream, 'w');
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Output;

use Symfony\Component\Console\Formatter\OutputFormatter;
use Symfony\Component\Console\Formatter\OutputFormatterInterface;

/**
 * NullOutput suppresses all output.
 *
 *     $output = new NullOutput();
 *
 * @author Fabien Potencier <fabien@symfony.com>
 * @author Tobias Schultze <http://tobion.de>
 *
 * @api
 */
class NullOutput implements OutputInterface
{
    /**
     * {@inheritdoc}
     */
    public function setFormatter(OutputFormatterInterface $formatter)
    {
        // do nothing
    }

    /**
     * {@inheritdoc}
     */
    public function getFormatter()
    {
        // to comply with the interface we must return a OutputFormatterInterface
        return new OutputFormatter();
    }

    /**
     * {@inheritdoc}
     */
    public function setDecorated($decorated)
    {
        // do nothing
    }

    /**
     * {@inheritdoc}
     */
    public function isDecorated()
    {
        return false;
    }

    /**
     * {@inheritdoc}
     */
    public function setVerbosity($level)
    {
        // do nothing
    }

    /**
     * {@inheritdoc}
     */
    public function getVerbosity()
    {
        return self::VERBOSITY_QUIET;
    }

    public function isQuiet()
    {
        return true;
    }

    public function isVerbose()
    {
        return false;
    }

    public function isVeryVerbose()
    {
        return false;
    }

    public function isDebug()
    {
        return false;
    }

    /**
     * {@inheritdoc}
     */
    public function writeln($messages, $type = self::OUTPUT_NORMAL)
    {
        // do nothing
    }

    /**
     * {@inheritdoc}
     */
    public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL)
    {
        // do nothing
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Output;

/**
 * @author Jean-François Simon <contact@jfsimon.fr>
 */
class BufferedOutput extends Output
{
    /**
     * @var string
     */
    private $buffer = '';

    /**
     * Empties buffer and returns its content.
     *
     * @return string
     */
    public function fetch()
    {
        $content = $this->buffer;
        $this->buffer = '';

        return $content;
    }

    /**
     * {@inheritdoc}
     */
    protected function doWrite($message, $newline)
    {
        $this->buffer .= $message;

        if ($newline) {
            $this->buffer .= "\n";
        }
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console;

/**
 * Contains all events dispatched by an Application.
 *
 * @author Francesco Levorato <git@flevour.net>
 */
final class ConsoleEvents
{
    /**
     * The COMMAND event allows you to attach listeners before any command is
     * executed by the console. It also allows you to modify the command, input and output
     * before they are handled to the command.
     *
     * The event listener method receives a Symfony\Component\Console\Event\ConsoleCommandEvent
     * instance.
     *
     * @Event
     *
     * @var string
     */
    const COMMAND = 'console.command';

    /**
     * The TERMINATE event allows you to attach listeners after a command is
     * executed by the console.
     *
     * The event listener method receives a Symfony\Component\Console\Event\ConsoleTerminateEvent
     * instance.
     *
     * @Event
     *
     * @var string
     */
    const TERMINATE = 'console.terminate';

    /**
     * The EXCEPTION event occurs when an uncaught exception appears.
     *
     * This event allows you to deal with the exception or
     * to modify the thrown exception. The event listener method receives
     * a Symfony\Component\Console\Event\ConsoleExceptionEvent
     * instance.
     *
     * @Event
     *
     * @var string
     */
    const EXCEPTION = 'console.exception';
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console;

use Symfony\Component\Console\Descriptor\TextDescriptor;
use Symfony\Component\Console\Descriptor\XmlDescriptor;
use Symfony\Component\Console\Helper\DebugFormatterHelper;
use Symfony\Component\Console\Helper\ProcessHelper;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputAwareInterface;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Command\HelpCommand;
use Symfony\Component\Console\Command\ListCommand;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Helper\FormatterHelper;
use Symfony\Component\Console\Helper\DialogHelper;
use Symfony\Component\Console\Helper\ProgressHelper;
use Symfony\Component\Console\Helper\TableHelper;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
 * An Application is the container for a collection of commands.
 *
 * It is the main entry point of a Console application.
 *
 * This class is optimized for a standard CLI environment.
 *
 * Usage:
 *
 *     $app = new Application('myapp', '1.0 (stable)');
 *     $app->add(new SimpleCommand());
 *     $app->run();
 *
 * @author Fabien Potencier <fabien@symfony.com>
 *
 * @api
 */
class Application
{
    private $commands = array();
    private $wantHelps = false;
    private $runningCommand;
    private $name;
    private $version;
    private $catchExceptions = true;
    private $autoExit = true;
    private $definition;
    private $helperSet;
    private $dispatcher;
    private $terminalDimensions;
    private $defaultCommand;

    /**
     * Constructor.
     *
     * @param string $name    The name of the application
     * @param string $version The version of the application
     *
     * @api
     */
    public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
    {
        $this->name = $name;
        $this->version = $version;
        $this->defaultCommand = 'list';
        $this->helperSet = $this->getDefaultHelperSet();
        $this->definition = $this->getDefaultInputDefinition();

        foreach ($this->getDefaultCommands() as $command) {
            $this->add($command);
        }
    }

    public function setDispatcher(EventDispatcherInterface $dispatcher)
    {
        $this->dispatcher = $dispatcher;
    }

    /**
     * Runs the current application.
     *
     * @param InputInterface  $input  An Input instance
     * @param OutputInterface $output An Output instance
     *
     * @return int 0 if everything went fine, or an error code
     *
     * @throws \Exception When doRun returns Exception
     *
     * @api
     */
    public function run(InputInterface $input = null, OutputInterface $output = null)
    {
        if (null === $input) {
            $input = new ArgvInput();
        }

        if (null === $output) {
            $output = new ConsoleOutput();
        }

        $this->configureIO($input, $output);

        try {
            $exitCode = $this->doRun($input, $output);
        } catch (\Exception $e) {
            if (!$this->catchExceptions) {
                throw $e;
            }

            if ($output instanceof ConsoleOutputInterface) {
                $this->renderException($e, $output->getErrorOutput());
            } else {
                $this->renderException($e, $output);
            }

            $exitCode = $e->getCode();
            if (is_numeric($exitCode)) {
                $exitCode = (int) $exitCode;
                if (0 === $exitCode) {
                    $exitCode = 1;
                }
            } else {
                $exitCode = 1;
            }
        }

        if ($this->autoExit) {
            if ($exitCode > 255) {
                $exitCode = 255;
            }

            exit($exitCode);
        }

        return $exitCode;
    }

    /**
     * Runs the current application.
     *
     * @param InputInterface  $input  An Input instance
     * @param OutputInterface $output An Output instance
     *
     * @return int 0 if everything went fine, or an error code
     */
    public function doRun(InputInterface $input, OutputInterface $output)
    {
        if (true === $input->hasParameterOption(array('--version', '-V'))) {
            $output->writeln($this->getLongVersion());

            return 0;
        }

        $name = $this->getCommandName($input);
        if (true === $input->hasParameterOption(array('--help', '-h'))) {
            if (!$name) {
                $name = 'help';
                $input = new ArrayInput(array('command' => 'help'));
            } else {
                $this->wantHelps = true;
            }
        }

        if (!$name) {
            $name = $this->defaultCommand;
            $input = new ArrayInput(array('command' => $this->defaultCommand));
        }

        // the command name MUST be the first element of the input
        $command = $this->find($name);

        $this->runningCommand = $command;
        $exitCode = $this->doRunCommand($command, $input, $output);
        $this->runningCommand = null;

        return $exitCode;
    }

    /**
     * Set a helper set to be used with the command.
     *
     * @param HelperSet $helperSet The helper set
     *
     * @api
     */
    public function setHelperSet(HelperSet $helperSet)
    {
        $this->helperSet = $helperSet;
    }

    /**
     * Get the helper set associated with the command.
     *
     * @return HelperSet The HelperSet instance associated with this command
     *
     * @api
     */
    public function getHelperSet()
    {
        return $this->helperSet;
    }

    /**
     * Set an input definition set to be used with this application.
     *
     * @param InputDefinition $definition The input definition
     *
     * @api
     */
    public function setDefinition(InputDefinition $definition)
    {
        $this->definition = $definition;
    }

    /**
     * Gets the InputDefinition related to this Application.
     *
     * @return InputDefinition The InputDefinition instance
     */
    public function getDefinition()
    {
        return $this->definition;
    }

    /**
     * Gets the help message.
     *
     * @return string A help message.
     */
    public function getHelp()
    {
        return $this->getLongVersion();
    }

    /**
     * Sets whether to catch exceptions or not during commands execution.
     *
     * @param bool $boolean Whether to catch exceptions or not during commands execution
     *
     * @api
     */
    public function setCatchExceptions($boolean)
    {
        $this->catchExceptions = (bool) $boolean;
    }

    /**
     * Sets whether to automatically exit after a command execution or not.
     *
     * @param bool $boolean Whether to automatically exit after a command execution or not
     *
     * @api
     */
    public function setAutoExit($boolean)
    {
        $this->autoExit = (bool) $boolean;
    }

    /**
     * Gets the name of the application.
     *
     * @return string The application name
     *
     * @api
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Sets the application name.
     *
     * @param string $name The application name
     *
     * @api
     */
    public function setName($name)
    {
        $this->name = $name;
    }

    /**
     * Gets the application version.
     *
     * @return string The application version
     *
     * @api
     */
    public function getVersion()
    {
        return $this->version;
    }

    /**
     * Sets the application version.
     *
     * @param string $version The application version
     *
     * @api
     */
    public function setVersion($version)
    {
        $this->version = $version;
    }

    /**
     * Returns the long version of the application.
     *
     * @return string The long application version
     *
     * @api
     */
    public function getLongVersion()
    {
        if ('UNKNOWN' !== $this->getName() && 'UNKNOWN' !== $this->getVersion()) {
            return sprintf('<info>%s</info> version <comment>%s</comment>', $this->getName(), $this->getVersion());
        }

        return '<info>Console Tool</info>';
    }

    /**
     * Registers a new command.
     *
     * @param string $name The command name
     *
     * @return Command The newly created command
     *
     * @api
     */
    public function register($name)
    {
        return $this->add(new Command($name));
    }

    /**
     * Adds an array of command objects.
     *
     * @param Command[] $commands An array of commands
     *
     * @api
     */
    public function addCommands(array $commands)
    {
        foreach ($commands as $command) {
            $this->add($command);
        }
    }

    /**
     * Adds a command object.
     *
     * If a command with the same name already exists, it will be overridden.
     *
     * @param Command $command A Command object
     *
     * @return Command The registered command
     *
     * @api
     */
    public function add(Command $command)
    {
        $command->setApplication($this);

        if (!$command->isEnabled()) {
            $command->setApplication(null);

            return;
        }

        if (null === $command->getDefinition()) {
            throw new \LogicException(sprintf('Command class "%s" is not correctly initialized. You probably forgot to call the parent constructor.', get_class($command)));
        }

        $this->commands[$command->getName()] = $command;

        foreach ($command->getAliases() as $alias) {
            $this->commands[$alias] = $command;
        }

        return $command;
    }

    /**
     * Returns a registered command by name or alias.
     *
     * @param string $name The command name or alias
     *
     * @return Command A Command object
     *
     * @throws \InvalidArgumentException When command name given does not exist
     *
     * @api
     */
    public function get($name)
    {
        if (!isset($this->commands[$name])) {
            throw new \InvalidArgumentException(sprintf('The command "%s" does not exist.', $name));
        }

        $command = $this->commands[$name];

        if ($this->wantHelps) {
            $this->wantHelps = false;

            $helpCommand = $this->get('help');
            $helpCommand->setCommand($command);

            return $helpCommand;
        }

        return $command;
    }

    /**
     * Returns true if the command exists, false otherwise.
     *
     * @param string $name The command name or alias
     *
     * @return bool true if the command exists, false otherwise
     *
     * @api
     */
    public function has($name)
    {
        return isset($this->commands[$name]);
    }

    /**
     * Returns an array of all unique namespaces used by currently registered commands.
     *
     * It does not returns the global namespace which always exists.
     *
     * @return array An array of namespaces
     */
    public function getNamespaces()
    {
        $namespaces = array();
        foreach ($this->commands as $command) {
            $namespaces = array_merge($namespaces, $this->extractAllNamespaces($command->getName()));

            foreach ($command->getAliases() as $alias) {
                $namespaces = array_merge($namespaces, $this->extractAllNamespaces($alias));
            }
        }

        return array_values(array_unique(array_filter($namespaces)));
    }

    /**
     * Finds a registered namespace by a name or an abbreviation.
     *
     * @param string $namespace A namespace or abbreviation to search for
     *
     * @return string A registered namespace
     *
     * @throws \InvalidArgumentException When namespace is incorrect or ambiguous
     */
    public function findNamespace($namespace)
    {
        $allNamespaces = $this->getNamespaces();
        $expr = preg_replace_callback('{([^:]+|)}', function ($matches) { return preg_quote($matches[1]).'[^:]*'; }, $namespace);
        $namespaces = preg_grep('{^'.$expr.'}', $allNamespaces);

        if (empty($namespaces)) {
            $message = sprintf('There are no commands defined in the "%s" namespace.', $namespace);

            if ($alternatives = $this->findAlternatives($namespace, $allNamespaces)) {
                if (1 == count($alternatives)) {
                    $message .= "\n\nDid you mean this?\n    ";
                } else {
                    $message .= "\n\nDid you mean one of these?\n    ";
                }

                $message .= implode("\n    ", $alternatives);
            }

            throw new \InvalidArgumentException($message);
        }

        $exact = in_array($namespace, $namespaces, true);
        if (count($namespaces) > 1 && !$exact) {
            throw new \InvalidArgumentException(sprintf('The namespace "%s" is ambiguous (%s).', $namespace, $this->getAbbreviationSuggestions(array_values($namespaces))));
        }

        return $exact ? $namespace : reset($namespaces);
    }

    /**
     * Finds a command by name or alias.
     *
     * Contrary to get, this command tries to find the best
     * match if you give it an abbreviation of a name or alias.
     *
     * @param string $name A command name or a command alias
     *
     * @return Command A Command instance
     *
     * @throws \InvalidArgumentException When command name is incorrect or ambiguous
     *
     * @api
     */
    public function find($name)
    {
        $allCommands = array_keys($this->commands);
        $expr = preg_replace_callback('{([^:]+|)}', function ($matches) { return preg_quote($matches[1]).'[^:]*'; }, $name);
        $commands = preg_grep('{^'.$expr.'}', $allCommands);

        if (empty($commands) || count(preg_grep('{^'.$expr.'$}', $commands)) < 1) {
            if (false !== $pos = strrpos($name, ':')) {
                // check if a namespace exists and contains commands
                $this->findNamespace(substr($name, 0, $pos));
            }

            $message = sprintf('Command "%s" is not defined.', $name);

            if ($alternatives = $this->findAlternatives($name, $allCommands)) {
                if (1 == count($alternatives)) {
                    $message .= "\n\nDid you mean this?\n    ";
                } else {
                    $message .= "\n\nDid you mean one of these?\n    ";
                }
                $message .= implode("\n    ", $alternatives);
            }

            throw new \InvalidArgumentException($message);
        }

        // filter out aliases for commands which are already on the list
        if (count($commands) > 1) {
            $commandList = $this->commands;
            $commands = array_filter($commands, function ($nameOrAlias) use ($commandList, $commands) {
                $commandName = $commandList[$nameOrAlias]->getName();

                return $commandName === $nameOrAlias || !in_array($commandName, $commands);
            });
        }

        $exact = in_array($name, $commands, true);
        if (count($commands) > 1 && !$exact) {
            $suggestions = $this->getAbbreviationSuggestions(array_values($commands));

            throw new \InvalidArgumentException(sprintf('Command "%s" is ambiguous (%s).', $name, $suggestions));
        }

        return $this->get($exact ? $name : reset($commands));
    }

    /**
     * Gets the commands (registered in the given namespace if provided).
     *
     * The array keys are the full names and the values the command instances.
     *
     * @param string $namespace A namespace name
     *
     * @return Command[] An array of Command instances
     *
     * @api
     */
    public function all($namespace = null)
    {
        if (null === $namespace) {
            return $this->commands;
        }

        $commands = array();
        foreach ($this->commands as $name => $command) {
            if ($namespace === $this->extractNamespace($name, substr_count($namespace, ':') + 1)) {
                $commands[$name] = $command;
            }
        }

        return $commands;
    }

    /**
     * Returns an array of possible abbreviations given a set of names.
     *
     * @param array $names An array of names
     *
     * @return array An array of abbreviations
     */
    public static function getAbbreviations($names)
    {
        $abbrevs = array();
        foreach ($names as $name) {
            for ($len = strlen($name); $len > 0; --$len) {
                $abbrev = substr($name, 0, $len);
                $abbrevs[$abbrev][] = $name;
            }
        }

        return $abbrevs;
    }

    /**
     * Returns a text representation of the Application.
     *
     * @param string $namespace An optional namespace name
     * @param bool   $raw       Whether to return raw command list
     *
     * @return string A string representing the Application
     *
     * @deprecated Deprecated since version 2.3, to be removed in 3.0.
     */
    public function asText($namespace = null, $raw = false)
    {
        $descriptor = new TextDescriptor();
        $output = new BufferedOutput(BufferedOutput::VERBOSITY_NORMAL, !$raw);
        $descriptor->describe($output, $this, array('namespace' => $namespace, 'raw_output' => true));

        return $output->fetch();
    }

    /**
     * Returns an XML representation of the Application.
     *
     * @param string $namespace An optional namespace name
     * @param bool   $asDom     Whether to return a DOM or an XML string
     *
     * @return string|\DOMDocument An XML string representing the Application
     *
     * @deprecated Deprecated since version 2.3, to be removed in 3.0.
     */
    public function asXml($namespace = null, $asDom = false)
    {
        $descriptor = new XmlDescriptor();

        if ($asDom) {
            return $descriptor->getApplicationDocument($this, $namespace);
        }

        $output = new BufferedOutput();
        $descriptor->describe($output, $this, array('namespace' => $namespace));

        return $output->fetch();
    }

    /**
     * Renders a caught exception.
     *
     * @param \Exception      $e      An exception instance
     * @param OutputInterface $output An OutputInterface instance
     */
    public function renderException($e, $output)
    {
        do {
            $title = sprintf('  [%s]  ', get_class($e));

            $len = $this->stringWidth($title);

            $width = $this->getTerminalWidth() ? $this->getTerminalWidth() - 1 : PHP_INT_MAX;
            // HHVM only accepts 32 bits integer in str_split, even when PHP_INT_MAX is a 64 bit integer: https://github.com/facebook/hhvm/issues/1327
            if (defined('HHVM_VERSION') && $width > 1 << 31) {
                $width = 1 << 31;
            }
            $formatter = $output->getFormatter();
            $lines = array();
            foreach (preg_split('/\r?\n/', $e->getMessage()) as $line) {
                foreach ($this->splitStringByWidth($line, $width - 4) as $line) {
                    // pre-format lines to get the right string length
                    $lineLength = $this->stringWidth(preg_replace('/\[[^m]*m/', '', $formatter->format($line))) + 4;
                    $lines[] = array($line, $lineLength);

                    $len = max($lineLength, $len);
                }
            }

            $messages = array('', '');
            $messages[] = $emptyLine = $formatter->format(sprintf('<error>%s</error>', str_repeat(' ', $len)));
            $messages[] = $formatter->format(sprintf('<error>%s%s</error>', $title, str_repeat(' ', max(0, $len - $this->stringWidth($title)))));
            foreach ($lines as $line) {
                $messages[] = $formatter->format(sprintf('<error>  %s  %s</error>', $line[0], str_repeat(' ', $len - $line[1])));
            }
            $messages[] = $emptyLine;
            $messages[] = '';
            $messages[] = '';

            $output->writeln($messages, OutputInterface::OUTPUT_RAW);

            if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
                $output->writeln('<comment>Exception trace:</comment>');

                // exception related properties
                $trace = $e->getTrace();
                array_unshift($trace, array(
                    'function' => '',
                    'file' => $e->getFile() !== null ? $e->getFile() : 'n/a',
                    'line' => $e->getLine() !== null ? $e->getLine() : 'n/a',
                    'args' => array(),
                ));

                for ($i = 0, $count = count($trace); $i < $count; ++$i) {
                    $class = isset($trace[$i]['class']) ? $trace[$i]['class'] : '';
                    $type = isset($trace[$i]['type']) ? $trace[$i]['type'] : '';
                    $function = $trace[$i]['function'];
                    $file = isset($trace[$i]['file']) ? $trace[$i]['file'] : 'n/a';
                    $line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a';

                    $output->writeln(sprintf(' %s%s%s() at <info>%s:%s</info>', $class, $type, $function, $file, $line));
                }

                $output->writeln('');
                $output->writeln('');
            }
        } while ($e = $e->getPrevious());

        if (null !== $this->runningCommand) {
            $output->writeln(sprintf('<info>%s</info>', sprintf($this->runningCommand->getSynopsis(), $this->getName())));
            $output->writeln('');
            $output->writeln('');
        }
    }

    /**
     * Tries to figure out the terminal width in which this application runs.
     *
     * @return int|null
     */
    protected function getTerminalWidth()
    {
        $dimensions = $this->getTerminalDimensions();

        return $dimensions[0];
    }

    /**
     * Tries to figure out the terminal height in which this application runs.
     *
     * @return int|null
     */
    protected function getTerminalHeight()
    {
        $dimensions = $this->getTerminalDimensions();

        return $dimensions[1];
    }

    /**
     * Tries to figure out the terminal dimensions based on the current environment.
     *
     * @return array Array containing width and height
     */
    public function getTerminalDimensions()
    {
        if ($this->terminalDimensions) {
            return $this->terminalDimensions;
        }

        if ('\\' === DIRECTORY_SEPARATOR) {
            // extract [w, H] from "wxh (WxH)"
            if (preg_match('/^(\d+)x\d+ \(\d+x(\d+)\)$/', trim(getenv('ANSICON')), $matches)) {
                return array((int) $matches[1], (int) $matches[2]);
            }
            // extract [w, h] from "wxh"
            if (preg_match('/^(\d+)x(\d+)$/', $this->getConsoleMode(), $matches)) {
                return array((int) $matches[1], (int) $matches[2]);
            }
        }

        if ($sttyString = $this->getSttyColumns()) {
            // extract [w, h] from "rows h; columns w;"
            if (preg_match('/rows.(\d+);.columns.(\d+);/i', $sttyString, $matches)) {
                return array((int) $matches[2], (int) $matches[1]);
            }
            // extract [w, h] from "; h rows; w columns"
            if (preg_match('/;.(\d+).rows;.(\d+).columns/i', $sttyString, $matches)) {
                return array((int) $matches[2], (int) $matches[1]);
            }
        }

        return array(null, null);
    }

    /**
     * Sets terminal dimensions.
     *
     * Can be useful to force terminal dimensions for functional tests.
     *
     * @param int $width  The width
     * @param int $height The height
     *
     * @return Application The current application
     */
    public function setTerminalDimensions($width, $height)
    {
        $this->terminalDimensions = array($width, $height);

        return $this;
    }

    /**
     * Configures the input and output instances based on the user arguments and options.
     *
     * @param InputInterface  $input  An InputInterface instance
     * @param OutputInterface $output An OutputInterface instance
     */
    protected function configureIO(InputInterface $input, OutputInterface $output)
    {
        if (true === $input->hasParameterOption(array('--ansi'))) {
            $output->setDecorated(true);
        } elseif (true === $input->hasParameterOption(array('--no-ansi'))) {
            $output->setDecorated(false);
        }

        if (true === $input->hasParameterOption(array('--no-interaction', '-n'))) {
            $input->setInteractive(false);
        } elseif (function_exists('posix_isatty') && $this->getHelperSet()->has('question')) {
            $inputStream = $this->getHelperSet()->get('question')->getInputStream();
            if (!@posix_isatty($inputStream) && false === getenv('SHELL_INTERACTIVE')) {
                $input->setInteractive(false);
            }
        }

        if (true === $input->hasParameterOption(array('--quiet', '-q'))) {
            $output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
        } else {
            if ($input->hasParameterOption('-vvv') || $input->hasParameterOption('--verbose=3') || $input->getParameterOption('--verbose') === 3) {
                $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG);
            } elseif ($input->hasParameterOption('-vv') || $input->hasParameterOption('--verbose=2') || $input->getParameterOption('--verbose') === 2) {
                $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE);
            } elseif ($input->hasParameterOption('-v') || $input->hasParameterOption('--verbose=1') || $input->hasParameterOption('--verbose') || $input->getParameterOption('--verbose')) {
                $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
            }
        }
    }

    /**
     * Runs the current command.
     *
     * If an event dispatcher has been attached to the application,
     * events are also dispatched during the life-cycle of the command.
     *
     * @param Command         $command A Command instance
     * @param InputInterface  $input   An Input instance
     * @param OutputInterface $output  An Output instance
     *
     * @return int 0 if everything went fine, or an error code
     *
     * @throws \Exception when the command being run threw an exception
     */
    protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
    {
        foreach ($command->getHelperSet() as $helper) {
            if ($helper instanceof InputAwareInterface) {
                $helper->setInput($input);
            }
        }

        if (null === $this->dispatcher) {
            return $command->run($input, $output);
        }

        $event = new ConsoleCommandEvent($command, $input, $output);
        $this->dispatcher->dispatch(ConsoleEvents::COMMAND, $event);

        if ($event->commandShouldRun()) {
            try {
                $exitCode = $command->run($input, $output);
            } catch (\Exception $e) {
                $event = new ConsoleTerminateEvent($command, $input, $output, $e->getCode());
                $this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);

                $event = new ConsoleExceptionEvent($command, $input, $output, $e, $event->getExitCode());
                $this->dispatcher->dispatch(ConsoleEvents::EXCEPTION, $event);

                throw $event->getException();
            }
        } else {
            $exitCode = ConsoleCommandEvent::RETURN_CODE_DISABLED;
        }

        $event = new ConsoleTerminateEvent($command, $input, $output, $exitCode);
        $this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);

        return $event->getExitCode();
    }

    /**
     * Gets the name of the command based on input.
     *
     * @param InputInterface $input The input interface
     *
     * @return string The command name
     */
    protected function getCommandName(InputInterface $input)
    {
        return $input->getFirstArgument();
    }

    /**
     * Gets the default input definition.
     *
     * @return InputDefinition An InputDefinition instance
     */
    protected function getDefaultInputDefinition()
    {
        return new InputDefinition(array(
            new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),

            new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message'),
            new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message'),
            new InputOption('--verbose', '-v|vv|vvv', InputOption::VALUE_NONE, 'Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug'),
            new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this application version'),
            new InputOption('--ansi', '', InputOption::VALUE_NONE, 'Force ANSI output'),
            new InputOption('--no-ansi', '', InputOption::VALUE_NONE, 'Disable ANSI output'),
            new InputOption('--no-interaction', '-n', InputOption::VALUE_NONE, 'Do not ask any interactive question'),
        ));
    }

    /**
     * Gets the default commands that should always be available.
     *
     * @return Command[] An array of default Command instances
     */
    protected function getDefaultCommands()
    {
        return array(new HelpCommand(), new ListCommand());
    }

    /**
     * Gets the default helper set with the helpers that should always be available.
     *
     * @return HelperSet A HelperSet instance
     */
    protected function getDefaultHelperSet()
    {
        return new HelperSet(array(
            new FormatterHelper(),
            new DialogHelper(),
            new ProgressHelper(),
            new TableHelper(),
            new DebugFormatterHelper(),
            new ProcessHelper(),
            new QuestionHelper(),
        ));
    }

    /**
     * Runs and parses stty -a if it's available, suppressing any error output.
     *
     * @return string
     */
    private function getSttyColumns()
    {
        if (!function_exists('proc_open')) {
            return;
        }

        $descriptorspec = array(1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
        $process = proc_open('stty -a | grep columns', $descriptorspec, $pipes, null, null, array('suppress_errors' => true));
        if (is_resource($process)) {
            $info = stream_get_contents($pipes[1]);
            fclose($pipes[1]);
            fclose($pipes[2]);
            proc_close($process);

            return $info;
        }
    }

    /**
     * Runs and parses mode CON if it's available, suppressing any error output.
     *
     * @return string <width>x<height> or null if it could not be parsed
     */
    private function getConsoleMode()
    {
        if (!function_exists('proc_open')) {
            return;
        }

        $descriptorspec = array(1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
        $process = proc_open('mode CON', $descriptorspec, $pipes, null, null, array('suppress_errors' => true));
        if (is_resource($process)) {
            $info = stream_get_contents($pipes[1]);
            fclose($pipes[1]);
            fclose($pipes[2]);
            proc_close($process);

            if (preg_match('/--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n/', $info, $matches)) {
                return $matches[2].'x'.$matches[1];
            }
        }
    }

    /**
     * Returns abbreviated suggestions in string format.
     *
     * @param array $abbrevs Abbreviated suggestions to convert
     *
     * @return string A formatted string of abbreviated suggestions
     */
    private function getAbbreviationSuggestions($abbrevs)
    {
        return sprintf('%s, %s%s', $abbrevs[0], $abbrevs[1], count($abbrevs) > 2 ? sprintf(' and %d more', count($abbrevs) - 2) : '');
    }

    /**
     * Returns the namespace part of the command name.
     *
     * This method is not part of public API and should not be used directly.
     *
     * @param string $name  The full name of the command
     * @param string $limit The maximum number of parts of the namespace
     *
     * @return string The namespace of the command
     */
    public function extractNamespace($name, $limit = null)
    {
        $parts = explode(':', $name);
        array_pop($parts);

        return implode(':', null === $limit ? $parts : array_slice($parts, 0, $limit));
    }

    /**
     * Finds alternative of $name among $collection,
     * if nothing is found in $collection, try in $abbrevs.
     *
     * @param string             $name       The string
     * @param array|\Traversable $collection The collection
     *
     * @return array A sorted array of similar string
     */
    private function findAlternatives($name, $collection)
    {
        $threshold = 1e3;
        $alternatives = array();

        $collectionParts = array();
        foreach ($collection as $item) {
            $collectionParts[$item] = explode(':', $item);
        }

        foreach (explode(':', $name) as $i => $subname) {
            foreach ($collectionParts as $collectionName => $parts) {
                $exists = isset($alternatives[$collectionName]);
                if (!isset($parts[$i]) && $exists) {
                    $alternatives[$collectionName] += $threshold;
                    continue;
                } elseif (!isset($parts[$i])) {
                    continue;
                }

                $lev = levenshtein($subname, $parts[$i]);
                if ($lev <= strlen($subname) / 3 || '' !== $subname && false !== strpos($parts[$i], $subname)) {
                    $alternatives[$collectionName] = $exists ? $alternatives[$collectionName] + $lev : $lev;
                } elseif ($exists) {
                    $alternatives[$collectionName] += $threshold;
                }
            }
        }

        foreach ($collection as $item) {
            $lev = levenshtein($name, $item);
            if ($lev <= strlen($name) / 3 || false !== strpos($item, $name)) {
                $alternatives[$item] = isset($alternatives[$item]) ? $alternatives[$item] - $lev : $lev;
            }
        }

        $alternatives = array_filter($alternatives, function ($lev) use ($threshold) { return $lev < 2 * $threshold; });
        asort($alternatives);

        return array_keys($alternatives);
    }

    /**
     * Sets the default Command name.
     *
     * @param string $commandName The Command name
     */
    public function setDefaultCommand($commandName)
    {
        $this->defaultCommand = $commandName;
    }

    private function stringWidth($string)
    {
        if (!function_exists('mb_strwidth')) {
            return strlen($string);
        }

        if (false === $encoding = mb_detect_encoding($string)) {
            return strlen($string);
        }

        return mb_strwidth($string, $encoding);
    }

    private function splitStringByWidth($string, $width)
    {
        // str_split is not suitable for multi-byte characters, we should use preg_split to get char array properly.
        // additionally, array_slice() is not enough as some character has doubled width.
        // we need a function to split string not by character count but by string width

        if (!function_exists('mb_strwidth')) {
            return str_split($string, $width);
        }

        if (false === $encoding = mb_detect_encoding($string)) {
            return str_split($string, $width);
        }

        $utf8String = mb_convert_encoding($string, 'utf8', $encoding);
        $lines = array();
        $line = '';
        foreach (preg_split('//u', $utf8String) as $char) {
            // test if $char could be appended to current line
            if (mb_strwidth($line.$char, 'utf8') <= $width) {
                $line .= $char;
                continue;
            }
            // if not, push current line to array and make new line
            $lines[] = str_pad($line, $width);
            $line = $char;
        }
        if ('' !== $line) {
            $lines[] = count($lines) ? str_pad($line, $width) : $line;
        }

        mb_convert_variables($encoding, 'utf8', $lines);

        return $lines;
    }

    /**
     * Returns all namespaces of the command name.
     *
     * @param string $name The full name of the command
     *
     * @return array The namespaces of the command
     */
    private function extractAllNamespaces($name)
    {
        // -1 as third argument is needed to skip the command short name when exploding
        $parts = explode(':', $name, -1);
        $namespaces = array();

        foreach ($parts as $part) {
            if (count($namespaces)) {
                $namespaces[] = end($namespaces).':'.$part;
            } else {
                $namespaces[] = $part;
            }
        }

        return $namespaces;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Tester;

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\StreamOutput;

/**
 * Eases the testing of console applications.
 *
 * When testing an application, don't forget to disable the auto exit flag:
 *
 *     $application = new Application();
 *     $application->setAutoExit(false);
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class ApplicationTester
{
    private $application;
    private $input;
    private $output;
    private $statusCode;

    /**
     * Constructor.
     *
     * @param Application $application An Application instance to test.
     */
    public function __construct(Application $application)
    {
        $this->application = $application;
    }

    /**
     * Executes the application.
     *
     * Available options:
     *
     *  * interactive: Sets the input interactive flag
     *  * decorated:   Sets the output decorated flag
     *  * verbosity:   Sets the output verbosity flag
     *
     * @param array $input   An array of arguments and options
     * @param array $options An array of options
     *
     * @return int The command exit code
     */
    public function run(array $input, $options = array())
    {
        $this->input = new ArrayInput($input);
        if (isset($options['interactive'])) {
            $this->input->setInteractive($options['interactive']);
        }

        $this->output = new StreamOutput(fopen('php://memory', 'w', false));
        if (isset($options['decorated'])) {
            $this->output->setDecorated($options['decorated']);
        }
        if (isset($options['verbosity'])) {
            $this->output->setVerbosity($options['verbosity']);
        }

        return $this->statusCode = $this->application->run($this->input, $this->output);
    }

    /**
     * Gets the display returned by the last execution of the application.
     *
     * @param bool $normalize Whether to normalize end of lines to \n or not
     *
     * @return string The display
     */
    public function getDisplay($normalize = false)
    {
        rewind($this->output->getStream());

        $display = stream_get_contents($this->output->getStream());

        if ($normalize) {
            $display = str_replace(PHP_EOL, "\n", $display);
        }

        return $display;
    }

    /**
     * Gets the input instance used by the last execution of the application.
     *
     * @return InputInterface The current input instance
     */
    public function getInput()
    {
        return $this->input;
    }

    /**
     * Gets the output instance used by the last execution of the application.
     *
     * @return OutputInterface The current output instance
     */
    public function getOutput()
    {
        return $this->output;
    }

    /**
     * Gets the status code returned by the last execution of the application.
     *
     * @return int The status code
     */
    public function getStatusCode()
    {
        return $this->statusCode;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Tester;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\StreamOutput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * Eases the testing of console commands.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class CommandTester
{
    private $command;
    private $input;
    private $output;
    private $statusCode;

    /**
     * Constructor.
     *
     * @param Command $command A Command instance to test.
     */
    public function __construct(Command $command)
    {
        $this->command = $command;
    }

    /**
     * Executes the command.
     *
     * Available execution options:
     *
     *  * interactive: Sets the input interactive flag
     *  * decorated:   Sets the output decorated flag
     *  * verbosity:   Sets the output verbosity flag
     *
     * @param array $input   An array of command arguments and options
     * @param array $options An array of execution options
     *
     * @return int The command exit code
     */
    public function execute(array $input, array $options = array())
    {
        // set the command name automatically if the application requires
        // this argument and no command name was passed
        if (!isset($input['command'])
            && (null !== $application = $this->command->getApplication())
            && $application->getDefinition()->hasArgument('command')
        ) {
            $input = array_merge(array('command' => $this->command->getName()), $input);
        }

        $this->input = new ArrayInput($input);
        if (isset($options['interactive'])) {
            $this->input->setInteractive($options['interactive']);
        }

        $this->output = new StreamOutput(fopen('php://memory', 'w', false));
        if (isset($options['decorated'])) {
            $this->output->setDecorated($options['decorated']);
        }
        if (isset($options['verbosity'])) {
            $this->output->setVerbosity($options['verbosity']);
        }

        return $this->statusCode = $this->command->run($this->input, $this->output);
    }

    /**
     * Gets the display returned by the last execution of the command.
     *
     * @param bool $normalize Whether to normalize end of lines to \n or not
     *
     * @return string The display
     */
    public function getDisplay($normalize = false)
    {
        rewind($this->output->getStream());

        $display = stream_get_contents($this->output->getStream());

        if ($normalize) {
            $display = str_replace(PHP_EOL, "\n", $display);
        }

        return $display;
    }

    /**
     * Gets the input instance used by the last execution of the command.
     *
     * @return InputInterface The current input instance
     */
    public function getInput()
    {
        return $this->input;
    }

    /**
     * Gets the output instance used by the last execution of the command.
     *
     * @return OutputInterface The current output instance
     */
    public function getOutput()
    {
        return $this->output;
    }

    /**
     * Gets the status code returned by the last execution of the application.
     *
     * @return int The status code
     */
    public function getStatusCode()
    {
        return $this->statusCode;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console;

use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Process\ProcessBuilder;
use Symfony\Component\Process\PhpExecutableFinder;

/**
 * A Shell wraps an Application to add shell capabilities to it.
 *
 * Support for history and completion only works with a PHP compiled
 * with readline support (either --with-readline or --with-libedit)
 *
 * @author Fabien Potencier <fabien@symfony.com>
 * @author Martin Hasoň <martin.hason@gmail.com>
 */
class Shell
{
    private $application;
    private $history;
    private $output;
    private $hasReadline;
    private $processIsolation = false;

    /**
     * Constructor.
     *
     * If there is no readline support for the current PHP executable
     * a \RuntimeException exception is thrown.
     *
     * @param Application $application An application instance
     */
    public function __construct(Application $application)
    {
        $this->hasReadline = function_exists('readline');
        $this->application = $application;
        $this->history = getenv('HOME').'/.history_'.$application->getName();
        $this->output = new ConsoleOutput();
    }

    /**
     * Runs the shell.
     */
    public function run()
    {
        $this->application->setAutoExit(false);
        $this->application->setCatchExceptions(true);

        if ($this->hasReadline) {
            readline_read_history($this->history);
            readline_completion_function(array($this, 'autocompleter'));
        }

        $this->output->writeln($this->getHeader());
        $php = null;
        if ($this->processIsolation) {
            $finder = new PhpExecutableFinder();
            $php = $finder->find();
            $this->output->writeln(<<<EOF
<info>Running with process isolation, you should consider this:</info>
  * each command is executed as separate process,
  * commands don't support interactivity, all params must be passed explicitly,
  * commands output is not colorized.

EOF
            );
        }

        while (true) {
            $command = $this->readline();

            if (false === $command) {
                $this->output->writeln("\n");

                break;
            }

            if ($this->hasReadline) {
                readline_add_history($command);
                readline_write_history($this->history);
            }

            if ($this->processIsolation) {
                $pb = new ProcessBuilder();

                $process = $pb
                    ->add($php)
                    ->add($_SERVER['argv'][0])
                    ->add($command)
                    ->inheritEnvironmentVariables(true)
                    ->getProcess()
                ;

                $output = $this->output;
                $process->run(function ($type, $data) use ($output) {
                    $output->writeln($data);
                });

                $ret = $process->getExitCode();
            } else {
                $ret = $this->application->run(new StringInput($command), $this->output);
            }

            if (0 !== $ret) {
                $this->output->writeln(sprintf('<error>The command terminated with an error status (%s)</error>', $ret));
            }
        }
    }

    /**
     * Returns the shell header.
     *
     * @return string The header string
     */
    protected function getHeader()
    {
        return <<<EOF

Welcome to the <info>{$this->application->getName()}</info> shell (<comment>{$this->application->getVersion()}</comment>).

At the prompt, type <comment>help</comment> for some help,
or <comment>list</comment> to get a list of available commands.

To exit the shell, type <comment>^D</comment>.

EOF;
    }

    /**
     * Renders a prompt.
     *
     * @return string The prompt
     */
    protected function getPrompt()
    {
        // using the formatter here is required when using readline
        return $this->output->getFormatter()->format($this->application->getName().' > ');
    }

    protected function getOutput()
    {
        return $this->output;
    }

    protected function getApplication()
    {
        return $this->application;
    }

    /**
     * Tries to return autocompletion for the current entered text.
     *
     * @param string $text The last segment of the entered text
     *
     * @return bool|array A list of guessed strings or true
     */
    private function autocompleter($text)
    {
        $info = readline_info();
        $text = substr($info['line_buffer'], 0, $info['end']);

        if ($info['point'] !== $info['end']) {
            return true;
        }

        // task name?
        if (false === strpos($text, ' ') || !$text) {
            return array_keys($this->application->all());
        }

        // options and arguments?
        try {
            $command = $this->application->find(substr($text, 0, strpos($text, ' ')));
        } catch (\Exception $e) {
            return true;
        }

        $list = array('--help');
        foreach ($command->getDefinition()->getOptions() as $option) {
            $list[] = '--'.$option->getName();
        }

        return $list;
    }

    /**
     * Reads a single line from standard input.
     *
     * @return string The single line from standard input
     */
    private function readline()
    {
        if ($this->hasReadline) {
            $line = readline($this->getPrompt());
        } else {
            $this->output->write($this->getPrompt());
            $line = fgets(STDIN, 1024);
            $line = (false === $line || '' === $line) ? false : rtrim($line);
        }

        return $line;
    }

    public function getProcessIsolation()
    {
        return $this->processIsolation;
    }

    public function setProcessIsolation($processIsolation)
    {
        $this->processIsolation = (bool) $processIsolation;

        if ($this->processIsolation && !class_exists('Symfony\\Component\\Process\\Process')) {
            throw new \RuntimeException('Unable to isolate processes as the Symfony Process Component is not installed.');
        }
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Question;

/**
 * Represents a Question.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class Question
{
    private $question;
    private $attempts;
    private $hidden = false;
    private $hiddenFallback = true;
    private $autocompleterValues;
    private $validator;
    private $default;
    private $normalizer;

    /**
     * Constructor.
     *
     * @param string $question The question to ask to the user
     * @param mixed  $default  The default answer to return if the user enters nothing
     */
    public function __construct($question, $default = null)
    {
        $this->question = $question;
        $this->default = $default;
    }

    /**
     * Returns the question.
     *
     * @return string
     */
    public function getQuestion()
    {
        return $this->question;
    }

    /**
     * Returns the default answer.
     *
     * @return mixed
     */
    public function getDefault()
    {
        return $this->default;
    }

    /**
     * Returns whether the user response must be hidden.
     *
     * @return bool
     */
    public function isHidden()
    {
        return $this->hidden;
    }

    /**
     * Sets whether the user response must be hidden or not.
     *
     * @param bool $hidden
     *
     * @return Question The current instance
     *
     * @throws \LogicException In case the autocompleter is also used
     */
    public function setHidden($hidden)
    {
        if ($this->autocompleterValues) {
            throw new \LogicException('A hidden question cannot use the autocompleter.');
        }

        $this->hidden = (bool) $hidden;

        return $this;
    }

    /**
     * In case the response can not be hidden, whether to fallback on non-hidden question or not.
     *
     * @return bool
     */
    public function isHiddenFallback()
    {
        return $this->hiddenFallback;
    }

    /**
     * Sets whether to fallback on non-hidden question if the response can not be hidden.
     *
     * @param bool $fallback
     *
     * @return Question The current instance
     */
    public function setHiddenFallback($fallback)
    {
        $this->hiddenFallback = (bool) $fallback;

        return $this;
    }

    /**
     * Gets values for the autocompleter.
     *
     * @return null|array|\Traversable
     */
    public function getAutocompleterValues()
    {
        return $this->autocompleterValues;
    }

    /**
     * Sets values for the autocompleter.
     *
     * @param null|array|\Traversable $values
     *
     * @return Question The current instance
     *
     * @throws \InvalidArgumentException
     * @throws \LogicException
     */
    public function setAutocompleterValues($values)
    {
        if (null !== $values && !is_array($values)) {
            if (!$values instanceof \Traversable || $values instanceof \Countable) {
                throw new \InvalidArgumentException('Autocompleter values can be either an array, `null` or an object implementing both `Countable` and `Traversable` interfaces.');
            }
        }

        if ($this->hidden) {
            throw new \LogicException('A hidden question cannot use the autocompleter.');
        }

        $this->autocompleterValues = $values;

        return $this;
    }

    /**
     * Sets a validator for the question.
     *
     * @param null|callable $validator
     *
     * @return Question The current instance
     */
    public function setValidator($validator)
    {
        $this->validator = $validator;

        return $this;
    }

    /**
     * Gets the validator for the question.
     *
     * @return null|callable
     */
    public function getValidator()
    {
        return $this->validator;
    }

    /**
     * Sets the maximum number of attempts.
     *
     * Null means an unlimited number of attempts.
     *
     * @param null|int $attempts
     *
     * @return Question The current instance
     *
     * @throws \InvalidArgumentException In case the number of attempts is invalid.
     */
    public function setMaxAttempts($attempts)
    {
        if (null !== $attempts && $attempts < 1) {
            throw new \InvalidArgumentException('Maximum number of attempts must be a positive value.');
        }

        $this->attempts = $attempts;

        return $this;
    }

    /**
     * Gets the maximum number of attempts.
     *
     * Null means an unlimited number of attempts.
     *
     * @return null|int
     */
    public function getMaxAttempts()
    {
        return $this->attempts;
    }

    /**
     * Sets a normalizer for the response.
     *
     * The normalizer can be a callable (a string), a closure or a class implementing __invoke.
     *
     * @param string|\Closure $normalizer
     *
     * @return Question The current instance
     */
    public function setNormalizer($normalizer)
    {
        $this->normalizer = $normalizer;

        return $this;
    }

    /**
     * Gets the normalizer for the response.
     *
     * The normalizer can ba a callable (a string), a closure or a class implementing __invoke.
     *
     * @return string|\Closure
     */
    public function getNormalizer()
    {
        return $this->normalizer;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Question;

/**
 * Represents a choice question.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class ChoiceQuestion extends Question
{
    private $choices;
    private $multiselect = false;
    private $prompt = ' > ';
    private $errorMessage = 'Value "%s" is invalid';

    /**
     * Constructor.
     *
     * @param string $question The question to ask to the user
     * @param array  $choices  The list of available choices
     * @param mixed  $default  The default answer to return
     */
    public function __construct($question, array $choices, $default = null)
    {
        parent::__construct($question, $default);

        $this->choices = $choices;
        $this->setValidator($this->getDefaultValidator());
        $this->setAutocompleterValues(array_keys($choices));
    }

    /**
     * Returns available choices.
     *
     * @return array
     */
    public function getChoices()
    {
        return $this->choices;
    }

    /**
     * Sets multiselect option.
     *
     * When multiselect is set to true, multiple choices can be answered.
     *
     * @param bool $multiselect
     *
     * @return ChoiceQuestion The current instance
     */
    public function setMultiselect($multiselect)
    {
        $this->multiselect = $multiselect;
        $this->setValidator($this->getDefaultValidator());

        return $this;
    }

    /**
     * Gets the prompt for choices.
     *
     * @return string
     */
    public function getPrompt()
    {
        return $this->prompt;
    }

    /**
     * Sets the prompt for choices.
     *
     * @param string $prompt
     *
     * @return ChoiceQuestion The current instance
     */
    public function setPrompt($prompt)
    {
        $this->prompt = $prompt;

        return $this;
    }

    /**
     * Sets the error message for invalid values.
     *
     * The error message has a string placeholder (%s) for the invalid value.
     *
     * @param string $errorMessage
     *
     * @return ChoiceQuestion The current instance
     */
    public function setErrorMessage($errorMessage)
    {
        $this->errorMessage = $errorMessage;
        $this->setValidator($this->getDefaultValidator());

        return $this;
    }

    /**
     * Returns the default answer validator.
     *
     * @return callable
     */
    private function getDefaultValidator()
    {
        $choices = $this->choices;
        $errorMessage = $this->errorMessage;
        $multiselect = $this->multiselect;

        return function ($selected) use ($choices, $errorMessage, $multiselect) {
            // Collapse all spaces.
            $selectedChoices = str_replace(' ', '', $selected);

            if ($multiselect) {
                // Check for a separated comma values
                if (!preg_match('/^[a-zA-Z0-9_-]+(?:,[a-zA-Z0-9_-]+)*$/', $selectedChoices, $matches)) {
                    throw new \InvalidArgumentException(sprintf($errorMessage, $selected));
                }
                $selectedChoices = explode(',', $selectedChoices);
            } else {
                $selectedChoices = array($selected);
            }

            $multiselectChoices = array();
            foreach ($selectedChoices as $value) {
                if (empty($choices[$value])) {
                    throw new \InvalidArgumentException(sprintf($errorMessage, $value));
                }

                $multiselectChoices[] = $choices[$value];
            }

            if ($multiselect) {
                return $multiselectChoices;
            }

            return $choices[$selected];
        };
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Question;

/**
 * Represents a yes/no question.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class ConfirmationQuestion extends Question
{
    /**
     * Constructor.
     *
     * @param string $question The question to ask to the user
     * @param bool   $default  The default answer to return, true or false
     */
    public function __construct($question, $default = true)
    {
        parent::__construct($question, (bool) $default);

        $this->setNormalizer($this->getDefaultNormalizer());
    }

    /**
     * Returns the default answer normalizer.
     *
     * @return callable
     */
    private function getDefaultNormalizer()
    {
        $default = $this->getDefault();

        return function ($answer) use ($default) {
            if (is_bool($answer)) {
                return $answer;
            }

            if (false === $default) {
                return $answer && 'y' === strtolower($answer[0]);
            }

            return !$answer || 'y' === strtolower($answer[0]);
        };
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Input;

/**
 * ArrayInput represents an input provided as an array.
 *
 * Usage:
 *
 *     $input = new ArrayInput(array('name' => 'foo', '--bar' => 'foobar'));
 *
 * @author Fabien Potencier <fabien@symfony.com>
 *
 * @api
 */
class ArrayInput extends Input
{
    private $parameters;

    /**
     * Constructor.
     *
     * @param array           $parameters An array of parameters
     * @param InputDefinition $definition A InputDefinition instance
     *
     * @api
     */
    public function __construct(array $parameters, InputDefinition $definition = null)
    {
        $this->parameters = $parameters;

        parent::__construct($definition);
    }

    /**
     * Returns the first argument from the raw parameters (not parsed).
     *
     * @return string The value of the first argument or null otherwise
     */
    public function getFirstArgument()
    {
        foreach ($this->parameters as $key => $value) {
            if ($key && '-' === $key[0]) {
                continue;
            }

            return $value;
        }
    }

    /**
     * Returns true if the raw parameters (not parsed) contain a value.
     *
     * This method is to be used to introspect the input parameters
     * before they have been validated. It must be used carefully.
     *
     * @param string|array $values The values to look for in the raw parameters (can be an array)
     *
     * @return bool true if the value is contained in the raw parameters
     */
    public function hasParameterOption($values)
    {
        $values = (array) $values;

        foreach ($this->parameters as $k => $v) {
            if (!is_int($k)) {
                $v = $k;
            }

            if (in_array($v, $values)) {
                return true;
            }
        }

        return false;
    }

    /**
     * Returns the value of a raw option (not parsed).
     *
     * This method is to be used to introspect the input parameters
     * before they have been validated. It must be used carefully.
     *
     * @param string|array $values  The value(s) to look for in the raw parameters (can be an array)
     * @param mixed        $default The default value to return if no result is found
     *
     * @return mixed The option value
     */
    public function getParameterOption($values, $default = false)
    {
        $values = (array) $values;

        foreach ($this->parameters as $k => $v) {
            if (is_int($k)) {
                if (in_array($v, $values)) {
                    return true;
                }
            } elseif (in_array($k, $values)) {
                return $v;
            }
        }

        return $default;
    }

    /**
     * Returns a stringified representation of the args passed to the command.
     *
     * @return string
     */
    public function __toString()
    {
        $params = array();
        foreach ($this->parameters as $param => $val) {
            if ($param && '-' === $param[0]) {
                $params[] = $param.('' != $val ? '='.$this->escapeToken($val) : '');
            } else {
                $params[] = $this->escapeToken($val);
            }
        }

        return implode(' ', $params);
    }

    /**
     * Processes command line arguments.
     */
    protected function parse()
    {
        foreach ($this->parameters as $key => $value) {
            if (0 === strpos($key, '--')) {
                $this->addLongOption(substr($key, 2), $value);
            } elseif ('-' === $key[0]) {
                $this->addShortOption(substr($key, 1), $value);
            } else {
                $this->addArgument($key, $value);
            }
        }
    }

    /**
     * Adds a short option value.
     *
     * @param string $shortcut The short option key
     * @param mixed  $value    The value for the option
     *
     * @throws \InvalidArgumentException When option given doesn't exist
     */
    private function addShortOption($shortcut, $value)
    {
        if (!$this->definition->hasShortcut($shortcut)) {
            throw new \InvalidArgumentException(sprintf('The "-%s" option does not exist.', $shortcut));
        }

        $this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value);
    }

    /**
     * Adds a long option value.
     *
     * @param string $name  The long option key
     * @param mixed  $value The value for the option
     *
     * @throws \InvalidArgumentException When option given doesn't exist
     * @throws \InvalidArgumentException When a required value is missing
     */
    private function addLongOption($name, $value)
    {
        if (!$this->definition->hasOption($name)) {
            throw new \InvalidArgumentException(sprintf('The "--%s" option does not exist.', $name));
        }

        $option = $this->definition->getOption($name);

        if (null === $value) {
            if ($option->isValueRequired()) {
                throw new \InvalidArgumentException(sprintf('The "--%s" option requires a value.', $name));
            }

            $value = $option->isValueOptional() ? $option->getDefault() : true;
        }

        $this->options[$name] = $value;
    }

    /**
     * Adds an argument value.
     *
     * @param string $name  The argument name
     * @param mixed  $value The value for the argument
     *
     * @throws \InvalidArgumentException When argument given doesn't exist
     */
    private function addArgument($name, $value)
    {
        if (!$this->definition->hasArgument($name)) {
            throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
        }

        $this->arguments[$name] = $value;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Input;

/**
 * Represents a command line argument.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 *
 * @api
 */
class InputArgument
{
    const REQUIRED = 1;
    const OPTIONAL = 2;
    const IS_ARRAY = 4;

    private $name;
    private $mode;
    private $default;
    private $description;

    /**
     * Constructor.
     *
     * @param string $name        The argument name
     * @param int    $mode        The argument mode: self::REQUIRED or self::OPTIONAL
     * @param string $description A description text
     * @param mixed  $default     The default value (for self::OPTIONAL mode only)
     *
     * @throws \InvalidArgumentException When argument mode is not valid
     *
     * @api
     */
    public function __construct($name, $mode = null, $description = '', $default = null)
    {
        if (null === $mode) {
            $mode = self::OPTIONAL;
        } elseif (!is_int($mode) || $mode > 7 || $mode < 1) {
            throw new \InvalidArgumentException(sprintf('Argument mode "%s" is not valid.', $mode));
        }

        $this->name = $name;
        $this->mode = $mode;
        $this->description = $description;

        $this->setDefault($default);
    }

    /**
     * Returns the argument name.
     *
     * @return string The argument name
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Returns true if the argument is required.
     *
     * @return bool true if parameter mode is self::REQUIRED, false otherwise
     */
    public function isRequired()
    {
        return self::REQUIRED === (self::REQUIRED & $this->mode);
    }

    /**
     * Returns true if the argument can take multiple values.
     *
     * @return bool true if mode is self::IS_ARRAY, false otherwise
     */
    public function isArray()
    {
        return self::IS_ARRAY === (self::IS_ARRAY & $this->mode);
    }

    /**
     * Sets the default value.
     *
     * @param mixed $default The default value
     *
     * @throws \LogicException When incorrect default value is given
     */
    public function setDefault($default = null)
    {
        if (self::REQUIRED === $this->mode && null !== $default) {
            throw new \LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.');
        }

        if ($this->isArray()) {
            if (null === $default) {
                $default = array();
            } elseif (!is_array($default)) {
                throw new \LogicException('A default value for an array argument must be an array.');
            }
        }

        $this->default = $default;
    }

    /**
     * Returns the default value.
     *
     * @return mixed The default value
     */
    public function getDefault()
    {
        return $this->default;
    }

    /**
     * Returns the description text.
     *
     * @return string The description text
     */
    public function getDescription()
    {
        return $this->description;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Input;

/**
 * Represents a command line option.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 *
 * @api
 */
class InputOption
{
    const VALUE_NONE = 1;
    const VALUE_REQUIRED = 2;
    const VALUE_OPTIONAL = 4;
    const VALUE_IS_ARRAY = 8;

    private $name;
    private $shortcut;
    private $mode;
    private $default;
    private $description;

    /**
     * Constructor.
     *
     * @param string       $name        The option name
     * @param string|array $shortcut    The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
     * @param int          $mode        The option mode: One of the VALUE_* constants
     * @param string       $description A description text
     * @param mixed        $default     The default value (must be null for self::VALUE_REQUIRED or self::VALUE_NONE)
     *
     * @throws \InvalidArgumentException If option mode is invalid or incompatible
     *
     * @api
     */
    public function __construct($name, $shortcut = null, $mode = null, $description = '', $default = null)
    {
        if (0 === strpos($name, '--')) {
            $name = substr($name, 2);
        }

        if (empty($name)) {
            throw new \InvalidArgumentException('An option name cannot be empty.');
        }

        if (empty($shortcut)) {
            $shortcut = null;
        }

        if (null !== $shortcut) {
            if (is_array($shortcut)) {
                $shortcut = implode('|', $shortcut);
            }
            $shortcuts = preg_split('{(\|)-?}', ltrim($shortcut, '-'));
            $shortcuts = array_filter($shortcuts);
            $shortcut = implode('|', $shortcuts);

            if (empty($shortcut)) {
                throw new \InvalidArgumentException('An option shortcut cannot be empty.');
            }
        }

        if (null === $mode) {
            $mode = self::VALUE_NONE;
        } elseif (!is_int($mode) || $mode > 15 || $mode < 1) {
            throw new \InvalidArgumentException(sprintf('Option mode "%s" is not valid.', $mode));
        }

        $this->name = $name;
        $this->shortcut = $shortcut;
        $this->mode = $mode;
        $this->description = $description;

        if ($this->isArray() && !$this->acceptValue()) {
            throw new \InvalidArgumentException('Impossible to have an option mode VALUE_IS_ARRAY if the option does not accept a value.');
        }

        $this->setDefault($default);
    }

    /**
     * Returns the option shortcut.
     *
     * @return string The shortcut
     */
    public function getShortcut()
    {
        return $this->shortcut;
    }

    /**
     * Returns the option name.
     *
     * @return string The name
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Returns true if the option accepts a value.
     *
     * @return bool true if value mode is not self::VALUE_NONE, false otherwise
     */
    public function acceptValue()
    {
        return $this->isValueRequired() || $this->isValueOptional();
    }

    /**
     * Returns true if the option requires a value.
     *
     * @return bool true if value mode is self::VALUE_REQUIRED, false otherwise
     */
    public function isValueRequired()
    {
        return self::VALUE_REQUIRED === (self::VALUE_REQUIRED & $this->mode);
    }

    /**
     * Returns true if the option takes an optional value.
     *
     * @return bool true if value mode is self::VALUE_OPTIONAL, false otherwise
     */
    public function isValueOptional()
    {
        return self::VALUE_OPTIONAL === (self::VALUE_OPTIONAL & $this->mode);
    }

    /**
     * Returns true if the option can take multiple values.
     *
     * @return bool true if mode is self::VALUE_IS_ARRAY, false otherwise
     */
    public function isArray()
    {
        return self::VALUE_IS_ARRAY === (self::VALUE_IS_ARRAY & $this->mode);
    }

    /**
     * Sets the default value.
     *
     * @param mixed $default The default value
     *
     * @throws \LogicException When incorrect default value is given
     */
    public function setDefault($default = null)
    {
        if (self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) {
            throw new \LogicException('Cannot set a default value when using InputOption::VALUE_NONE mode.');
        }

        if ($this->isArray()) {
            if (null === $default) {
                $default = array();
            } elseif (!is_array($default)) {
                throw new \LogicException('A default value for an array option must be an array.');
            }
        }

        $this->default = $this->acceptValue() ? $default : false;
    }

    /**
     * Returns the default value.
     *
     * @return mixed The default value
     */
    public function getDefault()
    {
        return $this->default;
    }

    /**
     * Returns the description text.
     *
     * @return string The description text
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * Checks whether the given option equals this one.
     *
     * @param InputOption $option option to compare
     *
     * @return bool
     */
    public function equals(InputOption $option)
    {
        return $option->getName() === $this->getName()
            && $option->getShortcut() === $this->getShortcut()
            && $option->getDefault() === $this->getDefault()
            && $option->isArray() === $this->isArray()
            && $option->isValueRequired() === $this->isValueRequired()
            && $option->isValueOptional() === $this->isValueOptional()
        ;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Input;

use Symfony\Component\Console\Descriptor\TextDescriptor;
use Symfony\Component\Console\Descriptor\XmlDescriptor;
use Symfony\Component\Console\Output\BufferedOutput;

/**
 * A InputDefinition represents a set of valid command line arguments and options.
 *
 * Usage:
 *
 *     $definition = new InputDefinition(array(
 *       new InputArgument('name', InputArgument::REQUIRED),
 *       new InputOption('foo', 'f', InputOption::VALUE_REQUIRED),
 *     ));
 *
 * @author Fabien Potencier <fabien@symfony.com>
 *
 * @api
 */
class InputDefinition
{
    private $arguments;
    private $requiredCount;
    private $hasAnArrayArgument = false;
    private $hasOptional;
    private $options;
    private $shortcuts;

    /**
     * Constructor.
     *
     * @param array $definition An array of InputArgument and InputOption instance
     *
     * @api
     */
    public function __construct(array $definition = array())
    {
        $this->setDefinition($definition);
    }

    /**
     * Sets the definition of the input.
     *
     * @param array $definition The definition array
     *
     * @api
     */
    public function setDefinition(array $definition)
    {
        $arguments = array();
        $options = array();
        foreach ($definition as $item) {
            if ($item instanceof InputOption) {
                $options[] = $item;
            } else {
                $arguments[] = $item;
            }
        }

        $this->setArguments($arguments);
        $this->setOptions($options);
    }

    /**
     * Sets the InputArgument objects.
     *
     * @param InputArgument[] $arguments An array of InputArgument objects
     *
     * @api
     */
    public function setArguments($arguments = array())
    {
        $this->arguments = array();
        $this->requiredCount = 0;
        $this->hasOptional = false;
        $this->hasAnArrayArgument = false;
        $this->addArguments($arguments);
    }

    /**
     * Adds an array of InputArgument objects.
     *
     * @param InputArgument[] $arguments An array of InputArgument objects
     *
     * @api
     */
    public function addArguments($arguments = array())
    {
        if (null !== $arguments) {
            foreach ($arguments as $argument) {
                $this->addArgument($argument);
            }
        }
    }

    /**
     * Adds an InputArgument object.
     *
     * @param InputArgument $argument An InputArgument object
     *
     * @throws \LogicException When incorrect argument is given
     *
     * @api
     */
    public function addArgument(InputArgument $argument)
    {
        if (isset($this->arguments[$argument->getName()])) {
            throw new \LogicException(sprintf('An argument with name "%s" already exists.', $argument->getName()));
        }

        if ($this->hasAnArrayArgument) {
            throw new \LogicException('Cannot add an argument after an array argument.');
        }

        if ($argument->isRequired() && $this->hasOptional) {
            throw new \LogicException('Cannot add a required argument after an optional one.');
        }

        if ($argument->isArray()) {
            $this->hasAnArrayArgument = true;
        }

        if ($argument->isRequired()) {
            ++$this->requiredCount;
        } else {
            $this->hasOptional = true;
        }

        $this->arguments[$argument->getName()] = $argument;
    }

    /**
     * Returns an InputArgument by name or by position.
     *
     * @param string|int $name The InputArgument name or position
     *
     * @return InputArgument An InputArgument object
     *
     * @throws \InvalidArgumentException When argument given doesn't exist
     *
     * @api
     */
    public function getArgument($name)
    {
        if (!$this->hasArgument($name)) {
            throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
        }

        $arguments = is_int($name) ? array_values($this->arguments) : $this->arguments;

        return $arguments[$name];
    }

    /**
     * Returns true if an InputArgument object exists by name or position.
     *
     * @param string|int $name The InputArgument name or position
     *
     * @return bool true if the InputArgument object exists, false otherwise
     *
     * @api
     */
    public function hasArgument($name)
    {
        $arguments = is_int($name) ? array_values($this->arguments) : $this->arguments;

        return isset($arguments[$name]);
    }

    /**
     * Gets the array of InputArgument objects.
     *
     * @return InputArgument[] An array of InputArgument objects
     *
     * @api
     */
    public function getArguments()
    {
        return $this->arguments;
    }

    /**
     * Returns the number of InputArguments.
     *
     * @return int The number of InputArguments
     */
    public function getArgumentCount()
    {
        return $this->hasAnArrayArgument ? PHP_INT_MAX : count($this->arguments);
    }

    /**
     * Returns the number of required InputArguments.
     *
     * @return int The number of required InputArguments
     */
    public function getArgumentRequiredCount()
    {
        return $this->requiredCount;
    }

    /**
     * Gets the default values.
     *
     * @return array An array of default values
     */
    public function getArgumentDefaults()
    {
        $values = array();
        foreach ($this->arguments as $argument) {
            $values[$argument->getName()] = $argument->getDefault();
        }

        return $values;
    }

    /**
     * Sets the InputOption objects.
     *
     * @param InputOption[] $options An array of InputOption objects
     *
     * @api
     */
    public function setOptions($options = array())
    {
        $this->options = array();
        $this->shortcuts = array();
        $this->addOptions($options);
    }

    /**
     * Adds an array of InputOption objects.
     *
     * @param InputOption[] $options An array of InputOption objects
     *
     * @api
     */
    public function addOptions($options = array())
    {
        foreach ($options as $option) {
            $this->addOption($option);
        }
    }

    /**
     * Adds an InputOption object.
     *
     * @param InputOption $option An InputOption object
     *
     * @throws \LogicException When option given already exist
     *
     * @api
     */
    public function addOption(InputOption $option)
    {
        if (isset($this->options[$option->getName()]) && !$option->equals($this->options[$option->getName()])) {
            throw new \LogicException(sprintf('An option named "%s" already exists.', $option->getName()));
        }

        if ($option->getShortcut()) {
            foreach (explode('|', $option->getShortcut()) as $shortcut) {
                if (isset($this->shortcuts[$shortcut]) && !$option->equals($this->options[$this->shortcuts[$shortcut]])) {
                    throw new \LogicException(sprintf('An option with shortcut "%s" already exists.', $shortcut));
                }
            }
        }

        $this->options[$option->getName()] = $option;
        if ($option->getShortcut()) {
            foreach (explode('|', $option->getShortcut()) as $shortcut) {
                $this->shortcuts[$shortcut] = $option->getName();
            }
        }
    }

    /**
     * Returns an InputOption by name.
     *
     * @param string $name The InputOption name
     *
     * @return InputOption A InputOption object
     *
     * @throws \InvalidArgumentException When option given doesn't exist
     *
     * @api
     */
    public function getOption($name)
    {
        if (!$this->hasOption($name)) {
            throw new \InvalidArgumentException(sprintf('The "--%s" option does not exist.', $name));
        }

        return $this->options[$name];
    }

    /**
     * Returns true if an InputOption object exists by name.
     *
     * @param string $name The InputOption name
     *
     * @return bool true if the InputOption object exists, false otherwise
     *
     * @api
     */
    public function hasOption($name)
    {
        return isset($this->options[$name]);
    }

    /**
     * Gets the array of InputOption objects.
     *
     * @return InputOption[] An array of InputOption objects
     *
     * @api
     */
    public function getOptions()
    {
        return $this->options;
    }

    /**
     * Returns true if an InputOption object exists by shortcut.
     *
     * @param string $name The InputOption shortcut
     *
     * @return bool true if the InputOption object exists, false otherwise
     */
    public function hasShortcut($name)
    {
        return isset($this->shortcuts[$name]);
    }

    /**
     * Gets an InputOption by shortcut.
     *
     * @param string $shortcut the Shortcut name
     *
     * @return InputOption An InputOption object
     */
    public function getOptionForShortcut($shortcut)
    {
        return $this->getOption($this->shortcutToName($shortcut));
    }

    /**
     * Gets an array of default values.
     *
     * @return array An array of all default values
     */
    public function getOptionDefaults()
    {
        $values = array();
        foreach ($this->options as $option) {
            $values[$option->getName()] = $option->getDefault();
        }

        return $values;
    }

    /**
     * Returns the InputOption name given a shortcut.
     *
     * @param string $shortcut The shortcut
     *
     * @return string The InputOption name
     *
     * @throws \InvalidArgumentException When option given does not exist
     */
    private function shortcutToName($shortcut)
    {
        if (!isset($this->shortcuts[$shortcut])) {
            throw new \InvalidArgumentException(sprintf('The "-%s" option does not exist.', $shortcut));
        }

        return $this->shortcuts[$shortcut];
    }

    /**
     * Gets the synopsis.
     *
     * @return string The synopsis
     */
    public function getSynopsis()
    {
        $elements = array();
        foreach ($this->getOptions() as $option) {
            $shortcut = $option->getShortcut() ? sprintf('-%s|', $option->getShortcut()) : '';
            $elements[] = sprintf('['.($option->isValueRequired() ? '%s--%s="..."' : ($option->isValueOptional() ? '%s--%s[="..."]' : '%s--%s')).']', $shortcut, $option->getName());
        }

        foreach ($this->getArguments() as $argument) {
            $elements[] = sprintf($argument->isRequired() ? '%s' : '[%s]', $argument->getName().($argument->isArray() ? '1' : ''));

            if ($argument->isArray()) {
                $elements[] = sprintf('... [%sN]', $argument->getName());
            }
        }

        return implode(' ', $elements);
    }

    /**
     * Returns a textual representation of the InputDefinition.
     *
     * @return string A string representing the InputDefinition
     *
     * @deprecated Deprecated since version 2.3, to be removed in 3.0.
     */
    public function asText()
    {
        $descriptor = new TextDescriptor();
        $output = new BufferedOutput(BufferedOutput::VERBOSITY_NORMAL, true);
        $descriptor->describe($output, $this, array('raw_output' => true));

        return $output->fetch();
    }

    /**
     * Returns an XML representation of the InputDefinition.
     *
     * @param bool $asDom Whether to return a DOM or an XML string
     *
     * @return string|\DOMDocument An XML string representing the InputDefinition
     *
     * @deprecated Deprecated since version 2.3, to be removed in 3.0.
     */
    public function asXml($asDom = false)
    {
        $descriptor = new XmlDescriptor();

        if ($asDom) {
            return $descriptor->getInputDefinitionDocument($this);
        }

        $output = new BufferedOutput();
        $descriptor->describe($output, $this);

        return $output->fetch();
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Input;

/**
 * InputInterface is the interface implemented by all input classes.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
interface InputInterface
{
    /**
     * Returns the first argument from the raw parameters (not parsed).
     *
     * @return string The value of the first argument or null otherwise
     */
    public function getFirstArgument();

    /**
     * Returns true if the raw parameters (not parsed) contain a value.
     *
     * This method is to be used to introspect the input parameters
     * before they have been validated. It must be used carefully.
     *
     * @param string|array $values The values to look for in the raw parameters (can be an array)
     *
     * @return bool true if the value is contained in the raw parameters
     */
    public function hasParameterOption($values);

    /**
     * Returns the value of a raw option (not parsed).
     *
     * This method is to be used to introspect the input parameters
     * before they have been validated. It must be used carefully.
     *
     * @param string|array $values  The value(s) to look for in the raw parameters (can be an array)
     * @param mixed        $default The default value to return if no result is found
     *
     * @return mixed The option value
     */
    public function getParameterOption($values, $default = false);

    /**
     * Binds the current Input instance with the given arguments and options.
     *
     * @param InputDefinition $definition A InputDefinition instance
     */
    public function bind(InputDefinition $definition);

    /**
     * Validates if arguments given are correct.
     *
     * Throws an exception when not enough arguments are given.
     *
     * @throws \RuntimeException
     */
    public function validate();

    /**
     * Returns all the given arguments merged with the default values.
     *
     * @return array
     */
    public function getArguments();

    /**
     * Gets argument by name.
     *
     * @param string $name The name of the argument
     *
     * @return mixed
     */
    public function getArgument($name);

    /**
     * Sets an argument value by name.
     *
     * @param string $name  The argument name
     * @param string $value The argument value
     *
     * @throws \InvalidArgumentException When argument given doesn't exist
     */
    public function setArgument($name, $value);

    /**
     * Returns true if an InputArgument object exists by name or position.
     *
     * @param string|int $name The InputArgument name or position
     *
     * @return bool true if the InputArgument object exists, false otherwise
     */
    public function hasArgument($name);

    /**
     * Returns all the given options merged with the default values.
     *
     * @return array
     */
    public function getOptions();

    /**
     * Gets an option by name.
     *
     * @param string $name The name of the option
     *
     * @return mixed
     */
    public function getOption($name);

    /**
     * Sets an option value by name.
     *
     * @param string      $name  The option name
     * @param string|bool $value The option value
     *
     * @throws \InvalidArgumentException When option given doesn't exist
     */
    public function setOption($name, $value);

    /**
     * Returns true if an InputOption object exists by name.
     *
     * @param string $name The InputOption name
     *
     * @return bool true if the InputOption object exists, false otherwise
     */
    public function hasOption($name);

    /**
     * Is this input means interactive?
     *
     * @return bool
     */
    public function isInteractive();

    /**
     * Sets the input interactivity.
     *
     * @param bool $interactive If the input should be interactive
     */
    public function setInteractive($interactive);
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Input;

/**
 * InputAwareInterface should be implemented by classes that depends on the
 * Console Input.
 *
 * @author Wouter J <waldio.webdesign@gmail.com>
 */
interface InputAwareInterface
{
    /**
     * Sets the Console Input.
     *
     * @param InputInterface
     */
    public function setInput(InputInterface $input);
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Input;

/**
 * StringInput represents an input provided as a string.
 *
 * Usage:
 *
 *     $input = new StringInput('foo --bar="foobar"');
 *
 * @author Fabien Potencier <fabien@symfony.com>
 *
 * @api
 */
class StringInput extends ArgvInput
{
    const REGEX_STRING = '([^\s]+?)(?:\s|(?<!\\\\)"|(?<!\\\\)\'|$)';
    const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')';

    /**
     * Constructor.
     *
     * @param string          $input      An array of parameters from the CLI (in the argv format)
     * @param InputDefinition $definition A InputDefinition instance
     *
     * @deprecated The second argument is deprecated as it does not work (will be removed in 3.0), use 'bind' method instead
     *
     * @api
     */
    public function __construct($input, InputDefinition $definition = null)
    {
        parent::__construct(array(), null);

        $this->setTokens($this->tokenize($input));

        if (null !== $definition) {
            $this->bind($definition);
        }
    }

    /**
     * Tokenizes a string.
     *
     * @param string $input The input to tokenize
     *
     * @return array An array of tokens
     *
     * @throws \InvalidArgumentException When unable to parse input (should never happen)
     */
    private function tokenize($input)
    {
        $tokens = array();
        $length = strlen($input);
        $cursor = 0;
        while ($cursor < $length) {
            if (preg_match('/\s+/A', $input, $match, null, $cursor)) {
            } elseif (preg_match('/([^="\'\s]+?)(=?)('.self::REGEX_QUOTED_STRING.'+)/A', $input, $match, null, $cursor)) {
                $tokens[] = $match[1].$match[2].stripcslashes(str_replace(array('"\'', '\'"', '\'\'', '""'), '', substr($match[3], 1, strlen($match[3]) - 2)));
            } elseif (preg_match('/'.self::REGEX_QUOTED_STRING.'/A', $input, $match, null, $cursor)) {
                $tokens[] = stripcslashes(substr($match[0], 1, strlen($match[0]) - 2));
            } elseif (preg_match('/'.self::REGEX_STRING.'/A', $input, $match, null, $cursor)) {
                $tokens[] = stripcslashes($match[1]);
            } else {
                // should never happen
                throw new \InvalidArgumentException(sprintf('Unable to parse input near "... %s ..."', substr($input, $cursor, 10)));
            }

            $cursor += strlen($match[0]);
        }

        return $tokens;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Input;

/**
 * Input is the base class for all concrete Input classes.
 *
 * Three concrete classes are provided by default:
 *
 *  * `ArgvInput`: The input comes from the CLI arguments (argv)
 *  * `StringInput`: The input is provided as a string
 *  * `ArrayInput`: The input is provided as an array
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
abstract class Input implements InputInterface
{
    /**
     * @var InputDefinition
     */
    protected $definition;
    protected $options = array();
    protected $arguments = array();
    protected $interactive = true;

    /**
     * Constructor.
     *
     * @param InputDefinition $definition A InputDefinition instance
     */
    public function __construct(InputDefinition $definition = null)
    {
        if (null === $definition) {
            $this->definition = new InputDefinition();
        } else {
            $this->bind($definition);
            $this->validate();
        }
    }

    /**
     * Binds the current Input instance with the given arguments and options.
     *
     * @param InputDefinition $definition A InputDefinition instance
     */
    public function bind(InputDefinition $definition)
    {
        $this->arguments = array();
        $this->options = array();
        $this->definition = $definition;

        $this->parse();
    }

    /**
     * Processes command line arguments.
     */
    abstract protected function parse();

    /**
     * Validates the input.
     *
     * @throws \RuntimeException When not enough arguments are given
     */
    public function validate()
    {
        if (count($this->arguments) < $this->definition->getArgumentRequiredCount()) {
            throw new \RuntimeException('Not enough arguments.');
        }
    }

    /**
     * Checks if the input is interactive.
     *
     * @return bool Returns true if the input is interactive
     */
    public function isInteractive()
    {
        return $this->interactive;
    }

    /**
     * Sets the input interactivity.
     *
     * @param bool $interactive If the input should be interactive
     */
    public function setInteractive($interactive)
    {
        $this->interactive = (bool) $interactive;
    }

    /**
     * Returns the argument values.
     *
     * @return array An array of argument values
     */
    public function getArguments()
    {
        return array_merge($this->definition->getArgumentDefaults(), $this->arguments);
    }

    /**
     * Returns the argument value for a given argument name.
     *
     * @param string $name The argument name
     *
     * @return mixed The argument value
     *
     * @throws \InvalidArgumentException When argument given doesn't exist
     */
    public function getArgument($name)
    {
        if (!$this->definition->hasArgument($name)) {
            throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
        }

        return isset($this->arguments[$name]) ? $this->arguments[$name] : $this->definition->getArgument($name)->getDefault();
    }

    /**
     * Sets an argument value by name.
     *
     * @param string $name  The argument name
     * @param string $value The argument value
     *
     * @throws \InvalidArgumentException When argument given doesn't exist
     */
    public function setArgument($name, $value)
    {
        if (!$this->definition->hasArgument($name)) {
            throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
        }

        $this->arguments[$name] = $value;
    }

    /**
     * Returns true if an InputArgument object exists by name or position.
     *
     * @param string|int $name The InputArgument name or position
     *
     * @return bool true if the InputArgument object exists, false otherwise
     */
    public function hasArgument($name)
    {
        return $this->definition->hasArgument($name);
    }

    /**
     * Returns the options values.
     *
     * @return array An array of option values
     */
    public function getOptions()
    {
        return array_merge($this->definition->getOptionDefaults(), $this->options);
    }

    /**
     * Returns the option value for a given option name.
     *
     * @param string $name The option name
     *
     * @return mixed The option value
     *
     * @throws \InvalidArgumentException When option given doesn't exist
     */
    public function getOption($name)
    {
        if (!$this->definition->hasOption($name)) {
            throw new \InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
        }

        return isset($this->options[$name]) ? $this->options[$name] : $this->definition->getOption($name)->getDefault();
    }

    /**
     * Sets an option value by name.
     *
     * @param string      $name  The option name
     * @param string|bool $value The option value
     *
     * @throws \InvalidArgumentException When option given doesn't exist
     */
    public function setOption($name, $value)
    {
        if (!$this->definition->hasOption($name)) {
            throw new \InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
        }

        $this->options[$name] = $value;
    }

    /**
     * Returns true if an InputOption object exists by name.
     *
     * @param string $name The InputOption name
     *
     * @return bool true if the InputOption object exists, false otherwise
     */
    public function hasOption($name)
    {
        return $this->definition->hasOption($name);
    }

    /**
     * Escapes a token through escapeshellarg if it contains unsafe chars.
     *
     * @param string $token
     *
     * @return string
     */
    public function escapeToken($token)
    {
        return preg_match('{^[\w-]+$}', $token) ? $token : escapeshellarg($token);
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Input;

/**
 * ArgvInput represents an input coming from the CLI arguments.
 *
 * Usage:
 *
 *     $input = new ArgvInput();
 *
 * By default, the `$_SERVER['argv']` array is used for the input values.
 *
 * This can be overridden by explicitly passing the input values in the constructor:
 *
 *     $input = new ArgvInput($_SERVER['argv']);
 *
 * If you pass it yourself, don't forget that the first element of the array
 * is the name of the running application.
 *
 * When passing an argument to the constructor, be sure that it respects
 * the same rules as the argv one. It's almost always better to use the
 * `StringInput` when you want to provide your own input.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 *
 * @see http://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html
 * @see http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap12.html#tag_12_02
 *
 * @api
 */
class ArgvInput extends Input
{
    private $tokens;
    private $parsed;

    /**
     * Constructor.
     *
     * @param array           $argv       An array of parameters from the CLI (in the argv format)
     * @param InputDefinition $definition A InputDefinition instance
     *
     * @api
     */
    public function __construct(array $argv = null, InputDefinition $definition = null)
    {
        if (null === $argv) {
            $argv = $_SERVER['argv'];
        }

        // strip the application name
        array_shift($argv);

        $this->tokens = $argv;

        parent::__construct($definition);
    }

    protected function setTokens(array $tokens)
    {
        $this->tokens = $tokens;
    }

    /**
     * Processes command line arguments.
     */
    protected function parse()
    {
        $parseOptions = true;
        $this->parsed = $this->tokens;
        while (null !== $token = array_shift($this->parsed)) {
            if ($parseOptions && '' == $token) {
                $this->parseArgument($token);
            } elseif ($parseOptions && '--' == $token) {
                $parseOptions = false;
            } elseif ($parseOptions && 0 === strpos($token, '--')) {
                $this->parseLongOption($token);
            } elseif ($parseOptions && '-' === $token[0] && '-' !== $token) {
                $this->parseShortOption($token);
            } else {
                $this->parseArgument($token);
            }
        }
    }

    /**
     * Parses a short option.
     *
     * @param string $token The current token.
     */
    private function parseShortOption($token)
    {
        $name = substr($token, 1);

        if (strlen($name) > 1) {
            if ($this->definition->hasShortcut($name[0]) && $this->definition->getOptionForShortcut($name[0])->acceptValue()) {
                // an option with a value (with no space)
                $this->addShortOption($name[0], substr($name, 1));
            } else {
                $this->parseShortOptionSet($name);
            }
        } else {
            $this->addShortOption($name, null);
        }
    }

    /**
     * Parses a short option set.
     *
     * @param string $name The current token
     *
     * @throws \RuntimeException When option given doesn't exist
     */
    private function parseShortOptionSet($name)
    {
        $len = strlen($name);
        for ($i = 0; $i < $len; ++$i) {
            if (!$this->definition->hasShortcut($name[$i])) {
                throw new \RuntimeException(sprintf('The "-%s" option does not exist.', $name[$i]));
            }

            $option = $this->definition->getOptionForShortcut($name[$i]);
            if ($option->acceptValue()) {
                $this->addLongOption($option->getName(), $i === $len - 1 ? null : substr($name, $i + 1));

                break;
            } else {
                $this->addLongOption($option->getName(), null);
            }
        }
    }

    /**
     * Parses a long option.
     *
     * @param string $token The current token
     */
    private function parseLongOption($token)
    {
        $name = substr($token, 2);

        if (false !== $pos = strpos($name, '=')) {
            $this->addLongOption(substr($name, 0, $pos), substr($name, $pos + 1));
        } else {
            $this->addLongOption($name, null);
        }
    }

    /**
     * Parses an argument.
     *
     * @param string $token The current token
     *
     * @throws \RuntimeException When too many arguments are given
     */
    private function parseArgument($token)
    {
        $c = count($this->arguments);

        // if input is expecting another argument, add it
        if ($this->definition->hasArgument($c)) {
            $arg = $this->definition->getArgument($c);
            $this->arguments[$arg->getName()] = $arg->isArray() ? array($token) : $token;

        // if last argument isArray(), append token to last argument
        } elseif ($this->definition->hasArgument($c - 1) && $this->definition->getArgument($c - 1)->isArray()) {
            $arg = $this->definition->getArgument($c - 1);
            $this->arguments[$arg->getName()][] = $token;

        // unexpected argument
        } else {
            throw new \RuntimeException('Too many arguments.');
        }
    }

    /**
     * Adds a short option value.
     *
     * @param string $shortcut The short option key
     * @param mixed  $value    The value for the option
     *
     * @throws \RuntimeException When option given doesn't exist
     */
    private function addShortOption($shortcut, $value)
    {
        if (!$this->definition->hasShortcut($shortcut)) {
            throw new \RuntimeException(sprintf('The "-%s" option does not exist.', $shortcut));
        }

        $this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value);
    }

    /**
     * Adds a long option value.
     *
     * @param string $name  The long option key
     * @param mixed  $value The value for the option
     *
     * @throws \RuntimeException When option given doesn't exist
     */
    private function addLongOption($name, $value)
    {
        if (!$this->definition->hasOption($name)) {
            throw new \RuntimeException(sprintf('The "--%s" option does not exist.', $name));
        }

        $option = $this->definition->getOption($name);

        // Convert false values (from a previous call to substr()) to null
        if (false === $value) {
            $value = null;
        }

        if (null !== $value && !$option->acceptValue()) {
            throw new \RuntimeException(sprintf('The "--%s" option does not accept a value.', $name));
        }

        if (null === $value && $option->acceptValue() && count($this->parsed)) {
            // if option accepts an optional or mandatory argument
            // let's see if there is one provided
            $next = array_shift($this->parsed);
            if (isset($next[0]) && '-' !== $next[0]) {
                $value = $next;
            } elseif (empty($next)) {
                $value = '';
            } else {
                array_unshift($this->parsed, $next);
            }
        }

        if (null === $value) {
            if ($option->isValueRequired()) {
                throw new \RuntimeException(sprintf('The "--%s" option requires a value.', $name));
            }

            if (!$option->isArray()) {
                $value = $option->isValueOptional() ? $option->getDefault() : true;
            }
        }

        if ($option->isArray()) {
            $this->options[$name][] = $value;
        } else {
            $this->options[$name] = $value;
        }
    }

    /**
     * Returns the first argument from the raw parameters (not parsed).
     *
     * @return string The value of the first argument or null otherwise
     */
    public function getFirstArgument()
    {
        foreach ($this->tokens as $token) {
            if ($token && '-' === $token[0]) {
                continue;
            }

            return $token;
        }
    }

    /**
     * Returns true if the raw parameters (not parsed) contain a value.
     *
     * This method is to be used to introspect the input parameters
     * before they have been validated. It must be used carefully.
     *
     * @param string|array $values The value(s) to look for in the raw parameters (can be an array)
     *
     * @return bool true if the value is contained in the raw parameters
     */
    public function hasParameterOption($values)
    {
        $values = (array) $values;

        foreach ($this->tokens as $token) {
            foreach ($values as $value) {
                if ($token === $value || 0 === strpos($token, $value.'=')) {
                    return true;
                }
            }
        }

        return false;
    }

    /**
     * Returns the value of a raw option (not parsed).
     *
     * This method is to be used to introspect the input parameters
     * before they have been validated. It must be used carefully.
     *
     * @param string|array $values  The value(s) to look for in the raw parameters (can be an array)
     * @param mixed        $default The default value to return if no result is found
     *
     * @return mixed The option value
     */
    public function getParameterOption($values, $default = false)
    {
        $values = (array) $values;
        $tokens = $this->tokens;

        while (0 < count($tokens)) {
            $token = array_shift($tokens);

            foreach ($values as $value) {
                if ($token === $value || 0 === strpos($token, $value.'=')) {
                    if (false !== $pos = strpos($token, '=')) {
                        return substr($token, $pos + 1);
                    }

                    return array_shift($tokens);
                }
            }
        }

        return $default;
    }

    /**
     * Returns a stringified representation of the args passed to the command.
     *
     * @return string
     */
    public function __toString()
    {
        $self = $this;
        $tokens = array_map(function ($token) use ($self) {
            if (preg_match('{^(-[^=]+=)(.+)}', $token, $match)) {
                return $match[1].$self->escapeToken($match[2]);
            }

            if ($token && $token[0] !== '-') {
                return $self->escapeToken($token);
            }

            return $token;
        }, $this->tokens);

        return implode(' ', $tokens);
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Logger;

use Psr\Log\AbstractLogger;
use Psr\Log\InvalidArgumentException;
use Psr\Log\LogLevel;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;

/**
 * PSR-3 compliant console logger
 *
 * @author Kévin Dunglas <dunglas@gmail.com>
 * @link http://www.php-fig.org/psr/psr-3/
 */
class ConsoleLogger extends AbstractLogger
{
    const INFO = 'info';
    const ERROR = 'error';

    /**
     * @var OutputInterface
     */
    private $output;
    /**
     * @var array
     */
    private $verbosityLevelMap = array(
        LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL,
        LogLevel::ALERT => OutputInterface::VERBOSITY_NORMAL,
        LogLevel::CRITICAL => OutputInterface::VERBOSITY_NORMAL,
        LogLevel::ERROR => OutputInterface::VERBOSITY_NORMAL,
        LogLevel::WARNING => OutputInterface::VERBOSITY_NORMAL,
        LogLevel::NOTICE => OutputInterface::VERBOSITY_VERBOSE,
        LogLevel::INFO => OutputInterface::VERBOSITY_VERY_VERBOSE,
        LogLevel::DEBUG => OutputInterface::VERBOSITY_DEBUG,
    );
    /**
     * @var array
     */
    private $formatLevelMap = array(
        LogLevel::EMERGENCY => self::ERROR,
        LogLevel::ALERT => self::ERROR,
        LogLevel::CRITICAL => self::ERROR,
        LogLevel::ERROR => self::ERROR,
        LogLevel::WARNING => self::INFO,
        LogLevel::NOTICE => self::INFO,
        LogLevel::INFO => self::INFO,
        LogLevel::DEBUG => self::INFO,
    );

    /**
     * @param OutputInterface $output
     * @param array           $verbosityLevelMap
     * @param array           $formatLevelMap
     */
    public function __construct(OutputInterface $output, array $verbosityLevelMap = array(), array $formatLevelMap = array())
    {
        $this->output = $output;
        $this->verbosityLevelMap = $verbosityLevelMap + $this->verbosityLevelMap;
        $this->formatLevelMap = $formatLevelMap + $this->formatLevelMap;
    }

    /**
     * {@inheritdoc}
     */
    public function log($level, $message, array $context = array())
    {
        if (!isset($this->verbosityLevelMap[$level])) {
            throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $level));
        }

        // Write to the error output if necessary and available
        if ($this->formatLevelMap[$level] === self::ERROR && $this->output instanceof ConsoleOutputInterface) {
            $output = $this->output->getErrorOutput();
        } else {
            $output = $this->output;
        }

        if ($output->getVerbosity() >= $this->verbosityLevelMap[$level]) {
            $output->writeln(sprintf('<%1$s>[%2$s] %3$s</%1$s>', $this->formatLevelMap[$level], $level, $this->interpolate($message, $context)));
        }
    }

    /**
     * Interpolates context values into the message placeholders
     *
     * @author PHP Framework Interoperability Group
     *
     * @param string $message
     * @param array  $context
     *
     * @return string
     */
    private function interpolate($message, array $context)
    {
        // build a replacement array with braces around the context keys
        $replace = array();
        foreach ($context as $key => $val) {
            if (!is_array($val) && (!is_object($val) || method_exists($val, '__toString'))) {
                $replace[sprintf('{%s}', $key)] = $val;
            }
        }

        // interpolate replacement values into the message and return
        return strtr($message, $replace);
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Formatter;

/**
 * Formatter class for console output.
 *
 * @author Konstantin Kudryashov <ever.zet@gmail.com>
 *
 * @api
 */
class OutputFormatter implements OutputFormatterInterface
{
    private $decorated;
    private $styles = array();
    private $styleStack;

    /**
     * Escapes "<" special char in given text.
     *
     * @param string $text Text to escape
     *
     * @return string Escaped text
     */
    public static function escape($text)
    {
        return preg_replace('/([^\\\\]?)</', '$1\\<', $text);
    }

    /**
     * Initializes console output formatter.
     *
     * @param bool                            $decorated Whether this formatter should actually decorate strings
     * @param OutputFormatterStyleInterface[] $styles    Array of "name => FormatterStyle" instances
     *
     * @api
     */
    public function __construct($decorated = false, array $styles = array())
    {
        $this->decorated = (bool) $decorated;

        $this->setStyle('error', new OutputFormatterStyle('white', 'red'));
        $this->setStyle('info', new OutputFormatterStyle('green'));
        $this->setStyle('comment', new OutputFormatterStyle('yellow'));
        $this->setStyle('question', new OutputFormatterStyle('black', 'cyan'));

        foreach ($styles as $name => $style) {
            $this->setStyle($name, $style);
        }

        $this->styleStack = new OutputFormatterStyleStack();
    }

    /**
     * Sets the decorated flag.
     *
     * @param bool $decorated Whether to decorate the messages or not
     *
     * @api
     */
    public function setDecorated($decorated)
    {
        $this->decorated = (bool) $decorated;
    }

    /**
     * Gets the decorated flag.
     *
     * @return bool true if the output will decorate messages, false otherwise
     *
     * @api
     */
    public function isDecorated()
    {
        return $this->decorated;
    }

    /**
     * Sets a new style.
     *
     * @param string                        $name  The style name
     * @param OutputFormatterStyleInterface $style The style instance
     *
     * @api
     */
    public function setStyle($name, OutputFormatterStyleInterface $style)
    {
        $this->styles[strtolower($name)] = $style;
    }

    /**
     * Checks if output formatter has style with specified name.
     *
     * @param string $name
     *
     * @return bool
     *
     * @api
     */
    public function hasStyle($name)
    {
        return isset($this->styles[strtolower($name)]);
    }

    /**
     * Gets style options from style with specified name.
     *
     * @param string $name
     *
     * @return OutputFormatterStyleInterface
     *
     * @throws \InvalidArgumentException When style isn't defined
     *
     * @api
     */
    public function getStyle($name)
    {
        if (!$this->hasStyle($name)) {
            throw new \InvalidArgumentException(sprintf('Undefined style: %s', $name));
        }

        return $this->styles[strtolower($name)];
    }

    /**
     * Formats a message according to the given styles.
     *
     * @param string $message The message to style
     *
     * @return string The styled message
     *
     * @api
     */
    public function format($message)
    {
        $message = (string) $message;
        $offset = 0;
        $output = '';
        $tagRegex = '[a-z][a-z0-9_=;-]*';
        preg_match_all("#<(($tagRegex) | /($tagRegex)?)>#ix", $message, $matches, PREG_OFFSET_CAPTURE);
        foreach ($matches[0] as $i => $match) {
            $pos = $match[1];
            $text = $match[0];

            if (0 != $pos && '\\' == $message[$pos - 1]) {
                continue;
            }

            // add the text up to the next tag
            $output .= $this->applyCurrentStyle(substr($message, $offset, $pos - $offset));
            $offset = $pos + strlen($text);

            // opening tag?
            if ($open = '/' != $text[1]) {
                $tag = $matches[1][$i][0];
            } else {
                $tag = isset($matches[3][$i][0]) ? $matches[3][$i][0] : '';
            }

            if (!$open && !$tag) {
                // </>
                $this->styleStack->pop();
            } elseif (false === $style = $this->createStyleFromString(strtolower($tag))) {
                $output .= $this->applyCurrentStyle($text);
            } elseif ($open) {
                $this->styleStack->push($style);
            } else {
                $this->styleStack->pop($style);
            }
        }

        $output .= $this->applyCurrentStyle(substr($message, $offset));

        return str_replace('\\<', '<', $output);
    }

    /**
     * @return OutputFormatterStyleStack
     */
    public function getStyleStack()
    {
        return $this->styleStack;
    }

    /**
     * Tries to create new style instance from string.
     *
     * @param string $string
     *
     * @return OutputFormatterStyle|bool false if string is not format string
     */
    private function createStyleFromString($string)
    {
        if (isset($this->styles[$string])) {
            return $this->styles[$string];
        }

        if (!preg_match_all('/([^=]+)=([^;]+)(;|$)/', strtolower($string), $matches, PREG_SET_ORDER)) {
            return false;
        }

        $style = new OutputFormatterStyle();
        foreach ($matches as $match) {
            array_shift($match);

            if ('fg' == $match[0]) {
                $style->setForeground($match[1]);
            } elseif ('bg' == $match[0]) {
                $style->setBackground($match[1]);
            } else {
                try {
                    $style->setOption($match[1]);
                } catch (\InvalidArgumentException $e) {
                    return false;
                }
            }
        }

        return $style;
    }

    /**
     * Applies current style from stack to text, if must be applied.
     *
     * @param string $text Input text
     *
     * @return string Styled text
     */
    private function applyCurrentStyle($text)
    {
        return $this->isDecorated() && strlen($text) > 0 ? $this->styleStack->getCurrent()->apply($text) : $text;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Formatter;

/**
 * Formatter style class for defining styles.
 *
 * @author Konstantin Kudryashov <ever.zet@gmail.com>
 *
 * @api
 */
class OutputFormatterStyle implements OutputFormatterStyleInterface
{
    private static $availableForegroundColors = array(
        'black' => array('set' => 30, 'unset' => 39),
        'red' => array('set' => 31, 'unset' => 39),
        'green' => array('set' => 32, 'unset' => 39),
        'yellow' => array('set' => 33, 'unset' => 39),
        'blue' => array('set' => 34, 'unset' => 39),
        'magenta' => array('set' => 35, 'unset' => 39),
        'cyan' => array('set' => 36, 'unset' => 39),
        'white' => array('set' => 37, 'unset' => 39),
        'default' => array('set' => 39, 'unset' => 39),
    );
    private static $availableBackgroundColors = array(
        'black' => array('set' => 40, 'unset' => 49),
        'red' => array('set' => 41, 'unset' => 49),
        'green' => array('set' => 42, 'unset' => 49),
        'yellow' => array('set' => 43, 'unset' => 49),
        'blue' => array('set' => 44, 'unset' => 49),
        'magenta' => array('set' => 45, 'unset' => 49),
        'cyan' => array('set' => 46, 'unset' => 49),
        'white' => array('set' => 47, 'unset' => 49),
        'default' => array('set' => 49, 'unset' => 49),
    );
    private static $availableOptions = array(
        'bold' => array('set' => 1, 'unset' => 22),
        'underscore' => array('set' => 4, 'unset' => 24),
        'blink' => array('set' => 5, 'unset' => 25),
        'reverse' => array('set' => 7, 'unset' => 27),
        'conceal' => array('set' => 8, 'unset' => 28),
    );

    private $foreground;
    private $background;
    private $options = array();

    /**
     * Initializes output formatter style.
     *
     * @param string|null $foreground The style foreground color name
     * @param string|null $background The style background color name
     * @param array       $options    The style options
     *
     * @api
     */
    public function __construct($foreground = null, $background = null, array $options = array())
    {
        if (null !== $foreground) {
            $this->setForeground($foreground);
        }
        if (null !== $background) {
            $this->setBackground($background);
        }
        if (count($options)) {
            $this->setOptions($options);
        }
    }

    /**
     * Sets style foreground color.
     *
     * @param string|null $color The color name
     *
     * @throws \InvalidArgumentException When the color name isn't defined
     *
     * @api
     */
    public function setForeground($color = null)
    {
        if (null === $color) {
            $this->foreground = null;

            return;
        }

        if (!isset(static::$availableForegroundColors[$color])) {
            throw new \InvalidArgumentException(sprintf(
                'Invalid foreground color specified: "%s". Expected one of (%s)',
                $color,
                implode(', ', array_keys(static::$availableForegroundColors))
            ));
        }

        $this->foreground = static::$availableForegroundColors[$color];
    }

    /**
     * Sets style background color.
     *
     * @param string|null $color The color name
     *
     * @throws \InvalidArgumentException When the color name isn't defined
     *
     * @api
     */
    public function setBackground($color = null)
    {
        if (null === $color) {
            $this->background = null;

            return;
        }

        if (!isset(static::$availableBackgroundColors[$color])) {
            throw new \InvalidArgumentException(sprintf(
                'Invalid background color specified: "%s". Expected one of (%s)',
                $color,
                implode(', ', array_keys(static::$availableBackgroundColors))
            ));
        }

        $this->background = static::$availableBackgroundColors[$color];
    }

    /**
     * Sets some specific style option.
     *
     * @param string $option The option name
     *
     * @throws \InvalidArgumentException When the option name isn't defined
     *
     * @api
     */
    public function setOption($option)
    {
        if (!isset(static::$availableOptions[$option])) {
            throw new \InvalidArgumentException(sprintf(
                'Invalid option specified: "%s". Expected one of (%s)',
                $option,
                implode(', ', array_keys(static::$availableOptions))
            ));
        }

        if (!in_array(static::$availableOptions[$option], $this->options)) {
            $this->options[] = static::$availableOptions[$option];
        }
    }

    /**
     * Unsets some specific style option.
     *
     * @param string $option The option name
     *
     * @throws \InvalidArgumentException When the option name isn't defined
     */
    public function unsetOption($option)
    {
        if (!isset(static::$availableOptions[$option])) {
            throw new \InvalidArgumentException(sprintf(
                'Invalid option specified: "%s". Expected one of (%s)',
                $option,
                implode(', ', array_keys(static::$availableOptions))
            ));
        }

        $pos = array_search(static::$availableOptions[$option], $this->options);
        if (false !== $pos) {
            unset($this->options[$pos]);
        }
    }

    /**
     * Sets multiple style options at once.
     *
     * @param array $options
     */
    public function setOptions(array $options)
    {
        $this->options = array();

        foreach ($options as $option) {
            $this->setOption($option);
        }
    }

    /**
     * Applies the style to a given text.
     *
     * @param string $text The text to style
     *
     * @return string
     */
    public function apply($text)
    {
        $setCodes = array();
        $unsetCodes = array();

        if (null !== $this->foreground) {
            $setCodes[] = $this->foreground['set'];
            $unsetCodes[] = $this->foreground['unset'];
        }
        if (null !== $this->background) {
            $setCodes[] = $this->background['set'];
            $unsetCodes[] = $this->background['unset'];
        }
        if (count($this->options)) {
            foreach ($this->options as $option) {
                $setCodes[] = $option['set'];
                $unsetCodes[] = $option['unset'];
            }
        }

        if (0 === count($setCodes)) {
            return $text;
        }

        return sprintf("\033[%sm%s\033[%sm", implode(';', $setCodes), $text, implode(';', $unsetCodes));
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Formatter;

/**
 * @author Jean-François Simon <contact@jfsimon.fr>
 */
class OutputFormatterStyleStack
{
    /**
     * @var OutputFormatterStyleInterface[]
     */
    private $styles;

    /**
     * @var OutputFormatterStyleInterface
     */
    private $emptyStyle;

    /**
     * Constructor.
     *
     * @param OutputFormatterStyleInterface|null $emptyStyle
     */
    public function __construct(OutputFormatterStyleInterface $emptyStyle = null)
    {
        $this->emptyStyle = $emptyStyle ?: new OutputFormatterStyle();
        $this->reset();
    }

    /**
     * Resets stack (ie. empty internal arrays).
     */
    public function reset()
    {
        $this->styles = array();
    }

    /**
     * Pushes a style in the stack.
     *
     * @param OutputFormatterStyleInterface $style
     */
    public function push(OutputFormatterStyleInterface $style)
    {
        $this->styles[] = $style;
    }

    /**
     * Pops a style from the stack.
     *
     * @param OutputFormatterStyleInterface|null $style
     *
     * @return OutputFormatterStyleInterface
     *
     * @throws \InvalidArgumentException When style tags incorrectly nested
     */
    public function pop(OutputFormatterStyleInterface $style = null)
    {
        if (empty($this->styles)) {
            return $this->emptyStyle;
        }

        if (null === $style) {
            return array_pop($this->styles);
        }

        foreach (array_reverse($this->styles, true) as $index => $stackedStyle) {
            if ($style->apply('') === $stackedStyle->apply('')) {
                $this->styles = array_slice($this->styles, 0, $index);

                return $stackedStyle;
            }
        }

        throw new \InvalidArgumentException('Incorrectly nested style tag found.');
    }

    /**
     * Computes current style with stacks top codes.
     *
     * @return OutputFormatterStyle
     */
    public function getCurrent()
    {
        if (empty($this->styles)) {
            return $this->emptyStyle;
        }

        return $this->styles[count($this->styles) - 1];
    }

    /**
     * @param OutputFormatterStyleInterface $emptyStyle
     *
     * @return OutputFormatterStyleStack
     */
    public function setEmptyStyle(OutputFormatterStyleInterface $emptyStyle)
    {
        $this->emptyStyle = $emptyStyle;

        return $this;
    }

    /**
     * @return OutputFormatterStyleInterface
     */
    public function getEmptyStyle()
    {
        return $this->emptyStyle;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Formatter;

/**
 * Formatter style interface for defining styles.
 *
 * @author Konstantin Kudryashov <ever.zet@gmail.com>
 *
 * @api
 */
interface OutputFormatterStyleInterface
{
    /**
     * Sets style foreground color.
     *
     * @param string $color The color name
     *
     * @api
     */
    public function setForeground($color = null);

    /**
     * Sets style background color.
     *
     * @param string $color The color name
     *
     * @api
     */
    public function setBackground($color = null);

    /**
     * Sets some specific style option.
     *
     * @param string $option The option name
     *
     * @api
     */
    public function setOption($option);

    /**
     * Unsets some specific style option.
     *
     * @param string $option The option name
     */
    public function unsetOption($option);

    /**
     * Sets multiple style options at once.
     *
     * @param array $options
     */
    public function setOptions(array $options);

    /**
     * Applies the style to a given text.
     *
     * @param string $text The text to style
     *
     * @return string
     */
    public function apply($text);
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Formatter;

/**
 * Formatter interface for console output.
 *
 * @author Konstantin Kudryashov <ever.zet@gmail.com>
 *
 * @api
 */
interface OutputFormatterInterface
{
    /**
     * Sets the decorated flag.
     *
     * @param bool $decorated Whether to decorate the messages or not
     *
     * @api
     */
    public function setDecorated($decorated);

    /**
     * Gets the decorated flag.
     *
     * @return bool true if the output will decorate messages, false otherwise
     *
     * @api
     */
    public function isDecorated();

    /**
     * Sets a new style.
     *
     * @param string                        $name  The style name
     * @param OutputFormatterStyleInterface $style The style instance
     *
     * @api
     */
    public function setStyle($name, OutputFormatterStyleInterface $style);

    /**
     * Checks if output formatter has style with specified name.
     *
     * @param string $name
     *
     * @return bool
     *
     * @api
     */
    public function hasStyle($name);

    /**
     * Gets style options from style with specified name.
     *
     * @param string $name
     *
     * @return OutputFormatterStyleInterface
     *
     * @api
     */
    public function getStyle($name);

    /**
     * Formats a message according to the given styles.
     *
     * @param string $message The message to style
     *
     * @return string The styled message
     *
     * @api
     */
    public function format($message);
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Command;

use Symfony\Component\Console\Descriptor\TextDescriptor;
use Symfony\Component\Console\Descriptor\XmlDescriptor;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\HelperSet;

/**
 * Base class for all commands.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 *
 * @api
 */
class Command
{
    private $application;
    private $name;
    private $processTitle;
    private $aliases = array();
    private $definition;
    private $help;
    private $description;
    private $ignoreValidationErrors = false;
    private $applicationDefinitionMerged = false;
    private $applicationDefinitionMergedWithArgs = false;
    private $code;
    private $synopsis;
    private $helperSet;

    /**
     * Constructor.
     *
     * @param string|null $name The name of the command; passing null means it must be set in configure()
     *
     * @throws \LogicException When the command name is empty
     *
     * @api
     */
    public function __construct($name = null)
    {
        $this->definition = new InputDefinition();

        if (null !== $name) {
            $this->setName($name);
        }

        $this->configure();

        if (!$this->name) {
            throw new \LogicException(sprintf('The command defined in "%s" cannot have an empty name.', get_class($this)));
        }
    }

    /**
     * Ignores validation errors.
     *
     * This is mainly useful for the help command.
     */
    public function ignoreValidationErrors()
    {
        $this->ignoreValidationErrors = true;
    }

    /**
     * Sets the application instance for this command.
     *
     * @param Application $application An Application instance
     *
     * @api
     */
    public function setApplication(Application $application = null)
    {
        $this->application = $application;
        if ($application) {
            $this->setHelperSet($application->getHelperSet());
        } else {
            $this->helperSet = null;
        }
    }

    /**
     * Sets the helper set.
     *
     * @param HelperSet $helperSet A HelperSet instance
     */
    public function setHelperSet(HelperSet $helperSet)
    {
        $this->helperSet = $helperSet;
    }

    /**
     * Gets the helper set.
     *
     * @return HelperSet A HelperSet instance
     */
    public function getHelperSet()
    {
        return $this->helperSet;
    }

    /**
     * Gets the application instance for this command.
     *
     * @return Application An Application instance
     *
     * @api
     */
    public function getApplication()
    {
        return $this->application;
    }

    /**
     * Checks whether the command is enabled or not in the current environment.
     *
     * Override this to check for x or y and return false if the command can not
     * run properly under the current conditions.
     *
     * @return bool
     */
    public function isEnabled()
    {
        return true;
    }

    /**
     * Configures the current command.
     */
    protected function configure()
    {
    }

    /**
     * Executes the current command.
     *
     * This method is not abstract because you can use this class
     * as a concrete class. In this case, instead of defining the
     * execute() method, you set the code to execute by passing
     * a Closure to the setCode() method.
     *
     * @param InputInterface  $input  An InputInterface instance
     * @param OutputInterface $output An OutputInterface instance
     *
     * @return null|int null or 0 if everything went fine, or an error code
     *
     * @throws \LogicException When this abstract method is not implemented
     *
     * @see setCode()
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        throw new \LogicException('You must override the execute() method in the concrete command class.');
    }

    /**
     * Interacts with the user.
     *
     * This method is executed before the InputDefinition is validated.
     * This means that this is the only place where the command can
     * interactively ask for values of missing required arguments.
     *
     * @param InputInterface  $input  An InputInterface instance
     * @param OutputInterface $output An OutputInterface instance
     */
    protected function interact(InputInterface $input, OutputInterface $output)
    {
    }

    /**
     * Initializes the command just after the input has been validated.
     *
     * This is mainly useful when a lot of commands extends one main command
     * where some things need to be initialized based on the input arguments and options.
     *
     * @param InputInterface  $input  An InputInterface instance
     * @param OutputInterface $output An OutputInterface instance
     */
    protected function initialize(InputInterface $input, OutputInterface $output)
    {
    }

    /**
     * Runs the command.
     *
     * The code to execute is either defined directly with the
     * setCode() method or by overriding the execute() method
     * in a sub-class.
     *
     * @param InputInterface  $input  An InputInterface instance
     * @param OutputInterface $output An OutputInterface instance
     *
     * @return int The command exit code
     *
     * @throws \Exception
     *
     * @see setCode()
     * @see execute()
     *
     * @api
     */
    public function run(InputInterface $input, OutputInterface $output)
    {
        // force the creation of the synopsis before the merge with the app definition
        $this->getSynopsis();

        // add the application arguments and options
        $this->mergeApplicationDefinition();

        // bind the input against the command specific arguments/options
        try {
            $input->bind($this->definition);
        } catch (\Exception $e) {
            if (!$this->ignoreValidationErrors) {
                throw $e;
            }
        }

        $this->initialize($input, $output);

        if (null !== $this->processTitle) {
            if (function_exists('cli_set_process_title')) {
                cli_set_process_title($this->processTitle);
            } elseif (function_exists('setproctitle')) {
                setproctitle($this->processTitle);
            } elseif (OutputInterface::VERBOSITY_VERY_VERBOSE === $output->getVerbosity()) {
                $output->writeln('<comment>Install the proctitle PECL to be able to change the process title.</comment>');
            }
        }

        if ($input->isInteractive()) {
            $this->interact($input, $output);
        }

        $input->validate();

        if ($this->code) {
            $statusCode = call_user_func($this->code, $input, $output);
        } else {
            $statusCode = $this->execute($input, $output);
        }

        return is_numeric($statusCode) ? (int) $statusCode : 0;
    }

    /**
     * Sets the code to execute when running this command.
     *
     * If this method is used, it overrides the code defined
     * in the execute() method.
     *
     * @param callable $code A callable(InputInterface $input, OutputInterface $output)
     *
     * @return Command The current instance
     *
     * @throws \InvalidArgumentException
     *
     * @see execute()
     *
     * @api
     */
    public function setCode($code)
    {
        if (!is_callable($code)) {
            throw new \InvalidArgumentException('Invalid callable provided to Command::setCode.');
        }

        $this->code = $code;

        return $this;
    }

    /**
     * Merges the application definition with the command definition.
     *
     * This method is not part of public API and should not be used directly.
     *
     * @param bool $mergeArgs Whether to merge or not the Application definition arguments to Command definition arguments
     */
    public function mergeApplicationDefinition($mergeArgs = true)
    {
        if (null === $this->application || (true === $this->applicationDefinitionMerged && ($this->applicationDefinitionMergedWithArgs || !$mergeArgs))) {
            return;
        }

        if ($mergeArgs) {
            $currentArguments = $this->definition->getArguments();
            $this->definition->setArguments($this->application->getDefinition()->getArguments());
            $this->definition->addArguments($currentArguments);
        }

        $this->definition->addOptions($this->application->getDefinition()->getOptions());

        $this->applicationDefinitionMerged = true;
        if ($mergeArgs) {
            $this->applicationDefinitionMergedWithArgs = true;
        }
    }

    /**
     * Sets an array of argument and option instances.
     *
     * @param array|InputDefinition $definition An array of argument and option instances or a definition instance
     *
     * @return Command The current instance
     *
     * @api
     */
    public function setDefinition($definition)
    {
        if ($definition instanceof InputDefinition) {
            $this->definition = $definition;
        } else {
            $this->definition->setDefinition($definition);
        }

        $this->applicationDefinitionMerged = false;

        return $this;
    }

    /**
     * Gets the InputDefinition attached to this Command.
     *
     * @return InputDefinition An InputDefinition instance
     *
     * @api
     */
    public function getDefinition()
    {
        return $this->definition;
    }

    /**
     * Gets the InputDefinition to be used to create XML and Text representations of this Command.
     *
     * Can be overridden to provide the original command representation when it would otherwise
     * be changed by merging with the application InputDefinition.
     *
     * This method is not part of public API and should not be used directly.
     *
     * @return InputDefinition An InputDefinition instance
     */
    public function getNativeDefinition()
    {
        return $this->getDefinition();
    }

    /**
     * Adds an argument.
     *
     * @param string $name        The argument name
     * @param int    $mode        The argument mode: InputArgument::REQUIRED or InputArgument::OPTIONAL
     * @param string $description A description text
     * @param mixed  $default     The default value (for InputArgument::OPTIONAL mode only)
     *
     * @return Command The current instance
     *
     * @api
     */
    public function addArgument($name, $mode = null, $description = '', $default = null)
    {
        $this->definition->addArgument(new InputArgument($name, $mode, $description, $default));

        return $this;
    }

    /**
     * Adds an option.
     *
     * @param string $name        The option name
     * @param string $shortcut    The shortcut (can be null)
     * @param int    $mode        The option mode: One of the InputOption::VALUE_* constants
     * @param string $description A description text
     * @param mixed  $default     The default value (must be null for InputOption::VALUE_REQUIRED or InputOption::VALUE_NONE)
     *
     * @return Command The current instance
     *
     * @api
     */
    public function addOption($name, $shortcut = null, $mode = null, $description = '', $default = null)
    {
        $this->definition->addOption(new InputOption($name, $shortcut, $mode, $description, $default));

        return $this;
    }

    /**
     * Sets the name of the command.
     *
     * This method can set both the namespace and the name if
     * you separate them by a colon (:)
     *
     *     $command->setName('foo:bar');
     *
     * @param string $name The command name
     *
     * @return Command The current instance
     *
     * @throws \InvalidArgumentException When the name is invalid
     *
     * @api
     */
    public function setName($name)
    {
        $this->validateName($name);

        $this->name = $name;

        return $this;
    }

    /**
     * Sets the process title of the command.
     *
     * This feature should be used only when creating a long process command,
     * like a daemon.
     *
     * PHP 5.5+ or the proctitle PECL library is required
     *
     * @param string $title The process title
     *
     * @return Command The current instance
     */
    public function setProcessTitle($title)
    {
        $this->processTitle = $title;

        return $this;
    }

    /**
     * Returns the command name.
     *
     * @return string The command name
     *
     * @api
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Sets the description for the command.
     *
     * @param string $description The description for the command
     *
     * @return Command The current instance
     *
     * @api
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

    /**
     * Returns the description for the command.
     *
     * @return string The description for the command
     *
     * @api
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * Sets the help for the command.
     *
     * @param string $help The help for the command
     *
     * @return Command The current instance
     *
     * @api
     */
    public function setHelp($help)
    {
        $this->help = $help;

        return $this;
    }

    /**
     * Returns the help for the command.
     *
     * @return string The help for the command
     *
     * @api
     */
    public function getHelp()
    {
        return $this->help;
    }

    /**
     * Returns the processed help for the command replacing the %command.name% and
     * %command.full_name% patterns with the real values dynamically.
     *
     * @return string The processed help for the command
     */
    public function getProcessedHelp()
    {
        $name = $this->name;

        $placeholders = array(
            '%command.name%',
            '%command.full_name%',
        );
        $replacements = array(
            $name,
            $_SERVER['PHP_SELF'].' '.$name,
        );

        return str_replace($placeholders, $replacements, $this->getHelp());
    }

    /**
     * Sets the aliases for the command.
     *
     * @param string[] $aliases An array of aliases for the command
     *
     * @return Command The current instance
     *
     * @throws \InvalidArgumentException When an alias is invalid
     *
     * @api
     */
    public function setAliases($aliases)
    {
        if (!is_array($aliases) && !$aliases instanceof \Traversable) {
            throw new \InvalidArgumentException('$aliases must be an array or an instance of \Traversable');
        }

        foreach ($aliases as $alias) {
            $this->validateName($alias);
        }

        $this->aliases = $aliases;

        return $this;
    }

    /**
     * Returns the aliases for the command.
     *
     * @return array An array of aliases for the command
     *
     * @api
     */
    public function getAliases()
    {
        return $this->aliases;
    }

    /**
     * Returns the synopsis for the command.
     *
     * @return string The synopsis
     */
    public function getSynopsis()
    {
        if (null === $this->synopsis) {
            $this->synopsis = trim(sprintf('%s %s', $this->name, $this->definition->getSynopsis()));
        }

        return $this->synopsis;
    }

    /**
     * Gets a helper instance by name.
     *
     * @param string $name The helper name
     *
     * @return mixed The helper value
     *
     * @throws \InvalidArgumentException if the helper is not defined
     *
     * @api
     */
    public function getHelper($name)
    {
        return $this->helperSet->get($name);
    }

    /**
     * Returns a text representation of the command.
     *
     * @return string A string representing the command
     *
     * @deprecated Deprecated since version 2.3, to be removed in 3.0.
     */
    public function asText()
    {
        $descriptor = new TextDescriptor();
        $output = new BufferedOutput(BufferedOutput::VERBOSITY_NORMAL, true);
        $descriptor->describe($output, $this, array('raw_output' => true));

        return $output->fetch();
    }

    /**
     * Returns an XML representation of the command.
     *
     * @param bool $asDom Whether to return a DOM or an XML string
     *
     * @return string|\DOMDocument An XML string representing the command
     *
     * @deprecated Deprecated since version 2.3, to be removed in 3.0.
     */
    public function asXml($asDom = false)
    {
        $descriptor = new XmlDescriptor();

        if ($asDom) {
            return $descriptor->getCommandDocument($this);
        }

        $output = new BufferedOutput();
        $descriptor->describe($output, $this);

        return $output->fetch();
    }

    /**
     * Validates a command name.
     *
     * It must be non-empty and parts can optionally be separated by ":".
     *
     * @param string $name
     *
     * @throws \InvalidArgumentException When the name is invalid
     */
    private function validateName($name)
    {
        if (!preg_match('/^[^\:]++(\:[^\:]++)*$/', $name)) {
            throw new \InvalidArgumentException(sprintf('Command name "%s" is invalid.', $name));
        }
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Command;

use Symfony\Component\Console\Helper\DescriptorHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * HelpCommand displays the help for a given command.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class HelpCommand extends Command
{
    private $command;

    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        $this->ignoreValidationErrors();

        $this
            ->setName('help')
            ->setDefinition(array(
                new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'),
                new InputOption('xml', null, InputOption::VALUE_NONE, 'To output help as XML'),
                new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output help in other formats', 'txt'),
                new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command help'),
            ))
            ->setDescription('Displays help for a command')
            ->setHelp(<<<EOF
The <info>%command.name%</info> command displays help for a given command:

  <info>php %command.full_name% list</info>

You can also output the help in other formats by using the <comment>--format</comment> option:

  <info>php %command.full_name% --format=xml list</info>

To display the list of available commands, please use the <info>list</info> command.
EOF
            )
        ;
    }

    /**
     * Sets the command.
     *
     * @param Command $command The command to set
     */
    public function setCommand(Command $command)
    {
        $this->command = $command;
    }

    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        if (null === $this->command) {
            $this->command = $this->getApplication()->find($input->getArgument('command_name'));
        }

        if ($input->getOption('xml')) {
            $input->setOption('format', 'xml');
        }

        $helper = new DescriptorHelper();
        $helper->describe($output, $this->command, array(
            'format' => $input->getOption('format'),
            'raw_text' => $input->getOption('raw'),
        ));

        $this->command = null;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Command;

use Symfony\Component\Console\Helper\DescriptorHelper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputDefinition;

/**
 * ListCommand displays the list of all available commands for the application.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class ListCommand extends Command
{
    /**
     * {@inheritdoc}
     */
    protected function configure()
    {
        $this
            ->setName('list')
            ->setDefinition($this->createDefinition())
            ->setDescription('Lists commands')
            ->setHelp(<<<EOF
The <info>%command.name%</info> command lists all commands:

  <info>php %command.full_name%</info>

You can also display the commands for a specific namespace:

  <info>php %command.full_name% test</info>

You can also output the information in other formats by using the <comment>--format</comment> option:

  <info>php %command.full_name% --format=xml</info>

It's also possible to get raw list of commands (useful for embedding command runner):

  <info>php %command.full_name% --raw</info>
EOF
            )
        ;
    }

    /**
     * {@inheritdoc}
     */
    public function getNativeDefinition()
    {
        return $this->createDefinition();
    }

    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        if ($input->getOption('xml')) {
            $input->setOption('format', 'xml');
        }

        $helper = new DescriptorHelper();
        $helper->describe($output, $this->getApplication(), array(
            'format' => $input->getOption('format'),
            'raw_text' => $input->getOption('raw'),
            'namespace' => $input->getArgument('namespace'),
        ));
    }

    /**
     * {@inheritdoc}
     */
    private function createDefinition()
    {
        return new InputDefinition(array(
            new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
            new InputOption('xml', null, InputOption::VALUE_NONE, 'To output list as XML'),
            new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'),
            new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output list in other formats', 'txt'),
        ));
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Event;

/**
 * Allows to do things before the command is executed, like skipping the command or changing the input.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class ConsoleCommandEvent extends ConsoleEvent
{
    /**
     * The return code for skipped commands, this will also be passed into the terminate event
     */
    const RETURN_CODE_DISABLED = 113;

    /**
     * Indicates if the command should be run or skipped
     *
     * @var bool
     */
    private $commandShouldRun = true;

    /**
     * Disables the command, so it won't be run
     *
     * @return bool
     */
    public function disableCommand()
    {
        return $this->commandShouldRun = false;
    }

    /**
     * Enables the command
     *
     * @return bool
     */
    public function enableCommand()
    {
        return $this->commandShouldRun = true;
    }

    /**
     * Returns true if the command is runnable, false otherwise
     *
     * @return bool
     */
    public function commandShouldRun()
    {
        return $this->commandShouldRun;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Event;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\EventDispatcher\Event;

/**
 * Allows to inspect input and output of a command.
 *
 * @author Francesco Levorato <git@flevour.net>
 */
class ConsoleEvent extends Event
{
    protected $command;

    private $input;
    private $output;

    public function __construct(Command $command, InputInterface $input, OutputInterface $output)
    {
        $this->command = $command;
        $this->input = $input;
        $this->output = $output;
    }

    /**
     * Gets the command that is executed.
     *
     * @return Command A Command instance
     */
    public function getCommand()
    {
        return $this->command;
    }

    /**
     * Gets the input instance.
     *
     * @return InputInterface An InputInterface instance
     */
    public function getInput()
    {
        return $this->input;
    }

    /**
     * Gets the output instance.
     *
     * @return OutputInterface An OutputInterface instance
     */
    public function getOutput()
    {
        return $this->output;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Event;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * Allows to manipulate the exit code of a command after its execution.
 *
 * @author Francesco Levorato <git@flevour.net>
 */
class ConsoleTerminateEvent extends ConsoleEvent
{
    /**
     * The exit code of the command.
     *
     * @var int
     */
    private $exitCode;

    public function __construct(Command $command, InputInterface $input, OutputInterface $output, $exitCode)
    {
        parent::__construct($command, $input, $output);

        $this->setExitCode($exitCode);
    }

    /**
     * Sets the exit code.
     *
     * @param int $exitCode The command exit code
     */
    public function setExitCode($exitCode)
    {
        $this->exitCode = (int) $exitCode;
    }

    /**
     * Gets the exit code.
     *
     * @return int The command exit code
     */
    public function getExitCode()
    {
        return $this->exitCode;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Console\Event;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * Allows to handle exception thrown in a command.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class ConsoleExceptionEvent extends ConsoleEvent
{
    private $exception;
    private $exitCode;

    public function __construct(Command $command, InputInterface $input, OutputInterface $output, \Exception $exception, $exitCode)
    {
        parent::__construct($command, $input, $output);

        $this->setException($exception);
        $this->exitCode = (int) $exitCode;
    }

    /**
     * Returns the thrown exception.
     *
     * @return \Exception The thrown exception
     */
    public function getException()
    {
        return $this->exception;
    }

    /**
     * Replaces the thrown exception.
     *
     * This exception will be thrown if no response is set in the event.
     *
     * @param \Exception $exception The thrown exception
     */
    public function setException(\Exception $exception)
    {
        $this->exception = $exception;
    }

    /**
     * Gets the exit code.
     *
     * @return int The command exit code
     */
    public function getExitCode()
    {
        return $this->exitCode;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\EventDispatcher;

/**
 * The EventDispatcherInterface is the central point of Symfony's event listener system.
 *
 * Listeners are registered on the manager and events are dispatched through the
 * manager.
 *
 * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
 * @author Jonathan Wage <jonwage@gmail.com>
 * @author Roman Borschel <roman@code-factory.org>
 * @author Bernhard Schussek <bschussek@gmail.com>
 * @author Fabien Potencier <fabien@symfony.com>
 * @author Jordi Boggiano <j.boggiano@seld.be>
 * @author Jordan Alliot <jordan.alliot@gmail.com>
 *
 * @api
 */
class EventDispatcher implements EventDispatcherInterface
{
    private $listeners = array();
    private $sorted = array();

    /**
     * @see EventDispatcherInterface::dispatch()
     *
     * @api
     */
    public function dispatch($eventName, Event $event = null)
    {
        if (null === $event) {
            $event = new Event();
        }

        $event->setDispatcher($this);
        $event->setName($eventName);

        if (!isset($this->listeners[$eventName])) {
            return $event;
        }

        $this->doDispatch($this->getListeners($eventName), $eventName, $event);

        return $event;
    }

    /**
     * @see EventDispatcherInterface::getListeners()
     */
    public function getListeners($eventName = null)
    {
        if (null !== $eventName) {
            if (!isset($this->sorted[$eventName])) {
                $this->sortListeners($eventName);
            }

            return $this->sorted[$eventName];
        }

        foreach ($this->listeners as $eventName => $eventListeners) {
            if (!isset($this->sorted[$eventName])) {
                $this->sortListeners($eventName);
            }
        }

        return array_filter($this->sorted);
    }

    /**
     * @see EventDispatcherInterface::hasListeners()
     */
    public function hasListeners($eventName = null)
    {
        return (bool) count($this->getListeners($eventName));
    }

    /**
     * @see EventDispatcherInterface::addListener()
     *
     * @api
     */
    public function addListener($eventName, $listener, $priority = 0)
    {
        $this->listeners[$eventName][$priority][] = $listener;
        unset($this->sorted[$eventName]);
    }

    /**
     * @see EventDispatcherInterface::removeListener()
     */
    public function removeListener($eventName, $listener)
    {
        if (!isset($this->listeners[$eventName])) {
            return;
        }

        foreach ($this->listeners[$eventName] as $priority => $listeners) {
            if (false !== ($key = array_search($listener, $listeners, true))) {
                unset($this->listeners[$eventName][$priority][$key], $this->sorted[$eventName]);
            }
        }
    }

    /**
     * @see EventDispatcherInterface::addSubscriber()
     *
     * @api
     */
    public function addSubscriber(EventSubscriberInterface $subscriber)
    {
        foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
            if (is_string($params)) {
                $this->addListener($eventName, array($subscriber, $params));
            } elseif (is_string($params[0])) {
                $this->addListener($eventName, array($subscriber, $params[0]), isset($params[1]) ? $params[1] : 0);
            } else {
                foreach ($params as $listener) {
                    $this->addListener($eventName, array($subscriber, $listener[0]), isset($listener[1]) ? $listener[1] : 0);
                }
            }
        }
    }

    /**
     * @see EventDispatcherInterface::removeSubscriber()
     */
    public function removeSubscriber(EventSubscriberInterface $subscriber)
    {
        foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
            if (is_array($params) && is_array($params[0])) {
                foreach ($params as $listener) {
                    $this->removeListener($eventName, array($subscriber, $listener[0]));
                }
            } else {
                $this->removeListener($eventName, array($subscriber, is_string($params) ? $params : $params[0]));
            }
        }
    }

    /**
     * Triggers the listeners of an event.
     *
     * This method can be overridden to add functionality that is executed
     * for each listener.
     *
     * @param callable[] $listeners The event listeners.
     * @param string     $eventName The name of the event to dispatch.
     * @param Event      $event     The event object to pass to the event handlers/listeners.
     */
    protected function doDispatch($listeners, $eventName, Event $event)
    {
        foreach ($listeners as $listener) {
            call_user_func($listener, $event, $eventName, $this);
            if ($event->isPropagationStopped()) {
                break;
            }
        }
    }

    /**
     * Sorts the internal list of listeners for the given event by priority.
     *
     * @param string $eventName The name of the event.
     */
    private function sortListeners($eventName)
    {
        $this->sorted[$eventName] = array();

        if (isset($this->listeners[$eventName])) {
            krsort($this->listeners[$eventName]);
            $this->sorted[$eventName] = call_user_func_array('array_merge', $this->listeners[$eventName]);
        }
    }
}
Copyright (c) 2004-2015 Fabien Potencier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\EventDispatcher;

/**
 * An EventSubscriber knows himself what events he is interested in.
 * If an EventSubscriber is added to an EventDispatcherInterface, the manager invokes
 * {@link getSubscribedEvents} and registers the subscriber as a listener for all
 * returned events.
 *
 * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
 * @author Jonathan Wage <jonwage@gmail.com>
 * @author Roman Borschel <roman@code-factory.org>
 * @author Bernhard Schussek <bschussek@gmail.com>
 *
 * @api
 */
interface EventSubscriberInterface
{
    /**
     * Returns an array of event names this subscriber wants to listen to.
     *
     * The array keys are event names and the value can be:
     *
     *  * The method name to call (priority defaults to 0)
     *  * An array composed of the method name to call and the priority
     *  * An array of arrays composed of the method names to call and respective
     *    priorities, or 0 if unset
     *
     * For instance:
     *
     *  * array('eventName' => 'methodName')
     *  * array('eventName' => array('methodName', $priority))
     *  * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
     *
     * @return array The event names to listen to
     *
     * @api
     */
    public static function getSubscribedEvents();
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\EventDispatcher;

/**
 * Event is the base class for classes containing event data.
 *
 * This class contains no event data. It is used by events that do not pass
 * state information to an event handler when an event is raised.
 *
 * You can call the method stopPropagation() to abort the execution of
 * further listeners in your event listener.
 *
 * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
 * @author Jonathan Wage <jonwage@gmail.com>
 * @author Roman Borschel <roman@code-factory.org>
 * @author Bernhard Schussek <bschussek@gmail.com>
 *
 * @api
 */
class Event
{
    /**
     * @var bool Whether no further event listeners should be triggered
     */
    private $propagationStopped = false;

    /**
     * @var EventDispatcher Dispatcher that dispatched this event
     */
    private $dispatcher;

    /**
     * @var string This event's name
     */
    private $name;

    /**
     * Returns whether further event listeners should be triggered.
     *
     * @see Event::stopPropagation()
     *
     * @return bool Whether propagation was already stopped for this event.
     *
     * @api
     */
    public function isPropagationStopped()
    {
        return $this->propagationStopped;
    }

    /**
     * Stops the propagation of the event to further event listeners.
     *
     * If multiple event listeners are connected to the same event, no
     * further event listener will be triggered once any trigger calls
     * stopPropagation().
     *
     * @api
     */
    public function stopPropagation()
    {
        $this->propagationStopped = true;
    }

    /**
     * Stores the EventDispatcher that dispatches this Event.
     *
     * @param EventDispatcherInterface $dispatcher
     *
     * @deprecated Deprecated in 2.4, to be removed in 3.0. The event dispatcher is passed to the listener call.
     *
     * @api
     */
    public function setDispatcher(EventDispatcherInterface $dispatcher)
    {
        $this->dispatcher = $dispatcher;
    }

    /**
     * Returns the EventDispatcher that dispatches this Event.
     *
     * @return EventDispatcherInterface
     *
     * @deprecated Deprecated in 2.4, to be removed in 3.0. The event dispatcher is passed to the listener call.
     *
     * @api
     */
    public function getDispatcher()
    {
        return $this->dispatcher;
    }

    /**
     * Gets the event's name.
     *
     * @return string
     *
     * @deprecated Deprecated in 2.4, to be removed in 3.0. The event name is passed to the listener call.
     *
     * @api
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Sets the event's name property.
     *
     * @param string $name The event name.
     *
     * @deprecated Deprecated in 2.4, to be removed in 3.0. The event name is passed to the listener call.
     *
     * @api
     */
    public function setName($name)
    {
        $this->name = $name;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\EventDispatcher\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;

/**
 * Compiler pass to register tagged services for an event dispatcher.
 */
class RegisterListenersPass implements CompilerPassInterface
{
    /**
     * @var string
     */
    protected $dispatcherService;

    /**
     * @var string
     */
    protected $listenerTag;

    /**
     * @var string
     */
    protected $subscriberTag;

    /**
     * Constructor.
     *
     * @param string $dispatcherService Service name of the event dispatcher in processed container
     * @param string $listenerTag       Tag name used for listener
     * @param string $subscriberTag     Tag name used for subscribers
     */
    public function __construct($dispatcherService = 'event_dispatcher', $listenerTag = 'kernel.event_listener', $subscriberTag = 'kernel.event_subscriber')
    {
        $this->dispatcherService = $dispatcherService;
        $this->listenerTag = $listenerTag;
        $this->subscriberTag = $subscriberTag;
    }

    public function process(ContainerBuilder $container)
    {
        if (!$container->hasDefinition($this->dispatcherService) && !$container->hasAlias($this->dispatcherService)) {
            return;
        }

        $definition = $container->findDefinition($this->dispatcherService);

        foreach ($container->findTaggedServiceIds($this->listenerTag) as $id => $events) {
            $def = $container->getDefinition($id);
            if (!$def->isPublic()) {
                throw new \InvalidArgumentException(sprintf('The service "%s" must be public as event listeners are lazy-loaded.', $id));
            }

            if ($def->isAbstract()) {
                throw new \InvalidArgumentException(sprintf('The service "%s" must not be abstract as event listeners are lazy-loaded.', $id));
            }

            foreach ($events as $event) {
                $priority = isset($event['priority']) ? $event['priority'] : 0;

                if (!isset($event['event'])) {
                    throw new \InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "%s" tags.', $id, $this->listenerTag));
                }

                if (!isset($event['method'])) {
                    $event['method'] = 'on'.preg_replace_callback(array(
                        '/(?<=\b)[a-z]/i',
                        '/[^a-z0-9]/i',
                    ), function ($matches) { return strtoupper($matches[0]); }, $event['event']);
                    $event['method'] = preg_replace('/[^a-z0-9]/i', '', $event['method']);
                }

                $definition->addMethodCall('addListenerService', array($event['event'], array($id, $event['method']), $priority));
            }
        }

        foreach ($container->findTaggedServiceIds($this->subscriberTag) as $id => $attributes) {
            $def = $container->getDefinition($id);
            if (!$def->isPublic()) {
                throw new \InvalidArgumentException(sprintf('The service "%s" must be public as event subscribers are lazy-loaded.', $id));
            }

            if ($def->isAbstract()) {
                throw new \InvalidArgumentException(sprintf('The service "%s" must not be abstract as event subscribers are lazy-loaded.', $id));
            }

            // We must assume that the class value has been correctly filled, even if the service is created by a factory
            $class = $container->getParameterBag()->resolveValue($def->getClass());

            $refClass = new \ReflectionClass($class);
            $interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface';
            if (!$refClass->implementsInterface($interface)) {
                throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
            }

            $definition->addMethodCall('addSubscriberService', array($id, $class));
        }
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\EventDispatcher;

/**
 * The EventDispatcherInterface is the central point of Symfony's event listener system.
 * Listeners are registered on the manager and events are dispatched through the
 * manager.
 *
 * @author Bernhard Schussek <bschussek@gmail.com>
 *
 * @api
 */
interface EventDispatcherInterface
{
    /**
     * Dispatches an event to all registered listeners.
     *
     * @param string $eventName The name of the event to dispatch. The name of
     *                          the event is the name of the method that is
     *                          invoked on listeners.
     * @param Event  $event     The event to pass to the event handlers/listeners.
     *                          If not supplied, an empty Event instance is created.
     *
     * @return Event
     *
     * @api
     */
    public function dispatch($eventName, Event $event = null);

    /**
     * Adds an event listener that listens on the specified events.
     *
     * @param string   $eventName The event to listen on
     * @param callable $listener  The listener
     * @param int      $priority  The higher this value, the earlier an event
     *                            listener will be triggered in the chain (defaults to 0)
     *
     * @api
     */
    public function addListener($eventName, $listener, $priority = 0);

    /**
     * Adds an event subscriber.
     *
     * The subscriber is asked for all the events he is
     * interested in and added as a listener for these events.
     *
     * @param EventSubscriberInterface $subscriber The subscriber.
     *
     * @api
     */
    public function addSubscriber(EventSubscriberInterface $subscriber);

    /**
     * Removes an event listener from the specified events.
     *
     * @param string   $eventName The event to remove a listener from
     * @param callable $listener  The listener to remove
     */
    public function removeListener($eventName, $listener);

    /**
     * Removes an event subscriber.
     *
     * @param EventSubscriberInterface $subscriber The subscriber
     */
    public function removeSubscriber(EventSubscriberInterface $subscriber);

    /**
     * Gets the listeners of a specific event or all listeners sorted by descending priority.
     *
     * @param string $eventName The name of the event
     *
     * @return array The event listeners for the specified event, or all event listeners by event name
     */
    public function getListeners($eventName = null);

    /**
     * Checks whether an event has any registered listeners.
     *
     * @param string $eventName The name of the event
     *
     * @return bool true if the specified event has any listeners, false otherwise
     */
    public function hasListeners($eventName = null);
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\EventDispatcher;

use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Lazily loads listeners and subscribers from the dependency injection
 * container.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 * @author Bernhard Schussek <bschussek@gmail.com>
 * @author Jordan Alliot <jordan.alliot@gmail.com>
 */
class ContainerAwareEventDispatcher extends EventDispatcher
{
    /**
     * The container from where services are loaded.
     *
     * @var ContainerInterface
     */
    private $container;

    /**
     * The service IDs of the event listeners and subscribers.
     *
     * @var array
     */
    private $listenerIds = array();

    /**
     * The services registered as listeners.
     *
     * @var array
     */
    private $listeners = array();

    /**
     * Constructor.
     *
     * @param ContainerInterface $container A ContainerInterface instance
     */
    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    /**
     * Adds a service as event listener.
     *
     * @param string $eventName Event for which the listener is added
     * @param array  $callback  The service ID of the listener service & the method
     *                          name that has to be called
     * @param int    $priority  The higher this value, the earlier an event listener
     *                          will be triggered in the chain.
     *                          Defaults to 0.
     *
     * @throws \InvalidArgumentException
     */
    public function addListenerService($eventName, $callback, $priority = 0)
    {
        if (!is_array($callback) || 2 !== count($callback)) {
            throw new \InvalidArgumentException('Expected an array("service", "method") argument');
        }

        $this->listenerIds[$eventName][] = array($callback[0], $callback[1], $priority);
    }

    public function removeListener($eventName, $listener)
    {
        $this->lazyLoad($eventName);

        if (isset($this->listenerIds[$eventName])) {
            foreach ($this->listenerIds[$eventName] as $i => $args) {
                list($serviceId, $method, $priority) = $args;
                $key = $serviceId.'.'.$method;
                if (isset($this->listeners[$eventName][$key]) && $listener === array($this->listeners[$eventName][$key], $method)) {
                    unset($this->listeners[$eventName][$key]);
                    if (empty($this->listeners[$eventName])) {
                        unset($this->listeners[$eventName]);
                    }
                    unset($this->listenerIds[$eventName][$i]);
                    if (empty($this->listenerIds[$eventName])) {
                        unset($this->listenerIds[$eventName]);
                    }
                }
            }
        }

        parent::removeListener($eventName, $listener);
    }

    /**
     * @see EventDispatcherInterface::hasListeners()
     */
    public function hasListeners($eventName = null)
    {
        if (null === $eventName) {
            return (bool) count($this->listenerIds) || (bool) count($this->listeners);
        }

        if (isset($this->listenerIds[$eventName])) {
            return true;
        }

        return parent::hasListeners($eventName);
    }

    /**
     * @see EventDispatcherInterface::getListeners()
     */
    public function getListeners($eventName = null)
    {
        if (null === $eventName) {
            foreach ($this->listenerIds as $serviceEventName => $args) {
                $this->lazyLoad($serviceEventName);
            }
        } else {
            $this->lazyLoad($eventName);
        }

        return parent::getListeners($eventName);
    }

    /**
     * Adds a service as event subscriber.
     *
     * @param string $serviceId The service ID of the subscriber service
     * @param string $class     The service's class name (which must implement EventSubscriberInterface)
     */
    public function addSubscriberService($serviceId, $class)
    {
        foreach ($class::getSubscribedEvents() as $eventName => $params) {
            if (is_string($params)) {
                $this->listenerIds[$eventName][] = array($serviceId, $params, 0);
            } elseif (is_string($params[0])) {
                $this->listenerIds[$eventName][] = array($serviceId, $params[0], isset($params[1]) ? $params[1] : 0);
            } else {
                foreach ($params as $listener) {
                    $this->listenerIds[$eventName][] = array($serviceId, $listener[0], isset($listener[1]) ? $listener[1] : 0);
                }
            }
        }
    }

    /**
     * {@inheritdoc}
     *
     * Lazily loads listeners for this event from the dependency injection
     * container.
     *
     * @throws \InvalidArgumentException if the service is not defined
     */
    public function dispatch($eventName, Event $event = null)
    {
        $this->lazyLoad($eventName);

        return parent::dispatch($eventName, $event);
    }

    public function getContainer()
    {
        return $this->container;
    }

    /**
     * Lazily loads listeners for this event from the dependency injection
     * container.
     *
     * @param string $eventName The name of the event to dispatch. The name of
     *                          the event is the name of the method that is
     *                          invoked on listeners.
     */
    protected function lazyLoad($eventName)
    {
        if (isset($this->listenerIds[$eventName])) {
            foreach ($this->listenerIds[$eventName] as $args) {
                list($serviceId, $method, $priority) = $args;
                $listener = $this->container->get($serviceId);

                $key = $serviceId.'.'.$method;
                if (!isset($this->listeners[$eventName][$key])) {
                    $this->addListener($eventName, array($listener, $method), $priority);
                } elseif ($listener !== $this->listeners[$eventName][$key]) {
                    parent::removeListener($eventName, array($this->listeners[$eventName][$key], $method));
                    $this->addListener($eventName, array($listener, $method), $priority);
                }

                $this->listeners[$eventName][$key] = $listener;
            }
        }
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\EventDispatcher\Debug;

use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
 * @author Fabien Potencier <fabien@symfony.com>
 */
class WrappedListener
{
    private $listener;
    private $name;
    private $called;
    private $stoppedPropagation;
    private $stopwatch;
    private $dispatcher;

    public function __construct($listener, $name, Stopwatch $stopwatch, EventDispatcherInterface $dispatcher = null)
    {
        $this->listener = $listener;
        $this->name = $name;
        $this->stopwatch = $stopwatch;
        $this->dispatcher = $dispatcher;
        $this->called = false;
        $this->stoppedPropagation = false;
    }

    public function getWrappedListener()
    {
        return $this->listener;
    }

    public function wasCalled()
    {
        return $this->called;
    }

    public function stoppedPropagation()
    {
        return $this->stoppedPropagation;
    }

    public function __invoke(Event $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        $this->called = true;

        $e = $this->stopwatch->start($this->name, 'event_listener');

        call_user_func($this->listener, $event, $eventName, $this->dispatcher ?: $dispatcher);

        if ($e->isStarted()) {
            $e->stop();
        }

        if ($event->isPropagationStopped()) {
            $this->stoppedPropagation = true;
        }
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\EventDispatcher\Debug;

use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\Stopwatch\Stopwatch;
use Psr\Log\LoggerInterface;

/**
 * Collects some data about event listeners.
 *
 * This event dispatcher delegates the dispatching to another one.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class TraceableEventDispatcher implements TraceableEventDispatcherInterface
{
    protected $logger;
    protected $stopwatch;

    private $called;
    private $dispatcher;
    private $wrappedListeners;

    /**
     * Constructor.
     *
     * @param EventDispatcherInterface $dispatcher An EventDispatcherInterface instance
     * @param Stopwatch                $stopwatch  A Stopwatch instance
     * @param LoggerInterface          $logger     A LoggerInterface instance
     */
    public function __construct(EventDispatcherInterface $dispatcher, Stopwatch $stopwatch, LoggerInterface $logger = null)
    {
        $this->dispatcher = $dispatcher;
        $this->stopwatch = $stopwatch;
        $this->logger = $logger;
        $this->called = array();
        $this->wrappedListeners = array();
    }

    /**
     * {@inheritdoc}
     */
    public function addListener($eventName, $listener, $priority = 0)
    {
        $this->dispatcher->addListener($eventName, $listener, $priority);
    }

    /**
     * {@inheritdoc}
     */
    public function addSubscriber(EventSubscriberInterface $subscriber)
    {
        $this->dispatcher->addSubscriber($subscriber);
    }

    /**
     * {@inheritdoc}
     */
    public function removeListener($eventName, $listener)
    {
        if (isset($this->wrappedListeners[$eventName])) {
            foreach ($this->wrappedListeners[$eventName] as $index => $wrappedListener) {
                if ($wrappedListener->getWrappedListener() === $listener) {
                    $listener = $wrappedListener;
                    unset($this->wrappedListeners[$eventName][$index]);
                    break;
                }
            }
        }

        return $this->dispatcher->removeListener($eventName, $listener);
    }

    /**
     * {@inheritdoc}
     */
    public function removeSubscriber(EventSubscriberInterface $subscriber)
    {
        return $this->dispatcher->removeSubscriber($subscriber);
    }

    /**
     * {@inheritdoc}
     */
    public function getListeners($eventName = null)
    {
        return $this->dispatcher->getListeners($eventName);
    }

    /**
     * {@inheritdoc}
     */
    public function hasListeners($eventName = null)
    {
        return $this->dispatcher->hasListeners($eventName);
    }

    /**
     * {@inheritdoc}
     */
    public function dispatch($eventName, Event $event = null)
    {
        if (null === $event) {
            $event = new Event();
        }

        $this->preProcess($eventName);
        $this->preDispatch($eventName, $event);

        $e = $this->stopwatch->start($eventName, 'section');

        $this->dispatcher->dispatch($eventName, $event);

        if ($e->isStarted()) {
            $e->stop();
        }

        $this->postDispatch($eventName, $event);
        $this->postProcess($eventName);

        return $event;
    }

    /**
     * {@inheritdoc}
     */
    public function getCalledListeners()
    {
        $called = array();
        foreach ($this->called as $eventName => $listeners) {
            foreach ($listeners as $listener) {
                $info = $this->getListenerInfo($listener->getWrappedListener(), $eventName);
                $called[$eventName.'.'.$info['pretty']] = $info;
            }
        }

        return $called;
    }

    /**
     * {@inheritdoc}
     */
    public function getNotCalledListeners()
    {
        try {
            $allListeners = $this->getListeners();
        } catch (\Exception $e) {
            if (null !== $this->logger) {
                $this->logger->info(sprintf('An exception was thrown while getting the uncalled listeners (%s)', $e->getMessage()), array('exception' => $e));
            }

            // unable to retrieve the uncalled listeners
            return array();
        }

        $notCalled = array();
        foreach ($allListeners as $eventName => $listeners) {
            foreach ($listeners as $listener) {
                $called = false;
                if (isset($this->called[$eventName])) {
                    foreach ($this->called[$eventName] as $l) {
                        if ($l->getWrappedListener() === $listener) {
                            $called = true;

                            break;
                        }
                    }
                }

                if (!$called) {
                    $info = $this->getListenerInfo($listener, $eventName);
                    $notCalled[$eventName.'.'.$info['pretty']] = $info;
                }
            }
        }

        return $notCalled;
    }

    /**
     * Proxies all method calls to the original event dispatcher.
     *
     * @param string $method    The method name
     * @param array  $arguments The method arguments
     *
     * @return mixed
     */
    public function __call($method, $arguments)
    {
        return call_user_func_array(array($this->dispatcher, $method), $arguments);
    }

    /**
     * Called before dispatching the event.
     *
     * @param string $eventName The event name
     * @param Event  $event     The event
     */
    protected function preDispatch($eventName, Event $event)
    {
    }

    /**
     * Called after dispatching the event.
     *
     * @param string $eventName The event name
     * @param Event  $event     The event
     */
    protected function postDispatch($eventName, Event $event)
    {
    }

    private function preProcess($eventName)
    {
        foreach ($this->dispatcher->getListeners($eventName) as $listener) {
            $this->dispatcher->removeListener($eventName, $listener);
            $info = $this->getListenerInfo($listener, $eventName);
            $name = isset($info['class']) ? $info['class'] : $info['type'];
            $wrappedListener = new WrappedListener($listener, $name, $this->stopwatch, $this);
            $this->wrappedListeners[$eventName][] = $wrappedListener;
            $this->dispatcher->addListener($eventName, $wrappedListener);
        }
    }

    private function postProcess($eventName)
    {
        unset($this->wrappedListeners[$eventName]);
        $skipped = false;
        foreach ($this->dispatcher->getListeners($eventName) as $listener) {
            if (!$listener instanceof WrappedListener) { // #12845: a new listener was added during dispatch.
                continue;
            }
            // Unwrap listener
            $this->dispatcher->removeListener($eventName, $listener);
            $this->dispatcher->addListener($eventName, $listener->getWrappedListener());

            $info = $this->getListenerInfo($listener->getWrappedListener(), $eventName);
            if ($listener->wasCalled()) {
                if (null !== $this->logger) {
                    $this->logger->debug(sprintf('Notified event "%s" to listener "%s".', $eventName, $info['pretty']));
                }

                if (!isset($this->called[$eventName])) {
                    $this->called[$eventName] = new \SplObjectStorage();
                }

                $this->called[$eventName]->attach($listener);
            }

            if (null !== $this->logger && $skipped) {
                $this->logger->debug(sprintf('Listener "%s" was not called for event "%s".', $info['pretty'], $eventName));
            }

            if ($listener->stoppedPropagation()) {
                if (null !== $this->logger) {
                    $this->logger->debug(sprintf('Listener "%s" stopped propagation of the event "%s".', $info['pretty'], $eventName));
                }

                $skipped = true;
            }
        }
    }

    /**
     * Returns information about the listener.
     *
     * @param object $listener  The listener
     * @param string $eventName The event name
     *
     * @return array Information about the listener
     */
    private function getListenerInfo($listener, $eventName)
    {
        $info = array(
            'event' => $eventName,
        );
        if ($listener instanceof \Closure) {
            $info += array(
                'type' => 'Closure',
                'pretty' => 'closure',
            );
        } elseif (is_string($listener)) {
            try {
                $r = new \ReflectionFunction($listener);
                $file = $r->getFileName();
                $line = $r->getStartLine();
            } catch (\ReflectionException $e) {
                $file = null;
                $line = null;
            }
            $info += array(
                'type' => 'Function',
                'function' => $listener,
                'file' => $file,
                'line' => $line,
                'pretty' => $listener,
            );
        } elseif (is_array($listener) || (is_object($listener) && is_callable($listener))) {
            if (!is_array($listener)) {
                $listener = array($listener, '__invoke');
            }
            $class = is_object($listener[0]) ? get_class($listener[0]) : $listener[0];
            try {
                $r = new \ReflectionMethod($class, $listener[1]);
                $file = $r->getFileName();
                $line = $r->getStartLine();
            } catch (\ReflectionException $e) {
                $file = null;
                $line = null;
            }
            $info += array(
                'type' => 'Method',
                'class' => $class,
                'method' => $listener[1],
                'file' => $file,
                'line' => $line,
                'pretty' => $class.'::'.$listener[1],
            );
        }

        return $info;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\EventDispatcher\Debug;

use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
 * @author Fabien Potencier <fabien@symfony.com>
 */
interface TraceableEventDispatcherInterface extends EventDispatcherInterface
{
    /**
     * Gets the called listeners.
     *
     * @return array An array of called listeners
     */
    public function getCalledListeners();

    /**
     * Gets the not called listeners.
     *
     * @return array An array of not called listeners
     */
    public function getNotCalledListeners();
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\EventDispatcher;

/**
 * A read-only proxy for an event dispatcher.
 *
 * @author Bernhard Schussek <bschussek@gmail.com>
 */
class ImmutableEventDispatcher implements EventDispatcherInterface
{
    /**
     * The proxied dispatcher.
     *
     * @var EventDispatcherInterface
     */
    private $dispatcher;

    /**
     * Creates an unmodifiable proxy for an event dispatcher.
     *
     * @param EventDispatcherInterface $dispatcher The proxied event dispatcher.
     */
    public function __construct(EventDispatcherInterface $dispatcher)
    {
        $this->dispatcher = $dispatcher;
    }

    /**
     * {@inheritdoc}
     */
    public function dispatch($eventName, Event $event = null)
    {
        return $this->dispatcher->dispatch($eventName, $event);
    }

    /**
     * {@inheritdoc}
     */
    public function addListener($eventName, $listener, $priority = 0)
    {
        throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
    }

    /**
     * {@inheritdoc}
     */
    public function addSubscriber(EventSubscriberInterface $subscriber)
    {
        throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
    }

    /**
     * {@inheritdoc}
     */
    public function removeListener($eventName, $listener)
    {
        throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
    }

    /**
     * {@inheritdoc}
     */
    public function removeSubscriber(EventSubscriberInterface $subscriber)
    {
        throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
    }

    /**
     * {@inheritdoc}
     */
    public function getListeners($eventName = null)
    {
        return $this->dispatcher->getListeners($eventName);
    }

    /**
     * {@inheritdoc}
     */
    public function hasListeners($eventName = null)
    {
        return $this->dispatcher->hasListeners($eventName);
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\EventDispatcher;

/**
 * Event encapsulation class.
 *
 * Encapsulates events thus decoupling the observer from the subject they encapsulate.
 *
 * @author Drak <drak@zikula.org>
 */
class GenericEvent extends Event implements \ArrayAccess, \IteratorAggregate
{
    /**
     * Event subject.
     *
     * @var mixed usually object or callable
     */
    protected $subject;

    /**
     * Array of arguments.
     *
     * @var array
     */
    protected $arguments;

    /**
     * Encapsulate an event with $subject and $args.
     *
     * @param mixed $subject   The subject of the event, usually an object.
     * @param array $arguments Arguments to store in the event.
     */
    public function __construct($subject = null, array $arguments = array())
    {
        $this->subject = $subject;
        $this->arguments = $arguments;
    }

    /**
     * Getter for subject property.
     *
     * @return mixed $subject The observer subject.
     */
    public function getSubject()
    {
        return $this->subject;
    }

    /**
     * Get argument by key.
     *
     * @param string $key Key.
     *
     * @throws \InvalidArgumentException If key is not found.
     *
     * @return mixed Contents of array key.
     */
    public function getArgument($key)
    {
        if ($this->hasArgument($key)) {
            return $this->arguments[$key];
        }

        throw new \InvalidArgumentException(sprintf('%s not found in %s', $key, $this->getName()));
    }

    /**
     * Add argument to event.
     *
     * @param string $key   Argument name.
     * @param mixed  $value Value.
     *
     * @return GenericEvent
     */
    public function setArgument($key, $value)
    {
        $this->arguments[$key] = $value;

        return $this;
    }

    /**
     * Getter for all arguments.
     *
     * @return array
     */
    public function getArguments()
    {
        return $this->arguments;
    }

    /**
     * Set args property.
     *
     * @param array $args Arguments.
     *
     * @return GenericEvent
     */
    public function setArguments(array $args = array())
    {
        $this->arguments = $args;

        return $this;
    }

    /**
     * Has argument.
     *
     * @param string $key Key of arguments array.
     *
     * @return bool
     */
    public function hasArgument($key)
    {
        return array_key_exists($key, $this->arguments);
    }

    /**
     * ArrayAccess for argument getter.
     *
     * @param string $key Array key.
     *
     * @throws \InvalidArgumentException If key does not exist in $this->args.
     *
     * @return mixed
     */
    public function offsetGet($key)
    {
        return $this->getArgument($key);
    }

    /**
     * ArrayAccess for argument setter.
     *
     * @param string $key   Array key to set.
     * @param mixed  $value Value.
     */
    public function offsetSet($key, $value)
    {
        $this->setArgument($key, $value);
    }

    /**
     * ArrayAccess for unset argument.
     *
     * @param string $key Array key.
     */
    public function offsetUnset($key)
    {
        if ($this->hasArgument($key)) {
            unset($this->arguments[$key]);
        }
    }

    /**
     * ArrayAccess has argument.
     *
     * @param string $key Array key.
     *
     * @return bool
     */
    public function offsetExists($key)
    {
        return $this->hasArgument($key);
    }

    /**
     * IteratorAggregate for iterating over the object like an array.
     *
     * @return \ArrayIterator
     */
    public function getIterator()
    {
        return new \ArrayIterator($this->arguments);
    }
}
Copyright (c) 2004-2015 Fabien Potencier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Exception;

/**
 * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
 */
class AccessDeniedException extends \UnexpectedValueException
{
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Exception;

/**
 * @author Jean-François Simon <contact@jfsimon.fr>
 */
interface ExceptionInterface
{
    /**
     * @return \Symfony\Component\Finder\Adapter\AdapterInterface
     */
    public function getAdapter();
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Exception;

/**
 * @author Jean-François Simon <contact@jfsimon.fr>
 */
class OperationNotPermitedException extends AdapterFailureException
{
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Exception;

use Symfony\Component\Finder\Adapter\AdapterInterface;
use Symfony\Component\Finder\Shell\Command;

/**
 * @author Jean-François Simon <contact@jfsimon.fr>
 */
class ShellCommandFailureException extends AdapterFailureException
{
    /**
     * @var Command
     */
    private $command;

    /**
     * @param AdapterInterface $adapter
     * @param Command          $command
     * @param \Exception|null  $previous
     */
    public function __construct(AdapterInterface $adapter, Command $command, \Exception $previous = null)
    {
        $this->command = $command;
        parent::__construct($adapter, 'Shell command failed: "'.$command->join().'".', $previous);
    }

    /**
     * @return Command
     */
    public function getCommand()
    {
        return $this->command;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Exception;

use Symfony\Component\Finder\Adapter\AdapterInterface;

/**
 * Base exception for all adapter failures.
 *
 * @author Jean-François Simon <contact@jfsimon.fr>
 */
class AdapterFailureException extends \RuntimeException implements ExceptionInterface
{
    /**
     * @var \Symfony\Component\Finder\Adapter\AdapterInterface
     */
    private $adapter;

    /**
     * @param AdapterInterface $adapter
     * @param string|null      $message
     * @param \Exception|null  $previous
     */
    public function __construct(AdapterInterface $adapter, $message = null, \Exception $previous = null)
    {
        $this->adapter = $adapter;
        parent::__construct($message ?: 'Search failed with "'.$adapter->getName().'" adapter.', $previous);
    }

    /**
     * {@inheritdoc}
     */
    public function getAdapter()
    {
        return $this->adapter;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder;

/**
 * Glob matches globbing patterns against text.
 *
 *   if match_glob("foo.*", "foo.bar") echo "matched\n";
 *
 * // prints foo.bar and foo.baz
 * $regex = glob_to_regex("foo.*");
 * for (array('foo.bar', 'foo.baz', 'foo', 'bar') as $t)
 * {
 *   if (/$regex/) echo "matched: $car\n";
 * }
 *
 * Glob implements glob(3) style matching that can be used to match
 * against text, rather than fetching names from a filesystem.
 *
 * Based on the Perl Text::Glob module.
 *
 * @author Fabien Potencier <fabien@symfony.com> PHP port
 * @author     Richard Clamp <richardc@unixbeard.net> Perl version
 * @copyright  2004-2005 Fabien Potencier <fabien@symfony.com>
 * @copyright  2002 Richard Clamp <richardc@unixbeard.net>
 */
class Glob
{
    /**
     * Returns a regexp which is the equivalent of the glob pattern.
     *
     * @param string $glob                The glob pattern
     * @param bool   $strictLeadingDot
     * @param bool   $strictWildcardSlash
     *
     * @return string regex The regexp
     */
    public static function toRegex($glob, $strictLeadingDot = true, $strictWildcardSlash = true)
    {
        $firstByte = true;
        $escaping = false;
        $inCurlies = 0;
        $regex = '';
        $sizeGlob = strlen($glob);
        for ($i = 0; $i < $sizeGlob; ++$i) {
            $car = $glob[$i];
            if ($firstByte) {
                if ($strictLeadingDot && '.' !== $car) {
                    $regex .= '(?=[^\.])';
                }

                $firstByte = false;
            }

            if ('/' === $car) {
                $firstByte = true;
            }

            if ('.' === $car || '(' === $car || ')' === $car || '|' === $car || '+' === $car || '^' === $car || '$' === $car) {
                $regex .= "\\$car";
            } elseif ('*' === $car) {
                $regex .= $escaping ? '\\*' : ($strictWildcardSlash ? '[^/]*' : '.*');
            } elseif ('?' === $car) {
                $regex .= $escaping ? '\\?' : ($strictWildcardSlash ? '[^/]' : '.');
            } elseif ('{' === $car) {
                $regex .= $escaping ? '\\{' : '(';
                if (!$escaping) {
                    ++$inCurlies;
                }
            } elseif ('}' === $car && $inCurlies) {
                $regex .= $escaping ? '}' : ')';
                if (!$escaping) {
                    --$inCurlies;
                }
            } elseif (',' === $car && $inCurlies) {
                $regex .= $escaping ? ',' : '|';
            } elseif ('\\' === $car) {
                if ($escaping) {
                    $regex .= '\\\\';
                    $escaping = false;
                } else {
                    $escaping = true;
                }

                continue;
            } else {
                $regex .= $car;
            }
            $escaping = false;
        }

        return '#^'.$regex.'$#';
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Expression;

/**
 * @author Jean-François Simon <contact@jfsimon.fr>
 */
class Regex implements ValueInterface
{
    const START_FLAG = '^';
    const END_FLAG = '$';
    const BOUNDARY = '~';
    const JOKER = '.*';
    const ESCAPING = '\\';

    /**
     * @var string
     */
    private $pattern;

    /**
     * @var array
     */
    private $options;

    /**
     * @var bool
     */
    private $startFlag;

    /**
     * @var bool
     */
    private $endFlag;

    /**
     * @var bool
     */
    private $startJoker;

    /**
     * @var bool
     */
    private $endJoker;

    /**
     * @param string $expr
     *
     * @return Regex
     *
     * @throws \InvalidArgumentException
     */
    public static function create($expr)
    {
        if (preg_match('/^(.{3,}?)([imsxuADU]*)$/', $expr, $m)) {
            $start = substr($m[1], 0, 1);
            $end = substr($m[1], -1);

            if (
                ($start === $end && !preg_match('/[*?[:alnum:] \\\\]/', $start))
                || ($start === '{' && $end === '}')
                || ($start === '(' && $end === ')')
            ) {
                return new self(substr($m[1], 1, -1), $m[2], $end);
            }
        }

        throw new \InvalidArgumentException('Given expression is not a regex.');
    }

    /**
     * @param string $pattern
     * @param string $options
     * @param string $delimiter
     */
    public function __construct($pattern, $options = '', $delimiter = null)
    {
        if (null !== $delimiter) {
            // removes delimiter escaping
            $pattern = str_replace('\\'.$delimiter, $delimiter, $pattern);
        }

        $this->parsePattern($pattern);
        $this->options = $options;
    }

    /**
     * @return string
     */
    public function __toString()
    {
        return $this->render();
    }

    /**
     * {@inheritdoc}
     */
    public function render()
    {
        return self::BOUNDARY
            .$this->renderPattern()
            .self::BOUNDARY
            .$this->options;
    }

    /**
     * {@inheritdoc}
     */
    public function renderPattern()
    {
        return ($this->startFlag ? self::START_FLAG : '')
            .($this->startJoker ? self::JOKER : '')
            .str_replace(self::BOUNDARY, '\\'.self::BOUNDARY, $this->pattern)
            .($this->endJoker ? self::JOKER : '')
            .($this->endFlag ? self::END_FLAG : '');
    }

    /**
     * {@inheritdoc}
     */
    public function isCaseSensitive()
    {
        return !$this->hasOption('i');
    }

    /**
     * {@inheritdoc}
     */
    public function getType()
    {
        return Expression::TYPE_REGEX;
    }

    /**
     * {@inheritdoc}
     */
    public function prepend($expr)
    {
        $this->pattern = $expr.$this->pattern;

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function append($expr)
    {
        $this->pattern .= $expr;

        return $this;
    }

    /**
     * @param string $option
     *
     * @return bool
     */
    public function hasOption($option)
    {
        return false !== strpos($this->options, $option);
    }

    /**
     * @param string $option
     *
     * @return Regex
     */
    public function addOption($option)
    {
        if (!$this->hasOption($option)) {
            $this->options .= $option;
        }

        return $this;
    }

    /**
     * @param string $option
     *
     * @return Regex
     */
    public function removeOption($option)
    {
        $this->options = str_replace($option, '', $this->options);

        return $this;
    }

    /**
     * @param bool $startFlag
     *
     * @return Regex
     */
    public function setStartFlag($startFlag)
    {
        $this->startFlag = $startFlag;

        return $this;
    }

    /**
     * @return bool
     */
    public function hasStartFlag()
    {
        return $this->startFlag;
    }

    /**
     * @param bool $endFlag
     *
     * @return Regex
     */
    public function setEndFlag($endFlag)
    {
        $this->endFlag = (bool) $endFlag;

        return $this;
    }

    /**
     * @return bool
     */
    public function hasEndFlag()
    {
        return $this->endFlag;
    }

    /**
     * @param bool $startJoker
     *
     * @return Regex
     */
    public function setStartJoker($startJoker)
    {
        $this->startJoker = $startJoker;

        return $this;
    }

    /**
     * @return bool
     */
    public function hasStartJoker()
    {
        return $this->startJoker;
    }

    /**
     * @param bool $endJoker
     *
     * @return Regex
     */
    public function setEndJoker($endJoker)
    {
        $this->endJoker = (bool) $endJoker;

        return $this;
    }

    /**
     * @return bool
     */
    public function hasEndJoker()
    {
        return $this->endJoker;
    }

    /**
     * @param array $replacement
     *
     * @return Regex
     */
    public function replaceJokers($replacement)
    {
        $replace = function ($subject) use ($replacement) {
            $subject = $subject[0];
            $replace = 0 === substr_count($subject, '\\') % 2;

            return $replace ? str_replace('.', $replacement, $subject) : $subject;
        };

        $this->pattern = preg_replace_callback('~[\\\\]*\\.~', $replace, $this->pattern);

        return $this;
    }

    /**
     * @param string $pattern
     */
    private function parsePattern($pattern)
    {
        if ($this->startFlag = self::START_FLAG === substr($pattern, 0, 1)) {
            $pattern = substr($pattern, 1);
        }

        if ($this->startJoker = self::JOKER === substr($pattern, 0, 2)) {
            $pattern = substr($pattern, 2);
        }

        if ($this->endFlag = (self::END_FLAG === substr($pattern, -1) && self::ESCAPING !== substr($pattern, -2, -1))) {
            $pattern = substr($pattern, 0, -1);
        }

        if ($this->endJoker = (self::JOKER === substr($pattern, -2) && self::ESCAPING !== substr($pattern, -3, -2))) {
            $pattern = substr($pattern, 0, -2);
        }

        $this->pattern = $pattern;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Expression;

/**
 * @author Jean-François Simon <contact@jfsimon.fr>
 */
class Expression implements ValueInterface
{
    const TYPE_REGEX = 1;
    const TYPE_GLOB = 2;

    /**
     * @var ValueInterface
     */
    private $value;

    /**
     * @param string $expr
     *
     * @return Expression
     */
    public static function create($expr)
    {
        return new self($expr);
    }

    /**
     * @param string $expr
     */
    public function __construct($expr)
    {
        try {
            $this->value = Regex::create($expr);
        } catch (\InvalidArgumentException $e) {
            $this->value = new Glob($expr);
        }
    }

    /**
     * @return string
     */
    public function __toString()
    {
        return $this->render();
    }

    /**
     * {@inheritdoc}
     */
    public function render()
    {
        return $this->value->render();
    }

    /**
     * {@inheritdoc}
     */
    public function renderPattern()
    {
        return $this->value->renderPattern();
    }

    /**
     * @return bool
     */
    public function isCaseSensitive()
    {
        return $this->value->isCaseSensitive();
    }

    /**
     * @return int
     */
    public function getType()
    {
        return $this->value->getType();
    }

    /**
     * {@inheritdoc}
     */
    public function prepend($expr)
    {
        $this->value->prepend($expr);

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function append($expr)
    {
        $this->value->append($expr);

        return $this;
    }

    /**
     * @return bool
     */
    public function isRegex()
    {
        return self::TYPE_REGEX === $this->value->getType();
    }

    /**
     * @return bool
     */
    public function isGlob()
    {
        return self::TYPE_GLOB === $this->value->getType();
    }

    /**
     * @throws \LogicException
     *
     * @return Glob
     */
    public function getGlob()
    {
        if (self::TYPE_GLOB !== $this->value->getType()) {
            throw new \LogicException('Regex can\'t be transformed to glob.');
        }

        return $this->value;
    }

    /**
     * @return Regex
     */
    public function getRegex()
    {
        return self::TYPE_REGEX === $this->value->getType() ? $this->value : $this->value->toRegex();
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Expression;

/**
 * @author Jean-François Simon <contact@jfsimon.fr>
 */
class Glob implements ValueInterface
{
    /**
     * @var string
     */
    private $pattern;

    /**
     * @param string $pattern
     */
    public function __construct($pattern)
    {
        $this->pattern = $pattern;
    }

    /**
     * {@inheritdoc}
     */
    public function render()
    {
        return $this->pattern;
    }

    /**
     * {@inheritdoc}
     */
    public function renderPattern()
    {
        return $this->pattern;
    }

    /**
     * {@inheritdoc}
     */
    public function getType()
    {
        return Expression::TYPE_GLOB;
    }

    /**
     * {@inheritdoc}
     */
    public function isCaseSensitive()
    {
        return true;
    }

    /**
     * {@inheritdoc}
     */
    public function prepend($expr)
    {
        $this->pattern = $expr.$this->pattern;

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function append($expr)
    {
        $this->pattern .= $expr;

        return $this;
    }

    /**
     * Tests if glob is expandable ("*.{a,b}" syntax).
     *
     * @return bool
     */
    public function isExpandable()
    {
        return false !== strpos($this->pattern, '{')
            && false !== strpos($this->pattern, '}');
    }

    /**
     * @param bool $strictLeadingDot
     * @param bool $strictWildcardSlash
     *
     * @return Regex
     */
    public function toRegex($strictLeadingDot = true, $strictWildcardSlash = true)
    {
        $firstByte = true;
        $escaping = false;
        $inCurlies = 0;
        $regex = '';
        $sizeGlob = strlen($this->pattern);
        for ($i = 0; $i < $sizeGlob; ++$i) {
            $car = $this->pattern[$i];
            if ($firstByte) {
                if ($strictLeadingDot && '.' !== $car) {
                    $regex .= '(?=[^\.])';
                }

                $firstByte = false;
            }

            if ('/' === $car) {
                $firstByte = true;
            }

            if ('.' === $car || '(' === $car || ')' === $car || '|' === $car || '+' === $car || '^' === $car || '$' === $car) {
                $regex .= "\\$car";
            } elseif ('*' === $car) {
                $regex .= $escaping ? '\\*' : ($strictWildcardSlash ? '[^/]*' : '.*');
            } elseif ('?' === $car) {
                $regex .= $escaping ? '\\?' : ($strictWildcardSlash ? '[^/]' : '.');
            } elseif ('{' === $car) {
                $regex .= $escaping ? '\\{' : '(';
                if (!$escaping) {
                    ++$inCurlies;
                }
            } elseif ('}' === $car && $inCurlies) {
                $regex .= $escaping ? '}' : ')';
                if (!$escaping) {
                    --$inCurlies;
                }
            } elseif (',' === $car && $inCurlies) {
                $regex .= $escaping ? ',' : '|';
            } elseif ('\\' === $car) {
                if ($escaping) {
                    $regex .= '\\\\';
                    $escaping = false;
                } else {
                    $escaping = true;
                }

                continue;
            } else {
                $regex .= $car;
            }
            $escaping = false;
        }

        return new Regex('^'.$regex.'$');
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Expression;

/**
 * @author Jean-François Simon <contact@jfsimon.fr>
 */
interface ValueInterface
{
    /**
     * Renders string representation of expression.
     *
     * @return string
     */
    public function render();

    /**
     * Renders string representation of pattern.
     *
     * @return string
     */
    public function renderPattern();

    /**
     * Returns value case sensitivity.
     *
     * @return bool
     */
    public function isCaseSensitive();

    /**
     * Returns expression type.
     *
     * @return int
     */
    public function getType();

    /**
     * @param string $expr
     *
     * @return ValueInterface
     */
    public function prepend($expr);

    /**
     * @param string $expr
     *
     * @return ValueInterface
     */
    public function append($expr);
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Adapter;

use Symfony\Component\Finder\Iterator;

/**
 * PHP finder engine implementation.
 *
 * @author Jean-François Simon <contact@jfsimon.fr>
 */
class PhpAdapter extends AbstractAdapter
{
    /**
     * {@inheritdoc}
     */
    public function searchInDirectory($dir)
    {
        $flags = \RecursiveDirectoryIterator::SKIP_DOTS;

        if ($this->followLinks) {
            $flags |= \RecursiveDirectoryIterator::FOLLOW_SYMLINKS;
        }

        $iterator = new \RecursiveIteratorIterator(
            new Iterator\RecursiveDirectoryIterator($dir, $flags, $this->ignoreUnreadableDirs),
            \RecursiveIteratorIterator::SELF_FIRST
        );

        if ($this->minDepth > 0 || $this->maxDepth < PHP_INT_MAX) {
            $iterator = new Iterator\DepthRangeFilterIterator($iterator, $this->minDepth, $this->maxDepth);
        }

        if ($this->mode) {
            $iterator = new Iterator\FileTypeFilterIterator($iterator, $this->mode);
        }

        if ($this->exclude) {
            $iterator = new Iterator\ExcludeDirectoryFilterIterator($iterator, $this->exclude);
        }

        if ($this->names || $this->notNames) {
            $iterator = new Iterator\FilenameFilterIterator($iterator, $this->names, $this->notNames);
        }

        if ($this->contains || $this->notContains) {
            $iterator = new Iterator\FilecontentFilterIterator($iterator, $this->contains, $this->notContains);
        }

        if ($this->sizes) {
            $iterator = new Iterator\SizeRangeFilterIterator($iterator, $this->sizes);
        }

        if ($this->dates) {
            $iterator = new Iterator\DateRangeFilterIterator($iterator, $this->dates);
        }

        if ($this->filters) {
            $iterator = new Iterator\CustomFilterIterator($iterator, $this->filters);
        }

        if ($this->sort) {
            $iteratorAggregate = new Iterator\SortableIterator($iterator, $this->sort);
            $iterator = $iteratorAggregate->getIterator();
        }

        if ($this->paths || $this->notPaths) {
            $iterator = new Iterator\PathFilterIterator($iterator, $this->paths, $this->notPaths);
        }

        return $iterator;
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'php';
    }

    /**
     * {@inheritdoc}
     */
    protected function canBeUsed()
    {
        return true;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Adapter;

use Symfony\Component\Finder\Exception\AccessDeniedException;
use Symfony\Component\Finder\Iterator;
use Symfony\Component\Finder\Shell\Shell;
use Symfony\Component\Finder\Expression\Expression;
use Symfony\Component\Finder\Shell\Command;
use Symfony\Component\Finder\Comparator\NumberComparator;
use Symfony\Component\Finder\Comparator\DateComparator;

/**
 * Shell engine implementation using GNU find command.
 *
 * @author Jean-François Simon <contact@jfsimon.fr>
 */
abstract class AbstractFindAdapter extends AbstractAdapter
{
    /**
     * @var Shell
     */
    protected $shell;

    /**
     * Constructor.
     */
    public function __construct()
    {
        $this->shell = new Shell();
    }

    /**
     * {@inheritdoc}
     */
    public function searchInDirectory($dir)
    {
        // having "/../" in path make find fail
        $dir = realpath($dir);

        // searching directories containing or not containing strings leads to no result
        if (Iterator\FileTypeFilterIterator::ONLY_DIRECTORIES === $this->mode && ($this->contains || $this->notContains)) {
            return new Iterator\FilePathsIterator(array(), $dir);
        }

        $command = Command::create();
        $find = $this->buildFindCommand($command, $dir);

        if ($this->followLinks) {
            $find->add('-follow');
        }

        $find->add('-mindepth')->add($this->minDepth + 1);

        if (PHP_INT_MAX !== $this->maxDepth) {
            $find->add('-maxdepth')->add($this->maxDepth + 1);
        }

        if (Iterator\FileTypeFilterIterator::ONLY_DIRECTORIES === $this->mode) {
            $find->add('-type d');
        } elseif (Iterator\FileTypeFilterIterator::ONLY_FILES === $this->mode) {
            $find->add('-type f');
        }

        $this->buildNamesFiltering($find, $this->names);
        $this->buildNamesFiltering($find, $this->notNames, true);
        $this->buildPathsFiltering($find, $dir, $this->paths);
        $this->buildPathsFiltering($find, $dir, $this->notPaths, true);
        $this->buildSizesFiltering($find, $this->sizes);
        $this->buildDatesFiltering($find, $this->dates);

        $useGrep = $this->shell->testCommand('grep') && $this->shell->testCommand('xargs');
        $useSort = is_int($this->sort) && $this->shell->testCommand('sort') && $this->shell->testCommand('cut');

        if ($useGrep && ($this->contains || $this->notContains)) {
            $grep = $command->ins('grep');
            $this->buildContentFiltering($grep, $this->contains);
            $this->buildContentFiltering($grep, $this->notContains, true);
        }

        if ($useSort) {
            $this->buildSorting($command, $this->sort);
        }

        $command->setErrorHandler(
            $this->ignoreUnreadableDirs
                // If directory is unreadable and finder is set to ignore it, `stderr` is ignored.
                ? function ($stderr) { return; }
                : function ($stderr) { throw new AccessDeniedException($stderr); }
        );

        $paths = $this->shell->testCommand('uniq') ? $command->add('| uniq')->execute() : array_unique($command->execute());
        $iterator = new Iterator\FilePathsIterator($paths, $dir);

        if ($this->exclude) {
            $iterator = new Iterator\ExcludeDirectoryFilterIterator($iterator, $this->exclude);
        }

        if (!$useGrep && ($this->contains || $this->notContains)) {
            $iterator = new Iterator\FilecontentFilterIterator($iterator, $this->contains, $this->notContains);
        }

        if ($this->filters) {
            $iterator = new Iterator\CustomFilterIterator($iterator, $this->filters);
        }

        if (!$useSort && $this->sort) {
            $iteratorAggregate = new Iterator\SortableIterator($iterator, $this->sort);
            $iterator = $iteratorAggregate->getIterator();
        }

        return $iterator;
    }

    /**
     * {@inheritdoc}
     */
    protected function canBeUsed()
    {
        return $this->shell->testCommand('find');
    }

    /**
     * @param Command $command
     * @param string  $dir
     *
     * @return Command
     */
    protected function buildFindCommand(Command $command, $dir)
    {
        return $command
            ->ins('find')
            ->add('find ')
            ->arg($dir)
            ->add('-noleaf'); // the -noleaf option is required for filesystems that don't follow the '.' and '..' conventions
    }

    /**
     * @param Command  $command
     * @param string[] $names
     * @param bool     $not
     */
    private function buildNamesFiltering(Command $command, array $names, $not = false)
    {
        if (0 === count($names)) {
            return;
        }

        $command->add($not ? '-not' : null)->cmd('(');

        foreach ($names as $i => $name) {
            $expr = Expression::create($name);

            // Find does not support expandable globs ("*.{a,b}" syntax).
            if ($expr->isGlob() && $expr->getGlob()->isExpandable()) {
                $expr = Expression::create($expr->getGlob()->toRegex(false));
            }

            // Fixes 'not search' and 'full path matching' regex problems.
            // - Jokers '.' are replaced by [^/].
            // - We add '[^/]*' before and after regex (if no ^|$ flags are present).
            if ($expr->isRegex()) {
                $regex = $expr->getRegex();
                $regex->prepend($regex->hasStartFlag() ? '/' : '/[^/]*')
                    ->setStartFlag(false)
                    ->setStartJoker(true)
                    ->replaceJokers('[^/]');
                if (!$regex->hasEndFlag() || $regex->hasEndJoker()) {
                    $regex->setEndJoker(false)->append('[^/]*');
                }
            }

            $command
                ->add($i > 0 ? '-or' : null)
                ->add($expr->isRegex()
                    ? ($expr->isCaseSensitive() ? '-regex' : '-iregex')
                    : ($expr->isCaseSensitive() ? '-name' : '-iname')
                )
                ->arg($expr->renderPattern());
        }

        $command->cmd(')');
    }

    /**
     * @param Command  $command
     * @param string   $dir
     * @param string[] $paths
     * @param bool     $not
     */
    private function buildPathsFiltering(Command $command, $dir, array $paths, $not = false)
    {
        if (0 === count($paths)) {
            return;
        }

        $command->add($not ? '-not' : null)->cmd('(');

        foreach ($paths as $i => $path) {
            $expr = Expression::create($path);

            // Find does not support expandable globs ("*.{a,b}" syntax).
            if ($expr->isGlob() && $expr->getGlob()->isExpandable()) {
                $expr = Expression::create($expr->getGlob()->toRegex(false));
            }

            // Fixes 'not search' regex problems.
            if ($expr->isRegex()) {
                $regex = $expr->getRegex();
                $regex->prepend($regex->hasStartFlag() ? preg_quote($dir).DIRECTORY_SEPARATOR : '.*')->setEndJoker(!$regex->hasEndFlag());
            } else {
                $expr->prepend('*')->append('*');
            }

            $command
                ->add($i > 0 ? '-or' : null)
                ->add($expr->isRegex()
                    ? ($expr->isCaseSensitive() ? '-regex' : '-iregex')
                    : ($expr->isCaseSensitive() ? '-path' : '-ipath')
                )
                ->arg($expr->renderPattern());
        }

        $command->cmd(')');
    }

    /**
     * @param Command            $command
     * @param NumberComparator[] $sizes
     */
    private function buildSizesFiltering(Command $command, array $sizes)
    {
        foreach ($sizes as $i => $size) {
            $command->add($i > 0 ? '-and' : null);

            switch ($size->getOperator()) {
                case '<=':
                    $command->add('-size -'.($size->getTarget() + 1).'c');
                    break;
                case '>=':
                    $command->add('-size +'.($size->getTarget() - 1).'c');
                    break;
                case '>':
                    $command->add('-size +'.$size->getTarget().'c');
                    break;
                case '!=':
                    $command->add('-size -'.$size->getTarget().'c');
                    $command->add('-size +'.$size->getTarget().'c');
                    break;
                case '<':
                default:
                    $command->add('-size -'.$size->getTarget().'c');
            }
        }
    }

    /**
     * @param Command          $command
     * @param DateComparator[] $dates
     */
    private function buildDatesFiltering(Command $command, array $dates)
    {
        foreach ($dates as $i => $date) {
            $command->add($i > 0 ? '-and' : null);

            $mins = (int) round((time() - $date->getTarget()) / 60);

            if (0 > $mins) {
                // mtime is in the future
                $command->add(' -mmin -0');
                // we will have no result so we don't need to continue
                return;
            }

            switch ($date->getOperator()) {
                case '<=':
                    $command->add('-mmin +'.($mins - 1));
                    break;
                case '>=':
                    $command->add('-mmin -'.($mins + 1));
                    break;
                case '>':
                    $command->add('-mmin -'.$mins);
                    break;
                case '!=':
                    $command->add('-mmin +'.$mins.' -or -mmin -'.$mins);
                    break;
                case '<':
                default:
                    $command->add('-mmin +'.$mins);
            }
        }
    }

    /**
     * @param Command $command
     * @param string  $sort
     *
     * @throws \InvalidArgumentException
     */
    private function buildSorting(Command $command, $sort)
    {
        $this->buildFormatSorting($command, $sort);
    }

    /**
     * @param Command $command
     * @param string  $sort
     */
    abstract protected function buildFormatSorting(Command $command, $sort);

    /**
     * @param Command $command
     * @param array   $contains
     * @param bool    $not
     */
    abstract protected function buildContentFiltering(Command $command, array $contains, $not = false);
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Adapter;

/**
 * Interface for finder engine implementations.
 *
 * @author Jean-François Simon <contact@jfsimon.fr>
 */
abstract class AbstractAdapter implements AdapterInterface
{
    protected $followLinks = false;
    protected $mode = 0;
    protected $minDepth = 0;
    protected $maxDepth = PHP_INT_MAX;
    protected $exclude = array();
    protected $names = array();
    protected $notNames = array();
    protected $contains = array();
    protected $notContains = array();
    protected $sizes = array();
    protected $dates = array();
    protected $filters = array();
    protected $sort = false;
    protected $paths = array();
    protected $notPaths = array();
    protected $ignoreUnreadableDirs = false;

    private static $areSupported = array();

    /**
     * {@inheritdoc}
     */
    public function isSupported()
    {
        $name = $this->getName();

        if (!array_key_exists($name, self::$areSupported)) {
            self::$areSupported[$name] = $this->canBeUsed();
        }

        return self::$areSupported[$name];
    }

    /**
     * {@inheritdoc}
     */
    public function setFollowLinks($followLinks)
    {
        $this->followLinks = $followLinks;

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function setMode($mode)
    {
        $this->mode = $mode;

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function setDepths(array $depths)
    {
        $this->minDepth = 0;
        $this->maxDepth = PHP_INT_MAX;

        foreach ($depths as $comparator) {
            switch ($comparator->getOperator()) {
                case '>':
                    $this->minDepth = $comparator->getTarget() + 1;
                    break;
                case '>=':
                    $this->minDepth = $comparator->getTarget();
                    break;
                case '<':
                    $this->maxDepth = $comparator->getTarget() - 1;
                    break;
                case '<=':
                    $this->maxDepth = $comparator->getTarget();
                    break;
                default:
                    $this->minDepth = $this->maxDepth = $comparator->getTarget();
            }
        }

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function setExclude(array $exclude)
    {
        $this->exclude = $exclude;

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function setNames(array $names)
    {
        $this->names = $names;

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function setNotNames(array $notNames)
    {
        $this->notNames = $notNames;

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function setContains(array $contains)
    {
        $this->contains = $contains;

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function setNotContains(array $notContains)
    {
        $this->notContains = $notContains;

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function setSizes(array $sizes)
    {
        $this->sizes = $sizes;

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function setDates(array $dates)
    {
        $this->dates = $dates;

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function setFilters(array $filters)
    {
        $this->filters = $filters;

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function setSort($sort)
    {
        $this->sort = $sort;

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function setPath(array $paths)
    {
        $this->paths = $paths;

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function setNotPath(array $notPaths)
    {
        $this->notPaths = $notPaths;

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function ignoreUnreadableDirs($ignore = true)
    {
        $this->ignoreUnreadableDirs = (bool) $ignore;

        return $this;
    }

    /**
     * Returns whether the adapter is supported in the current environment.
     *
     * This method should be implemented in all adapters. Do not implement
     * isSupported in the adapters as the generic implementation provides a cache
     * layer.
     *
     * @see isSupported()
     *
     * @return bool Whether the adapter is supported
     */
    abstract protected function canBeUsed();
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Adapter;

use Symfony\Component\Finder\Shell\Shell;
use Symfony\Component\Finder\Shell\Command;
use Symfony\Component\Finder\Iterator\SortableIterator;
use Symfony\Component\Finder\Expression\Expression;

/**
 * Shell engine implementation using BSD find command.
 *
 * @author Jean-François Simon <contact@jfsimon.fr>
 */
class BsdFindAdapter extends AbstractFindAdapter
{
    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'bsd_find';
    }

    /**
     * {@inheritdoc}
     */
    protected function canBeUsed()
    {
        return in_array($this->shell->getType(), array(Shell::TYPE_BSD, Shell::TYPE_DARWIN)) && parent::canBeUsed();
    }

    /**
     * {@inheritdoc}
     */
    protected function buildFormatSorting(Command $command, $sort)
    {
        switch ($sort) {
            case SortableIterator::SORT_BY_NAME:
                $command->ins('sort')->add('| sort');

                return;
            case SortableIterator::SORT_BY_TYPE:
                $format = '%HT';
                break;
            case SortableIterator::SORT_BY_ACCESSED_TIME:
                $format = '%a';
                break;
            case SortableIterator::SORT_BY_CHANGED_TIME:
                $format = '%c';
                break;
            case SortableIterator::SORT_BY_MODIFIED_TIME:
                $format = '%m';
                break;
            default:
                throw new \InvalidArgumentException(sprintf('Unknown sort options: %s.', $sort));
        }

        $command
            ->add('-print0 | xargs -0 stat -f')
            ->arg($format.'%t%N')
            ->add('| sort | cut -f 2');
    }

    /**
     * {@inheritdoc}
     */
    protected function buildFindCommand(Command $command, $dir)
    {
        parent::buildFindCommand($command, $dir)->addAtIndex('-E', 1);

        return $command;
    }

    /**
     * {@inheritdoc}
     */
    protected function buildContentFiltering(Command $command, array $contains, $not = false)
    {
        foreach ($contains as $contain) {
            $expr = Expression::create($contain);

            // todo: avoid forking process for each $pattern by using multiple -e options
            $command
                ->add('| grep -v \'^$\'')
                ->add('| xargs -I{} grep -I')
                ->add($expr->isCaseSensitive() ? null : '-i')
                ->add($not ? '-L' : '-l')
                ->add('-Ee')->arg($expr->renderPattern())
                ->add('{}')
            ;
        }
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Adapter;

use Symfony\Component\Finder\Shell\Shell;
use Symfony\Component\Finder\Shell\Command;
use Symfony\Component\Finder\Iterator\SortableIterator;
use Symfony\Component\Finder\Expression\Expression;

/**
 * Shell engine implementation using GNU find command.
 *
 * @author Jean-François Simon <contact@jfsimon.fr>
 */
class GnuFindAdapter extends AbstractFindAdapter
{
    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'gnu_find';
    }

    /**
     * {@inheritdoc}
     */
    protected function buildFormatSorting(Command $command, $sort)
    {
        switch ($sort) {
            case SortableIterator::SORT_BY_NAME:
                $command->ins('sort')->add('| sort');

                return;
            case SortableIterator::SORT_BY_TYPE:
                $format = '%y';
                break;
            case SortableIterator::SORT_BY_ACCESSED_TIME:
                $format = '%A@';
                break;
            case SortableIterator::SORT_BY_CHANGED_TIME:
                $format = '%C@';
                break;
            case SortableIterator::SORT_BY_MODIFIED_TIME:
                $format = '%T@';
                break;
            default:
                throw new \InvalidArgumentException(sprintf('Unknown sort options: %s.', $sort));
        }

        $command
            ->get('find')
            ->add('-printf')
            ->arg($format.' %h/%f\\n')
            ->add('| sort | cut')
            ->arg('-d ')
            ->arg('-f2-')
        ;
    }

    /**
     * {@inheritdoc}
     */
    protected function canBeUsed()
    {
        return $this->shell->getType() === Shell::TYPE_UNIX && parent::canBeUsed();
    }

    /**
     * {@inheritdoc}
     */
    protected function buildFindCommand(Command $command, $dir)
    {
        return parent::buildFindCommand($command, $dir)->add('-regextype posix-extended');
    }

    /**
     * {@inheritdoc}
     */
    protected function buildContentFiltering(Command $command, array $contains, $not = false)
    {
        foreach ($contains as $contain) {
            $expr = Expression::create($contain);

            // todo: avoid forking process for each $pattern by using multiple -e options
            $command
                ->add('| xargs -I{} -r grep -I')
                ->add($expr->isCaseSensitive() ? null : '-i')
                ->add($not ? '-L' : '-l')
                ->add('-Ee')->arg($expr->renderPattern())
                ->add('{}')
            ;
        }
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Adapter;

/**
 * @author Jean-François Simon <contact@jfsimon.fr>
 */
interface AdapterInterface
{
    /**
     * @param bool $followLinks
     *
     * @return AdapterInterface Current instance
     */
    public function setFollowLinks($followLinks);

    /**
     * @param int $mode
     *
     * @return AdapterInterface Current instance
     */
    public function setMode($mode);

    /**
     * @param array $exclude
     *
     * @return AdapterInterface Current instance
     */
    public function setExclude(array $exclude);

    /**
     * @param array $depths
     *
     * @return AdapterInterface Current instance
     */
    public function setDepths(array $depths);

    /**
     * @param array $names
     *
     * @return AdapterInterface Current instance
     */
    public function setNames(array $names);

    /**
     * @param array $notNames
     *
     * @return AdapterInterface Current instance
     */
    public function setNotNames(array $notNames);

    /**
     * @param array $contains
     *
     * @return AdapterInterface Current instance
     */
    public function setContains(array $contains);

    /**
     * @param array $notContains
     *
     * @return AdapterInterface Current instance
     */
    public function setNotContains(array $notContains);

    /**
     * @param array $sizes
     *
     * @return AdapterInterface Current instance
     */
    public function setSizes(array $sizes);

    /**
     * @param array $dates
     *
     * @return AdapterInterface Current instance
     */
    public function setDates(array $dates);

    /**
     * @param array $filters
     *
     * @return AdapterInterface Current instance
     */
    public function setFilters(array $filters);

    /**
     * @param \Closure|int $sort
     *
     * @return AdapterInterface Current instance
     */
    public function setSort($sort);

    /**
     * @param array $paths
     *
     * @return AdapterInterface Current instance
     */
    public function setPath(array $paths);

    /**
     * @param array $notPaths
     *
     * @return AdapterInterface Current instance
     */
    public function setNotPath(array $notPaths);

    /**
     * @param bool $ignore
     *
     * @return AdapterInterface Current instance
     */
    public function ignoreUnreadableDirs($ignore = true);

    /**
     * @param string $dir
     *
     * @return \Iterator Result iterator
     */
    public function searchInDirectory($dir);

    /**
     * Tests adapter support for current platform.
     *
     * @return bool
     */
    public function isSupported();

    /**
     * Returns adapter name.
     *
     * @return string
     */
    public function getName();
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Comparator;

/**
 * DateCompare compiles date comparisons.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class DateComparator extends Comparator
{
    /**
     * Constructor.
     *
     * @param string $test A comparison string
     *
     * @throws \InvalidArgumentException If the test is not understood
     */
    public function __construct($test)
    {
        if (!preg_match('#^\s*(==|!=|[<>]=?|after|since|before|until)?\s*(.+?)\s*$#i', $test, $matches)) {
            throw new \InvalidArgumentException(sprintf('Don\'t understand "%s" as a date test.', $test));
        }

        try {
            $date = new \DateTime($matches[2]);
            $target = $date->format('U');
        } catch (\Exception $e) {
            throw new \InvalidArgumentException(sprintf('"%s" is not a valid date.', $matches[2]));
        }

        $operator = isset($matches[1]) ? $matches[1] : '==';
        if ('since' === $operator || 'after' === $operator) {
            $operator = '>';
        }

        if ('until' === $operator || 'before' === $operator) {
            $operator = '<';
        }

        $this->setOperator($operator);
        $this->setTarget($target);
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Comparator;

/**
 * NumberComparator compiles a simple comparison to an anonymous
 * subroutine, which you can call with a value to be tested again.
 *
 * Now this would be very pointless, if NumberCompare didn't understand
 * magnitudes.
 *
 * The target value may use magnitudes of kilobytes (k, ki),
 * megabytes (m, mi), or gigabytes (g, gi).  Those suffixed
 * with an i use the appropriate 2**n version in accordance with the
 * IEC standard: http://physics.nist.gov/cuu/Units/binary.html
 *
 * Based on the Perl Number::Compare module.
 *
 * @author    Fabien Potencier <fabien@symfony.com> PHP port
 * @author    Richard Clamp <richardc@unixbeard.net> Perl version
 * @copyright 2004-2005 Fabien Potencier <fabien@symfony.com>
 * @copyright 2002 Richard Clamp <richardc@unixbeard.net>
 *
 * @see http://physics.nist.gov/cuu/Units/binary.html
 */
class NumberComparator extends Comparator
{
    /**
     * Constructor.
     *
     * @param string $test A comparison string
     *
     * @throws \InvalidArgumentException If the test is not understood
     */
    public function __construct($test)
    {
        if (!preg_match('#^\s*(==|!=|[<>]=?)?\s*([0-9\.]+)\s*([kmg]i?)?\s*$#i', $test, $matches)) {
            throw new \InvalidArgumentException(sprintf('Don\'t understand "%s" as a number test.', $test));
        }

        $target = $matches[2];
        if (!is_numeric($target)) {
            throw new \InvalidArgumentException(sprintf('Invalid number "%s".', $target));
        }
        if (isset($matches[3])) {
            // magnitude
            switch (strtolower($matches[3])) {
                case 'k':
                    $target *= 1000;
                    break;
                case 'ki':
                    $target *= 1024;
                    break;
                case 'm':
                    $target *= 1000000;
                    break;
                case 'mi':
                    $target *= 1024 * 1024;
                    break;
                case 'g':
                    $target *= 1000000000;
                    break;
                case 'gi':
                    $target *= 1024 * 1024 * 1024;
                    break;
            }
        }

        $this->setTarget($target);
        $this->setOperator(isset($matches[1]) ? $matches[1] : '==');
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Comparator;

/**
 * Comparator.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class Comparator
{
    private $target;
    private $operator = '==';

    /**
     * Gets the target value.
     *
     * @return string The target value
     */
    public function getTarget()
    {
        return $this->target;
    }

    /**
     * Sets the target value.
     *
     * @param string $target The target value
     */
    public function setTarget($target)
    {
        $this->target = $target;
    }

    /**
     * Gets the comparison operator.
     *
     * @return string The operator
     */
    public function getOperator()
    {
        return $this->operator;
    }

    /**
     * Sets the comparison operator.
     *
     * @param string $operator A valid operator
     *
     * @throws \InvalidArgumentException
     */
    public function setOperator($operator)
    {
        if (!$operator) {
            $operator = '==';
        }

        if (!in_array($operator, array('>', '<', '>=', '<=', '==', '!='))) {
            throw new \InvalidArgumentException(sprintf('Invalid operator "%s".', $operator));
        }

        $this->operator = $operator;
    }

    /**
     * Tests against the target.
     *
     * @param mixed $test A test value
     *
     * @return bool
     */
    public function test($test)
    {
        switch ($this->operator) {
            case '>':
                return $test > $this->target;
            case '>=':
                return $test >= $this->target;
            case '<':
                return $test < $this->target;
            case '<=':
                return $test <= $this->target;
            case '!=':
                return $test != $this->target;
        }

        return $test == $this->target;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Shell;

/**
 * @author Jean-François Simon <contact@jfsimon.fr>
 */
class Command
{
    /**
     * @var Command|null
     */
    private $parent;

    /**
     * @var array
     */
    private $bits = array();

    /**
     * @var array
     */
    private $labels = array();

    /**
     * @var \Closure|null
     */
    private $errorHandler;

    /**
     * Constructor.
     *
     * @param Command|null $parent Parent command
     */
    public function __construct(Command $parent = null)
    {
        $this->parent = $parent;
    }

    /**
     * Returns command as string.
     *
     * @return string
     */
    public function __toString()
    {
        return $this->join();
    }

    /**
     * Creates a new Command instance.
     *
     * @param Command|null $parent Parent command
     *
     * @return Command New Command instance
     */
    public static function create(Command $parent = null)
    {
        return new self($parent);
    }

    /**
     * Escapes special chars from input.
     *
     * @param string $input A string to escape
     *
     * @return string The escaped string
     */
    public static function escape($input)
    {
        return escapeshellcmd($input);
    }

    /**
     * Quotes input.
     *
     * @param string $input An argument string
     *
     * @return string The quoted string
     */
    public static function quote($input)
    {
        return escapeshellarg($input);
    }

    /**
     * Appends a string or a Command instance.
     *
     * @param string|Command $bit
     *
     * @return Command The current Command instance
     */
    public function add($bit)
    {
        $this->bits[] = $bit;

        return $this;
    }

    /**
     * Prepends a string or a command instance.
     *
     * @param string|Command $bit
     *
     * @return Command The current Command instance
     */
    public function top($bit)
    {
        array_unshift($this->bits, $bit);

        foreach ($this->labels as $label => $index) {
            $this->labels[$label] += 1;
        }

        return $this;
    }

    /**
     * Appends an argument, will be quoted.
     *
     * @param string $arg
     *
     * @return Command The current Command instance
     */
    public function arg($arg)
    {
        $this->bits[] = self::quote($arg);

        return $this;
    }

    /**
     * Appends escaped special command chars.
     *
     * @param string $esc
     *
     * @return Command The current Command instance
     */
    public function cmd($esc)
    {
        $this->bits[] = self::escape($esc);

        return $this;
    }

    /**
     * Inserts a labeled command to feed later.
     *
     * @param string $label The unique label
     *
     * @return Command The current Command instance
     *
     * @throws \RuntimeException If label already exists
     */
    public function ins($label)
    {
        if (isset($this->labels[$label])) {
            throw new \RuntimeException(sprintf('Label "%s" already exists.', $label));
        }

        $this->bits[] = self::create($this);
        $this->labels[$label] = count($this->bits) - 1;

        return $this->bits[$this->labels[$label]];
    }

    /**
     * Retrieves a previously labeled command.
     *
     * @param string $label
     *
     * @return Command The labeled command
     *
     * @throws \RuntimeException
     */
    public function get($label)
    {
        if (!isset($this->labels[$label])) {
            throw new \RuntimeException(sprintf('Label "%s" does not exist.', $label));
        }

        return $this->bits[$this->labels[$label]];
    }

    /**
     * Returns parent command (if any).
     *
     * @return Command Parent command
     *
     * @throws \RuntimeException If command has no parent
     */
    public function end()
    {
        if (null === $this->parent) {
            throw new \RuntimeException('Calling end on root command doesn\'t make sense.');
        }

        return $this->parent;
    }

    /**
     * Counts bits stored in command.
     *
     * @return int The bits count
     */
    public function length()
    {
        return count($this->bits);
    }

    /**
     * @param \Closure $errorHandler
     *
     * @return Command
     */
    public function setErrorHandler(\Closure $errorHandler)
    {
        $this->errorHandler = $errorHandler;

        return $this;
    }

    /**
     * @return \Closure|null
     */
    public function getErrorHandler()
    {
        return $this->errorHandler;
    }

    /**
     * Executes current command.
     *
     * @return array The command result
     *
     * @throws \RuntimeException
     */
    public function execute()
    {
        if (null === $errorHandler = $this->errorHandler) {
            exec($this->join(), $output);
        } else {
            $process = proc_open($this->join(), array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $pipes);
            $output = preg_split('~(\r\n|\r|\n)~', stream_get_contents($pipes[1]), -1, PREG_SPLIT_NO_EMPTY);

            if ($error = stream_get_contents($pipes[2])) {
                $errorHandler($error);
            }

            proc_close($process);
        }

        return $output ?: array();
    }

    /**
     * Joins bits.
     *
     * @return string
     */
    public function join()
    {
        return implode(' ', array_filter(
            array_map(function ($bit) {
                return $bit instanceof Command ? $bit->join() : ($bit ?: null);
            }, $this->bits),
            function ($bit) { return null !== $bit; }
        ));
    }

    /**
     * Insert a string or a Command instance before the bit at given position $index (index starts from 0).
     *
     * @param string|Command $bit
     * @param int            $index
     *
     * @return Command The current Command instance
     */
    public function addAtIndex($bit, $index)
    {
        array_splice($this->bits, $index, 0, $bit instanceof self ? array($bit) : $bit);

        return $this;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Shell;

/**
 * @author Jean-François Simon <contact@jfsimon.fr>
 */
class Shell
{
    const TYPE_UNIX = 1;
    const TYPE_DARWIN = 2;
    const TYPE_CYGWIN = 3;
    const TYPE_WINDOWS = 4;
    const TYPE_BSD = 5;

    /**
     * @var string|null
     */
    private $type;

    /**
     * Returns guessed OS type.
     *
     * @return int
     */
    public function getType()
    {
        if (null === $this->type) {
            $this->type = $this->guessType();
        }

        return $this->type;
    }

    /**
     * Tests if a command is available.
     *
     * @param string $command
     *
     * @return bool
     */
    public function testCommand($command)
    {
        if (!function_exists('exec')) {
            return false;
        }

        // todo: find a better way (command could not be available)
        $testCommand = 'which ';
        if (self::TYPE_WINDOWS === $this->type) {
            $testCommand = 'where ';
        }

        $command = escapeshellcmd($command);

        exec($testCommand.$command, $output, $code);

        return 0 === $code && count($output) > 0;
    }

    /**
     * Guesses OS type.
     *
     * @return int
     */
    private function guessType()
    {
        $os = strtolower(PHP_OS);

        if (false !== strpos($os, 'cygwin')) {
            return self::TYPE_CYGWIN;
        }

        if (false !== strpos($os, 'darwin')) {
            return self::TYPE_DARWIN;
        }

        if (false !== strpos($os, 'bsd')) {
            return self::TYPE_BSD;
        }

        if (0 === strpos($os, 'win')) {
            return self::TYPE_WINDOWS;
        }

        return self::TYPE_UNIX;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder;

use Symfony\Component\Finder\Adapter\AdapterInterface;
use Symfony\Component\Finder\Adapter\GnuFindAdapter;
use Symfony\Component\Finder\Adapter\BsdFindAdapter;
use Symfony\Component\Finder\Adapter\PhpAdapter;
use Symfony\Component\Finder\Comparator\DateComparator;
use Symfony\Component\Finder\Comparator\NumberComparator;
use Symfony\Component\Finder\Exception\ExceptionInterface;
use Symfony\Component\Finder\Iterator\CustomFilterIterator;
use Symfony\Component\Finder\Iterator\DateRangeFilterIterator;
use Symfony\Component\Finder\Iterator\DepthRangeFilterIterator;
use Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator;
use Symfony\Component\Finder\Iterator\FilecontentFilterIterator;
use Symfony\Component\Finder\Iterator\FilenameFilterIterator;
use Symfony\Component\Finder\Iterator\SizeRangeFilterIterator;
use Symfony\Component\Finder\Iterator\SortableIterator;

/**
 * Finder allows to build rules to find files and directories.
 *
 * It is a thin wrapper around several specialized iterator classes.
 *
 * All rules may be invoked several times.
 *
 * All methods return the current Finder object to allow easy chaining:
 *
 * $finder = Finder::create()->files()->name('*.php')->in(__DIR__);
 *
 * @author Fabien Potencier <fabien@symfony.com>
 *
 * @api
 */
class Finder implements \IteratorAggregate, \Countable
{
    const IGNORE_VCS_FILES = 1;
    const IGNORE_DOT_FILES = 2;

    private $mode = 0;
    private $names = array();
    private $notNames = array();
    private $exclude = array();
    private $filters = array();
    private $depths = array();
    private $sizes = array();
    private $followLinks = false;
    private $sort = false;
    private $ignore = 0;
    private $dirs = array();
    private $dates = array();
    private $iterators = array();
    private $contains = array();
    private $notContains = array();
    private $adapters = array();
    private $paths = array();
    private $notPaths = array();
    private $ignoreUnreadableDirs = false;

    private static $vcsPatterns = array('.svn', '_svn', 'CVS', '_darcs', '.arch-params', '.monotone', '.bzr', '.git', '.hg');

    /**
     * Constructor.
     */
    public function __construct()
    {
        $this->ignore = static::IGNORE_VCS_FILES | static::IGNORE_DOT_FILES;

        $this
            ->addAdapter(new GnuFindAdapter())
            ->addAdapter(new BsdFindAdapter())
            ->addAdapter(new PhpAdapter(), -50)
            ->setAdapter('php')
        ;
    }

    /**
     * Creates a new Finder.
     *
     * @return Finder A new Finder instance
     *
     * @api
     */
    public static function create()
    {
        return new static();
    }

    /**
     * Registers a finder engine implementation.
     *
     * @param AdapterInterface $adapter  An adapter instance
     * @param int              $priority Highest is selected first
     *
     * @return Finder The current Finder instance
     */
    public function addAdapter(AdapterInterface $adapter, $priority = 0)
    {
        $this->adapters[$adapter->getName()] = array(
            'adapter' => $adapter,
            'priority' => $priority,
            'selected' => false,
        );

        return $this->sortAdapters();
    }

    /**
     * Sets the selected adapter to the best one according to the current platform the code is run on.
     *
     * @return Finder The current Finder instance
     */
    public function useBestAdapter()
    {
        $this->resetAdapterSelection();

        return $this->sortAdapters();
    }

    /**
     * Selects the adapter to use.
     *
     * @param string $name
     *
     * @throws \InvalidArgumentException
     *
     * @return Finder The current Finder instance
     */
    public function setAdapter($name)
    {
        if (!isset($this->adapters[$name])) {
            throw new \InvalidArgumentException(sprintf('Adapter "%s" does not exist.', $name));
        }

        $this->resetAdapterSelection();
        $this->adapters[$name]['selected'] = true;

        return $this->sortAdapters();
    }

    /**
     * Removes all adapters registered in the finder.
     *
     * @return Finder The current Finder instance
     */
    public function removeAdapters()
    {
        $this->adapters = array();

        return $this;
    }

    /**
     * Returns registered adapters ordered by priority without extra information.
     *
     * @return AdapterInterface[]
     */
    public function getAdapters()
    {
        return array_values(array_map(function (array $adapter) {
            return $adapter['adapter'];
        }, $this->adapters));
    }

    /**
     * Restricts the matching to directories only.
     *
     * @return Finder The current Finder instance
     *
     * @api
     */
    public function directories()
    {
        $this->mode = Iterator\FileTypeFilterIterator::ONLY_DIRECTORIES;

        return $this;
    }

    /**
     * Restricts the matching to files only.
     *
     * @return Finder The current Finder instance
     *
     * @api
     */
    public function files()
    {
        $this->mode = Iterator\FileTypeFilterIterator::ONLY_FILES;

        return $this;
    }

    /**
     * Adds tests for the directory depth.
     *
     * Usage:
     *
     *   $finder->depth('> 1') // the Finder will start matching at level 1.
     *   $finder->depth('< 3') // the Finder will descend at most 3 levels of directories below the starting point.
     *
     * @param int $level The depth level expression
     *
     * @return Finder The current Finder instance
     *
     * @see DepthRangeFilterIterator
     * @see NumberComparator
     *
     * @api
     */
    public function depth($level)
    {
        $this->depths[] = new Comparator\NumberComparator($level);

        return $this;
    }

    /**
     * Adds tests for file dates (last modified).
     *
     * The date must be something that strtotime() is able to parse:
     *
     *   $finder->date('since yesterday');
     *   $finder->date('until 2 days ago');
     *   $finder->date('> now - 2 hours');
     *   $finder->date('>= 2005-10-15');
     *
     * @param string $date A date range string
     *
     * @return Finder The current Finder instance
     *
     * @see strtotime
     * @see DateRangeFilterIterator
     * @see DateComparator
     *
     * @api
     */
    public function date($date)
    {
        $this->dates[] = new Comparator\DateComparator($date);

        return $this;
    }

    /**
     * Adds rules that files must match.
     *
     * You can use patterns (delimited with / sign), globs or simple strings.
     *
     * $finder->name('*.php')
     * $finder->name('/\.php$/') // same as above
     * $finder->name('test.php')
     *
     * @param string $pattern A pattern (a regexp, a glob, or a string)
     *
     * @return Finder The current Finder instance
     *
     * @see FilenameFilterIterator
     *
     * @api
     */
    public function name($pattern)
    {
        $this->names[] = $pattern;

        return $this;
    }

    /**
     * Adds rules that files must not match.
     *
     * @param string $pattern A pattern (a regexp, a glob, or a string)
     *
     * @return Finder The current Finder instance
     *
     * @see FilenameFilterIterator
     *
     * @api
     */
    public function notName($pattern)
    {
        $this->notNames[] = $pattern;

        return $this;
    }

    /**
     * Adds tests that file contents must match.
     *
     * Strings or PCRE patterns can be used:
     *
     * $finder->contains('Lorem ipsum')
     * $finder->contains('/Lorem ipsum/i')
     *
     * @param string $pattern A pattern (string or regexp)
     *
     * @return Finder The current Finder instance
     *
     * @see FilecontentFilterIterator
     */
    public function contains($pattern)
    {
        $this->contains[] = $pattern;

        return $this;
    }

    /**
     * Adds tests that file contents must not match.
     *
     * Strings or PCRE patterns can be used:
     *
     * $finder->notContains('Lorem ipsum')
     * $finder->notContains('/Lorem ipsum/i')
     *
     * @param string $pattern A pattern (string or regexp)
     *
     * @return Finder The current Finder instance
     *
     * @see FilecontentFilterIterator
     */
    public function notContains($pattern)
    {
        $this->notContains[] = $pattern;

        return $this;
    }

    /**
     * Adds rules that filenames must match.
     *
     * You can use patterns (delimited with / sign) or simple strings.
     *
     * $finder->path('some/special/dir')
     * $finder->path('/some\/special\/dir/') // same as above
     *
     * Use only / as dirname separator.
     *
     * @param string $pattern A pattern (a regexp or a string)
     *
     * @return Finder The current Finder instance
     *
     * @see FilenameFilterIterator
     */
    public function path($pattern)
    {
        $this->paths[] = $pattern;

        return $this;
    }

    /**
     * Adds rules that filenames must not match.
     *
     * You can use patterns (delimited with / sign) or simple strings.
     *
     * $finder->notPath('some/special/dir')
     * $finder->notPath('/some\/special\/dir/') // same as above
     *
     * Use only / as dirname separator.
     *
     * @param string $pattern A pattern (a regexp or a string)
     *
     * @return Finder The current Finder instance
     *
     * @see FilenameFilterIterator
     */
    public function notPath($pattern)
    {
        $this->notPaths[] = $pattern;

        return $this;
    }

    /**
     * Adds tests for file sizes.
     *
     * $finder->size('> 10K');
     * $finder->size('<= 1Ki');
     * $finder->size(4);
     *
     * @param string $size A size range string
     *
     * @return Finder The current Finder instance
     *
     * @see SizeRangeFilterIterator
     * @see NumberComparator
     *
     * @api
     */
    public function size($size)
    {
        $this->sizes[] = new Comparator\NumberComparator($size);

        return $this;
    }

    /**
     * Excludes directories.
     *
     * @param string|array $dirs A directory path or an array of directories
     *
     * @return Finder The current Finder instance
     *
     * @see ExcludeDirectoryFilterIterator
     *
     * @api
     */
    public function exclude($dirs)
    {
        $this->exclude = array_merge($this->exclude, (array) $dirs);

        return $this;
    }

    /**
     * Excludes "hidden" directories and files (starting with a dot).
     *
     * @param bool $ignoreDotFiles Whether to exclude "hidden" files or not
     *
     * @return Finder The current Finder instance
     *
     * @see ExcludeDirectoryFilterIterator
     *
     * @api
     */
    public function ignoreDotFiles($ignoreDotFiles)
    {
        if ($ignoreDotFiles) {
            $this->ignore |= static::IGNORE_DOT_FILES;
        } else {
            $this->ignore &= ~static::IGNORE_DOT_FILES;
        }

        return $this;
    }

    /**
     * Forces the finder to ignore version control directories.
     *
     * @param bool $ignoreVCS Whether to exclude VCS files or not
     *
     * @return Finder The current Finder instance
     *
     * @see ExcludeDirectoryFilterIterator
     *
     * @api
     */
    public function ignoreVCS($ignoreVCS)
    {
        if ($ignoreVCS) {
            $this->ignore |= static::IGNORE_VCS_FILES;
        } else {
            $this->ignore &= ~static::IGNORE_VCS_FILES;
        }

        return $this;
    }

    /**
     * Adds VCS patterns.
     *
     * @see ignoreVCS()
     *
     * @param string|string[] $pattern VCS patterns to ignore
     */
    public static function addVCSPattern($pattern)
    {
        foreach ((array) $pattern as $p) {
            self::$vcsPatterns[] = $p;
        }

        self::$vcsPatterns = array_unique(self::$vcsPatterns);
    }

    /**
     * Sorts files and directories by an anonymous function.
     *
     * The anonymous function receives two \SplFileInfo instances to compare.
     *
     * This can be slow as all the matching files and directories must be retrieved for comparison.
     *
     * @param \Closure $closure An anonymous function
     *
     * @return Finder The current Finder instance
     *
     * @see SortableIterator
     *
     * @api
     */
    public function sort(\Closure $closure)
    {
        $this->sort = $closure;

        return $this;
    }

    /**
     * Sorts files and directories by name.
     *
     * This can be slow as all the matching files and directories must be retrieved for comparison.
     *
     * @return Finder The current Finder instance
     *
     * @see SortableIterator
     *
     * @api
     */
    public function sortByName()
    {
        $this->sort = Iterator\SortableIterator::SORT_BY_NAME;

        return $this;
    }

    /**
     * Sorts files and directories by type (directories before files), then by name.
     *
     * This can be slow as all the matching files and directories must be retrieved for comparison.
     *
     * @return Finder The current Finder instance
     *
     * @see SortableIterator
     *
     * @api
     */
    public function sortByType()
    {
        $this->sort = Iterator\SortableIterator::SORT_BY_TYPE;

        return $this;
    }

    /**
     * Sorts files and directories by the last accessed time.
     *
     * This is the time that the file was last accessed, read or written to.
     *
     * This can be slow as all the matching files and directories must be retrieved for comparison.
     *
     * @return Finder The current Finder instance
     *
     * @see SortableIterator
     *
     * @api
     */
    public function sortByAccessedTime()
    {
        $this->sort = Iterator\SortableIterator::SORT_BY_ACCESSED_TIME;

        return $this;
    }

    /**
     * Sorts files and directories by the last inode changed time.
     *
     * This is the time that the inode information was last modified (permissions, owner, group or other metadata).
     *
     * On Windows, since inode is not available, changed time is actually the file creation time.
     *
     * This can be slow as all the matching files and directories must be retrieved for comparison.
     *
     * @return Finder The current Finder instance
     *
     * @see SortableIterator
     *
     * @api
     */
    public function sortByChangedTime()
    {
        $this->sort = Iterator\SortableIterator::SORT_BY_CHANGED_TIME;

        return $this;
    }

    /**
     * Sorts files and directories by the last modified time.
     *
     * This is the last time the actual contents of the file were last modified.
     *
     * This can be slow as all the matching files and directories must be retrieved for comparison.
     *
     * @return Finder The current Finder instance
     *
     * @see SortableIterator
     *
     * @api
     */
    public function sortByModifiedTime()
    {
        $this->sort = Iterator\SortableIterator::SORT_BY_MODIFIED_TIME;

        return $this;
    }

    /**
     * Filters the iterator with an anonymous function.
     *
     * The anonymous function receives a \SplFileInfo and must return false
     * to remove files.
     *
     * @param \Closure $closure An anonymous function
     *
     * @return Finder The current Finder instance
     *
     * @see CustomFilterIterator
     *
     * @api
     */
    public function filter(\Closure $closure)
    {
        $this->filters[] = $closure;

        return $this;
    }

    /**
     * Forces the following of symlinks.
     *
     * @return Finder The current Finder instance
     *
     * @api
     */
    public function followLinks()
    {
        $this->followLinks = true;

        return $this;
    }

    /**
     * Tells finder to ignore unreadable directories.
     *
     * By default, scanning unreadable directories content throws an AccessDeniedException.
     *
     * @param bool $ignore
     *
     * @return Finder The current Finder instance
     */
    public function ignoreUnreadableDirs($ignore = true)
    {
        $this->ignoreUnreadableDirs = (bool) $ignore;

        return $this;
    }

    /**
     * Searches files and directories which match defined rules.
     *
     * @param string|array $dirs A directory path or an array of directories
     *
     * @return Finder The current Finder instance
     *
     * @throws \InvalidArgumentException if one of the directories does not exist
     *
     * @api
     */
    public function in($dirs)
    {
        $resolvedDirs = array();

        foreach ((array) $dirs as $dir) {
            if (is_dir($dir)) {
                $resolvedDirs[] = $dir;
            } elseif ($glob = glob($dir, (defined('GLOB_BRACE') ? GLOB_BRACE : 0) | GLOB_ONLYDIR)) {
                $resolvedDirs = array_merge($resolvedDirs, $glob);
            } else {
                throw new \InvalidArgumentException(sprintf('The "%s" directory does not exist.', $dir));
            }
        }

        $this->dirs = array_merge($this->dirs, $resolvedDirs);

        return $this;
    }

    /**
     * Returns an Iterator for the current Finder configuration.
     *
     * This method implements the IteratorAggregate interface.
     *
     * @return \Iterator An iterator
     *
     * @throws \LogicException if the in() method has not been called
     */
    public function getIterator()
    {
        if (0 === count($this->dirs) && 0 === count($this->iterators)) {
            throw new \LogicException('You must call one of in() or append() methods before iterating over a Finder.');
        }

        if (1 === count($this->dirs) && 0 === count($this->iterators)) {
            return $this->searchInDirectory($this->dirs[0]);
        }

        $iterator = new \AppendIterator();
        foreach ($this->dirs as $dir) {
            $iterator->append($this->searchInDirectory($dir));
        }

        foreach ($this->iterators as $it) {
            $iterator->append($it);
        }

        return $iterator;
    }

    /**
     * Appends an existing set of files/directories to the finder.
     *
     * The set can be another Finder, an Iterator, an IteratorAggregate, or even a plain array.
     *
     * @param mixed $iterator
     *
     * @return Finder The finder
     *
     * @throws \InvalidArgumentException When the given argument is not iterable.
     */
    public function append($iterator)
    {
        if ($iterator instanceof \IteratorAggregate) {
            $this->iterators[] = $iterator->getIterator();
        } elseif ($iterator instanceof \Iterator) {
            $this->iterators[] = $iterator;
        } elseif ($iterator instanceof \Traversable || is_array($iterator)) {
            $it = new \ArrayIterator();
            foreach ($iterator as $file) {
                $it->append($file instanceof \SplFileInfo ? $file : new \SplFileInfo($file));
            }
            $this->iterators[] = $it;
        } else {
            throw new \InvalidArgumentException('Finder::append() method wrong argument type.');
        }

        return $this;
    }

    /**
     * Counts all the results collected by the iterators.
     *
     * @return int
     */
    public function count()
    {
        return iterator_count($this->getIterator());
    }

    /**
     * @return Finder The current Finder instance
     */
    private function sortAdapters()
    {
        uasort($this->adapters, function (array $a, array $b) {
            if ($a['selected'] || $b['selected']) {
                return $a['selected'] ? -1 : 1;
            }

            return $a['priority'] > $b['priority'] ? -1 : 1;
        });

        return $this;
    }

    /**
     * @param $dir
     *
     * @return \Iterator
     *
     * @throws \RuntimeException When none of the adapters are supported
     */
    private function searchInDirectory($dir)
    {
        if (static::IGNORE_VCS_FILES === (static::IGNORE_VCS_FILES & $this->ignore)) {
            $this->exclude = array_merge($this->exclude, self::$vcsPatterns);
        }

        if (static::IGNORE_DOT_FILES === (static::IGNORE_DOT_FILES & $this->ignore)) {
            $this->notPaths[] = '#(^|/)\..+(/|$)#';
        }

        foreach ($this->adapters as $adapter) {
            if ($adapter['adapter']->isSupported()) {
                try {
                    return $this
                        ->buildAdapter($adapter['adapter'])
                        ->searchInDirectory($dir);
                } catch (ExceptionInterface $e) {
                }
            }
        }

        throw new \RuntimeException('No supported adapter found.');
    }

    /**
     * @param AdapterInterface $adapter
     *
     * @return AdapterInterface
     */
    private function buildAdapter(AdapterInterface $adapter)
    {
        return $adapter
            ->setFollowLinks($this->followLinks)
            ->setDepths($this->depths)
            ->setMode($this->mode)
            ->setExclude($this->exclude)
            ->setNames($this->names)
            ->setNotNames($this->notNames)
            ->setContains($this->contains)
            ->setNotContains($this->notContains)
            ->setSizes($this->sizes)
            ->setDates($this->dates)
            ->setFilters($this->filters)
            ->setSort($this->sort)
            ->setPath($this->paths)
            ->setNotPath($this->notPaths)
            ->ignoreUnreadableDirs($this->ignoreUnreadableDirs);
    }

    /**
     * Unselects all adapters.
     */
    private function resetAdapterSelection()
    {
        $this->adapters = array_map(function (array $properties) {
            $properties['selected'] = false;

            return $properties;
        }, $this->adapters);
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder;

/**
 * Extends \SplFileInfo to support relative paths.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class SplFileInfo extends \SplFileInfo
{
    private $relativePath;
    private $relativePathname;

    /**
     * Constructor.
     *
     * @param string $file             The file name
     * @param string $relativePath     The relative path
     * @param string $relativePathname The relative path name
     */
    public function __construct($file, $relativePath, $relativePathname)
    {
        parent::__construct($file);
        $this->relativePath = $relativePath;
        $this->relativePathname = $relativePathname;
    }

    /**
     * Returns the relative path.
     *
     * @return string the relative path
     */
    public function getRelativePath()
    {
        return $this->relativePath;
    }

    /**
     * Returns the relative path name.
     *
     * @return string the relative path name
     */
    public function getRelativePathname()
    {
        return $this->relativePathname;
    }

    /**
     * Returns the contents of the file.
     *
     * @return string the contents of the file
     *
     * @throws \RuntimeException
     */
    public function getContents()
    {
        $level = error_reporting(0);
        $content = file_get_contents($this->getPathname());
        error_reporting($level);
        if (false === $content) {
            $error = error_get_last();
            throw new \RuntimeException($error['message']);
        }

        return $content;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Iterator;

/**
 * PathFilterIterator filters files by path patterns (e.g. some/special/dir).
 *
 * @author Fabien Potencier  <fabien@symfony.com>
 * @author Włodzimierz Gajda <gajdaw@gajdaw.pl>
 */
class PathFilterIterator extends MultiplePcreFilterIterator
{
    /**
     * Filters the iterator values.
     *
     * @return bool true if the value should be kept, false otherwise
     */
    public function accept()
    {
        $filename = $this->current()->getRelativePathname();

        if ('\\' === DIRECTORY_SEPARATOR) {
            $filename = strtr($filename, '\\', '/');
        }

        // should at least not match one rule to exclude
        foreach ($this->noMatchRegexps as $regex) {
            if (preg_match($regex, $filename)) {
                return false;
            }
        }

        // should at least match one rule
        $match = true;
        if ($this->matchRegexps) {
            $match = false;
            foreach ($this->matchRegexps as $regex) {
                if (preg_match($regex, $filename)) {
                    return true;
                }
            }
        }

        return $match;
    }

    /**
     * Converts strings to regexp.
     *
     * PCRE patterns are left unchanged.
     *
     * Default conversion:
     *     'lorem/ipsum/dolor' ==>  'lorem\/ipsum\/dolor/'
     *
     * Use only / as directory separator (on Windows also).
     *
     * @param string $str Pattern: regexp or dirname.
     *
     * @return string regexp corresponding to a given string or regexp
     */
    protected function toRegex($str)
    {
        return $this->isRegex($str) ? $str : '/'.preg_quote($str, '/').'/';
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Iterator;

use Symfony\Component\Finder\Expression\Expression;

/**
 * FilenameFilterIterator filters files by patterns (a regexp, a glob, or a string).
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class FilenameFilterIterator extends MultiplePcreFilterIterator
{
    /**
     * Filters the iterator values.
     *
     * @return bool true if the value should be kept, false otherwise
     */
    public function accept()
    {
        $filename = $this->current()->getFilename();

        // should at least not match one rule to exclude
        foreach ($this->noMatchRegexps as $regex) {
            if (preg_match($regex, $filename)) {
                return false;
            }
        }

        // should at least match one rule
        $match = true;
        if ($this->matchRegexps) {
            $match = false;
            foreach ($this->matchRegexps as $regex) {
                if (preg_match($regex, $filename)) {
                    return true;
                }
            }
        }

        return $match;
    }

    /**
     * Converts glob to regexp.
     *
     * PCRE patterns are left unchanged.
     * Glob strings are transformed with Glob::toRegex().
     *
     * @param string $str Pattern: glob or regexp
     *
     * @return string regexp corresponding to a given glob or regexp
     */
    protected function toRegex($str)
    {
        return Expression::create($str)->getRegex()->render();
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Iterator;

use Symfony\Component\Finder\SplFileInfo;

/**
 * Iterate over shell command result.
 *
 * @author Jean-François Simon <contact@jfsimon.fr>
 */
class FilePathsIterator extends \ArrayIterator
{
    /**
     * @var string
     */
    private $baseDir;

    /**
     * @var int
     */
    private $baseDirLength;

    /**
     * @var string
     */
    private $subPath;

    /**
     * @var string
     */
    private $subPathname;

    /**
     * @var SplFileInfo
     */
    private $current;

    /**
     * @param array  $paths   List of paths returned by shell command
     * @param string $baseDir Base dir for relative path building
     */
    public function __construct(array $paths, $baseDir)
    {
        $this->baseDir = $baseDir;
        $this->baseDirLength = strlen($baseDir);

        parent::__construct($paths);
    }

    /**
     * @param string $name
     * @param array  $arguments
     *
     * @return mixed
     */
    public function __call($name, array $arguments)
    {
        return call_user_func_array(array($this->current(), $name), $arguments);
    }

    /**
     * Return an instance of SplFileInfo with support for relative paths.
     *
     * @return SplFileInfo File information
     */
    public function current()
    {
        return $this->current;
    }

    /**
     * @return string
     */
    public function key()
    {
        return $this->current->getPathname();
    }

    public function next()
    {
        parent::next();
        $this->buildProperties();
    }

    public function rewind()
    {
        parent::rewind();
        $this->buildProperties();
    }

    /**
     * @return string
     */
    public function getSubPath()
    {
        return $this->subPath;
    }

    /**
     * @return string
     */
    public function getSubPathname()
    {
        return $this->subPathname;
    }

    private function buildProperties()
    {
        $absolutePath = parent::current();

        if ($this->baseDir === substr($absolutePath, 0, $this->baseDirLength)) {
            $this->subPathname = ltrim(substr($absolutePath, $this->baseDirLength), '/\\');
            $dir = dirname($this->subPathname);
            $this->subPath = '.' === $dir ? '' : $dir;
        } else {
            $this->subPath = $this->subPathname = '';
        }

        $this->current = new SplFileInfo(parent::current(), $this->subPath, $this->subPathname);
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Iterator;

use Symfony\Component\Finder\Expression\Expression;

/**
 * MultiplePcreFilterIterator filters files using patterns (regexps, globs or strings).
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
abstract class MultiplePcreFilterIterator extends FilterIterator
{
    protected $matchRegexps = array();
    protected $noMatchRegexps = array();

    /**
     * Constructor.
     *
     * @param \Iterator $iterator        The Iterator to filter
     * @param array     $matchPatterns   An array of patterns that need to match
     * @param array     $noMatchPatterns An array of patterns that need to not match
     */
    public function __construct(\Iterator $iterator, array $matchPatterns, array $noMatchPatterns)
    {
        foreach ($matchPatterns as $pattern) {
            $this->matchRegexps[] = $this->toRegex($pattern);
        }

        foreach ($noMatchPatterns as $pattern) {
            $this->noMatchRegexps[] = $this->toRegex($pattern);
        }

        parent::__construct($iterator);
    }

    /**
     * Checks whether the string is a regex.
     *
     * @param string $str
     *
     * @return bool Whether the given string is a regex
     */
    protected function isRegex($str)
    {
        return Expression::create($str)->isRegex();
    }

    /**
     * Converts string into regexp.
     *
     * @param string $str Pattern
     *
     * @return string regexp corresponding to a given string
     */
    abstract protected function toRegex($str);
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Iterator;

use Symfony\Component\Finder\Comparator\DateComparator;

/**
 * DateRangeFilterIterator filters out files that are not in the given date range (last modified dates).
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class DateRangeFilterIterator extends FilterIterator
{
    private $comparators = array();

    /**
     * Constructor.
     *
     * @param \Iterator        $iterator    The Iterator to filter
     * @param DateComparator[] $comparators An array of DateComparator instances
     */
    public function __construct(\Iterator $iterator, array $comparators)
    {
        $this->comparators = $comparators;

        parent::__construct($iterator);
    }

    /**
     * Filters the iterator values.
     *
     * @return bool true if the value should be kept, false otherwise
     */
    public function accept()
    {
        $fileinfo = $this->current();

        if (!file_exists($fileinfo->getRealPath())) {
            return false;
        }

        $filedate = $fileinfo->getMTime();
        foreach ($this->comparators as $compare) {
            if (!$compare->test($filedate)) {
                return false;
            }
        }

        return true;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Iterator;

/**
 * SortableIterator applies a sort on a given Iterator.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class SortableIterator implements \IteratorAggregate
{
    const SORT_BY_NAME = 1;
    const SORT_BY_TYPE = 2;
    const SORT_BY_ACCESSED_TIME = 3;
    const SORT_BY_CHANGED_TIME = 4;
    const SORT_BY_MODIFIED_TIME = 5;

    private $iterator;
    private $sort;

    /**
     * Constructor.
     *
     * @param \Traversable $iterator The Iterator to filter
     * @param int|callable $sort     The sort type (SORT_BY_NAME, SORT_BY_TYPE, or a PHP callback)
     *
     * @throws \InvalidArgumentException
     */
    public function __construct(\Traversable $iterator, $sort)
    {
        $this->iterator = $iterator;

        if (self::SORT_BY_NAME === $sort) {
            $this->sort = function ($a, $b) {
                return strcmp($a->getRealpath(), $b->getRealpath());
            };
        } elseif (self::SORT_BY_TYPE === $sort) {
            $this->sort = function ($a, $b) {
                if ($a->isDir() && $b->isFile()) {
                    return -1;
                } elseif ($a->isFile() && $b->isDir()) {
                    return 1;
                }

                return strcmp($a->getRealpath(), $b->getRealpath());
            };
        } elseif (self::SORT_BY_ACCESSED_TIME === $sort) {
            $this->sort = function ($a, $b) {
                return ($a->getATime() - $b->getATime());
            };
        } elseif (self::SORT_BY_CHANGED_TIME === $sort) {
            $this->sort = function ($a, $b) {
                return ($a->getCTime() - $b->getCTime());
            };
        } elseif (self::SORT_BY_MODIFIED_TIME === $sort) {
            $this->sort = function ($a, $b) {
                return ($a->getMTime() - $b->getMTime());
            };
        } elseif (is_callable($sort)) {
            $this->sort = $sort;
        } else {
            throw new \InvalidArgumentException('The SortableIterator takes a PHP callable or a valid built-in sort algorithm as an argument.');
        }
    }

    public function getIterator()
    {
        $array = iterator_to_array($this->iterator, true);
        uasort($array, $this->sort);

        return new \ArrayIterator($array);
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Iterator;

/**
 * This iterator just overrides the rewind method in order to correct a PHP bug.
 *
 * @see https://bugs.php.net/bug.php?id=49104
 *
 * @author Alex Bogomazov
 */
abstract class FilterIterator extends \FilterIterator
{
    /**
     * This is a workaround for the problem with \FilterIterator leaving inner \FilesystemIterator in wrong state after
     * rewind in some cases.
     *
     * @see FilterIterator::rewind()
     */
    public function rewind()
    {
        $iterator = $this;
        while ($iterator instanceof \OuterIterator) {
            $innerIterator = $iterator->getInnerIterator();

            if ($innerIterator instanceof RecursiveDirectoryIterator) {
                if ($innerIterator->isRewindable()) {
                    $innerIterator->next();
                    $innerIterator->rewind();
                }
            } elseif ($iterator->getInnerIterator() instanceof \FilesystemIterator) {
                $iterator->getInnerIterator()->next();
                $iterator->getInnerIterator()->rewind();
            }
            $iterator = $iterator->getInnerIterator();
        }

        parent::rewind();
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Iterator;

/**
 * FileTypeFilterIterator only keeps files, directories, or both.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class FileTypeFilterIterator extends FilterIterator
{
    const ONLY_FILES = 1;
    const ONLY_DIRECTORIES = 2;

    private $mode;

    /**
     * Constructor.
     *
     * @param \Iterator $iterator The Iterator to filter
     * @param int       $mode     The mode (self::ONLY_FILES or self::ONLY_DIRECTORIES)
     */
    public function __construct(\Iterator $iterator, $mode)
    {
        $this->mode = $mode;

        parent::__construct($iterator);
    }

    /**
     * Filters the iterator values.
     *
     * @return bool true if the value should be kept, false otherwise
     */
    public function accept()
    {
        $fileinfo = $this->current();
        if (self::ONLY_DIRECTORIES === (self::ONLY_DIRECTORIES & $this->mode) && $fileinfo->isFile()) {
            return false;
        } elseif (self::ONLY_FILES === (self::ONLY_FILES & $this->mode) && $fileinfo->isDir()) {
            return false;
        }

        return true;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Iterator;

use Symfony\Component\Finder\Exception\AccessDeniedException;
use Symfony\Component\Finder\SplFileInfo;

/**
 * Extends the \RecursiveDirectoryIterator to support relative paths.
 *
 * @author Victor Berchet <victor@suumit.com>
 */
class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
{
    /**
     * @var bool
     */
    private $ignoreUnreadableDirs;

    /**
     * @var bool
     */
    private $rewindable;

    /**
     * Constructor.
     *
     * @param string $path
     * @param int    $flags
     * @param bool   $ignoreUnreadableDirs
     *
     * @throws \RuntimeException
     */
    public function __construct($path, $flags, $ignoreUnreadableDirs = false)
    {
        if ($flags & (self::CURRENT_AS_PATHNAME | self::CURRENT_AS_SELF)) {
            throw new \RuntimeException('This iterator only support returning current as fileinfo.');
        }

        parent::__construct($path, $flags);
        $this->ignoreUnreadableDirs = $ignoreUnreadableDirs;
    }

    /**
     * Return an instance of SplFileInfo with support for relative paths.
     *
     * @return SplFileInfo File information
     */
    public function current()
    {
        return new SplFileInfo(parent::current()->getPathname(), $this->getSubPath(), $this->getSubPathname());
    }

    /**
     * @return \RecursiveIterator
     *
     * @throws AccessDeniedException
     */
    public function getChildren()
    {
        try {
            $children = parent::getChildren();

            if ($children instanceof self) {
                // parent method will call the constructor with default arguments, so unreadable dirs won't be ignored anymore
                $children->ignoreUnreadableDirs = $this->ignoreUnreadableDirs;
            }

            return $children;
        } catch (\UnexpectedValueException $e) {
            if ($this->ignoreUnreadableDirs) {
                // If directory is unreadable and finder is set to ignore it, a fake empty content is returned.
                return new \RecursiveArrayIterator(array());
            } else {
                throw new AccessDeniedException($e->getMessage(), $e->getCode(), $e);
            }
        }
    }

    /**
     * Do nothing for non rewindable stream.
     */
    public function rewind()
    {
        if (false === $this->isRewindable()) {
            return;
        }

        // @see https://bugs.php.net/bug.php?id=49104
        parent::next();

        parent::rewind();
    }

    /**
     * Checks if the stream is rewindable.
     *
     * @return bool true when the stream is rewindable, false otherwise
     */
    public function isRewindable()
    {
        if (null !== $this->rewindable) {
            return $this->rewindable;
        }

        if (false !== $stream = @opendir($this->getPath())) {
            $infos = stream_get_meta_data($stream);
            closedir($stream);

            if ($infos['seekable']) {
                return $this->rewindable = true;
            }
        }

        return $this->rewindable = false;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Iterator;

use Symfony\Component\Finder\Comparator\NumberComparator;

/**
 * SizeRangeFilterIterator filters out files that are not in the given size range.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class SizeRangeFilterIterator extends FilterIterator
{
    private $comparators = array();

    /**
     * Constructor.
     *
     * @param \Iterator          $iterator    The Iterator to filter
     * @param NumberComparator[] $comparators An array of NumberComparator instances
     */
    public function __construct(\Iterator $iterator, array $comparators)
    {
        $this->comparators = $comparators;

        parent::__construct($iterator);
    }

    /**
     * Filters the iterator values.
     *
     * @return bool true if the value should be kept, false otherwise
     */
    public function accept()
    {
        $fileinfo = $this->current();
        if (!$fileinfo->isFile()) {
            return true;
        }

        $filesize = $fileinfo->getSize();
        foreach ($this->comparators as $compare) {
            if (!$compare->test($filesize)) {
                return false;
            }
        }

        return true;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Iterator;

/**
 * DepthRangeFilterIterator limits the directory depth.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class DepthRangeFilterIterator extends FilterIterator
{
    private $minDepth = 0;

    /**
     * Constructor.
     *
     * @param \RecursiveIteratorIterator $iterator The Iterator to filter
     * @param int                        $minDepth The min depth
     * @param int                        $maxDepth The max depth
     */
    public function __construct(\RecursiveIteratorIterator $iterator, $minDepth = 0, $maxDepth = PHP_INT_MAX)
    {
        $this->minDepth = $minDepth;
        $iterator->setMaxDepth(PHP_INT_MAX === $maxDepth ? -1 : $maxDepth);

        parent::__construct($iterator);
    }

    /**
     * Filters the iterator values.
     *
     * @return bool true if the value should be kept, false otherwise
     */
    public function accept()
    {
        return $this->getInnerIterator()->getDepth() >= $this->minDepth;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Iterator;

/**
 * ExcludeDirectoryFilterIterator filters out directories.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class ExcludeDirectoryFilterIterator extends FilterIterator
{
    private $patterns = array();

    /**
     * Constructor.
     *
     * @param \Iterator $iterator    The Iterator to filter
     * @param array     $directories An array of directories to exclude
     */
    public function __construct(\Iterator $iterator, array $directories)
    {
        foreach ($directories as $directory) {
            $this->patterns[] = '#(^|/)'.preg_quote($directory, '#').'(/|$)#';
        }

        parent::__construct($iterator);
    }

    /**
     * Filters the iterator values.
     *
     * @return bool true if the value should be kept, false otherwise
     */
    public function accept()
    {
        $path = $this->isDir() ? $this->current()->getRelativePathname() : $this->current()->getRelativePath();
        $path = strtr($path, '\\', '/');
        foreach ($this->patterns as $pattern) {
            if (preg_match($pattern, $path)) {
                return false;
            }
        }

        return true;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Iterator;

/**
 * FilecontentFilterIterator filters files by their contents using patterns (regexps or strings).
 *
 * @author Fabien Potencier  <fabien@symfony.com>
 * @author Włodzimierz Gajda <gajdaw@gajdaw.pl>
 */
class FilecontentFilterIterator extends MultiplePcreFilterIterator
{
    /**
     * Filters the iterator values.
     *
     * @return bool true if the value should be kept, false otherwise
     */
    public function accept()
    {
        if (!$this->matchRegexps && !$this->noMatchRegexps) {
            return true;
        }

        $fileinfo = $this->current();

        if ($fileinfo->isDir() || !$fileinfo->isReadable()) {
            return false;
        }

        $content = $fileinfo->getContents();
        if (!$content) {
            return false;
        }

        // should at least not match one rule to exclude
        foreach ($this->noMatchRegexps as $regex) {
            if (preg_match($regex, $content)) {
                return false;
            }
        }

        // should at least match one rule
        $match = true;
        if ($this->matchRegexps) {
            $match = false;
            foreach ($this->matchRegexps as $regex) {
                if (preg_match($regex, $content)) {
                    return true;
                }
            }
        }

        return $match;
    }

    /**
     * Converts string to regexp if necessary.
     *
     * @param string $str Pattern: string or regexp
     *
     * @return string regexp corresponding to a given string or regexp
     */
    protected function toRegex($str)
    {
        return $this->isRegex($str) ? $str : '/'.preg_quote($str, '/').'/';
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Finder\Iterator;

/**
 * CustomFilterIterator filters files by applying anonymous functions.
 *
 * The anonymous function receives a \SplFileInfo and must return false
 * to remove files.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */
class CustomFilterIterator extends FilterIterator
{
    private $filters = array();

    /**
     * Constructor.
     *
     * @param \Iterator $iterator The Iterator to filter
     * @param array     $filters  An array of PHP callbacks
     *
     * @throws \InvalidArgumentException
     */
    public function __construct(\Iterator $iterator, array $filters)
    {
        foreach ($filters as $filter) {
            if (!is_callable($filter)) {
                throw new \InvalidArgumentException('Invalid PHP callback.');
            }
        }
        $this->filters = $filters;

        parent::__construct($iterator);
    }

    /**
     * Filters the iterator values.
     *
     * @return bool true if the value should be kept, false otherwise
     */
    public function accept()
    {
        $fileinfo = $this->current();

        foreach ($this->filters as $filter) {
            if (false === call_user_func($filter, $fileinfo)) {
                return false;
            }
        }

        return true;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Process;

use Symfony\Component\Process\Exception\InvalidArgumentException;

/**
 * ProcessUtils is a bunch of utility methods.
 *
 * This class contains static methods only and is not meant to be instantiated.
 *
 * @author Martin Hasoň <martin.hason@gmail.com>
 */
class ProcessUtils
{
    /**
     * This class should not be instantiated.
     */
    private function __construct()
    {
    }

    /**
     * Escapes a string to be used as a shell argument.
     *
     * @param string $argument The argument that will be escaped
     *
     * @return string The escaped argument
     */
    public static function escapeArgument($argument)
    {
        //Fix for PHP bug #43784 escapeshellarg removes % from given string
        //Fix for PHP bug #49446 escapeshellarg doesn't work on Windows
        //@see https://bugs.php.net/bug.php?id=43784
        //@see https://bugs.php.net/bug.php?id=49446
        if ('\\' === DIRECTORY_SEPARATOR) {
            if ('' === $argument) {
                return escapeshellarg($argument);
            }

            $escapedArgument = '';
            $quote = false;
            foreach (preg_split('/(")/', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) {
                if ('"' === $part) {
                    $escapedArgument .= '\\"';
                } elseif (self::isSurroundedBy($part, '%')) {
                    // Avoid environment variable expansion
                    $escapedArgument .= '^%"'.substr($part, 1, -1).'"^%';
                } else {
                    // escape trailing backslash
                    if ('\\' === substr($part, -1)) {
                        $part .= '\\';
                    }
                    $quote = true;
                    $escapedArgument .= $part;
                }
            }
            if ($quote) {
                $escapedArgument = '"'.$escapedArgument.'"';
            }

            return $escapedArgument;
        }

        return escapeshellarg($argument);
    }

    /**
     * Validates and normalizes a Process input.
     *
     * @param string $caller The name of method call that validates the input
     * @param mixed  $input  The input to validate
     *
     * @return string The validated input
     *
     * @throws InvalidArgumentException In case the input is not valid
     */
    public static function validateInput($caller, $input)
    {
        if (null !== $input) {
            if (is_resource($input)) {
                return $input;
            }
            if (is_scalar($input)) {
                return (string) $input;
            }
            // deprecated as of Symfony 2.5, to be removed in 3.0
            if (is_object($input) && method_exists($input, '__toString')) {
                return (string) $input;
            }

            throw new InvalidArgumentException(sprintf('%s only accepts strings or stream resources.', $caller));
        }

        return $input;
    }

    private static function isSurroundedBy($arg, $char)
    {
        return 2 < strlen($arg) && $char === $arg[0] && $char === $arg[strlen($arg) - 1];
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Process;

/**
 * An executable finder specifically designed for the PHP executable.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
 */
class PhpExecutableFinder
{
    private $executableFinder;

    public function __construct()
    {
        $this->executableFinder = new ExecutableFinder();
    }

    /**
     * Finds The PHP executable.
     *
     * @param bool $includeArgs Whether or not include command arguments
     *
     * @return string|false The PHP executable path or false if it cannot be found
     */
    public function find($includeArgs = true)
    {
        // HHVM support
        if (defined('HHVM_VERSION')) {
            return (getenv('PHP_BINARY') ?: PHP_BINARY).($includeArgs ? ' '.implode(' ', $this->findArguments()) : '');
        }

        // PHP_BINARY return the current sapi executable
        if (defined('PHP_BINARY') && PHP_BINARY && in_array(PHP_SAPI, array('cli', 'cli-server')) && is_file(PHP_BINARY)) {
            return PHP_BINARY;
        }

        if ($php = getenv('PHP_PATH')) {
            if (!is_executable($php)) {
                return false;
            }

            return $php;
        }

        if ($php = getenv('PHP_PEAR_PHP_BIN')) {
            if (is_executable($php)) {
                return $php;
            }
        }

        $dirs = array(PHP_BINDIR);
        if ('\\' === DIRECTORY_SEPARATOR) {
            $dirs[] = 'C:\xampp\php\\';
        }

        return $this->executableFinder->find('php', false, $dirs);
    }

    /**
     * Finds the PHP executable arguments.
     *
     * @return array The PHP executable arguments
     */
    public function findArguments()
    {
        $arguments = array();

        // HHVM support
        if (defined('HHVM_VERSION')) {
            $arguments[] = '--php';
        }

        return $arguments;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Process;

use Symfony\Component\Process\Exception\InvalidArgumentException;
use Symfony\Component\Process\Exception\LogicException;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Exception\ProcessTimedOutException;
use Symfony\Component\Process\Exception\RuntimeException;
use Symfony\Component\Process\Pipes\PipesInterface;
use Symfony\Component\Process\Pipes\UnixPipes;
use Symfony\Component\Process\Pipes\WindowsPipes;

/**
 * Process is a thin wrapper around proc_* functions to easily
 * start independent PHP processes.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 * @author Romain Neutron <imprec@gmail.com>
 *
 * @api
 */
class Process
{
    const ERR = 'err';
    const OUT = 'out';

    const STATUS_READY = 'ready';
    const STATUS_STARTED = 'started';
    const STATUS_TERMINATED = 'terminated';

    const STDIN = 0;
    const STDOUT = 1;
    const STDERR = 2;

    // Timeout Precision in seconds.
    const TIMEOUT_PRECISION = 0.2;

    private $callback;
    private $commandline;
    private $cwd;
    private $env;
    private $input;
    private $starttime;
    private $lastOutputTime;
    private $timeout;
    private $idleTimeout;
    private $options;
    private $exitcode;
    private $fallbackExitcode;
    private $processInformation;
    private $outputDisabled = false;
    private $stdout;
    private $stderr;
    private $enhanceWindowsCompatibility = true;
    private $enhanceSigchildCompatibility;
    private $process;
    private $status = self::STATUS_READY;
    private $incrementalOutputOffset = 0;
    private $incrementalErrorOutputOffset = 0;
    private $tty;
    private $pty;

    private $useFileHandles = false;
    /** @var PipesInterface */
    private $processPipes;

    private $latestSignal;

    private static $sigchild;

    /**
     * Exit codes translation table.
     *
     * User-defined errors must use exit codes in the 64-113 range.
     *
     * @var array
     */
    public static $exitCodes = array(
        0 => 'OK',
        1 => 'General error',
        2 => 'Misuse of shell builtins',

        126 => 'Invoked command cannot execute',
        127 => 'Command not found',
        128 => 'Invalid exit argument',

        // signals
        129 => 'Hangup',
        130 => 'Interrupt',
        131 => 'Quit and dump core',
        132 => 'Illegal instruction',
        133 => 'Trace/breakpoint trap',
        134 => 'Process aborted',
        135 => 'Bus error: "access to undefined portion of memory object"',
        136 => 'Floating point exception: "erroneous arithmetic operation"',
        137 => 'Kill (terminate immediately)',
        138 => 'User-defined 1',
        139 => 'Segmentation violation',
        140 => 'User-defined 2',
        141 => 'Write to pipe with no one reading',
        142 => 'Signal raised by alarm',
        143 => 'Termination (request to terminate)',
        // 144 - not defined
        145 => 'Child process terminated, stopped (or continued*)',
        146 => 'Continue if stopped',
        147 => 'Stop executing temporarily',
        148 => 'Terminal stop signal',
        149 => 'Background process attempting to read from tty ("in")',
        150 => 'Background process attempting to write to tty ("out")',
        151 => 'Urgent data available on socket',
        152 => 'CPU time limit exceeded',
        153 => 'File size limit exceeded',
        154 => 'Signal raised by timer counting virtual time: "virtual timer expired"',
        155 => 'Profiling timer expired',
        // 156 - not defined
        157 => 'Pollable event',
        // 158 - not defined
        159 => 'Bad syscall',
    );

    /**
     * Constructor.
     *
     * @param string         $commandline The command line to run
     * @param string|null    $cwd         The working directory or null to use the working dir of the current PHP process
     * @param array|null     $env         The environment variables or null to inherit
     * @param string|null    $input       The input
     * @param int|float|null $timeout     The timeout in seconds or null to disable
     * @param array          $options     An array of options for proc_open
     *
     * @throws RuntimeException When proc_open is not installed
     *
     * @api
     */
    public function __construct($commandline, $cwd = null, array $env = null, $input = null, $timeout = 60, array $options = array())
    {
        if (!function_exists('proc_open')) {
            throw new RuntimeException('The Process class relies on proc_open, which is not available on your PHP installation.');
        }

        $this->commandline = $commandline;
        $this->cwd = $cwd;

        // on Windows, if the cwd changed via chdir(), proc_open defaults to the dir where PHP was started
        // on Gnu/Linux, PHP builds with --enable-maintainer-zts are also affected
        // @see : https://bugs.php.net/bug.php?id=51800
        // @see : https://bugs.php.net/bug.php?id=50524
        if (null === $this->cwd && (defined('ZEND_THREAD_SAFE') || '\\' === DIRECTORY_SEPARATOR)) {
            $this->cwd = getcwd();
        }
        if (null !== $env) {
            $this->setEnv($env);
        }

        $this->input = $input;
        $this->setTimeout($timeout);
        $this->useFileHandles = '\\' === DIRECTORY_SEPARATOR;
        $this->pty = false;
        $this->enhanceWindowsCompatibility = true;
        $this->enhanceSigchildCompatibility = '\\' !== DIRECTORY_SEPARATOR && $this->isSigchildEnabled();
        $this->options = array_replace(array('suppress_errors' => true, 'binary_pipes' => true), $options);
    }

    public function __destruct()
    {
        // stop() will check if we have a process running.
        $this->stop();
    }

    public function __clone()
    {
        $this->resetProcessData();
    }

    /**
     * Runs the process.
     *
     * The callback receives the type of output (out or err) and
     * some bytes from the output in real-time. It allows to have feedback
     * from the independent process during execution.
     *
     * The STDOUT and STDERR are also available after the process is finished
     * via the getOutput() and getErrorOutput() methods.
     *
     * @param callable|null $callback A PHP callback to run whenever there is some
     *                                output available on STDOUT or STDERR
     *
     * @return int The exit status code
     *
     * @throws RuntimeException When process can't be launched
     * @throws RuntimeException When process stopped after receiving signal
     * @throws LogicException   In case a callback is provided and output has been disabled
     *
     * @api
     */
    public function run($callback = null)
    {
        $this->start($callback);

        return $this->wait();
    }

    /**
     * Runs the process.
     *
     * This is identical to run() except that an exception is thrown if the process
     * exits with a non-zero exit code.
     *
     * @param callable|null $callback
     *
     * @return self
     *
     * @throws RuntimeException       if PHP was compiled with --enable-sigchild and the enhanced sigchild compatibility mode is not enabled
     * @throws ProcessFailedException if the process didn't terminate successfully
     */
    public function mustRun($callback = null)
    {
        if ($this->isSigchildEnabled() && !$this->enhanceSigchildCompatibility) {
            throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.');
        }

        if (0 !== $this->run($callback)) {
            throw new ProcessFailedException($this);
        }

        return $this;
    }

    /**
     * Starts the process and returns after writing the input to STDIN.
     *
     * This method blocks until all STDIN data is sent to the process then it
     * returns while the process runs in the background.
     *
     * The termination of the process can be awaited with wait().
     *
     * The callback receives the type of output (out or err) and some bytes from
     * the output in real-time while writing the standard input to the process.
     * It allows to have feedback from the independent process during execution.
     * If there is no callback passed, the wait() method can be called
     * with true as a second parameter then the callback will get all data occurred
     * in (and since) the start call.
     *
     * @param callable|null $callback A PHP callback to run whenever there is some
     *                                output available on STDOUT or STDERR
     *
     * @throws RuntimeException When process can't be launched
     * @throws RuntimeException When process is already running
     * @throws LogicException   In case a callback is provided and output has been disabled
     */
    public function start($callback = null)
    {
        if ($this->isRunning()) {
            throw new RuntimeException('Process is already running');
        }
        if ($this->outputDisabled && null !== $callback) {
            throw new LogicException('Output has been disabled, enable it to allow the use of a callback.');
        }

        $this->resetProcessData();
        $this->starttime = $this->lastOutputTime = microtime(true);
        $this->callback = $this->buildCallback($callback);
        $descriptors = $this->getDescriptors();

        $commandline = $this->commandline;

        if ('\\' === DIRECTORY_SEPARATOR && $this->enhanceWindowsCompatibility) {
            $commandline = 'cmd /V:ON /E:ON /C "('.$commandline.')';
            foreach ($this->processPipes->getFiles() as $offset => $filename) {
                $commandline .= ' '.$offset.'>'.ProcessUtils::escapeArgument($filename);
            }
            $commandline .= '"';

            if (!isset($this->options['bypass_shell'])) {
                $this->options['bypass_shell'] = true;
            }
        }

        $this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $this->env, $this->options);

        if (!is_resource($this->process)) {
            throw new RuntimeException('Unable to launch a new process.');
        }
        $this->status = self::STATUS_STARTED;

        if ($this->tty) {
            return;
        }

        $this->updateStatus(false);
        $this->checkTimeout();
    }

    /**
     * Restarts the process.
     *
     * Be warned that the process is cloned before being started.
     *
     * @param callable|null $callback A PHP callback to run whenever there is some
     *                                output available on STDOUT or STDERR
     *
     * @return Process The new process
     *
     * @throws RuntimeException When process can't be launched
     * @throws RuntimeException When process is already running
     *
     * @see start()
     */
    public function restart($callback = null)
    {
        if ($this->isRunning()) {
            throw new RuntimeException('Process is already running');
        }

        $process = clone $this;
        $process->start($callback);

        return $process;
    }

    /**
     * Waits for the process to terminate.
     *
     * The callback receives the type of output (out or err) and some bytes
     * from the output in real-time while writing the standard input to the process.
     * It allows to have feedback from the independent process during execution.
     *
     * @param callable|null $callback A valid PHP callback
     *
     * @return int The exitcode of the process
     *
     * @throws RuntimeException When process timed out
     * @throws RuntimeException When process stopped after receiving signal
     * @throws LogicException   When process is not yet started
     */
    public function wait($callback = null)
    {
        $this->requireProcessIsStarted(__FUNCTION__);

        $this->updateStatus(false);
        if (null !== $callback) {
            $this->callback = $this->buildCallback($callback);
        }

        do {
            $this->checkTimeout();
            $running = '\\' === DIRECTORY_SEPARATOR ? $this->isRunning() : $this->processPipes->areOpen();
            $close = '\\' !== DIRECTORY_SEPARATOR || !$running;
            $this->readPipes(true, $close);
        } while ($running);

        while ($this->isRunning()) {
            usleep(1000);
        }

        if ($this->processInformation['signaled'] && $this->processInformation['termsig'] !== $this->latestSignal) {
            throw new RuntimeException(sprintf('The process has been signaled with signal "%s".', $this->processInformation['termsig']));
        }

        return $this->exitcode;
    }

    /**
     * Returns the Pid (process identifier), if applicable.
     *
     * @return int|null The process id if running, null otherwise
     *
     * @throws RuntimeException In case --enable-sigchild is activated
     */
    public function getPid()
    {
        if ($this->isSigchildEnabled()) {
            throw new RuntimeException('This PHP has been compiled with --enable-sigchild. The process identifier can not be retrieved.');
        }

        $this->updateStatus(false);

        return $this->isRunning() ? $this->processInformation['pid'] : null;
    }

    /**
     * Sends a POSIX signal to the process.
     *
     * @param int $signal A valid POSIX signal (see http://www.php.net/manual/en/pcntl.constants.php)
     *
     * @return Process
     *
     * @throws LogicException   In case the process is not running
     * @throws RuntimeException In case --enable-sigchild is activated
     * @throws RuntimeException In case of failure
     */
    public function signal($signal)
    {
        $this->doSignal($signal, true);

        return $this;
    }

    /**
     * Disables fetching output and error output from the underlying process.
     *
     * @return Process
     *
     * @throws RuntimeException In case the process is already running
     * @throws LogicException   if an idle timeout is set
     */
    public function disableOutput()
    {
        if ($this->isRunning()) {
            throw new RuntimeException('Disabling output while the process is running is not possible.');
        }
        if (null !== $this->idleTimeout) {
            throw new LogicException('Output can not be disabled while an idle timeout is set.');
        }

        $this->outputDisabled = true;

        return $this;
    }

    /**
     * Enables fetching output and error output from the underlying process.
     *
     * @return Process
     *
     * @throws RuntimeException In case the process is already running
     */
    public function enableOutput()
    {
        if ($this->isRunning()) {
            throw new RuntimeException('Enabling output while the process is running is not possible.');
        }

        $this->outputDisabled = false;

        return $this;
    }

    /**
     * Returns true in case the output is disabled, false otherwise.
     *
     * @return bool
     */
    public function isOutputDisabled()
    {
        return $this->outputDisabled;
    }

    /**
     * Returns the current output of the process (STDOUT).
     *
     * @return string The process output
     *
     * @throws LogicException in case the output has been disabled
     * @throws LogicException In case the process is not started
     *
     * @api
     */
    public function getOutput()
    {
        if ($this->outputDisabled) {
            throw new LogicException('Output has been disabled.');
        }

        $this->requireProcessIsStarted(__FUNCTION__);

        $this->readPipes(false, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true);

        return $this->stdout;
    }

    /**
     * Returns the output incrementally.
     *
     * In comparison with the getOutput method which always return the whole
     * output, this one returns the new output since the last call.
     *
     * @throws LogicException in case the output has been disabled
     * @throws LogicException In case the process is not started
     *
     * @return string The process output since the last call
     */
    public function getIncrementalOutput()
    {
        $this->requireProcessIsStarted(__FUNCTION__);

        $data = $this->getOutput();

        $latest = substr($data, $this->incrementalOutputOffset);

        if (false === $latest) {
            return '';
        }

        $this->incrementalOutputOffset = strlen($data);

        return $latest;
    }

    /**
     * Clears the process output.
     *
     * @return Process
     */
    public function clearOutput()
    {
        $this->stdout = '';
        $this->incrementalOutputOffset = 0;

        return $this;
    }

    /**
     * Returns the current error output of the process (STDERR).
     *
     * @return string The process error output
     *
     * @throws LogicException in case the output has been disabled
     * @throws LogicException In case the process is not started
     *
     * @api
     */
    public function getErrorOutput()
    {
        if ($this->outputDisabled) {
            throw new LogicException('Output has been disabled.');
        }

        $this->requireProcessIsStarted(__FUNCTION__);

        $this->readPipes(false, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true);

        return $this->stderr;
    }

    /**
     * Returns the errorOutput incrementally.
     *
     * In comparison with the getErrorOutput method which always return the
     * whole error output, this one returns the new error output since the last
     * call.
     *
     * @throws LogicException in case the output has been disabled
     * @throws LogicException In case the process is not started
     *
     * @return string The process error output since the last call
     */
    public function getIncrementalErrorOutput()
    {
        $this->requireProcessIsStarted(__FUNCTION__);

        $data = $this->getErrorOutput();

        $latest = substr($data, $this->incrementalErrorOutputOffset);

        if (false === $latest) {
            return '';
        }

        $this->incrementalErrorOutputOffset = strlen($data);

        return $latest;
    }

    /**
     * Clears the process output.
     *
     * @return Process
     */
    public function clearErrorOutput()
    {
        $this->stderr = '';
        $this->incrementalErrorOutputOffset = 0;

        return $this;
    }

    /**
     * Returns the exit code returned by the process.
     *
     * @return null|int The exit status code, null if the Process is not terminated
     *
     * @throws RuntimeException In case --enable-sigchild is activated and the sigchild compatibility mode is disabled
     *
     * @api
     */
    public function getExitCode()
    {
        if ($this->isSigchildEnabled() && !$this->enhanceSigchildCompatibility) {
            throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.');
        }

        $this->updateStatus(false);

        return $this->exitcode;
    }

    /**
     * Returns a string representation for the exit code returned by the process.
     *
     * This method relies on the Unix exit code status standardization
     * and might not be relevant for other operating systems.
     *
     * @return null|string A string representation for the exit status code, null if the Process is not terminated.
     *
     * @throws RuntimeException In case --enable-sigchild is activated and the sigchild compatibility mode is disabled
     *
     * @see http://tldp.org/LDP/abs/html/exitcodes.html
     * @see http://en.wikipedia.org/wiki/Unix_signal
     */
    public function getExitCodeText()
    {
        if (null === $exitcode = $this->getExitCode()) {
            return;
        }

        return isset(self::$exitCodes[$exitcode]) ? self::$exitCodes[$exitcode] : 'Unknown error';
    }

    /**
     * Checks if the process ended successfully.
     *
     * @return bool true if the process ended successfully, false otherwise
     *
     * @api
     */
    public function isSuccessful()
    {
        return 0 === $this->getExitCode();
    }

    /**
     * Returns true if the child process has been terminated by an uncaught signal.
     *
     * It always returns false on Windows.
     *
     * @return bool
     *
     * @throws RuntimeException In case --enable-sigchild is activated
     * @throws LogicException   In case the process is not terminated
     *
     * @api
     */
    public function hasBeenSignaled()
    {
        $this->requireProcessIsTerminated(__FUNCTION__);

        if ($this->isSigchildEnabled()) {
            throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.');
        }

        $this->updateStatus(false);

        return $this->processInformation['signaled'];
    }

    /**
     * Returns the number of the signal that caused the child process to terminate its execution.
     *
     * It is only meaningful if hasBeenSignaled() returns true.
     *
     * @return int
     *
     * @throws RuntimeException In case --enable-sigchild is activated
     * @throws LogicException   In case the process is not terminated
     *
     * @api
     */
    public function getTermSignal()
    {
        $this->requireProcessIsTerminated(__FUNCTION__);

        if ($this->isSigchildEnabled()) {
            throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.');
        }

        $this->updateStatus(false);

        return $this->processInformation['termsig'];
    }

    /**
     * Returns true if the child process has been stopped by a signal.
     *
     * It always returns false on Windows.
     *
     * @return bool
     *
     * @throws LogicException In case the process is not terminated
     *
     * @api
     */
    public function hasBeenStopped()
    {
        $this->requireProcessIsTerminated(__FUNCTION__);

        $this->updateStatus(false);

        return $this->processInformation['stopped'];
    }

    /**
     * Returns the number of the signal that caused the child process to stop its execution.
     *
     * It is only meaningful if hasBeenStopped() returns true.
     *
     * @return int
     *
     * @throws LogicException In case the process is not terminated
     *
     * @api
     */
    public function getStopSignal()
    {
        $this->requireProcessIsTerminated(__FUNCTION__);

        $this->updateStatus(false);

        return $this->processInformation['stopsig'];
    }

    /**
     * Checks if the process is currently running.
     *
     * @return bool true if the process is currently running, false otherwise
     */
    public function isRunning()
    {
        if (self::STATUS_STARTED !== $this->status) {
            return false;
        }

        $this->updateStatus(false);

        return $this->processInformation['running'];
    }

    /**
     * Checks if the process has been started with no regard to the current state.
     *
     * @return bool true if status is ready, false otherwise
     */
    public function isStarted()
    {
        return $this->status != self::STATUS_READY;
    }

    /**
     * Checks if the process is terminated.
     *
     * @return bool true if process is terminated, false otherwise
     */
    public function isTerminated()
    {
        $this->updateStatus(false);

        return $this->status == self::STATUS_TERMINATED;
    }

    /**
     * Gets the process status.
     *
     * The status is one of: ready, started, terminated.
     *
     * @return string The current process status
     */
    public function getStatus()
    {
        $this->updateStatus(false);

        return $this->status;
    }

    /**
     * Stops the process.
     *
     * @param int|float $timeout The timeout in seconds
     * @param int       $signal  A POSIX signal to send in case the process has not stop at timeout, default is SIGKILL
     *
     * @return int The exit-code of the process
     *
     * @throws RuntimeException if the process got signaled
     */
    public function stop($timeout = 10, $signal = null)
    {
        $timeoutMicro = microtime(true) + $timeout;
        if ($this->isRunning()) {
            if ('\\' === DIRECTORY_SEPARATOR && !$this->isSigchildEnabled()) {
                exec(sprintf('taskkill /F /T /PID %d 2>&1', $this->getPid()), $output, $exitCode);
                if ($exitCode > 0) {
                    throw new RuntimeException('Unable to kill the process');
                }
            }
            // given `SIGTERM` may not be defined and that `proc_terminate` uses the constant value and not the constant itself, we use the same here
            $this->doSignal(15, false);
            do {
                usleep(1000);
            } while ($this->isRunning() && microtime(true) < $timeoutMicro);

            if ($this->isRunning() && !$this->isSigchildEnabled()) {
                if (null !== $signal || defined('SIGKILL')) {
                    // avoid exception here :
                    // process is supposed to be running, but it might have stop
                    // just after this line.
                    // in any case, let's silently discard the error, we can not do anything
                    $this->doSignal($signal ?: SIGKILL, false);
                }
            }
        }

        $this->updateStatus(false);
        if ($this->processInformation['running']) {
            $this->close();
        }

        return $this->exitcode;
    }

    /**
     * Adds a line to the STDOUT stream.
     *
     * @param string $line The line to append
     */
    public function addOutput($line)
    {
        $this->lastOutputTime = microtime(true);
        $this->stdout .= $line;
    }

    /**
     * Adds a line to the STDERR stream.
     *
     * @param string $line The line to append
     */
    public function addErrorOutput($line)
    {
        $this->lastOutputTime = microtime(true);
        $this->stderr .= $line;
    }

    /**
     * Gets the command line to be executed.
     *
     * @return string The command to execute
     */
    public function getCommandLine()
    {
        return $this->commandline;
    }

    /**
     * Sets the command line to be executed.
     *
     * @param string $commandline The command to execute
     *
     * @return self The current Process instance
     */
    public function setCommandLine($commandline)
    {
        $this->commandline = $commandline;

        return $this;
    }

    /**
     * Gets the process timeout (max. runtime).
     *
     * @return float|null The timeout in seconds or null if it's disabled
     */
    public function getTimeout()
    {
        return $this->timeout;
    }

    /**
     * Gets the process idle timeout (max. time since last output).
     *
     * @return float|null The timeout in seconds or null if it's disabled
     */
    public function getIdleTimeout()
    {
        return $this->idleTimeout;
    }

    /**
     * Sets the process timeout (max. runtime).
     *
     * To disable the timeout, set this value to null.
     *
     * @param int|float|null $timeout The timeout in seconds
     *
     * @return self The current Process instance
     *
     * @throws InvalidArgumentException if the timeout is negative
     */
    public function setTimeout($timeout)
    {
        $this->timeout = $this->validateTimeout($timeout);

        return $this;
    }

    /**
     * Sets the process idle timeout (max. time since last output).
     *
     * To disable the timeout, set this value to null.
     *
     * @param int|float|null $timeout The timeout in seconds
     *
     * @return self The current Process instance.
     *
     * @throws LogicException           if the output is disabled
     * @throws InvalidArgumentException if the timeout is negative
     */
    public function setIdleTimeout($timeout)
    {
        if (null !== $timeout && $this->outputDisabled) {
            throw new LogicException('Idle timeout can not be set while the output is disabled.');
        }

        $this->idleTimeout = $this->validateTimeout($timeout);

        return $this;
    }

    /**
     * Enables or disables the TTY mode.
     *
     * @param bool $tty True to enabled and false to disable
     *
     * @return self The current Process instance
     *
     * @throws RuntimeException In case the TTY mode is not supported
     */
    public function setTty($tty)
    {
        if ('\\' === DIRECTORY_SEPARATOR && $tty) {
            throw new RuntimeException('TTY mode is not supported on Windows platform.');
        }
        if ($tty && (!file_exists('/dev/tty') || !is_readable('/dev/tty'))) {
            throw new RuntimeException('TTY mode requires /dev/tty to be readable.');
        }

        $this->tty = (bool) $tty;

        return $this;
    }

    /**
     * Checks if the TTY mode is enabled.
     *
     * @return bool true if the TTY mode is enabled, false otherwise
     */
    public function isTty()
    {
        return $this->tty;
    }

    /**
     * Sets PTY mode.
     *
     * @param bool $bool
     *
     * @return self
     */
    public function setPty($bool)
    {
        $this->pty = (bool) $bool;

        return $this;
    }

    /**
     * Returns PTY state.
     *
     * @return bool
     */
    public function isPty()
    {
        return $this->pty;
    }

    /**
     * Gets the working directory.
     *
     * @return string|null The current working directory or null on failure
     */
    public function getWorkingDirectory()
    {
        if (null === $this->cwd) {
            // getcwd() will return false if any one of the parent directories does not have
            // the readable or search mode set, even if the current directory does
            return getcwd() ?: null;
        }

        return $this->cwd;
    }

    /**
     * Sets the current working directory.
     *
     * @param string $cwd The new working directory
     *
     * @return self The current Process instance
     */
    public function setWorkingDirectory($cwd)
    {
        $this->cwd = $cwd;

        return $this;
    }

    /**
     * Gets the environment variables.
     *
     * @return array The current environment variables
     */
    public function getEnv()
    {
        return $this->env;
    }

    /**
     * Sets the environment variables.
     *
     * An environment variable value should be a string.
     * If it is an array, the variable is ignored.
     *
     * That happens in PHP when 'argv' is registered into
     * the $_ENV array for instance.
     *
     * @param array $env The new environment variables
     *
     * @return self The current Process instance
     */
    public function setEnv(array $env)
    {
        // Process can not handle env values that are arrays
        $env = array_filter($env, function ($value) {
            return !is_array($value);
        });

        $this->env = array();
        foreach ($env as $key => $value) {
            $this->env[(binary) $key] = (binary) $value;
        }

        return $this;
    }

    /**
     * Gets the contents of STDIN.
     *
     * @return string|null The current contents
     *
     * @deprecated Deprecated since version 2.5, to be removed in 3.0.
     *             This method is deprecated in favor of getInput.
     */
    public function getStdin()
    {
        return $this->getInput();
    }

    /**
     * Gets the Process input.
     *
     * @return null|string The Process input
     */
    public function getInput()
    {
        return $this->input;
    }

    /**
     * Sets the contents of STDIN.
     *
     * @param string|null $stdin The new contents
     *
     * @return self The current Process instance
     *
     * @deprecated Deprecated since version 2.5, to be removed in 3.0.
     *             This method is deprecated in favor of setInput.
     *
     * @throws LogicException           In case the process is running
     * @throws InvalidArgumentException In case the argument is invalid
     */
    public function setStdin($stdin)
    {
        return $this->setInput($stdin);
    }

    /**
     * Sets the input.
     *
     * This content will be passed to the underlying process standard input.
     *
     * @param string|null $input The content
     *
     * @return self The current Process instance
     *
     * @throws LogicException In case the process is running
     */
    public function setInput($input)
    {
        if ($this->isRunning()) {
            throw new LogicException('Input can not be set while the process is running.');
        }

        $this->input = ProcessUtils::validateInput(sprintf('%s::%s', __CLASS__, __FUNCTION__), $input);

        return $this;
    }

    /**
     * Gets the options for proc_open.
     *
     * @return array The current options
     */
    public function getOptions()
    {
        return $this->options;
    }

    /**
     * Sets the options for proc_open.
     *
     * @param array $options The new options
     *
     * @return self The current Process instance
     */
    public function setOptions(array $options)
    {
        $this->options = $options;

        return $this;
    }

    /**
     * Gets whether or not Windows compatibility is enabled.
     *
     * This is true by default.
     *
     * @return bool
     */
    public function getEnhanceWindowsCompatibility()
    {
        return $this->enhanceWindowsCompatibility;
    }

    /**
     * Sets whether or not Windows compatibility is enabled.
     *
     * @param bool $enhance
     *
     * @return self The current Process instance
     */
    public function setEnhanceWindowsCompatibility($enhance)
    {
        $this->enhanceWindowsCompatibility = (bool) $enhance;

        return $this;
    }

    /**
     * Returns whether sigchild compatibility mode is activated or not.
     *
     * @return bool
     */
    public function getEnhanceSigchildCompatibility()
    {
        return $this->enhanceSigchildCompatibility;
    }

    /**
     * Activates sigchild compatibility mode.
     *
     * Sigchild compatibility mode is required to get the exit code and
     * determine the success of a process when PHP has been compiled with
     * the --enable-sigchild option
     *
     * @param bool $enhance
     *
     * @return self The current Process instance
     */
    public function setEnhanceSigchildCompatibility($enhance)
    {
        $this->enhanceSigchildCompatibility = (bool) $enhance;

        return $this;
    }

    /**
     * Performs a check between the timeout definition and the time the process started.
     *
     * In case you run a background process (with the start method), you should
     * trigger this method regularly to ensure the process timeout
     *
     * @throws ProcessTimedOutException In case the timeout was reached
     */
    public function checkTimeout()
    {
        if ($this->status !== self::STATUS_STARTED) {
            return;
        }

        if (null !== $this->timeout && $this->timeout < microtime(true) - $this->starttime) {
            $this->stop(0);

            throw new ProcessTimedOutException($this, ProcessTimedOutException::TYPE_GENERAL);
        }

        if (null !== $this->idleTimeout && $this->idleTimeout < microtime(true) - $this->lastOutputTime) {
            $this->stop(0);

            throw new ProcessTimedOutException($this, ProcessTimedOutException::TYPE_IDLE);
        }
    }

    /**
     * Returns whether PTY is supported on the current operating system.
     *
     * @return bool
     */
    public static function isPtySupported()
    {
        static $result;

        if (null !== $result) {
            return $result;
        }

        if ('\\' === DIRECTORY_SEPARATOR) {
            return $result = false;
        }

        $proc = @proc_open('echo 1', array(array('pty'), array('pty'), array('pty')), $pipes);
        if (is_resource($proc)) {
            proc_close($proc);

            return $result = true;
        }

        return $result = false;
    }

    /**
     * Creates the descriptors needed by the proc_open.
     *
     * @return array
     */
    private function getDescriptors()
    {
        if ('\\' === DIRECTORY_SEPARATOR) {
            $this->processPipes = WindowsPipes::create($this, $this->input);
        } else {
            $this->processPipes = UnixPipes::create($this, $this->input);
        }
        $descriptors = $this->processPipes->getDescriptors($this->outputDisabled);

        if (!$this->useFileHandles && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
            // last exit code is output on the fourth pipe and caught to work around --enable-sigchild
            $descriptors = array_merge($descriptors, array(array('pipe', 'w')));

            $this->commandline = '('.$this->commandline.') 3>/dev/null; code=$?; echo $code >&3; exit $code';
        }

        return $descriptors;
    }

    /**
     * Builds up the callback used by wait().
     *
     * The callbacks adds all occurred output to the specific buffer and calls
     * the user callback (if present) with the received output.
     *
     * @param callable|null $callback The user defined PHP callback
     *
     * @return callable A PHP callable
     */
    protected function buildCallback($callback)
    {
        $that = $this;
        $out = self::OUT;
        $callback = function ($type, $data) use ($that, $callback, $out) {
            if ($out == $type) {
                $that->addOutput($data);
            } else {
                $that->addErrorOutput($data);
            }

            if (null !== $callback) {
                call_user_func($callback, $type, $data);
            }
        };

        return $callback;
    }

    /**
     * Updates the status of the process, reads pipes.
     *
     * @param bool $blocking Whether to use a blocking read call.
     */
    protected function updateStatus($blocking)
    {
        if (self::STATUS_STARTED !== $this->status) {
            return;
        }

        $this->processInformation = proc_get_status($this->process);
        $this->captureExitCode();

        $this->readPipes($blocking, '\\' === DIRECTORY_SEPARATOR ? !$this->processInformation['running'] : true);

        if (!$this->processInformation['running']) {
            $this->close();
        }
    }

    /**
     * Returns whether PHP has been compiled with the '--enable-sigchild' option or not.
     *
     * @return bool
     */
    protected function isSigchildEnabled()
    {
        if (null !== self::$sigchild) {
            return self::$sigchild;
        }

        if (!function_exists('phpinfo')) {
            return self::$sigchild = false;
        }

        ob_start();
        phpinfo(INFO_GENERAL);

        return self::$sigchild = false !== strpos(ob_get_clean(), '--enable-sigchild');
    }

    /**
     * Validates and returns the filtered timeout.
     *
     * @param int|float|null $timeout
     *
     * @return float|null
     *
     * @throws InvalidArgumentException if the given timeout is a negative number
     */
    private function validateTimeout($timeout)
    {
        $timeout = (float) $timeout;

        if (0.0 === $timeout) {
            $timeout = null;
        } elseif ($timeout < 0) {
            throw new InvalidArgumentException('The timeout value must be a valid positive integer or float number.');
        }

        return $timeout;
    }

    /**
     * Reads pipes, executes callback.
     *
     * @param bool $blocking Whether to use blocking calls or not.
     * @param bool $close    Whether to close file handles or not.
     */
    private function readPipes($blocking, $close)
    {
        $result = $this->processPipes->readAndWrite($blocking, $close);

        $callback = $this->callback;
        foreach ($result as $type => $data) {
            if (3 == $type) {
                $this->fallbackExitcode = (int) $data;
            } else {
                $callback($type === self::STDOUT ? self::OUT : self::ERR, $data);
            }
        }
    }

    /**
     * Captures the exitcode if mentioned in the process information.
     */
    private function captureExitCode()
    {
        if (isset($this->processInformation['exitcode']) && -1 != $this->processInformation['exitcode']) {
            $this->exitcode = $this->processInformation['exitcode'];
        }
    }

    /**
     * Closes process resource, closes file handles, sets the exitcode.
     *
     * @return int The exitcode
     */
    private function close()
    {
        $this->processPipes->close();
        if (is_resource($this->process)) {
            $exitcode = proc_close($this->process);
        } else {
            $exitcode = -1;
        }

        $this->exitcode = -1 !== $exitcode ? $exitcode : (null !== $this->exitcode ? $this->exitcode : -1);
        $this->status = self::STATUS_TERMINATED;

        if (-1 === $this->exitcode && null !== $this->fallbackExitcode) {
            $this->exitcode = $this->fallbackExitcode;
        } elseif (-1 === $this->exitcode && $this->processInformation['signaled'] && 0 < $this->processInformation['termsig']) {
            // if process has been signaled, no exitcode but a valid termsig, apply Unix convention
            $this->exitcode = 128 + $this->processInformation['termsig'];
        }

        return $this->exitcode;
    }

    /**
     * Resets data related to the latest run of the process.
     */
    private function resetProcessData()
    {
        $this->starttime = null;
        $this->callback = null;
        $this->exitcode = null;
        $this->fallbackExitcode = null;
        $this->processInformation = null;
        $this->stdout = null;
        $this->stderr = null;
        $this->process = null;
        $this->latestSignal = null;
        $this->status = self::STATUS_READY;
        $this->incrementalOutputOffset = 0;
        $this->incrementalErrorOutputOffset = 0;
    }

    /**
     * Sends a POSIX signal to the process.
     *
     * @param int  $signal         A valid POSIX signal (see http://www.php.net/manual/en/pcntl.constants.php)
     * @param bool $throwException Whether to throw exception in case signal failed
     *
     * @return bool True if the signal was sent successfully, false otherwise
     *
     * @throws LogicException   In case the process is not running
     * @throws RuntimeException In case --enable-sigchild is activated
     * @throws RuntimeException In case of failure
     */
    private function doSignal($signal, $throwException)
    {
        if (!$this->isRunning()) {
            if ($throwException) {
                throw new LogicException('Can not send signal on a non running process.');
            }

            return false;
        }

        if ($this->isSigchildEnabled()) {
            if ($throwException) {
                throw new RuntimeException('This PHP has been compiled with --enable-sigchild. The process can not be signaled.');
            }

            return false;
        }

        if (true !== @proc_terminate($this->process, $signal)) {
            if ($throwException) {
                throw new RuntimeException(sprintf('Error while sending signal `%s`.', $signal));
            }

            return false;
        }

        $this->latestSignal = $signal;

        return true;
    }

    /**
     * Ensures the process is running or terminated, throws a LogicException if the process has a not started.
     *
     * @param string $functionName The function name that was called.
     *
     * @throws LogicException If the process has not run.
     */
    private function requireProcessIsStarted($functionName)
    {
        if (!$this->isStarted()) {
            throw new LogicException(sprintf('Process must be started before calling %s.', $functionName));
        }
    }

    /**
     * Ensures the process is terminated, throws a LogicException if the process has a status different than `terminated`.
     *
     * @param string $functionName The function name that was called.
     *
     * @throws LogicException If the process is not yet terminated.
     */
    private function requireProcessIsTerminated($functionName)
    {
        if (!$this->isTerminated()) {
            throw new LogicException(sprintf('Process must be terminated before calling %s.', $functionName));
        }
    }
}
Copyright (c) 2004-2015 Fabien Potencier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Process;

use Symfony\Component\Process\Exception\InvalidArgumentException;
use Symfony\Component\Process\Exception\LogicException;

/**
 * Process builder.
 *
 * @author Kris Wallsmith <kris@symfony.com>
 */
class ProcessBuilder
{
    private $arguments;
    private $cwd;
    private $env = array();
    private $input;
    private $timeout = 60;
    private $options = array();
    private $inheritEnv = true;
    private $prefix = array();
    private $outputDisabled = false;

    /**
     * Constructor.
     *
     * @param string[] $arguments An array of arguments
     */
    public function __construct(array $arguments = array())
    {
        $this->arguments = $arguments;
    }

    /**
     * Creates a process builder instance.
     *
     * @param string[] $arguments An array of arguments
     *
     * @return ProcessBuilder
     */
    public static function create(array $arguments = array())
    {
        return new static($arguments);
    }

    /**
     * Adds an unescaped argument to the command string.
     *
     * @param string $argument A command argument
     *
     * @return ProcessBuilder
     */
    public function add($argument)
    {
        $this->arguments[] = $argument;

        return $this;
    }

    /**
     * Adds a prefix to the command string.
     *
     * The prefix is preserved when resetting arguments.
     *
     * @param string|array $prefix A command prefix or an array of command prefixes
     *
     * @return ProcessBuilder
     */
    public function setPrefix($prefix)
    {
        $this->prefix = is_array($prefix) ? $prefix : array($prefix);

        return $this;
    }

    /**
     * Sets the arguments of the process.
     *
     * Arguments must not be escaped.
     * Previous arguments are removed.
     *
     * @param string[] $arguments
     *
     * @return ProcessBuilder
     */
    public function setArguments(array $arguments)
    {
        $this->arguments = $arguments;

        return $this;
    }

    /**
     * Sets the working directory.
     *
     * @param null|string $cwd The working directory
     *
     * @return ProcessBuilder
     */
    public function setWorkingDirectory($cwd)
    {
        $this->cwd = $cwd;

        return $this;
    }

    /**
     * Sets whether environment variables will be inherited or not.
     *
     * @param bool $inheritEnv
     *
     * @return ProcessBuilder
     */
    public function inheritEnvironmentVariables($inheritEnv = true)
    {
        $this->inheritEnv = $inheritEnv;

        return $this;
    }

    /**
     * Sets an environment variable.
     *
     * Setting a variable overrides its previous value. Use `null` to unset a
     * defined environment variable.
     *
     * @param string      $name  The variable name
     * @param null|string $value The variable value
     *
     * @return ProcessBuilder
     */
    public function setEnv($name, $value)
    {
        $this->env[$name] = $value;

        return $this;
    }

    /**
     * Adds a set of environment variables.
     *
     * Already existing environment variables with the same name will be
     * overridden by the new values passed to this method. Pass `null` to unset
     * a variable.
     *
     * @param array $variables The variables
     *
     * @return ProcessBuilder
     */
    public function addEnvironmentVariables(array $variables)
    {
        $this->env = array_replace($this->env, $variables);

        return $this;
    }

    /**
     * Sets the input of the process.
     *
     * @param string|null $input The input as a string
     *
     * @return ProcessBuilder
     *
     * @throws InvalidArgumentException In case the argument is invalid
     */
    public function setInput($input)
    {
        $this->input = ProcessUtils::validateInput(sprintf('%s::%s', __CLASS__, __FUNCTION__), $input);

        return $this;
    }

    /**
     * Sets the process timeout.
     *
     * To disable the timeout, set this value to null.
     *
     * @param float|null $timeout
     *
     * @return ProcessBuilder
     *
     * @throws InvalidArgumentException
     */
    public function setTimeout($timeout)
    {
        if (null === $timeout) {
            $this->timeout = null;

            return $this;
        }

        $timeout = (float) $timeout;

        if ($timeout < 0) {
            throw new InvalidArgumentException('The timeout value must be a valid positive integer or float number.');
        }

        $this->timeout = $timeout;

        return $this;
    }

    /**
     * Adds a proc_open option.
     *
     * @param string $name  The option name
     * @param string $value The option value
     *
     * @return ProcessBuilder
     */
    public function setOption($name, $value)
    {
        $this->options[$name] = $value;

        return $this;
    }

    /**
     * Disables fetching output and error output from the underlying process.
     *
     * @return ProcessBuilder
     */
    public function disableOutput()
    {
        $this->outputDisabled = true;

        return $this;
    }

    /**
     * Enables fetching output and error output from the underlying process.
     *
     * @return ProcessBuilder
     */
    public function enableOutput()
    {
        $this->outputDisabled = false;

        return $this;
    }

    /**
     * Creates a Process instance and returns it.
     *
     * @return Process
     *
     * @throws LogicException In case no arguments have been provided
     */
    public function getProcess()
    {
        if (0 === count($this->prefix) && 0 === count($this->arguments)) {
            throw new LogicException('You must add() command arguments before calling getProcess().');
        }

        $options = $this->options;

        $arguments = array_merge($this->prefix, $this->arguments);
        $script = implode(' ', array_map(array(__NAMESPACE__.'\\ProcessUtils', 'escapeArgument'), $arguments));

        if ($this->inheritEnv) {
            // include $_ENV for BC purposes
            $env = array_replace($_ENV, $_SERVER, $this->env);
        } else {
            $env = $this->env;
        }

        $process = new Process($script, $this->cwd, $env, $this->input, $this->timeout, $options);

        if ($this->outputDisabled) {
            $process->disableOutput();
        }

        return $process;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Process\Exception;

/**
 * RuntimeException for the Process Component.
 *
 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
 */
class RuntimeException extends \RuntimeException implements ExceptionInterface
{
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Process\Exception;

use Symfony\Component\Process\Process;

/**
 * Exception for failed processes.
 *
 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
 */
class ProcessFailedException extends RuntimeException
{
    private $process;

    public function __construct(Process $process)
    {
        if ($process->isSuccessful()) {
            throw new InvalidArgumentException('Expected a failed process, but the given process was successful.');
        }

        $error = sprintf('The command "%s" failed.'."\nExit Code: %s(%s)",
            $process->getCommandLine(),
            $process->getExitCode(),
            $process->getExitCodeText()
        );

        if (!$process->isOutputDisabled()) {
            $error .= sprintf("\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s",
                $process->getOutput(),
                $process->getErrorOutput()
            );
        }

        parent::__construct($error);

        $this->process = $process;
    }

    public function getProcess()
    {
        return $this->process;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Process\Exception;

/**
 * Marker Interface for the Process Component.
 *
 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
 */
interface ExceptionInterface
{
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Process\Exception;

use Symfony\Component\Process\Process;

/**
 * Exception that is thrown when a process times out.
 *
 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
 */
class ProcessTimedOutException extends RuntimeException
{
    const TYPE_GENERAL = 1;
    const TYPE_IDLE = 2;

    private $process;
    private $timeoutType;

    public function __construct(Process $process, $timeoutType)
    {
        $this->process = $process;
        $this->timeoutType = $timeoutType;

        parent::__construct(sprintf(
            'The process "%s" exceeded the timeout of %s seconds.',
            $process->getCommandLine(),
            $this->getExceededTimeout()
        ));
    }

    public function getProcess()
    {
        return $this->process;
    }

    public function isGeneralTimeout()
    {
        return $this->timeoutType === self::TYPE_GENERAL;
    }

    public function isIdleTimeout()
    {
        return $this->timeoutType === self::TYPE_IDLE;
    }

    public function getExceededTimeout()
    {
        switch ($this->timeoutType) {
            case self::TYPE_GENERAL:
                return $this->process->getTimeout();

            case self::TYPE_IDLE:
                return $this->process->getIdleTimeout();

            default:
                throw new \LogicException(sprintf('Unknown timeout type "%d".', $this->timeoutType));
        }
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Process\Exception;

/**
 * InvalidArgumentException for the Process Component.
 *
 * @author Romain Neutron <imprec@gmail.com>
 */
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
{
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Process\Exception;

/**
 * LogicException for the Process Component.
 *
 * @author Romain Neutron <imprec@gmail.com>
 */
class LogicException extends \LogicException implements ExceptionInterface
{
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Process;

/**
 * Generic executable finder.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
 */
class ExecutableFinder
{
    private $suffixes = array('.exe', '.bat', '.cmd', '.com');

    /**
     * Replaces default suffixes of executable.
     *
     * @param array $suffixes
     */
    public function setSuffixes(array $suffixes)
    {
        $this->suffixes = $suffixes;
    }

    /**
     * Adds new possible suffix to check for executable.
     *
     * @param string $suffix
     */
    public function addSuffix($suffix)
    {
        $this->suffixes[] = $suffix;
    }

    /**
     * Finds an executable by name.
     *
     * @param string $name      The executable name (without the extension)
     * @param string $default   The default to return if no executable is found
     * @param array  $extraDirs Additional dirs to check into
     *
     * @return string The executable path or default value
     */
    public function find($name, $default = null, array $extraDirs = array())
    {
        if (ini_get('open_basedir')) {
            $searchPath = explode(PATH_SEPARATOR, ini_get('open_basedir'));
            $dirs = array();
            foreach ($searchPath as $path) {
                if (is_dir($path)) {
                    $dirs[] = $path;
                } else {
                    if (basename($path) == $name && is_executable($path)) {
                        return $path;
                    }
                }
            }
        } else {
            $dirs = array_merge(
                explode(PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')),
                $extraDirs
            );
        }

        $suffixes = array('');
        if ('\\' === DIRECTORY_SEPARATOR) {
            $pathExt = getenv('PATHEXT');
            $suffixes = $pathExt ? explode(PATH_SEPARATOR, $pathExt) : $this->suffixes;
        }
        foreach ($suffixes as $suffix) {
            foreach ($dirs as $dir) {
                if (is_file($file = $dir.DIRECTORY_SEPARATOR.$name.$suffix) && ('\\' === DIRECTORY_SEPARATOR || is_executable($file))) {
                    return $file;
                }
            }
        }

        return $default;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Process;

use Symfony\Component\Process\Exception\RuntimeException;

/**
 * PhpProcess runs a PHP script in an independent process.
 *
 * $p = new PhpProcess('<?php echo "foo"; ?>');
 * $p->run();
 * print $p->getOutput()."\n";
 *
 * @author Fabien Potencier <fabien@symfony.com>
 *
 * @api
 */
class PhpProcess extends Process
{
    /**
     * Constructor.
     *
     * @param string $script  The PHP script to run (as a string)
     * @param string $cwd     The working directory
     * @param array  $env     The environment variables
     * @param int    $timeout The timeout in seconds
     * @param array  $options An array of options for proc_open
     *
     * @api
     */
    public function __construct($script, $cwd = null, array $env = array(), $timeout = 60, array $options = array())
    {
        $executableFinder = new PhpExecutableFinder();
        if (false === $php = $executableFinder->find()) {
            $php = null;
        }

        parent::__construct($php, $cwd, $env, $script, $timeout, $options);
    }

    /**
     * Sets the path to the PHP binary to use.
     *
     * @api
     */
    public function setPhpBinary($php)
    {
        $this->setCommandLine($php);
    }

    /**
     * {@inheritdoc}
     */
    public function start($callback = null)
    {
        if (null === $this->getCommandLine()) {
            throw new RuntimeException('Unable to find the PHP executable.');
        }

        parent::start($callback);
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Process\Pipes;

use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\RuntimeException;

/**
 * WindowsPipes implementation uses temporary files as handles.
 *
 * @see https://bugs.php.net/bug.php?id=51800
 * @see https://bugs.php.net/bug.php?id=65650
 *
 * @author Romain Neutron <imprec@gmail.com>
 *
 * @internal
 */
class WindowsPipes extends AbstractPipes
{
    /** @var array */
    private $files = array();
    /** @var array */
    private $fileHandles = array();
    /** @var array */
    private $readBytes = array(
        Process::STDOUT => 0,
        Process::STDERR => 0,
    );
    /** @var bool */
    private $disableOutput;

    public function __construct($disableOutput, $input)
    {
        $this->disableOutput = (bool) $disableOutput;

        if (!$this->disableOutput) {
            // Fix for PHP bug #51800: reading from STDOUT pipe hangs forever on Windows if the output is too big.
            // Workaround for this problem is to use temporary files instead of pipes on Windows platform.
            //
            // @see https://bugs.php.net/bug.php?id=51800
            $this->files = array(
                Process::STDOUT => tempnam(sys_get_temp_dir(), 'sf_proc_stdout'),
                Process::STDERR => tempnam(sys_get_temp_dir(), 'sf_proc_stderr'),
            );
            foreach ($this->files as $offset => $file) {
                $this->fileHandles[$offset] = fopen($this->files[$offset], 'rb');
                if (false === $this->fileHandles[$offset]) {
                    throw new RuntimeException('A temporary file could not be opened to write the process output to, verify that your TEMP environment variable is writable');
                }
            }
        }

        if (is_resource($input)) {
            $this->input = $input;
        } else {
            $this->inputBuffer = $input;
        }
    }

    public function __destruct()
    {
        $this->close();
        $this->removeFiles();
    }

    /**
     * {@inheritdoc}
     */
    public function getDescriptors()
    {
        if ($this->disableOutput) {
            $nullstream = fopen('NUL', 'c');

            return array(
                array('pipe', 'r'),
                $nullstream,
                $nullstream,
            );
        }

        // We're not using pipe on Windows platform as it hangs (https://bugs.php.net/bug.php?id=51800)
        // We're not using file handles as it can produce corrupted output https://bugs.php.net/bug.php?id=65650
        // So we redirect output within the commandline and pass the nul device to the process
        return array(
            array('pipe', 'r'),
            array('file', 'NUL', 'w'),
            array('file', 'NUL', 'w'),
        );
    }

    /**
     * {@inheritdoc}
     */
    public function getFiles()
    {
        return $this->files;
    }

    /**
     * {@inheritdoc}
     */
    public function readAndWrite($blocking, $close = false)
    {
        $this->write($blocking, $close);

        $read = array();
        $fh = $this->fileHandles;
        foreach ($fh as $type => $fileHandle) {
            if (0 !== fseek($fileHandle, $this->readBytes[$type])) {
                continue;
            }
            $data = '';
            $dataread = null;
            while (!feof($fileHandle)) {
                if (false !== $dataread = fread($fileHandle, self::CHUNK_SIZE)) {
                    $data .= $dataread;
                }
            }
            if (0 < $length = strlen($data)) {
                $this->readBytes[$type] += $length;
                $read[$type] = $data;
            }

            if (false === $dataread || (true === $close && feof($fileHandle) && '' === $data)) {
                fclose($this->fileHandles[$type]);
                unset($this->fileHandles[$type]);
            }
        }

        return $read;
    }

    /**
     * {@inheritdoc}
     */
    public function areOpen()
    {
        return (bool) $this->pipes && (bool) $this->fileHandles;
    }

    /**
     * {@inheritdoc}
     */
    public function close()
    {
        parent::close();
        foreach ($this->fileHandles as $handle) {
            fclose($handle);
        }
        $this->fileHandles = array();
    }

    /**
     * Creates a new WindowsPipes instance.
     *
     * @param Process $process The process
     * @param $input
     *
     * @return WindowsPipes
     */
    public static function create(Process $process, $input)
    {
        return new static($process->isOutputDisabled(), $input);
    }

    /**
     * Removes temporary files
     */
    private function removeFiles()
    {
        foreach ($this->files as $filename) {
            if (file_exists($filename)) {
                @unlink($filename);
            }
        }
        $this->files = array();
    }

    /**
     * Writes input to stdin
     *
     * @param bool $blocking
     * @param bool $close
     */
    private function write($blocking, $close)
    {
        if (empty($this->pipes)) {
            return;
        }

        $this->unblock();

        $r = null !== $this->input ? array('input' => $this->input) : null;
        $w = isset($this->pipes[0]) ? array($this->pipes[0]) : null;
        $e = null;

        // let's have a look if something changed in streams
        if (false === $n = @stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1E6 : 0)) {
            // if a system call has been interrupted, forget about it, let's try again
            // otherwise, an error occurred, let's reset pipes
            if (!$this->hasSystemCallBeenInterrupted()) {
                $this->pipes = array();
            }

            return;
        }

        // nothing has changed
        if (0 === $n) {
            return;
        }

        if (null !== $w && 0 < count($r)) {
            $data = '';
            while ($dataread = fread($r['input'], self::CHUNK_SIZE)) {
                $data .= $dataread;
            }

            $this->inputBuffer .= $data;

            if (false === $data || (true === $close && feof($r['input']) && '' === $data)) {
                // no more data to read on input resource
                // use an empty buffer in the next reads
                $this->input = null;
            }
        }

        if (null !== $w && 0 < count($w)) {
            while (strlen($this->inputBuffer)) {
                $written = fwrite($w[0], $this->inputBuffer, 2 << 18);
                if ($written > 0) {
                    $this->inputBuffer = (string) substr($this->inputBuffer, $written);
                } else {
                    break;
                }
            }
        }

        // no input to read on resource, buffer is empty and stdin still open
        if ('' === $this->inputBuffer && null === $this->input && isset($this->pipes[0])) {
            fclose($this->pipes[0]);
            unset($this->pipes[0]);
        }
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Process\Pipes;

/**
 * @author Romain Neutron <imprec@gmail.com>
 *
 * @internal
 */
abstract class AbstractPipes implements PipesInterface
{
    /** @var array */
    public $pipes = array();

    /** @var string */
    protected $inputBuffer = '';
    /** @var resource|null */
    protected $input;

    /** @var bool */
    private $blocked = true;

    /**
     * {@inheritdoc}
     */
    public function close()
    {
        foreach ($this->pipes as $pipe) {
            fclose($pipe);
        }
        $this->pipes = array();
    }

    /**
     * Returns true if a system call has been interrupted.
     *
     * @return bool
     */
    protected function hasSystemCallBeenInterrupted()
    {
        $lastError = error_get_last();

        // stream_select returns false when the `select` system call is interrupted by an incoming signal
        return isset($lastError['message']) && false !== stripos($lastError['message'], 'interrupted system call');
    }

    /**
     * Unblocks streams
     */
    protected function unblock()
    {
        if (!$this->blocked) {
            return;
        }

        foreach ($this->pipes as $pipe) {
            stream_set_blocking($pipe, 0);
        }
        if (null !== $this->input) {
            stream_set_blocking($this->input, 0);
        }

        $this->blocked = false;
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Process\Pipes;

use Symfony\Component\Process\Process;

/**
 * UnixPipes implementation uses unix pipes as handles.
 *
 * @author Romain Neutron <imprec@gmail.com>
 *
 * @internal
 */
class UnixPipes extends AbstractPipes
{
    /** @var bool */
    private $ttyMode;
    /** @var bool */
    private $ptyMode;
    /** @var bool */
    private $disableOutput;

    public function __construct($ttyMode, $ptyMode, $input, $disableOutput)
    {
        $this->ttyMode = (bool) $ttyMode;
        $this->ptyMode = (bool) $ptyMode;
        $this->disableOutput = (bool) $disableOutput;

        if (is_resource($input)) {
            $this->input = $input;
        } else {
            $this->inputBuffer = (string) $input;
        }
    }

    public function __destruct()
    {
        $this->close();
    }

    /**
     * {@inheritdoc}
     */
    public function getDescriptors()
    {
        if ($this->disableOutput) {
            $nullstream = fopen('/dev/null', 'c');

            return array(
                array('pipe', 'r'),
                $nullstream,
                $nullstream,
            );
        }

        if ($this->ttyMode) {
            return array(
                array('file', '/dev/tty', 'r'),
                array('file', '/dev/tty', 'w'),
                array('file', '/dev/tty', 'w'),
            );
        }

        if ($this->ptyMode && Process::isPtySupported()) {
            return array(
                array('pty'),
                array('pty'),
                array('pty'),
            );
        }

        return array(
            array('pipe', 'r'),
            array('pipe', 'w'), // stdout
            array('pipe', 'w'), // stderr
        );
    }

    /**
     * {@inheritdoc}
     */
    public function getFiles()
    {
        return array();
    }

    /**
     * {@inheritdoc}
     */
    public function readAndWrite($blocking, $close = false)
    {
        // only stdin is left open, job has been done !
        // we can now close it
        if (1 === count($this->pipes) && array(0) === array_keys($this->pipes)) {
            fclose($this->pipes[0]);
            unset($this->pipes[0]);
        }

        if (empty($this->pipes)) {
            return array();
        }

        $this->unblock();

        $read = array();

        if (null !== $this->input) {
            // if input is a resource, let's add it to stream_select argument to
            // fill a buffer
            $r = array_merge($this->pipes, array('input' => $this->input));
        } else {
            $r = $this->pipes;
        }
        // discard read on stdin
        unset($r[0]);

        $w = isset($this->pipes[0]) ? array($this->pipes[0]) : null;
        $e = null;

        // let's have a look if something changed in streams
        if (false === $n = @stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1E6 : 0)) {
            // if a system call has been interrupted, forget about it, let's try again
            // otherwise, an error occurred, let's reset pipes
            if (!$this->hasSystemCallBeenInterrupted()) {
                $this->pipes = array();
            }

            return $read;
        }

        // nothing has changed
        if (0 === $n) {
            return $read;
        }

        foreach ($r as $pipe) {
            // prior PHP 5.4 the array passed to stream_select is modified and
            // lose key association, we have to find back the key
            $type = (false !== $found = array_search($pipe, $this->pipes)) ? $found : 'input';
            $data = '';
            while ('' !== $dataread = (string) fread($pipe, self::CHUNK_SIZE)) {
                $data .= $dataread;
            }

            if ('' !== $data) {
                if ($type === 'input') {
                    $this->inputBuffer .= $data;
                } else {
                    $read[$type] = $data;
                }
            }

            if (false === $data || (true === $close && feof($pipe) && '' === $data)) {
                if ($type === 'input') {
                    // no more data to read on input resource
                    // use an empty buffer in the next reads
                    $this->input = null;
                } else {
                    fclose($this->pipes[$type]);
                    unset($this->pipes[$type]);
                }
            }
        }

        if (null !== $w && 0 < count($w)) {
            while (strlen($this->inputBuffer)) {
                $written = fwrite($w[0], $this->inputBuffer, 2 << 18); // write 512k
                if ($written > 0) {
                    $this->inputBuffer = (string) substr($this->inputBuffer, $written);
                } else {
                    break;
                }
            }
        }

        // no input to read on resource, buffer is empty and stdin still open
        if ('' === $this->inputBuffer && null === $this->input && isset($this->pipes[0])) {
            fclose($this->pipes[0]);
            unset($this->pipes[0]);
        }

        return $read;
    }

    /**
     * {@inheritdoc}
     */
    public function areOpen()
    {
        return (bool) $this->pipes;
    }

    /**
     * Creates a new UnixPipes instance
     *
     * @param Process         $process
     * @param string|resource $input
     *
     * @return UnixPipes
     */
    public static function create(Process $process, $input)
    {
        return new static($process->isTty(), $process->isPty(), $input, $process->isOutputDisabled());
    }
}
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\Process\Pipes;

/**
 * PipesInterface manages descriptors and pipes for the use of proc_open.
 *
 * @author Romain Neutron <imprec@gmail.com>
 *
 * @internal
 */
interface PipesInterface
{
    const CHUNK_SIZE = 16384;

    /**
     * Returns an array of descriptors for the use of proc_open.
     *
     * @return array
     */
    public function getDescriptors();

    /**
     * Returns an array of filenames indexed by their related stream in case these pipes use temporary files.
     *
     * @return string[]
     */
    public function getFiles();

    /**
     * Reads data in file handles and pipes.
     *
     * @param bool $blocking Whether to use blocking calls or not.
     * @param bool $close    Whether to close pipes if they've reached EOF.
     *
     * @return string[] An array of read data indexed by their fd.
     */
    public function readAndWrite($blocking, $close = false);

    /**
     * Returns if the current state has open file handles or pipes.
     *
     * @return bool
     */
    public function areOpen();

    /**
     * Closes file handles and pipes.
     */
    public function close();
}
Q�!�����@)�=�6�GBMBstages:
    - build
    - upload
    - release

variables:
  # Package version can only contain numbers (0-9), and dots (.).
  # Must be in the format of X.Y.Z, i.e. should match /\A\d+\.\d+\.\d+\z/ regular expresion.
  # See https://docs.gitlab.com/ee/user/packages/generic_packages/#publish-a-package-file
  PACKAGE_VERSION: "0.8.${CI_PIPELINE_IID}"
  PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/code-scrawl/${PACKAGE_VERSION}/scrawl.phar"

build:
    stage: build
    image: registry.gitlab.com/gitlab-org/release-cli:latest
    script:
      - echo "Creating scrawl.phar"
      - composer install
      - bin/build-phar --build-phar
    artifacts:
        paths:
            - build/

upload:
    stage: upload
    image: curlimages/curl:latest
    script:
        - curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file build/scrawl.phar "${PACKAGE_REGISTRY_URL}"

release:
  stage: release
  image: registry.gitlab.com/gitlab-org/release-cli:latest
  - script:
      - echo "Creating release"
  release:                                         # See https://docs.gitlab.com/ee/ci/yaml/#release for available properties
    tag_name: '$PACKAGE_VERSION'                # The version is incremented per pipeline.
    description: '$PACKAGE_VERSION'
    ref: '$CI_COMMIT_SHA'                          # The tag is created from the pipeline SHA.
    assets:
        links:
            - name: 'scrawl.phar'
              url: "${PACKAGE_REGISTRY_URL}"
              filepath: 'scrawl.phar'
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Ext/ExportDocBlock.php  
  
# class Tlf\Scrawl\FileExt\ExportDocBlock  
Export docblock content above `@export(key)`  
@featured  
See source code at [/src/Ext/ExportDocBlock.php](/src/Ext/ExportDocBlock.php)  
  
## Constants  
  
## Properties  
- `protected $regs = [  
        'export.key' => '/\@export\(([^\)]*)\)/',  
        'Exports' => '/((?:.|\n)*) *(\@export.*)/',  
    ];`   
  
## Methods   
- `public function get_docblocks(string $str): array` get an array of docblocks  
- `public function get_exports(array $docblocks)` get an array of exported text  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Ext/ExportStartEnd.php  
  
# class Tlf\Scrawl\FileExt\ExportStartEnd  
Export code between `// @export_start(key)` and `// @export_end(key)`  
@featured  
See source code at [/src/Ext/ExportStartEnd.php](/src/Ext/ExportStartEnd.php)  
  
## Constants  
  
## Properties  
- `protected $regs = [  
        'exports'=>   
                        '/\ *(?:\/\/|\#)\ *@export_start\(([^\)]*)\)((?:.|\r|\n)+)\ *(?:\/\/|\#)\ *(@export_end\(\1\))/',  
    ];`   
  
## Methods   
- `public function __construct()`   
- `public function get_exports($str)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Ext/Main.php  
  
# class Tlf\Scrawl\Ext\Main  
  
See source code at [/src/Ext/Main.php](/src/Ext/Main.php)  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function copy_readme($scrawl)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Ext/Php.php  
  
# class Tlf\Scrawl\FileExt\Php  
Integrate the lexer for PHP files  
See source code at [/src/Ext/Php.php](/src/Ext/Php.php)  
  
## Constants  
  
## Properties  
- `public \Tlf\Scrawl $scrawl;`   
  
## Methods   
- `public function __construct(\Tlf\Scrawl $scrawl)`   
- `public function get_all_classes()`   
- `public function set_ast(array $ast)`   
- `public function parse_str(string $str): array` Parsed `$str` into an ast (using the Lexer)  
- `public function parse_file(string $file_path): array` Parsed `$str` into an ast (using the Lexer)  
  
- `public function make_docs(array $ast)` use the ast to create docs using the classList template  
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Ext/TestExtension.php  
  
# class Tlf\Scrawl\TestExtension  
Class purely exists to test that extensions work  
See source code at [/src/Ext/TestExtension.php](/src/Ext/TestExtension.php)  
  
## Constants  
  
## Properties  
- `protected \Tlf\Scrawl $scrawl;` a scrawl instance  
  
## Methods   
- `public function __construct(\Tlf\Scrawl $scrawl)`   
- `public function bootstrap()`   
- `public function ast_generated(string $className, array $ast)`   
- `public function astlist_generated(array $asts)`   
- `public function scan_filelist_loaded(array $code_files)`   
- `public function scan_file_processed(string $path, string $relPath, string $file_content, array $file_exports)`   
- `public function scan_filelist_processed(array $code_files, array $all_exports)`   
- `public function doc_filelist_loaded(array $doc_files, \Tlf\Scrawl\Ext\MdVerbs $mdverb_ext)`   
- `public function doc_file_loaded($path,$relPath,$file_content)`   
- `public function doc_file_processed($path,$relPath,$file_content)`   
- `public function doc_filelist_processed($doc_files)`   
- `public function scrawl_finished()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Ext/DoNothingExtension.php  
  
# class Tlf\Scrawl\DoNothingExtension  
Literally does nothing except the constructor and $scrawl property. Just a base class to save boilerplate on the interface  
See source code at [/src/Ext/DoNothingExtension.php](/src/Ext/DoNothingExtension.php)  
  
## Constants  
  
## Properties  
- `protected \Tlf\Scrawl $scrawl;` a scrawl instance  
  
## Methods   
- `public function __construct(\Tlf\Scrawl $scrawl)`   
- `public function bootstrap()`   
- `public function ast_generated(string $className, array $ast)`   
- `public function astlist_generated(array $asts)`   
- `public function scan_filelist_loaded(array $code_files)`   
- `public function scan_file_processed(string $path, string $relPath, string $file_content, array $file_exports)`   
- `public function scan_filelist_processed(array $code_files, array $all_exports)`   
- `public function doc_filelist_loaded(array $doc_files, \Tlf\Scrawl\Ext\MdVerbs $mdverb_ext)`   
- `public function doc_file_loaded($path,$relPath,$file_content)`   
- `public function doc_file_processed($path,$relPath,$file_content)`   
- `public function doc_filelist_processed($doc_files)`   
- `public function scrawl_finished()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/MdVerb/AstVerb.php  
  
# class Tlf\Scrawl\Ext\MdVerb\Ast  
  
See source code at [/src/MdVerb/AstVerb.php](/src/MdVerb/AstVerb.php)  
  
## Constants  
  
## Properties  
- `public \Tlf\Scrawl $scrawl;`   
  
## Methods   
- `public function __construct($scrawl)`   
- `public function get_markdown($key, $template='ast/default')` Get an ast & optionally load a custom template for it  
  
- `public function get_ast(string $key, int $length=-1)`   
- `public function getVerbs(): array`   
- `public function getAstClassInfo(array $info, string $fqn, string $dotProperty)`   
- `public function verbAst($info, $className, $dotProperty)`   
- `public function getClassMethodsTemplate($verb, $argListStr, $line)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/MdVerb/MainVerbs.php  
  
# class Tlf\Scrawl\Ext\MdVerb\MainVerbs  
  
See source code at [/src/MdVerb/MainVerbs.php](/src/MdVerb/MainVerbs.php)  
  
## Constants  
  
## Properties  
- `public \Tlf\Scrawl $scrawl;` a scrawl instance  
  
## Methods   
- `public function __construct(\Tlf\Scrawl $scrawl)`   
- `public function setup_handlers(\Tlf\Scrawl\Ext\MdVerbs $md_ext)` add callbacks to `$md_ext->handlers`  
- `public function at_system(string $system_command, ...$options)` Run a command on the computer's operating system.  
  
Supported options: `trim`, `trim_empty_lines`, `last_x_lines, int`  
  
- `public function at_template(string $templateName, ...$templateArgs)` Load a template  
- `public function at_import(string $key)` Import something previously exported with `@export` or `@export_start/@export_end`  
  
- `public function at_file(string $relFilePath)` Copy a file's content into your markdown.  
  
- `public function at_see_file(string $relFilePath, string $link_name = null)` Get a link to a file in your repo  
  
- `public function at_hard_link(string $url, string $name=null)` just returns a regular markdown link. In future, may check validity of link or do some kind of logging  
- `public function at_link(string $link_name, string $alternative_text = null)` Output links configured in your config json file.  
Config format is `{..., "links": { "link_name": "https://example.org"} }`  
  
- `public function at_easy_link(string $service, string $target)` Get a link to common services (twitter, gitlab, github, facebook)  
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/MdVerb/MdVerbs.php  
  
# class Tlf\Scrawl\Ext\MdVerbs  
Runs `@mdverb` extensions, enabling special callbacks for `@verb()`s in `.src.md` files  
See source code at [/src/MdVerb/MdVerbs.php](/src/MdVerb/MdVerbs.php)  
  
## Constants  
  
## Properties  
- `protected $regs = [  
          
        'verb' =>'/(?<!\\\\)\@([a-zA-Z_]+)\(([^\)]*)\)/m',  
    ];`   
- `public $handlers = [];` array of verb handlers  
  
- `public \Tlf\Scrawl $scrawl;`   
  
## Methods   
- `public function __construct(\Tlf\Scrawl $scrawl=null)`   
- `public function get_verbs(string $str): array` Get all `@verbs(arg1, arg2)`   
- `public function replace_all_verbs(string $doc): string` Get all verbs, execute them, and replace them within the doc  
- `public function run_verb(string $src, string $verb, array $args): string` Execute a verb handler and get its output   
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Utility/DocBlock.php  
  
# class Tlf\Scrawl\Utility\DocBlock  
@featured  
See source code at [/src/Utility/DocBlock.php](/src/Utility/DocBlock.php)  
  
## Constants  
  
## Properties  
- `public $raw;`   
- `public $clean;`   
- `static protected $regex = [  
                'DocBlock./**' => ['/((\/\*\*.*\n)( *\*.*\n)* *\*\/)/'],  
        'DocBlock./**.removeBlockOpen' => '/(^\/\*\*)/',  
        'DocBlock./**.removeLineOpenAndBlockClose' => '/(\n\s*\* ?\/?)/',  
    ];`   
  
## Methods   
- `public function __construct($rawBlock, $cleanBlock)`   
- `static public function DocBlock($name, $match, $nullFile, $info)`   
- `static public function extractBlocks($fileContent)`   
- `static public function cleanBlock($rawBlock)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Utility/Main.php  
  
# class Tlf\Scrawl\Utility\Main  
  
See source code at [/src/Utility/Main.php](/src/Utility/Main.php)  
  
## Constants  
  
## Properties  
- `static protected $classMap=[];`   
- `static protected $isRegistered=false;`   
  
## Methods   
- `static public function removeLeftHandPad($textBlock)`   
- `static public function allFilesFromDir(string $rootDir, string $relDir, array $forExt=[])`   
- `static public function DANGEROUS_removeNonEmptyDirectory($directory)`   
- `static public function getComposerPackageName()` Check your composer.json in the current working directory for a `"name"`  
- `static public function getCurrentBranchForComposer()`   
- `static public function getGitCloneUrl(): string` Return the git clone url, but always return the https version  
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Utility/Regex.php  
  
# class Tlf\Scrawl\Utility\Regex  
  
See source code at [/src/Utility/Regex.php](/src/Utility/Regex.php)  
  
## Constants  
  
## Properties  
  
## Methods   
- `static public function matchRegexes($targetObject, $regexArray, File $file=null, $textnull)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Old.php  
  
# class Tlf\Scrawl\OldStuffs\ugh_old_things  
just old code that i don't wanna get rid of  
See source code at [/src/Old.php](/src/Old.php)  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function run_init($cli, $args)`   
- `public function prompt($message, $default)`   
- `public function pathToRootFrom($configuredDirectory)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Scrawl.php  
  
# class Tlf\Scrawl  
Central class for running scrawl.  
See source code at [/src/Scrawl.php](/src/Scrawl.php)  
  
## Constants  
  
## Properties  
- `public array $stuff = [];` array for get/set  
- `public array $extensions = [  
        'code'=>[],  
    ];`   
- `public array $ScrawlExtensions = [];` Array of \Tlf\Scrawl\Extension objects  
- `public \Tlf\Scrawl\Ext\MdVerbs $mdverb_ext;` \Tlf\Scrawl\Ext\MdVerbs  
- `public string $file_bootstrap = null;` absolute path to php file to `require()` before scrawl runs  
- `public string $dir_docs = null;` absolute path to your documentation dir  
- `public string $dir_root = null;` absolute path to the root of your project  
- `public string $dir_src = null;` absolute path to the documentation source dir  
- `public array $dir_scan = [];` array of relative path to dirs to scan, within your dir_root  
- `public array $verb_handlers = [];` array of handlers for the mdverb extension  
- `public array $template_dirs = [];` absolute path to directories that contain md templates  
- `public bool $markdown_preserveNewLines = true;` if true, append two spaces to every line so all new lines are parsed as new lines  
- `public bool $markdown_prependGenNotice = true;` if true, add an html comment to md docs saying not to edit directly  
- `public bool $readme_copyFromDocs = true;` if true, copies `docs/README.md` to project root `README.md`  
- `public bool $deleteExistingDocs = false;` If true will delete all files in your docs dir before running  
- `public string $api_output_dir = 'api/';` Which directory to write Class/Method/Property info to  
- `public bool $api_generate_readme = true;` True to generate a README listing all classes, inside the api_output_dir  
- `public array $options = [];` Array of values, typically passed in through cli  
  
## Methods   
- `public function __construct(array $options=[])`   
- `public function parse_rel_path(string $base_path, string $target_path, bool $use_realpath = true): string` Get the relative path within target_path, if it starts with root_path  
  
- `public function get_doc_path(\Tlf\Cli $cli, array $args): string` Cli function to get the absolute path to a code file  
  
- `public function get_doc_source_path(\Tlf\Cli $cli, array $args): string` Cli function to get the absolute path to a documentation source file for a .md file   
  
- `public function get_template(string $name, array $args)` Get a template stored on disk. `$name` should be relative path without extension. `$args` is passed to template code, but not `extract`ed. Template files must end with `.md.php` or just `.php`.  
- `public function get(string $group, string $key)`   
- `public function get_group(string $group)`   
- `public function set(string $group, string $key, $value)`   
- `public function parse_str($str, $ext)`   
- `public function write_doc(string $rel_path, string $content)` save a file to disk in the documents directory  
- `public function write_file(string $rel_path, string $content)` save a file to disk in the root directory  
- `public function read_file(string $rel_path)` Read a file from disk, from the project root  
- `public function read_doc(string $rel_path)` Read a file from disk, from the project docs dir  
- `public function doc_path(string $rel_path)` get a path to a docs file  
- `public function report(string $msg)` Output a message to cli (may do logging later, idk)  
- `public function warn($header, $message)` Output a message to cli, header highlighted in red  
- `public function good($header, $message)` Output a message to cli, header highlighted in red  
- `public function prepare_md_content(string $markdown)` apply small fixes to markdown  
- `public function get_all_docsrc_files()`   
- `public function get_all_scan_files(): array` get array of all files in `$scrawl->dir_scan`   
- `public function generate_apis()` Generate api docs for all files  
(currently only php files)  
- `public function generate_apis_readme()` Create a README file that lists all of the classes in the API dir.  
- `public function generate_api($rel_path)` Generate api doc for a single file  
(currently only php files)  
  
- `public function get_all_classes(): array` Get an array of all classes scanned within this repo.   
  
- `public function get_all_traits(): array` Get an array of all classes scanned within this repo.   
  
- `public function setup_extensions(array $extension_classes)` Array of \Tlf\Scrawl\Extension objects  
- `public function run()` Execute scrawl in its entirety  
- `public function get_ast(string $file): array` get an array ast from a file  
Currently only supports php files  
Also sets the ast to scrawl  
- `public function setup_mdverb_ext()` get the class ast  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/run//Integrate.php  
  
# class Tlf\Scrawl\Test\Integrate  
  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function check_full_test(string $which)`   
- `public function testRunCli()`   
- `public function testRunFull()`   
- `public function testAllClasses()`   
- `public function testGenerateApiDir()` @test  
- `public function testGenerateApiDirPrototype()`   
- `public function testGetAllClasses()`   
- `public function testPhpExtWithScrawl()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/run//MdDocs.php  
  
# class Tlf\Scrawl\Test\MdDocs  
For testing all things `.md` file  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function testAstVerb()`   
- `public function testMdVerbsMain()`   
- `public function testMdVerbsParsing()`   
- `public function testCopyReadme()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/run//MdTemplates.php  
  
# class Tlf\Scrawl\Test\MdTemplates  
For testing all things `.md` file  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function testBashInstall()`   
- `public function testComposerInstall()`   
- `public function testAstTemplates()` These tests are pretty straightforward & do NOT use the ast verb or verb class at all (except passing it to the the templates) ... those more involved tests are integration tests & not every template needs to be tested that way ... just one or two  
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/run//SrcCode.php  
  
# class Tlf\Scrawl\Test\SrcCode  
For testing all things related to source code  
  
## Constants  
  
## Properties  
- `public $php_code =   
        ;`   
  
## Methods   
- `public function testExportStartEnd()`   
- `public function testDocblockExport()`   
- `public function testPhpExt()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
<!-- Project Classlist generated by ast/ApiReadme template. -->  
<!-- To Disable: Set api.generate_readme = false in your config.json -->  
# All Classes  
Browse 18 classes &amp; traits in this project. There are 14 source classes, 4 test classes, and 0 traits.  
  
*Note: As of Dec 23, 2023, only classes &amp; traits are listed. interfaces &amp; enums are not supported.*  
  
## Source Classes (not tests)  
- [`Scrawl`](src/Scrawl.php.md): Central class for running scrawl.    
- [`ugh_old_things`](src/Old.php.md): just old code that i don't wanna get rid of    
- [`Regex`](src/Utility/Regex.php.md): No description...    
- [`Main`](src/Utility/Main.php.md): No description...    
- [`DocBlock`](src/Utility/DocBlock.php.md): @featured    
- [`MdVerbs`](src/MdVerb/MdVerbs.php.md): Runs `@mdverb` extensions, enabling special callbacks for `@verb()`s in `.src.md` files    
- [`MainVerbs`](src/MdVerb/MainVerbs.php.md): No description...    
- [`Ast`](src/MdVerb/AstVerb.php.md): No description...    
- [`DoNothingExtension`](src/Ext/DoNothingExtension.php.md): Literally does nothing except the constructor and $scrawl property. Just a base class to save boilerplate on the interface    
- [`TestExtension`](src/Ext/TestExtension.php.md): Class purely exists to test that extensions work    
- [`Php`](src/Ext/Php.php.md): Integrate the lexer for PHP files    
- [`Main`](src/Ext/Main.php.md): No description...    
- [`ExportStartEnd`](src/Ext/ExportStartEnd.php.md): Export code between `// @export_start(key)` and `// @export_end(key)`  
    @featured    
- [`ExportDocBlock`](src/Ext/ExportDocBlock.php.md): Export docblock content above `@export(key)`  
    @featured    
  
  
## Traits  
  
  
  
## Test Classes   
- [`SrcCode`](test/run/SrcCode.php.md): For testing all things related to source code    
- [`MdTemplates`](test/run/MdTemplates.php.md): For testing all things `.md` file    
- [`MdDocs`](test/run/MdDocs.php.md): For testing all things `.md` file    
- [`Integrate`](test/run/Integrate.php.md): No description...    
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# All Classes  
Documentation generated by @easy_link(tlf, php/code-scrawl)  
  
## Tlf\Scrawl\FileExt\ExportDocBlock    
Export docblock content above `@export(key)`  
@featured    
See [ExportDocBlock.php](/docs/api/src/Ext/ExportDocBlock.php.md) for more.  
  
  
## Tlf\Scrawl\FileExt\ExportStartEnd    
Export code between `// @export_start(key)` and `// @export_end(key)`  
@featured    
See [ExportStartEnd.php](/docs/api/src/Ext/ExportStartEnd.php.md) for more.  
  
  
## Tlf\Scrawl\Ext\Main    
no docblock    
See [Main.php](/docs/api/src/Ext/Main.php.md) for more.  
  
  
## Tlf\Scrawl\FileExt\Php    
Integrate the lexer for PHP files    
See [Php.php](/docs/api/src/Ext/Php.php.md) for more.  
  
  
## Tlf\Scrawl\TestExtension    
Class purely exists to test that extensions work    
See [TestExtension.php](/docs/api/src/Ext/TestExtension.php.md) for more.  
  
  
## Tlf\Scrawl\DoNothingExtension    
Literally does nothing except the constructor and $scrawl property. Just a base class to save boilerplate on the interface    
See [DoNothingExtension.php](/docs/api/src/Ext/DoNothingExtension.php.md) for more.  
  
  
## Tlf\Scrawl\Ext\MdVerb\Ast    
no docblock    
See [Ast.php](/docs/api/src/MdVerb/AstVerb.php.md) for more.  
  
  
## Tlf\Scrawl\Ext\MdVerb\MainVerbs    
no docblock    
See [MainVerbs.php](/docs/api/src/MdVerb/MainVerbs.php.md) for more.  
  
  
## Tlf\Scrawl\Ext\MdVerbs    
Runs `@mdverb` extensions, enabling special callbacks for `@verb()`s in `.src.md` files    
See [MdVerbs.php](/docs/api/src/MdVerb/MdVerbs.php.md) for more.  
  
  
## Tlf\Scrawl\Utility\DocBlock    
@featured    
See [DocBlock.php](/docs/api/src/Utility/DocBlock.php.md) for more.  
  
  
## Tlf\Scrawl\Utility\Main    
no docblock    
See [Main.php](/docs/api/src/Utility/Main.php.md) for more.  
  
  
## Tlf\Scrawl\Utility\Regex    
no docblock    
See [Regex.php](/docs/api/src/Utility/Regex.php.md) for more.  
  
  
## Tlf\Scrawl\OldStuffs\ugh_old_things    
just old code that i don't wanna get rid of    
See [ugh_old_things.php](/docs/api/src/Old.php.md) for more.  
  
  
## Tlf\Scrawl    
Central class for running scrawl.    
See [Scrawl.php](/docs/api/src/Scrawl.php.md) for more.  
  
  
## Tlf\Scrawl\Test\Integrate    
no docblock    
See [Integrate.php](/docs/api/test/run//Integrate.php.md) for more.  
  
  
## Tlf\Scrawl\Test\MdDocs    
For testing all things `.md` file    
See [MdDocs.php](/docs/api/test/run//MdDocs.php.md) for more.  
  
  
## Tlf\Scrawl\Test\MdTemplates    
For testing all things `.md` file    
See [MdTemplates.php](/docs/api/test/run//MdTemplates.php.md) for more.  
  
  
## Tlf\Scrawl\Test\SrcCode    
For testing all things related to source code    
See [SrcCode.php](/docs/api/test/run//SrcCode.php.md) for more.  
  
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# Code Scrawl  
Code Scrawl is a documentation generator. You write `.src.md` files and call buit-in functions with `@‌verbs()` within, including `@‌template(template_name)` to load several built-in templates. You can create custom extensions and templates for your own projects, or to generate documentation for using a library you made.   
  
Also generate full API documentation of PHP classes. AST Generation uses `taeluf/lexer`, which can be extended to support other languages, but as of May 2023, there are no clear plans to do this.  
  
## Features  
- Integrated AST generation to automatically copy+paste specific parts of source code, thanks to [php/lexer](https://tluf.me/php/lexer)  
- Several builtin verbs and templates  
- Extend with custom verbs and templates.  
  
## Deprecation Warning:  
- v1.0 will stop using hidden directories like `.docsrc/` and instead use `docsrc/`. The defaults.json file will be changed to accomodate in v1.0  
- v1.0 will use dir `src/` instead of `code/` as a default directory to scan. (currently also scans `test/`, which will not change)  
  
### Install  
```bash  
composer require taeluf/code-scrawl v0.8.x-dev   
```  
or in your `composer.json`  
```json  
{"require":{ "taeluf/code-scrawl": "v0.8.x-dev"}}  
```  
  
  
### Configure  
Create a file `.config/scrawl.json` or `scrawl.json` in your project root. Defaults:  
```json  
{  
    "--NOTICE":"v1.0 will introduce updated defaults.",  
  
    "template.dirs": [".doctemplate"],  
  
    "dir.docs": "docs",  
    "dir.src": ".docsrc",  
    "dir.scan": ["code", "test"],  
    "ScrawlExtensions":[],  
  
    "file.bootstrap":"scrawl-bootstrap.php",  
  
    "api.output_dir": "api/",  
    "api.generate_readme": true,  
  
    "deleteExistingDocs": false,  
    "readme.copyFromDocs": false,  
  
    "markdown.preserveNewLines": true,  
    "markdown.prependGenNotice": true  
}  
```  
  
### Default Configs / File Structre  
**Note:** Instructions updated to use non-hidden directories, but the default.json file still uses hidden directories. This inconsistency will be fixed in v1.0  
- `config/scrawl.json`: configuration file  
- `docsrc/*.src.md`: documentation source files (from which your documentation is generated)  
- `docs/`: generated documentation output  
- `src/*`, and `test/*`: Code files to scan  
- `doctemplate/*.md.php` and `CodeScrawl/src/Template/*.md.php`: re-usable templates   
- `scrawl-bootstrap.php`: Runs at start of `$scrawl->run()` and `$this` is the `$scrawl` instance.  
  
## Usage  
Overview:  
- Execute with `vendor/bin/scrawl` from your project root.  
- Write files like `docsrc/README.src.md`  
- Use Markdown Verbs (mdverb) to load documentation and code into your `.src.md` files: `@‌file(src/defaults.json)` would print the content of `src/defaults.json`  
- Use the `@‌template` mdverb to load a template: `@‌template(php/compose_install, taeluf/code-scrawl)` to print composer install instructions   
- Use the `@‌ast` mdverb to load code from the AST (Asymmetric Syntax Tree): `@‌ast(class.\Tlf\Scrawl.docblock.description)` to print directly or `@‌ast(class.\Tlf\Scrawl, ast/class)` to use an ast template.  
- Write special `@‌codeverbs` in comments in code source files to export docblocks and code.   
- Extend it! Write custom templates and `@‌mdverb` handlers  
- Write custom md verb handlers (see 'Extension' section below)  
- Write custom templates (see 'Extension' section below)  
- Use an `ASCII Non-Joiner` character after an `@` sign, to write a literal `@‌at_sign_with_text` and not execute the verb handler.  
  
### Write Documents: Example  
Write files in your `docsrc` folder with the extension `.src.md`.  
Example, from [docsrc/README.src.md](/docsrc/README.src.md)  
  
This would display the `## Install` instructions and `## Configure` instructions as above  
```md  
# Code Scrawl  
Intro text  
  
## Setup   
### Install  
@‌template(php/compose_install, taeluf/code-scrawl)  
  
### Configure  
Create a file `.config/scrawl.json` or `scrawl.json` in your project root. Defaults:  
‌```json  
@‌file(src/defaults.json)  
‌```  
```  
  
### `@‌MdVerbs` List  
Write these in your markdown source files for special functionality    
- `@import()`: Import something previously exported with `@export` or `@export_start/@export_end`. Usage: `@import(Namespace.Key)`    
- `@file()`: Copy a file's content into your markdown.. Usage: `@file(rel/path/to/file.ext)`    
- `@template()`: Load a template. Usage: `@template(template_name, arg1, arg2)`    
- `@link()`: Output links configured in your config json file.  
Config format is `{..., "links": { "link_name": "https://example.org"} }`. Usage: `@link(phpunit)`    
- `@easy_link()`: Get a link to common services (twitter, gitlab, github, facebook). Usage: `@easy_link(twitter, TaelufDev)`    
- `@hard_link()`: just returns a regular markdown link. In future, may check validity of link or do some kind of logging. Usage: `@hard_link(https://url.com, LinkName)`    
- `@see_file()`: Get a link to a file in your repo. Usage: `@see_file(relative/file/path)`    
- `@see()`: Get a link to a file in your repo. Usage: `@see_file(relative/file/path)`    
- `@system()`: Run a command on the computer's operating system.  
  
Supported options: `trim`, `trim_empty_lines`, `last_x_lines, int`    
- `@ast()`: Get an ast & optionally load a custom template for it. Usage: `@ast(class.ClassName.methods.docblock.description, ast/default)`    
  
  
### Template List  
Templates can be loaded with `@‌template(template_name, arg1, arg2)`, except `ast/*` templates (see below for those).  
  
Each template contains documentation for how to use it & what args it requres.  
  
  
### `@‌ast()` Templates (Asymmetric Syntax Tree)  
Example: `@‌ast(class.\Tlf\Scrawl.docblock.description)` to print directly or `@‌ast(class.\Tlf\Scrawl, ast/class)` to use an ast template.  
  
### `@‌CodeVerbs` Exports (from code in scan dirs)  
In a docblock, write `@‌export(Some.Key)` to export everything above it.  
  
In a block of code (or literally anywhere), write `// @‌export_start(Some.Key)` then `// @‌export_end(Some.Key)` to export everything in between.  
  
See [test/run/SrcCode.php](/test/run/SrcCode.php) for examples  
  
## Extensions  
  
### Templates: Write a custom template  
Look at existing templates in [doctemplate/](/doctemplate/) or [src/Template](/src/Template) for examples.  
  
### Verb Handlers: Write a custom verb handler  
In your `scrawl-bootstrap.php` file, do something like:  
```php  
<?php  
/**  
 * @param $scrawl instance of `\Tlf\Scrawl`  
 */  
  
$scrawl->verb_handlers['own_verb'] =   
    function($arg1, $arg2){  
        return $arg1.'--'.$arg2;  
  
    };  
```  
  
### PHP Extensions  
Create a class that `implements \Tlf\Scrawl\Extension`. See file [src/Extension.php](/src/Extension.php). You can `class YourExt extends \Tlf\Scrawl\DoNothingExtension` as a base class and then only override the methods you need.  
  
In your `config.json`, set `"ScrawlExtensions": ["Your\\Fully\\Qualified\\ClassName"]`, with as many extension classes as you like.  
  
## Architecture  
- `Tlf\Scrawl`: Primary class that `run()`s everything.  
- `\Tlf\Scrawl->run()`: generate `api/*` files. Load all php classes. scan code files. Scan `.src.md` files & output `.md` files.  
    - file set as `file.bootstrap` is `require()`d at start of `run()` to setup additional mdverb handlers and (eventually) other extensions. Default is `scrawl-bootstrap.php`  
- `Tlf\Scrawl\Ext\MdVerbs`: Instantiated during `run()` prior to scanning documentation source files. When an `@‌mdverb(arg1,arg2)` is encounter in documentation source file, a handler (`$mdverbs->handlers['mdverb']`) is called with string arguments like `$handler('arg1', 'arg2')`. Extend it by adding a callable to `$scrawl->mdverb_ext->handlers`.  
    - `Tlf\Scrawl\Ext\MdVerb\MainVerbs`: Has functions for simple verb handlers like `@‌file`, `@‌template`. Adds each function as a handler to the `MdVerbs` class.  
    - `\Tlf\Scrawl\Ext\MdVerb\Ast`: A special mdverb handler that loads ASTs from the lexer and passes it to a named (or default) template.  
- `Tlf\Scrawl\FileExt\Php`: The only AST extension currently active. It is a convenience class that wraps the Lexer so it is easily called by `Scrawl`. It is called to setup ASTs by `class.ClassName...` on `$scrawl`. Call `$scrawl->get('ast', 'class.ClassName...')`. It is called to generate the `api/*` documentation files.  
- INACTIVE CLASS `Tlf\Scrawl\Ext\Main` simply copies the `project_root/.docrsc/README.src.md` to `project_root/README.md`  
- `Tlf\Scrawl\FileExt\ExportDocBlock` and `ExportStartEnd` handle the `@‌export()` tag in docblocks and the `@‌export_start()/@‌export_end()` tags.  
- `\Tlf\Scrawl\Utility\DocBlock`: Convenience class for extracting docblocks from files.  
- `\Tlf\Scrawl\Utility\Main`: Class with some convenience functions  
- `\Tlf\Scrawl\Utility\Regex`: Class to make regex matching within a file more abstract & object oriented. (it's not particularly good)  
  
## More Info  
- Run withOUT the cli: Some of the configs require absolute paths when running through php, rather than from the cli. An example is in [test/run/Integrate.php](/test/run/Integrate.php) under method `testRunFull()`  
- `@‌literal`: Displaying a literal `@‌literal` in an md source file can be done by putting a [Zero Width Non-Joiner](https://unicode-explorer.com/c/200C) after the arroba (`@`). You can also use a backslash like so: `@\literal`, but then the backslash prints  
- All classes in this repo: [docs/ClassList.md](/docs/ClassList.md)  
- `$scrawl` has a `get/set` feature. In a template, you can get an ast like `$scrawl->get('ast.Fully\Qualified\ClassName')`. Outside a template, you can use the `Php` class ([src/Ext/Php.php](/src/Ext/Php.php)) to get an ast from a file or string.  
- the `deleteExistingDocs` config has a bit of a sanity check to make sure you don't accidentally delete your whole system or something ...  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# Code Scrawl  
Documentation Generation with `@‌verbs()` in markdown for special functionality and templates for common documentation needs. Define your own verbs & templates.   
  
Integrated with [php/lexer](https://tluf.me/php/lexer) for ASTs of PHP classes (there may be bugs & it's tested only with php 7.4).  
  
Run scrawl with `vendor/bin/scrawl` from your project root.  
  
## Example `.docsrc/README.src.md`  
See below for a list of templates & `@‌verbs` available to use.  
  
This would display the `## Install` instructions and `## Configure` instructions as below  
```md  
# Code Scrawl  
Intro text  
  
## Install  
@‌template(php/compose_install, taeluf/code-scrawl)  
  
## Configure  
Create a file `.config/scrawl.json` or `scrawl.json` in your project root. Defaults:  
‌```  
@‌file(src/defaults.json)  
‌```  
```  
  
## Install  
```bash  
composer require taeluf/code-scrawl v0.8.x-dev   
```  
or in your `composer.json`  
```json  
{"require":{ "taeluf/code-scrawl": "v0.8.x-dev"}}  
```  
  
  
## Configure  
Create a file `.config/scrawl.json` or `scrawl.json` in your project root. Defaults:  
```php  
{  
  
    "--comments":{  
        "Documentation": "Visit https://www.taeluf.com/docs/Code%20Scrawl or https://gitlab.com/taeluf/php/CodeScrawl",  
        "Deprecation 1":"Version 1.0 will scan src/ & test/ ",  
        "Deprecation 2":"Version 1.0 will default to non-hidden directories 'docsrc' and 'doctemplate'",  
        "Deprecation 3":"Version 1.0 will fully-default to 'config/' dir rather than '.config/', though both will still work.",  
  
        "Addition 1": "2023-12-23: Added 'api.output_dir = 'api/' config. If `null`, then do not write api output files. Previously, APIs were ALWAYS output to the api/ dir. Default config has the same behavior as before.",  
        "Addition 2": "2023-12-23: Add api.generate_readme config (default TRUE). This is NEW Functionality that creates a README in the api/ dir."  
    },  
  
    "template.dirs": [".doctemplate"],  
  
    "dir.docs": "docs",  
    "dir.src": ".docsrc",  
    "dir.scan": ["code", "test"],  
  
    "api.output_dir": "api/",  
    "api.generate_readme": true,  
  
  
    "ScrawlExtensions":[],  
  
    "file.bootstrap":"scrawl-bootstrap.php",  
  
    "deleteExistingDocs": false,  
    "readme.copyFromDocs": false,  
  
    "markdown.preserveNewLines": true,  
    "markdown.prependGenNotice": true  
}  
```  
  
## Define your own verbs   
In your `scrawl-bootstrap.php` file, do something like:  
```php  
<?php  
/**  
 * @param $scrawl instance of `\Tlf\Scrawl`  
 */  
  
$scrawl->verb_handlers['own_verb'] =   
    function($arg1, $arg2){  
        return $arg1.'--'.$arg2;  
  
    };  
```  
  
## Write your own templates  
Look at existing templates in [doctemplate/](/doctemplate/) or [src/Template](/src/Template) for examples.  
  
## Run Scrawl  
`cd` into your project root  
```bash  
# run documentation on the current dir  
vendor/bin/scrawl   
```  
  
## File Structure (defaults)  
- `.config/scrawl.json`: configuration file  
- `.docsrc/*.src.md`: documentation source files (from which your documentation is generated)  
- `docs/`: generated documentation output  
- `code/*`, and `test/*`: Code files to scan  
- `doctemplate/*.md.php` and `CodeScrawl/src/Template/*.md.php`: re-usable templates   
- `scrawl-bootstrap.php`: Runs before `$scrawl->run()` and has access to `$scrawl` instance  
  
## `@‌Verbs`  
Write these in your markdown source files for special functionality    
- `@import()`: Import something previously exported with `@export` or `@export_start/@export_end`. Usage: `@import(Namespace.Key)`    
- `@file()`: Copy a file's content into your markdown.. Usage: `@file(rel/path/to/file.ext)`    
- `@template()`: Load a template. Usage: `@template(template_name, arg1, arg2)`    
- `@link()`: Output links configured in your config json file.  
Config format is `{..., "links": { "link_name": "https://example.org"} }`. Usage: `@link(phpunit)`    
- `@easy_link()`: Get a link to common services (twitter, gitlab, github, facebook). Usage: `@easy_link(twitter, TaelufDev)`    
- `@hard_link()`: just returns a regular markdown link. In future, may check validity of link or do some kind of logging. Usage: `@hard_link(https://url.com, LinkName)`    
- `@see_file()`: Get a link to a file in your repo. Usage: `@see_file(relative/file/path)`    
- `@see()`: Get a link to a file in your repo. Usage: `@see_file(relative/file/path)`    
- `@system()`: Run a command on the computer's operating system.  
  
Supported options: `trim`, `trim_empty_lines`, `last_x_lines, int`    
- `@ast()`: Get an ast & optionally load a custom template for it. Usage: `@ast(class.ClassName.methods.docblock.description, ast/default)`    
  
  
## Templates  
Templates can be loaded with `@‌template(template_name, arg1, arg2)`, though ast templates should be loaded with `@‌ast(class.ClassName.ast_path, ast/template_name)` where the template name is optional.  
  
Click the link to view the template file to see the documentation on how to use it & what args it requires  
  
  
## Exports (from code in scan dirs)  
In a docblock, write `@‌export(Some.Key)` to export everything above it.  
  
In a block of code (or literally anywhere), write `// @‌export_start(Some.Key)` then `// @‌export_end(Some.key)` to export everything in between.  
  
See [test/run/SrcCode.php](/test/run/SrcCode.php) for examples  
  
## More Info  
- Run withOUT the cli: Some of the configs require absolute paths when running through php, rather than from the cli. An example is in [test/run/Integrate.php](/test/run/Integrate.php) under method `testRunFull()`  
- `@‌literal`: Displaying a literal `@‌literal` in an md source file can be done by putting a [Zero Width Non-Joiner](https://unicode-explorer.com/c/200C) after the arroba (`@`). You can also use a backslash like so: `@\literal`, but then the backslash prints  
- All classes in this repo: [docs/ClassList.md](/docs/ClassList.md)  
- `$scrawl` has a `get/set` feature. In a template, you can get an ast like `$scrawl->get('ast.Fully\Qualified\ClassName')`. Outside a template, you can use the `Php` class ([src/Ext/Php.php](/src/Ext/Php.php)) to get an ast from a file or string.  
- the `deleteExistingDocs` config has a bit of a sanity check to make sure you don't accidentally delete your whole system or something ...  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# ChangeLog  
  
## Noted Changes  
- 2023-12-23: Repo cleanup (use non-hidden dirs, etc). Add API readme generation. Add git Changelog template  
  
## Git Log  
`git log` on Sat, 03 Feb 2024 20:11:01 +0000    
- bf7c05a  (HEAD -> v0.8, origin/v0.8) add git/CloneUrl template & document the utility function it calls U& add a return type [22 hours ago]  
- e71a8df  Add inline printing of [2 days ago]  
- 5e84a13  Add alt link text to link() verb [2 days ago]  
- d23dc61  run scrawl [2 days ago]  
- a56488b  add @link() verb [2 days ago]  
- d21b651  run scrawl [6 weeks ago]  
- bb13968  Add note that interfaces & enums are not supported [6 weeks ago]  
- 3f453d1  slightly improve apireadme opening description [6 weeks ago]  
- 71e970e  full composer update [6 weeks ago]  
- 81ebffd  composer update taeluf/lexer to support trait docblocks [6 weeks ago]  
- 8fb98e6  add trait support to api readme + a get_all_traits method to Scrawl proper [6 weeks ago]  
- 94a10d4  status notes [6 weeks ago]  
- 7535260  run scrawl [6 weeks ago]  
- c119802  Fix url path for class documentation, so that any double forward-slashes are removed. [6 weeks ago]  
- ed30a63  add git/ChangeLog template & a changelog documentation src file (template for everybody. src file for itself) [6 weeks ago]  
- 6c61bbe  Add api.generate_readme config (default TRUE). This is NEW Functionality that creates a README in the api/ dir. Created template for api readme generation & implemented it for Code Scrawl's docs [6 weeks ago]  
- de02bb5  add api.output_dir configuration. Default avlue has same functionality as before (always output API to doc/api/ dir. Set null/false in your config to disable api output). [6 weeks ago]  
- fd071e4  other fixes. run scrawl. No errors any more! [6 weeks ago]  
- 4bc75e1  minor pathing fixes. run scrawl [6 weeks ago]  
- 8a59b35  move files. code/ -> src/, .docsrc / -> docsrc/, .config/ -> config/, .doctemplate -> doctemplate/ [6 weeks ago]  
- 5ac0d4e  minor bugfix for declaration not found in the class template [7 weeks ago]  
- 53718ae  fix mdverbs template, used in the readme [2 months ago]  
- 85d7e41  add 'last_x_lines' option to '@system()' command. some docs changes, it looks like [2 months ago]  
- cbe9328  create defaults-1.0.json & add comments to defaults.json [2 months ago]  
- fbbc157  add mdverb `@system()` [3 months ago]  
- cecddd2  support config/scraw.json as a config location [3 months ago]  
- 460421a  composer upgrade [5 months ago]  
- e5aabfb  idk [8 months ago]  
- b9f5eb9  New introduction. Run scrawl [8 months ago]  
- e154a2f  too sleepy [8 months ago]  
- e79ef9e  in docs, add link to source code [8 months ago]  
- 5f36fd3  experimental parse_rel_path method on scrawl [9 months ago]  
- 777cd28  make get_doc_src_path work with README.md at the root dir [9 months ago]  
- 3d98f77  allow php ext ->parse_file() to take an absolute path. One minor bugfix. Minor documentation changes [9 months ago]  
- 78238f3  add get_doc_src_path for cli & get_doc_source_path for Scrawl. [11 months ago]  
- 89cc06c  add get_doc_path for use via cli, intended for use by vim/nerdtree [11 months ago]  
- 90cbf1c  create a debubg template for debugging @ast verb calls [1 year, 1 month ago]  
- a8dcd1d  bent diff [1 year, 1 month ago]  
- db05612  fix file link for all classes template [1 year, 1 month ago]  
- c30a177  bugfix for when no asts are generated [1 year, 1 month ago]  
- 70bfa11  composer upgrade [1 year, 1 month ago]  
- c648d78  add support for extensions by implementing TlfScrawlExtension. No unit tests, but I did write a TestExtension class that runs on this repo as a test. [1 year, 1 month ago]  
- 9629723  minor documentation changes [1 year, 1 month ago]  
- fb072aa  minor fix in mdverbs template. run scrawl [1 year, 1 month ago]  
- 1e658e5  make mdverb_ext accessible to bootstrap file. Document architecture. [1 year, 1 month ago]  
- 1fe6265  move `require` of file.bootstrap to start of run() method. [1 year, 1 month ago]  
- 504d6a1  notes, composer update [1 year, 2 months ago]  
- 2ef318c  minor readme change [1 year, 2 months ago]  
- e5db2b6  minor readme update [1 year, 2 months ago]  
- 9c38404  minor changes to readme .run scrawl [1 year, 2 months ago]  
- 487bd27  update readme documentation [1 year, 2 months ago]  
- d79564b  note about extensions [1 year, 2 months ago]  
- 9cfbd2b  update bin/scrawl to work with the new composer that stopped symlinking bin files [1 year, 2 months ago]  
- 018f550  make config.json in .docsrc work & make composer_install template auto-detect the composer package name [1 year, 9 months ago]  
- 98db8d9  fix the cli to auto-use the vendor install if present [1 year, 10 months ago]  
- c6fdf8d  when an md verb is not found, just return the source (while still warning in the console) [1 year, 10 months ago]  
- 490d72b  add a couple 'report's to the cli output. update docs [1 year, 11 months ago]  
- 9ca31b1  composer update [1 year, 11 months ago]  
- 392d8c0  (origin/v0.7, v0.7) minor fixes in ast/class_methods [1 year, 11 months ago]  
- f3ff5ff  delete unused docs [2 years ago]  
- 9345c07  readme done! [2 years ago]  
- 16c445d  readme [2 years ago]  
- 1ad6dfd  fixed mdverbs issue in readme [2 years ago]  
- 34ad813  i think readme is ready? [2 years ago]  
- d06ff9e  m [2 years ago]  
- 3078783  m [2 years ago]  
- 042f2c6  readme update [2 years ago]  
- f8e21d8  readme might be good? [2 years ago]  
- be8c0ef  add mdverbs template & fix up the Templates list template [2 years ago]  
- a47541f  progress on an mdverbs template [2 years ago]  
- 7f8f3ad  notes [2 years ago]  
- 5e67b73  notes [2 years ago]  
- e4080e0  not [2 years ago]  
- 11115dd  run scrawl (with issues) [2 years ago]  
- 7e59488  cleanup repo [2 years ago]  
- 4a01555  note [2 years ago]  
- 2afd2c1  cli runs successfully!!!! test passing [2 years ago]  
- e0fbe92  maybe cli works now? [2 years ago]  
- 1d7741b  i think the cli is ready? [2 years ago]  
- 8cc5eff  cli transition in progress [2 years ago]  
- f0c6973  rename Scrawl2 to Scrawl [2 years ago]  
- 7ce7a9c  mid-transition to use new scrawl for cli [2 years ago]  
- 7cae443  full scral run test passing [2 years ago]  
- e6507c6  full scrawl run is working ... the test is incomplete & some configs are not integrated [2 years ago]  
- a783a34  all classes template works [2 years ago]  
- 031d265  generate api dir working & tested [2 years ago]  
- ab113a0  prototype generatin gapi docs ... notes [2 years ago]  
- f3715db  idk ... work on file ast parsing [2 years ago]  
- 103dd00  add & test get_all_classes to php ext ... also fix issue with scrwall->get_template() ... it was using require_once() like a dummy [2 years ago]  
- 25706a9  update & test function list template, class template, and class methods template [2 years ago]  
- 09420d2  update and test composer install template [2 years ago]  
- 010f611  test bash install template. reorganize ext code [2 years ago]  
- 45090f5  delete old code. add notes [2 years ago]  
- 816d0bd  ast verb test ... complete? [2 years ago]  
- c748a8e  early implementation of ast verb [2 years ago]  
- 894f37c  delete old File, Php, and Regex classes (moved to my Stuff repo) [2 years ago]  
- 0594815  notes [2 years ago]  
- 71cbe9c  cleanup. notes. md verb stuff [2 years ago]  
- 3a2a756  updated all simple verbs & got a test passing [2 years ago]  
- 0ffd17d  md verbs partially implemented ... other stuff? [2 years ago]  
- a0e1b9c  move old code to old dirs. fix new tests to work with better regex (& the classes they test) [2 years ago]  
- 840eae3  composer.lock [2 years ago]  
- 8953360  update composer.json [2 years ago]  
- 5e4bb23  notes [2 years ago]  
- 64ce4c0  progress toward rewriting with new structure ... made an ew version of better reg (separate lib) [2 years ago]  
- 839f529  re-implement ExportDocBlock extension [2 years ago]  
- 05dbf2e  successfull prototype of writing a classList template to doc dir [2 years ago]  
- b33be33  prototyping a new setup for scrawl, that is more testable and less confusing [2 years ago]  
- ab2e98a  run scrawl [2 years ago]  
- 37c817f  add all_classes template [2 years ago]  
- f4ea2bc  note [2 years ago]  
- 1f3e338  lexer integration iworking for php!!! ran scrawl to generate api docs [2 years ago]  
- 504793b  return early in @ast hhandler & print useful emssage [2 years, 1 month ago]  
- c9d9b7b  hopefully fix issue with redirecting to vendor/bin/scrawl [2 years, 2 months ago]  
- ff224e6  fix error in composer.json [2 years, 2 months ago]  
- c10160d  bump for composer [2 years, 2 months ago]  
- 7469a1f  add bin script to composer.json [2 years, 2 months ago]  
- 69e4a6e  notes [2 years, 2 months ago]  
- cd8d0b7  print json_encode($args) on generate_docs [2 years, 2 months ago]  
- cb66a10  note [2 years, 2 months ago]  
- 912f5ec  note [2 years, 2 months ago]  
- 83639e8  notes & docs [2 years, 2 months ago]  
- 6b24511  fix init test [2 years, 2 months ago]  
- 22be0fa  some cleanup [2 years, 2 months ago]  
- 8de3d1b  start traits, delete old code, move scrawl's own doctemplate [2 years, 2 months ago]  
- 154de80  scrawl config file & propmt before running scrawl or initing [2 years, 2 months ago]  
- 43320e0  implement scrawl init [2 years, 2 months ago]  
- d27211c  implement run_init [2 years, 2 months ago]  
- e7c0540  run scrawl [2 years, 2 months ago]  
- 673a416  test: templates [2 years, 2 months ago]  
- 8f87a82  regex test passing [2 years, 2 months ago]  
- 99191d3  cleanup docs [2 years, 2 months ago]  
- 1b8b727  fix: add makrdown.prependGenNotice to defaults [2 years, 2 months ago]  
- 4b784da  scrawl executes on self successfully (have not checked actual output) [2 years, 2 months ago]  
- ca85175  add: cli lib implementation [2 years, 2 months ago]  
- 27a0090  composer lock [2 years, 2 months ago]  
- 25126f1  test: files present passing [2 years, 2 months ago]  
- 412be8f  files present test written [2 years, 2 months ago]  
- 7e47b21  progress on docgen test [2 years, 2 months ago]  
- 030de8f  fix docs output dir. run scrawl [2 years, 2 months ago]  
- 1537da7  add: template that lists code scrawl templates [2 years, 2 months ago]  
- 920ea74  fix: mdverb bug [2 years, 2 months ago]  
- 4ef6d86  fix: autoload file path [2 years, 2 months ago]  
- 31a7f02  cleanup. write docs [2 years, 2 months ago]  
- 583d167  update composer [2 years, 2 months ago]  
- 6923682  update composer & generate lock file [2 years, 2 months ago]  
- 0bfbcfb  (origin/v0.5, v0.5) version notes [2 years, 2 months ago]  
- 32ad469  notes [2 years, 2 months ago]  
- 6ab250e  notes about versions [2 years, 2 months ago]  
- 0edc491  [no commit msg given] [2 years, 4 months ago]  
- 879f39d  [no commit msg given] [2 years, 4 months ago]  
- c2fbc9f  [no commit msg given] [2 years, 4 months ago]  
- 5b7e299  notes [2 years, 4 months ago]  
- 6095c37  link to code scrawl example [2 years, 4 months ago]  
- 2adee9c  clerical [2 years, 4 months ago]  
- 6573930  minor notes [2 years, 4 months ago]  
- a428ead  fix autoload file [2 years, 4 months ago]  
- 7b1d1e8  small classmap change [2 years, 4 months ago]  
- fbefd63  fix composer.json. add note to readme [2 years, 4 months ago]  
- 982323e  remove old bash extension [2 years, 4 months ago]  
- 267e95c  bash stuff [2 years, 4 months ago]  
- 73c0bc8  notes [2 years, 5 months ago]  
- 1cdb057  notes [2 years, 5 months ago]  
- c2de993  use classlist template to also show traits [2 years, 7 months ago]  
- 4b4c3a6  apparently deleted my generated api docs. Updated the classList template for the latest phpgrammar [2 years, 7 months ago]  
- c7a2cb2  note [2 years, 7 months ago]  
- bf29d3c  add error reporting. fix @ast_class and @ast. change lex setting to lex.php & lex.bash [2 years, 7 months ago]  
- 183921e  notes. tests failing [2 years, 7 months ago]  
- ad141b3  composer description [2 years, 7 months ago]  
- 23ef5b1  add description, fix dependencies [2 years, 7 months ago]  
- 2c317f8  minor improvement to autoloading and config file output [2 years, 7 months ago]  
- fab70f9  composer dep [2 years, 8 months ago]  
- c0df098  composer dependency fix [2 years, 8 months ago]  
- f0993ba  move cli/scrawl to bin/scrawl [2 years, 8 months ago]  
- ba54502  docblocks and TODOs [2 years, 8 months ago]  
- 754b0f4  add bash_install template. improve composer install template. Add some simple verbs [2 years, 8 months ago]  
- 1a0aae0  add gitlab, github, and facebook to easy links. fix bug with composer_install template [2 years, 8 months ago]  
- 4905b52  fix bug in composer install template. add easy_link mdverb. fix mdverbs so they dont have to be at start or end of aline [2 years, 8 months ago]  
- a27c06c  added templates, lex config, an composer_install template [2 years, 8 months ago]  
- f2650c6  notes, mostly... [2 years, 9 months ago]  
- 74826fd  idunno in a hurry [2 years, 9 months ago]  
- 7015127  significant improvements to ast verb. md verbs now receive a list of arguments instead of an argliststring [2 years, 9 months ago]  
- 53eff51  notes [2 years, 9 months ago]  
- a6cc401  notes [2 years, 9 months ago]  
- 1851ada  refactor done. Seems to be functional [2 years, 9 months ago]  
- fbac9be  refactor complete? I think it works? [2 years, 9 months ago]  
- 3276ed4  notes [2 years, 9 months ago]  
- c341a67  much refactor, bu working rn [2 years, 9 months ago]  
- d090279  clean up documentation files [2 years, 9 months ago]  
- c5a71ae  add @file() verb [2 years, 9 months ago]  
- a0d61c5  update composer [2 years, 9 months ago]  
- 7a8370b  autoload improvement [2 years, 9 months ago]  
- e488afb  fix ast verb error [2 years, 10 months ago]  
- a0c9ed5  small template fix [2 years, 10 months ago]  
- 5ab13d1  [no commit msg given] [2 years, 10 months ago]  
- a4e8274  docs updated [2 years, 10 months ago]  
- cbeeb2b  docs regen [2 years, 10 months ago]  
- 6b4be1f  fixed classlist errors, and a no-files-found bug [2 years, 10 months ago]  
- c4dce73  classMethods template now outputs multi-line description successfully [2 years, 10 months ago]  
- b636b3e  add instancearg to classMethods declaration listing [2 years, 10 months ago]  
- 7cc1a14  add ast extension and classMethods template [2 years, 10 months ago]  
- 67934f0  [no commit msg given] [2 years, 11 months ago]  
- aefb7b3  implement functionList template in BashApiLexer [2 years, 11 months ago]  
- 9bba529  status doc [2 years, 11 months ago]  
- 48cf020  suppress mkdir error & phpapi lexer foreach error [2 years, 11 months ago]  
- d284938  Add BashApiLexer [2 years, 11 months ago]  
- d743a25  some refactor [2 years, 11 months ago]  
- bf7bacf  implement lexer-based php api scraper. refactor [2 years, 11 months ago]  
- c2330be  [no commit msg given] [2 years, 11 months ago]  
- 40324cd  started status doc [2 years, 11 months ago]  
- c61150a  prototype class list templating [2 years, 11 months ago]  
- 02d5976  prototype of class & method finding [3 years ago]  
- a2ecef3  implement BetterReg in Configs own extension [3 years ago]  
- da9833e  implement BetterReg in Events own extension [3 years ago]  
- 65bdc90  cleanup [3 years ago]  
- 02e10a1  refactored verb matching [3 years ago]  
- 80a28ad  implement BetterReg in ExportDocBlock extension [3 years ago]  
- 8f49735  add ext.PhpApiScraper setting [3 years ago]  
- f83f558  add interface & trait to class-finder. Convert autoloader to 2-step classmap, rather than require_all_in_dir. Prototyped output of methods along with class [3 years ago]  
- 24635a8  funcitonal prototype of PhpApi extension [3 years ago]  
- fed6933  rename Extensions [3 years ago]  
- 4328cb5  implement verb-calling in markdown files [3 years ago]  
- 0b48e05  recover tlf-test.json [3 years ago]  
- 0309df4  fixed test [3 years ago]  
- a06b9a5  integrate regex_matching. Resolve merge conflict. [3 years ago]  
- 4173c72  Create and implement Regex Matching Utility for Shared Extensions [3 years ago]  
- d4a648e  assign defaults when target directory does not exist [3 years ago]  
- e9b1b9e  Copy Readme.md to root of project [3 years ago]  
- e49ff5c  autoload function, autoload setting is now used, minor docs improvements [3 years ago]  
- c16a887  provided default value of empty array for scrawl.ext [3 years ago]  
- 2eeb15b  description [3 years ago]  
- 7097dfb  todos [3 years ago]  
- 4fa175f  cleaned up Extensions docs [3 years ago]  
- ce3e743  docs finished? Except cliAndPhp, but thats ok [3 years ago]  
- ee2d6ee  extensions docs [3 years ago]  
- 79ac501  todos cleaned up [3 years ago]  
- 6664826  docs are sorta decent [3 years ago]  
- e3751b2  Save made by GitBent with no description from user. [3 years ago]  
- 50d81fd  Save made by GitBent with no description from user. [3 years ago]  
- 01bffae  Save made by GitBent with no description from user. [3 years ago]  
- 9b5ea2d  Save made by GitBent with no description from user. [3 years ago]  
- 16cbbe6  Save made by GitBent with no description from user. [3 years ago]  
- 95b1526  Save made by GitBent with no description from user. [3 years ago]  
- f31451b  Save made by GitBent with no description from user. [3 years ago]  
- d682e3f  configs docs [3 years ago]  
- b5183b0  Save made by GitBent with no description from user. [3 years ago]  
- e2a4a5d  regen-docs [3 years ago]  
- 079e24d  updated README, started files for other docs [3 years ago]  
- ee30ae3  non-joiners... [3 years ago]  
- d175654  README improvements [3 years ago]  
- d8f0e7c  Save made by GitBent with no description from user. [3 years ago]  
- 9dd5fc2  started the 'Getting Started' section [3 years ago]  
- 75a1504  progress on docs. deleted old docs [3 years ago]  
- fccc8ab  configs and most extension calls are now being auto-documented [3 years ago]  
- 82807ac  added the deleteExistingDocs setting listing into Cli prompt. Updated docs. Reran scrawl [3 years ago]  
- 77a2c90  worked on documentation [3 years ago]  
- 9f54833  some more docs. dir removal is working [3 years ago]  
- 8e18d81  some tests. Added dangerous remove non empty directory function & implemented a deleteExistingDocs feature [3 years ago]  
- 6ec550d  updated Readme [3 years, 1 month ago]  
- ea6a6b9  Save made by GitBent with no description from user. [3 years, 1 month ago]  
- 3196460  deleted old code [3 years, 1 month ago]  
- 7034129  cleaning up repo [3 years, 1 month ago]  
- 2b23f66  template source files are writing to proper destination. key exports are working, too [3 years, 1 month ago]  
- c418384  its pretty much functional, i think? testing it & cleaning up problems rn [3 years, 1 month ago]  
- 9315851  refactored cli. progress on config intake. added config file to scrawl (for documenting itself). wrote some notes, a todo [3 years, 1 month ago]  
- d14f87d  Save made by GitBent with no description from user. [3 years, 1 month ago]  
- 01151ca  progress on default configs, minor cli changes [3 years, 1 month ago]  
- 03d4d25  cli script & autoload, renamed properties 'docu' to 'scrawl' [3 years, 1 month ago]  
- 977f43e  extensioninterface, refactored approach to extensions, changed name to Scrawl [3 years, 1 month ago]  
- 387772c  notes for future reed [3 years, 1 month ago]  
- a71fd98  refactored almost everything, but there's still gaps in functionality [3 years, 1 month ago]  
- 6b4e873  Nearly figured out new design, still much code to move & get working again [3 years, 1 month ago]  
- 4b7ef8d  idk [3 years, 1 month ago]  
- 3ddebb0  added some notes about future plans [3 years, 2 months ago]  
- 0d375be  updated url [3 years, 4 months ago]  
- e034d06  readme [3 years, 4 months ago]  
- b4dee81  install works! Fixed .gitignore [3 years, 4 months ago]  
- 624a821  a note [3 years, 4 months ago]  
- 8f32514  testing installs cript [3 years, 4 months ago]  
- 932040e  possibly fixed the install script [3 years, 4 months ago]  
- e1db2bc  readme is probably real good now! [3 years, 4 months ago]  
- 14601e0  built [3 years, 4 months ago]  
- 2f70a8e  readme work [3 years, 4 months ago]  
- 824b541  rebuilt [3 years, 4 months ago]  
- 004c0a6  readme improvmeents [3 years, 4 months ago]  
- 149cf46  rebuilt [3 years, 4 months ago]  
- e942899  cleaned up readme src [3 years, 4 months ago]  
- d18835c  re-built [3 years, 4 months ago]  
- 5cb82b2  rewriting README. Going to re-build and view in browser [3 years, 4 months ago]  
- babec5f  improved install instructions [3 years, 4 months ago]  
- 257bbf9  notes [3 years, 5 months ago]  
- 0a6cf3a  Save made by GitBent with no description from user. [3 years, 5 months ago]  
- 2353d70  Save made by GitBent with no description from user. [3 years, 5 months ago]  
- efcc351  Save made by GitBent with no description from user. [3 years, 5 months ago]  
- 1586856  minor docs [3 years, 5 months ago]  
- a808fe9  bash documenting is functional [3 years, 5 months ago]  
- 936e3a4  Save made by GitBent with no description from user. [3 years, 5 months ago]  
- bc9e39a  improved install script and added .gitignore [3 years, 5 months ago]  
- 95f47e2  added code-install dir [3 years, 5 months ago]  
- ea75980  Save made by GitBent with no description from user. [3 years, 5 months ago]  
- c6e9b28  moved folders around [3 years, 5 months ago]  
- f84cb79  Going to refactor, maybe change some of the api [3 years, 5 months ago]  
- 8a3ef9e  actually added self-promo todo item [3 years, 5 months ago]  
- ad05103  added self-promo todo item [3 years, 5 months ago]  
- a3f8d6c  docs are in good order! [3 years, 5 months ago]  
- 97bbe04  Save made by GitBent with no description from user. [3 years, 5 months ago]  
- a806e6c  Save made by GitBent with no description from user. [3 years, 5 months ago]  
- 3b2b338  install instructions [3 years, 5 months ago]  
- 5b5cb50  Save made by GitBent with no description from user. [3 years, 5 months ago]  
- ae8cb79  Save made by GitBent with no description from user. [3 years, 5 months ago]  
- 9c54981  testing docs [3 years, 5 months ago]  
- 6690b0e  improved docs [3 years, 5 months ago]  
- 0282a29  export wrapped block is working. Need to fix left-hand-padding [3 years, 5 months ago]  
- b5908ec  refactored. Now will implement wrapped export [3 years, 5 months ago]  
- a6fdb01  exports moved out of docs folder, with unused-exports renamed & in docs folder as well [3 years, 5 months ago]  
- 133b1c5  docs are nice! [3 years, 5 months ago]  
- 52d75af  Save made by GitBent with no description from user. [3 years, 5 months ago]  
- 543682b  Docs are in decent shape [3 years, 5 months ago]  
- 3d29bb6  Save made by GitBent with no description from user. [3 years, 5 months ago]  
- 7623c98  Save made by GitBent with no description from user. [3 years, 5 months ago]  
- a92c157  Save made by GitBent with no description from user. [3 years, 5 months ago]  
- 5c383c4  Save made by GitBent with no description from user. [3 years, 5 months ago]  
- 994ddce  Save made by GitBent with no description from user. [3 years, 5 months ago]  
- 80b54c1  readme improvements [3 years, 5 months ago]  
- 2a31003  Save made by GitBent with no description from user. [3 years, 5 months ago]  
- 21349ef  Save made by GitBent with no description from user. [3 years, 5 months ago]  
- f9247b4  added TODO [3 years, 5 months ago]  
- 3701e91  Is this on webhook? Just checking [3 years, 5 months ago]  
- 799ca20  just [3 years, 6 months ago]  
- 4c2223d  whatever wehbook [3 years, 6 months ago]  
- 15afca4  webhook test... hopefully the last one [3 years, 6 months ago]  
- e3aacd1  new lines, webhook testing [3 years, 6 months ago]  
- af77303  new lines webhook [3 years, 6 months ago]  
- 6e0623a  blank lines for webhook testing [3 years, 6 months ago]  
- 94cede7  webhook tests [3 years, 6 months ago]  
- 46cee81  same testing [3 years, 6 months ago]  
- 86227d0  remove blank lines for webhook testing [3 years, 6 months ago]  
- f76415b  blank lines for git webhook testing [3 years, 6 months ago]  
- f7a32bb  added preserveNewLines feature [3 years, 6 months ago]  
- eda7f44  classmap instead of psr4 [3 years, 6 months ago]  
- 975128c  composer [3 years, 6 months ago]  
- 0419d28  autoload [3 years, 6 months ago]  
- ebc1945  docs done for now [3 years, 6 months ago]  
- d8f4a60  l [3 years, 6 months ago]  
- 9bc23d3  update [3 years, 6 months ago]  
- 38c0dcf  l [3 years, 6 months ago]  
- 0dc51af  doc update [3 years, 6 months ago]  
- 2b38c26  docs and minor improvements [3 years, 6 months ago]  
- 589a843  blah [3 years, 6 months ago]  
- c6995a4  (tag: archive/master) seems to be working! [3 years, 6 months ago]  
- f201952  Create LICENSE [3 years, 6 months ago]  
- 269ae2f  l [3 years, 6 months ago]  
- 8e92342  l [3 years, 6 months ago]  
- feb488c  initial commit [3 years, 6 months ago]  
<?php

// autoload.php @generated by Composer

if (PHP_VERSION_ID < 50600) {
    if (!headers_sent()) {
        header('HTTP/1.1 500 Internal Server Error');
    }
    $err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
    if (!ini_get('display_errors')) {
        if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
            fwrite(STDERR, $err);
        } elseif (!headers_sent()) {
            echo $err;
        }
    }
    trigger_error(
        $err,
        E_USER_ERROR
    );
}

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInitad297aaad40050f09f444c559e4b76fb::getLoader();
<?php

/*
 * This file is part of Composer.
 *
 * (c) Nils Adermann <naderman@naderman.de>
 *     Jordi Boggiano <j.boggiano@seld.be>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Composer\Autoload;

/**
 * ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
 *
 *     $loader = new \Composer\Autoload\ClassLoader();
 *
 *     // register classes with namespaces
 *     $loader->add('Symfony\Component', __DIR__.'/component');
 *     $loader->add('Symfony',           __DIR__.'/framework');
 *
 *     // activate the autoloader
 *     $loader->register();
 *
 *     // to enable searching the include path (eg. for PEAR packages)
 *     $loader->setUseIncludePath(true);
 *
 * In this example, if you try to use a class in the Symfony\Component
 * namespace or one of its children (Symfony\Component\Console for instance),
 * the autoloader will first look for the class under the component/
 * directory, and it will then fallback to the framework/ directory if not
 * found before giving up.
 *
 * This class is loosely based on the Symfony UniversalClassLoader.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 * @author Jordi Boggiano <j.boggiano@seld.be>
 * @see    https://www.php-fig.org/psr/psr-0/
 * @see    https://www.php-fig.org/psr/psr-4/
 */
class ClassLoader
{
    /** @var \Closure(string):void */
    private static $includeFile;

    /** @var string|null */
    private $vendorDir;

    // PSR-4
    /**
     * @var array<string, array<string, int>>
     */
    private $prefixLengthsPsr4 = array();
    /**
     * @var array<string, list<string>>
     */
    private $prefixDirsPsr4 = array();
    /**
     * @var list<string>
     */
    private $fallbackDirsPsr4 = array();

    // PSR-0
    /**
     * List of PSR-0 prefixes
     *
     * Structured as array('F (first letter)' => array('Foo\Bar (full prefix)' => array('path', 'path2')))
     *
     * @var array<string, array<string, list<string>>>
     */
    private $prefixesPsr0 = array();
    /**
     * @var list<string>
     */
    private $fallbackDirsPsr0 = array();

    /** @var bool */
    private $useIncludePath = false;

    /**
     * @var array<string, string>
     */
    private $classMap = array();

    /** @var bool */
    private $classMapAuthoritative = false;

    /**
     * @var array<string, bool>
     */
    private $missingClasses = array();

    /** @var string|null */
    private $apcuPrefix;

    /**
     * @var array<string, self>
     */
    private static $registeredLoaders = array();

    /**
     * @param string|null $vendorDir
     */
    public function __construct($vendorDir = null)
    {
        $this->vendorDir = $vendorDir;
        self::initializeIncludeClosure();
    }

    /**
     * @return array<string, list<string>>
     */
    public function getPrefixes()
    {
        if (!empty($this->prefixesPsr0)) {
            return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
        }

        return array();
    }

    /**
     * @return array<string, list<string>>
     */
    public function getPrefixesPsr4()
    {
        return $this->prefixDirsPsr4;
    }

    /**
     * @return list<string>
     */
    public function getFallbackDirs()
    {
        return $this->fallbackDirsPsr0;
    }

    /**
     * @return list<string>
     */
    public function getFallbackDirsPsr4()
    {
        return $this->fallbackDirsPsr4;
    }

    /**
     * @return array<string, string> Array of classname => path
     */
    public function getClassMap()
    {
        return $this->classMap;
    }

    /**
     * @param array<string, string> $classMap Class to filename map
     *
     * @return void
     */
    public function addClassMap(array $classMap)
    {
        if ($this->classMap) {
            $this->classMap = array_merge($this->classMap, $classMap);
        } else {
            $this->classMap = $classMap;
        }
    }

    /**
     * Registers a set of PSR-0 directories for a given prefix, either
     * appending or prepending to the ones previously set for this prefix.
     *
     * @param string              $prefix  The prefix
     * @param list<string>|string $paths   The PSR-0 root directories
     * @param bool                $prepend Whether to prepend the directories
     *
     * @return void
     */
    public function add($prefix, $paths, $prepend = false)
    {
        $paths = (array) $paths;
        if (!$prefix) {
            if ($prepend) {
                $this->fallbackDirsPsr0 = array_merge(
                    $paths,
                    $this->fallbackDirsPsr0
                );
            } else {
                $this->fallbackDirsPsr0 = array_merge(
                    $this->fallbackDirsPsr0,
                    $paths
                );
            }

            return;
        }

        $first = $prefix[0];
        if (!isset($this->prefixesPsr0[$first][$prefix])) {
            $this->prefixesPsr0[$first][$prefix] = $paths;

            return;
        }
        if ($prepend) {
            $this->prefixesPsr0[$first][$prefix] = array_merge(
                $paths,
                $this->prefixesPsr0[$first][$prefix]
            );
        } else {
            $this->prefixesPsr0[$first][$prefix] = array_merge(
                $this->prefixesPsr0[$first][$prefix],
                $paths
            );
        }
    }

    /**
     * Registers a set of PSR-4 directories for a given namespace, either
     * appending or prepending to the ones previously set for this namespace.
     *
     * @param string              $prefix  The prefix/namespace, with trailing '\\'
     * @param list<string>|string $paths   The PSR-4 base directories
     * @param bool                $prepend Whether to prepend the directories
     *
     * @throws \InvalidArgumentException
     *
     * @return void
     */
    public function addPsr4($prefix, $paths, $prepend = false)
    {
        $paths = (array) $paths;
        if (!$prefix) {
            // Register directories for the root namespace.
            if ($prepend) {
                $this->fallbackDirsPsr4 = array_merge(
                    $paths,
                    $this->fallbackDirsPsr4
                );
            } else {
                $this->fallbackDirsPsr4 = array_merge(
                    $this->fallbackDirsPsr4,
                    $paths
                );
            }
        } elseif (!isset($this->prefixDirsPsr4[$prefix])) {
            // Register directories for a new namespace.
            $length = strlen($prefix);
            if ('\\' !== $prefix[$length - 1]) {
                throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
            }
            $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
            $this->prefixDirsPsr4[$prefix] = $paths;
        } elseif ($prepend) {
            // Prepend directories for an already registered namespace.
            $this->prefixDirsPsr4[$prefix] = array_merge(
                $paths,
                $this->prefixDirsPsr4[$prefix]
            );
        } else {
            // Append directories for an already registered namespace.
            $this->prefixDirsPsr4[$prefix] = array_merge(
                $this->prefixDirsPsr4[$prefix],
                $paths
            );
        }
    }

    /**
     * Registers a set of PSR-0 directories for a given prefix,
     * replacing any others previously set for this prefix.
     *
     * @param string              $prefix The prefix
     * @param list<string>|string $paths  The PSR-0 base directories
     *
     * @return void
     */
    public function set($prefix, $paths)
    {
        if (!$prefix) {
            $this->fallbackDirsPsr0 = (array) $paths;
        } else {
            $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
        }
    }

    /**
     * Registers a set of PSR-4 directories for a given namespace,
     * replacing any others previously set for this namespace.
     *
     * @param string              $prefix The prefix/namespace, with trailing '\\'
     * @param list<string>|string $paths  The PSR-4 base directories
     *
     * @throws \InvalidArgumentException
     *
     * @return void
     */
    public function setPsr4($prefix, $paths)
    {
        if (!$prefix) {
            $this->fallbackDirsPsr4 = (array) $paths;
        } else {
            $length = strlen($prefix);
            if ('\\' !== $prefix[$length - 1]) {
                throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
            }
            $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
            $this->prefixDirsPsr4[$prefix] = (array) $paths;
        }
    }

    /**
     * Turns on searching the include path for class files.
     *
     * @param bool $useIncludePath
     *
     * @return void
     */
    public function setUseIncludePath($useIncludePath)
    {
        $this->useIncludePath = $useIncludePath;
    }

    /**
     * Can be used to check if the autoloader uses the include path to check
     * for classes.
     *
     * @return bool
     */
    public function getUseIncludePath()
    {
        return $this->useIncludePath;
    }

    /**
     * Turns off searching the prefix and fallback directories for classes
     * that have not been registered with the class map.
     *
     * @param bool $classMapAuthoritative
     *
     * @return void
     */
    public function setClassMapAuthoritative($classMapAuthoritative)
    {
        $this->classMapAuthoritative = $classMapAuthoritative;
    }

    /**
     * Should class lookup fail if not found in the current class map?
     *
     * @return bool
     */
    public function isClassMapAuthoritative()
    {
        return $this->classMapAuthoritative;
    }

    /**
     * APCu prefix to use to cache found/not-found classes, if the extension is enabled.
     *
     * @param string|null $apcuPrefix
     *
     * @return void
     */
    public function setApcuPrefix($apcuPrefix)
    {
        $this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
    }

    /**
     * The APCu prefix in use, or null if APCu caching is not enabled.
     *
     * @return string|null
     */
    public function getApcuPrefix()
    {
        return $this->apcuPrefix;
    }

    /**
     * Registers this instance as an autoloader.
     *
     * @param bool $prepend Whether to prepend the autoloader or not
     *
     * @return void
     */
    public function register($prepend = false)
    {
        spl_autoload_register(array($this, 'loadClass'), true, $prepend);

        if (null === $this->vendorDir) {
            return;
        }

        if ($prepend) {
            self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
        } else {
            unset(self::$registeredLoaders[$this->vendorDir]);
            self::$registeredLoaders[$this->vendorDir] = $this;
        }
    }

    /**
     * Unregisters this instance as an autoloader.
     *
     * @return void
     */
    public function unregister()
    {
        spl_autoload_unregister(array($this, 'loadClass'));

        if (null !== $this->vendorDir) {
            unset(self::$registeredLoaders[$this->vendorDir]);
        }
    }

    /**
     * Loads the given class or interface.
     *
     * @param  string    $class The name of the class
     * @return true|null True if loaded, null otherwise
     */
    public function loadClass($class)
    {
        if ($file = $this->findFile($class)) {
            $includeFile = self::$includeFile;
            $includeFile($file);

            return true;
        }

        return null;
    }

    /**
     * Finds the path to the file where the class is defined.
     *
     * @param string $class The name of the class
     *
     * @return string|false The path if found, false otherwise
     */
    public function findFile($class)
    {
        // class map lookup
        if (isset($this->classMap[$class])) {
            return $this->classMap[$class];
        }
        if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
            return false;
        }
        if (null !== $this->apcuPrefix) {
            $file = apcu_fetch($this->apcuPrefix.$class, $hit);
            if ($hit) {
                return $file;
            }
        }

        $file = $this->findFileWithExtension($class, '.php');

        // Search for Hack files if we are running on HHVM
        if (false === $file && defined('HHVM_VERSION')) {
            $file = $this->findFileWithExtension($class, '.hh');
        }

        if (null !== $this->apcuPrefix) {
            apcu_add($this->apcuPrefix.$class, $file);
        }

        if (false === $file) {
            // Remember that this class does not exist.
            $this->missingClasses[$class] = true;
        }

        return $file;
    }

    /**
     * Returns the currently registered loaders keyed by their corresponding vendor directories.
     *
     * @return array<string, self>
     */
    public static function getRegisteredLoaders()
    {
        return self::$registeredLoaders;
    }

    /**
     * @param  string       $class
     * @param  string       $ext
     * @return string|false
     */
    private function findFileWithExtension($class, $ext)
    {
        // PSR-4 lookup
        $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;

        $first = $class[0];
        if (isset($this->prefixLengthsPsr4[$first])) {
            $subPath = $class;
            while (false !== $lastPos = strrpos($subPath, '\\')) {
                $subPath = substr($subPath, 0, $lastPos);
                $search = $subPath . '\\';
                if (isset($this->prefixDirsPsr4[$search])) {
                    $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
                    foreach ($this->prefixDirsPsr4[$search] as $dir) {
                        if (file_exists($file = $dir . $pathEnd)) {
                            return $file;
                        }
                    }
                }
            }
        }

        // PSR-4 fallback dirs
        foreach ($this->fallbackDirsPsr4 as $dir) {
            if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
                return $file;
            }
        }

        // PSR-0 lookup
        if (false !== $pos = strrpos($class, '\\')) {
            // namespaced class name
            $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
                . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
        } else {
            // PEAR-like class name
            $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
        }

        if (isset($this->prefixesPsr0[$first])) {
            foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
                if (0 === strpos($class, $prefix)) {
                    foreach ($dirs as $dir) {
                        if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
                            return $file;
                        }
                    }
                }
            }
        }

        // PSR-0 fallback dirs
        foreach ($this->fallbackDirsPsr0 as $dir) {
            if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
                return $file;
            }
        }

        // PSR-0 include paths.
        if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
            return $file;
        }

        return false;
    }

    /**
     * @return void
     */
    private static function initializeIncludeClosure()
    {
        if (self::$includeFile !== null) {
            return;
        }

        /**
         * Scope isolated include.
         *
         * Prevents access to $this/self from included files.
         *
         * @param  string $file
         * @return void
         */
        self::$includeFile = \Closure::bind(static function($file) {
            include $file;
        }, null, null);
    }
}
<?php

/*
 * This file is part of Composer.
 *
 * (c) Nils Adermann <naderman@naderman.de>
 *     Jordi Boggiano <j.boggiano@seld.be>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Composer;

use Composer\Autoload\ClassLoader;
use Composer\Semver\VersionParser;

/**
 * This class is copied in every Composer installed project and available to all
 *
 * See also https://getcomposer.org/doc/07-runtime.md#installed-versions
 *
 * To require its presence, you can require `composer-runtime-api ^2.0`
 *
 * @final
 */
class InstalledVersions
{
    /**
     * @var mixed[]|null
     * @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}|array{}|null
     */
    private static $installed;

    /**
     * @var bool|null
     */
    private static $canGetVendors;

    /**
     * @var array[]
     * @psalm-var array<string, array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
     */
    private static $installedByVendor = array();

    /**
     * Returns a list of all package names which are present, either by being installed, replaced or provided
     *
     * @return string[]
     * @psalm-return list<string>
     */
    public static function getInstalledPackages()
    {
        $packages = array();
        foreach (self::getInstalled() as $installed) {
            $packages[] = array_keys($installed['versions']);
        }

        if (1 === \count($packages)) {
            return $packages[0];
        }

        return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
    }

    /**
     * Returns a list of all package names with a specific type e.g. 'library'
     *
     * @param  string   $type
     * @return string[]
     * @psalm-return list<string>
     */
    public static function getInstalledPackagesByType($type)
    {
        $packagesByType = array();

        foreach (self::getInstalled() as $installed) {
            foreach ($installed['versions'] as $name => $package) {
                if (isset($package['type']) && $package['type'] === $type) {
                    $packagesByType[] = $name;
                }
            }
        }

        return $packagesByType;
    }

    /**
     * Checks whether the given package is installed
     *
     * This also returns true if the package name is provided or replaced by another package
     *
     * @param  string $packageName
     * @param  bool   $includeDevRequirements
     * @return bool
     */
    public static function isInstalled($packageName, $includeDevRequirements = true)
    {
        foreach (self::getInstalled() as $installed) {
            if (isset($installed['versions'][$packageName])) {
                return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false;
            }
        }

        return false;
    }

    /**
     * Checks whether the given package satisfies a version constraint
     *
     * e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call:
     *
     *   Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3')
     *
     * @param  VersionParser $parser      Install composer/semver to have access to this class and functionality
     * @param  string        $packageName
     * @param  string|null   $constraint  A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package
     * @return bool
     */
    public static function satisfies(VersionParser $parser, $packageName, $constraint)
    {
        $constraint = $parser->parseConstraints((string) $constraint);
        $provided = $parser->parseConstraints(self::getVersionRanges($packageName));

        return $provided->matches($constraint);
    }

    /**
     * Returns a version constraint representing all the range(s) which are installed for a given package
     *
     * It is easier to use this via isInstalled() with the $constraint argument if you need to check
     * whether a given version of a package is installed, and not just whether it exists
     *
     * @param  string $packageName
     * @return string Version constraint usable with composer/semver
     */
    public static function getVersionRanges($packageName)
    {
        foreach (self::getInstalled() as $installed) {
            if (!isset($installed['versions'][$packageName])) {
                continue;
            }

            $ranges = array();
            if (isset($installed['versions'][$packageName]['pretty_version'])) {
                $ranges[] = $installed['versions'][$packageName]['pretty_version'];
            }
            if (array_key_exists('aliases', $installed['versions'][$packageName])) {
                $ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']);
            }
            if (array_key_exists('replaced', $installed['versions'][$packageName])) {
                $ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']);
            }
            if (array_key_exists('provided', $installed['versions'][$packageName])) {
                $ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']);
            }

            return implode(' || ', $ranges);
        }

        throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
    }

    /**
     * @param  string      $packageName
     * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
     */
    public static function getVersion($packageName)
    {
        foreach (self::getInstalled() as $installed) {
            if (!isset($installed['versions'][$packageName])) {
                continue;
            }

            if (!isset($installed['versions'][$packageName]['version'])) {
                return null;
            }

            return $installed['versions'][$packageName]['version'];
        }

        throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
    }

    /**
     * @param  string      $packageName
     * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
     */
    public static function getPrettyVersion($packageName)
    {
        foreach (self::getInstalled() as $installed) {
            if (!isset($installed['versions'][$packageName])) {
                continue;
            }

            if (!isset($installed['versions'][$packageName]['pretty_version'])) {
                return null;
            }

            return $installed['versions'][$packageName]['pretty_version'];
        }

        throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
    }

    /**
     * @param  string      $packageName
     * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference
     */
    public static function getReference($packageName)
    {
        foreach (self::getInstalled() as $installed) {
            if (!isset($installed['versions'][$packageName])) {
                continue;
            }

            if (!isset($installed['versions'][$packageName]['reference'])) {
                return null;
            }

            return $installed['versions'][$packageName]['reference'];
        }

        throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
    }

    /**
     * @param  string      $packageName
     * @return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path.
     */
    public static function getInstallPath($packageName)
    {
        foreach (self::getInstalled() as $installed) {
            if (!isset($installed['versions'][$packageName])) {
                continue;
            }

            return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null;
        }

        throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
    }

    /**
     * @return array
     * @psalm-return array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}
     */
    public static function getRootPackage()
    {
        $installed = self::getInstalled();

        return $installed[0]['root'];
    }

    /**
     * Returns the raw installed.php data for custom implementations
     *
     * @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect.
     * @return array[]
     * @psalm-return array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}
     */
    public static function getRawData()
    {
        @trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED);

        if (null === self::$installed) {
            // only require the installed.php file if this file is loaded from its dumped location,
            // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
            if (substr(__DIR__, -8, 1) !== 'C' && is_file(__DIR__ . '/installed.php')) {
                self::$installed = include __DIR__ . '/installed.php';
            } else {
                self::$installed = array();
            }
        }

        return self::$installed;
    }

    /**
     * Returns the raw data of all installed.php which are currently loaded for custom implementations
     *
     * @return array[]
     * @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
     */
    public static function getAllRawData()
    {
        return self::getInstalled();
    }

    /**
     * Lets you reload the static array from another file
     *
     * This is only useful for complex integrations in which a project needs to use
     * this class but then also needs to execute another project's autoloader in process,
     * and wants to ensure both projects have access to their version of installed.php.
     *
     * A typical case would be PHPUnit, where it would need to make sure it reads all
     * the data it needs from this class, then call reload() with
     * `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure
     * the project in which it runs can then also use this class safely, without
     * interference between PHPUnit's dependencies and the project's dependencies.
     *
     * @param  array[] $data A vendor/composer/installed.php data set
     * @return void
     *
     * @psalm-param array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $data
     */
    public static function reload($data)
    {
        self::$installed = $data;
        self::$installedByVendor = array();
    }

    /**
     * @return array[]
     * @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
     */
    private static function getInstalled()
    {
        if (null === self::$canGetVendors) {
            self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
        }

        $installed = array();

        if (self::$canGetVendors) {
            foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
                if (isset(self::$installedByVendor[$vendorDir])) {
                    $installed[] = self::$installedByVendor[$vendorDir];
                } elseif (is_file($vendorDir.'/composer/installed.php')) {
                    /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
                    $required = require $vendorDir.'/composer/installed.php';
                    $installed[] = self::$installedByVendor[$vendorDir] = $required;
                    if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
                        self::$installed = $installed[count($installed) - 1];
                    }
                }
            }
        }

        if (null === self::$installed) {
            // only require the installed.php file if this file is loaded from its dumped location,
            // and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
            if (substr(__DIR__, -8, 1) !== 'C' && is_file(__DIR__ . '/installed.php')) {
                /** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
                $required = require __DIR__ . '/installed.php';
                self::$installed = $required;
            } else {
                self::$installed = array();
            }
        }

        if (self::$installed !== array()) {
            $installed[] = self::$installed;
        }

        return $installed;
    }
}
<?php

// autoload_classmap.php @generated by Composer

$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);

return array(
    'Breg' => $vendorDir . '/taeluf/better-regex/code/Breg.php',
    'Breg\\Parser' => $vendorDir . '/taeluf/better-regex/code/Parser.php',
    'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
    'Taeluf\\Tester' => $vendorDir . '/taeluf/tester/src/BackwardCompatTester.php',
    'Tlf\\Breg\\Regex' => $vendorDir . '/taeluf/better-regex/code/Matcher.php',
    'Tlf\\Cli' => $vendorDir . '/taeluf/cli/src/Cli.php',
    'Tlf\\Cli\\Msgs' => $vendorDir . '/taeluf/cli/src/Msgs.php',
    'Tlf\\Lexer' => $vendorDir . '/taeluf/lexer/src/Lexer.php',
    'Tlf\\LexerTrait\\Cache' => $vendorDir . '/taeluf/lexer/src/Lexer/Cache.php',
    'Tlf\\LexerTrait\\Directives' => $vendorDir . '/taeluf/lexer/src/Lexer/Directives.php',
    'Tlf\\LexerTrait\\InstructionProcessor' => $vendorDir . '/taeluf/lexer/src/Lexer/InstructionProcessor.php',
    'Tlf\\LexerTrait\\Instructions' => $vendorDir . '/taeluf/lexer/src/Lexer/Instructions.php',
    'Tlf\\LexerTrait\\Internals' => $vendorDir . '/taeluf/lexer/src/Lexer/Internals.php',
    'Tlf\\LexerTrait\\MappedMethods' => $vendorDir . '/taeluf/lexer/src/Lexer/MappedMethods.php',
    'Tlf\\Lexer\\ArrayAst' => $vendorDir . '/taeluf/lexer/src/Ast/ArrayAst.php',
    'Tlf\\Lexer\\Ast' => $vendorDir . '/taeluf/lexer/src/Ast.php',
    'Tlf\\Lexer\\Ast\\ClassAst' => $vendorDir . '/taeluf/lexer/src/NewAst/ClassAst.php',
    'Tlf\\Lexer\\Ast\\DocblockAst' => $vendorDir . '/taeluf/lexer/src/NewAst/DocblockAst.php',
    'Tlf\\Lexer\\Ast\\PropertyAst' => $vendorDir . '/taeluf/lexer/src/NewAst/PropertyAst.php',
    'Tlf\\Lexer\\BashGrammar' => $vendorDir . '/taeluf/lexer/src/Bash/BashGrammar.php',
    'Tlf\\Lexer\\Bash\\OtherDirectives' => $vendorDir . '/taeluf/lexer/src/Bash/OtherDirectives.php',
    'Tlf\\Lexer\\DocblockGrammar' => $vendorDir . '/taeluf/lexer/src/Docblock/DocblockGrammar.php',
    'Tlf\\Lexer\\DocblockGrammar_Defunct' => $vendorDir . '/taeluf/lexer/src/Docblock/DocblockGrammar.defunct.php',
    'Tlf\\Lexer\\Grammar' => $vendorDir . '/taeluf/lexer/src/Grammar.php',
    'Tlf\\Lexer\\Helper' => $vendorDir . '/taeluf/lexer/src/Helper.php',
    'Tlf\\Lexer\\JsonAst' => $vendorDir . '/taeluf/lexer/src/Ast/JsonAst.php',
    'Tlf\\Lexer\\JsonGrammar' => $vendorDir . '/taeluf/lexer/src/old/JsonGrammar.php',
    'Tlf\\Lexer\\OldBashGrammar' => $vendorDir . '/taeluf/lexer/src/old/OldBashGrammar.php',
    'Tlf\\Lexer\\PhpGrammar' => $vendorDir . '/taeluf/lexer/src/Php/PhpGrammar.php',
    'Tlf\\Lexer\\PhpNew\\CoreDirectives' => $vendorDir . '/taeluf/lexer/src/Php/CoreDirectives.php',
    'Tlf\\Lexer\\PhpNew\\Handlers' => $vendorDir . '/taeluf/lexer/src/Php/Handlers.php',
    'Tlf\\Lexer\\PhpNew\\Operations' => $vendorDir . '/taeluf/lexer/src/Php/Operations.php',
    'Tlf\\Lexer\\PhpNew\\StringDirectives' => $vendorDir . '/taeluf/lexer/src/Php/StringDirectives.php',
    'Tlf\\Lexer\\PhpNew\\Words' => $vendorDir . '/taeluf/lexer/src/Php/Words.php',
    'Tlf\\Lexer\\StringAst' => $vendorDir . '/taeluf/lexer/src/Ast/StringAst.php',
    'Tlf\\Lexer\\Token' => $vendorDir . '/taeluf/lexer/src/Token.php',
    'Tlf\\Lexer\\Utility' => $vendorDir . '/taeluf/lexer/src/Lexer/Utility.php',
    'Tlf\\Lexer\\Versions' => $vendorDir . '/taeluf/lexer/src/Lexer/Versions.php',
    'Tlf\\Scrawl' => $baseDir . '/src/Scrawl.php',
    'Tlf\\Scrawl\\DoNothingExtension' => $baseDir . '/src/Ext/DoNothingExtension.php',
    'Tlf\\Scrawl\\Ext\\Main' => $baseDir . '/src/Ext/Main.php',
    'Tlf\\Scrawl\\Ext\\MdVerb\\Ast' => $baseDir . '/src/MdVerb/AstVerb.php',
    'Tlf\\Scrawl\\Ext\\MdVerb\\MainVerbs' => $baseDir . '/src/MdVerb/MainVerbs.php',
    'Tlf\\Scrawl\\Ext\\MdVerbs' => $baseDir . '/src/MdVerb/MdVerbs.php',
    'Tlf\\Scrawl\\Extension' => $baseDir . '/src/Extension.php',
    'Tlf\\Scrawl\\FileExt\\ExportDocBlock' => $baseDir . '/src/Ext/ExportDocBlock.php',
    'Tlf\\Scrawl\\FileExt\\ExportStartEnd' => $baseDir . '/src/Ext/ExportStartEnd.php',
    'Tlf\\Scrawl\\FileExt\\Php' => $baseDir . '/src/Ext/Php.php',
    'Tlf\\Scrawl\\OldStuffs\\ugh_old_things' => $baseDir . '/src/Old.php',
    'Tlf\\Scrawl\\TestExtension' => $baseDir . '/src/Ext/TestExtension.php',
    'Tlf\\Scrawl\\Utility\\DocBlock' => $baseDir . '/src/Utility/DocBlock.php',
    'Tlf\\Scrawl\\Utility\\Main' => $baseDir . '/src/Utility/Main.php',
    'Tlf\\Scrawl\\Utility\\Regex' => $baseDir . '/src/Utility/Regex.php',
    'Tlf\\Tester' => $vendorDir . '/taeluf/tester/src/Tester.php',
    'Tlf\\Tester\\Assertions' => $vendorDir . '/taeluf/tester/src/Tester/Assertions.php',
    'Tlf\\Tester\\CurlBrowser' => $vendorDir . '/taeluf/tester/src/CurlBrowser.php',
    'Tlf\\Tester\\Databasing' => $vendorDir . '/taeluf/tester/src/Tester/Databasing.php',
    'Tlf\\Tester\\ExceptionCatcher' => $vendorDir . '/taeluf/tester/src/ExceptionCatcher.php',
    'Tlf\\Tester\\Exceptions' => $vendorDir . '/taeluf/tester/src/Tester/Exceptions.php',
    'Tlf\\Tester\\FakeServer' => $vendorDir . '/taeluf/tester/src/FakeServer.php',
    'Tlf\\Tester\\Other' => $vendorDir . '/taeluf/tester/src/Tester/Other.php',
    'Tlf\\Tester\\Runner' => $vendorDir . '/taeluf/tester/src/Runner.php',
    'Tlf\\Tester\\Server' => $vendorDir . '/taeluf/tester/src/Tester/Server.php',
    'Tlf\\Tester\\Utilities' => $vendorDir . '/taeluf/tester/src/Tester/Utilities.php',
    'Tlf\\Tester\\Utility' => $vendorDir . '/taeluf/tester/src/Utility.php',
    'Tlf\\Util' => $vendorDir . '/taeluf/util/code/Util.php',
    'Tlf\\Util\\FormSpam' => $vendorDir . '/taeluf/util/code/FormSpam.php',
);
<?php

// autoload_namespaces.php @generated by Composer

$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);

return array(
);
<?php

// autoload_psr4.php @generated by Composer

$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);

return array(
);
<?php

// autoload_real.php @generated by Composer

class ComposerAutoloaderInitad297aaad40050f09f444c559e4b76fb
{
    private static $loader;

    public static function loadClassLoader($class)
    {
        if ('Composer\Autoload\ClassLoader' === $class) {
            require __DIR__ . '/ClassLoader.php';
        }
    }

    /**
     * @return \Composer\Autoload\ClassLoader
     */
    public static function getLoader()
    {
        if (null !== self::$loader) {
            return self::$loader;
        }

        spl_autoload_register(array('ComposerAutoloaderInitad297aaad40050f09f444c559e4b76fb', 'loadClassLoader'), true, true);
        self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
        spl_autoload_unregister(array('ComposerAutoloaderInitad297aaad40050f09f444c559e4b76fb', 'loadClassLoader'));

        require __DIR__ . '/autoload_static.php';
        call_user_func(\Composer\Autoload\ComposerStaticInitad297aaad40050f09f444c559e4b76fb::getInitializer($loader));

        $loader->register(true);

        return $loader;
    }
}
<?php

// autoload_static.php @generated by Composer

namespace Composer\Autoload;

class ComposerStaticInitad297aaad40050f09f444c559e4b76fb
{
    public static $classMap = array (
        'Breg' => __DIR__ . '/..' . '/taeluf/better-regex/code/Breg.php',
        'Breg\\Parser' => __DIR__ . '/..' . '/taeluf/better-regex/code/Parser.php',
        'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
        'Taeluf\\Tester' => __DIR__ . '/..' . '/taeluf/tester/src/BackwardCompatTester.php',
        'Tlf\\Breg\\Regex' => __DIR__ . '/..' . '/taeluf/better-regex/code/Matcher.php',
        'Tlf\\Cli' => __DIR__ . '/..' . '/taeluf/cli/src/Cli.php',
        'Tlf\\Cli\\Msgs' => __DIR__ . '/..' . '/taeluf/cli/src/Msgs.php',
        'Tlf\\Lexer' => __DIR__ . '/..' . '/taeluf/lexer/src/Lexer.php',
        'Tlf\\LexerTrait\\Cache' => __DIR__ . '/..' . '/taeluf/lexer/src/Lexer/Cache.php',
        'Tlf\\LexerTrait\\Directives' => __DIR__ . '/..' . '/taeluf/lexer/src/Lexer/Directives.php',
        'Tlf\\LexerTrait\\InstructionProcessor' => __DIR__ . '/..' . '/taeluf/lexer/src/Lexer/InstructionProcessor.php',
        'Tlf\\LexerTrait\\Instructions' => __DIR__ . '/..' . '/taeluf/lexer/src/Lexer/Instructions.php',
        'Tlf\\LexerTrait\\Internals' => __DIR__ . '/..' . '/taeluf/lexer/src/Lexer/Internals.php',
        'Tlf\\LexerTrait\\MappedMethods' => __DIR__ . '/..' . '/taeluf/lexer/src/Lexer/MappedMethods.php',
        'Tlf\\Lexer\\ArrayAst' => __DIR__ . '/..' . '/taeluf/lexer/src/Ast/ArrayAst.php',
        'Tlf\\Lexer\\Ast' => __DIR__ . '/..' . '/taeluf/lexer/src/Ast.php',
        'Tlf\\Lexer\\Ast\\ClassAst' => __DIR__ . '/..' . '/taeluf/lexer/src/NewAst/ClassAst.php',
        'Tlf\\Lexer\\Ast\\DocblockAst' => __DIR__ . '/..' . '/taeluf/lexer/src/NewAst/DocblockAst.php',
        'Tlf\\Lexer\\Ast\\PropertyAst' => __DIR__ . '/..' . '/taeluf/lexer/src/NewAst/PropertyAst.php',
        'Tlf\\Lexer\\BashGrammar' => __DIR__ . '/..' . '/taeluf/lexer/src/Bash/BashGrammar.php',
        'Tlf\\Lexer\\Bash\\OtherDirectives' => __DIR__ . '/..' . '/taeluf/lexer/src/Bash/OtherDirectives.php',
        'Tlf\\Lexer\\DocblockGrammar' => __DIR__ . '/..' . '/taeluf/lexer/src/Docblock/DocblockGrammar.php',
        'Tlf\\Lexer\\DocblockGrammar_Defunct' => __DIR__ . '/..' . '/taeluf/lexer/src/Docblock/DocblockGrammar.defunct.php',
        'Tlf\\Lexer\\Grammar' => __DIR__ . '/..' . '/taeluf/lexer/src/Grammar.php',
        'Tlf\\Lexer\\Helper' => __DIR__ . '/..' . '/taeluf/lexer/src/Helper.php',
        'Tlf\\Lexer\\JsonAst' => __DIR__ . '/..' . '/taeluf/lexer/src/Ast/JsonAst.php',
        'Tlf\\Lexer\\JsonGrammar' => __DIR__ . '/..' . '/taeluf/lexer/src/old/JsonGrammar.php',
        'Tlf\\Lexer\\OldBashGrammar' => __DIR__ . '/..' . '/taeluf/lexer/src/old/OldBashGrammar.php',
        'Tlf\\Lexer\\PhpGrammar' => __DIR__ . '/..' . '/taeluf/lexer/src/Php/PhpGrammar.php',
        'Tlf\\Lexer\\PhpNew\\CoreDirectives' => __DIR__ . '/..' . '/taeluf/lexer/src/Php/CoreDirectives.php',
        'Tlf\\Lexer\\PhpNew\\Handlers' => __DIR__ . '/..' . '/taeluf/lexer/src/Php/Handlers.php',
        'Tlf\\Lexer\\PhpNew\\Operations' => __DIR__ . '/..' . '/taeluf/lexer/src/Php/Operations.php',
        'Tlf\\Lexer\\PhpNew\\StringDirectives' => __DIR__ . '/..' . '/taeluf/lexer/src/Php/StringDirectives.php',
        'Tlf\\Lexer\\PhpNew\\Words' => __DIR__ . '/..' . '/taeluf/lexer/src/Php/Words.php',
        'Tlf\\Lexer\\StringAst' => __DIR__ . '/..' . '/taeluf/lexer/src/Ast/StringAst.php',
        'Tlf\\Lexer\\Token' => __DIR__ . '/..' . '/taeluf/lexer/src/Token.php',
        'Tlf\\Lexer\\Utility' => __DIR__ . '/..' . '/taeluf/lexer/src/Lexer/Utility.php',
        'Tlf\\Lexer\\Versions' => __DIR__ . '/..' . '/taeluf/lexer/src/Lexer/Versions.php',
        'Tlf\\Scrawl' => __DIR__ . '/../..' . '/src/Scrawl.php',
        'Tlf\\Scrawl\\DoNothingExtension' => __DIR__ . '/../..' . '/src/Ext/DoNothingExtension.php',
        'Tlf\\Scrawl\\Ext\\Main' => __DIR__ . '/../..' . '/src/Ext/Main.php',
        'Tlf\\Scrawl\\Ext\\MdVerb\\Ast' => __DIR__ . '/../..' . '/src/MdVerb/AstVerb.php',
        'Tlf\\Scrawl\\Ext\\MdVerb\\MainVerbs' => __DIR__ . '/../..' . '/src/MdVerb/MainVerbs.php',
        'Tlf\\Scrawl\\Ext\\MdVerbs' => __DIR__ . '/../..' . '/src/MdVerb/MdVerbs.php',
        'Tlf\\Scrawl\\Extension' => __DIR__ . '/../..' . '/src/Extension.php',
        'Tlf\\Scrawl\\FileExt\\ExportDocBlock' => __DIR__ . '/../..' . '/src/Ext/ExportDocBlock.php',
        'Tlf\\Scrawl\\FileExt\\ExportStartEnd' => __DIR__ . '/../..' . '/src/Ext/ExportStartEnd.php',
        'Tlf\\Scrawl\\FileExt\\Php' => __DIR__ . '/../..' . '/src/Ext/Php.php',
        'Tlf\\Scrawl\\OldStuffs\\ugh_old_things' => __DIR__ . '/../..' . '/src/Old.php',
        'Tlf\\Scrawl\\TestExtension' => __DIR__ . '/../..' . '/src/Ext/TestExtension.php',
        'Tlf\\Scrawl\\Utility\\DocBlock' => __DIR__ . '/../..' . '/src/Utility/DocBlock.php',
        'Tlf\\Scrawl\\Utility\\Main' => __DIR__ . '/../..' . '/src/Utility/Main.php',
        'Tlf\\Scrawl\\Utility\\Regex' => __DIR__ . '/../..' . '/src/Utility/Regex.php',
        'Tlf\\Tester' => __DIR__ . '/..' . '/taeluf/tester/src/Tester.php',
        'Tlf\\Tester\\Assertions' => __DIR__ . '/..' . '/taeluf/tester/src/Tester/Assertions.php',
        'Tlf\\Tester\\CurlBrowser' => __DIR__ . '/..' . '/taeluf/tester/src/CurlBrowser.php',
        'Tlf\\Tester\\Databasing' => __DIR__ . '/..' . '/taeluf/tester/src/Tester/Databasing.php',
        'Tlf\\Tester\\ExceptionCatcher' => __DIR__ . '/..' . '/taeluf/tester/src/ExceptionCatcher.php',
        'Tlf\\Tester\\Exceptions' => __DIR__ . '/..' . '/taeluf/tester/src/Tester/Exceptions.php',
        'Tlf\\Tester\\FakeServer' => __DIR__ . '/..' . '/taeluf/tester/src/FakeServer.php',
        'Tlf\\Tester\\Other' => __DIR__ . '/..' . '/taeluf/tester/src/Tester/Other.php',
        'Tlf\\Tester\\Runner' => __DIR__ . '/..' . '/taeluf/tester/src/Runner.php',
        'Tlf\\Tester\\Server' => __DIR__ . '/..' . '/taeluf/tester/src/Tester/Server.php',
        'Tlf\\Tester\\Utilities' => __DIR__ . '/..' . '/taeluf/tester/src/Tester/Utilities.php',
        'Tlf\\Tester\\Utility' => __DIR__ . '/..' . '/taeluf/tester/src/Utility.php',
        'Tlf\\Util' => __DIR__ . '/..' . '/taeluf/util/code/Util.php',
        'Tlf\\Util\\FormSpam' => __DIR__ . '/..' . '/taeluf/util/code/FormSpam.php',
    );

    public static function getInitializer(ClassLoader $loader)
    {
        return \Closure::bind(function () use ($loader) {
            $loader->classMap = ComposerStaticInitad297aaad40050f09f444c559e4b76fb::$classMap;

        }, null, ClassLoader::class);
    }
}
{
    "packages": [
        {
            "name": "taeluf/better-regex",
            "version": "v0.4.x-dev",
            "version_normalized": "0.4.9999999.9999999-dev",
            "source": {
                "type": "git",
                "url": "git@gitlab.com:taeluf/php/better-regex.git",
                "reference": "3ee2ff3482d8903d6977fa1fd97a227f4457dc54"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Fbetter-regex/repository/archive.zip?sha=3ee2ff3482d8903d6977fa1fd97a227f4457dc54",
                "reference": "3ee2ff3482d8903d6977fa1fd97a227f4457dc54",
                "shasum": ""
            },
            "require-dev": {
                "taeluf/code-scrawl": "v0.7.x-dev",
                "taeluf/tester": "v0.3.x-dev"
            },
            "time": "2022-03-28T20:55:32+00:00",
            "default-branch": true,
            "type": "library",
            "installation-source": "dist",
            "autoload": {
                "classmap": [
                    "code"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "install-path": "../taeluf/better-regex"
        },
        {
            "name": "taeluf/cli",
            "version": "v0.1.x-dev",
            "version_normalized": "0.1.9999999.9999999-dev",
            "source": {
                "type": "git",
                "url": "https://gitlab.com/taeluf/php/cli.git",
                "reference": "12d7dd6b9a5a1fa0602405e579b807dd5b65a39d"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Fcli/repository/archive.zip?sha=12d7dd6b9a5a1fa0602405e579b807dd5b65a39d",
                "reference": "12d7dd6b9a5a1fa0602405e579b807dd5b65a39d",
                "shasum": ""
            },
            "require-dev": {
                "taeluf/code-scrawl": "v0.8.x-dev"
            },
            "time": "2024-02-03T13:23:25+00:00",
            "default-branch": true,
            "bin": [
                "bin/tlf-cli"
            ],
            "type": "library",
            "installation-source": "dist",
            "autoload": {
                "files": [],
                "classmap": [
                    "src"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "support": {
                "issues": "https://gitlab.com/taeluf/php/cli/-/issues",
                "source": "https://gitlab.com/taeluf/php/cli/-/tree/v0.1"
            },
            "install-path": "../taeluf/cli"
        },
        {
            "name": "taeluf/lexer",
            "version": "v0.8.x-dev",
            "version_normalized": "0.8.9999999.9999999-dev",
            "source": {
                "type": "git",
                "url": "https://gitlab.com/taeluf/php/lexer.git",
                "reference": "c019eb59d150f04ff8c16a19792b5d725046cd90"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Flexer/repository/archive.zip?sha=c019eb59d150f04ff8c16a19792b5d725046cd90",
                "reference": "c019eb59d150f04ff8c16a19792b5d725046cd90",
                "shasum": ""
            },
            "require": {
                "taeluf/util": "v0.1.x-dev"
            },
            "require-dev": {
                "taeluf/code-scrawl": "v0.8.x-dev",
                "taeluf/tester": "v0.3.x-dev"
            },
            "time": "2024-02-03T15:33:41+00:00",
            "default-branch": true,
            "bin": [
                "bin/lex"
            ],
            "type": "library",
            "installation-source": "dist",
            "autoload": {
                "classmap": [
                    "src"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "description": "A declarative lexer seamlessly hooking into php functions, building ASTs for multiple languages.",
            "support": {
                "issues": "https://gitlab.com/taeluf/php/lexer/-/issues",
                "source": "https://gitlab.com/taeluf/php/lexer/-/tree/v0.8"
            },
            "install-path": "../taeluf/lexer"
        },
        {
            "name": "taeluf/tester",
            "version": "v0.3.x-dev",
            "version_normalized": "0.3.9999999.9999999-dev",
            "source": {
                "type": "git",
                "url": "https://gitlab.com/taeluf/php/php-tests.git",
                "reference": "68b4623cd9c4ae8a7e7a6eaf0bacae6933cfa178"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Fphp-tests/repository/archive.zip?sha=68b4623cd9c4ae8a7e7a6eaf0bacae6933cfa178",
                "reference": "68b4623cd9c4ae8a7e7a6eaf0bacae6933cfa178",
                "shasum": ""
            },
            "require": {
                "taeluf/cli": "v0.1.x-dev",
                "taeluf/util": "v0.1.x-dev"
            },
            "require-dev": {
                "taeluf/code-scrawl": "v0.6.x-dev"
            },
            "time": "2024-01-10T13:40:51+00:00",
            "default-branch": true,
            "bin": [
                "bin/phptest"
            ],
            "type": "library",
            "installation-source": "dist",
            "autoload": {
                "classmap": [
                    "src/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "description": "A unit testing library for Php.",
            "support": {
                "issues": "https://gitlab.com/taeluf/php/php-tests/-/issues",
                "source": "https://gitlab.com/taeluf/php/php-tests/-/tree/v0.3"
            },
            "install-path": "../taeluf/tester"
        },
        {
            "name": "taeluf/util",
            "version": "v0.1.x-dev",
            "version_normalized": "0.1.9999999.9999999-dev",
            "source": {
                "type": "git",
                "url": "git@gitlab.com:taeluf/php/php-utilities.git",
                "reference": "95524064e9be1b587064c1661980fee20793a1a3"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Fphp-utilities/repository/archive.zip?sha=95524064e9be1b587064c1661980fee20793a1a3",
                "reference": "95524064e9be1b587064c1661980fee20793a1a3",
                "shasum": ""
            },
            "require-dev": {
                "taeluf/code-scrawl": "v0.8.x-dev",
                "taeluf/phtml": "v0.1.x-dev",
                "taeluf/tester": "v0.3.x-dev"
            },
            "time": "2023-12-09T08:23:28+00:00",
            "default-branch": true,
            "type": "library",
            "installation-source": "dist",
            "autoload": {
                "classmap": [
                    "code"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "description": "Utility methods",
            "install-path": "../taeluf/util"
        }
    ],
    "dev": true,
    "dev-package-names": [
        "taeluf/tester"
    ]
}
<?php return array(
    'root' => array(
        'name' => 'taeluf/code-scrawl',
        'pretty_version' => '0.0.3.x-dev',
        'version' => '0.0.3.9999999-dev',
        'reference' => '6ae90bba41dea4a52da8dd6638dca010996faba2',
        'type' => 'library',
        'install_path' => __DIR__ . '/../../',
        'aliases' => array(),
        'dev' => true,
    ),
    'versions' => array(
        'taeluf/better-regex' => array(
            'pretty_version' => 'v0.4.x-dev',
            'version' => '0.4.9999999.9999999-dev',
            'reference' => '3ee2ff3482d8903d6977fa1fd97a227f4457dc54',
            'type' => 'library',
            'install_path' => __DIR__ . '/../taeluf/better-regex',
            'aliases' => array(),
            'dev_requirement' => false,
        ),
        'taeluf/cli' => array(
            'pretty_version' => 'v0.1.x-dev',
            'version' => '0.1.9999999.9999999-dev',
            'reference' => '12d7dd6b9a5a1fa0602405e579b807dd5b65a39d',
            'type' => 'library',
            'install_path' => __DIR__ . '/../taeluf/cli',
            'aliases' => array(),
            'dev_requirement' => false,
        ),
        'taeluf/code-scrawl' => array(
            'pretty_version' => '0.0.3.x-dev',
            'version' => '0.0.3.9999999-dev',
            'reference' => '6ae90bba41dea4a52da8dd6638dca010996faba2',
            'type' => 'library',
            'install_path' => __DIR__ . '/../../',
            'aliases' => array(),
            'dev_requirement' => false,
        ),
        'taeluf/lexer' => array(
            'pretty_version' => 'v0.8.x-dev',
            'version' => '0.8.9999999.9999999-dev',
            'reference' => 'c019eb59d150f04ff8c16a19792b5d725046cd90',
            'type' => 'library',
            'install_path' => __DIR__ . '/../taeluf/lexer',
            'aliases' => array(),
            'dev_requirement' => false,
        ),
        'taeluf/tester' => array(
            'pretty_version' => 'v0.3.x-dev',
            'version' => '0.3.9999999.9999999-dev',
            'reference' => '68b4623cd9c4ae8a7e7a6eaf0bacae6933cfa178',
            'type' => 'library',
            'install_path' => __DIR__ . '/../taeluf/tester',
            'aliases' => array(),
            'dev_requirement' => true,
        ),
        'taeluf/util' => array(
            'pretty_version' => 'v0.1.x-dev',
            'version' => '0.1.9999999.9999999-dev',
            'reference' => '95524064e9be1b587064c1661980fee20793a1a3',
            'type' => 'library',
            'install_path' => __DIR__ . '/../taeluf/util',
            'aliases' => array(),
            'dev_requirement' => false,
        ),
    ),
);
MIT License

Copyright (c) 2020 Reed Sutman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/code-scrawl/ -->
# Better Regex  
Multi-line regex with comments and functions.   
  
## Features  
- `# comments`   
- `::functions(arg1 ;; {{array_item_1}}{{array_item_2}} ;; arg3)`  
    - `$br->handle('functions', function(string $arg1, array $arg2, string $arg3){return 'a string';})`  
- multi-line (`abc<NEWLINE>def` yields `abcdef`)  
  
## Additional Functionality  
- `trim`med lines  
- End of line escaped space `pattern \ NEWLINE`   
- escaped hash `pattern \# pattern` (literal hashtag)  
- escaped backslash `pattern \\NEWLINE ` (preserves the `\\`)  
  
## Install  
```bash  
composer require taeluf/better-regex v0.4.x-dev   
```  
or in your `composer.json`  
```json  
{"require":{ "taeluf/better-regex": "v0.4.x-dev"}}  
```  
  
  
## Full Example  
```php  
<?php  
$reg = <<<REGEX  
    /abc\ # abc then a space  
        ( # join referenced regexes with a |  
        ::combine({{one}}{{two}}{{three}} ;; | )  
        )\\ # literal backslash  
  
        \# # literal hashtag (then comment)  
    xyz/  
REGEX;  
$reg_refs = [  
    'one'=>'(1|one|uno)',  
    'two'=>'(2|two|dos)',  
    'three'=>'(3|three|tres)',  
    'four'=>'(4|four|quatro)'  
];  
$br = new \Breg();  
$br->handle('combine',  
    function(array $keys, string $joiner) use ($reg_refs){  
        // make an array of only the selected regs  
        $regs = [];  
        foreach ($keys as $k){  
            $regs[] = $reg_refs[$k];  
        }  
        return implode($joiner, $regs);  
    }  
);  
$final = $br->parse($reg);  
  
$this->compare(  
    '/abc\ ((1|one|uno)|(2|two|dos)|(3|three|tres))\\\\#xyz/',  
    $final,  
);  
$this->is_true(  
    preg_match($final, 'abc dos\\#xyz/') === 1  
);  
```  
  
## Versions  
- `v0.3` is an old, terribly designed version  
- `v0.4` is good to go   
- Future plans: I don't expect to change this library much. It works and it doesn't need more features. It MIGHT get some built-in `::functions()` or a nicer syntax at some point? But it doesn't matter.  
  
## Troubleshooting / Extra Stuff  
- I think comments require a space before the `#`  
- comments & multi-line are available with the `PCRE_EXTENDED` flag in php normally  
# Dev Status

## TODO
- (mar 28,2022) Don't require functions to be on their own line ... maybe
    - at least write in the docs that functions must be on their own line

## Feb 10, 2022
The new version is designed, implemented, tested, and documented.

I could add some buil-in functions or modify the function syntax.

BUT, i think this library is done. Like, permanently. It does what i need.
<?php

class Breg {


    /**
     * Callbacks for functions defined in the regex
     */
    public $handlers = [];

    /**
     * @param $function_name the name of the reg function to handle
     * @param $callable a callable that returns a string replacement
     */
    public function handle(string $function_name, callable $callable){
        $this->handlers[$function_name] = $callable;
    }

    /**
     * Match 'better' regex against a string
     * @param $regex to parse & `preg_match` with
     * @param $string to search within
     * @return matches from `preg_match_all(..., PREG_SET_ORDER)` after parsing 
     */
    public function match($regex, $string){
        $reg = $this->parse($regex);
        $didMatch = preg_match_all($regex, $string, $matches, PREG_SET_ORDER);
        return $matches;
    }


    /**
     * Parse the regex, then call all `::functions()` & fill in the regex with their results
     * @param $regex;
     */
    public function parse($regex){
        $parser = new \Breg\Parser();
        $parsed = $parser->parse($regex);

        $clean = $parsed['clean_reg'];
        foreach ($parsed['functions'] as $f){
            $handler = $this->handlers[$f['name']];
            $replacement = $handler(...$f['args']);

            $clean = str_replace($f['definition'], $replacement, $clean);
        }

        return $clean;
    }
}

<?php

namespace Tlf\Breg;

/**
 * This class not in use ... it comes from Code Scrawl. it's an incomplete prototype for getting additional information along with a preg match (like position of the match within the string)
 */
class Regex {


    /**
     *
     */
    static public function matchRegexes($targetObject, $regexArray, File $file=null, $text=null){
        if ($file === null && $text === null)throw new \Exception("Either \$file or \$text must be set");
        if ($text === null)$text = $file->content();

        $ret = [];
        foreach ($regexArray as $name => $regs){
            // echo "\nName:$name\n\n";
            $func = $regs['function'] ?? str_replace(['-','.'], '_', $name);
            unset($regs['function']);
            foreach ($regs as $i => $regex){
                $didMatch = preg_match_all($regex, $text, $matches, PREG_SET_ORDER);
                if ($didMatch){
                    //@export_start(Regex.infoArray)
                    $info = [
                        'matchList'=>$matches, // Array of all matches
                        'lineStart' => -1, // (not implemented, @TODO) Line in file/text that your match starts on
                        'lineEnd' => -1,   // (not implemented, @TODO) Line in file/text that your match ends on
                        'text' => $text,   //
                        'regIndex' => null,
                    ];
                    //@export_end(Regex.infoArray))
                    foreach ($matches as $key => $match){
                        $info['regIndex']=$key;
                        $lineStart = 0;
                        $lineEnd = 0;
                        $info['lineStart'] = $lineStart;
                        $info['lineEnd'] = $lineEnd;
                        $ret[] = call_user_func([$targetObject, $func], $name, $match, $file, $info);
                    }
                }
            }
        }
        return $ret;
    }
}
<?php

namespace Breg;

class Parser {


    // protected $regex;


    protected $patterns = [
        'function'=> '/\:\:([a-zA-Z0-9\_]*)\((.*)\)/',
        'comment'=>'/(?:^|\s)#[^\n]*$/m',
        'pad'=> '/(^\s*|\s*$)/m',
        'esc_trail_slash'=>'/(^|[^\\\\])((?:\\\\\\\\)*)(\\\\)$/m',
        'replace_esc_trail_slash'=>'$1$2\\ ',
    ];



    /**
     * parse a regex string into an array
     * 
     */
    public function parse($regex){
        $parsed = ['source_reg'=>$regex, 'functions'=>[], 'clean_reg'=>null];
        $reg = $regex;
        $cleanReg = $reg;
        $cleanReg = $this->removeComments($cleanReg);
        $cleanReg = $this->removePad($cleanReg);
        $cleanReg = $this->addEscapedTrailingSpace($cleanReg);
        $cleanReg = $this->implodeLines($cleanReg);
        $parsed['clean_reg'] = $cleanReg;

        $split = explode("\n",$reg);
        $lines = array_map([$this,'cleanLine'], $split);
        
        $functions = [];
        $i = 0;
        do {
            $line = $lines[$i];
            $func = $this->parseRegFunc($line);
            if ($func==false)continue;

            $parsed['functions'][] = $func;
        } while (count($lines)>++$i);

            // echo "\n\n";
            // var_dump($parsed);
            // echo "\n\n";
            // exit;
        return $parsed;
    }

    // public function replace($function, $string){
    //     $this->regex = str_replace($function->declaration, $string,$this->regex);
    // }
    //

    protected function removeComments($reg){
        $reg = preg_replace($this->patterns['comment'],'',$reg);
        return $reg;
    }
    protected function removePad($reg){
        $reg = preg_replace($this->patterns['pad'],'',$reg);
        return $reg;
    }
    protected function addEscapedTrailingSpace($reg){
        $reg = preg_replace($this->patterns['esc_trail_slash'], $this->patterns['replace_esc_trail_slash'], $reg);
        return $reg;
    }
    protected function implodeLines($reg){
        $arrayOfLines = explode("\n",
                    str_replace(["\r\n","\n\r","\r"],"\n",$reg)
            );
        $reg = implode('',$arrayOfLines);
        return $reg;
    }



    /**
     * Each comment must start with ` #` (space hash). Everything following in that line is comment and will be removed from output
     * If your pattern uses ` #`, escape it like ` \#`
     * 
     * @export(Syntax.Comments)
     */
    protected function cleanLine($regLine){
        // $
        $pos = strpos($regLine,' ## ');
        if ($pos!==false)$regLine = substr($regLine,0,$pos);
        $regLine = trim($regLine);
        return trim($regLine);
    }

    /**
     * ```
     * ::functionName(arg1 ;; arg2 ;; arg3) ## Comments if you want
     * ```
     * - The function must be the only thing on the line. Comments allowed.  
     * - Args must **not** be quoted. Every arg will be trimmed (surrounding whitespace is removed).  
     * - Args are separated by ' ;; ' (space semicolon semicolon space)
     * 
     * 
     * @export(Syntax.Functions)
     */
    protected function parseRegFunc($line){

        // $funcReg = '/^\:\:([a-zA-Z0-9]*)\((.*)\)$/';
        $funcReg = '/\:\:([a-zA-Z0-9]*)\((.*)\)/';
        // $refListReg = '/\{\{([a-zA-Z\.0-9]+)\}\}/';
        $matches = [];
        $match = preg_match($this->patterns['function'],$line,$matches);
        if (!$match) return false;
        $specialCharsReg = '\.\-\_';
        /**
         * Functions can accept a refs list as an argument. Each ref is closed in double moustaches `{{refname}}`
         * ```
         * ## Combine selected refs with the bar (|) separator
         * ::combine( {{ref1}}{{ref2}}{{ref3}} ;; |)
         * ```
         * Each ref name can be composed of `a-z`, `A-Z`, `0-9`, and/or special chars: `. - _`
         * 
         * @export(Syntax.Refs)
         */
        $getRefs = '/\{\{([a-zA-Z'.$specialCharsReg.'0-9]+)\}\}/';
        $isRefsArg = '/^(\{\{([a-zA-Z'.$specialCharsReg.'0-9]+)\}\})+$/';
        
        $funcName = $matches[1];
        $argsList = explode(' ;; ',$matches[2]);
        $finalArgList = [];

        $func = ['definition'=>$matches[0],'name'=>$funcName,'args'=>[], 'argString'=>$matches[2]];
        while ($arg = current($argsList)){
            next($argsList);
            $arg = trim($arg);
            if (preg_match($isRefsArg,$arg)){
                // echo "IS REF ARG: ".$arg."\n\n";
                $refs = [];
                preg_match_all($getRefs,$arg,$refs);
                // $func['items'][] = $refs[1];
                // var_dump($refs);
                // $arg = $this->namespace.'.'.$refs[1][0];
                $arg = $refs[1];
            }
            $func['args'][] = $arg;
        }

        return $func;
    }
}
{
    "name": "taeluf/better-regex",
    "autoload":{
        "classmap":["code"]
    },
    "license": "MIT",
    "require":{

    },
    "require-dev":{
        "taeluf/code-scrawl": "v0.7.x-dev",
        "taeluf/tester": "v0.3.x-dev"
    },
    "minimum-stability":"dev"
}
{
    "_readme": [
        "This file locks the dependencies of your project to a known state",
        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
        "This file is @generated automatically"
    ],
    "content-hash": "05812340814cdf43b74d85261a64e42b",
    "packages": [],
    "packages-dev": [
        {
            "name": "taeluf/cli",
            "version": "v0.1.x-dev",
            "source": {
                "type": "git",
                "url": "https://gitlab.com/taeluf/php/cli.git",
                "reference": "ad54fabde41d2a7f301e24128bdd6407de2bfd52"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Fcli/repository/archive.zip?sha=ad54fabde41d2a7f301e24128bdd6407de2bfd52",
                "reference": "ad54fabde41d2a7f301e24128bdd6407de2bfd52",
                "shasum": ""
            },
            "require-dev": {
                "taeluf/code-scrawl": "v0.5.x-dev"
            },
            "default-branch": true,
            "type": "library",
            "autoload": {
                "files": [],
                "classmap": [
                    "code"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "support": {
                "issues": "https://gitlab.com/taeluf/php/cli/-/issues",
                "source": "https://gitlab.com/taeluf/php/cli/-/tree/v0.1"
            },
            "time": "2021-12-03T20:20:44+00:00"
        },
        {
            "name": "taeluf/code-scrawl",
            "version": "v0.7.x-dev",
            "source": {
                "type": "git",
                "url": "https://gitlab.com/taeluf/php/CodeScrawl.git",
                "reference": "840eae3bf1f3840e4b8f48bb7054983bb197f79c"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2FCodeScrawl/repository/archive.zip?sha=840eae3bf1f3840e4b8f48bb7054983bb197f79c",
                "reference": "840eae3bf1f3840e4b8f48bb7054983bb197f79c",
                "shasum": ""
            },
            "require": {
                "taeluf/better-regex": "v0.4.x-dev",
                "taeluf/cli": "v0.1.x-dev",
                "taeluf/lexer": "v0.7.x-dev"
            },
            "require-dev": {
                "taeluf/tester": "v0.3.x-dev"
            },
            "bin": [
                "bin/scrawl"
            ],
            "type": "library",
            "autoload": {
                "classmap": [
                    "code/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "description": "A documentation generation framework with some built-in extensions for exporting comments and code, and importing into markdown. ",
            "support": {
                "issues": "https://gitlab.com/taeluf/php/CodeScrawl/-/issues",
                "source": "https://gitlab.com/taeluf/php/CodeScrawl/-/tree/v0.7"
            },
            "time": "2022-02-10T17:48:58+00:00"
        },
        {
            "name": "taeluf/lexer",
            "version": "v0.7.x-dev",
            "source": {
                "type": "git",
                "url": "https://gitlab.com/taeluf/php/lexer.git",
                "reference": "f542bc987c28e075d8bd4f5363db54aa962f11f8"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Flexer/repository/archive.zip?sha=f542bc987c28e075d8bd4f5363db54aa962f11f8",
                "reference": "f542bc987c28e075d8bd4f5363db54aa962f11f8",
                "shasum": ""
            },
            "require-dev": {
                "taeluf/tester": "v0.3.x-dev"
            },
            "type": "library",
            "autoload": {
                "classmap": [
                    "code"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "description": "A declarative lexer seamlessly hooking into php functions, building ASTs for multiple languages.",
            "support": {
                "issues": "https://gitlab.com/taeluf/php/lexer/-/issues",
                "source": "https://gitlab.com/taeluf/php/lexer/-/tree/v0.7"
            },
            "time": "2022-01-28T22:13:29+00:00"
        },
        {
            "name": "taeluf/tester",
            "version": "v0.3.x-dev",
            "source": {
                "type": "git",
                "url": "https://gitlab.com/taeluf/php/php-tests.git",
                "reference": "8fe649f3c6a2830e745b38ec1f608486e153f8ca"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Fphp-tests/repository/archive.zip?sha=8fe649f3c6a2830e745b38ec1f608486e153f8ca",
                "reference": "8fe649f3c6a2830e745b38ec1f608486e153f8ca",
                "shasum": ""
            },
            "require": {
                "taeluf/cli": "v0.1.x-dev"
            },
            "require-dev": {
                "taeluf/code-scrawl": "v0.6.x-dev"
            },
            "bin": [
                "code/phptest"
            ],
            "type": "library",
            "autoload": {
                "classmap": [
                    "code/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "description": "A unit testing library for Php.",
            "support": {
                "issues": "https://gitlab.com/taeluf/php/php-tests/-/issues",
                "source": "https://gitlab.com/taeluf/php/php-tests/-/tree/v0.3"
            },
            "time": "2022-02-03T19:27:30+00:00"
        }
    ],
    "aliases": [],
    "minimum-stability": "dev",
    "stability-flags": {
        "taeluf/code-scrawl": 20,
        "taeluf/tester": 20
    },
    "prefer-stable": false,
    "prefer-lowest": false,
    "platform": [],
    "platform-dev": [],
    "plugin-api-version": "2.1.0"
}
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/code-scrawl/ -->
# Better Regex  
Multi-line regex with comments and functions.   
  
## Features  
- `# comments`   
- `::functions(arg1 ;; {{array_item_1}}{{array_item_2}} ;; arg3)`  
    - `$br->handle('functions', function(string $arg1, array $arg2, string $arg3){return 'a string';})`  
- multi-line (`abc<NEWLINE>def` yields `abcdef`)  
  
## Additional Functionality  
- `trim`med lines  
- End of line escaped space `pattern \ NEWLINE`   
- escaped hash `pattern \# pattern` (literal hashtag)  
- escaped backslash `pattern \\NEWLINE ` (preserves the `\\`)  
  
## Install  
```bash  
composer require taeluf/better-regex v0.4.x-dev   
```  
or in your `composer.json`  
```json  
{"require":{ "taeluf/better-regex": "v0.4.x-dev"}}  
```  
  
  
## Full Example  
```php  
<?php  
$reg = <<<REGEX  
    /abc\ # abc then a space  
        ( # join referenced regexes with a |  
        ::combine({{one}}{{two}}{{three}} ;; | )  
        )\\ # literal backslash  
  
        \# # literal hashtag (then comment)  
    xyz/  
REGEX;  
$reg_refs = [  
    'one'=>'(1|one|uno)',  
    'two'=>'(2|two|dos)',  
    'three'=>'(3|three|tres)',  
    'four'=>'(4|four|quatro)'  
];  
$br = new \Breg();  
$br->handle('combine',  
    function(array $keys, string $joiner) use ($reg_refs){  
        // make an array of only the selected regs  
        $regs = [];  
        foreach ($keys as $k){  
            $regs[] = $reg_refs[$k];  
        }  
        return implode($joiner, $regs);  
    }  
);  
$final = $br->parse($reg);  
  
$this->compare(  
    '/abc\ ((1|one|uno)|(2|two|dos)|(3|three|tres))\\\\#xyz/',  
    $final,  
);  
$this->is_true(  
    preg_match($final, 'abc dos\\#xyz/') === 1  
);  
```  
  
## Versions  
- `v0.3` is an old, terribly designed version  
- `v0.4` is good to go   
- Future plans: I don't expect to change this library much. It works and it doesn't need more features. It MIGHT get some built-in `::functions()` or a nicer syntax at some point? But it doesn't matter.  
  
## Troubleshooting / Extra Stuff  
- I think comments require a space before the `#`  
- comments & multi-line are available with the `PCRE_EXTENDED` flag in php normally  
# class Breg



## Constants

## Properties
- `public $handlers = [];` Callbacks for functions defined in the regex

## Methods 
- `public function handle(string $function_name, callable $callable)` 
- `public function match($regex, $string)` Match 'better' regex against a string
- `public function parse($regex)` Parse the regex, then call all `::functions()` & fill in the regex with their results




# class Breg\Parser



## Constants

## Properties
- `protected $patterns = [
        'comment'=>'/(?:^|\s)#[^\n]*$/m',
        'pad'=> '/(^\s*|\s*$)/m',
        'esc_trail_slash'=>'/(^|[^\\\\])((?:\\\\\\\\)*)(\\\\)$/m',
        'replace_esc_trail_slash'=>'$1$2\\ ',
    ];` 

## Methods 
- `public function parse($regex)` parse a regex string into an array
- `protected function removeComments($reg)` 
- `protected function removePad($reg)` 
- `protected function addEscapedTrailingSpace($reg)` 
- `protected function implodeLines($reg)` 
- `protected function cleanLine($regLine)` Each comment must start with ` #` (space hash). Everything following in that line is comment and will be removed from output
If your pattern uses ` #`, escape it like ` \#`

- `protected function parseRegFunc($line)` ```
::functionName(arg1 ;; arg2 ;; arg3) ## Comments if you want
```
- The function must be the only thing on the line. Comments allowed.  
- Args must **not** be quoted. Every arg will be trimmed (surrounding whitespace is removed).  
- Args are separated by ' ;; ' (space semicolon semicolon space)






# class Taeluf\BetterReg\Test\Cleaning\Cleaning



## Constants

## Properties

## Methods 
- `public function testCleaning()` 




# class Tlf\Breg\Test\Main



## Constants

## Properties
- `$final = $brparse($reg);` 
- `$thiscompare(
            '/abc\ ((1|one|uno)|(2|two|dos)|(3|three|tres))\\\\#xyz/',
            $final,
        );` 
- `$thisis_true(
            preg_match($final, 'abc dos\\#xyz/') = 1
        );` 

## Methods 
- `public function testBasicMatch()` 
- `public function testDocumentation()` 





# Syntax.Comments
Each comment must start with ` #` (space hash). Everything following in that line is comment and will be removed from output
If your pattern uses ` #`, escape it like ` \#`


# Syntax.Functions
```
::functionName(arg1 ;; arg2 ;; arg3) ## Comments if you want
```
- The function must be the only thing on the line. Comments allowed.  
- Args must **not** be quoted. Every arg will be trimmed (surrounding whitespace is removed).  
- Args are separated by ' ;; ' (space semicolon semicolon space)


# Syntax.Refs
Functions can accept a refs list as an argument. Each ref is closed in double moustaches `{{refname}}`
```
## Combine selected refs with the bar (|) separator
::combine( {{ref1}}{{ref2}}{{ref3}} ;; |)
```
Each ref name can be composed of `a-z`, `A-Z`, `0-9`, and/or special chars: `. - _`


# Example.Cleaning.Src
<<<REGEX
One
#a comment at the start
## Another start of line comment
#
##
\#\ 
\
\ 
    eol_esc_slash\\\\\\\\\\\\
    eol_space_test\\\\\\\\\         
    abc\ #Should this be a comment? It IS, only because making it NOT a comment is much more complicated & harder to communicate.
    def\  #this IS a comment
    ghi\ \#this is not a comment
    jkl\\\\ #this IS a comment
        #
    \ Two # Am a comment
    ( ( # Am another comment
        \#Three # This seems like a lot of comments
		#[0-9] # You need escape your # lie \# to use a space + hash as not-a-comment
    ))?
REGEX,


# Example.Cleaning.Target
'One\\#\\ \\ \\ eol_esc_slash\\\\\\\\\\\\eol_space_test\\\\\\\\\\ abc\\ def\\ ghi\\ \\#this is not a commentjkl\\\\\ Two( (\#Three))?',


# Example.Full
$reg = <<<REGEX
    /abc\ # abc then a space
        ( # join referenced regexes with a |
        ::combine({{one}}{{two}}{{three}} ;; | )
        )\\ # literal backslash

        \# # literal hashtag (then comment)
    xyz/
REGEX;
$reg_refs = [
    'one'=>'(1|one|uno)',
    'two'=>'(2|two|dos)',
    'three'=>'(3|three|tres)',
    'four'=>'(4|four|quatro)'
];
$br = new \Breg();
$br->handle('combine',
    function(array $keys, string $joiner) use ($reg_refs){
        // make an array of only the selected regs
        $regs = [];
        foreach ($keys as $k){
            $regs[] = $reg_refs[$k];
        }
        return implode($joiner, $regs);
    }
);
$final = $br->parse($reg);

$this->compare(
    '/abc\ ((1|one|uno)|(2|two|dos)|(3|three|tres))\\\\#xyz/',
    $final,
);
$this->is_true(
    preg_match($final, 'abc dos\\#xyz/') === 1
);

<?php
return array (
  'Syntax.Comments' => 'Each comment must start with ` #` (space hash). Everything following in that line is comment and will be removed from output
If your pattern uses ` #`, escape it like ` \\#`',
  'Syntax.Functions' => '```
::functionName(arg1 ;; arg2 ;; arg3) ## Comments if you want
```
- The function must be the only thing on the line. Comments allowed.  
- Args must **not** be quoted. Every arg will be trimmed (surrounding whitespace is removed).  
- Args are separated by \' ;; \' (space semicolon semicolon space)',
  'Syntax.Refs' => 'Functions can accept a refs list as an argument. Each ref is closed in double moustaches `{{refname}}`
```
## Combine selected refs with the bar (|) separator
::combine( {{ref1}}{{ref2}}{{ref3}} ;; |)
```
Each ref name can be composed of `a-z`, `A-Z`, `0-9`, and/or special chars: `. - _`',
  'Example.Cleaning.Src' => '<<<REGEX
One
#a comment at the start
## Another start of line comment
#
##
\\#\\ 
\\
\\ 
    eol_esc_slash\\\\\\\\\\\\\\\\\\\\\\\\
    eol_space_test\\\\\\\\\\\\\\\\\\         
    abc\\ #Should this be a comment? It IS, only because making it NOT a comment is much more complicated & harder to communicate.
    def\\  #this IS a comment
    ghi\\ \\#this is not a comment
    jkl\\\\\\\\ #this IS a comment
        #
    \\ Two # Am a comment
    ( ( # Am another comment
        \\#Three # This seems like a lot of comments
		#[0-9] # You need escape your # lie \\# to use a space + hash as not-a-comment
    ))?
REGEX,',
  'Example.Cleaning.Target' => '\'One\\\\#\\\\ \\\\ \\\\ eol_esc_slash\\\\\\\\\\\\\\\\\\\\\\\\eol_space_test\\\\\\\\\\\\\\\\\\\\ abc\\\\ def\\\\ ghi\\\\ \\\\#this is not a commentjkl\\\\\\\\\\ Two( (\\#Three))?\',',
  'Example.Full' => '$reg = <<<REGEX
    /abc\\ # abc then a space
        ( # join referenced regexes with a |
        ::combine({{one}}{{two}}{{three}} ;; | )
        )\\\\ # literal backslash

        \\# # literal hashtag (then comment)
    xyz/
REGEX;
$reg_refs = [
    \'one\'=>\'(1|one|uno)\',
    \'two\'=>\'(2|two|dos)\',
    \'three\'=>\'(3|three|tres)\',
    \'four\'=>\'(4|four|quatro)\'
];
$br = new \\Breg();
$br->handle(\'combine\',
    function(array $keys, string $joiner) use ($reg_refs){
        // make an array of only the selected regs
        $regs = [];
        foreach ($keys as $k){
            $regs[] = $reg_refs[$k];
        }
        return implode($joiner, $regs);
    }
);
$final = $br->parse($reg);

$this->compare(
    \'/abc\\ ((1|one|uno)|(2|two|dos)|(3|three|tres))\\\\\\\\#xyz/\',
    $final,
);
$this->is_true(
    preg_match($final, \'abc dos\\\\#xyz/\') === 1
);',
)
?>{
    "dir.test":"test/run",
    "dir.exclude":[],
    "file.require":[],
    "dir.require":[],
    "results.writeHtml":false,

    "server.dir":"test/Server/",
    "server.router":"deliver.php",

    "test":[]
}
::subtags(whenever.actor ;; |) ## Comment for BetterReg testing
::subtags(whenever.action ;; |) ## Comment
Whenever 
    ( ## Actor
        ::subtags(whenever.actor ;; |) ## Comment for BetterReg testing
    )
        ::subtags(whenever.action ;; |) ## Comment
    )
    ( (  ## Target of the action
        a card|a land card
        |another land|a Mountain|a Swamp|a Spirit or Arcane spell|THIS_CARD|an instant or sorcery spell
        |a (white|blue|black|red|green) spell|another card
        |(this|a|an)( (historic|artifact|enchantment))? spell
        |a spell or ability|a card|no Swamps|an Aura
        |(your second|a multicolored|a Druid|an instant|a legendary|a Giant|a planeswalker) spell
        |(a Kithkin|a silver-bordered|a blue or black|an Aura) spell
        |a Clue|you|a player|a land|a spell or ability|your hand|a permanent|another permanent
        |no other artifacts|an opponent|an opponent\'s graveyard
        |one or more targets|flying|a white\, blue\, black\, or red spell|a blue\, black\, or red spell
    ))? 
    ( ( ## describes further or is too complex for current algo
        for mana|from your graveyard|no permanents other than THIS_CARD and have no cards in hand
        |for the first time each turn|during an opponent\'s turn 
        |your second spell each turn
        |by one or more Orcs|an opponent controls|from your graveyard
        |from your library|on a six-sided die|on a die|from anywhere
    ))?
##  Whenever statement ends in a comma!
\,
<?php

namespace Taeluf\BetterReg\Test\Cleaning;

function regex(){ 
    return
    [
    'src'=>
//@export_start(Example.Cleaning.Src)
<<<REGEX
One
#a comment at the start
## Another start of line comment
#
##
\#\ 
\
\ 
    eol_esc_slash\\\\\\\\\\\\
    eol_space_test\\\\\\\\\         
    abc\ #Should this be a comment? It IS, only because making it NOT a comment is much more complicated & harder to communicate.
    def\  #this IS a comment
    ghi\ \#this is not a comment
    jkl\\\\ #this IS a comment
        #
    \ Two # Am a comment
    ( ( # Am another comment
        \#Three # This seems like a lot of comments
		#[0-9] # You need escape your # lie \# to use a space + hash as not-a-comment
    ))?
REGEX,
//@export_end(Example.Cleaning.Src)
    'target'=>
//@export_start(Example.Cleaning.Target)
    'One\\#\\ \\ \\ eol_esc_slash\\\\\\\\\\\\eol_space_test\\\\\\\\\\ abc\\ def\\ ghi\\ \\#this is not a commentjkl\\\\\ Two( (\#Three))?',
//@export_end(Example.Cleaning.Target)
    // 'target'=>'Oneeol_space_test\\\\\ abc\ def\ ghi\ \#this is not a commentjkl\\\ Two( (\#Three))?',
    ];
}
class Cleaning extends \Tlf\Tester {

    public function testCleaning(){
        // This tests:
        // a. Removing comments
        // b. End of line escaped space `\ `
        // c. Beginning of line escaped space
        // d. Trimming lines
        // e. Removing newlines
        // f. escaped hash `\#`
        // g. escaped slash `\\` at end of line (but there should NOT be a space)
        $regex = regex();
        $regexSrc = $regex['src'];
        $target = $regex['target'];

        $parser = new \Breg\Parser();
        $parsed = $parser->parse($regexSrc);
        $this->compare($target,$parsed['clean_reg']);

    }
}

<?php

namespace Tlf\Breg\Test;

class Main extends \Tlf\Tester {

    /**
     * @bug(fixed, 3-20-2022) When a function call has an arg, the rest of the functions fail to parse. 
     *
     *
     */
    public function testTwoFunctionCalls(){
        $br = new \Breg();
        $br->handle('everything',function(){return '(.+)';});
        $br->handle('subtags',function(){return 'sub';});
        $reg = <<<REGEX
            /a  \    
                ::everything(arg) # everything in between
                some stuff
                ::everything(unother)
                ::subtags()
            g/ # umm, the alphabet ends on z, actually

        REGEX;
        $parsed = $br->parse($reg);

        $this->compare(
            '/a  \ (.+)some stuff(.+)subg/',
            $parsed
        );
    }

    /** @test matching a basic regex */
    public function testBasicMatch(){
        $br = new \Breg();
        $reg = '/a(.+)g(h)/';
        $str = '0abcdefghi';
        $ret = $br->match($reg, $str);
        $this->compare(
            ['abcdefgh','bcdef','h'],
            $ret[0]
        );
    }

    /** @test a full-featured usage for documentation */
    public function testDocumentation(){
        // @export_start(Example.Full)
        $reg = <<<REGEX
            /abc\ # abc then a space
                ( # join referenced regexes with a |
                ::combine({{one}}{{two}}{{three}} ;; | )
                )\\ # literal backslash

                \# # literal hashtag (then comment)
            xyz/
        REGEX;
        $reg_refs = [
            'one'=>'(1|one|uno)',
            'two'=>'(2|two|dos)',
            'three'=>'(3|three|tres)',
            'four'=>'(4|four|quatro)'
        ];
        $br = new \Breg();
        $br->handle('combine',
            function(array $keys, string $joiner) use ($reg_refs){
                // make an array of only the selected regs
                $regs = [];
                foreach ($keys as $k){
                    $regs[] = $reg_refs[$k];
                }
                return implode($joiner, $regs);
            }
        );
        $final = $br->parse($reg);
        
        $this->compare(
            '/abc\ ((1|one|uno)|(2|two|dos)|(3|three|tres))\\\\#xyz/',
            $final,
        );
        $this->is_true(
            preg_match($final, 'abc dos\\#xyz/') === 1
        );
        // @export_end(Example.Full)
    }

    /**
     * @test argument list (array)
     */
    public function testBuildRegFuncArgs(){
        $br = new \Breg();
        $br->handle('letters',
            function(array $letters){
                return implode('', $letters);
            }
        );
        $reg = <<<REGEX
            /a 
                ::letters({{b}}{{c}}{{d}}{{f}}) # everything in between
            g/ # umm, the alphabet ends on z, actually

        REGEX;
        $target = '/a  \ ::everything()g/';
        $parsed = $br->parse($reg);

        $this->compare(
            '/abcdfg/',
            $parsed
        );
    }
    /** @test regex with function call containing an underscore */
    public function testBuildFunctionWithUnderscore(){
        $br = new \Breg();
        $br->handle('every_thing',function(){return '(.+)';});
        $reg = <<<REGEX
            /a  \    
                ::every_thing() # everything in between
            g/ # umm, the alphabet ends on z, actually

        REGEX;
        $parsed = $br->parse($reg);

        $this->compare(
            '/a  \ (.+)g/',
            $parsed
        );
    }

    /** @test regex with function call */
    public function testBuildRegAuto(){
        $br = new \Breg();
        $br->handle('everything',function(){return '(.+)';});
        $reg = <<<REGEX
            /a  \    
                ::everything() # everything in between
            g/ # umm, the alphabet ends on z, actually

        REGEX;
        $parsed = $br->parse($reg);

        $this->compare(
            '/a  \ (.+)g/',
            $parsed
        );
    }

    /**
     * @test parsing regex & then filling in the function manually
     */
    public function testBuildRegManual(){
        $parser = new \Breg\Parser();

        $reg = <<<REGEX
            /a  \    
                ::everything() # everything in between
            g/ # umm, the alphabet ends on z, actually

        REGEX;
        $parsed = $parser->parse($reg);

        //this would normally use a callback, but this is a simple test
        $replacement = '(.+)'; 
        $clean = $parsed['clean_reg'];
        $clean = str_replace($parsed['functions'][0]['definition'], $replacement, $clean);

        $this->compare(
            '/a  \ (.+)g/',
            $clean
        );
    }

    /**
     * @test function is parsed out
     */
    public function testParseFunctions(){
        $br = new \Breg\Parser();
        $reg = <<<REGEX
            /a  \    
                ::everything() # everything in between
            g/ # umm, the alphabet ends on z, actually

        REGEX;
        $target = '/a  \ ::everything()g/';
        $parsed = $br->parse($reg);

        $this->compare(
            ['source_reg'=>$reg,
            'functions'=>[
                [   'definition'=>'::everything()',
                    'name'=>'everything',
                    'args'=>[],
                    'argString'=>'',
                ]
            ],
            'clean_reg'=>$target,
            ],
            $parsed
        );
    }

    /**
     *
     * @test backslash at end of line adds `\<space>` to the regex (and preserves whitespace before the backslash)
     */
    public function testParseEscapedEndOfLine(){
        $br = new \Breg\Parser();
        $reg = <<<REGEX
            /a  \    
                (.+) # everything in between
            g/ # umm, the alphabet ends on z, actually

        REGEX;
        $target = '/a  \ (.+)g/';
        $parsed = $br->parse($reg);
        print_r($parsed);

        $this->compare(
            ['source_reg'=>$reg,
            'functions'=>[],
            'clean_reg'=>$target,
            ],
            $parsed
        );
    }

    /** @test comments in regex */
    public function testParseComments(){
        $br = new \Breg\Parser();
        $reg = <<<REGEX
            /a # first letter of the alphabet
                (.+) # everything in between
            g/ # umm, the alphabet ends on z, actually

        REGEX;
        $target = '/a(.+)g/';
        $parsed = $br->parse($reg);
        print_r($parsed);

        $this->compare(
            ['source_reg'=>$reg,
            'functions'=>[],
            'clean_reg'=>$target,
            ],
            $parsed
        );
    }

    /** @test multi-line regex */
    public function testParseMultiLine(){
        $br = new \Breg\Parser();
        $reg = <<<REGEX
            /a
                (.+)
            g/

        REGEX;
        $target = '/a(.+)g/';
        $parsed = $br->parse($reg);
        print_r($parsed);

        $this->compare(
            ['source_reg'=>$reg,
            'functions'=>[],
            'clean_reg'=>$target,
            ],
            $parsed
        );
    }

    /**
     * @test regular regex
     */
    public function testParseSimple(){
        $br = new \Breg\Parser();
        $reg = '/a(.+)g/';
        $parsed = $br->parse($reg);
        print_r($parsed);

        $this->compare(
            ['source_reg'=>$reg,
            'functions'=>[],
            'clean_reg'=>$reg,
            ],
            $parsed
        );
    }
}
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# Php Cli Framework  
A (hopefully) simple framework for running cli apps. It is not very feature rich. (no automatic help menus and not really any built-in cli functions)  
  
## Install  
```bash  
composer require taeluf/cli v0.1.x-dev   
```  
or in your `composer.json`  
```json  
{"require":{ "taeluf/cli": "v0.1.x-dev"}}  
```  
  
  
## Get Started  
Use the built-in cli to generate a cli starter script for you, then edit it to fit your needs.  
  
```bash  
vendor/bin/tlf-cli setup  
```  
  
## Usage  
Generally, you'll make an executable file with the `#!/usr/bin/env php` shebang at the top, then a `<?php` on the next line, then your script to follow.  
  
Here is a sample we use for testing  
```php  
#!/usr/bin/env php  
<?php  
/**  
 * This file is to be a sample cli setup, like somebody would write if they were implementing this library.  
 *  
 * So let's try to implement 3 cli functions  
 *  
 * proto & proto main  ## print some useless information  
 * proto rand -chars abc -len 20 ## generate a random number  
 * proto evens -from 1 -to 113   
 *        ## get all even numbers in the range  
 *        ## defaults to -from 0 -to 50  
 *  
 */  
  
require(__DIR__.'/../code/Msgs.php');  
require(__DIR__.'/../code/Cli.php');  
  
  
$cli = new \Tlf\Cli();  
// load_json_file fails silently if the file does not exist  
$cli->load_json_file(__DIR__.'/defaults.json');   
$cli->load_inputs(json_decode(file_get_contents(__DIR__.'/user_configs.json'),true));  
$cli->load_stdin();  
  
$cli->load_command('main',  
    function($cli, $args){  
        echo "pointless output";  
    }  
);  
  
$cli->load_command('rand',   
    function($cli, $args){  
  
        $chars = $args['chars'];  
        $len = $args['len'];  
        $random = '';  
        $i = 0;  
        while(++$i<=$len){  
            $random .=   
                $chars[random_int(0,strlen($chars)-1)];  
        }  
  
        echo $random;  
    }, "generate a random number from --chars string of --length int"  
);  
  
$cli->load_command('evens',  
    function($cli, $args){  
        extract($args);  
        $i = $from;  
        do {  
            if ($i%2==0)echo $i."\n";  
        } while ($i++<$to);  
    }, "list even numbers. --from int --to int"  
);  
  
  
  
  
$cli->execute();  
```  
  
## Testing this lib  
I don't use my testing framework, since my testing framework uses this & a circular dependency like that is just a headache.  
  
To test this lib during development run `php test/test.php`  
  
The tests are simple & should stay that way.  
  
## TODO  
- Write better documentation???  
# Development Status

## Feb 3, 2024
Creating v1.0 branch, with better documentation, better API, and CICD releases.

## Nov 28, 2023
See changelog

## December 3, 2021
I think it's basically good to go. More features can always be added, though. I didn't setup most the things listed in the TODO below


## Before December 3, 2021

- `test/proto` is a sample implementation of the library
- `test/Cli.php` is a very simple, early version, feature incomplete implementation of a cli-library
- `test.php` is a sample test file with a few simple tests that are passing

### TODO
- add handling for 'command not found'
- add handling for sub-commands
- add handling for routing parent commands
- scope configs/settings to the command they're relevant to
- add help menus (even if it ONLY lists the commands with no help info)
- add helper functions for:
    - load json file as inputs
    - load php file (which returns an array) as inputs
    - load a class's methods as a set of commands
- Documentation
- polish
#!/usr/bin/env php  
<?php  
/**  
 * This cli is used to setup bin scripts
 *  
 *  @usage vendor/bin/tlf-cli help
 *  @usage vendor/bin/tlf-cli setup
 *  
 */  
  
$own_autloader = dirname(__DIR__).'/vendor/autoload.php'; 
$their_autoloader = dirname(__DIR__, 3).'/autoload.php'; // presuming vendor/taeluf/cli/bin
//$pwd_autoloader = getcwd().'/vendor/autoload.php';
//if (file_exists($pwd_autoloader))require_once($pwd_autoloader); else
if (file_exists($their_autoloader))require_once($their_autoloader);
else if (file_exists($own_autloader))require_once($own_autloader);
else {
    echo "\nautoload file not found.\n";
    return;
}
 
$cli = new \Tlf\Cli();  
// load_json_file fails silently if the file does not exist  
//$cli->load_json_file(__DIR__.'/defaults.json');   
//$cli->load_inputs(json_decode(file_get_contents(__DIR__.'/user_configs.json'),true));  
$cli->load_stdin();  
  
$cli->load_command('main',  
    function($cli, $args){  
        $cli->call_command('help',[]);
    }, 'Show this help menu'  
);  
  
$cli->load_command('setup',   
    function($cli, $args){  
        $script_name = $cli->prompt("Enter script name");
        $file = getcwd().'/bin/'.$script_name;
        $write_file = false;
        if (file_exists($file)){
            $write_file = $cli->ask("Overwrite existing file");
        } else {
            $write_file = $cli->ask("Create script '$file'");
        }

        if ($write_file)file_put_contents($file, file_get_contents(__FILE__));
        else return;

        if ($cli->ask("Make file executable")){
            $current_permissions = fileperms($file);
            $new_permissions = $current_permissions | 0b001001001;
            chmod($file, $new_permissions);
            //echo "File permissions are now"
        }

    }, "Initialize a bin script with Tlf\Cli already setup"  
);  
  
$cli->execute();  
{
    "name": "taeluf/cli",
    "type": "library",
    "license": "MIT",
    "autoload":{
        "classmap":["src"],
        "files":[]
    },
    "bin":["bin/tlf-cli"],

    "require": {

    },

    "require-dev":{
        "taeluf/code-scrawl": "v0.8.x-dev"
    },

    "minimum-stability": "dev"
}
{
    "_readme": [
        "This file locks the dependencies of your project to a known state",
        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
        "This file is @generated automatically"
    ],
    "content-hash": "985eaf682787db416504cb217c6d3f3b",
    "packages": [],
    "packages-dev": [
        {
            "name": "taeluf/better-regex",
            "version": "v0.4.x-dev",
            "source": {
                "type": "git",
                "url": "git@gitlab.com:taeluf/php/better-regex.git",
                "reference": "3ee2ff3482d8903d6977fa1fd97a227f4457dc54"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Fbetter-regex/repository/archive.zip?sha=3ee2ff3482d8903d6977fa1fd97a227f4457dc54",
                "reference": "3ee2ff3482d8903d6977fa1fd97a227f4457dc54",
                "shasum": ""
            },
            "require-dev": {
                "taeluf/code-scrawl": "v0.7.x-dev",
                "taeluf/tester": "v0.3.x-dev"
            },
            "default-branch": true,
            "type": "library",
            "autoload": {
                "classmap": [
                    "code"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "time": "2022-03-28T20:55:32+00:00"
        },
        {
            "name": "taeluf/code-scrawl",
            "version": "v0.8.x-dev",
            "source": {
                "type": "git",
                "url": "git@gitlab.com:taeluf/php/CodeScrawl.git",
                "reference": "53718aea95ebc28535c9420421d7853902a25318"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2FCodeScrawl/repository/archive.zip?sha=53718aea95ebc28535c9420421d7853902a25318",
                "reference": "53718aea95ebc28535c9420421d7853902a25318",
                "shasum": ""
            },
            "require": {
                "taeluf/better-regex": "v0.4.x-dev",
                "taeluf/cli": "v0.1.x-dev",
                "taeluf/lexer": "v0.8.x-dev"
            },
            "require-dev": {
                "taeluf/tester": "v0.3.x-dev"
            },
            "default-branch": true,
            "bin": [
                "bin/scrawl"
            ],
            "type": "library",
            "autoload": {
                "classmap": [
                    "code/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "description": "A documentation generation framework with some built-in extensions for exporting comments and code, and importing into markdown. ",
            "time": "2023-11-21T22:24:48+00:00"
        },
        {
            "name": "taeluf/lexer",
            "version": "v0.8.x-dev",
            "source": {
                "type": "git",
                "url": "git@gitlab.com:taeluf/php/lexer.git",
                "reference": "e478fe21c2a96ca03cd168ec6558b290287c73c5"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Flexer/repository/archive.zip?sha=e478fe21c2a96ca03cd168ec6558b290287c73c5",
                "reference": "e478fe21c2a96ca03cd168ec6558b290287c73c5",
                "shasum": ""
            },
            "require": {
                "taeluf/code-scrawl": "v0.8.x-dev",
                "taeluf/util": "v0.1.x-dev"
            },
            "require-dev": {
                "taeluf/tester": "v0.3.x-dev"
            },
            "default-branch": true,
            "bin": [
                "bin/lex"
            ],
            "type": "library",
            "autoload": {
                "classmap": [
                    "src"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "description": "A declarative lexer seamlessly hooking into php functions, building ASTs for multiple languages.",
            "time": "2023-11-22T03:05:28+00:00"
        },
        {
            "name": "taeluf/util",
            "version": "v0.1.x-dev",
            "source": {
                "type": "git",
                "url": "git@gitlab.com:taeluf/php/php-utilities.git",
                "reference": "8ec08e8b751f7e524fd122c9c24b38aa6ffb60a8"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Fphp-utilities/repository/archive.zip?sha=8ec08e8b751f7e524fd122c9c24b38aa6ffb60a8",
                "reference": "8ec08e8b751f7e524fd122c9c24b38aa6ffb60a8",
                "shasum": ""
            },
            "require-dev": {
                "taeluf/code-scrawl": "v0.8.x-dev",
                "taeluf/phtml": "v0.1.x-dev",
                "taeluf/tester": "v0.3.x-dev"
            },
            "default-branch": true,
            "type": "library",
            "autoload": {
                "classmap": [
                    "code"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "description": "Utility methods",
            "time": "2023-10-19T19:30:32+00:00"
        }
    ],
    "aliases": [],
    "minimum-stability": "dev",
    "stability-flags": {
        "taeluf/code-scrawl": 20
    },
    "prefer-stable": false,
    "prefer-lowest": false,
    "platform": [],
    "platform-dev": [],
    "plugin-api-version": "2.6.0"
}
{
    "dir.docs": "doc",
    "dir.template": "docsrc",
    "dir.code": "src",
    "file.code.ext": "*",
    "file.template.ext": ".src.md",
    "deleteExistingDocs": false,
    "markdown.preserveNewLines": true,
    "markdown.prependGenNotice": true,
    "scrawl.ext": [],
    "autoload": {
        "classmap": []
    },
    "readme.copyFromDocs": true,
    "ext.PhpApiScraper": true,
    "lex": true
}
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# ChangeLog  
  
## Other Notes  
- 2023-11-28: Move dirs: .docsrc, .config, code => docsrc, config, src
- 2023-11-28: Add `$cli->exclude_from_help[] = 'main';` to hide any command from the help menu  
  
## Git Log  
`git log` on Tue Nov 28 09:34:58 PM CST 2023`  
- bc7a5c2  (HEAD -> v0.1) update composer [5 seconds ago]  
- 6595946  (origin/v0.1) add exclude_from_help property to cli class [2 minutes ago]  
- 7933a8a  bugfix minor error with print_table [29 hours ago]  
- ad897a9  add print_table() method, to print similar to how mysql cli does [30 hours ago]  
- 8fee575  add $main_on_command_not_found = false property to allow main to be run when there are arguments. [2 weeks ago]  
- fb127a0  run scrawl [9 weeks ago]  
- c3b4071  hopefully fixed autloader inclusion [9 weeks ago]  
- b962ecf  add tlf-clifor easier setup [9 weeks ago]  
- 3df78ea  add prompt() for string prompts. Added docblocks. Slightly improved ask question formatting [9 weeks ago]  
- 2a39939  add notice method [7 months ago]  
- 0a66b9d  run scrawl [7 months ago]  
- fa09a14  trim each line of a logged message [8 months ago]  
- 73c0682  trim message, then append newline to end [8 months ago]  
- 621931a  add logging method [8 months ago]  
- ab3067f  composer update [12 months ago]  
- 8293092  define argv for php 8.2 compatability [12 months ago]  
- f90037f  add ask() method to cli [1 year, 6 months ago]  
- 9ee3ed8  add help menu [1 year, 6 months ago]  
- 1b5f917  add error() method & msgs trait [1 year, 6 months ago]  
- 04bf8fe  update scrawl, run scrawl [1 year, 7 months ago]  
- eb3ae3d  documentation [1 year, 8 months ago]  
- e08da2c  docs, and add load_json_file() method [1 year, 8 months ago]  
- cd42303  add call_command() method [1 year, 8 months ago]  
- ad54fab  fix: add classmap autoloader to composer.json [2 years ago]  
- afb1b80  notes [2 years ago]  
- 0c3de98  minor changes & I think it works [2 years ago]  
- 7c8b1e8  notes [2 years ago]  
- 734d843  tests passing. add notes [2 years ago]  
- 0307358  init repo [2 years ago]  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# Php Cli Framework  
A (hopefully) simple framework for running cli apps. It is not very feature rich. (no automatic help menus and not really any built-in cli functions)  
  
## Install  
```bash  
composer require taeluf/cli v0.1.x-dev   
```  
or in your `composer.json`  
```json  
{"require":{ "taeluf/cli": "v0.1.x-dev"}}  
```  
  
  
## Get Started  
Use the built-in cli to generate a cli starter script for you, then edit it to fit your needs.  
  
```bash  
vendor/bin/tlf-cli setup  
```  
  
## Usage  
Generally, you'll make an executable file with the `#!/usr/bin/env php` shebang at the top, then a `<?php` on the next line, then your script to follow.  
  
Here is a sample we use for testing  
```php  
#!/usr/bin/env php  
<?php  
/**  
 * This file is to be a sample cli setup, like somebody would write if they were implementing this library.  
 *  
 * So let's try to implement 3 cli functions  
 *  
 * proto & proto main  ## print some useless information  
 * proto rand -chars abc -len 20 ## generate a random number  
 * proto evens -from 1 -to 113   
 *        ## get all even numbers in the range  
 *        ## defaults to -from 0 -to 50  
 *  
 */  
  
require(__DIR__.'/../code/Msgs.php');  
require(__DIR__.'/../code/Cli.php');  
  
  
$cli = new \Tlf\Cli();  
// load_json_file fails silently if the file does not exist  
$cli->load_json_file(__DIR__.'/defaults.json');   
$cli->load_inputs(json_decode(file_get_contents(__DIR__.'/user_configs.json'),true));  
$cli->load_stdin();  
  
$cli->load_command('main',  
    function($cli, $args){  
        echo "pointless output";  
    }  
);  
  
$cli->load_command('rand',   
    function($cli, $args){  
  
        $chars = $args['chars'];  
        $len = $args['len'];  
        $random = '';  
        $i = 0;  
        while(++$i<=$len){  
            $random .=   
                $chars[random_int(0,strlen($chars)-1)];  
        }  
  
        echo $random;  
    }, "generate a random number from --chars string of --length int"  
);  
  
$cli->load_command('evens',  
    function($cli, $args){  
        extract($args);  
        $i = $from;  
        do {  
            if ($i%2==0)echo $i."\n";  
        } while ($i++<$to);  
    }, "list even numbers. --from int --to int"  
);  
  
  
  
  
$cli->execute();  
```  
  
## Testing this lib  
I don't use my testing framework, since my testing framework uses this & a circular dependency like that is just a headache.  
  
To test this lib during development run `php test/test.php`  
  
The tests are simple & should stay that way.  
  
## TODO  
- Write better documentation???  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File code/Cli.php  
  
# class Tlf\Cli  
  
See source code at [/code/Cli.php](/code/Cli.php)  
  
## Constants  
  
## Properties  
- `public bool $main_on_command_not_found = false;` Set true to run main instead of showing an error when the first arg is not a valid command.  
- `public array $exclude_from_help = [];` array<int index, string command_name> Array of commands to exclude from the help menu  
- `public $pwd;` The current working directory  
- `public $command_map = [];` map of command name to callable  
- `public $help_map = [];` command_name=>help_msg  
- `public $command = 'main';` The command being executed  
- `public $args = [];` The args to pass to your command's callable (key=>value array)  
- `public $name;` The name of the command used to execute this (not path)  
- `public string $log_dir;` Directory to write log files to.  
- `public $argv;`   
  
## Methods   
- `public function __construct($pwd = null, $argv  null)`   
- `public function log(string $message, string $log_file = 'tlf-main')` Log $message to disk with a date & timestamp. You must set `$cli->log_dir` to a valid directory.  
  
- `public function load_stdin($stdin=null)` load standard inputs from cli  
- `public function parse_args($stdin_args, $args=[])`   
- `public function load_command(string $command, $callable, string $help_msg='')`   
- `public function load_json_file(string $file)` Load a json settings file, if it exists. Fails silently if it does not exist.  
  
- `public function load_inputs($args)`   
- `public function call_command(string $command, array $args=[])` Execute a command by name  
  
- `public function execute()` Run the cli based on loaded inputs  
- `public function help_menu($cli, $args)`   
- `public function ask(string $msg, $success_func=null,...$args)` Prompt user for y/no answer. Lowercase 'y' is yes. All other answers are no.  
  
- `public function prompt(string $msg)` Prompt user for string input  
  
- `public function print_table(array $rows)` Print an array as a table, just like mysql cli does. all values will be printed. column width will be fixed to the maximum length  
  
  
# ChangeLog

## Other Notes
- 2023-11-28: Move dirs: .docsrc, .config, code => docsrc, config, src
- 2023-11-28: Add `$cli->exclude_from_help[] = 'main';` to hide any command from the help menu

## Git Log
`git log` on @system(date, trim)`
@system(git log --pretty=format:'- %h %d %s [%cr]' --abbrev-commit)
# Php Cli Framework
A (hopefully) simple framework for running cli apps. It is not very feature rich. (no automatic help menus and not really any built-in cli functions)

## Install
@template(php/composer_install, taeluf/cli)

## Get Started
Use the built-in cli to generate a cli starter script for you, then edit it to fit your needs.

```bash
vendor/bin/tlf-cli setup
```

## Usage
Generally, you'll make an executable file with the `#!/usr/bin/env php` shebang at the top, then a `<?php` on the next line, then your script to follow.

Here is a sample we use for testing
```php
@file(test/proto)
```

## Testing this lib
I don't use my testing framework, since my testing framework uses this & a circular dependency like that is just a headache.

To test this lib during development run `php test/test.php`

The tests are simple & should stay that way.

## TODO
- Write better documentation???
<?php

namespace Tlf;

class Cli {

    use Cli\Msgs;

    /**
     * Set true to run main instead of showing an error when the first arg is not a valid command.
     */
    public bool $main_on_command_not_found = false;

    /**
     * array<int index, string command_name> Array of commands to exclude from the help menu
     * @usage `$cli->exclude_from_help[] = 'main';`
     */
    public array $exclude_from_help = [];

    /**
     * The current working directory
     */
    public $pwd;

    /** map of command name to callable
     */
    public $command_map = [];

    /**
     * command_name=>help_msg
     */
    public $help_map = [];

    /**
     * the array of commands (for environments that have sub-commands)
     */
    // public $commands;
    
    /**
     * The command being executed
     */
    public $command = 'main';
    /**
     * The args to pass to your command's callable (key=>value array)
     */
    public $args = [];
    /**
     * The name of the command used to execute this (not path)
     */
    public $name;

    /**
     * Directory to write log files to.
     */
    public string $log_dir;

    /**
     * 
     */
    public $argv;

    public function __construct($pwd = null, $argv = null){
        $this->pwd = $pwd ?? $_SERVER['PWD'];
        $this->argv = $argv ?? $_SERVER['argv'];
        $this->load_command('help', [$this, 'help_menu'], 'show this help menu');
        $this->help_map['main'] = 'When the script is called with no arguments';
        $this->name = basename($this->argv[0]);
    }

    /**
     * Log $message to disk with a date & timestamp. You must set `$cli->log_dir` to a valid directory.
     *
     * @param $message a message to log. New lines are padded, and it is prefixed with a date & time.
     * @param $log_file the name of a file to log to inside `$cli->log_dir`. The file does not need to exist prior to logging.
     *
     * @return void does not return anything
     */
    public function log(string $message, string $log_file = 'tlf-main'){
        if (!isset($this->log_dir)){
            echo "\nERROR: Cannot log. log_dir not set.\n";
            return;
        }
        $fh = fopen($this->log_dir.'/'.$log_file,'a');
        if ($fh===false){
            echo "\nERROR: Cannot log to file $log_file. fopen() failed.\n";
            return;
        }
        $date = new \DateTime();
        $date_string = $date->format('Y-m-d H:i:s T');

        $parts = explode("\n", trim($message));
        $parts = array_map('trim', $parts);
        $padded_message = implode("\n    ", $parts);

        $write_message = "[$date_string]: $padded_message\n";

        fwrite($fh, $write_message);

        fclose($fh);
    }

    /**
     * load standard inputs from cli
     * @param $stdin (optional) array of arguments like `['filename', 'subcommand', '-option', 'option_value', '--flag', 'etc']`
     * @default $stdin to $_SERVER['argv']
     */
    public function load_stdin($stdin=null){
        $stdin = $stdin ?? $this->argv;
        $this->script = basename($stdin[0]);
        if (!isset($stdin[1])||substr($stdin[1],0,1)=='-'){
            $this->command = $this->command;
            $slice = 1;
        } else {
            $this->command = $stdin[1];
            $slice = 2;
        }
        $args = $this->parse_args(array_slice($stdin,$slice), $this->args);
        $this->args = array_merge($this->args, $args);
    }

    public function parse_args($stdin_args, $args=[]){
        $last_key = null;
        foreach ($stdin_args as $arg){
            if ($arg[0]=='-'){
                if ($arg[1]=='-'){
                    $last_key= substr($arg,2);
                    $args[$last_key] = true;
                    continue;
                }
                $last_key = substr($arg,1);
                if (!isset($args[$last_key])){
                    $args[$last_key] = null;
                } 
            } else if ($last_key==null){
                $args['--'][] = $arg;
            } else {
                if ($arg==='true')$arg = true;
                else if ($arg === 'false')$arg = false;
                if (is_array($args[$last_key])){
                    $args[$last_key][] = $arg;
                } else {
                    $args[$last_key] = $arg;
                }
                $last_key = null;
            }
        }

        return $args;
    }

    /**
     * @param $command the command 
     * @param $callable Ex: `function(\Tlf\Cli $cli, array $args){}`
     * @param $help_msg short description for help menu
     */
    public function load_command(string $command, $callable, string $help_msg=''){
        $this->command_map[$command] = $callable;
        if ($help_msg!='')$this->help_map[$command] = $help_msg;
    }

    /**
     * Load a json settings file, if it exists. Fails silently if it does not exist.
     *
     * @param string $file
     * @return array of data from the file, or false on failure
     */
    public function load_json_file(string $file){
        if (!file_exists($file))return false;
        $content = file_get_contents($file);
        $settings = json_decode($content, true);
        $this->load_inputs($settings);
        return $settings;
    }
    public function load_inputs($args){
        $this->args = array_merge($this->args, $args);
    }

    /**
     *
     * Execute a command by name
     *
     * @param $command the name of the command to execute
     * @param $args args to execute
     */
    public function call_command(string $command, array $args=[]){
        if (!isset($this->command_map[$command])){
            if ($this->main_on_command_not_found){
                if (!isset($args['--']))$args['--'] = [];
                
                array_unshift($args['--'], $command);
                $command = 'main';
            } else {
                echo 'Command "'.$command.'" does not exist.'."\n";
                echo "Try \"$command help \".";
                return;
            }
        }
        $call = $this->command_map[$command];
        $ret = $call($this, $args);
        echo "\n";
        return $ret;
    }

    /**
     * Run the cli based on loaded inputs
     */
    public function execute(){
        return $this->call_command($this->command, $this->args);
    }

    public function help_menu($cli, $args){
        foreach ($this->command_map as $command => $c){
            // if ($command=='main')continue;
            if (array_search($command, $this->exclude_from_help) === false){
                echo "\n    $command - ". ($this->help_map[$command]??'');
            }
        }
        echo "\n";
    }

    /**
     * Prompt user for y/no answer. Lowercase 'y' is yes. All other answers are no.
     *
     * @param $msg string message to display (newline added before, question mark after)
     * @param $success_func (optional) a callback that receives ...$args if user answers 'y'.
     * @param ...$args, args to pass to the success function
     *
     * @return true if user answers 'y', false otherwsie.
     */
    public function ask(string $msg, $success_func=null,...$args){
        $answer = readline("\n".$msg."(y/n)? ");
        if (strtolower($answer)!='y')return false;
        if ($success_func==null)return true;
        $success_func(...$args);
        return true;
    }

    /**
     * Prompt user for string input
     *
     * @param $msg string message to display (newline added before, colon after)
     *
     * @return user's input, trimmed.
     */
    public function prompt(string $msg){
        $answer = readline("\n".$msg.": ");
        return trim($answer);
    }
    /**
     * Print an array as a table, just like mysql cli does. all values will be printed. column width will be fixed to the maximum length
     *
     * @param $rows array<string key, mixed value> keys will be printed as headers. 
     */
    public function print_table(array $rows){
        $stats = [];
        foreach ($rows as $rownum=>$row){
            foreach ($row as $key=>$value){
                $cur_len = $stats[$key] ?? 0;
                if (($new_len = strlen($value)) > $cur_len)$stats[$key] = $new_len;
                if (($keylen = strlen($key)) > $new_len) $stats[$key] = $keylen;
            }
        }

        $total_len = 0;
        $lines = ["","",""];
        $last_line = '';
        foreach ($stats as $key=>$len){
            $pluspart = "+". str_repeat('-',$len + 2);
            $lines[0] .= $pluspart;
            $lines[1] .= "| $key ";
            $lines[2] .= $pluspart;
            $last_line .= $pluspart;
            if (($diff = ($len - strlen($key) ) ) >0)$lines[1] .= str_repeat(' ',$diff);
        }

        $lines[0] .= '+';
        $lines[1] .= '|';
        $lines[2] .= '+';

        foreach ($lines as $line){
            echo "\n".$line;
        }

        foreach ($rows as $row){
            echo "\n";
            foreach ($row as $key=>$value){
                $value = str_replace("\n", "\\n", $value);
                echo "| ".$value .' ';
                $maxlen = $stats[$key] ?? 0;
                $thislen = strlen($value);
                if (($diff = ($maxlen - $thislen)) > 0) echo str_repeat(" ", $diff);
            }
            echo "|";
        }

        echo "\n{$last_line}+";
        echo "\n";


// EXAMPLE ... except we're not right-justifying nulls & numbers
//+----+---------------+-------------+--------------+---------------------+---------+--------------------+
//| id | title         | description | slug         | created_at          | status  | related_article_id |
//+----+---------------+-------------+--------------+---------------------+---------+--------------------+
//|  1 | One           | Desc 1      | one          | 2023-11-27 15:31:01 | public  |               NULL |
//|  2 | Two           | Desc 2      | two          | 2023-11-27 15:31:01 | public  |               NULL |
//|  3 | Three         | Desc 3      | three        | 2023-11-27 15:31:01 | public  |                  1 |
//|  4 | Four, Private | Desc 4      | four-private | 2023-11-27 15:31:01 | private |                  1 |
//+----+---------------+-------------+--------------+---------------------+---------+--------------------+

    }
}
<?php

namespace Tlf\Cli;

trait Msgs {

    /** 
     * print an error to the cli 
     *
     * @param $msg the error to highlight in red
     * @param $nobold optional message to print in default terminal color
     */
    public function error(string $msg, string $nobold=''){
        echo "\n\033[0;31m$msg\033[0m";
        if ($nobold!='')echo ': '.$nobold;
    }

    /**
     * Print a notice to the cli
     * @param $title the error to highlight in red
     * @param $message optional message to print in default terminal color
     */
    public function notice(string $title, string $message){
        echo "\n\033[0;31m$title\033[0m"
            .": ".$message;
    }
}
{

    "chars":"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+-=",
    "len": 20,
    "from": 0,
    "to": 20
    
}
#!/usr/bin/env php
<?php
/**
 * This file is to be a sample cli setup, like somebody would write if they were implementing this library.
 *
 * So let's try to implement 3 cli functions
 *
 * proto & proto main  ## print some useless information
 * proto rand -chars abc -len 20 ## generate a random number
 * proto evens -from 1 -to 113 
 *        ## get all even numbers in the range
 *        ## defaults to -from 0 -to 50
 *
 */

require(__DIR__.'/../src/Msgs.php');
require(__DIR__.'/../src/Cli.php');


$cli = new \Tlf\Cli();
// load_json_file fails silently if the file does not exist
$cli->load_json_file(__DIR__.'/defaults.json'); 
$cli->load_inputs(json_decode(file_get_contents(__DIR__.'/user_configs.json'),true));
$cli->load_stdin();

$cli->load_command('main',
    function($cli, $args){
        echo "pointless output";
    }
);

$cli->load_command('rand', 
    function($cli, $args){

        $chars = $args['chars'];
        $len = $args['len'];
        $random = '';
        $i = 0;
        while(++$i<=$len){
            $random .= 
                $chars[random_int(0,strlen($chars)-1)];
        }

        echo $random;
    }, "generate a random number from --chars string of --length int"
);

$cli->load_command('evens',
    function($cli, $args){
        extract($args);
        $i = $from;
        do {
            if ($i%2==0)echo $i."\n";
        } while ($i++<$to);
    }, "list even numbers. --from int --to int"
);




$cli->execute();
<?php
/**
 * To test this library execute `php test/test.php` from the root of this repo.
 * You should see 4 tests passing
 *
 */

$command = __DIR__.'/';

$tests = [
    'proto'=>'pointless output',
    'proto main'=>'pointless output',
    'proto rand -chars a -len 1'=> 'a',
    'proto evens -from 1 -to 5'=> "2\n4",
];

foreach ($tests as $c=>$t){

    ob_start();
    system("${command}${c}");
    $output = trim(ob_get_clean());
    if ($output==$t){
        echo "\n+pass: $c";
    } else {
        echo "\n-fail: $c";
        echo"\n    -$output-";
    }
}

echo "\n";
{

    "chars":"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+-=",
    "len": "10"
    

}
# Devlog
This contains old notes i no longer need


## March 10, 2022
I didn't work on re-adding empty bodies to method asts, so a lot of the directive tests are still failing.

I want to capture the entire method body as a string. I also want to capture every expression in a list of expressions (whether in a method or just in a script). I'm concerned that manually catching each expression will be overly complex & patchwork, having a handler on semicolons, another one on parenthesis close (for if statements, foreach, etc), another on block open & block close & probably others i'm not thinking of (comments, docblocks) ...

I'm concerned that adding the body by hooking on each of the individual things will add unnecessary complication. I tried adding a hook for everytime $token->next() is called, then ended up with a LOT of repeated characters, bc many of the directives rewind. 

I might be able to find a generic way to address this. By somehow manually keeping track of the position in the string & probably some custom code in the rewind section. I'm not exactly sure. I might be able to dump all that code into token, so the lexer doesn't have to "think" about it. Then have a hook for "new_char_added" or something that ONLY gets called the first time a character is added to the token's buffer.

Something like this would allow me to just capture every character while the `method_body` ast is the head & then have a string body. I do like this approach, to some extent.

However, I also want to (eventually) have a list (array) of expressions. So if I had something like:
```php
function abc(){
    $var = true;
    $abc = new \Whatever();
    if ($var){
        echo "cats";
    }
    return false;
}
```
Then I would have 4 expressions as direct children of the method body. The `if ($var){echo "cats";}` block would be one expression that also contains expressions. (well it contains one expression, 'echo cats', but still)

I'm not sure how to manage all that. And then I think a comment would also be in this expressions list. Doing this would require me to hook on each individual thing ... but in these cases, the specific functionality is actually needed. There will need to be custom logic to handle blocks & whatnot, i guess ...

And if I'm going to implement that, why not use it for the method body string as well? Maybe because they have different purposes. I have a tendency to ignore whitespace. I don't think I have any special handling for whitespace. I suppose I could add it. But I definitely don't want whitespace in the expressions. And docblocks aren't expressions. the docblocks would be attached to the expression, not BE an expression in the array ...

So there is a distinct need for both approaches, i guess? I could merge them, but the two approaches solve two different (though related) feature requests.

Okay. So, this is going to require some though & some experimentation. And definitely a lot of patience. It'll be hard not to break things in this process.

Okay, thanks Reed! Hope you come back to this feeling good :)


### Updating Directive tests to be passing
Method.ReturnReference
Method.WithNestedBlock.2
Method.WithNestedBlock
Method.WithReturnType
Method.TwoArgs
Method.OneArg
Method.Simple.OneArg
Method.Static
Method.Simple
//Class.Implements
//Class.Extends
//Class.Abstract
//Class.OpenInFile
//Class.OpenInNamespace
Integration.Class.Methods.WithNestedBlock
Integration.Class.Final.Method
Integration.Class.Bug.ModifiersMethods
Integration.Class.Method.2
Integration.Trait.Method
Integration.Class.Method

## March 5, 2022
Majorly cleaned up Test\PhpGrammar. Big issue: Comment counts are all wrong because they're not being extracted from the body. docblock has the same issue.
These are also awful unit tests. These are fine for debugging & then making sure i don't later screw things up, but they're awful unit tests & directive tests are GOOD unit tests ... i need to get the directive tests passing. I think they're all failing bc of the body issue, but it might be other stuff too. idk

## March 3, 2022
I haven't resolved the feb 11 issue
I'm working on cleaning up tests

### TODO
- fix the method body issue (see Grammars/PhpGrammar test, even though that test should be in debug)
    - maybe add unit tests for the ast classes??
- separate the `lex` dir into ones just for counts, then another for debugging, then probably another for validating full trees
- move `input/php/tree/` to the output dir (in the code)
- clean up the php grammar parse_file function
- work through the failing php directive tests & get them passing ()
- create a passing bash grammar test
- create a wrapper class or convenience functions that make it easier to just run the lexer on a file or string for a given language
- delete the old BashGrammar, JsonGrammar, defunct Docblock grammar,
- document directives
- idk what else! :)


## Feb 11, 2022 ISSUE
- `phptest -test MethodBodyIsString` ... the method body is showin gas an array when it should be a string ... i messed around with it a bit & at times it was returning an ast object instead of an array ... idk what the problem is ... ALSO, the third method has a body nested in the body ... which makes no sense ... so this is a whole heck of a thing, it seems.
    - i was accidentally running the test with cache enabled so ... whoops
    - i decided to just remove body because it wasn't working anyway ...
    - so i commented out a line in Operations that set 'body' on the ast
    - this needs to be investigated

## Jan 26, 2022
- the PhpGrammar tests have a bunch of commented out lines ... this needs refactored so I can properly run these tests with confidence rather than require manual review
- I need to write unit tests for the `string_backslash` issue (and maybe others that I've solved, with operations & such)

## Jan 25, 2022
- work on the php grammar ... handles functions (not just methods), and fixes bugs with catching 'class' and 'function' keywords in the wrong context

## Next
- the `string_backslash` directive is supposed to handle backslash escaped things inside a string ... well it catches the first one, so a string like `"iam \" a string \" with two quote marks"` will fail on the second `\"`.  I tried to do a work-around in php, but that was a mess ... I don't think it's worth refactoring the internals ... I need to make a unit test just to test strings that contain backslash-escaped quotation marks. i THINK it's because of the order ... after the first time string_backslash is hit, the list of unstarted directives is changed (it getting stopped appends it, rather than putting it back in its original spot) ... that's 100% it


... i found a workaround for the string backslash ... added its own handler ...

... phtml classes are all passing the methdos count ...

I need to improve the generic test & its output ... its all just takes up so much space for no good reason


## Known Issues (PhpGrammar)
- when there IS a namespace in a file, `class` is nested under neath it. When there is NO namespace in the file, `namespace=''` and `class=[]` is adjacent, ... for now, i just have a workaround in the test code
- the string backslash issue ... i'd rather not have it be a workaround in php ... idk how to fix it and its probably not a priority

## Welcome back (Jan 24, 2022)
- I can't parse a method with a body
- See `run/Documentation.php` ... There is a test for PhpGrammarNew that shows very nicely how to run the lexer.
- `test/output/PhpFeatures.md` contains a list of directive unit tests (their description, input code, and whether they passed their tests). Looking at this is a good way to see what language features have been implemented
- `PhpGrammarNew`'s test PhpGrammarNew_SampleClass is failing and i don't know why (it was failing before i moved files around, but i need to fix that too)

Things I want to do:
- Restructure the test directory
- delete old code that I don't need
- disable tests that I don't care about (old grammars and such)
- turn `PhpGrammarNew` into `PhpGrammar` & either delete the old one or rename the old one to `PhpGrammarOld`
- structure the `code/PhpNew` directory ... the `code/Lexer` dir ... maybe just review all the files & try to structure things better ... `code/` should have `code/Grammars/`...
- genericize the running & testing of lexing full php files ... the idea is ... i WILL run into bugs while I'm working on other software. WHEN i run into a bug, i could just copy+paste the entire source code of the file into this genericized test suite & make it easy to view the ast output & make it easy to change what's expected
- clean up `PhpGrammarNew` ?? I think delete the old code I don't need ... maybe write other tests? idk



## PhpGrammarNew status 

### Current
- Working on `phptest -test PhpGrammarNew_SampleClass`. Manually comparing `test/php-new/SampleClass.tree2.php` to `test/php-new/SampleClass.php`. 
    - The class is not getting a docblock. Maybe I need to write a little test for this. 

### Next Major steps
- Test that docblocks work on: (I just kind of assume they do...)
    - consts
    - properties
    - methods
    - classes
    - traits
    - DONE `use TraitName;`
    - `namespace NS;`

### TODO (low priority)
- Consider always setting namespace & (or at least) fqn on `class`... 


## Latest
- Handling nowdoc & heredoc `<<<STR` && `<<<'STR'` (somewhat lazily)
- Rewrote strings directives (phpgrammar)
- Fix bug (docblockgrammar): Empty docblocks led to infinite loop
- Fixed Bug (phpgrammar): Nested blocks inside methods were not being caught, so methods were ending when nested blocks closed
- Fixed Bug (phpgrammar): `<?php class Abc extends Alphabet{}` Fails to get `Alphabet`. Write a test for & fix it.
- Move `cmdMethods` and the method map into their own trait
- add `:+directive_name` as alternate to `:_blank-directive_name`
- fix `stop` instruction, so it now ONLY stops directives if they're started in the top stack
- add `inherit`/`directive.inherit` instruction
- add `then.pop` instruction
- Write Documentation tests & an Examples doc file & cleanup README
- add `namespace.docblock` to `file` ast & update tests
- Added modifier to `const` ast
- Docblock grammar integrated into phpgrammar
- Docblock Grammar passing 
- Fixed: Some lines would show `*` after docblock grammar was done parsing.
- `then` instruction now allows you to specify grammar like `then docblock:/*`
- Clean up DocBlockGrammar stuff
- Wrote a docblock grammar in almost pure php
- Add Tester class to simplify testing of many directives
- Minor improvements to intuitiveness of `lex` api 
- remove inspect-loop param from lexer
- Refactor Command Processing
- Refactor instruction execution
    - Move the switch into its entire own function & provide more clarity about passed in args
    - Improve naming scheme by namespacing all commands. There are also namespace free defaults
    - Create separate methods to replace complex `case`s (for readability & maintainability)
- Create command parsing function (`executeMethodString()`)that handles things like `_token:buffer` or `_lexer:unsetPrevious docblock`
- Disable bash grammar tests
- Reorganize lexer's internals into traits & remove old functions
- cleaned up PhpGrammar test.
- Refactored names & namespaces of php grammar & directives
- Deleted old, useless php grammars
- Sorted PhpGrammar directives into traits
- removed unneeded functions for phpgrammarnew & separated directives into a trait
- Got PhpGrammarNew working for SampleClass.php
- Got v0.6 working

## Issue 1, Scrawl2
```
// ////////
// // debugging
// ////////
// //
//
// // issue: addExtension's declaration is showing
//     // foreach ($extensions as $ext)
//     //     ---multiple blank lines---
//     // public function addExtension(object $ext)
// // issue recurs as long as the block `{}` or unterminated statement `foreach()` remains
// // if i terminate the block `{};` the issue goes away
// // foreach block open is loop 501
//
// // solution: the expression needed reset on block end, so i `lexer->setPrevious('xpn', new Ast())`
// // side effect: crashed Phad test due to `implode($xpn->declaration)` failing due to declaration NOT being an array
//
// $stop_loop = -1;
// $ast = $this->get_ast('code-scrawl/Scrawl2-partial.php',false, $stop_loop);
// $methods = $this->get_ast_methods($ast);
// print_r($methods);
//
// // print_r($ast);
//
// return;
// $this->run_parse_file('MethodParseErrors',true);
```
MIT License

Copyright (c) 2021 Taeluf / php

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# Lexer  
Parse code and other text into structured trees.  
  
The Lexer loops over the characters in a string, and processes them through Grammars to generate Asymmetrical Syntax Trees (AST) - Basically just a multi-dimensional array that describes the code.   
  
## Documentation  
- Installation & Getting Started are below  
- [Create a Parser](docs/CreateParser.md) - Create a language parser that builds an AST, or modify an existing parser.  
<!--   
- [Parse Code / Create AST](docs/ParseCode.md) - Parse your code into an AST using an existing language parser.  
- [Use ASTs](docs/UseAST.md) - Use an AST to retrieve classes, methods, properties, and more.  
-->  
  
### Other/Old Documentation  
- Extend Lexer - Create your own grammars to support new languages  
    - [Getting Started](/docs/GettingStarted.md) - Write a grammar class, create directives, and test your grammar.  
    - [Tips & Overview](/docs/Tips.md) - How To tips & troubleshooting  
    - [Directive Commands](/docs/DirectiveCommands.md) - Commands you can use in your directives.  
    - [Extra Examples](/docs/Examples.md)   
    - [Testing your grammar](/docs/Testing.md)  
- [docs/api/code/](/docs/api/code/) - Generated api documentation   
- [Architecture](/docs/Architecture.md)  
- Development - Further develop this library  
    - [Development Status & Notes](/Status.md) - The current state of development, and common development tips.  
    - [Php Grammar](/docs/Development/PhpGrammar.md) - How to further develop the PHP Grammar.  
    - [Changelog](/docs/Changelog.md)  
- Defunct documentation  
    - [Grammar Examples](/docs/GrammarExample.md)  
    - [docs/OldReadme1.md](/docs/OldReadme1.md) - An old README that might have useful information.  
  
## Supported Languages  
Additional language support can be added through new grammars. See [docs/Extend.md](/docs/Extend.md).  
- Docblocks: Parses standard docblocks (`/** */`) for description and `@param`. Somewhat language independent.  
- Php: Very Good (php 7.4 - 8.2)  
- Bash: Broken. There was an old grammar which would parse functions and doclbocks (using `##\n#`), but it has not been returned to functionality with the current lexer.  
  
## Install  
```bash  
composer require taeluf/lexer v0.8.x-dev   
```  
or in your `composer.json`  
```json  
{"require":{ "taeluf/lexer": "v0.8.x-dev"}}  
```  
  
  
  
## Parse with CLI  
This prints an Asymmetrical Syntax Tree (AST) as JSON.  
```bash  
# only file path is required  
bin/lex file rel/path/to/file.php -nocache -debug -stop_at -1  
```  
  
## Basic Usage  
  
For built-in grammars, it is easiest to use the helper class.   
  
```php  
<?php  
$file = '/path/to/file/';  
$helper = new \Tlf\Lexer\Helper();  
$lexer = $helper->get_lexer_for_file($full_path); // \Tlf\Lexer  
  
# These are the default settings  
$lexer->useCache = true; // set false to disable caching  
$lexer->debug = false; // set true to show debug messages  
$lexer->stop_loop = -1; // set to a positive int to stop processing & print current lexer status (for debugging)  
  
$ast = $lexer->lexFile($full_path); // \Tlf\Lexer\Ast  
  
print_r($ast->getTree()); // array  
```  
  
## Example Tree  
Grammars determine tree structure. This is a php file in this repo. See [code/Ast/StringAst.php](/code/Ast/StringAst.php). This example only has one method and no properties. From the root of this repo, run `bin/lex file code/Lexer.php` for an example of a larger class.  
```json  
{  
    "type": "file",  
    "ext": "php",  
    "name": "StringAst",  
    "path": "\/path-to-downloads-dir\/Lexer\/code\/Ast\/StringAst.php",  
    "namespace": {  
        "type": "namespace",  
        "name": "Tlf\\Lexer",  
        "declaration": "namespace Tlf\\Lexer;",  
        "class": [  
            {  
                "type": "class",  
                "namespace": "Tlf\\Lexer",  
                "fqn": "Tlf\\Lexer\\StringAst",  
                "name": "StringAst",  
                "extends": "Ast",  
                "declaration": "class StringAst extends Ast",  
                "methods": [  
                    {  
                        "type": "method",  
                        "args": [  
                            {  
                                "type": "arg",  
                                "name": "sourceTree",  
                                "value": "null",  
                                "declaration": "$sourceTree = null"  
                            }  
                        ],  
                        "modifiers": [  
                            "public"  
                        ],  
                        "name": "getTree",  
                        "body": "return $this->get('value');",  
                        "declaration": "public function getTree($sourceTree = null)"  
                    }  
                ]  
            }  
        ]  
    }  
}  
```  
  
A php class property looks like:  
```json  
{  
    "type": "property",  
    "modifiers": [  
        "public",  
        "int"  
    ],  
    "docblock": {  
        "type": "docblock",  
        "description": "The loop we're on. 0 means not started. 1 means we're executing the first loop. 2 means 2nd loop, etc."  
    },  
    "name": "loop_count",  
    "value": "0",  
    "declaration": "public int $loop_count = 0;"  
}  
```  
  
  
  
# Lexer
Convert code or other text into a structured tree (multi-dimensional array).

In This File:
- create a grammar with directives & handler functions
- test a grammar
- a complex directive that builds an AST without php
- How to write an extension

## Usage, Parsing code into an AST
To parse code
- instantiate the lexer
- instantiate the grammar(s) to use
- setup the starting directive(s)
- setup the root AST.
- lex it
Example:
```php
@import(Test.Doc.LexPhpString)
```

## Extending
To Extend the Lexer and process unsupported files, or to process files differently:
- Create a Grammar class, extending from `\Tlf\Lexer\Grammar`
- Write directive tests, starting with very simple ones
- Write directives for processing
- Write supporting functions that support your directives

### Create a Grammar

```php
<?php

/** this is a partial copy of the bash grammar */
class MyGrammar extends \Tlf\Lexer\Grammar {

    protected $my_directives = [
        'root'=>[
            'is'=>[
                // ':comment',
                ':docblock',
                ':function',
            ],
        ],

        'docblock'=>[
            'start'=>[
                'match'=>'##',
            ],
            'stop'=>[
                'match'=>'/(^\s*[^\#])/m',
                'rewind 2',
                'this:handleDocblockEnd',
                'buffer.clear',
                // 'forward 2'
            ]
        ],

        'function'=>[
            'start'=>[
                'match'=>'/(?:function\s+)?([a-zA-Z\_0-9]*)(?:(?:\s*\(\))|\s+)\{/',
                'this:handleFunction',
                'stop',
                'buffer.clear',
            ]
        ],
        // an additional 'comment' directive is below
    ];

    public function getNamespace(){return 'mygrammar';}

    public function __construct(){
        $this->directives = array_merge(
            $this->main_directives,
            // $this->_other_directives,
        );
    }

    public function onLexerStart($lexer,$file,$token){

    }

    public function handleDocblockEnd($lexer, $ast, $token, $directive){
        $block = $token->buffer();
        $clean_input = preg_replace('/^\s*#+/m','',$block);
        $db_grammar = new \Tlf\Lexer\DocblockGrammar();
        $ast = $db_grammar->buildAstWithAttributes(explode("\n",$clean_input));
        $lexer->setPrevious('docblock', $ast);
    }

    public function handleFunction($lexer, $ast, $token, $directive){
        // $func_name = $token->match(1);
        $func = new \Tlf\Lexer\Ast('function');
        $func->name = $token->match(1);
        $func->docblock = $lexer->previous('docblock');
        $lexer->getHead()->add('function', $func);
    }
}
```

### Test a Grammar
```php
<?php

class MyGrammarTest extends extends \Tlf\Lexer\Test\Tester {

    protected $my_tests = [
        'Comments'=>[
            // the 'comment' directive is below and can be added to the `MyGrammar` that is above
            'start'=>'comment', // t
            'input'=>"var=\"abc\"\n#I am a comment\nvarb=\"def\"",
            'expect'=>[
                "comments"=>[
                    0=>[
                        'type'=>'comment',
                        'src'=>'#I am a comment',
                        'description'=> "I am a comment",
                    ]
                ],
            ],
        ],
    ];

    public function testBashDirectives(){
        $myGrammar = new \MyGrammar();
        $grammars = [
            $myGrammar
        ];
        // $docGram->buildDirectives();

        $this->runDirectiveTests($grammars, $this->my_tests);
    }

}
```

### A more complex directive
```php
<?php
// you would put this in your directives class
$directives = [
    'comment'=>[
        'start'=>[
            'match'=>'/#[^\#]/',
            'rewind 2',
            'buffer.clear',
            'forward 1',
            // you can create & modify ASTs all in the directive code, without php
            'ast.new'=>[
                '_addto'=>'comments',
                '_type'=>'comment',
                'src'=>'_token:buffer',
            ],
            'buffer.clear //again',
        ],

        // `match` gets called for each char after `start`
        'match'=>[
            'match'=>'/@[a-zA-Z0-9]/', // match an @attribute
            'rewind 1',
            'ast.append src',
            'rewind 1 // again',
            'ast.append description',
            'forward 2',
            'buffer.clear',
            'then :+'=>[ // the :+ means that we're defining a new directive rather than referencing an existing one
                'start'=>[
                    //just immediately start
                    'match'=>'',
                    'rewind 1',
                ],
                'stop'=>[
                    // i honestly don't know why I have this here.
                    'match'=>'/(\\r|\\n)/',
                    'rewind 1',
                    'ast.append src',
                    'buffer.clear',
                ]
            ],

        ],
        'stop'=>[
            'match'=>'/(\\r|\\n)/',
            'rewind'=>1,
            'ast.append src',
            'ast.append description',
            'forward'=>1,
            'buffer.clear',
        ],
    ]
];
```
# Development Status of Lexer

## Notes
- PHP directive test: 
    - `phptest -test ShowMePhpFeatures` for a summary of the directive tests
        - see `test/output/PhpFeatures.md` or view in the terminal
    - `phptest -test Directives -run Directive.TestName` 
        - add `-stop_loop 50` to stop after the 50th loop
        - add `-version 0.1` to run without new code. Default in tests is `version 1.0`
        - see `test/src/Php` to create new directive test
        - see `test/Tester.php::runDirectiveTests()`
- Generate Documentation (memory limit):
    - `php -d memory_limit=900M "$scrawl_dir/scrawl"` where `$scrawl_dir` is the path to Code Scrawl's `bin` directory

## Bad stuff
- `function abc() use ($var){}` uses `method_arglist` instructions. It works, it's just does not create the ideal ast structure.

## Versions
- v0.2: has simple (poor) bash lexing and old (incomplete, partially broken) php lexing
- v0.3: I don't know (broken, probably?)
- v0.5: I don't know (broken, probably?)
- v0.6: abandoned intermediate version, I BELIEVE (but not 100% sure)
- v0.7: The up and coming version
- v0.8: get rid of old php grammar. Clean up tests. Document. Maybe some additional polish & niceties for running the lexer.

## Grammar Changes
- Feb 14, 2022, PHP: reset `$xpn` on `op_block_end()` when ast type is `block_body`. See `Php->testScrawl2()`

## Nov 21, 2023
Output ASTs as code. I'd like a proof of concept that starts with ASTs and outputs PHP code. If time allows, I'd like to also allow output of javascript code. (I'm sticking with those two because I know them well)

I need to start with an AST, then add a method to it to output code. If it contains other ASTs, those will also have their output-code methods called.

I'll start with an empty class because I already have good parsing of classes. I'll then add in properties & methods with no body.

WHOO!! PROOF OF CONCEPT WORKS
I did:
- Create ClassAst, DocblockAst, and PropertyAst
- Create get_php_code() & get_javascript_code() methods on each to return string code in the target language
- Create test class Translate at `test/run/translate/Translate.php` with a hard-coded ast to js & php test, and a test outputting the code for `test/output/php/tree/SampleClass.js`.

Notes:
- SampleClass.js outputs with the property value wrapped in extra quotes like `dog = '"PandaBearDog"'`. I'm using `var_export()` bc my sample ast in the first test doesn't have the string quote marks around the value. That AST is probably written incorrectly. Idk.
- I'm tired.
- I would like each of the new ASTs to be strongly typed & docblock-commented to describe what each property is. 

## Oct 21, 2023
Making a .bak file of the current PHP Grammar. Going to maybe make some major changes to the directives. Tempted to start fresh, but kind of know that's gonna be a bad idea. I want to eliminate all of the php components, except for more generic directives. I want all of the logic to be in the Directive definitions.


## Oct 18, 2023
I'm basically done with CreateParser.src.md. I maybe should add a better example of a full Directive. I may want to move the breakdown of instructions into its own file. And maybe rename CreateParser. Also, I suppose I haven't actually touched on any of the PHP of creating a Parser. Yeah. I guess I'll need to do that. So yeah, there's work to do yet on CreateParser.src.md

I updated the readme slightly. Commented out the Use an ast & parse code documentation links, but those will need to be made eventually.

## Oct 17, 2023
Documented in CreateParser.src.md. Did a little docblocking. Only 7 more instructions to document!!!

## Oct 16, 2023
I worked on documentation. I started a new README (DON'T RUN SCRAWL!). I added .docsrc/CreateParser.src.md and documented a fair bit about how the lexer works, as well as several instructions. I documented ALL the instructions that are in the MappedMethods.php file. I need to still document all the instructions in the switch statement in Instructions.php. 

At some point it might be nice to refactor this stuff. It's all pretty confusing. But, I'm doing fine going through it and writing documentation, so I guess it doesn't really matter. As long as the documentation is good, it should be fine.

I probably need a new / better format for documenting the instructions, but what I have currently in CreateParser.src.md is quite alright for now.

I didn't add or modify any docblocks, and some of the documentation I found was wrong.

## Aug 10, 2023
started in-depth parsing of vars in method body.
added some return types
added some docblocks
added `\Tlf\Lexer\Versions` for versioning code
added `$signal` to lexer for expressing expectations simply.
added `has()` to ast to check for a key

Production by default runs with the old lexing.
Tests, however, by default use Lexer\Versions::\_1 (i.e. `1.0`)

To check the var parsing & new signal-stuff see:
- `phptest -test Directives -run Var.Assign.Variable -stop_loop 27`
- `phptest -test Directives -run Var.Assign.String` (i broke this some how, but it WAS working)
- or to run directive tests without new code: `phptest -test Directives -version 0.1`
- code/Php/Operations.php
- code/Php/Words.php
- test/src/Php/Vars.php

## TODO
- (May 13, 2022) LilMigrations fails parsing. I believe `foreach()` is the problem, starting line 105. Need to figure out / fix this.
- (apr 27, 2022) php method body does not contain blank newlines. It should, though, so i can print it back out just as it is written
- review documentation
- add to documentation: `test/output/PhpFeatures.md` contains a list of directive unit tests (their description, input code, and whether they passed their tests). Looking at this is a good way to see what language features have been implemented
- maybe remove nesting a php class inside a namespace ast ... i just don't like it
- am i handling interfaces?
- clean up the php grammar (remove old commented debug code & whatnot)
- create passing BashGrammar tests
- create an easy mode feature like: `$ast = $lexer->easy_mode('php', $string_to_lex)`
- delete the old BashGrammar, JsonGrammar, defunct Docblock grammar,
- document directives (use docblocks, but i don't think the lexer can currently get docblocks attached to array keys like i want for this)
- make generic base grammar that works how the PhpGrammar does
    - maybe make a StringGrammar as well, since string features are often shared between languages

## March 13, 2022
All my tests are passing! I haven't implemented all of the PHP features, but I have the majority of them handled. I haven't added anything that's new in 8.0 or 8.1 & I don't know how I'll handle versioning ... 

My directive tests are cleaned up. All my grammar tests are cleaned up. Basically, this thing is now awesome, robust, trustworthy.

It will still probably need features added here & there, but it's finally at a point where I can count on it.

It would be nice (but not necessary) to write a code-scrawl extension that documents all the directive tests for each grammar.

I would like to add an "EasyMode" to simply do like ... `$ast = $lexer->easy_mode('php', $string_to_lex)`

And I want to clean up this document.

Eventually, I want to catch expression, so a script or function body would have an array of expressions like `$var = 'whatever';` and `return true;` as well as breaking down `if`s/`foreach`es (ones with block at least) as expressions containing expressions.

Eventually, i would like to break down each expression so `$var = 'whatever'` is generic like: `type=set variable, name='var', value='whatever'`

Eventually, all this expression breakdown could be used to transpile between different languages.

## TODOs (old, but maybe still relevant)
- Finish the `GrammarTesting` documentation (once method bodies are available)
### High Priority (internals)
- Make DocblockGrammar work for bash (docblock starts with `##`) 
- BashGrammar + simple tests. Catch:
    - docblocks
    - functions
    - maybe comments
    - nothing else

### Low Priority
- rename `previous` to `meta` or `data`. I'm thinking `meta`. & make it its own group if its not
- Add meta information to ASTs & OPTIONALLY include meta information when getting an AST tree
    - Convert `type` to `_type` on ASTs maybe? (its meta information)
- add additional command arg expansion features (`[]` and `!`)
- `abort` feature:
    - Add an instruction that: Mark a directive as an abortion target
    - Add an instruction that: pop directives until a named abortion target is on the top of the stack
- Threaded parsing. Starts as a single thread, then any instruction can create a new thread & now we'll continue processing on the main thread & process on the new thread as well. Ultimately only one thread can "win", so all but the "correct" thread will be discarded
    - move the `while` loop in `Internals` into its own function like `do_the_actual_lexing($lexer, $token)` or something. 
    - Might just have to create multiple lexer instances to do this.
- Performance: Use arrays, & do object conversions on directives at the last possible moment. I only want them as objects, so they're easier to work with by reference.


## Latest (pretty old list)
- Support return by reference on methods: `public function &global_warming()` (this method launches billionaires to space temporarily & returns a reference to an array detailing the CO2 pollution. (which is bad, because you can just lie and change it to less pollution, now that we're done with the space trip))
- Support all arithmetic operators
- added `none` operation target, which just stops the directive from being processed if it is that operation
    - Used by the `/*` operation so that the docblock directive still handles it
- Refactored operation stuff & multi-char operations are now functional. 
- wrote `operation_match()` method to check if the current buffer is an operation. Simplifies matching multi-char operations.
- Operators are refactored, so multi-char operators can be used
- support simple array declaration 
- add `Values` trait to test value assignment
- parse `trait`s the same way I do `class`es (for the most part)
- implemented: `namespace Abc; class Def {}` - get fully qualified name for the class
- support & test php class `use TraitName;`
- support & test php class `const`s
- add a `stop` instruction set to `php_code` directive
- catch `<?php` and `?>`
- Unit test `static` properties and methods 
- add minimal debugging output to the `wd_` and `op_` routing.
- clean up notes
- Property & method tests passing (& all other current tests)
- Fix the `methods are inside class modifiers` bug
- Add ability to `-run Namespace.*` and run any tests that wildcard match, basically.
- Separate php directive tests into traits
- Add word routing to `wd_theword($lexer, $xpn, $ast)`
- Rename OtherDirectives to CoreDirectives
- Refactored operations into Handlers, Operations, and Words
- Methods are completely handled! (I think)
- Implement almost complete for properties 
    - Properties handle string concatenation, but NOT numeric operations
- add operation routing to `op_opname($lexer, $xpn)`
- New mechanism of operations & words

#!/usr/bin/php
<?php

// supports being in root dir, vendor/, vendor/bin, vendor/taeluf/lexer 
if (file_exists(__DIR__.'/vendor/autoload.php')){
    require(__DIR__.'/vendor/autoload.php');
} else if (file_exists(__DIR__.'/../vendor/autoload.php')){
    require(__DIR__.'/../vendor/autoload.php');
} else if (file_exists(__DIR__.'/../../vendor/autoload.php')){
    require(__DIR__.'/../../vendor/autoload.php');
} else if (file_exists(__DIR__.'/../../../vendor/autoload.php')){
    require(__DIR__.'/../../vendor/autoload.php');
} 
// I'm concerned this would be unexpected and cause weird results
// else if (file_exists(getcwd().'/vendor/autoload.php')){
    // require(getcwd().'/vendor/autoload.php');
// }


$cli = new \Tlf\Cli(getcwd(), $argv);
$cli->load_stdin();

$cli->load_command('main', 
    function(\Tlf\Cli $cli, array $args){
        $cli->call_command('help');
    },
    "Show the help menu"
);


$cli->load_command('file help', function(){echo 'HAAAALP';});
$cli->load_command('file',
    function(\Tlf\Cli $cli, array $args){
        $file = $args['--'][0] ?? null;
        $full_path = $cli->pwd.'/'.$file;

        if (!is_file($full_path)){
            $cli->notice("File not found.","File '$file' does not exist in '".basename($cli->pwd)."/'");
            return;
        }

        print_r($args);
        // exit;

        $helper = new \Tlf\Lexer\Helper();
        $lexer = $helper ->get_lexer_for_file($full_path);
        $lexer->useCache = array_key_exists('nocache', $args) ? false : true; 
        $lexer->debug = array_key_exists('debug',$args) ? true : false; 
        $lexer->stop_loop = isset($args['stop_at']) ? (int)$args['stop_at'] : -1; 

        if ($lexer->debug)ob_start();
        $ast = $lexer->lexFile($full_path);
        if ($lexer->debug)ob_end_clean();

        $json = json_encode($ast->getTree(), JSON_PRETTY_PRINT);

        echo "\n\n";
        echo $json;
        echo "\n\n";
    },
    "Parse a file and output the ast as json. Pass relative path to file to parse."
);

$cli->execute();
{
    "name": "taeluf/lexer",
    "type": "library",
    "description":"A declarative lexer seamlessly hooking into php functions, building ASTs for multiple languages.",
    "autoload": {
        "classmap":["src"]
    },
    "license": "MIT",
    "require": {
        "taeluf/util": "v0.1.x-dev"
    },
    "require-dev":{
        "taeluf/tester": "v0.3.x-dev",
        "taeluf/code-scrawl": "v0.8.x-dev"
    },

    "bin":[
        "bin/lex"
    ],

    "minimum-stability":"dev"
}
{
    "_readme": [
        "This file locks the dependencies of your project to a known state",
        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
        "This file is @generated automatically"
    ],
    "content-hash": "8bf85004b7f952ff0b3f6fe19cb6b399",
    "packages": [
        {
            "name": "taeluf/util",
            "version": "v0.1.x-dev",
            "source": {
                "type": "git",
                "url": "git@gitlab.com:taeluf/php/php-utilities.git",
                "reference": "95524064e9be1b587064c1661980fee20793a1a3"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Fphp-utilities/repository/archive.zip?sha=95524064e9be1b587064c1661980fee20793a1a3",
                "reference": "95524064e9be1b587064c1661980fee20793a1a3",
                "shasum": ""
            },
            "require-dev": {
                "taeluf/code-scrawl": "v0.8.x-dev",
                "taeluf/phtml": "v0.1.x-dev",
                "taeluf/tester": "v0.3.x-dev"
            },
            "default-branch": true,
            "type": "library",
            "autoload": {
                "classmap": [
                    "code"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "description": "Utility methods",
            "time": "2023-12-09T08:23:28+00:00"
        }
    ],
    "packages-dev": [
        {
            "name": "taeluf/better-regex",
            "version": "v0.4.x-dev",
            "source": {
                "type": "git",
                "url": "https://gitlab.com/taeluf/php/better-regex.git",
                "reference": "3ee2ff3482d8903d6977fa1fd97a227f4457dc54"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Fbetter-regex/repository/archive.zip?sha=3ee2ff3482d8903d6977fa1fd97a227f4457dc54",
                "reference": "3ee2ff3482d8903d6977fa1fd97a227f4457dc54",
                "shasum": ""
            },
            "require-dev": {
                "taeluf/code-scrawl": "v0.7.x-dev",
                "taeluf/tester": "v0.3.x-dev"
            },
            "default-branch": true,
            "type": "library",
            "autoload": {
                "classmap": [
                    "code"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "support": {
                "issues": "https://gitlab.com/taeluf/php/better-regex/-/issues",
                "source": "https://gitlab.com/taeluf/php/better-regex/-/tree/v0.4"
            },
            "time": "2022-03-28T20:55:32+00:00"
        },
        {
            "name": "taeluf/cli",
            "version": "v0.1.x-dev",
            "source": {
                "type": "git",
                "url": "https://gitlab.com/taeluf/php/cli.git",
                "reference": "12d7dd6b9a5a1fa0602405e579b807dd5b65a39d"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Fcli/repository/archive.zip?sha=12d7dd6b9a5a1fa0602405e579b807dd5b65a39d",
                "reference": "12d7dd6b9a5a1fa0602405e579b807dd5b65a39d",
                "shasum": ""
            },
            "require-dev": {
                "taeluf/code-scrawl": "v0.8.x-dev"
            },
            "default-branch": true,
            "bin": [
                "bin/tlf-cli"
            ],
            "type": "library",
            "autoload": {
                "files": [],
                "classmap": [
                    "src"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "support": {
                "issues": "https://gitlab.com/taeluf/php/cli/-/issues",
                "source": "https://gitlab.com/taeluf/php/cli/-/tree/v0.1"
            },
            "time": "2024-02-03T13:23:25+00:00"
        },
        {
            "name": "taeluf/code-scrawl",
            "version": "v0.8.x-dev",
            "source": {
                "type": "git",
                "url": "https://gitlab.com/taeluf/php/CodeScrawl.git",
                "reference": "0dd692e411e8bba0c435c60d3423c52546e80c79"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2FCodeScrawl/repository/archive.zip?sha=0dd692e411e8bba0c435c60d3423c52546e80c79",
                "reference": "0dd692e411e8bba0c435c60d3423c52546e80c79",
                "shasum": ""
            },
            "require": {
                "taeluf/better-regex": "v0.4.x-dev",
                "taeluf/cli": "v0.1.x-dev",
                "taeluf/lexer": "v0.8.x-dev"
            },
            "require-dev": {
                "taeluf/tester": "v0.3.x-dev"
            },
            "default-branch": true,
            "bin": [
                "bin/scrawl"
            ],
            "type": "library",
            "autoload": {
                "classmap": [
                    "src/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "description": "A documentation generation framework with some built-in extensions for exporting comments and code, and importing into markdown. ",
            "support": {
                "issues": "https://gitlab.com/taeluf/php/CodeScrawl/-/issues",
                "source": "https://gitlab.com/taeluf/php/CodeScrawl/-/tree/v0.8"
            },
            "time": "2024-02-03T15:30:04+00:00"
        },
        {
            "name": "taeluf/tester",
            "version": "v0.3.x-dev",
            "source": {
                "type": "git",
                "url": "https://gitlab.com/taeluf/php/php-tests.git",
                "reference": "68b4623cd9c4ae8a7e7a6eaf0bacae6933cfa178"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Fphp-tests/repository/archive.zip?sha=68b4623cd9c4ae8a7e7a6eaf0bacae6933cfa178",
                "reference": "68b4623cd9c4ae8a7e7a6eaf0bacae6933cfa178",
                "shasum": ""
            },
            "require": {
                "taeluf/cli": "v0.1.x-dev",
                "taeluf/util": "v0.1.x-dev"
            },
            "require-dev": {
                "taeluf/code-scrawl": "v0.6.x-dev"
            },
            "default-branch": true,
            "bin": [
                "bin/phptest"
            ],
            "type": "library",
            "autoload": {
                "classmap": [
                    "src/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "description": "A unit testing library for Php.",
            "support": {
                "issues": "https://gitlab.com/taeluf/php/php-tests/-/issues",
                "source": "https://gitlab.com/taeluf/php/php-tests/-/tree/v0.3"
            },
            "time": "2024-01-10T13:40:51+00:00"
        }
    ],
    "aliases": [],
    "minimum-stability": "dev",
    "stability-flags": {
        "taeluf/util": 20,
        "taeluf/tester": 20,
        "taeluf/code-scrawl": 20
    },
    "prefer-stable": false,
    "prefer-lowest": false,
    "platform": [],
    "platform-dev": [],
    "plugin-api-version": "2.6.0"
}
{
    "dir.test":["test/run", "test/run/Grammars"],
    "dir.exclude":[],
    "file.require":["test/Tester.php", "test/src"],
    "results.writeHtml":false,
    "server.dir":"test/Server/",

    "test":[]
}
{

    "--comments":{
        "Documentation": "Visit https://www.taeluf.com/docs/Code%20Scrawl or https://gitlab.com/taeluf/php/CodeScrawl",
        "Change 1":"Version 0.8 scanned code/ & test/. Version 1.0 scans src/ & test/ ",
        "Change 2":"Now using non-hidden directories .doctemplate and .docsrc",
        "Change 3":"Version 1.0 defaults to non-hidden 'config/' dir. '.config/' still works."
    },

    "template.dirs": ["doctemplate"],

    "dir.docs": "docs",
    "dir.src": "docsrc",
    "dir.scan": ["src", "test"],
    "ScrawlExtensions":[],

    "file.bootstrap":"scrawl-bootstrap.php",

    "deleteExistingDocs": true,
    "readme.copyFromDocs": true,

    "markdown.preserveNewLines": true,
    "markdown.prependGenNotice": true
}
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# Architecture  
This is a pretty poor explanation of the architecture, but its good enough for me. If its not good enough for you, please submit a PR.  
  
The Lexer manages the directive stack, overall program execution, and most things. The Token manages our placement in the input string. The Grammars declare directives which have instructions to perform when they're matched. These instructions can modify the token, the lexer, and create new Asymmetrical Syntax Trees (ASTs) to create structured representation of the source. Grammars also declare methods to use as additional instructions.  
  
If you want to write a grammar, see [docs/GrammarWriting.md](/docs/GrammarWriting.md). (but it might help to understand the architecture).  
  
## Flow of Lexing  
1. Lexer is initialized  
2. Grammars are added to the lexer.  
3. An `Ast` is created to be the root  
    - Lexer has convenience methods, or you can create your own AST to lex.  
4. The ast is set as the `head`   
5. A `Token` is created from the input `string`  
6. For each grammar `onLexerStart($lexer, $ast, $token)` is called  
7. Perform the lexing (see below)  
8. For each grammar `onLexerEnd($lexer, $ast, $token)` is called  
  
### The Pieces  
- `Lexer:` takes Grammars to process an input string using a Token  
    - `$directiveStack`: A multi-layered stack of directives. Each layer can have multiple directives. Each layer has a 'started' and 'unstarted' list.  
    - `$astStack`: The stack of ASTs. Generally the head ast is operated on  
- `Token`: Contains the input string. Manages our position in the input string.  
- `Grammar`: Declares directives   
    - `directive`: A set of targets & instructions. Generally contains a string or regex (target) to match against & instructions for what to do upon that match.  
- `Ast`: An Asymmetrical Syntax Tree... holds values & can be output as an array  
  
### The Lexing   
1. using a while loop, set `$token = $token->next()`, which returns itself with an updated buffer, or `false`, if there are no more characters to process  
    - `next()` adds one character to the buffer at a time.  
2. Each `started` directive is checked for `match` and `stop`. If there are no `started` directives, then `unstarted` directives are checked for `start`  
3. If `started` directives stop, they're moved back into `unstarted`. And visa versa when `unstarted` directive start.  
4. Any regexes that passed in step #3 are now processed for their instructions, in the order those instructions were declared.  
5. `then`s are processed & any target directives are added to a new layer of the directive stack  
6. Repeat from #1 until the token has been fully buffered  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# ChangeLog  
  
## Other Notes  
- 2023-11-21: Cleaned up the repo, moved files around  
- 2023-11-21: Added prototype outputting code from an ast  
  
## Git Log  
`git log` on Tue Nov 21 09:05:05 PM CST 2023`  
- d295e34  (HEAD -> v0.8, origin/v0.8) fix scrawl config [62 seconds ago]  
- 0c59fd9  add readme. run scrawl [3 minutes ago]  
- 13e797d  add bin script to composer. move some old docs [5 minutes ago]  
- 580bf7f  move files around [6 minutes ago]  
- 202b17e  composer update to fix tester bin script [8 minutes ago]  
- fafbb87  revert composer update, then update all packages but tester [13 minutes ago]  
- c7d2a3b  composer update [21 minutes ago]  
- 91fc8ae  note [23 minutes ago]  
- 7496217  add output-ast-as-code prototype. Implemented new asts for specific ast types & added a translate test class, running the prototype [24 minutes ago]  
- 7dd3546  notes, making new branch for dev [4 weeks ago]  
- 9c32b3b  more create parser documentation. instructions are pretty well covered! [5 weeks ago]  
- f0594aa  Wrote more documentation [5 weeks ago]  
- 439e7ce  documentation work, developing CreateParser.md, describing how the lexer works & what instructions are available [5 weeks ago]  
- 63d1726  work on a new readme & CreateParser.md documentation [5 weeks ago]  
- c777a11  docblocks on versions [3 months ago]  
- e5604c2  status notes [3 months ago]  
- e0a6c7f  run scrawl [3 months ago]  
- f066b6f  started in-depth parsing of vars ia method body. added basic versioning to lexer handling. add signal to lexer. add has() to ast. [3 months ago]  
- e00f271  documented phpgrammar & started work on enum [6 months ago]  
- dde6e60  fix typo in file name [6 months ago]  
- b4a1f1c  fixed a docs link [6 months ago]  
- cfddca7  php grammar docs [6 months ago]  
- ad4f933  some documentation improvement (and some broken links) [6 months ago]  
- aa760c6  run scrawl, some update documentation [6 months ago]  
- c4ab127  add static cachemap to lexer to prevent oout of memory error [6 months ago]  
- 339d61c  composer update (cli, again) [7 months ago]  
- 7bcadef  composer update (cli) [7 months ago]  
- 1c400ba  generate documentation with scrawl [7 months ago]  
- 535ae95  add cli. add LexerHelper for easier usage. New documentation [7 months ago]  
- 9adc727  tried to fix namespace bug, but couldn't get my php grammar tests to run... wrote readme about how the php grammar works [8 months ago]  
- 3daab39  add a php directive test for the namespace in a method arg bug, but tests aren't working [8 months ago]  
- df6df64  rename `code/old/BashGrammar.php` class to `OldBashGrammar` [9 months ago]  
- 34bf7f7  wrote test function LexPhp & modified README2.md ... need to convert it to a .src.md file so the mdverbs work [11 months ago]  
- ef150a9  added bash tests. fixed issues with bash grammar. It was left in an invalid state after comments & after the start of a docblock that was preceded by whitespace, so many things didn't get parsed, & nesting was messed up. Seems to be fixed now [11 months ago]  
- 13433ff  setup file-based bash tests [11 months ago]  
- 0f65bbf  write README2.md with relatively good examples [12 months ago]  
- 2e386db  update bash grammar to process functions witht heir docblocks [12 months ago]  
- e11f3cd  updated to work with php 8.2. Merely defined some previously dynamic properties and changed some from protected to public [12 months ago]  
- 9755bc2  ugh [1 year, 6 months ago]  
- 51011bb  update Status section of README [1 year, 6 months ago]  
- f9986f6  fix docs dir & run scrawl [1 year, 6 months ago]  
- 6c09415  fix the LilMigrations bug caused by use($var1, $var2) not being valid in anonymous functions [1 year, 6 months ago]  
- 56ecc14  add LilMigrations test (which is failing, and left as a TODO) [1 year, 6 months ago]  
- d838156  remove the LexerGrammarTest that was never implemented fully [1 year, 8 months ago]  
- b8a3162  update readme [1 year, 8 months ago]  
- a4ad191  fix some scrawl issues & run it. update readme [1 year, 8 months ago]  
- ca5f8c3  update readme [1 year, 8 months ago]  
- 72b4ee9  run scrawl [1 year, 8 months ago]  
- b4f0371  bugfix: program stalled when docblock contained an attribute with trailing whitespace and no text on the same line [1 year, 8 months ago]  
- afcf93f  composer update [1 year, 8 months ago]  
- 56b690e  notes [1 year, 8 months ago]  
- ac9ef9e  improve trait ast. pass all integration tests [1 year, 8 months ago]  
- 93635c4  improve function ast & capture body [1 year, 8 months ago]  
- 43f6bd6  capture method body & tests are passing [1 year, 8 months ago]  
- 3179bca  notes [1 year, 8 months ago]  
- 2f1b6e3  add Method.SimpleBody directive test [1 year, 8 months ago]  
- 4bb7eba  php: classes directive tests passing [1 year, 8 months ago]  
- 009811e  major cleanup to PhpGrammar tests [1 year, 9 months ago]  
- ec5bda5  cleanup. notes. ran tests [1 year, 9 months ago]  
- d68ab4b  rename PhpGrammrNew to PhpGrammar [1 year, 9 months ago]  
- 85fe929  clean up tester clsas and some tests [1 year, 9 months ago]  
- bd329a2  clean up starter grammar test [1 year, 9 months ago]  
- 7b33dcd  some cleanup and docblocks [1 year, 9 months ago]  
- 31d6069  clean up 2 tests & move old php grammar to old dir [1 year, 9 months ago]  
- 4e2006f  (origin/v0.7, v0.7) fix bug with nested block not terminating expression [1 year, 9 months ago]  
- 2dedaba  stopped setting body on methods, for the time being [1 year, 9 months ago]  
- 6a29f1c  notes [1 year, 9 months ago]  
- 7e5eed6  prototyped a new php grammar test bc body is returning ast objects in the tree .... [1 year, 9 months ago]  
- f542bc9  fix fqn issue [1 year, 10 months ago]  
- 83a856d  attempt to add docblock to classes & ensure they always have namespace and fqn present [1 year, 10 months ago]  
- e42946c  fix heredoc issue (i wasn't clearing the buffer when matching the closing heredoc key [1 year, 10 months ago]  
- 204ff7a  fixed string_backslash again (better this time, hoepfully!) [1 year, 10 months ago]  
- e0686bc  note [1 year, 10 months ago]  
- 064ae5f  work on the php grammar ... handles functions (not just methods), and fixes bugs with catching 'class' and 'function' keywords in the wrong context [1 year, 10 months ago]  
- b77859a  added a lot of operations, which got quite a few parse tests passing (method counts, anyway). [1 year, 10 months ago]  
- b79cfd1  moved files around. genericized lexing expectation tests [1 year, 10 months ago]  
- fcfa158  moved some files. added a documentations test class. wrote a clean test of running the lexer for php code (as documentation). wrote a bunch of notes. [1 year, 10 months ago]  
- 81072a5  update phptester [1 year, 10 months ago]  
- 39d8580  composer install [2 years ago]  
- 1841d31  notes on versions [2 years ago]  
- 47b6e89  ran scrawl [2 years, 2 months ago]  
- afb9eeb  started work on getting PhpGrammarNew_SampleClass to pass [2 years, 4 months ago]  
- 794e9c3  support return by reference methods [2 years, 4 months ago]  
- 3df1846  add operation_match() method to check if buffer is an operation [2 years, 4 months ago]  
- 7802c9e  working on operator for arrays with keys. All tests passing except the with keys test [2 years, 4 months ago]  
- 8ce70f9  add values test & get simple array passing [2 years, 4 months ago]  
- fe5e3b8  support traits [2 years, 4 months ago]  
- 1077526  set fqn on classes in namespaces [2 years, 4 months ago]  
- b240367  notes.... The last commit merged in a lot of changes to how the php grammar was written as well as new php language features [2 years, 4 months ago]  
- 1016d52  Implement AST driven approach to state-checking in the php grammar [2 years, 4 months ago]  
- b9c14a8  notes [2 years, 4 months ago]  
- 036ee33  notes [2 years, 4 months ago]  
- 9dd5399  class integration tests [2 years, 4 months ago]  
- 263c868  catching class names & stuff [2 years, 4 months ago]  
- 8adc98e  simple class name capture is working [2 years, 4 months ago]  
- 7195907  all methods tests passing. cleaned up and refactored operations. added routing via wd_theword() [2 years, 4 months ago]  
- 92ffba1  method parsing is tested and successful [2 years, 4 months ago]  
- ae7da6b  notes [2 years, 4 months ago]  
- 1b267b8  namespace tests passing [2 years, 4 months ago]  
- 05f9594  properties and args catch string concatenation in their default values [2 years, 4 months ago]  
- 9e15f43  arglists & properties are highly parseable, but not complete [2 years, 4 months ago]  
- 0e59d16  some refactoring done & working for property parsing [2 years, 4 months ago]  
- 1b03aff  refactor operations [2 years, 4 months ago]  
- 2cbf0f0  prototyped capturing a method [2 years, 4 months ago]  
- 1c0a597  early prototype of new php grammar [2 years, 4 months ago]  
- ac14a2c  notes on new grammar style [2 years, 4 months ago]  
- 0ddc8df  added property test with and without type. with type fails [2 years, 4 months ago]  
- 532047f  notes [2 years, 4 months ago]  
- cbb0a2d  generate docs [2 years, 4 months ago]  
- 99f28fd  now catching heredoc & nowdoc [2 years, 4 months ago]  
- c54efd5  New class directives. catching traits. fixed some bugs. new string directives [2 years, 4 months ago]  
- 7ef94d0  notes [2 years, 4 months ago]  
- fda5996  attempted to write new ClassDirective. added tests that pass with the new implementation. but then scrawl doesn't work... [2 years, 4 months ago]  
- 4261efa  fixed all the failing tests [2 years, 4 months ago]  
- e88035a  notes [2 years, 4 months ago]  
- 0daf102  mostly documentation. Some minor changes & fixes too i think [2 years, 4 months ago]  
- 9824ac2  docgen [2 years, 4 months ago]  
- 75ce844  docs [2 years, 4 months ago]  
- 87b381c  docgen [2 years, 4 months ago]  
- f4d86d9  generate docs [2 years, 4 months ago]  
- 4b329c0  docs [2 years, 4 months ago]  
- 3b5f9e0  convert _blank- to +. Move mapped methods into their own trait [2 years, 4 months ago]  
- 4edd8c2  notes [2 years, 4 months ago]  
- 569676c  add `+` alternative to `_blank` [2 years, 4 months ago]  
- 44db265  docs gen [2 years, 4 months ago]  
- 5ee46aa  docs [2 years, 4 months ago]  
- d543851  add inherit instruction [2 years, 4 months ago]  
- 662292f  some docs. add then.pop instruction. Add StarterGrammar and test [2 years, 4 months ago]  
- 0afe251  docs [2 years, 4 months ago]  
- 53daa5a  add status of grammars to readme [2 years, 4 months ago]  
- 629e650  readme [2 years, 4 months ago]  
- 8e0f938  minor code improvements (like 15 lines across 3 files). Much documentation [2 years, 4 months ago]  
- 8bc4ae0  some docs [2 years, 4 months ago]  
- 75e41c4  minor cleanup [2 years, 4 months ago]  
- 1de6b72  add `namespace.docblock` to `file` ast & update tests [2 years, 4 months ago]  
- a87ebb0  docblock tests passing. php grammar tests passing with docblock grammar integrated [2 years, 4 months ago]  
- d966019  then can now reference a grammar by namespace:directivename [2 years, 4 months ago]  
- 91bf3b5  notes [2 years, 4 months ago]  
- 2e11c5b  description in composer.json [2 years, 4 months ago]  
- fa79ef4  readme warning [2 years, 4 months ago]  
- b0d5f8a  update composer.json [2 years, 4 months ago]  
- 7a74c90  cleanup, mostly docblockgrammar stuff [2 years, 4 months ago]  
- 6201513  finished a custom php implementation of the Docblock Grammar [2 years, 4 months ago]  
- 545a6cd  docblock grammar planning work. Some code too [2 years, 5 months ago]  
- a94c00c  working on the docblock grammar. little stuck [2 years, 5 months ago]  
- d13c454  started work on Docblock Grammar [2 years, 5 months ago]  
- d239831  added some more php directive tests [2 years, 5 months ago]  
- 5ce22f5  tests passing & bugs fixed with the custom Tester [2 years, 5 months ago]  
- 6b579da  add Tester class to simplify testing of many directives. Start work on the Php Tests. Some bugs remain with Tester. [2 years, 5 months ago]  
- ea97099  remove inspect_loop param from lexer [2 years, 5 months ago]  
- 4d643b3  notes [2 years, 5 months ago]  
- 0d9f584  some notes [2 years, 5 months ago]  
- 1d92b30  cleanup from refactor. Notes [2 years, 5 months ago]  
- 7f6eaac  refactored instruction processing. Needs cleanup! [2 years, 5 months ago]  
- 2e50433  finish documenting instruction processor [2 years, 5 months ago]  
- 3ccd0d1  documenting internal processes, so I can refactor them [2 years, 5 months ago]  
- 63da65f  create a command parsing function and refactor instruction execution. All changes are present, but many commits were lost due to an error with git [2 years, 5 months ago]  
- 63dce34  some bash grammar work, but moreso comment grammar work & some test work [2 years, 5 months ago]  
- 4837711  re-ran code scrawl [2 years, 5 months ago]  
- 4b57479  minor cleanup, including of documentation [2 years, 5 months ago]  
- bde69d4  organize lexer internals into traits & remove old functions [2 years, 5 months ago]  
- eb1a771  reorganized lexer's internal code into traits [2 years, 5 months ago]  
- 3e2def3  general test cleanup [2 years, 5 months ago]  
- 22f9279  clean up php grammar test [2 years, 5 months ago]  
- 2157602  removed old php grammars & cleaned up naming & namespaces [2 years, 5 months ago]  
- 4f73357  cleaned up Php Directives into multiple files [2 years, 5 months ago]  
- babf129  removed unneeded functions for phpgrammarnew & separated directives into a trait [2 years, 5 months ago]  
- 5c4edb6  notes [2 years, 5 months ago]  
- e7fae1a  notes [2 years, 5 months ago]  
- caca97c  fixed minor bug with const definition [2 years, 5 months ago]  
- fbd6a0e  PhpGrammarNew fully parses SampleClass.php [2 years, 5 months ago]  
- 7900447  successfully capturing method!!! [2 years, 5 months ago]  
- 0c50e73  new varchars works for class_property [2 years, 5 months ago]  
- 42dcfb2  minor redesign to 'varchars' complete for namespace and class. reviewing for class_properties [2 years, 5 months ago]  
- 5d06f66  notes [2 years, 5 months ago]  
- c46ddcd  Catching Php properties, working on methods [2 years, 5 months ago]  
- 6a383ab  notes [2 years, 5 months ago]  
- ed254ab  it seems like the lexer is working, along with overrides and 'is' directives & everything [2 years, 5 months ago]  
- 5bc04a7  kind of got 'is' directives working. Added more tests. Wrote notes. [2 years, 6 months ago]  
- 80bcc2b  major progress on getDirectives() & started work on expanding is directives [2 years, 6 months ago]  
- f35791a  add tests for overrides & normalization [2 years, 6 months ago]  
- aa94855  fix 'then' adding multiple directive layers [2 years, 6 months ago]  
- 839a0d2  match processing is part of instruction processing now. implement overrides. implement new command features except []. process directives in order. correct some directive issues. [2 years, 6 months ago]  
- 3098494  notes, mostly [2 years, 6 months ago]  
- 4cb5ac2  much progress on the lexer. Lotta stuff working. Some things to clean up. NOtes made. [2 years, 6 months ago]  
- fc80e5e  I think most old code is cleaned up. Started working on some enhancements [2 years, 6 months ago]  
- f9deae0  major progress on new design. Going to delete all the unneeded code [2 years, 6 months ago]  
- b4251f2  progress on new lexer setup. Stuck on parsing of keys & values as commands [2 years, 6 months ago]  
- e8f4fc7  major progress on PhpGrammarNew. Class, docblock, and property are working [2 years, 6 months ago]  
- ed33c3b  progress on phpgrammarnew [2 years, 6 months ago]  
- 9578957  progress on phpgrammarnew [2 years, 6 months ago]  
- 5d8e6a7  namespace parsing working. [2 years, 6 months ago]  
- cbd2b60  some progress on phpgrammar [2 years, 6 months ago]  
- 4d8ffef  work on PhpGrammarNew [2 years, 6 months ago]  
- 2d397a3  worked on PhpGrammarNew [2 years, 6 months ago]  
- 3944e58  note around installing. remove broken dependencies from composer.json [2 years, 6 months ago]  
- ded50cb  fix composer.json [2 years, 6 months ago]  
- acdf87a  update composer.json [2 years, 6 months ago]  
- 71572af  documentation [2 years, 6 months ago]  
- e38e3b9  doc cleanup [2 years, 6 months ago]  
- 5fe8c3d  cleanup old files [2 years, 6 months ago]  
- 5eb0cb5  note in readme. Some doc stuff [2 years, 6 months ago]  
- 869b6b7  started some notes/docs [2 years, 6 months ago]  
- d5f7d45  docblocked Ast a bit [2 years, 6 months ago]  
- 8fc1dde  cleaned up Grammar. Wrote some Docblocks [2 years, 6 months ago]  
- 6d8b3f2  refactored lexer & wrote some docblocks [2 years, 6 months ago]  
- a595a3b  add string-based matching. add array-based prior-match fillins. add _fillReg attribute to directives to signal string-based prior-match fillins [2 years, 6 months ago]  
- aa64ba2  added notice to readme [2 years, 6 months ago]  
- f42cfb8  cleaned up old code & docs [2 years, 6 months ago]  
- c8a20bf  cleaned up status doc & some old code files [2 years, 6 months ago]  
- a80d924  [no commit msg given] [2 years, 6 months ago]  
- 96bad45  json grammar works for nested arrays! And outputs valid php array! And ast class can be customized by grammar or by individual declarations [2 years, 6 months ago]  
- d7aac74  JsonGrammar works! Except for printing. Added ast information to debug output [2 years, 6 months ago]  
- 18fd7b7  add directive dump for specified loop iteration when debugging [2 years, 6 months ago]  
- 0bb29b6  added really nice debugging messages [2 years, 6 months ago]  
- ffd50f4  much progress on new lexer version. Issue with getting nested arrays on the pseudo-json grammar [2 years, 6 months ago]  
- cffb085  everything seems to be working except bubble [2 years, 6 months ago]  
- 02b33fc  lots of progress on the new implementation [2 years, 6 months ago]  
- c05726a  planning progress [2 years, 6 months ago]  
- 3e28c02  notes [2 years, 6 months ago]  
- 9c6834a  planning progress on new lexer design [2 years, 6 months ago]  
- 4dfa97c  progress on new lexer implementation [2 years, 6 months ago]  
- 9e6a3f6  gitignore vendor dir [2 years, 6 months ago]  
- 6f5db27  [no commit msg given] [2 years, 6 months ago]  
- 3e55a9c  started directives implementation on Grammar and Lexer [2 years, 6 months ago]  
- b697e5f  minor notes & ideas [2 years, 6 months ago]  
- 15e419e  Significant progress on structure of directives [2 years, 6 months ago]  
- 5a9f6aa  notes [2 years, 6 months ago]  
- d91812f  major cleanup. Minor fixes. Run scrawl, even though there are problems. [2 years, 6 months ago]  
- dc7856b  notes [2 years, 6 months ago]  
- 7199848  notes [2 years, 6 months ago]  
- e401d10  PhpGrammar2 gets classes, properties, methods, functions, and constants [2 years, 6 months ago]  
- 92367da  phpgrammar2 is almost ready. Lexer is basically ready [2 years, 6 months ago]  
- c7320b3  notes [2 years, 6 months ago]  
- 8f74f78  notes, mostly? [2 years, 6 months ago]  
- da11a20  fixed bug regarding caching. Some work toward finishing phpgrammar2 [2 years, 6 months ago]  
- a95710c  finish implementing file ast cacheMinor notes [2 years, 7 months ago]  
- 1f6e6df  implement file ast cache (not yet tested) [2 years, 7 months ago]  
- f16b279  cache ast note [2 years, 8 months ago]  
- 5cfd300  cleanup status notes [2 years, 8 months ago]  
- f072b3f  ran code scrawl [2 years, 8 months ago]  
- 472edbe  notes/docs [2 years, 8 months ago]  
- 06588a9  new lexer is working & old grammars are converted [2 years, 8 months ago]  
- 6ecbb20  dev status notes [2 years, 8 months ago]  
- e1a7fd0  comments in old phpgrammar [2 years, 8 months ago]  
- 45d5a66  refactored. Wrote many notes [2 years, 8 months ago]  
- 34d9b65  notes [2 years, 8 months ago]  
- 7c89e33  fixed some problems with lexer. php grammar2 working [2 years, 8 months ago]  
- 525ed50  implemented new lexer. No ast on mw php grammar, but it executes without error! [2 years, 8 months ago]  
- fcb1cbf  docblock attributes now accept numbers & underscores [2 years, 8 months ago]  
- 192f41b  bugfix? [2 years, 8 months ago]  
- 09724ea  TODOs [2 years, 8 months ago]  
- bbf1d1d  add docblockgrammar to phpGrammar, causing breaking changes. [2 years, 8 months ago]  
- 24f36cc  wrote most of an introduction [2 years, 8 months ago]  
- e32aaef  notes [2 years, 8 months ago]  
- 55f542f  update status [2 years, 8 months ago]  
- 60506ab  fix verb issue with docblock [2 years, 8 months ago]  
- c1e3fb9  status doc update [2 years, 8 months ago]  
- 726bbf8  bash grammar improvements. rudimentary docblock grammar [2 years, 8 months ago]  
- 85f1898  add bash grammar [2 years, 8 months ago]  
- 3de3dfe  cleanup. add declaration to phpgrammar method. set Tlf namespace. [2 years, 9 months ago]  
- b72cdac  [no commit msg given] [2 years, 9 months ago]  
- d8f612e  some cleanup [2 years, 9 months ago]  
- 46f17c0  Add LICENSE [2 years, 9 months ago]  
- 887c7bc  Project Initialized from local [2 years, 9 months ago]  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# Create Language Parser  
To parse a new, currently unsupported language, you'll define `Directives`, written in a simplified programming language. Directives are backed by php code, either built-in to the `Lexer` or added to your language parser's `Grammar`.  
  
The goal of parsing code is to create an AST - Asymmetrical Syntax Tree. It's just a multi-dimensional array that details the structure of the parsed code.  
  
(*The Lexer could potentionally parse things other than code, such as cooking recipes.*)  
  
## In this file  
- How the Lexer Works  
- Directives  
- Instruction Examples  
- Available Instructions  
  
## How the Lexer Works  
The Lexer creates a  `Token`, an `Ast` stack, and a `Directive` stack, then loops over each individual character in the input string, adding one character to the Token's buffer on each loop.  
  
On each loop, the head of the Directive stack is processed, and instructions may modify the head ast, add another directive to the top of the stack, create a new ast, rewind the buffer, or do many other tasks. (*Note: Most instruction sets start with a `match /regex/` instruction, which must succeed to run other instructions.*/  
  
Each layer of the Directive stack contains an 'unstarted' and a 'started' list (*each list is an array of Directives, or an empty array*).  
  
Each Directive may contain up to 3 instructions sets: 'start', 'match', and 'stop'. (*@todo We'll talk about the special 'is' instruction set later.)  
  
When the 'started' list is empty, 'unstarted' directives are processed. When an 'unstarted' directive is processed, its 'start' instruction set is executed. If the 'start' instruction set succeeds, the Directive is added to the 'started' list.  
  
When the 'started' list is NOT empty, 'started' directives are processed. When a 'started' directive is processed, its 'match' and 'stop' instruction sets are executed. 'match' goes first. If 'stop' is executed successfully, the Directive is moved back to the 'unstarted' list.  
  
A Directive may add a layer to the directive stack. Then on subsequent loops, the new head directive layer will be processed, and the previous directive layer will be paused, until it is the head layer again.  
  
The Lexer loops in this way, over each character, until all characters are processed.   
  
When the Lexer finishes parsing a string, it returns a detailed AST describing the input file/string.  
  
To recap, Directives and ASTs are both on a stack. Directives are processed on each loop, executing instructions that modify ASTs, create new ASTs, and tell the Lexer which Directives it should run next.   
  
*Tip: the lexer has a 'stop_loop' setting for debugging, to stop after a given number of loops.*)  
  
## Directives & Instruction Sets  
A `Directive` is a named array of instruction sets. Each instruction set contains an array of `instructions` (*lol*).  
  
Most instruction sets begin with a `match /regex/`, which matches against the Token's current buffer. If the regex matches, an unstarted directive is started, and the instructions after the match instruction are processed. If the regex does not match, the rest of the instruction set is not processed.   
  
## Instructions  
There are 20+ instructions available, and you can directly call methods on your Grammar, the Lexer, or the Token.  
  
Instructions can be a string like `'token.rewind 3'` or a key/value pair like `'ast.new' => ['type'=>'class','name'=>'_token:buffer' ...]`, which creates a new ast.  
  
If defining a **key/value pair**, the key is the instruction and the key may conain arguments, and the value is an argument to pass to the instruction.   
*Tip: This allows arrays to be passed to instructions.*    
*Tip: If the value is (*strict boolean*) `false`, the instruction is disabled.*    
*Tip: If the key begins with an underscore (`_`), the instruction is disabled.*    
  
The instruction can include arguments, separated by a space. The key may end in a special/reserved argument. The reserved arguments are `...`, `[]`, `!`, and `// comment`. The value may be any php data type, depending on the instruction's requirements & any reserved args that are used.   
  
(*Tip: Add comments if you ever have two identical keys in an instruction set.*)  
  
If you only define a value (no string key), then the value is your instruction, and reserved arguments are unavailable.  
  
## Instruction Examples  
`"instruction a b c"` passes three arguments `('a','b','c')` to the instruction  
`"object:method arg1 arg2"` calls a php object's method, passing two args `('arg1', 'arg2')`  
`"instruction a" => "b b"` passes two arguments ('a', 'b b') to the instruction  
`"instruction a" => ['b', 'c', 'd'`] passes two arguments to the instruction `('a', ['b','c','d'])`    
`"instruction a ..." => ['b', 'c', 'd'`] passes four arguments `('a','b','c','d')` to the instruction.    
`"instruction []" => 'value'` throws an exception because `[]` is reserved for future use.  
`"instruction !" => '\_object:method arg1 arg2'` calls the named php object/method, and the return value is passed to the instruction.   
  
For `object:method`, you can call any public method on the object, and available objects are:  
- `lexer`, \Tlf\Lexer   
- `token`, \Tlf\Lexer\Token  
- `ast`, \Tlf\Lexer\Ast - the head ast  
- `this`, \Tlf\Lexer\Grammar - the Grammar attached to the current directive (*The Grammar that defines the current directive*).  
- any other grammar name.  (*must be a grammar that's added to your lexer instance*)  
  
Non-Grammar methods are called like `$object->method(...$args)` where `$args` is what's defined in your instruction, like `['arg1', 'arg2']`.  
  
Grammar methods receive `($lexer, $headAst, $token, $directive, $args)`, where `$args` is what's defined in your instruction, like `['arg1', 'arg2']`.   
  
## Available Instructions  
- `match /regex/` - Start directive & continue processing instruction set if `/regex/` matches the current token buffer  
    - or `buffer.match`  
- `then :directive_name` - Add the named directive to the directive stack. Creates a new layer on the stack once per loop.  
    - or `directive.then`  
    - `then grammarname:directive_name` - Add a directive of another grammar, such as from the docblock grammar  
    - `then directive_name.stop` -  Add the named directive's 'stop' instruction set as a 'start'   
    - `"then :+new_directive_name" => $directive` - Create a new directive to add to the stack, instead of referencing a named directive.  
    - `"then _blank" => $directive` - same as to `:+`  
    - `"then directive_name" => $directive_overrides` - To add a directive, but override parts of it. See [Grammar.php](code/Grammar.php) `getOverriddenDirective()`.  
- `then.pop :directive_name layers_to_pop` - Add a directive to the stack & immediately pop the directive layer when it is matched (instead of the directive's normal functioning).   
    - `layers_to_pop` is an int  
    - Rewinds by the length of the first capture group from the target directive's match  
    - Creates new Directive stack layer before pop if it is the first `then` call this loop  
- `buffer.notin key` - Check if the current buffer matches a string in your grammar's `public $notin`. If no match, then clear the buffer and ... i think start/stop directive? idk  
    - Your grammar defines `public $notin = array<string key, array array_of_strings>`.   
    - `buffer.notin key` checks `!in_array($grammar->notin['key'], 'current_buffer')`  
- `"ast.new" => []` - Create a new ast   
    - arg `type=>class` or `_type` - a string type or `_object:method arg1 arg2` to call on lexer, token, or head ast  
    - arg `_setHead=true|false` - (optional) true to add to top of ast stack. false to not. default is true.  
    - arg `_class=>PhpClass` - (optional) the Ast's php class.  
    - arg `_setto=>property` - (optional) Add the new ast to the current head ast's named property.  
    - arg `_addto=>property` - (optional) Same as `_setto`  
    - arg `_setPrevious=>key` - (optional) Set the new ast to the 'previous' key.   
        - *Ex: we create a docblock ast & we `_setPrevious=>'docblock'`, then we encounter a class and retrieve it with `$lexer->previous('docblock')`, to set the class's docblock.*  
    - If not `_setto` or `_addto`, then if the type is 'class', then the new ast is added to the current head ast's 'class' property.  
    - Any other key/value pair - the key is the name of a property on the ast. The value is either the value to set, or it calls an `_object:method arg1 arg2` if it is a string starting with an underscore (`_`). Ex: `_token:buffer` would set the current buffer string to the property.  
- `debug.die` or `die` - Same as `debug.print` but `exit`s.   
- `debug.print` or `print` - Shows what php values were created from your instruction.  
- `directive.inherit [:directive.isn] ["match"]` or `inherit` - Run commands of another directive, except for the 'match' instruction.   
    - Ex: `inherit :string_instructions.stop`  
    - Include literal string 'match' to enable the 'match' instruction.   
    - arg `:directive.isn` - `isn` is the instruction set name ('start', 'match', or 'stop').   
- `directive.start` or `start` - Mark the current directive as started.   
    - You can start a Directive with `start` instead of match.  
- `directive.stop` or `stop` - Mark the current directive as stopped  
    - Allows a 'match' instruction set to stop a directive  
- `token.rewind [num_chars]` or `rewind` - Rewind the token.   
- `token.forward [num_chars]` or `forward` - Move the token forward  
- `directive.halt` or `halt` - Halt the current directive, so further instructions in the active instruction set will not be processed. Other instruction sets in the active stack list will be processed.  
- `halt.all` - Halt the all other instructions sets waiting to be processed. To also halt the active instruction set, call 'directive.halt' AFTER 'halt.all'  
- `previous.set [key]` - Set the current buffer to the 'previous' key/value set, for the given key.  
    - Ex: `previous.set docblock` is used to capture a docblock, then when the next class or function is found, the Directive will call `"ast.set docblock !" => _lexer:previous docblock`   
- `previous.append [key]` - Append the current buffer to the 'previous' key/value set, for the given key.  
    - `"previous.append" => ['statement', 'method_declaration']` also works  
- `directive.stop_others` - Loop through the list of all other started directives and move them to the unstarted list. Does NOT stop the active directive (*the one calling directive.stop_others*).  
- `directive.pop [num_layers]` - Pop layers off the Directive stack.  
- `buffer.clear` - Clear the buffer  
- `buffer.clearNext [num_chars]` - Progress the buffer forward [num\_chars], but do NOT add those chars to the buffer. May corrupt the token...   
- `buffer.appendChar [string]` - Append a string to the buffer. May corrupt the token...  
- `ast.pop` - Remove the head AST from the top of the stack, unless it's the last one.  
- `"ast.set [property] !" => '_object:method arg1 arg2'` - Set head AST's `[property]` to `$object->method('arg1','arg2')`'s return value.  
    - `ast.set [property]` will set the head AST's `[property]` to the current buffer.  
    - Ex: `"ast.set docblock !" => '_lexer:previous docblock'` will get the docblock from the 'previous' key/value set, and set the 'docblock' property on the head ast.  
- `ast.push [property]` - Append the current buffer to given array property on the head ast.  
- `"ast.append [property] !" => '_object:method arg1 arg2'` - Append to the head AST's `[property]`. Same as ast.set, except this appends.  
  
  
## Example  
// @todo make a better example  
```<?php  
['docblock'=>  
    [    
        'start'=>[    
            'match'=>'##',    
        ],    
        'stop'=>[    
            'match'=>'/(^\s*[^\#])/m',    
            'rewind 2',    
            'this:handleDocblockEnd',    
            'buffer.clear',    
            // 'forward 2'    
        ]    
    ]  
];  
```  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# PHP Grammar  
This document is for the further development of the PHP Grammar.  
  
## Status  
- Language Support: Php 8.2  
- Parses:  
    - Classes, traits, interfaces, namespaces  
    - methods, functions, anonymous functions  
    - class propreties, class consts, method/function properties  
    - docblocks, comments  
    - return types, property types  
- Does NOT parse:  
    - expressions, for loops, method calls  
    - enums  
- Work being conducted:  
    - wrote `wd_enum` and the elseif in `unhandled_wd` to set the enum name. (*commented them out*)  
    - adding enum support requires parsing the `case`es & may have other syntax. Need a quick break down of the syntax & some tests.  
  
## Documentation   
- [Features Available](/test/output/PhpFeatures.md) - Overview of which features are implemented, tested, and passing.  
- [Architecture Description](/code/Php/README.md)  
  
## Overview  
You most likely will work on `Operations.php` or `Words.php` to add any new features. If you define or modify any directives, then you may want to add handlers in `Handlers.php`.  
  
To *define new operations*, add a symbol to the operations array in get_operations. It will look like `'&&'=>'and'`. Then define a method `op_and()`  
1. Define an operation handler like: `public function op_my_new_symbol($lexer, $ast, $xpn)`  
2. Add the symbol to `get_operations()`: `'&%'=>'my_new_symbol'`  
3. Fill out your operation handler  
  
To *define new words*, either:  
- define a word handler: `public function wd_enum($lexer, $xpn, $ast)`  
- or add a case to `unhandled_wd()`, like `else if ($ast->type == 'trait' && !isset($ast->name))`  
  
To *create a new handler*, definable in the directives:  
- `public function handleMyNewDirective($lexer, $ast, $token, $directive)`  
- Then, In a directive write `'this:handleMyNewDirective'`  
  
For *writing directives*, look at the CoreDirectives.php file and the [README](/README.md).  
  
## Code  
- [PhpGrammar.php](/code/Php/PhpGrammar.php) - Base class, implementing the lexer's callback methods, and `use`ing the directive & handler traits.  
- Directives  
    - [CoreDirectives.php](/code/Php/CoreDirectives.php)  
    - [Words.php](/code/Php/StringDirectives.php)  
- Handlers  
    - [Handlers.php](/code/Php/Handlers.php) - Defines methods callable by directives. Enables Operations & Words as simplified handlers.  
    - [Operations.php](/code/Php/Operations.php) - Handles all the symbols  
    - [Words.php](/code/Php/Words.php) - handles keywords & other non-string alphanumeric chars, like property names.  
  
## Testing  
- PHP directive test:   
    - `phptest -test ShowMePhpFeatures` for a summary of the directive tests  
        - see `test/output/PhpFeatures.md` or view in the terminal  
    - `phptest -test Directives -run Directive.TestName`   
        - add `-version 0.1` to skip new directive handling. Default in tests is `-version 1.0` which has new signal-based functionality. Default in production is `0.1` and in code use `$lexer->version \Tlf\Lexer\Versions::_1` for signal-based.  
        - add `-stop_loop 50` to stop after the 50th loop  
        - see [`test/src/Php`](/test/src/Php/) to create new directive test  
        - see [`test/Tester.php`](/test/Tester.php) - see the `$sample_thingies` at the top for an example. And see `runDirectiveTests()`, though idr how it works.  
  
## TODO  
- parse expressions  
- Document it better  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# Grammar Commands  
These commands are available for your directives to execute. See an example at [docs/GrammarExample.md](/docs/GrammarExample.md). See instructions for writing a grammar at [docs/GrammarWriting.md](/docs/GrammarWriting.md)  
  
In the internals, there are two types of commands.   
- switch/case commands, which generally have a simple or small implementation.   
- mapped commands, which point a command to a method (rather than the switch-case)  
      
## Mapped commands  
The key points to a method on the `$lexer` instance, but they're written in the `MappedMethods` trait. See [code/Lexer/MappedMethods.php](/code/Lexer/MappedMethods.php)  
```php  
[  
    'directive.then'=>'cmdThen',  
    'then'=>'cmdThen',  
    'then.pop'=>'cmdThenPop',  
  
    'match'=>'cmdMatch',  
    'buffer.match'=>'cmdMatch',  
  
    'buffer.notin'=>'cmdBuffer_notin',  
  
    'ast.new'=>'cmdAst_new',  
];  
```  
  
## `switch/case` commands   
These are the exact implementations of the commands from [code/Lexer/Instructions.php](/code/Lexer/Instructions.php)  
```php  
switch ($command){  
    ///  
    // comands for debugging  
    ///  
    case "debug.die":  
    case "die":  
        var_dump($args);  
        exit;  
        break;  
    case "debug.print":  
    case "print":  
        var_dump($args);  
        break;  
    /**  
     * Run commands of another directive. Does not run 'match' by default  
     *  
     * @arg :directive.isn  
     * @arg literal string 'match' to keep the match command from the inherited directive  
     *  
     * @example directive.inherit :varchars.start  
     */  
    case "directive.inherit":  
    case "inherit":  
        $arg2 = $args[1]??'';  
        $parts = explode('.', $arg1);  
        $name = $parts[0];  
        $isn = $parts[1];  
        $directives = $directive->_grammar->getDirectives($name);  
        foreach ($directives as $d){  
            if ($arg2!=='match'){  
                unset($d->$isn['match']);  
            }  
            // print_r($d  
            $this->processInstructions($d, $isn, $directiveList);  
            if ($arg2==='match'&&isset($d->$isn['_matches'])){  
                $directive->$isn['_matches'] = $d->$isn['_matches'];  
            }  
        }  
        echo "\n\033[0;32mContinue ".$directive->_name."\033[0m";  
        break;  
    //  
    // commands with non-namespaced shorthands  
    //  
    case "directive.start":  
    case "start":  
        $this->directiveStarted($directive);  
        break;  
    case "directive.stop":  
    case "stop":  
        $this->directiveStopped($directive);  
        break;  
    case "token.rewind":  
    case "rewind":  
        $token->rewind($arg1);  
        break;  
    case "token.forward":  
    case "forward":  
        $token->forward($arg1);  
        break;  
    /**  
     * Halt execution of current directive (don't run its following instructions). Useful for preventing overrides from being executed  
     */  
    case "directive.halt":  
    case "halt":  
        $this->haltInstructions();  
        break;  
    case "halt.all":  
        // @TODO maybe I should also haltInstruction, but ... I shouldn't break things.  
        $this->haltAll();  
        break;  
    //  
    // namespaced commands  
    //  
    case "previous.append":  
        if (!is_array($arg1))$arg1 = [$arg1];  
        foreach ($arg1 as $index=>$keyForPrevious){  
            $this->appendToPrevious($keyForPrevious, $token->buffer());  
        }  
        break;  
    case "previous.set":  
        $value = $args[1] ?? $token->buffer();  
        if ($value ===true)$value = $token->buffer();  
        $this->setPrevious($arg1, $value);  
        break;  
    case "directive.stop_others":  
        foreach ($directiveList['started'] as $started){  
            if ($started!=$directive){  
                $this->directiveStopped($started, $list);  
            }  
        }  
        break;  
    case "directive.pop":  
        $arg1 = (int)$arg1;  
        if ($arg1===0)echo "\n    --no directives popped.";  
        while ($arg1-- > 0){  
            $this->popDirectivesLayer();  
        }  
        break;  
  
    //  
    // buffer commands  
    //  
    case "buffer.clear":  
        $token->clearBuffer();  
        break;  
    case "buffer.clearNext":  
        $amount = (int)$arg1;  
        $remove = 0;  
        while ($amount-->0){  
            if ($token->next())$remove++;  
        }  
        $token->setBuffer(substr($token->buffer(),0,-$remove));  
        break;  
    case "buffer.appendChar":  
        $token->setBuffer($token->buffer() . $arg1);  
        break;  
    //  
    // ast commands  
    //  
    case "ast.pop":  
        $this->popHead();  
        break;  
    case "ast.set":  
        if (isset($args[1])){  
            $value = $this->executeMethodString($args[1]);  
        } else $value = $token->buffer();  
        $this->getHead()->set($arg1, $value);  
        break;  
    /**  
     * Save the currrent buffer to the given key  
     * @arg key to push to  
     */  
    case "ast.push":  
        $key = $arg1;  
        $toPush = $token->buffer();  
        $ast = $this->getHead();  
        $ast->add($key,$toPush);  
        break;  
    case "ast.append":  
        $key = $arg1;  
        if (isset($args[1])&&is_string($args[1])){  
            var_dump($args[1]);  
            $value = $this->executeMethodString($args[1]);  
        } else $value = $token->buffer();  
        $ast = $this->getHead();  
        $src = $ast->get($key);  
        $new = $src . $value;  
        $ast->set($key, $new);  
        break;  
  
    default:  
        throw new \Exception("\nAction '$command' not handled yet. Maybe it needs to be a callable. Prepend `this:` to call a method on your grammar.");  
}  
```  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# Lexer Examples  
  
## Lex a file  
```php  
<?php  
$lexer = new \Tlf\Lexer();  
$lexer->useCache = false; // cache is disabled only for testing  
$lexer->addGrammar($phpGrammar = new \Tlf\Lexer\PhpGrammar());  
  
$ast = $lexer->lexFile(dirname(__DIR__).'/php/SampleClass.php');  
  
// An array detailing the file   
$tree = $ast->getTree();   
```  
See [test/input/php/lex/SampleClass.php](/test/input/php/lex/SampleClass.php) for the input file and [test/output/php/tree/SampleClass.js](/test/output/php/tree/SampleClass.js) for the output `$tree`.  
  
## Lex a string  
This example is a bit more involved. `Docblock` is generally added by a programming language's grammar, so `Docblock` does not automatically start being listened for, the way `<?php` would be with the PhpGrammar.  
```php  
$lexer = new \Tlf\Lexer();  
$docGrammar = new \Tlf\Lexer\DocblockGrammar();  
$lexer->addGrammar($docGrammar);  
$lexer->addDirective($docGrammar->getDirectives(':/*')['/*']);  
$str = "/** I am docblock */";  
$ast = $lexer->lex($str);  
  
$tree = $ast->getTree();  
$actual = $tree['docblock'][0];  
$expect = [  
    'type'=>'docblock',  
    'description'=>'I am docblock',  
];  
```  
The root ast contains the string, which we're not really interested in.  
  
## Lex with your own root ast  
This is basically what happens when you lex a file, EXCEPT `lexFile()` automatically handles caching, so subsequent runs on the same unchanged file will be loaded from cache. This approach ignores the cache completely.  
```php  
<?php  
$lexer = new \Tlf\Lexer();  
$phpGrammar = new \Tlf\Lexer\PhpGrammar();  
$lexer->addGrammar($phpGrammar);  
  
// set up the ast  
$ast = new \Tlf\Lexer\Ast('code');  
$ast->set ('language', 'php');  
$code = '<?php class Abc extends Alphabet {}';  
$ast->set('src', $code);  
  
  
$ast = $lexer->lex($code, $ast);  
$actual = $ast->getTree();  
$expect = [  
    'type'=>'code',  
    'language'=>'php',  
    'src'=>$code,  
    'class'=>[  
        0=>[  
            'type'=>'class',  
            'docblock'=>'',  
            'namespace'=>'',  
            'name'=>'Abc',  
            'declaration'=>'class Abc extends Alphabet ',  
        ],  
    ],  
];  
```  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# Extending the lexer  
Convert code or other text into a structured tree (multi-dimensional array).  
  
In This File:  
- create a grammar with directives & handler functions  
- test a grammar  
- a complex directive that builds an AST without php  
- How to write an extension  
  
## Extending  
To extend the lexer, we will do four things, iteratively.   
1. Create a Grammar  
2. Create an array of Directives  
3. Create a trait for callbacks Directives use  
4. Write Directive tests  
  
To run it, I suggest using your preferred test suite. Though, the built-in directive tests (composer) require `taeluf/tester`  
  
### 1. Grammar  
We'll be recreating part of the Bash Grammar.   
  
```php  
<?php  
  
class MyBashGrammar extends \Tlf\Lexer\Grammar {  
  
    use MyBashGrammarCallbacks;  
  
    public function getNamespace(){return 'mybash';}  
  
    protected $directives = [];  
  
    public function __construct(){  
        $file = file_get_contents(__DIR__.'/directives.php');  
        $directives = require($file);  
        $this->directives = $directives;  
        // @tip use `array_merge()` to load directives from multiple files  
    }  
  
    public function onLexerStart($lexer,$file,$token){  
        // if you have any additional setup to do  
    }  
}  
```  
  
### 2. Directives  
**directives.php**  
```  
return [  
        'root'=>[  
            'is'=>[  
                // ':comment',  
                ':docblock',  
                ':function',  
            ],  
        ],  
  
        'docblock'=>[  
            'start'=>[  
                'match'=>'##',  
            ],  
            'stop'=>[  
                'match'=>'/(^\s*[^\#])/m',  
                'rewind 2',  
                'this:handleDocblockEnd',  
                'buffer.clear',  
                // 'forward 2'  
            ]  
        ],  
  
        'function'=>[  
            'start'=>[  
                'match'=>'/(?:function\s+)?([a-zA-Z\_0-9]*)(?:(?:\s*\(\))|\s+)\{/',  
                'this:handleFunction',  
                'stop',  
                'buffer.clear',  
            ]  
        ],  
        // an additional 'comment' directive is below  
    ];  
```  
  
### 3. Callbacks   
We'll write a trait with function to handle directive calls. You'll notice `this:handleFunction` in the directives above. That will call `handleFunction(...)` on your trait below.   
  
```php  
<?php  
trait MyBashGrammarCallbacks {  
  
    public function handleDocblockEnd($lexer, $ast, $token, $directive){  
        $block = $token->buffer();  
        $clean_input = preg_replace('/^\s*#+/m','',$block);  
        $db_grammar = new \Tlf\Lexer\DocblockGrammar();  
        $ast = $db_grammar->buildAstWithAttributes(explode("\n",$clean_input));  
        $lexer->setPrevious('docblock', $ast);  
    }  
  
    public function handleFunction($lexer, $ast, $token, $directive){  
        // $func_name = $token->match(1);  
        $func = new \Tlf\Lexer\Ast('function');  
        $func->name = $token->match(1);  
        $func->docblock = $lexer->previous('docblock');  
        $lexer->getHead()->add('function', $func);  
    }  
```  
  
### 4. Directive Tests  
You need to be using `taeluf/tester` for built-in tests to work  
```php  
<?php  
  
class MyBashGrammarTest extends extends \Tlf\Lexer\Test\Tester {  
  
    protected $my_tests = [  
        'Comments'=>[  
            // the 'comment' directive is below and can be added to the `MyGrammar` that is above  
            'start'=>'comment', // t  
            'input'=>"var=\"abc\"\n#I am a comment\nvarb=\"def\"",  
            'expect'=>[  
                "comments"=>[  
                    0=>[  
                        'type'=>'comment',  
                        'src'=>'#I am a comment',  
                        'description'=> "I am a comment",  
                    ]  
                ],  
            ],  
        ],  
    ];  
  
    public function testBashDirectives(){  
        $myGrammar = new \MyGrammar();  
        $grammars = [  
            $myGrammar  
        ];  
        // $docGram->buildDirectives();  
  
        $this->runDirectiveTests($grammars, $this->my_tests);  
    }  
  
}  
```  
  
## A more complex directive  
```php  
<?php  
// you would put this in your directives class  
$directives = [  
    'comment'=>[  
        'start'=>[  
            'match'=>'/#[^\#]/',  
            'rewind 2',  
            'buffer.clear',  
            'forward 1',  
            // you can create & modify ASTs all in the directive code, without php  
            'ast.new'=>[  
                '_addto'=>'comments',  
                '_type'=>'comment',  
                'src'=>'_token:buffer',  
            ],  
            'buffer.clear //again',  
        ],  
  
        // `match` gets called for each char after `start`  
        'match'=>[  
            'match'=>'/@[a-zA-Z0-9]/', // match an @attribute  
            'rewind 1',  
            'ast.append src',  
            'rewind 1 // again',  
            'ast.append description',  
            'forward 2',  
            'buffer.clear',  
            'then :+'=>[ // the :+ means that we're defining a new directive rather than referencing an existing one  
                'start'=>[  
                    //just immediately start  
                    'match'=>'',  
                    'rewind 1',  
                ],  
                'stop'=>[  
                    // i honestly don't know why I have this here.  
                    'match'=>'/(\\r|\\n)/',  
                    'rewind 1',  
                    'ast.append src',  
                    'buffer.clear',  
                ]  
            ],  
  
        ],  
        'stop'=>[  
            'match'=>'/(\\r|\\n)/',  
            'rewind'=>1,  
            'ast.append src',  
            'ast.append description',  
            'forward'=>1,  
            'buffer.clear',  
        ],  
    ]  
];  
```  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# Example  
This is a really simple example of a functional, tested grammar. They get much more complex.  
- Get further grammar-writing instructions in [docs/GrammarWriting.md](/docs/GrammarWriting.md)  
- Look at the commands available in [docs/GrammarCommands.md](/docs/GrammarCommands.md)  
  
  
## StarterGrammar's Directives  
Most grammars will have more directives & multiple traits to facilitate organization. This example only uses one trait.  
```php  
'/home/reed/data/owner/Reed/projects/php/Lexer/code/Starter/OtherDirectives.php' is not a file.  
```  
  
## StarterGrammar  
See that directives are built during `onGrammarAdded()` from the traits.  
```php  
'/home/reed/data/owner/Reed/projects/php/Lexer/code/Starter/StarterGrammar.php' is not a file.  
```  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# Php Lexer  
A declarative lexer seamlessly hooking into php functions, building ASTs for multiple languages.  
  
## Development Status / Roadmap   
### May 13, 2022 Update:  
Branch `v0.8` is highly tested for PhpGrammar. It does not support PHP 8.0+ features. Most other Php Features are supported, but likely not all.   
  
The documentation is ... not good.  
  
This project is in use by [Code Scrawl](https://tluf.me/php/code-scrawl) & will be further developed as i personally need it to be. For example today (may 13), i added support for `use ($var)` on anonymous functions, because i was unable to generate proper documentation for [Lil Db](https://tluf.me/php/lildb)  
  
I dream, one day, of supporting many languages & possibly transpilation. I doubt that dream will be realized.   
  
I don't plan to significantly change the internal implementation of the lexer or grammars. I think it could be a lot better, but this would require serious development time I'm not likely to give to this project.  
  
## Install  
For development, it depends upon [taeluf/php/php-tests](https://gitlab.com/taeluf/php/php-tests), which is installed via composer and [taeluf/php/CodeScrawl](https://gitlab.com/taeluf/php/CodeScrawl), which is NOT installed via composer because of circular dependency sometimes causing havoc.  
```bash  
composer require taeluf/lexer v0.8.x-dev   
```  
or in your `composer.json`  
```json  
{"require":{ "taeluf/lexer": "v0.8.x-dev"}}  
```  
  
  
## Generate an AST  
See [docs/Examples.md](/docs/Examples.md) for more examples  
Example:  
```php  
$lexer = new \Tlf\Lexer();  
$lexer->useCache = false; // cache is disabled only for testing  
$lexer->addGrammar($phpGrammar = new \Tlf\Lexer\PhpGrammar());  
  
$ast = $lexer->lexFile(dirname(__DIR__).'/php/SampleClass.php');  
  
// An array detailing the file   
$tree = $ast->getTree();   
```  
See [test/input/php/lex/SampleClass.php](/test/input/php/lex/SampleClass.php) for the input file and [test/output/php/tree/SampleClass.js](/test/output/php/tree/SampleClass.js) for the output `$tree`.  
  
## Status of Grammars  
- Php: Early implementation that catches most class information (in a lazy form) but may have bugs  
- Docblock: Currently handles `/*` style, cleans up indentation, removes leading `*` from each line, and processes simple attributes (start a line with `  * @something description`).  
    - Coming soon (maybe): Processsing of `@‌method_attributes(arg1,arg2)`  
- Bash: Coming soon, but will only catch function declarations & their docblocks.   
    - the docblocks start with `##` and each subsequent line must start with whitespace then `#` or just `#`.  
    - I'm writing it so i can document [git-bent](https://tluf.me/git-bent)  
- Javascript: Coming soon, but will only catch docblocks, classes, methods, static functions, and mayyybee properties on classes.   
    - I'm writing it so i can document [js-autowire](https://tluf.me/js-autowire)  
  
## Write a Grammar  
A Grammar is an array declaration of `directives` that define `instructions`. Those `instructions` may call built-in `command`s or may explicitly call methods on a grammar, the lexer, the token, or the head ast.  
  
Writing a grammar is very involved, so please see [docs/GrammarWriting.md](/docs/GrammarWriting.md) for details.  
  
## Warning  
- Sometimes when you run the lexer, there will be `echo`d output. Use output buffering if you want to stop this.  
- During `onLexerEnd(...)`, Docblock does `$ast->add('docblock', $lexer->previous('docblock'))` IF there's a previous docblock set.  
  
## Contribute  
- Need features? Check out the `Status.md` document and see what needs to be done. Open up an issue if you're working on something, so we don't double efforts.  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# Parse Code into an AST  
Docs to-be-written  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# Lexer  
Parse code and other text into structured trees.  
  
The Lexer loops over the characters in a string, and processes them through Grammars to generate Asymmetrical Syntax Trees (AST) - Basically just a multi-dimensional array that describes the code.   
  
## Documentation  
- Installation & Getting Started are below  
- [Create a Parser](docs/CreateParser.md) - Create a language parser that builds an AST, or modify an existing parser.  
<!--   
- [Parse Code / Create AST](docs/ParseCode.md) - Parse your code into an AST using an existing language parser.  
- [Use ASTs](docs/UseAST.md) - Use an AST to retrieve classes, methods, properties, and more.  
-->  
  
### Other/Old Documentation  
- Extend Lexer - Create your own grammars to support new languages  
    - [Getting Started](/docs/GettingStarted.md) - Write a grammar class, create directives, and test your grammar.  
    - [Tips & Overview](/docs/Tips.md) - How To tips & troubleshooting  
    - [Directive Commands](/docs/DirectiveCommands.md) - Commands you can use in your directives.  
    - [Extra Examples](/docs/Examples.md)   
    - [Testing your grammar](/docs/Testing.md)  
- [docs/api/code/](/docs/api/code/) - Generated api documentation   
- [Architecture](/docs/Architecture.md)  
- Development - Further develop this library  
    - [Development Status & Notes](/Status.md) - The current state of development, and common development tips.  
    - [Php Grammar](/docs/Development/PhpGrammar.md) - How to further develop the PHP Grammar.  
    - [Changelog](/docs/Changelog.md)  
- Defunct documentation  
    - [Grammar Examples](/docs/GrammarExample.md)  
    - [docs/OldReadme1.md](/docs/OldReadme1.md) - An old README that might have useful information.  
  
## Supported Languages  
Additional language support can be added through new grammars. See [docs/Extend.md](/docs/Extend.md).  
- Docblocks: Parses standard docblocks (`/** */`) for description and `@param`. Somewhat language independent.  
- Php: Very Good (php 7.4 - 8.2)  
- Bash: Broken. There was an old grammar which would parse functions and doclbocks (using `##\n#`), but it has not been returned to functionality with the current lexer.  
  
## Install  
```bash  
composer require taeluf/lexer v0.8.x-dev   
```  
or in your `composer.json`  
```json  
{"require":{ "taeluf/lexer": "v0.8.x-dev"}}  
```  
  
  
  
## Parse with CLI  
This prints an Asymmetrical Syntax Tree (AST) as JSON.  
```bash  
# only file path is required  
bin/lex file rel/path/to/file.php -nocache -debug -stop_at -1  
```  
  
## Basic Usage  
  
For built-in grammars, it is easiest to use the helper class.   
  
```php  
<?php  
$file = '/path/to/file/';  
$helper = new \Tlf\Lexer\Helper();  
$lexer = $helper->get_lexer_for_file($full_path); // \Tlf\Lexer  
  
# These are the default settings  
$lexer->useCache = true; // set false to disable caching  
$lexer->debug = false; // set true to show debug messages  
$lexer->stop_loop = -1; // set to a positive int to stop processing & print current lexer status (for debugging)  
  
$ast = $lexer->lexFile($full_path); // \Tlf\Lexer\Ast  
  
print_r($ast->getTree()); // array  
```  
  
## Example Tree  
Grammars determine tree structure. This is a php file in this repo. See [code/Ast/StringAst.php](/code/Ast/StringAst.php). This example only has one method and no properties. From the root of this repo, run `bin/lex file code/Lexer.php` for an example of a larger class.  
```json  
{  
    "type": "file",  
    "ext": "php",  
    "name": "StringAst",  
    "path": "\/path-to-downloads-dir\/Lexer\/code\/Ast\/StringAst.php",  
    "namespace": {  
        "type": "namespace",  
        "name": "Tlf\\Lexer",  
        "declaration": "namespace Tlf\\Lexer;",  
        "class": [  
            {  
                "type": "class",  
                "namespace": "Tlf\\Lexer",  
                "fqn": "Tlf\\Lexer\\StringAst",  
                "name": "StringAst",  
                "extends": "Ast",  
                "declaration": "class StringAst extends Ast",  
                "methods": [  
                    {  
                        "type": "method",  
                        "args": [  
                            {  
                                "type": "arg",  
                                "name": "sourceTree",  
                                "value": "null",  
                                "declaration": "$sourceTree = null"  
                            }  
                        ],  
                        "modifiers": [  
                            "public"  
                        ],  
                        "name": "getTree",  
                        "body": "return $this->get('value');",  
                        "declaration": "public function getTree($sourceTree = null)"  
                    }  
                ]  
            }  
        ]  
    }  
}  
```  
  
A php class property looks like:  
```json  
{  
    "type": "property",  
    "modifiers": [  
        "public",  
        "int"  
    ],  
    "docblock": {  
        "type": "docblock",  
        "description": "The loop we're on. 0 means not started. 1 means we're executing the first loop. 2 means 2nd loop, etc."  
    },  
    "name": "loop_count",  
    "value": "0",  
    "declaration": "public int $loop_count = 0;"  
}  
```  
  
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# Grammar Testing  
Unit testing is the best way I've found to really develop a grammar. It allows you to focus on very specific pieces of the grammar at a time, then later put it all together by parsing an entire document.  
  
This library depends upon [php-tests](https://tluf.me/php-tests) for testing.  
  
Links:  
- Writing a Grammar: [docs/GrammarWriting.md](/docs/GrammarWriting.md)  
- Grammar Example: [docs/GrammarExample.md](/docs/GrammarExample.md)  
- Grammar Commands: [docs/GrammarCommands.md](/docs/GrammarCommands.md)  
  
## Howto  
1. Extend `\Tlf\Lexer\Test\Tester` which extends from `\Tlf\Tester` or copy the methods from it & modify as needed for a different testing library.  
2. Implement a `testGrammarName()` method that uses the test runner  
3. Implement the data structure for defining the unit tests.  
  
Example of `2.`:  
```php  
Template 'methods.testPhpDirectives.definition' does not exist. {  
Template 'methods.testPhpDirectives.body' does not exist.  
}  
```  
  
Example of  `3.`:  
-- whatever goes here  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# Write a Grammar  
A Grammar is an array declaration of `directives` that define `instructions`. Those `instructions` may call built-in commands or may explicitly call methods on the grammar, the lexer, the token, or the head ast.  
  
**First:** Look at the example in [docs/GrammarExample.md](/docs/GrammarExample.md)  
**Then:**  
- Read through this document  
- Look at the commands available in [docs/GrammarCommands.md](/docs/GrammarCommands.md)  
- Learn how to test a grammar. See [docs/GrammarTesting.md](/docs/GrammarTesting.md)  
- Review the Architecture, if you like. See [docs/Architecture.md](/docs/Architecture.md)  
  
  
## Tips  
- `$grammar->getDirectives(':directive_name')` returns an associative array of directives.  
- `then` directive:  
    - You can pass a directive declaration to `then`, like `then :name=>['start'=>[/*instructions*/]]` to override the target directive  
    - You can pass `:directive_name.stop` to use the `stop` as `start`.  
        - idk if you can override in this case, but I think you can  
- `then.pop :directive_name X` lets you pop X layers when `:directive_name` is matched.   
- `inherit :directive.stop` or `inherit :directive.start` lets you auto-execute all commands from the named directive & instruction set.  
- Pass `:+name` to `then` to create a new directive, rather than loading from/merging with an existing directive.  
    - `:_blank` and `:_blank-name` are deprecated alternatives  
  
## Troubleshooting Tips  
- Always `rewind` BEFORE `buffer.clear`, or no rewind is performed.  
- `match` has special handling & the recommended style is `'match'=>'string'` or `'match'=>'/regex/'`. The alternate styles like `match string` or `match /regex/` *should* work, but might make problems.  
- set `$lexer->useCache` to false to disable cache.   
- `$lexer->debug = true` to print debug information  
- `$lexer->stop_loop = 30` to stop processsing on loop 30 & print debug info.  
- `rewind` can cause an infinite loop. Ex: The instructions `match == :` & `rewind == 1` on the same directive. The `:` is matched, then we rewind 1, then the `:` is matched & we rewind 1 & so on.   
- `stop` instruction ALWAYS acts upon the top directive list at the time it is executed. If the current directive is not in the directive list's `started`, then nothing happens. Meaning it is NOT added to the `unstarted` list.  
- `directive.inherit` instruction ALWAYS ignores the `match` instruction of the inherited directive.   
  
## Recommended structure  
To keep files smaller & more organized, I keep my directives inside traits that my grammar `use`s.  
- `MyGrammarClass extends \Tlf\Lexer\Grammar`  
    - `use MyGrammar\Main_Directives`  
    - `use MyGrammar\Comments_Directives`,  
    - `function buildDirectives()`: `$this->directives = array_merge( comments_directives, main_directives)`  
        - override `onGrammarAdded()` to implement this  
    - `onLexerStart()`/`onLexerEnd()` if needed  
    - methods your directives will call  
  
## Structure of directives  
The form is `$directives -> directive_name -> instruction set -> array of instructions`. There are two instruction sets `start`, `stop`. There is a third instruction set, but I plan to remove or change it.  
```php  
<?php  
protected $directives = [  
    'php_open'=>[  
        'start'=>[  
            'match'=>'<?php',   
            //instructions go here  
        ],  
        'stop'=>[  
            'match'=>'?>',  
            //instructions go here  
        ],  
    ],  
]  
```  
1. When `<?php` matches, `php_open` becomes `started`.   
2. On subsequent loops `stop` will be checked.   
3. When `?>` matches, `php_open` becomes stopped.  
  
### Notes  
- The subsequent instructions only execute if `match` passes.  
- `match` is NOT a required instruction   
- `match` does NOT have to be the first instruction  
- `match` has a lot of special handling to handle merging of overridden directives.  
  
## Declaring instructions  
Many commands have a shorthand and a longhand like `stop` and `directive.stop`  
Examples:  
- `'command arg1 arg2' => 'arg3'`  
- `'command arg1 arg2 //comment' => 'arg3'`  
- `'command arg1 ...' => ['arg2', 'arg3', 'arg4'] `  
  
Instead of a `command`, you can use a `namespace:method` to directly call a method on an object from internally defined namespace targets or from one of the available grammars.  
The available namespace targets are defined here:  
```php  
$namespaceTargets = [  
    'lexer'=>$this,  
    'token'=>$this->token,  
    'ast'=>$this->getHead(),  
];  
$grammarTargets = $this->grammars;  
$grammarTargets['this'] = $directive->_grammar ?? null;  
```  
  
## Special object-calling  
Some commands, like `ast.new` allow you give values that call objects+methods in much the same way as instructions. This is on a command-by-command basis  
  
The format is `_namespace:method arg1 arg2 arg3`  
Example:  
```php  
['ast.new'=>[  
    '_type'=>'class',  
    'name'=> '_token:buffer',  
    'docblock'=> '_lexer:unsetPrevious docblock'  
    ]  
]  
```  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# Use an AST   
Documentation to be written  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Ast.php  
  
# class Tlf\Lexer\Ast  
  
See source code at [/src/Ast.php](/src/Ast.php)  
  
## Constants  
  
## Properties  
- `protected $_path;`   
- `protected $_name;`   
- `protected $_ext;`   
- `public $_source;`   
- `protected $_tree = [];`   
- `public $_type;`   
- `protected $passthrough = [];`   
  
## Methods   
- `public function __construct($type, $startingTree=[])`   
- `public function removeAst($key, $ast)` Removes an ast if it is setto/addedto this ast. If $key points to an empty array, then $key is unset from this ast  
  
- `public function set($key,$value)` Set $value to $key, overwriting any previously set value  
- `public function append($key, $value)`   
- `public function setAll(array $keyValues)`   
- `public function add($key,$value, $subKey=false)` Add $value to an array  
- `public function push($key, $value, $subKey=false)` Alias for add   
- `public function has(string $key): bool` Check if key is set on this ast.  
- `public function get($key)`   
- `public function getAll()` Get the current tree as-is (asts are still asts)  
- `public function addPassthrough($ast)`   
- `public function getTree($sourceTree=null)` Get the tree as a pure array  
- `public function setTree($astTree)`   
- `public function __get($prop)`   
- `public function __set($prop, $value)`   
- `public function __isset($prop)`   
- `static public function __set_state($array)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Ast/ArrayAst.php  
  
# class Tlf\Lexer\ArrayAst  
  
See source code at [/src/Ast/ArrayAst.php](/src/Ast/ArrayAst.php)  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function getTree($sourceTree = null)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Ast/JsonAst.php  
  
# class Tlf\Lexer\JsonAst  
  
See source code at [/src/Ast/JsonAst.php](/src/Ast/JsonAst.php)  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function getJsonData()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Ast/StringAst.php  
  
# class Tlf\Lexer\StringAst  
  
See source code at [/src/Ast/StringAst.php](/src/Ast/StringAst.php)  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function getTree($sourceTree = null)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Bash/BashGrammar.php  
  
# class Tlf\Lexer\BashGrammar  
This is not for actual parsing yet. This is for design work. The $directives array & 'php_open' and 'namespace' are design aspects I'm interested in implementing at some point... maybe  
See source code at [/src/Bash/BashGrammar.php](/src/Bash/BashGrammar.php)  
  
## Constants  
  
## Properties  
- `protected $expect = ['html', 'php_open'];`   
- `public $directives;` Filled by traits  
- `public $notin = [  
        'asfdasdfkeyword'=>[  
                        '__halt_compiler', 'abstract', 'and', 'array', 'as', 'break', 'callable', 'case', 'catch', 'class', 'clone', 'const', 'continue', 'declare', 'default', 'die', 'do', 'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'eval', 'exit', 'extends', 'final', 'for', 'foreach', 'function', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'isset', 'list', 'namespace', 'new', 'or', 'print', 'private', 'protected', 'public', 'require', 'require_once', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'unset', 'use', 'var', 'while', 'xor'  
        ],  
    ];`   
  
## Methods   
- `public function getNamespace()`   
- `public function __construct()`   
- `public function onLexerStart($lexer,$file,$token)`   
- `public function handleDocblockEnd($lexer, $ast, $token, $directive)`   
- `public function handleFunction($lexer, $ast, $token, $directive)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Docblock/DocblockGrammar.defunct.php  
  
# class Tlf\Lexer\DocblockGrammar_Defunct  
I ran into a lot of issues while writing this grammar, so I took a completely different approach.  
  
I think there's some useful stuff here, but if a new Docblock Grammar is to be written, I think this should all be scrapped & a new setup designe.  
  
Be sure to read the notes in ` I ran into a lot of issues while writing this grammar, so I took a completely different approach.  
  
I think there's some useful stuff here, but if a new Docblock Grammar is to be written, I think this should all be scrapped & a new setup designe.  
  
Be sure to read the notes in `.dev` folder before developing this further!  
See source code at [/src/Docblock/DocblockGrammar.defunct.php](/src/Docblock/DocblockGrammar.defunct.php)  
  
## Constants  
  
## Properties  
- `public $directives = [  
        '/*'=>[  
            'start'=>[  
                'match'=>'/\\/\*/',  
                'buffer.clear',  
                'ast.new'=>[  
                    '_type'=>'docblock',  
                    '_addto'=>false,  
                                        '_setPrevious'=>'docblock',  
                ],  
                'then :@',  
                'then :\n',  
                'then :*',  
                'then :!*',  
                'then :*/'=>[  
                    'start'=>[  
                        'rewind 2',  
                        'ast.append description',  
                        'buffer.clear',  
                    ],  
                ],  
            ],  
            'stop'=>[  
                'match'=> '*/',  
                                                'lexer:popHead'  
            ]  
        ],  
        '*/'=>[  
            'start'=>[  
                'match'=>'*/',  
                'directive.pop 1',  
                'rewind 1',  
            ]  
        ],  
        '\n'=>[  
            'start'=>[  
                'match'=>'/(\r|\n)/',  
                'then :*',  
                'then :!*',  
            ],  
        ],  
        '*'=>[  
            'start'=>[  
                'match'=>"/\*[^\/]/",  
                                'rewind 2',  
                'buffer.clearNext 1',  
                'buffer.appendChar'=>' ',  
                'forward 1',  
                'stop',  
            ]  
        ],  
        '!*'=>[  
            'start'=>[  
                'match'=>'/[^\s\*]$/',  
                'rewind 1',  
                'buffer.clear',  
                'then :\n' =>[  
                    'start'=>[  
                                                'ast.append description',  
                        'buffer.clear',  
                                            ]  
                ],  
                'then :@',  
                'then :*/'=>[  
                    'start'=>[  
                        'rewind 2',  
                        'ast.append description',  
                        'buffer.clear'  
                    ],  
                ],  
            ],  
            'stop'=>[  
                'match'=>'*/',  
                'rewind 1',  
            ],  
        ],  
        '@'=>[  
            'start'=>[  
                'match'=>'@',  
            ]  
        ]  
  
    ];`   
  
## Methods   
- `public function onGrammarAdded($lexer)`   
- `public function onLexerStart($lexer, $ast, $token)`   
- `public function onLexerEnd($lexer, $ast, $token)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Docblock/DocblockGrammar.php  
  
# class Tlf\Lexer\DocblockGrammar  
  
See source code at [/src/Docblock/DocblockGrammar.php](/src/Docblock/DocblockGrammar.php)  
  
## Constants  
  
## Properties  
- `public $directives = [  
  
        '/*'=>[  
            'start'=>[  
                'match'=>'/\\/\*/',  
                'buffer.clear',  
            ],  
            'stop'=>[  
                'match'=>'*/',  
                                'rewind 2',  
                'this:processDocblock',  
                'forward 2',  
                'buffer.clear',  
            ]  
        ],  
    ];`   
  
## Methods   
- `public function getNamespace()`   
- `public function onGrammarAdded($lexer)`   
- `public function onLexerStart($lexer, $ast, $token)`   
- `public function onLexerEnd($lexer, $ast, $token)`   
- `public function processDocblock($lexer, $ast, $token, $directive)`   
- `public function buildAstWithAttributes($lines)`   
- `public function cleanIndentation($body)` Remove indentation and * from docblock body   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Grammar.php  
  
# class Tlf\Lexer\Grammar  
  
See source code at [/src/Grammar.php](/src/Grammar.php)  
  
## Constants  
  
## Properties  
- `protected $blankCount = 0;`   
- `public $directives = [];` The actual array of directives, built during onGrammarAdded()  
- `protected \Tlf\Lexer $lexer;` the lexer currently running  
  
## Methods   
- `public function lexer_started($lexer, $ast, $token)`   
- `public function setLexer($lexer)`   
- `public function getNamespace()` Get a namespace prefix to use for specifying what directive to target  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Helper.php  
  
# class Tlf\Lexer\Helper  
  
See source code at [/src/Helper.php](/src/Helper.php)  
  
## Constants  
  
## Properties  
- `public array $grammars = [  
        'docblock'=>'Tlf\\Lexer\DocblockGrammar',  
        'php'=>'Tlf\\Lexer\\PhpGrammar',  
        'bash'=>'Tlf\\Lexer\\BashGrammar',  
    ];` Array of grammar classes  
  
## Methods   
- `public function getAstFromFile(string $file_path): \Tlf\Lexer\Ast` Create a   
- `public function get_lexer_for(string $language_ext): \Tlf\Lexer` Get a Lexer initialized with the correct grammars.  
  
- `public function get_lexer_for_file(string $file_path): \Tlf\Lexer`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Lexer.php  
  
# class Tlf\Lexer  
Used to process a string into an Asymmetrical Syntax Tree (AST)  
See source code at [/src/Lexer.php](/src/Lexer.php)  
  
## Constants  
  
## Properties  
- `public float $version = \Tlf\Lexer\Versions_old;`   
- `public bool $debug = false;` set true to show debug messages  
- `public int $loop_count = 0;` The loop we're on. 0 means not started. 1 means we're executing the first loop. 2 means 2nd loop, etc.  
- `public bool $useCache = true;` Whether to load from & save to the cache or not.  
- `public $token = null;` The token currently being processed  
- `protected $grammarListForCache = null;` array of grammar class names & their file's last mtime  
- `public $stop_loop = -1;` the loop to stop processing on. Used for debugging, when writing a grammar.  
- `public string $signal = null;` A string that can be set & checked by handlers, to determine what operations should be completed.  
  
## Methods   
- `public function abort()` stop lexing  
- `public function haltAll()`   
- `public function continueAll()`   
- `public function haltInstructions()`   
- `public function continueInstructions()`   
- `public function previous($key)`   
- `public function setPrevious($key, $value)`   
- `public function appendToPrevious($key, $value)`   
- `public function unsetPrevious($key)`   
- `public function clearBuffer()`   
- `public function getToken()`   
- `public function addGrammar(object $grammar, string $namespace=null, $executeOnAddtrue)`   
- `public function getGrammar(string $namespace)`   
- `public function setHead($ast)` Append an ast to top of stack.  
  
- `public function popHead(): \Tlf\Lexer\Ast` Get top-level ast and remove it from the stack. If only one ast, then return it and leave at bottom of stack.  
  
- `public function getHead(): \Tlf\Lexer\Ast` Get top-level AST from stack.   
  
See Internals::$head  
  
- `public function rootAst(): \Tlf\Lexer\Ast` Get bottom-level AST from stack.  
  
See Internals::$head  
- `public function lexFile($file): \Tlf\Lexer\Ast` Create a 'file' ast & call 'lexAst'. Asts generated by this function are cached. Chache is invalidated when the source of the active grammars or the file being processed changes.  
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Lexer/Utility.php  
  
# class Tlf\Lexer\Utility  
  
See source code at [/src/Lexer/Utility.php](/src/Lexer/Utility.php)  
  
## Constants  
  
## Properties  
  
## Methods   
- `static public function trim_trailing_whitespace(string $str)` Trim trailing whitespace from each line  
- `static public function trim_indents(string $str)` Remove leading indents from every line, but keep relative indents  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Lexer/Versions.php  
  
# class Tlf\Lexer\Versions  
  
See source code at [/src/Lexer/Versions.php](/src/Lexer/Versions.php)  
  
## Constants  
- `const _old = 0.1;`   
- `const _1   = 1.0;`   
  
## Properties  
  
## Methods   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/NewAst/ClassAst.php  
  
# class Tlf\Lexer\Ast\ClassAst  
  
See source code at [/src/NewAst/ClassAst.php](/src/NewAst/ClassAst.php)  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function getTree($sourceTree = null)`   
- `public function getCode(string $language): string`   
- `public function get_php_code(): string`   
- `public function get_javascript_code(): string`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/NewAst/DocblockAst.php  
  
# class Tlf\Lexer\Ast\DocblockAst  
  
See source code at [/src/NewAst/DocblockAst.php](/src/NewAst/DocblockAst.php)  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function getTree($sourceTree = null)`   
- `public function getCode(string $language): string`   
- `public function get_php_code(): string`   
- `public function get_javascript_code(): string`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/NewAst/PropertyAst.php  
  
# class Tlf\Lexer\Ast\PropertyAst  
  
See source code at [/src/NewAst/PropertyAst.php](/src/NewAst/PropertyAst.php)  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function getTree($sourceTree = null)`   
- `public function getCode(string $language): string`   
- `public function get_php_code(): string`   
- `public function get_javascript_code(): string`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Php/PhpGrammar.php  
  
# class Tlf\Lexer\PhpGrammar  
This is not for actual parsing yet. This is for design work. The $directives array & 'php_open' and 'namespace' are design aspects I'm interested in implementing at some point... maybe  
See source code at [/src/Php/PhpGrammar.php](/src/Php/PhpGrammar.php)  
  
## Constants  
  
## Properties  
- `public $directives;`   
- `public $notin = [  
        'keyword'=>[  
                        '__halt_compiler', 'abstract', 'and', 'array', 'as', 'break', 'callable', 'case', 'catch', 'class', 'clone', 'const', 'continue', 'declare', 'default', 'die', 'do', 'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'eval', 'exit', 'extends', 'final', 'for', 'foreach', 'function', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'isset', 'list', 'namespace', 'new', 'or', 'print', 'private', 'protected', 'public', 'require', 'require_once', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'unset', 'use', 'var', 'while', 'xor'  
        ],  
    ];`   
  
## Methods   
- `public function getNamespace()`   
- `public function buildDirectives()`   
- `public function onGrammarAdded($lexer)`   
- `public function onLexerStart($lexer,$file,$token)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Token.php  
  
# class Tlf\Lexer\Token  
  
See source code at [/src/Token.php](/src/Token.php)  
  
## Constants  
  
## Properties  
- `public $source;` the source string  
- `protected $remainder = false;`   
- `protected $buffer = false;`   
- `public $index = -1;` start position in source. First time next() is called, index becomes 0  
- `protected $len = 0;`   
- `protected $prevToken;`   
- `protected $matches =[];`   
- `protected $match;`   
- `public int $line_number = 0;` The line number currently being processed.   
Ticks up WHEN next() adds a \n, so line number will be increased while \n at top of buffer.  
Ticks down WHEN rewind() is called, for EACH \n in the rewound chars.  
  
## Methods   
- `public function __construct($source)`   
- `public function buffer()`   
- `public function remainder()`   
- `public function setBuffer($newBuffer)` Set a new buffer. May corrupt the token, but remainder is unchanged.  
  
- `public function append($str)`   
- `public function clearBuffer()`   
- `public function next()`   
- `public function rewind(int $amount)` Remove $amount characters from the buffer & prepend them to $remainder.  
- `public function forward(int $amount)` Move the pointer forward by `$amount` chars by repeatedly calling `$this->next()`  
- `public function match($index=false)`   
- `public function setMatch($match)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/old/JsonGrammar.php  
  
# class Tlf\Lexer\JsonGrammar  
This is an incomplete grammar, mainly used for testing & building v0.5 of the lexer. It gets "quoted values" and nested arrays.  
See source code at [/src/old/JsonGrammar.php](/src/old/JsonGrammar.php)  
  
## Constants  
  
## Properties  
- `public $directives = [  
  
        'file'=>[  
                                                'onStart'=>[  
                'rewind'=>1,  
                'then'=>[  
                    ':object',  
                    ':array',  
                    ':whitespace',  
                ],  
            ],  
        ],  
              
        'object' => [  
            'start'=>'{',  
            'onStart'=>[  
                'buffer.clear'=>true,  
                'ast.new'=>[  
                    '_setto'=>'root',  
                    'type'=>'object',  
                ],  
            ],  
            'stop'=>'}',  
            'onStop'=>  
            [  
                'pop_head'=>true,  
                'pop_directive'=>true,  
                'buffer.clear'=>true,  
            ],  
  
            'then'=>[  
                ':key'=>[],  
                ':whitespace'=>[],  
            ]  
        ],  
  
        'array' => [   
            'start'=>'[',  
            'onStart'=>[  
                'buffer.clear'=>true,  
                                'ast.new'=>[  
                    '_setto'=> 'root',  
                                        'type'=>"array",  
                ],  
                'then'=>[  
                                        ':array'=>[  
                        'onStart'=>[  
                            'buffer.clear'=>true,  
                                                        'ast.new'=>[  
                                '_addto'=>'value',  
                                                                'type'=>"array",  
                            ],  
                        ],  
                        'onStop'=>[  
                            'pop_head'=>true,  
                            'buffer.clear'=>true,  
                            'pop_directive'=>false,  
                            'then'=>[  
                                ':whitespace',  
                                ':comma',  
                                ':array.stop'=>[  
                                    'onStart'=>[  
                                        'pop_directive'=>true,  
                                        'pop_head'=>false,  
                                                                                                                    ]  
                                ],  
                            ]  
                        ],  
                    ],  
                    ':whitespace',  
                    ':value'=>[  
                        'onStop'=>[  
                            'rewind'=>1,  
                            'this:appendValueToAst',  
                            'forward'=>1,  
                            'buffer.clear'=>true,  
                              
                            'then'=>[  
                                ':whitespace',  
                                ':comma'=>[  
                                                                                                                                                                                                                                    ],  
                                ':array.stop'=>[  
                                    'onStart'=>[  
                                        'pop_head'=>false,  
                                        'pop_directive'=>true,  
                                        'rewind'=>1,  
                                                                            ]  
                                ],  
                            ],  
  
                        ],  
                    ],  
                    ':array.stop'=>[  
                        'onStart'=>[  
                            'pop_head'=>false,  
                            'pop_directive'=>true,  
                            'rewind'=>1,  
                                                    ]  
                    ],  
                ],  
            ],  
            'stop'=>']',  
            'onStop'=>[  
                'pop_head'=>true,  
                'pop_directive'=>true,  
                'buffer.clear'=>true,  
            ],  
  
        ],  
  
  
        'key'=>[  
                                    'start' => ["'", '"'],  
                'onStart'=>[  
                    'buffer.clear',  
                ],  
            'match'=>'/^$1([a-zA-Z0-9_\-]+)/',  
            'stop'=>'/$1$/',  
            'onStop'=>[  
                                                                'previous'=>'key',  
                'pop_directive'=>true,  
            ],  
  
            'then'=>[  
                ':whitespace',  
                ':colon'=>[  
                ],  
            ]  
        ],  
  
        'value'=>[  
            'is'=>[  
                                                ':str_value',  
            ],  
        ],  
  
          
                  
                'str_value'=>[  
            'start' => [  
                    "'",  
                    '"',  
                ],  
            'onStart'=>[  
                'buffer.clear',  
            ],  
                                    'match'=>[['/((?<!\\\\)[^' ,1, '])+/']],  
                        'stop'=>[['/[^\\\\]',1,'$/']],  
            'onStop'=>[  
                                                                                'buffer.clear'=>true,  
                  
                                'then'=>[  
                    ':comma'=>[  
                    ],  
                    ':whitespace',  
                ]  
            ],  
        ],  
  
        'comma'=>[  
            'start'=>',',  
            'onStart'=>[  
                'buffer.clear'=>true,  
                                                'pop_directive'=>true,  
            ],  
        ],  
  
        'colon'=>[  
            'match'=> ':',  
            'then'=> [  
                ':whitespace'=> [  
  
                ],  
                ':value'=>[  
                    'then'=>[  
                        ':comma'=>[  
                            'then'=>[  
                                ':key',  
                                ':object.stop'=>[  
                                    'bubble'=>true,  
                                ],  
                            ]  
                        ],  
  
                    ],  
                ],  
            ],  
        ],  
        'whitespace'=>[  
                                                'match'=>'/^\s+$/i',  
            'onStop'=>[  
                'buffer.clear'=>true,  
            ],  
        ],  
    ];`   
  
## Methods   
- `public function getNamespace()`   
- `public function getAstClass():string`   
- `public function onLexerStart($lexer,$file,$token)`   
- `public function appendValueToAst($lexer, $ast, $token)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/old/OldBashGrammar.php  
  
# class Tlf\Lexer\OldBashGrammar  
  
See source code at [/src/old/OldBashGrammar.php](/src/old/OldBashGrammar.php)  
  
## Constants  
  
## Properties  
- `protected $regexes = [  
  
        'docblockStart'=>[  
            'regex'=>'/(##.*)/',  
            'state'=>[null, 'comment'],  
        ],  
        'docblockEnd'=>[  
            'regex'=>'/(^\s*[^\#])/m',  
            'state'=>['docblock'],  
        ],  
        'function'=>[  
            'regex'=>'/(?:function\s+)?([a-zA-Z\_0-9]*)(?:(?:\s*\(\))|\s+)\{/',  
            'state'=>[null],  
        ],  
        'comment'=>[  
            'regex'=> '/#[^#]/',  
            'state'=>[null],  
        ],  
        'commentEnd'=>[  
            'regex'=> '/#[^\n]*\n/m',  
            'state'=>['comment'],  
        ]  
    ];`   
  
## Methods   
- `public function onLexerStart($lexer,$file,$token)`   
- `public function onComment($lexer, $fileAst, $token)`   
- `public function onCommentEnd($lexer, $fileAst, $token)`   
- `public function onDocblockStart($lexer, $ast, $token)`   
- `public function onDocblockEnd($lexer, $ast, $token)`   
- `public function onFunction($lexer, $file, $token)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/Tester.php  
  
# class Tlf\Lexer\Test\Tester  
  
  
## Constants  
  
## Properties  
- `protected $sample_thingies = [  
  
                'Values.CloseArgList'=>[  
                        'ast.type'=>'var_assign',  
                        'start'=>['php_code'],  
                        'input'=>'"This")',  
                        'expect'=>[  
                'value'=>'"This"',  
                'declaration'=>'"This"',  
            ],  
        ],  
  
        'Docblock.OneLine'=>[  
                        'start'=>['/*'],   
                        'input'=>"/* abc */",  
                        'expect.previous'=>[  
                                "docblock"=> [  
                    'type'=>'docblock',  
                    'description'=>'abc',  
                ],  
            ],  
        ],  
    ];` you pass an array like this to runDirectiveTest($grammars, $thingies)  
  
## Methods   
- `protected function runDirectiveTests($grammars, $thingies)` See above sample  
  
- `protected function parse(\Tlf\Lexer $lexer, string $toLex, array $startingDirectives, array $startingAst)` parse input and return an ast tree (without the ast type & the source)  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/old/all/BashGrammar.php  
  
# class Tlf\Lexer\Test\BashGrammar  
  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function testABash5()`   
- `public function testABash4()`   
- `public function testABash3()`   
- `public function testABash2()`   
- `public function testABash()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/old/all/JsonGrammar.php  
  
# class Tlf\Lexer\Test\JsonGrammar  
  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function testJsonNestedArray()`   
- `public function testJsonArray()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/old/php-new/PhpGrammar.16jul21.php  
  
# class Tlf\Lexer\Test\PhpGrammar_16Jul21  
This is not for actual parsing yet. This is for design work. The $directives array & 'php_open' and 'namespace' are design aspects I'm interested in implementing at some point... maybe  
  
## Constants  
  
## Properties  
- `protected $directives;`   
- `public $notin = [  
        'keyword'=>[  
                        '__halt_compiler', 'abstract', 'and', 'array', 'as', 'break', 'callable', 'case', 'catch', 'class', 'clone', 'const', 'continue', 'declare', 'default', 'die', 'do', 'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'eval', 'exit', 'extends', 'final', 'for', 'foreach', 'function', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'isset', 'list', 'namespace', 'new', 'or', 'print', 'private', 'protected', 'public', 'require', 'require_once', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'unset', 'use', 'var', 'while', 'xor'  
        ],  
    ];`   
  
## Methods   
- `public function getNamespace()`   
- `public function buildDirectives()`   
- `public function onGrammarAdded($lexer)`   
- `public function onLexerStart($lexer,$file,$token)`   
- `public function holdNamespaceName($lexer, $file, $token)`   
- `public function saveNamespace($lexer, $file, $token)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/old/php-new/SampleClass.php  
  
# class Cats\Whatever\Sample  
This is the best class anyone has ever written.  
  
## Constants  
- `public const Doygle = "Hoygle Floygl";`   
  
## Properties  
- `protected $giraffe = "Bob";` Why would you name a giraffe Bob?  
- `private $cat = "Jeff";`   
- `static public $dog = "PandaBearDog";`   
  
## Methods   
- `public function dogs($a= "abc")` dogs  
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/old/php-new/StarterGrammar.16jul21.php  
  
# class Tlf\Lexer\Test\StarterGrammar_16Jul21  
An extremely simple grammar that builds sets of arglist from `(arg1,arg2,c) (list2_arg1,arg2)`  
  
## Constants  
  
## Properties  
- `protected $directives;` The actual array of directives, built during onGrammarAdded()  
  
## Methods   
- `public function getNamespace()` Defaults to 'startergrammar'  
- `public function buildDirectives()` Combine the directives from traits  
- `public function onGrammarAdded(\Tlf\Lexer $lexer)`   
- `public function onLexerStart(\Tlf\Lexer $lexer,\Tlf\Lexer\Ast $ast,\Tlf\Lexer\Token $token)`   
- `public function trimBuffer(\Tlf\Lexer $lexer, \Tlf\Lexer\Ast $ast, \Tlf\Lexer\Token $token, \stdClass $directive, array $args)` A method this grammar uses as an instruction to trim() the buffer  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/old/php-old/PhpGrammar.16jul21.php  
  
# class Tlf\Lexer\Test\PhpGrammar_16Jul21  
This is not for actual parsing yet. This is for design work. The $directives array & 'php_open' and 'namespace' are design aspects I'm interested in implementing at some point... maybe  
  
## Constants  
  
## Properties  
- `protected $directives;`   
- `public $notin = [  
        'keyword'=>[  
                        '__halt_compiler', 'abstract', 'and', 'array', 'as', 'break', 'callable', 'case', 'catch', 'class', 'clone', 'const', 'continue', 'declare', 'default', 'die', 'do', 'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'eval', 'exit', 'extends', 'final', 'for', 'foreach', 'function', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'isset', 'list', 'namespace', 'new', 'or', 'print', 'private', 'protected', 'public', 'require', 'require_once', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'unset', 'use', 'var', 'while', 'xor'  
        ],  
    ];`   
  
## Methods   
- `public function getNamespace()`   
- `public function buildDirectives()`   
- `public function onGrammarAdded($lexer)`   
- `public function onLexerStart($lexer,$file,$token)`   
- `public function holdNamespaceName($lexer, $file, $token)`   
- `public function saveNamespace($lexer, $file, $token)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/old/php-old/SampleClass.php  
  
# class Cats\Whatever\Sample  
This is the best class anyone has ever written.  
  
## Constants  
- `public const Doygle = "Hoygle Floygl";`   
  
## Properties  
- `protected $giraffe = "Bob";` Why would you name a giraffe Bob?  
- `private $cat = "Jeff";`   
- `static public $dog = "PandaBearDog";`   
  
## Methods   
- `public function dogs($a= "abc")` dogs  
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/old/php-old/StarterGrammar.16jul21.php  
  
# class Tlf\Lexer\Test\StarterGrammar_16Jul21  
An extremely simple grammar that builds sets of arglist from `(arg1,arg2,c) (list2_arg1,arg2)`  
  
## Constants  
  
## Properties  
- `protected $directives;` The actual array of directives, built during onGrammarAdded()  
  
## Methods   
- `public function getNamespace()` Defaults to 'startergrammar'  
- `public function buildDirectives()` Combine the directives from traits  
- `public function onGrammarAdded(\Tlf\Lexer $lexer)`   
- `public function onLexerStart(\Tlf\Lexer $lexer,\Tlf\Lexer\Ast $ast,\Tlf\Lexer\Token $token)`   
- `public function trimBuffer(\Tlf\Lexer $lexer, \Tlf\Lexer\Ast $ast, \Tlf\Lexer\Token $token, \stdClass $directive, array $args)` A method this grammar uses as an instruction to trim() the buffer  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/php/DocumentationExample.php  
  
# class DocumentationExample  
A class that does nothing  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function one()` A method that does nothing.  
- `public function two()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/php/lex/MethodParseErrors.php  
  
# class Sample  
  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function cats()`   
- `public function dogs($arg)`   
- `public function dogs2($arg=1)`   
- `public function dogs_3($arg='yes')`   
- `public function bears()` bears are so cute  
- `public function bears_are_best()` bears are so cute  
- `public function bears_do_stuff()`   
- `public function bears_cuddle_stuff()`   
- `public function bears_nest()`   
- `public function cleanSource($srcCode): string` Replaces inline PHP code with placeholder, indexes the placeholder, and returns the modified code  
  
- `public function makes_it_11()`   
- `public function output(): string`   
- `public function ok_13()`   
- `public function writeTo(string $file, $chmodTo=null): bool`   
- `public function yep_15()`   
- `public function __construct($html)`   
- `public function okay_17()`   
- `public function output2($withPHP=true)`   
- `public function now_19()`   
- `public function fill_php($html, $withPHP=true)`   
- `public function ugh_21()`   
- `public function create(string $tableName, array $colDefinitions, bool $recreateIfExists=false)`   
- `public function its_23()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/php/lex/SampleClass.php  
  
# class Cats\Whatever\Sample  
This is the best class anyone has ever written.  
  
## Constants  
- `public const Doygle = "Hoygle Floygl";`   
  
## Properties  
- `protected $giraffe = "Bob";` Why would you name a giraffe Bob?  
- `private $cat = "Jeff";`   
- `static public $dog = "PandaBearDog";`   
  
## Methods   
- `public function dogs($a= "abc")` dogs  
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/php/lex/code-scrawl/IntegrationTest.php  
  
# class Tlf\Lexer\Test\Scrawl\Integrate  
  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function testIdk()`   
- `public function testGetAllClasses()`   
- `public function testPhpExtWithScrawl()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/php/lex/code-scrawl/MainVerbs.php  
  
# class Tlf\Scrawl\Ext\MdVerb\MainVerbs  
  
See source code at [/vendor/taeluf/code-scrawl/code/MdVerb/MainVerbs.php](/vendor/taeluf/code-scrawl/code/MdVerb/MainVerbs.php)  
  
## Constants  
  
## Properties  
- `public \Tlf\Scrawl $scrawl;` a scrawl instance  
  
## Methods   
- `public function __construct(\Tlf\Scrawl $scrawl)`   
- `public function setup_handlers(\Tlf\Scrawl\Ext\MdVerbs $md_ext)` add callbacks to `$md_ext->handlers`  
- `public function at_template(string $templateName, ...$templateArgs)` Load a template  
- `public function at_import(string $key)` Import something previously exported with @export or @export_start/@export_end  
  
- `public function at_file(string $relFilePath)` Copy a file's content into your markdown.  
  
- `public function at_see_file(string $relFilePath)` Get a link to a file in your repo  
  
- `public function at_hard_link(string $url, string $name=null)` just returns a regular markdown link. In future, may check validity of link or do some kind of logging  
- `public function at_easy_link(string $service, string $target)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/php/lex/code-scrawl/Scrawl2-partial.php  
  
# class Tlf\Scrawl2  
  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function process_str(string $string, string $file_ext)`   
- `public function addExtension(object $ext)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/php/lex/code-scrawl/Scrawl2.php  
  
# class Tlf\Scrawl2  
  
  
## Constants  
  
## Properties  
- `public array $stuff = [];` array for get/set  
- `public array $extensions = [  
        'code'=>[],  
    ];`   
- `public string $dir_docs = null;` absolute path to your documentation dir  
- `public string $dir_root = null;` absolute path to the root of your project  
- `public array $template_dirs = [  
  
    ];`   
- `public bool $markdown_preserveNewLines = true;` if true, append two spaces to every line so all new lines are parsed as new lines  
- `public bool $markdown_prependGenNotice = true;` if true, add an html comment to md docs saying not to edit directly  
  
## Methods   
- `public function __construct(array $options=[])`   
- `public function get_template(string $name, array $args)`   
- `public function process_str(string $string, string $file_ext)`   
- `public function addExtension(object $ext)`   
- `public function get(string $group, string $key)`   
- `public function get_group(string $group)`   
- `public function set(string $group, string $key, $value)`   
- `public function parse_str($str, $ext)`   
- `public function write_doc(string $rel_path, string $content)` save a file to disk in the documents directory  
- `public function read_file(string $rel_path)` Read a file from disk, from the project root  
- `public function report(string $msg)` Output a message to cli (may do logging later, idk)  
- `public function warn($header, $message)` Output a message to cli, header highlighted in red  
- `public function good($header, $message)` Output a message to cli, header highlighted in red  
- `public function prepare_md_content(string $markdown)` apply small fixes to markdown  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/php/lex/code-scrawl/functionListTemplate.php  
  
# class Abc  
  
  
## Constants  
  
## Properties  
  
## Methods   
  
  
# class Def  
  
  
## Constants  
  
## Properties  
  
## Methods   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/php/lex/lildb/LilDb.php  
  
# class Tlf\LilDb  
A lil tiny database class  
  
## Constants  
  
## Properties  
- `public \PDO $pdo;` a pdo instance  
  
## Methods   
- `static public function new(string $user, string $password, string $db, $host='localhost')` Convenience method to initialize with pdo  
- `static public function sqlite(string $dbName = ':memory:')` Convenience method to initialize sqlite db in memory  
- `static public function mysql($dbName = ':memory:')` Convenience method to initialize mysql db in memory  
- `public function __construct(\PDO $pdo)` Initialize with a db handle  
- `public function create(string $tableName, array $colDefinitions, bool $recreateIfExists=false)` Create a new table if it doesn't exist.  
  
- `public function query(string $sql, array $binds=[])` Execute an Sql statement & get rows back  
- `public function select(string $tableName, array $whereCols=[])` Get rows from a table with the given $whereCols  
- `public function insert(string $table, array $row)` Insert a row into the database  
- `public function insertAll(string $table, array $rowSet)`   
- `public function update(string $table, array $newRowValues, string $idColumnName='id')` Update an existing row. Shorthand for `updateWhere()` with the id column set as the where values.  
- `public function updateWhere(string $table, array $newRowValues, array $whereVals)`   
- `public function delete(string $table, array $whereCols)` Delete rows from a table  
- `public function execute(string $sql, array $binds=[])` Execute an Sql statement & get a PDOStatement back  
- `public function exec(string $sql, array $binds=[])` Alias for `execute()`  
- `public function getPdo()` get the pdo object  
- `public function pdo()` get the pdo object  
- `static public function whereSqlFromCols(array $columns)` Convert key=>value array into a 'WHERE' sql.  
  
- `static public function keysToBinds(array $keyedValues)` Convert an array `['key'=>$val, ':key2'=>$val]` into binds: `[':key'=>$val, ':key2'=>$val]`.  
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/php/lex/lildb/LilMigrations.php  
  
# class Tlf\LilMigrations  
A minimal class for handling sql migration. Create a migrations dir. Then create dirs like `v1`, `v2` & create files `up.sql`, `down.sql` in each versioned dir. Migrating from 1 to 2 will execute `v2/up.sql`. From 3 down to 1 will execute `v2/down.sql` and `v1/down.sql`. You may also make files like `v1/up-1.sql`, `v1/up-2.sql` to execute multiple files in order.  
  
  
## Constants  
  
## Properties  
- `public \PDO $pdo;` a pdo instance  
- `public string $dir;` the dir for migrations scripts.  
  
## Methods   
- `public function __construct(\PDO $pdo, string $dir)` In $dir, there should be directories named 'v1', 'v2', 'v3', and so on.  
In the v1/v2/v3 dirs, there should be up.sql & down.sql files with valid SQL statements for whatever database you're using  
  
- `static public function sqlite(string $dbName = ':memory:')` Convenience method to initialize sqlite db in memory  
- `public function migrate(int $old, int $new)` Migrate from old version to new  
  
- `public function run_migration_version($version, $up_or_down)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/php/lex/lildb/LilMigrationsBug.php  
  
# class Tlf\LilMigrationsBug  
This is a minimal version of LilMigrations for debugging the properties issue  
  
## Constants  
  
## Properties  
- `public $prop = 'okay';`   
  
## Methods   
- `public function ok()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/php/lex/phad/FormsTest.php  
  
# class Phad\Test\Integration\Forms  
This class appears to test both form compilation and form submission  
  
  
## Constants  
  
## Properties  
- `protected array $blogTableColumns = ['id'=>'INTEGER PRIMARY KEY','title'=>'VARCHAR(200)', 'body'=>'VARCHAR(2000)'];`   
  
## Methods   
- `public function testDeleteItem()`   
- `public function testErrorMessage()`   
- `public function testSubmitDocumentation()`   
- `public function testControllerOnSubmitDocumentation()`   
- `public function testWithInlineOnSubmit()`   
- `public function testInsertWithValidOption()`   
- `public function testUpdateRedirectsToTarget()`   
- `public function testUpdateValid()`   
- `public function testInsertValid()`   
- `public function testSubmitInvalid()`   
- `public function testDisplayWithNoObject()`   
- `public function testHasSelectOptions()`   
- `public function testHasPropertiesData()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/php/lex/phtml/Compiler.php  
  
# class Taeluf\PHTML\Compiler  
  
  
## Constants  
  
## Properties  
- `protected $code = [];` An array of code to output.  
Likely contains placeholder which will be replaced.   
May contain objects which implement __toString  
- `protected $src;` The content of a PHP file for compilation  
- `protected $placeholder = [];` An array of placeholder code with codeId => [prependedCode, code, appendedCode]... there can be any number of entries for each codeId  
Code may be string or an object which implements __toString  
codeIds are either sha sums (alpha-numeric, i think) or randmoized alpha  
- `protected $htmlSource;` The parsed source code, with the PHP code replaced by placeholders  
  
## Methods   
- `public function __construct()`   
- `public function cleanSource($srcCode): string` Replaces inline PHP code with placeholder, indexes the placeholder, and returns the modified code  
  
- `public function placeholderFor($phpCodeWithOpenCloseTags): string` 1. Generates an id  
2. indexes the passed-in-code with that id  
3. Returns the id.  
  
- `public function appendCode($code)` Appends code to the output-to-be  
  
- `public function prependCode($code)` Prepends code to the output-to-be  
  
- `public function placeholderPrepend($placeholder,$code)` Prepend code immediately prior to the given placeholder  
  
- `public function placeholderAppend($placeholder,$code)` Append code immediately after the given placeholder  
  
- `public function output(): string` Compile the code into a string & return it.   
output() can be called several times as it does NOT affect the state of the compiler.  
  
- `public function writeTo(string $file, $chmodTo=null): bool` Writes the compiled output to the given file  
  
- `public function fileForCode($compileDir,$code): string` Get an absolute file path which can be included to execute the given code  
  
1. $codeId = sha1($code)  
2. file_put_contents("$compileDir/$codeId.php", $code)  
3. return the path of the new file  
  
- Will create the directory (non-recursive) if not exists  
  
- `protected function freshId($length = 26): string` Generate a random string of lowercase letters  
  
- `public function codeForId(string $codeId,bool $asArray=false)` Get the code for the given code id.  
  
Placeholder code is stored as an array to enable the placeholderPrepend|Append functions, so I make it available as an array if you want.  
  
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/php/lex/phtml/Node.php  
  
# class Taeluf\PHTML\Node  
less sucky HTML DOM Element  
  
This class extends PHP's DOMElement to make it suck less  
  
The original version of this file was a pre-made script by the author below.  
The only meaningful pieces of code I kept are the two `if 'innerHTML'` blocks of code.  
No license information was available in the copied code and I don't remember what it said on the author's website.  
  
The original package had the following notes from the author:  
  
- Authored by: Keyvan Minoukadeh - http://www.keyvan.net - keyvan@keyvan.net  
  - See: http://fivefilters.org (the project this was written for)  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function __construct()`   
- `public function is(string $tagName): bool` is this node the given tag  
- `public function has(string $attribute): bool`   
- `public function attributes()` get an array of DOMAttrs on this node  
- `public function attributesAsArray()` return an array of attributes ['attributeName'=>'value', ...];  
- `public function __set($name, $value)` Used for setting innerHTML like it's done in JavaScript:  
@code  
$div->innerHTML = '<h2>Chapter 2</h2><p>The story begins...</p>';  
@endcode  
- `public function __unset($name)` if the node has the named attribute, it will be removed. Otherwise, nothing happens  
- `public function __isset($name)`   
- `public function __get($name)` Used for getting innerHTML like it's done in JavaScript:  
@code  
$string = $div->innerHTML;  
@endcode  
- `public function __toString()`   
- `public function xpath($xpath)`   
- `public function addHiddenInput($inputName, $value)` Adds a hidden input to a form node  
If a hidden input already exists with that name, do nothing  
If a hidden input does not exist with that name, create and append it  
  
- `public function boolAttribute($attributeName)` Find out if this node has a true value for the given attribute name.  
Literally just returns $this->hasAttribute($attributeName)  
  
I wanted to implement an attribute="false" option... but that goes against the standards of HTML5, so that idea is on hold.  
  
See https://stackoverflow.com/questions/4139786/what-does-it-mean-in-html-5-when-an-attribute-is-a-boolean-attribute   
  
- `public function getInnerText()`   
- `public function __call($method, $args)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/php/lex/phtml/PHPParser.php  
  
# class Taeluf\PHTML\PHPParser  
Parses .php files into:  
 1. A string with placeholders for the PHP code  
 2. An array of PHP code, identified by their placeholders  
  
## Constants  
  
## Properties  
- `protected string $src;` The source HTML + PHP code  
  
- `protected object $pieces;` The parsed pieces of code in the format:  
 [  
     'html' => '<div>A string of code with php placeholders like <b>phpadsfwefhaksldfjaskdlfjaskldfjasldfkphp</b> </div> and trailing text...',  
     'php'  => [  
         'phpadsfwefhaksldfjaskdlfjaskldfjasldfkphp' => '<?="Something echod";?>',   
         'phpid2'=>'<?php // another code block/?>'  
     ]  
 ]  
The array is simply (object) cast  
  
## Methods   
- `public function __construct(string $htmlPHPString)` Create a new PHP parser instance from a string  
  
- `public function pieces(): object` Return the parsed pieces. See doc for protected $pieces  
  
- `protected function separatePHP(): object` Separate the source code into it's pieces. See the protected $pieces docs  
- `protected function randomAlpha($length = 26): string` Generates a random string of characters a-z, all lowercase & returns them  
 this is used for the PHP placeholders  
  
- `static public function getRandomAlpha($length = 26): string` Generates a random string of characters a-z, all lowercase & returns them  
 this is used for the PHP placeholders  
  
- `protected function tokens(): array` Tokenize the src code into a slightly better format than token_get_all  
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/php/lex/phtml/Phtml.php  
  
# class Taeluf\Phtml  
Makes DUMDocument... less terrible, but still not truly good  
  
## Constants  
  
## Properties  
- `protected string $src;` The source HTML + PHP code  
  
- `protected string $cleanSrc;` The source code with all the PHP replaced by placeholders  
- `protected array $php;` [ 'phpplaceholder' => $phpCode, 'placeholder2' => $morePHP ]  
- `protected $phpAttrValue;` A random string used when adding php code to a node's tag declaration. This string is later removed during output()  
  
## Methods   
- `public function __construct($html)` Create a DOMDocument, passing your HTML + PHP to __construct.   
  
  
- `public function placeholder(string $string): string`   
- `public function codeFromPlaceholder(string $placeholder): string` Get the code that's represented by the placeholder  
- `public function phpPlaceholder(string $enclosedPHP): string` Get a placeholder for the given block of code  
Intention is to parse a single '<?php //piece of php code ?>' and not '<?php //stuff ?><?php //more stuff?>'  
When used as intended, will return a single 'word' that is the placeholder for the given code  
  
- `public function fillWithPHP(string $codeWithPlaceholders): string` Decode the given code by replacing PHP placeholders with the PHP code itself  
  
- `public function __toString()` See output()  
  
- `public function output($withPHP=true)` Return the decoded document as as tring. All PHP will be back in its place  
  
- `public function fill_php($html, $withPHP=true)`   
- `public function xpath($xpath,$refNode=null)` get the results of an xpath query  
  
- `public function addPhpToTag($node, $phpCode)` Set an attribute that will place PHP code inside the tag declartion of a node.   
Basically: `<node phpCodePlaceholder>`, which pHtml will later convert to `<node <?='some_stuff'?>>`.   
This avoids problems caused by attributes requiring a `=""`, which `DOMDocument` automatically places.  
  
- `public function insertCodeBefore(\DOMNode $node, $phpCode)`   
- `public function insertCodeAfter(\DOMNode $node, $phpCode)`   
- `public function cleanHTML($html)`   
- `public function restoreHtml($html)`   
- `public function __get($param)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/php/lex/phtml/TextNode.php  
  
# class Taeluf\PHTML\TextNode  
  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function is(string $tagName): bool` is this node the given tag  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/output/PhpExampleAst.php  
  
# class Abc  
  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function coolio()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/run/DefunctTests.php  
  
# class Tlf\Lexer\Test\DefunctTests  
These are tests that either aren't really tests or that probably don't have a place any more  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function testMakeJson()` convert a tree into json to see if i like the output better  
This was never a test. Just a way to run some code.  
- `public function testPhpGrammarNew_SampleClass()` An old test I was using to design the new php grammar.  
It is just a mess now and i don't want to mess with it.  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/run/Grammars/BashGrammar.php  
  
# class Tlf\Lexer\Test\BashGrammar  
  
  
## Constants  
  
## Properties  
- `protected $thingies = [  
                'ws_dblock_func_cmnt'=>[  
            'start'=>'bash',  
            'input_file'=>'test/input/bash/ws_dblock_func_cmnt.bash',  
            'input'=>null,  
            'expect'=>[  
                'function'=>  
                [  
                    0=>[  
                        'type' => 'function',  
                        'name' => 'echo_path',  
                        'docblock' =>   
                        [  
                            'type' => 'docblock',  
                            'description' => "\n Description",  
                            'attribute' =>   
                            [  
                                0 =>   
                                [  
                                    'type' => 'attribute',  
                                    'name' => 'arg',  
                                    'description' => '$1 a path',  
                                ]  
  
                            ]  
                        ]  
                    ],  
                    1=>[  
                        'type'=>'function',  
                        'name'=>'echo_string',  
                        'docblock'=>null  
                    ]  
                ],  
                'comments'=>[  
                    0=>[  
                        'type'=>'comment',  
                        'src'=> '# comment 1',  
                        'description'=> ' comment 1',  
                    ],  
                    1=>[  
                        'type'=>'comment',  
                        'src'=> '# comment 2',  
                        'description'=> ' comment 2',  
                    ],  
                    2=>[  
                        'type'=>'comment',  
                        'src'=> '# comment 3',  
                        'description'=> ' comment 3',  
                    ]  
                ],  
            ],  
        ],  
        'comments_functions'=>[  
            'start'=>'bash',  
            'input_file'=>'test/input/bash/comments_functions.bash',  
            'input'=>null,  
            'expect'=>[  
                'comments'=>[  
                    0=>[  
                        'type'=>'comment',  
                        'src'=>'#!/usr/bin/env bash',  
                        'description'=>'!/usr/bin/env bash',  
                    ],  
                    1=>[  
                        'type'=>'comment',  
                        'src'=>'# comment one',  
                        'description'=> ' comment one',  
                    ]  
                ],  
                'function'=>[  
                    0=>[ 'type'=>'function',  
                        'name'=>'pre_comment',  
                        'docblock'=>null  
                    ],  
                    1=>[ 'type'=>'function',  
                        'name'=>'post_comment',  
                        'docblock'=>null  
                    ],  
                ],  
            ],  
        ],  
        'whitespace_docblock_function'=>[  
            'start'=>'bash',  
            'input_file'=>'test/input/bash/whitespace_docblock_function.bash',  
            'input'=>null,  
            'expect'=>[  
                'function'=>  
                [  
                    0=>[  
                        'type' => 'function',  
                        'name' => 'echo_path',  
                        'docblock' =>   
                        [  
                            'type' => 'docblock',  
                            'description' => "\n Description",  
                            'attribute' =>   
                            [  
                                0 =>   
                                [  
                                    'type' => 'attribute',  
                                    'name' => 'arg',  
                                    'description' => '$1 a path',  
                                ]  
  
                            ]  
  
                        ]  
                    ]  
                ]  
            ],  
        ],  
        'Docblock_Function'=>[  
            'start'=>'bash',  
            'input'=>"##\n# Commit all files & push to origin host\n#\n# @tip Save your project\n# @shorthand s, commit\n#"  
                    ."\nfunction core_save(){\nmsg \"Pretend save function\"\n}",  
            'expect'=>[  
                'function'=>[  
                    0=>[  
                        'type'=>'function',  
                        'name'=>'core_save',  
                        'docblock'=>[  
                            'type'=>'docblock',  
                            'description'=> "\n Commit all files & push to origin host\n",  
                            "attribute"=>[  
                                0=>[  
                                    'type'=>'attribute',  
                                    'name'=>'tip',  
                                    'description'=>'Save your project'  
                                ],  
                                1=>[  
                                    'type'=>'attribute',  
                                    'name'=>'shorthand',  
                                    'description'=>"s, commit\n",  
                                ]  
                            ],  
                        ]  
                    ],  
                ]  
            ],  
        ],  
        'Comments'=>[  
            'start'=>'comment',  
            'input'=>"var=\"abc\"\n#I am a comment\nvarb=\"def\"",  
            'expect'=>[  
                "comments"=>[  
                    0=>[  
                        'type'=>'comment',  
                        'src'=>'#I am a comment',  
                        'description'=> "I am a comment",  
                    ]  
                ],  
            ],  
        ],  
    ];` Array of inputs to lex & test  
  
## Methods   
- `public function testBashStuff()`   
- `public function testBashComment()`   
- `public function testBashDirectives()` Parse & test all tests listed in `$this->thingies[]`  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/run/Grammars/DocblockGrammar.php  
  
# class Tlf\Lexer\Test\DocblockGrammar  
  
  
## Constants  
  
## Properties  
- `protected $thingies = [  
  
        'Docblock.AttributeStalls'=>[  
            'is_bad_test'=>'Good test: tests when a docblock contains an @attribute followed by whitespace on one line, then an @attribute on the next line, causing the program to stall & output nothing',   
                        'start'=>['/*'],  
            'input'=>  
                "/**\n* @one \n* @two okay \n*/",  
            'expect.previous'=>[  
                "docblock"=> [  
                    'type'=>'docblock',  
                    'description'=>"",  
                    'attribute'=>[  
                        0=>[  
                            'type'=>'attribute',  
                            'name'=>'one',  
                            'description'=>'',  
                        ],  
                        1=>[  
                            'type'=>'attribute',  
                            'name'=>'two',  
                            'description'=>'okay',  
                        ],  
                    ],  
                ],  
            ]  
  
        ],  
        'Docblock.Empty'=>[  
            'start'=>['/*'],  
            'input'=>"/**\n     *\n     */",  
            'expect.previous'=>[  
                "docblock"=>[  
                    'type'=>'docblock',  
                    'description'=>'',  
                ]  
            ]  
        ],  
  
        'Docblock.MultilineWithGaps'=>[  
            'start'=>['/*'],  
            'input'=>"/**\n *\n * first \n * \n * \n * second \n * \n * \n */",  
            'expect.previous'=>[  
                "docblock"=> [  
                    'type'=>'docblock',  
                    'description'=>"first \n\n\nsecond ",  
                ],  
            ],  
        ],  
  
  
        'Docblock.SameNameAttributes'=>[  
            'start'=>['/*'],  
            'input'=>"  /*\n* abc \n* @cat attr-describe\n  still describing def"  
                    ."\n * \n*\n @cat (did) a thing\n*/",  
            'expect.previous'=>[  
                "docblock"=> [  
                    'type'=>'docblock',  
                    'description'=>" abc ",  
                    'attribute'=>[  
                        0=>[  
                            'type'=>'attribute',  
                            'name'=>'cat',  
                            'description'=>"attr-describe\n still describing def",  
                        ],  
                        1=>[  
                            'type'=>'attribute',  
                            'name'=>'cat',  
                            'description'=>"(did) a thing",  
                        ],  
                    ],  
                ],  
            ],  
        ],  
  
        'Docblock.TwoAttributes'=>[  
            'start'=>['/*'],  
            'input'=>"  /*\n* abc \n* @def attr-describe\n  still describing def"  
                    ."\n * \n*\n @cat (did) a thing\n*/",  
            'expect.previous'=>[  
                "docblock"=> [  
                    'type'=>'docblock',  
                    'description'=>" abc ",  
                    'attribute'=>[  
                        0=>[  
                            'type'=>'attribute',  
                            'name'=>'def',  
                            'description'=>"attr-describe\n still describing def",  
                        ],  
                        1=>[  
                            'type'=>'attribute',  
                            'name'=>'cat',  
                            'description'=>"(did) a thing",  
                        ],  
                    ],  
                ],  
            ],  
        ],  
  
        'Docblock.WithAttribute'=>[  
            'start'=>['/*'],  
            'input'=>"  /*\n* abc \n* @def attr-describe\n  still describing def*/",  
            'expect.previous'=>[  
                "docblock"=> [  
                    'type'=>'docblock',  
                    'description'=>"abc ",  
                    'attribute'=>[  
                        0=>[  
                            'type'=>'attribute',  
                            'name'=>'def',  
                            'description'=>"attr-describe\nstill describing def",  
                        ],  
                    ],  
                ],  
            ],  
        ],  
        'Docblock.VariedIndents'=>[  
            'start'=>['/*'],  
            'input'=>"  /*01\n  * abc \n    * def \n ghi*/",  
            'expect.previous'=>[  
                "docblock"=> [  
                    'type'=>'docblock',  
                    'description'=>"01\n   abc \n     def \nghi",  
                ],  
            ],  
        ],  
  
        'Docblock.IndentedLines'=>[  
            'start'=>['/*'],  
            'input'=>"  /* abc \n    * def \n*/",  
            'expect.previous'=>[  
                "docblock"=> [  
                    'type'=>'docblock',  
                    'description'=>"abc\ndef ",  
                ],  
            ],  
        ],  
        'Docblock.MultiLine2'=>[  
            'start'=>['/*'],  
            'input'=>"/*\n*\n*\n* abc \n* def \n*/",  
            'expect.previous'=>[  
                "docblock"=> [  
                    'type'=>'docblock',  
                    'description'=>"abc \ndef ",  
                ],  
            ],  
        ],  
        'Docblock.MultiLine'=>[  
            'start'=>['/*'],  
            'input'=>"/** abc \n* def */",  
            'expect.previous'=>[  
                "docblock"=> [  
                    'type'=>'docblock',  
                    'description'=>"abc\ndef ",  
                ],  
            ],  
        ],  
        'Docblock./**OneLine'=>[  
            'start'=>['/*'],  
            'input'=>"/** abc */",  
            'expect.previous'=>[  
                "docblock"=> [  
                    'type'=>'docblock',  
                    'description'=>'abc',  
                ],  
            ],  
        ],  
        'Docblock.OneLine'=>[  
            'start'=>['/*'],  
            'input'=>"/* abc */",  
            'expect.previous'=>[  
                "docblock"=> [  
                    'type'=>'docblock',  
                    'description'=>'abc',  
                ],  
            ],  
        ],  
    ];` Directives to test.  
  
See Tester clsas for details on how these are structured.  
  
## Methods   
- `public function testBuildAstWithAttributesBug()`   
- `public function testBuildAstWithAttributes()`   
- `public function testDocblockDirectives()` Test a bunch of directives  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/run/Grammars/PhpGrammar.php  
  
# class Tlf\Lexer\Test\PhpGrammar  
  
  
## Constants  
  
## Properties  
- `protected $directive_tests;`   
  
## Methods   
- `public function prepare()`   
- `public function input_file($file)`   
- `public function testDirectives()` Unit test individual directives from the `test/src/Php/*.php` files  
  
For a summary of the directives, run `phptest -test testShowMePhpFeatures`, then see `test/output/PhpFeatures.md`  
- `public function testLilMigrationsBug()`   
- `public function testLilMigrations()`   
- `public function testLilDb()`   
- `public function testPhadFormsTest()`   
- `public function testScrawlFnTemplate()`   
- `public function testMethodParseErrors()`   
- `public function testPhtmlNode()`   
- `public function testPhtmlParser()`   
- `public function testPhtml()`   
- `public function testPhtmlCompiler()`   
- `public function testPhtmlTextNode()`   
- `public function testSampleClass()`   
- `public function parse_file($file, $debug, $stop_loop)` Get an ast tree from a file  
- `public function output_tree(string $file, array $tree)`   
- `public function get_counts($file)` get the expected counts from `test/php/counts/$file.json`  
- `public function assert_counts(array $ast_tree, array $target_counts)` Assert that the ast tree contains the given counts of items  
- `public function assert_file($file, bool $debug=true, int $stop_loop  -1)` Run tests on the given file. (currently just tree counts)  
  
1. Parses the input file into an ast tree  
2. Loads InputFile.expect.js, which contains things like the expected number of consts, methods, and comments  
3. Compares the output ast against the expected counts  
4. Writes the ast tree to `test/input/php/tree/{$file}.js` & `.../{$file.printr.js}`  
   - this is just for visual verification (i think)  
   - this should be changed to the output dir  
  
- `public function testShowMePhpFeatures()` This is not really a test.   
  
It writes file `test/output/PhpFeatures.md` showing a synopsis of which directives passed / failed & what their input was  
  
The output is like:  
 -FailedTestname: input string that was lexed  
 +PassedTestName: input string that was lexed  
- `public function testRunFile()` test an individual file (or all files in a directory) as needed  
  
- `public function testGetTreeCounts()` Test the test function  
- `public function get_tree_counts($array, $counts)` get an array of counts across an entire array.  
Each key increases by one when it is found,  
except when the value is an array containing numeric indices,  
then the count[key] increases by count(value)  
- `public function has_numeric_indices(array $array): bool`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/run/debug/PhpGrammar.php  
  
# class Tlf\Lexer\Test\Debug\PhpGrammar  
  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function testMethodBodyIsString()`   
- `public function testScrawl2()` A block nested within a method caused the next method declaration to be incorect, so test all methods are correctly parsed in code-scrawl/Scraw2.php   
- `public function get_ast($file, $debug=true, $stop_loop-1): array` Get the ast of a file in `test/input/php/lex/`  
  
- `public function get_ast_methods(array $ast): array` Get the method names & declaration from an class ast  
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/run/document/Idk.php  
  
# class Tlf\Lexer\Test\Document\Idk  
  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function testLexPhp()`   
- `public function testLexString()`   
- `public function testLexAst()`   
- `public function testLexFile()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/run/document/PhpGrammar.php  
  
# class Tlf\Lexer\Test\Document\PhpGrammar  
This class is for writing documentation as code  
So tests should be extremely clean & not seek to be unit tests, but seek to confirm broad functionality  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function testVerbose()` Just an example of how to run the php grammar  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/run/main/Api.php  
  
# class Tlf\Lexer\Test\Main\Api  
For developing a new programming interface, possibly just a wrapper for the Lexer.  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function testMain()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/run/main/Grammar.php  
  
# class Tlf\Lexer\Test\Main\Grammar  
Test features of the grammar class, not lexing, and not any language-specific grammars  
  
## Constants  
  
## Properties  
- `protected $grammar;`   
- `protected $sampleDirectiveList = [  
            'grp'=>[  
                'stop'=>[  
                                        'rewind'=>1  
                ],  
                'is'=>[  
                    ':target'=>[  
                                                'rewind'=>2,  
                    ],  
                    ':target_2'=>[],  
                ]  
            ],  
            'target'=>[  
                'stop'=>[  
                    'match'=>'abc',  
                                        'rewind'=>3,  
                ]  
            ],  
            'parent'=>[  
                'stop'=>[  
                    'then :grp'=>[  
                                                'rewind'=>4  
                    ],  
                ]  
            ],  
  
            'target_2'=>[],  
        ];` I wrote this for thinking purposes, and I will probably use it for some testing maybe????  
Might be able to delete it.  
  
## Methods   
- `public function prepare()`   
- `public function testGetDirectives()`   
- `public function testDirectiveNormalization()` Test grammar->normalizeDirective();  
- `public function testExpandIsDirective()` Test that an `is` directive expands into an array of the directives it names  
  
- `public function testDirectiveOverrides()` Rules:  
- `public function getDirectivesToLookup()`   
- `public function getSourceDirectives()`   
- `public function getOverrideDirectives()`   
- `public function getNormalizeDirectives()` Get directives as they would be defined & those same directives as they would be after normaliztion  
  
- `public function testExpandIsDirectiveWithOverrides()` Test that is directives accept overrides   
The functionality exists, i think, but the test is not implemented  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/run/main/Main.php  
  
# class Tlf\Lexer\Test\Main  
Tests otherwise unsorted  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function testTrimTrailingWhitespace()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/run/main/StarterGrammar.php  
  
# class Tlf\Lexer\Test\Main\StarterGrammar  
Just a simple test with a simple grammar to make sure the lexer works  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function testStarterGrammar()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/run/translate/Translate.php  
  
# class Tlf\Lexer\Test\Translate\Translate  
Tests output ASTs as code  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function testOutputSampleClass()`   
- `public function testOutputPhpAndJs()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/src/Starter/StarterGrammar.php  
  
# class Tlf\Lexer\Test\Src\StarterGrammar  
An extremely simple grammar that builds sets of arglist from `(arg1,arg2,c) (list2_arg1,arg2)`   
  
Basically just a proof of concept   
  
## Constants  
  
## Properties  
- `public $directives;` The actual array of directives, built during onGrammarAdded()  
  
## Methods   
- `public function getNamespace()` Defaults to 'startergrammar'  
- `public function buildDirectives()` Combine the directives from traits  
- `public function onGrammarAdded(\Tlf\Lexer $lexer)`   
- `public function onLexerStart(\Tlf\Lexer $lexer,\Tlf\Lexer\Ast $ast,\Tlf\Lexer\Token $token)`   
- `public function trimBuffer(\Tlf\Lexer $lexer, \Tlf\Lexer\Ast $ast, \Tlf\Lexer\Token $token, \stdClass $directive, array $args)` A method this grammar uses as an instruction to trim() the buffer  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# Docblock + Comments Grammar  
  
## July 13, 2021  
I decided to just do a custom php implementation of the whole thing. The grammar handles catching the start & end of the docblock & calling the appropriate php function. This seemed easier, because I couldn't really store anything to the ast until I had already gone through the entire thing & I need to know about lines & it just seemed really complex, so writing pure php seemed easier.  
  
I still think it should be re-written as a proper grammar, but there's no explicit reason to do this.  
  
I may want a grammar that processes strings containing attributes, though, like so I can capture `@attr(arg, arg2, etc) and description`  
  
But I don't need that right now, so I'm not doing it right now  
  
The "OLD" notes below are likely a good starting point for writing a proper docblock grammar.   
  
## OLD (before July 13, 2021)  
  
I wrote most of a Docblock Grammar. Then started trying to handle the padding issue & it was non-starter. So that has to basically be scratched so I can implement this new version.  
  
I think I'll just go through the breakdown WITH attributes & set that one up, instead of trying to work attributes in after setting up the simpler attribute-free one.  
  
I would mayybe like to setup some smaller tests. But Idunno. I'm probably okay with just parsing one big docblock & making sure its how I expect it. Especially since docblocks aren't complex & don't have a lot of components.  
  
  
## Some rules  
- leading whitespace is always removed from the first line. Like `/**  something` becomes `something`  
- left-pad consists of `whitespace * whitespace` & is converted to full whitespace  
    - the `*` is always replaced with a ` ` (space) before further processing  
- `leftPadToRemove = ` the length of whichever line has the shortest left-pad.   
    - Does NOT count any lines after a start-of-line `@attribute`  
    - Does NOT count the first line  
    - Does NOT count empty lines (though they will be trimmed)  
    - Then each non-empty line has that much left-pad removed from them.  
- Attributes MUST be `[a-zA-Z_]+`  
- Attributes MAY have parenthetical arguments like `@attr(arg1, arg2)`  
    - Can occur anywhere  
    - Can only have a description if it's the first thing on a line  
        - `\n  * something [this](/this) thing yes please`. There is no description for `[this](/this)`   
        - `\n  * [this](/this) thing yes please`. `thing yes please` is the description  
- Attributes without parenthetical arguments  
    - MUST be the first non-whitespace non-star character. Like `\n  * @attr whatever`  
    - Captures a description until the next `@attribute`  
  
## The Lexer breakdown  
```  
  /* abc  
   * def  
   *    ghi  
       *   jkl  
      mno  
   */  
```  
1. match `/*` & discard all before.   
2. match `\n` & store `abc` as `docblock.line1`  
3. match `*` & replace it with ` `  
4. match `\n` & push the line `     def` onto `doblock.lines`  
5. match `*` & replace it with ` `  
6. match `\n` & push the line `        ghi` onto `docblock.lines`  
7. match `\n` & push the line `      mno` onto `docblock.lines`  
8. match `*/` & set the line `   ` to `docblock.last_line`  
9. call php method to clean up the docblock, which will do:  
    - trim the first line  
    - iterate over all lines & find the shortest left-pad  
    - remove left-padding from all lines per the rules  
    - trim the last line  
    - combine all the lines for the description & the attributes.  
  
### Breakdown with attributes  
```  
  /* abc  
   * def  
     @param this is a sentence about @param  
         line 2 param  
   * @param(two,three) has a description. [something](/something)  
   */  
```  
1. match `/*` & discard all before.   
2. match `\n` & store `abc` as `docblock.line1`  
3. match `*` & replace it with ` `  
4. match `\n` & push the line `     def` onto `doblock.lines`  
5. match `@param `, create new attribute `ast` & set its name  
6. match `\n`. Store the line on the attribute ast as `attr.line1`  
7. match `\n`. Store the line `        line 2 param` on `attr.lines`  
    - it will be trimmed via the same left-pad trimming as docblock lines  
8. match `*` & replace it with ` `  
9. match `@param(`, terminate processing of any prior `@attribute`. Create new attribute ast & set its name & create an empty argslist  
10. match `,`. push `two` onto `attribute.args`  
11. match `)`. push `three` onto `attribute.args`.   
12. match `[set name. create `attribute.args` list.   
    - Append it to `@param(two](/`. new attribute `ast`)`s `attributes`   
    - OR add the attribute to the docblock? (probably not)  
13. match `)`. push `something` to `attribute.args`. immediately stop this directive.  
14. match `\n`. Store `has a description. [something](/something)` as `attribute.line1` on `@param(two,three)`  
15. match `*/`. set the line `    ` to `attribute.last_line`  
16. call php method to clean up the docblock, which will do:  
    - trim the first line  
    - iterate over all lines & find the shortest left-pad  
    - remove left-padding from all lines per the rules  
    - trim the last line  
    - combine all the lines for the description & the attributes.  
  
  
  
  
## Older notes  
  
### The indentation problem  
```  
    /* abc  
     * def  
     *    ghi  
         *   jkl  
        mno  
    */  
```  
Should become:  
```  
abc  
def  
   ghi  
      jkl  
 mno  
```  
  
So the indent to remove is the shortest indent, other than the first line.  
  
The shortest indent is:  
`    * `, before `def`  
  
For the rest the lines, it doesn't matter if they have a star or not.  
It just matters the distance from the 0 column to the first non-star char  
  
So we find the SMALLEST distance from the 0 column to the first non-star char  
  
The first line is always free from indentation considerations, due to how the grammar processes  
  
  
  
  
  
  
## The old notes  
- Write DocBlock + Comments Grammar  
    - `src`, `description`, and `attributes`  
    - Can come from multiple different styles (`##\n#\n#\n#` or `/**\n*\n*` or `// comment` or `! comment` or whatever)  
        - Maybe there is a docblock cleanup step that is non lexerryy?? Or I have to add something to make it flexible ...  
        - I suppose I could have a method that modifies one of my directives, so basically you just set the docblock type to `/*`, then the relevant directives are modified accordingly. This is a fairly convoluted approach, but it would also work. It could even be "aware" of what other language grammar is present, maybe. (maybe not though).  
    - catches `@name and the description about it`, `@name(arg1,arg2) description about it`, ... what about `@arg prop_name description about it` & catch `prop_name`??? I think this is a case-by-case kind of thing. Maybe depending upon the particular attribute? maybe the language grammar can define it  
  
  
/**  
*  
*/  
  
or /** */  
  
or   
##  
#  
#  
  
  
or   
#  
#  
#  
#  
  
or  
//  
//  
//  
  
So, first I have to make a decision about "what is a docblock?", well the common answer is:  
```  
/**  
*  
*  
*/  
```  
  
But if I want docblock functionality in different languages (bash), how tf do I do that?  
Well I've proposed:  
```  
##  
#  
#  
#  
```  
Which doesn't supply a clear terminator, but it makes sense.   
  
  
I could also do just a series of single-line comments. But I think that breaks a common expectation. So no. I won't do that.  
  
  
So right now, I'm counting `##\n#\n#` and `/**\n*\n*/` as well as their single-line counterparts `## stuff` and `/** */`  
  
But the `## stuff` breaks the docblock contract  
  
  
But how do I count `## whatever` as a docblock but NOT catch it as a comment?  
  
by simply defining things separately.... basically. The `#` would start a comment, but listen for docblock. Then if the next char is `#`, then that means we have a docblock & the comment listening can stop & we go into docblock mode.  
  
  
But how does docblock processing actually work? Lets start with a single line example.  
```docblock  
/** I am a simple docblock */  
```  
  
`/*` starts a docblock  
`*/` ends a docblock  
` I am a simple docblock ` is the description / body  
  
Then  
```  
/**  
* Simple multi-line docblock  
*/  
```  
  
So ...  
previously, I was just parsing all of the stars out after getting the end of the docblock. I could do that still, I suppose, but its kind of a jank solution, especially considering I have a lexer!  
  
So the things I want to remove are:  
`^\s+\*`  
If there is no `*` on a line,  
  
1. Get a `/*` to start a docblock  
2. Get a `\n` to end a line  
    - rewind 1  
    - append to body. Append to description?  
    - forward 1  
3. Get a `\n` or a `*` and discard what's before `*`  
  
  
Attributes:  
- Start-of-line attributes like `@param $argName description of arg`  
- in-line attributes like `I want you to @see TheThing`  
- start-of-line like `@param($argName, string) description of the arg`  
- in-line like: `Lets [TheThing](/TheThing)`  
  
I don't really care about the `This is @abad Inline Type`. Because its just ... not really clear how that should be interpreted & I don't think I want to make decisions about it & Code Scrawl doesn't use this style. Or it hasn't, anyway.  
  
  
  
  
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# Info I wanna keep around just because  
Some of this is actual like ... historical information for the project. A lot of it is just ... stuff I wrote down & might want to use later.  
  
  
## v0.6 changes  
A complete redesign to how directives are declared. The codebase is significantly cleaned up, and the project should be far more maintainable going forward, as well as much more useful as a lexer. I think `v0.5` was never fully functional. I believe I abandoned that in favor of a new design for v0.6  
  
## Some questions   
These are probably not accurate. But I wanted to keep them around & maybe answer them again.  
  
when is 'start' checked?  
    When the top 'started' list is empty and 'unstarted' is non-empty  
when are 'match' and 'stop' checked?  
    A directive's 'match' and 'stop' are checked if it begins the loop on the top started stack  
    'stop' is checked after 'match'  
    neither 'match' nor 'stop' are checked on the same loop that 'start' is checked.  
    'stop' is checked whether 'match' passes or not  
    'stop' is propagated upward at the end of lexing (before or after onLexerEnd()? )  
How do I customize tree output?  
    Possibly a custom Ast class. Should be specifiable in `ast.new`  
  
  
## Changes Prior to v0.5   
- set_previous feature  
- ast_set feature  
- rewind() feature to move the pointer back   
- Wrote Sample code & a draft document regarding a new design for lexer. One that moves away from state-based into expectations-based  
- Some changes and improvements to lexer & grammar  
    - Grammar's flow for building regexes is improved  
    - Lexer has minor changes to its implementation, especially in regard to automatically popping state & clearing buffers.   
- PhpGramamr2 handles properties, constants, methods, functions, strings, and some other things.   
- Implemented AST caching for files. File to parse checks `sha1_file`. `filemtime` is checked for each grammar. Does not check `lexer`, `ast`, `token`, or the base `Grammar` class files.  
- Write some docs. Clean up status notes  
- Updated existing grammars to work with refactored  
- Refactored lexer & Grammar & added new features.  
- Wrote most of an introduction  
- Small DocBlockGrammar fix  
- Some bug fixes with lexing & state  
- (php grammar)Catch namespace, class, method, docblock, and property  
- Create Docblock grammar  
- Write bash grammar to capture docblocks & function names  
- docblock parsing (to get attributes, basically)  
- PhpGrammar successfully prototyped & catching docblocks, properties, and methods for PHP  
- Ast getTree()   
- Generalized Ast  
- Refactored tests  
- Make its own repo  
- Convert current run script to a tlftest  
  
  
## v0.3 architecture  
This is out of date. We no longer use a `state` approach. Instead, each directive uses `then`s to point to the next directives to watch for  
  
### The lexer manages  
- `state`: The name of what's being processed at the moment. State is kept on a stack.  
    - `state` may be an asterisk (`'*'`) or asterisk in array (`['*']`) to be valid for all states  
    - Ex: After `/**` is found, we enter `state=='docblock'`.  
        - When `*/` is reached, we `pop` the state & return the parent state. Something like `class_body`, if the docblock was found inside a `class Something { /** docblock here */ }`  
    - When the `state` changes from one loop to the next, the list of valid regexes is updated  
- `token`: The text we're processing with convenience methods to get the current buffer, add a char to the buffer, etc  
- `head`: The `ast` at the top of the stack.  
    - The initial ast is always on the bottom of the stack & is the first `head` that is used  
    - Grammars append new `ast`s to the stack & can pop them off.  
        - Currently, this must be done programmatically in php. There is not a declarative solution.  
- `valid_regex_list`: The list of directives to check for the current state  
- `success_regex`: The directive who's pattern matched the current buffer  
- `grammar`: Directives & methods that allow you to do ast building & parsing with the lexer   
- `directive`: A regex to match & instructions about what to do when the regex is matched  
    - Formerly, directives were simply called regexes  
  
### Setting up the lexer environment  
1. Lexer is initialized  
2. Grammars are added to the lexer. Additional work is done during their `__construct`ors  
    - Grammar must do additional processing for regex declarations. See Grammar.php for up-to-date implementation info  
        - Convert all non-array values to arrays (except `set_state`)  
        - check for `onRegexName()` method on the grammar and set it to `onMatch`  
            - also checks `on_regexName`  
        - Set `state=>['*']` if it wasn't set  
        - Set `name=> `, the key that identified this regex entry in the grammar.  
    - Grammar supports a `regex_end` feature which is not supported by the Lexer. Each `regex_end` entry is converted into a standalone `regex` with flags:  
        - `name=>'endofreg:the_original_regexes_name'`  
        - `regex=> ` the regex array found at `regex_end`  
        - `state=> ` Whatever `set_state` is on the original regex  
        - `pop_state => true`  
        - `onMatch => ` For a regex with name `"string_open"`, Method `onendString_open()` if the method exists on the current grammar  
    - the `regex_end` feature is now better used as `'end'=>[/*normal regex declaration*/]` where everything in `end` is copied into its own regex entry  
3. An `Ast` is created to be the root  
    - `lex($filePath)` creates an ast & sets attributes to that ast  
    - For `lex($filePath)`, the cache is checked & a new lex is only done if the file or any of the grammars are different from last time it was run (or if `$lexer->useCache` is `false`).  
4. The ast is set as the `head`   
5. A `Token` is created from the passed in `string` (file contents in the case of `lex($filePath)`)  
6. For each grammar `onLexerStart($lexer, $ast, $token)` is called  
  
  
### lexing begins  
1. using a while loop, set `$token = $token->next()`, which returns itself with an updated buffer, or `false`, if there are no more characters to process  
    - `next()` adds one character to the buffer at a time.  
2. Each `valid_regex` for the current state is now checked.   
    - Warning: No more `valid_regex`es are checked after the first one matches  
3. The first regex that matches is stored as a `success_regex`  
    - The `success_regex` contains some or all of:  
        - `cur_match`, the current results of `preg_match`ing.  where `[0]` is the full match, `[1]` is the first set of parentheses & so on  
  
        - `regex=>[/regex1/, /regex2/]`. Only one regex has to match & and processing stops after the first regex is matched  
        - `state=>[state1, state_2]`. The state `$lexer` must be in for this regex to be checked  
        - `state_not=>[state3, state_4]`. If `$lexer->getState()` is one of these, do not check this regex. For every other state, check this regex (unless `state=>` is also given.)  
        - `onMatch =>` the function to call when this regex is matched   
        - `set_state` => `new_state`. to call `$lexer->setState('new_state')` when this regex is matched  
        - `buffer.clear => true` to call `$token->clearBuffer()` when regex is matched  
        - `pop_state => true` to call `$lexer->popState()` and `$token->clearBuffer()`  
4. Every `success_regex` now begins processing  
5. if `$debug` is on (hardcoded rn), then print state information.  
6. set `cur_match` to `$token->setMatch($cur_match)`  
8. Call `onMatch` function, if it was set  
7. Process every other directive  
7. Set `$lexer->state` to `set_state` if key present on the directive  
8. Print additional state information if `$debug==true`  
9. Call `onLexerEnd()` on each grammar  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# PhpGrammar Architecture  
The Php Grammar uses the Lexer's declarative features to capture a small set of basic information, then routes to appropriate PHP functions for additional handling. There are `words` and `operators`. `words` are basically any string of alphanumeric characters, including underscore and backslash. `operators` are basically any symbol (or series of symbols) that have a particular meaning in the language.  
  
There is a `Handlers` trait which takes the basic information & routes it to an appropriate method. Operations are mapped from symbol to a string (like `=` is `assign`). Then operations are routed like `$this->op_assign()`. Words like `$this->op_function` (when the word `function` hits).   
  
There is an `$xpn` (expression) ast used as a simple object to hold meta data / state information.   
- `$xpn->declaration` is automatically appended to by whitespace, words, operators (maybe docblocks??? maybe comments ??).   
- `$xpn->words` is automatically appended to each time a word is encountered.  
- `$xpn->last_op` is the last operation recorded & is set automatically after an operation is done being handled.  
- `$xpn->waiting_for` is set by specific handlers for specific words/operators & checked by subsequent handlers to see if the state is correct.  
- `$xpn->head` ... is sometimes set as an ast for something to be acted upon, but is not added to the regular ast stack. Idr the use case.  
  
Both declaration & words are reset to an empty array frequently by specific handlers.  
  
  
## Old notes from developing the idea of the current arcitechture  
I'm thinking of a new paradigm where I catch EVERYTHING & at 'stoppers' I will process what has been captured. Essentially I will capture "words" which are .... and encapsulated sequence of characters. `" i am a string"` is one `word` because that's a single unit for parsing.  
  
in `public int $abc = "I am a thing";`, the words are:  
- public  
- int  
- $abc  
- =  
- "I am a thing"  
  
Then `;` is a `stopper`. Maybe `=` is a stopper, too.  
  
The idea is that ... everything works out to be an expression made up of words and operators.   
  
```php  
<?php  
protected $whatever = 'cat';  
/** abc */  
static public function abc(bool $b): string {  
    $abc = "cat";  
    $def = "dog";  
    return "zeep";  
}  
```  
It's gonna build the same kind of AST, but now I get to think about it differently.  
so, `protected $whatever =`.  
When I hit `=`, I know I have an `assignment` operation  
the left-hand words of that operation are `['protected', '$whatever']`;  
The last word is the property name. All words before it are modifiers (which may include type).  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# Php Language Features  
This likely is not an exhaustive list & not necessarily everything here is handled by the PhpGrammar. Also, Docblocks are handled by their own grammar.  
  
  
- `use NS\ClassName as ShortName` statements (maybe)  
- `use TraitName` statements  
    - done  
- interfaces  
- traits  
- docblocks  
    - description  
    - attributes in style `@tag some_tag`  
        - name  
        - value (some_tag)  
    - attribute in style `@tag(some_tag) a description`  
        - name  
        - value (some_tag)  
        - description  
    - The next expression/ast/thing.   
        - Currently, I'm using the `previous` mechanic to attach docblock to stuff. I don't really think there's a better way about this.  
- comments  
    - content  
    - attributes in both styles (see docblocks)  
    - The next expression/ast/thing, maybe???  
- class (including anonymous classes)  
    - properties  
        - private/public/protected  
        - static/not-static  
        - name  
        - docblock  
        - default value  
    - constants  
        - private/public/protected  
        - static/not-static  
        - name  
        - docblock  
        - default value  
    - methods  
        - private/public/protected  
        - static/not-static  
        - name  
        - docblock  
        - arg list   
            - paramater names  
            - default values  
        - method body code  
- functions  
    - name  
    - docblock  
    - arg list  
    - function body code  
- HEREDOC - & discard it  
- NOWDOC - & discard it  
- string & discard it  
- php8 attributes? Meh  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
## Cli command parsing  
Options:  
- call `$this->execCommand()`  
    - If there is no namespace  
- call `$grammars[namespace]->$command()`  
    - if there is a namespace  
- call `$targets[$namespace]->$command()`  
    - if there is a namespace  
  
Args options:  
- `command` is an argument (only for `execCommand` / no namespace)  
- `$phpArg` is `false` (do not run the command)  
- `$phpArg` is `true` (run the command)  
- `$phpArg` is a single argument appended to cli arguments (anything but `false`)  
- `$phpArg` is an array of arguments. Give `...` as the last cli argument  
- TODO `$phpArg` is an array of commands to run. Give `[]` as the last cli argument. `command` is prepended to each entry in the `$phpArg` array  
- TODO `$phpArg` is an executable object+method+args. Pass `!` as the last cli argument, then use `_object:method arg1 arg2` like `_lexer:previous docblock`  
  
  
So basically, we parse the `namespace:command` which gets us an object + method & MAY start an arg list. Then we parse the cli command args & add them to the list.  
1: Create an args list from the cli args + php args  
2: Get the object + method & modify args list as needed  
3: Call object + method with the final args list  
  
  
## Command Expansion  
Add `command ...`, `command []`, and `command // abc dogs and cats` features  
- default: `command abc=>[1,2,3]` is same as `command abc [1,2,3]`. (though arrays aren't allowed in the command shorthands. The array is a single argument)  
- `...`: `command abc ...=>['d','e','f']` is same as `command abc d e f`   
- `[]`: `command abc []=>['a'=>true, 'b'=>'dog']` is same as `command abc a true` and `command abc b dog`  
    - `command abc []=>['a','b']` is same as `command abc a` and `command abc b`  
- `//`: `command abc // cats` is same as `command abc`. The `//` lets you write multiple matches, for example.  
- `!`: `command def ! => '_lexer:previous docblock'` will call `command def $lexer->previous('docblock')`, essentially  
  
  
## Directive Overrides   
I don't know if this is accurate, but I think it is & once verified, these notes can be used for documentation.  
  
- Inheritance rules:  
    - if raw `match` directive is first in src directive, then add it first  
    - then add instructions from the child directive, in declared order  
    - then add all other instructions from the source directive, in their declared order.  
        - If child directive contains any keys found in source directive, then do not copy the value from the source directive. The child simply overwrites (but in the child's declared order)  
# Architecture
This is a pretty poor explanation of the architecture, but its good enough for me. If its not good enough for you, please submit a PR.

The Lexer manages the directive stack, overall program execution, and most things. The Token manages our placement in the input string. The Grammars declare directives which have instructions to perform when they're matched. These instructions can modify the token, the lexer, and create new Asymmetrical Syntax Trees (ASTs) to create structured representation of the source. Grammars also declare methods to use as additional instructions.

If you want to write a grammar, see @see_file(docs/GrammarWriting.md). (but it might help to understand the architecture).

## Flow of Lexing
1. Lexer is initialized
2. Grammars are added to the lexer.
3. An `Ast` is created to be the root
    - Lexer has convenience methods, or you can create your own AST to lex.
4. The ast is set as the `head` 
5. A `Token` is created from the input `string`
6. For each grammar `onLexerStart($lexer, $ast, $token)` is called
7. Perform the lexing (see below)
8. For each grammar `onLexerEnd($lexer, $ast, $token)` is called

### The Pieces
- `Lexer:` takes Grammars to process an input string using a Token
    - `$directiveStack`: A multi-layered stack of directives. Each layer can have multiple directives. Each layer has a 'started' and 'unstarted' list.
    - `$astStack`: The stack of ASTs. Generally the head ast is operated on
- `Token`: Contains the input string. Manages our position in the input string.
- `Grammar`: Declares directives 
    - `directive`: A set of targets & instructions. Generally contains a string or regex (target) to match against & instructions for what to do upon that match.
- `Ast`: An Asymmetrical Syntax Tree... holds values & can be output as an array

### The Lexing 
1. using a while loop, set `$token = $token->next()`, which returns itself with an updated buffer, or `false`, if there are no more characters to process
    - `next()` adds one character to the buffer at a time.
2. Each `started` directive is checked for `match` and `stop`. If there are no `started` directives, then `unstarted` directives are checked for `start`
3. If `started` directives stop, they're moved back into `unstarted`. And visa versa when `unstarted` directive start.
4. Any regexes that passed in step #3 are now processed for their instructions, in the order those instructions were declared.
5. `then`s are processed & any target directives are added to a new layer of the directive stack
6. Repeat from #1 until the token has been fully buffered
# ChangeLog

## Other Notes
- 2023-12-23: Create branch v0.8-programming-language. Idea: Focus the Lexer around an own-built programming language. Currently the language is written as Directives & the stdlib is in php. This library is centered around the Lexer. Instead, this library could be centered around the programming language.
- 2023-11-21: Cleaned up the repo, moved files around
- 2023-11-21: Added prototype outputting code from an ast

## Git Log
`git log` on @system(date, trim)`
@system(git log --pretty=format:'- %h %d %s [%cr]' --abbrev-commit)
# Create Language Parser
To parse a new, currently unsupported language, you'll define `Directives`, written in a simplified programming language. Directives are backed by php code, either built-in to the `Lexer` or added to your language parser's `Grammar`.

The goal of parsing code is to create an AST - Asymmetrical Syntax Tree. It's just a multi-dimensional array that details the structure of the parsed code.

(*The Lexer could potentionally parse things other than code, such as cooking recipes.*)

## In this file
- How the Lexer Works
- Directives
- Instruction Examples
- Available Instructions

## How the Lexer Works
The Lexer creates a  `Token`, an `Ast` stack, and a `Directive` stack, then loops over each individual character in the input string, adding one character to the Token's buffer on each loop.

On each loop, the head of the Directive stack is processed, and instructions may modify the head ast, add another directive to the top of the stack, create a new ast, rewind the buffer, or do many other tasks. (*Note: Most instruction sets start with a `match /regex/` instruction, which must succeed to run other instructions.*/

Each layer of the Directive stack contains an 'unstarted' and a 'started' list (*each list is an array of Directives, or an empty array*).

Each Directive may contain up to 3 instructions sets: 'start', 'match', and 'stop'. (*@todo We'll talk about the special 'is' instruction set later.)

When the 'started' list is empty, 'unstarted' directives are processed. When an 'unstarted' directive is processed, its 'start' instruction set is executed. If the 'start' instruction set succeeds, the Directive is added to the 'started' list.

When the 'started' list is NOT empty, 'started' directives are processed. When a 'started' directive is processed, its 'match' and 'stop' instruction sets are executed. 'match' goes first. If 'stop' is executed successfully, the Directive is moved back to the 'unstarted' list.

A Directive may add a layer to the directive stack. Then on subsequent loops, the new head directive layer will be processed, and the previous directive layer will be paused, until it is the head layer again.

The Lexer loops in this way, over each character, until all characters are processed. 

When the Lexer finishes parsing a string, it returns a detailed AST describing the input file/string.

To recap, Directives and ASTs are both on a stack. Directives are processed on each loop, executing instructions that modify ASTs, create new ASTs, and tell the Lexer which Directives it should run next. 

*Tip: the lexer has a 'stop_loop' setting for debugging, to stop after a given number of loops.*)

## Directives & Instruction Sets
A `Directive` is a named array of instruction sets. Each instruction set contains an array of `instructions` (*lol*).

Most instruction sets begin with a `match /regex/`, which matches against the Token's current buffer. If the regex matches, an unstarted directive is started, and the instructions after the match instruction are processed. If the regex does not match, the rest of the instruction set is not processed. 

## Instructions
There are 20+ instructions available, and you can directly call methods on your Grammar, the Lexer, or the Token.

Instructions can be a string like `'token.rewind 3'` or a key/value pair like `'ast.new' => ['type'=>'class','name'=>'_token:buffer' ...]`, which creates a new ast.

If defining a **key/value pair**, the key is the instruction and the key may conain arguments, and the value is an argument to pass to the instruction. 
*Tip: This allows arrays to be passed to instructions.*  
*Tip: If the value is (*strict boolean*) `false`, the instruction is disabled.*  
*Tip: If the key begins with an underscore (`_`), the instruction is disabled.*  

The instruction can include arguments, separated by a space. The key may end in a special/reserved argument. The reserved arguments are `...`, `[]`, `!`, and `// comment`. The value may be any php data type, depending on the instruction's requirements & any reserved args that are used. 

(*Tip: Add comments if you ever have two identical keys in an instruction set.*)

If you only define a value (no string key), then the value is your instruction, and reserved arguments are unavailable.

## Instruction Examples
`"instruction a b c"` passes three arguments `('a','b','c')` to the instruction
`"object:method arg1 arg2"` calls a php object's method, passing two args `('arg1', 'arg2')`
`"instruction a" => "b b"` passes two arguments ('a', 'b b') to the instruction
`"instruction a" => ['b', 'c', 'd'`] passes two arguments to the instruction `('a', ['b','c','d'])`  
`"instruction a ..." => ['b', 'c', 'd'`] passes four arguments `('a','b','c','d')` to the instruction.  
`"instruction []" => 'value'` throws an exception because `[]` is reserved for future use.
`"instruction !" => '\_object:method arg1 arg2'` calls the named php object/method, and the return value is passed to the instruction. 

For `object:method`, you can call any public method on the object, and available objects are:
- `lexer`, \Tlf\Lexer 
- `token`, \Tlf\Lexer\Token
- `ast`, \Tlf\Lexer\Ast - the head ast
- `this`, \Tlf\Lexer\Grammar - the Grammar attached to the current directive (*The Grammar that defines the current directive*).
- any other grammar name.  (*must be a grammar that's added to your lexer instance*)

Non-Grammar methods are called like `$object->method(...$args)` where `$args` is what's defined in your instruction, like `['arg1', 'arg2']`.

Grammar methods receive `($lexer, $headAst, $token, $directive, $args)`, where `$args` is what's defined in your instruction, like `['arg1', 'arg2']`. 

## Available Instructions
- `match /regex/` - Start directive & continue processing instruction set if `/regex/` matches the current token buffer
    - or `buffer.match`
- `then :directive_name` - Add the named directive to the directive stack. Creates a new layer on the stack once per loop.
    - or `directive.then`
    - `then grammarname:directive_name` - Add a directive of another grammar, such as from the docblock grammar
    - `then directive_name.stop` -  Add the named directive's 'stop' instruction set as a 'start' 
    - `"then :+new_directive_name" => $directive` - Create a new directive to add to the stack, instead of referencing a named directive.
    - `"then _blank" => $directive` - same as to `:+`
    - `"then directive_name" => $directive_overrides` - To add a directive, but override parts of it. See [Grammar.php](code/Grammar.php) `getOverriddenDirective()`.
- `then.pop :directive_name layers_to_pop` - Add a directive to the stack & immediately pop the directive layer when it is matched (instead of the directive's normal functioning). 
    - `layers_to_pop` is an int
    - Rewinds by the length of the first capture group from the target directive's match
    - Creates new Directive stack layer before pop if it is the first `then` call this loop
- `buffer.notin key` - Check if the current buffer matches a string in your grammar's `public $notin`. If no match, then clear the buffer and ... i think start/stop directive? idk
    - Your grammar defines `public $notin = array<string key, array array_of_strings>`. 
    - `buffer.notin key` checks `!in_array($grammar->notin['key'], 'current_buffer')`
- `"ast.new" => []` - Create a new ast 
    - arg `type=>class` or `_type` - a string type or `_object:method arg1 arg2` to call on lexer, token, or head ast
    - arg `_setHead=true|false` - (optional) true to add to top of ast stack. false to not. default is true.
    - arg `_class=>PhpClass` - (optional) the Ast's php class.
    - arg `_setto=>property` - (optional) Add the new ast to the current head ast's named property.
    - arg `_addto=>property` - (optional) Same as `_setto`
    - arg `_setPrevious=>key` - (optional) Set the new ast to the 'previous' key. 
        - *Ex: we create a docblock ast & we `_setPrevious=>'docblock'`, then we encounter a class and retrieve it with `$lexer->previous('docblock')`, to set the class's docblock.*
    - If not `_setto` or `_addto`, then if the type is 'class', then the new ast is added to the current head ast's 'class' property.
    - Any other key/value pair - the key is the name of a property on the ast. The value is either the value to set, or it calls an `_object:method arg1 arg2` if it is a string starting with an underscore (`_`). Ex: `_token:buffer` would set the current buffer string to the property.
- `debug.die` or `die` - Same as `debug.print` but `exit`s. 
- `debug.print` or `print` - Shows what php values were created from your instruction.
- `directive.inherit [:directive.isn] ["match"]` or `inherit` - Run commands of another directive, except for the 'match' instruction. 
    - Ex: `inherit :string_instructions.stop`
    - Include literal string 'match' to enable the 'match' instruction. 
    - arg `:directive.isn` - `isn` is the instruction set name ('start', 'match', or 'stop'). 
- `directive.start` or `start` - Mark the current directive as started. 
    - You can start a Directive with `start` instead of match.
- `directive.stop` or `stop` - Mark the current directive as stopped
    - Allows a 'match' instruction set to stop a directive
- `token.rewind [num_chars]` or `rewind` - Rewind the token. 
- `token.forward [num_chars]` or `forward` - Move the token forward
- `directive.halt` or `halt` - Halt the current directive, so further instructions in the active instruction set will not be processed. Other instruction sets in the active stack list will be processed.
- `halt.all` - Halt the all other instructions sets waiting to be processed. To also halt the active instruction set, call 'directive.halt' AFTER 'halt.all'
- `previous.set [key]` - Set the current buffer to the 'previous' key/value set, for the given key.
    - Ex: `previous.set docblock` is used to capture a docblock, then when the next class or function is found, the Directive will call `"ast.set docblock !" => _lexer:previous docblock` 
- `previous.append [key]` - Append the current buffer to the 'previous' key/value set, for the given key.
    - `"previous.append" => ['statement', 'method_declaration']` also works
- `directive.stop_others` - Loop through the list of all other started directives and move them to the unstarted list. Does NOT stop the active directive (*the one calling directive.stop_others*).
- `directive.pop [num_layers]` - Pop layers off the Directive stack.
- `buffer.clear` - Clear the buffer
- `buffer.clearNext [num_chars]` - Progress the buffer forward [num\_chars], but do NOT add those chars to the buffer. May corrupt the token... 
- `buffer.appendChar [string]` - Append a string to the buffer. May corrupt the token...
- `ast.pop` - Remove the head AST from the top of the stack, unless it's the last one.
- `"ast.set [property] !" => '_object:method arg1 arg2'` - Set head AST's `[property]` to `$object->method('arg1','arg2')`'s return value.
    - `ast.set [property]` will set the head AST's `[property]` to the current buffer.
    - Ex: `"ast.set docblock !" => '_lexer:previous docblock'` will get the docblock from the 'previous' key/value set, and set the 'docblock' property on the head ast.
- `ast.push [property]` - Append the current buffer to given array property on the head ast.
- `"ast.append [property] !" => '_object:method arg1 arg2'` - Append to the head AST's `[property]`. Same as ast.set, except this appends.


## Example
// @todo make a better example
```<?php
['docblock'=>
    [  
        'start'=>[  
            'match'=>'##',  
        ],  
        'stop'=>[  
            'match'=>'/(^\s*[^\#])/m',  
            'rewind 2',  
            'this:handleDocblockEnd',  
            'buffer.clear',  
            // 'forward 2'  
        ]  
    ]
];
```
# PHP Grammar
This document is for the further development of the PHP Grammar.

## Status
- Language Support: Php 8.2
- Parses:
    - Classes, traits, interfaces, namespaces
    - methods, functions, anonymous functions
    - class propreties, class consts, method/function properties
    - docblocks, comments
    - return types, property types
- Does NOT parse:
    - expressions, for loops, method calls
    - enums
- Work being conducted:
    - wrote `wd_enum` and the elseif in `unhandled_wd` to set the enum name. (*commented them out*)
    - adding enum support requires parsing the `case`es & may have other syntax. Need a quick break down of the syntax & some tests.

## Documentation 
- @see_file(test/output/PhpFeatures.md, Features Available) - Overview of which features are implemented, tested, and passing.
- @see_file(code/Php/README.md, Architecture Description)

## Overview
You most likely will work on `Operations.php` or `Words.php` to add any new features. If you define or modify any directives, then you may want to add handlers in `Handlers.php`.

To *define new operations*, add a symbol to the operations array in get_operations. It will look like `'&&'=>'and'`. Then define a method `op_and()`
1. Define an operation handler like: `public function op_my_new_symbol($lexer, $ast, $xpn)`
2. Add the symbol to `get_operations()`: `'&%'=>'my_new_symbol'`
3. Fill out your operation handler

To *define new words*, either:
- define a word handler: `public function wd_enum($lexer, $xpn, $ast)`
- or add a case to `unhandled_wd()`, like `else if ($ast->type == 'trait' && !isset($ast->name))`

To *create a new handler*, definable in the directives:
- `public function handleMyNewDirective($lexer, $ast, $token, $directive)`
- Then, In a directive write `'this:handleMyNewDirective'`

For *writing directives*, look at the CoreDirectives.php file and the @see_file(README.md, README).

## Code
- @see_file(code/Php/PhpGrammar.php, PhpGrammar.php) - Base class, implementing the lexer's callback methods, and `use`ing the directive & handler traits.
- Directives
    - @see_file(code/Php/CoreDirectives.php, CoreDirectives.php)
    - @see_file(code/Php/StringDirectives.php, Words.php)
- Handlers
    - @see_file(code/Php/Handlers.php, Handlers.php) - Defines methods callable by directives. Enables Operations & Words as simplified handlers.
    - @see_file(code/Php/Operations.php, Operations.php) - Handles all the symbols
    - @see_file(code/Php/Words.php, Words.php) - handles keywords & other non-string alphanumeric chars, like property names.

## Testing
- PHP directive test: 
    - `phptest -test ShowMePhpFeatures` for a summary of the directive tests
        - see `test/output/PhpFeatures.md` or view in the terminal
    - `phptest -test Directives -run Directive.TestName` 
        - add `-version 0.1` to skip new directive handling. Default in tests is `-version 1.0` which has new signal-based functionality. Default in production is `0.1` and in code use `$lexer->version \Tlf\Lexer\Versions::_1` for signal-based.
        - add `-stop_loop 50` to stop after the 50th loop
        - see @see_file(test/src/Php/,`test/src/Php`) to create new directive test
        - see @see_file(test/Tester.php,`test/Tester.php`) - see the `$sample_thingies` at the top for an example. And see `runDirectiveTests()`, though idr how it works.

## TODO
- parse expressions
- Document it better
# Grammar Commands
These commands are available for your directives to execute. See an example at @see_file(docs/GrammarExample.md). See instructions for writing a grammar at @see_file(docs/GrammarWriting.md)

In the internals, there are two types of commands. 
- switch/case commands, which generally have a simple or small implementation. 
- mapped commands, which point a command to a method (rather than the switch-case)
    
## Mapped commands
The key points to a method on the `$lexer` instance, but they're written in the `MappedMethods` trait. See @see_file(code/Lexer/MappedMethods.php)
```php
@import(Commands.MethodMap)
```

## `switch/case` commands 
These are the exact implementations of the commands from @see_file(code/Lexer/Instructions.php)
```php
@import(Commands.SwitchCase)
```
# Lexer Examples

## Lex a file
```php
<?php
@import(Test.Doc.LexFile)
```
See @see_file(test/input/php/lex/SampleClass.php) for the input file and @see_file(test/output/php/tree/SampleClass.js) for the output `$tree`.

## Lex a string
This example is a bit more involved. `Docblock` is generally added by a programming language's grammar, so `Docblock` does not automatically start being listened for, the way `<?php` would be with the PhpGrammar.
```php
@import(Test.Doc.LexString)
```
The root ast contains the string, which we're not really interested in.

## Lex with your own root ast
This is basically what happens when you lex a file, EXCEPT `lexFile()` automatically handles caching, so subsequent runs on the same unchanged file will be loaded from cache. This approach ignores the cache completely.
```php
<?php
@import(Test.Doc.LexAst)
```
# Extending the lexer
Convert code or other text into a structured tree (multi-dimensional array).

In This File:
- create a grammar with directives & handler functions
- test a grammar
- a complex directive that builds an AST without php
- How to write an extension

## Extending
To extend the lexer, we will do four things, iteratively. 
1. Create a Grammar
2. Create an array of Directives
3. Create a trait for callbacks Directives use
4. Write Directive tests

To run it, I suggest using your preferred test suite. Though, the built-in directive tests (composer) require `taeluf/tester`

### 1. Grammar
We'll be recreating part of the Bash Grammar. 

```php
<?php

class MyBashGrammar extends \Tlf\Lexer\Grammar {

    use MyBashGrammarCallbacks;

    public function getNamespace(){return 'mybash';}

    protected $directives = [];

    public function __construct(){
        $file = file_get_contents(__DIR__.'/directives.php');
        $directives = require($file);
        $this->directives = $directives;
        // @tip use `array_merge()` to load directives from multiple files
    }

    public function onLexerStart($lexer,$file,$token){
        // if you have any additional setup to do
    }
}
```

### 2. Directives
**directives.php**
```
return [
        'root'=>[
            'is'=>[
                // ':comment',
                ':docblock',
                ':function',
            ],
        ],

        'docblock'=>[
            'start'=>[
                'match'=>'##',
            ],
            'stop'=>[
                'match'=>'/(^\s*[^\#])/m',
                'rewind 2',
                'this:handleDocblockEnd',
                'buffer.clear',
                // 'forward 2'
            ]
        ],

        'function'=>[
            'start'=>[
                'match'=>'/(?:function\s+)?([a-zA-Z\_0-9]*)(?:(?:\s*\(\))|\s+)\{/',
                'this:handleFunction',
                'stop',
                'buffer.clear',
            ]
        ],
        // an additional 'comment' directive is below
    ];
```

### 3. Callbacks 
We'll write a trait with function to handle directive calls. You'll notice `this:handleFunction` in the directives above. That will call `handleFunction(...)` on your trait below. 

```php
<?php
trait MyBashGrammarCallbacks {

    public function handleDocblockEnd($lexer, $ast, $token, $directive){
        $block = $token->buffer();
        $clean_input = preg_replace('/^\s*#+/m','',$block);
        $db_grammar = new \Tlf\Lexer\DocblockGrammar();
        $ast = $db_grammar->buildAstWithAttributes(explode("\n",$clean_input));
        $lexer->setPrevious('docblock', $ast);
    }

    public function handleFunction($lexer, $ast, $token, $directive){
        // $func_name = $token->match(1);
        $func = new \Tlf\Lexer\Ast('function');
        $func->name = $token->match(1);
        $func->docblock = $lexer->previous('docblock');
        $lexer->getHead()->add('function', $func);
    }
```

### 4. Directive Tests
You need to be using `taeluf/tester` for built-in tests to work
```php
<?php

class MyBashGrammarTest extends extends \Tlf\Lexer\Test\Tester {

    protected $my_tests = [
        'Comments'=>[
            // the 'comment' directive is below and can be added to the `MyGrammar` that is above
            'start'=>'comment', // t
            'input'=>"var=\"abc\"\n#I am a comment\nvarb=\"def\"",
            'expect'=>[
                "comments"=>[
                    0=>[
                        'type'=>'comment',
                        'src'=>'#I am a comment',
                        'description'=> "I am a comment",
                    ]
                ],
            ],
        ],
    ];

    public function testBashDirectives(){
        $myGrammar = new \MyGrammar();
        $grammars = [
            $myGrammar
        ];
        // $docGram->buildDirectives();

        $this->runDirectiveTests($grammars, $this->my_tests);
    }

}
```

## A more complex directive
```php
<?php
// you would put this in your directives class
$directives = [
    'comment'=>[
        'start'=>[
            'match'=>'/#[^\#]/',
            'rewind 2',
            'buffer.clear',
            'forward 1',
            // you can create & modify ASTs all in the directive code, without php
            'ast.new'=>[
                '_addto'=>'comments',
                '_type'=>'comment',
                'src'=>'_token:buffer',
            ],
            'buffer.clear //again',
        ],

        // `match` gets called for each char after `start`
        'match'=>[
            'match'=>'/@[a-zA-Z0-9]/', // match an @attribute
            'rewind 1',
            'ast.append src',
            'rewind 1 // again',
            'ast.append description',
            'forward 2',
            'buffer.clear',
            'then :+'=>[ // the :+ means that we're defining a new directive rather than referencing an existing one
                'start'=>[
                    //just immediately start
                    'match'=>'',
                    'rewind 1',
                ],
                'stop'=>[
                    // i honestly don't know why I have this here.
                    'match'=>'/(\\r|\\n)/',
                    'rewind 1',
                    'ast.append src',
                    'buffer.clear',
                ]
            ],

        ],
        'stop'=>[
            'match'=>'/(\\r|\\n)/',
            'rewind'=>1,
            'ast.append src',
            'ast.append description',
            'forward'=>1,
            'buffer.clear',
        ],
    ]
];
```
# Example
This is a really simple example of a functional, tested grammar. They get much more complex.
- Get further grammar-writing instructions in @see_file(docs/GrammarWriting.md)
- Look at the commands available in @see_file(docs/GrammarCommands.md)


## StarterGrammar's Directives
Most grammars will have more directives & multiple traits to facilitate organization. This example only uses one trait.
```php
@file(code/Starter/OtherDirectives.php)
```

## StarterGrammar
See that directives are built during `onGrammarAdded()` from the traits.
```php
@file(code/Starter/StarterGrammar.php)
```

# Php Lexer
A declarative lexer seamlessly hooking into php functions, building ASTs for multiple languages.

## Development Status / Roadmap 
### May 13, 2022 Update:
Branch `v0.8` is highly tested for PhpGrammar. It does not support PHP 8.0+ features. Most other Php Features are supported, but likely not all. 

The documentation is ... not good.

This project is in use by [Code Scrawl](https://tluf.me/php/code-scrawl) & will be further developed as i personally need it to be. For example today (may 13), i added support for `use ($var)` on anonymous functions, because i was unable to generate proper documentation for [Lil Db](https://tluf.me/php/lildb)

I dream, one day, of supporting many languages & possibly transpilation. I doubt that dream will be realized. 

I don't plan to significantly change the internal implementation of the lexer or grammars. I think it could be a lot better, but this would require serious development time I'm not likely to give to this project.

## Install
For development, it depends upon @easy_link(gitlab, taeluf/php/php-tests), which is installed via composer and @easy_link(gitlab, taeluf/php/CodeScrawl), which is NOT installed via composer because of circular dependency sometimes causing havoc.
@template(php/composer_install,taeluf/lexer)

## Generate an AST
See @see_file(docs/Examples.md) for more examples
Example:
```php
@import(Test.Doc.LexFile)
```
See @see_file(test/input/php/lex/SampleClass.php) for the input file and @see_file(test/output/php/tree/SampleClass.js) for the output `$tree`.

## Status of Grammars
- Php: Early implementation that catches most class information (in a lazy form) but may have bugs
- Docblock: Currently handles `/*` style, cleans up indentation, removes leading `*` from each line, and processes simple attributes (start a line with `  * @something description`).
    - Coming soon (maybe): Processsing of `@‌method_attributes(arg1,arg2)`
- Bash: Coming soon, but will only catch function declarations & their docblocks. 
    - the docblocks start with `##` and each subsequent line must start with whitespace then `#` or just `#`.
    - I'm writing it so i can document @easy_link(tlf, git-bent)
- Javascript: Coming soon, but will only catch docblocks, classes, methods, static functions, and mayyybee properties on classes. 
    - I'm writing it so i can document @easy_link(tlf, js-autowire)

## Write a Grammar
A Grammar is an array declaration of `directives` that define `instructions`. Those `instructions` may call built-in `command`s or may explicitly call methods on a grammar, the lexer, the token, or the head ast.

Writing a grammar is very involved, so please see @see_file(docs/GrammarWriting.md) for details.

## Warning
- Sometimes when you run the lexer, there will be `echo`d output. Use output buffering if you want to stop this.
- During `onLexerEnd(...)`, Docblock does `$ast->add('docblock', $lexer->previous('docblock'))` IF there's a previous docblock set.

## Contribute
- Need features? Check out the `Status.md` document and see what needs to be done. Open up an issue if you're working on something, so we don't double efforts.
# Parse Code into an AST
Docs to-be-written
# Lexer
Parse code and other text into structured trees.

The Lexer loops over the characters in a string, and processes them through Grammars to generate Asymmetrical Syntax Trees (AST) - Basically just a multi-dimensional array that describes the code. 

## Documentation
- Installation & Getting Started are below
- [Create a Parser](docs/CreateParser.md) - Create a language parser that builds an AST, or modify an existing parser.
<!-- 
- [Parse Code / Create AST](docs/ParseCode.md) - Parse your code into an AST using an existing language parser.
- [Use ASTs](docs/UseAST.md) - Use an AST to retrieve classes, methods, properties, and more.
-->

### Other/Old Documentation
- Extend Lexer - Create your own grammars to support new languages
    - @see_file(docs/GettingStarted.md, Getting Started) - Write a grammar class, create directives, and test your grammar.
    - @see_file(docs/Tips.md, Tips & Overview) - How To tips & troubleshooting
    - @see_file(docs/DirectiveCommands.md, Directive Commands) - Commands you can use in your directives.
    - @see_file(docs/Examples.md, Extra Examples) 
    - @see_file(docs/Testing.md, Testing your grammar)
- @see_file(docs/api/code/) - Generated api documentation 
- @see_file(docs/Architecture.md, Architecture)
- Development - Further develop this library
    - @see_file(Status.md, Development Status & Notes) - The current state of development, and common development tips.
    - @see_file(docs/Development/PhpGrammar.md, Php Grammar) - How to further develop the PHP Grammar.
    - [Changelog](/docs/Changelog.md)
- Defunct documentation
    - @see_file(docs/GrammarExample.md, Grammar Examples)
    - @see_file(docs/OldReadme1.md) - An old README that might have useful information.

## Supported Languages
Additional language support can be added through new grammars. See @see_file(docs/Extend.md).
- Docblocks: Parses standard docblocks (`/** */`) for description and `@param`. Somewhat language independent.
- Php: Very Good (php 7.4 - 8.2)
- Bash: Broken. There was an old grammar which would parse functions and doclbocks (using `##\n#`), but it has not been returned to functionality with the current lexer.

## Install
@template(php/composer_install)


## Parse with CLI
This prints an Asymmetrical Syntax Tree (AST) as JSON.
```bash
# only file path is required
bin/lex file rel/path/to/file.php -nocache -debug -stop_at -1
```

## Basic Usage

For built-in grammars, it is easiest to use the helper class. 

```php
<?php
$file = '/path/to/file/';
$helper = new \Tlf\Lexer\Helper();
$lexer = $helper->get_lexer_for_file($full_path); // \Tlf\Lexer

# These are the default settings
$lexer->useCache = true; // set false to disable caching
$lexer->debug = false; // set true to show debug messages
$lexer->stop_loop = -1; // set to a positive int to stop processing & print current lexer status (for debugging)

$ast = $lexer->lexFile($full_path); // \Tlf\Lexer\Ast

print_r($ast->getTree()); // array
```

## Example Tree
Grammars determine tree structure. This is a php file in this repo. See @see_file(code/Ast/StringAst.php). This example only has one method and no properties. From the root of this repo, run `bin/lex file code/Lexer.php` for an example of a larger class.
```json
{
    "type": "file",
    "ext": "php",
    "name": "StringAst",
    "path": "\/path-to-downloads-dir\/Lexer\/code\/Ast\/StringAst.php",
    "namespace": {
        "type": "namespace",
        "name": "Tlf\\Lexer",
        "declaration": "namespace Tlf\\Lexer;",
        "class": [
            {
                "type": "class",
                "namespace": "Tlf\\Lexer",
                "fqn": "Tlf\\Lexer\\StringAst",
                "name": "StringAst",
                "extends": "Ast",
                "declaration": "class StringAst extends Ast",
                "methods": [
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "sourceTree",
                                "value": "null",
                                "declaration": "$sourceTree = null"
                            }
                        ],
                        "modifiers": [
                            "public"
                        ],
                        "name": "getTree",
                        "body": "return $this->get('value');",
                        "declaration": "public function getTree($sourceTree = null)"
                    }
                ]
            }
        ]
    }
}
```

A php class property looks like:
```json
{
    "type": "property",
    "modifiers": [
        "public",
        "int"
    ],
    "docblock": {
        "type": "docblock",
        "description": "The loop we're on. 0 means not started. 1 means we're executing the first loop. 2 means 2nd loop, etc."
    },
    "name": "loop_count",
    "value": "0",
    "declaration": "public int $loop_count = 0;"
}
```



# Grammar Testing
Unit testing is the best way I've found to really develop a grammar. It allows you to focus on very specific pieces of the grammar at a time, then later put it all together by parsing an entire document.

This library depends upon @easy_link(tlf, php-tests) for testing.

Links:
- Writing a Grammar: @see_file(docs/GrammarWriting.md)
- Grammar Example: @see_file(docs/GrammarExample.md)
- Grammar Commands: @see_file(docs/GrammarCommands.md)

## Howto
1. Extend `\Tlf\Lexer\Test\Tester` which extends from `\Tlf\Tester` or copy the methods from it & modify as needed for a different testing library.
2. Implement a `testGrammarName()` method that uses the test runner
3. Implement the data structure for defining the unit tests.

Example of `2.`:
```php
@ast(Tlf\Lexer\Test\PhpGrammar, methods.testPhpDirectives.definition) {
@ast(Tlf\Lexer\Test\PhpGrammar, methods.testPhpDirectives.body)
}
```

Example of  `3.`:
-- whatever goes here

# Write a Grammar
A Grammar is an array declaration of `directives` that define `instructions`. Those `instructions` may call built-in commands or may explicitly call methods on the grammar, the lexer, the token, or the head ast.

**First:** Look at the example in @see_file(docs/GrammarExample.md)
**Then:**
- Read through this document
- Look at the commands available in @see_file(docs/GrammarCommands.md)
- Learn how to test a grammar. See @see_file(docs/GrammarTesting.md)
- Review the Architecture, if you like. See @see_file(docs/Architecture.md)


## Tips
- `$grammar->getDirectives(':directive_name')` returns an associative array of directives.
- `then` directive:
    - You can pass a directive declaration to `then`, like `then :name=>['start'=>[/*instructions*/]]` to override the target directive
    - You can pass `:directive_name.stop` to use the `stop` as `start`.
        - idk if you can override in this case, but I think you can
- `then.pop :directive_name X` lets you pop X layers when `:directive_name` is matched. 
- `inherit :directive.stop` or `inherit :directive.start` lets you auto-execute all commands from the named directive & instruction set.
- Pass `:+name` to `then` to create a new directive, rather than loading from/merging with an existing directive.
    - `:_blank` and `:_blank-name` are deprecated alternatives

## Troubleshooting Tips
- Always `rewind` BEFORE `buffer.clear`, or no rewind is performed.
- `match` has special handling & the recommended style is `'match'=>'string'` or `'match'=>'/regex/'`. The alternate styles like `match string` or `match /regex/` *should* work, but might make problems.
- set `$lexer->useCache` to false to disable cache. 
- `$lexer->debug = true` to print debug information
- `$lexer->stop_loop = 30` to stop processsing on loop 30 & print debug info.
- `rewind` can cause an infinite loop. Ex: The instructions `match == :` & `rewind == 1` on the same directive. The `:` is matched, then we rewind 1, then the `:` is matched & we rewind 1 & so on. 
- `stop` instruction ALWAYS acts upon the top directive list at the time it is executed. If the current directive is not in the directive list's `started`, then nothing happens. Meaning it is NOT added to the `unstarted` list.
- `directive.inherit` instruction ALWAYS ignores the `match` instruction of the inherited directive. 

## Recommended structure
To keep files smaller & more organized, I keep my directives inside traits that my grammar `use`s.
- `MyGrammarClass extends \Tlf\Lexer\Grammar`
    - `use MyGrammar\Main_Directives`
    - `use MyGrammar\Comments_Directives`,
    - `function buildDirectives()`: `$this->directives = array_merge( comments_directives, main_directives)`
        - override `onGrammarAdded()` to implement this
    - `onLexerStart()`/`onLexerEnd()` if needed
    - methods your directives will call

## Structure of directives
The form is `$directives -> directive_name -> instruction set -> array of instructions`. There are two instruction sets `start`, `stop`. There is a third instruction set, but I plan to remove or change it.
```php
<?php
protected $directives = [
    'php_open'=>[
        'start'=>[
            'match'=>'<?php', 
            //instructions go here
        ],
        'stop'=>[
            'match'=>'?>',
            //instructions go here
        ],
    ],
]
```
1. When `<?php` matches, `php_open` becomes `started`. 
2. On subsequent loops `stop` will be checked. 
3. When `?>` matches, `php_open` becomes stopped.

### Notes
- The subsequent instructions only execute if `match` passes.
- `match` is NOT a required instruction 
- `match` does NOT have to be the first instruction
- `match` has a lot of special handling to handle merging of overridden directives.

## Declaring instructions
Many commands have a shorthand and a longhand like `stop` and `directive.stop`
Examples:
- `'command arg1 arg2' => 'arg3'`
- `'command arg1 arg2 //comment' => 'arg3'`
- `'command arg1 ...' => ['arg2', 'arg3', 'arg4'] `

Instead of a `command`, you can use a `namespace:method` to directly call a method on an object from internally defined namespace targets or from one of the available grammars.
The available namespace targets are defined here:
```php
@import(Commands.NamespaceTargets)
```

## Special object-calling
Some commands, like `ast.new` allow you give values that call objects+methods in much the same way as instructions. This is on a command-by-command basis

The format is `_namespace:method arg1 arg2 arg3`
Example:
```php
['ast.new'=>[
    '_type'=>'class',
    'name'=> '_token:buffer',
    'docblock'=> '_lexer:unsetPrevious docblock'
    ]
]
```
# Use an AST 
Documentation to be written
# Docblock + Comments Grammar

## July 13, 2021
I decided to just do a custom php implementation of the whole thing. The grammar handles catching the start & end of the docblock & calling the appropriate php function. This seemed easier, because I couldn't really store anything to the ast until I had already gone through the entire thing & I need to know about lines & it just seemed really complex, so writing pure php seemed easier.

I still think it should be re-written as a proper grammar, but there's no explicit reason to do this.

I may want a grammar that processes strings containing attributes, though, like so I can capture `@attr(arg, arg2, etc) and description`

But I don't need that right now, so I'm not doing it right now

The "OLD" notes below are likely a good starting point for writing a proper docblock grammar. 

## OLD (before July 13, 2021)

I wrote most of a Docblock Grammar. Then started trying to handle the padding issue & it was non-starter. So that has to basically be scratched so I can implement this new version.

I think I'll just go through the breakdown WITH attributes & set that one up, instead of trying to work attributes in after setting up the simpler attribute-free one.

I would mayybe like to setup some smaller tests. But Idunno. I'm probably okay with just parsing one big docblock & making sure its how I expect it. Especially since docblocks aren't complex & don't have a lot of components.


## Some rules
- leading whitespace is always removed from the first line. Like `/**  something` becomes `something`
- left-pad consists of `whitespace * whitespace` & is converted to full whitespace
    - the `*` is always replaced with a ` ` (space) before further processing
- `leftPadToRemove = ` the length of whichever line has the shortest left-pad. 
    - Does NOT count any lines after a start-of-line `@attribute`
    - Does NOT count the first line
    - Does NOT count empty lines (though they will be trimmed)
    - Then each non-empty line has that much left-pad removed from them.
- Attributes MUST be `[a-zA-Z_]+`
- Attributes MAY have parenthetical arguments like `@attr(arg1, arg2)`
    - Can occur anywhere
    - Can only have a description if it's the first thing on a line
        - `\n  * something @see(this) thing yes please`. There is no description for `@see(this)` 
        - `\n  * @see(this) thing yes please`. `thing yes please` is the description
- Attributes without parenthetical arguments
    - MUST be the first non-whitespace non-star character. Like `\n  * @attr whatever`
    - Captures a description until the next `@attribute`

## The Lexer breakdown
```
  /* abc
   * def
   *    ghi
       *   jkl
      mno
   */
```
1. match `/*` & discard all before. 
2. match `\n` & store `abc` as `docblock.line1`
3. match `*` & replace it with ` `
4. match `\n` & push the line `     def` onto `doblock.lines`
5. match `*` & replace it with ` `
6. match `\n` & push the line `        ghi` onto `docblock.lines`
7. match `\n` & push the line `      mno` onto `docblock.lines`
8. match `*/` & set the line `   ` to `docblock.last_line`
9. call php method to clean up the docblock, which will do:
    - trim the first line
    - iterate over all lines & find the shortest left-pad
    - remove left-padding from all lines per the rules
    - trim the last line
    - combine all the lines for the description & the attributes.

### Breakdown with attributes
```
  /* abc
   * def
     @param this is a sentence about @param
         line 2 param
   * @param(two,three) has a description. @see(something)
   */
```
1. match `/*` & discard all before. 
2. match `\n` & store `abc` as `docblock.line1`
3. match `*` & replace it with ` `
4. match `\n` & push the line `     def` onto `doblock.lines`
5. match `@param `, create new attribute `ast` & set its name
6. match `\n`. Store the line on the attribute ast as `attr.line1`
7. match `\n`. Store the line `        line 2 param` on `attr.lines`
    - it will be trimmed via the same left-pad trimming as docblock lines
8. match `*` & replace it with ` `
9. match `@param(`, terminate processing of any prior `@attribute`. Create new attribute ast & set its name & create an empty argslist
10. match `,`. push `two` onto `attribute.args`
11. match `)`. push `three` onto `attribute.args`. 
12. match `@see(`. new attribute `ast`, set name. create `attribute.args` list. 
    - Append it to `@param(two,three)`s `attributes` 
    - OR add the attribute to the docblock? (probably not)
13. match `)`. push `something` to `attribute.args`. immediately stop this directive.
14. match `\n`. Store `has a description. @see(something)` as `attribute.line1` on `@param(two,three)`
15. match `*/`. set the line `    ` to `attribute.last_line`
16. call php method to clean up the docblock, which will do:
    - trim the first line
    - iterate over all lines & find the shortest left-pad
    - remove left-padding from all lines per the rules
    - trim the last line
    - combine all the lines for the description & the attributes.




## Older notes

### The indentation problem
```
    /* abc
     * def
     *    ghi
         *   jkl
        mno
    */
```
Should become:
```
abc
def
   ghi
      jkl
 mno
```

So the indent to remove is the shortest indent, other than the first line.

The shortest indent is:
`    * `, before `def`

For the rest the lines, it doesn't matter if they have a star or not.
It just matters the distance from the 0 column to the first non-star char

So we find the SMALLEST distance from the 0 column to the first non-star char

The first line is always free from indentation considerations, due to how the grammar processes






## The old notes
- Write DocBlock + Comments Grammar
    - `src`, `description`, and `attributes`
    - Can come from multiple different styles (`##\n#\n#\n#` or `/**\n*\n*` or `// comment` or `! comment` or whatever)
        - Maybe there is a docblock cleanup step that is non lexerryy?? Or I have to add something to make it flexible ...
        - I suppose I could have a method that modifies one of my directives, so basically you just set the docblock type to `/*`, then the relevant directives are modified accordingly. This is a fairly convoluted approach, but it would also work. It could even be "aware" of what other language grammar is present, maybe. (maybe not though).
    - catches `@name and the description about it`, `@name(arg1,arg2) description about it`, ... what about `@arg prop_name description about it` & catch `prop_name`??? I think this is a case-by-case kind of thing. Maybe depending upon the particular attribute? maybe the language grammar can define it


/**
*
*/

or /** */

or 
##
#
#


or 
#
#
#
#

or
//
//
//

So, first I have to make a decision about "what is a docblock?", well the common answer is:
```
/**
*
*
*/
```

But if I want docblock functionality in different languages (bash), how tf do I do that?
Well I've proposed:
```
##
#
#
#
```
Which doesn't supply a clear terminator, but it makes sense. 


I could also do just a series of single-line comments. But I think that breaks a common expectation. So no. I won't do that.


So right now, I'm counting `##\n#\n#` and `/**\n*\n*/` as well as their single-line counterparts `## stuff` and `/** */`

But the `## stuff` breaks the docblock contract


But how do I count `## whatever` as a docblock but NOT catch it as a comment?

by simply defining things separately.... basically. The `#` would start a comment, but listen for docblock. Then if the next char is `#`, then that means we have a docblock & the comment listening can stop & we go into docblock mode.


But how does docblock processing actually work? Lets start with a single line example.
```docblock
/** I am a simple docblock */
```

`/*` starts a docblock
`*/` ends a docblock
` I am a simple docblock ` is the description / body

Then
```
/**
* Simple multi-line docblock
*/
```

So ...
previously, I was just parsing all of the stars out after getting the end of the docblock. I could do that still, I suppose, but its kind of a jank solution, especially considering I have a lexer!

So the things I want to remove are:
`^\s+\*`
If there is no `*` on a line,

1. Get a `/*` to start a docblock
2. Get a `\n` to end a line
    - rewind 1
    - append to body. Append to description?
    - forward 1
3. Get a `\n` or a `*` and discard what's before `*`


Attributes:
- Start-of-line attributes like `@param $argName description of arg`
- in-line attributes like `I want you to @see TheThing`
- start-of-line like `@param($argName, string) description of the arg`
- in-line like: `Lets @see(TheThing)`

I don't really care about the `This is @abad Inline Type`. Because its just ... not really clear how that should be interpreted & I don't think I want to make decisions about it & Code Scrawl doesn't use this style. Or it hasn't, anyway.






# Info I wanna keep around just because
Some of this is actual like ... historical information for the project. A lot of it is just ... stuff I wrote down & might want to use later.


## v0.6 changes
A complete redesign to how directives are declared. The codebase is significantly cleaned up, and the project should be far more maintainable going forward, as well as much more useful as a lexer. I think `v0.5` was never fully functional. I believe I abandoned that in favor of a new design for v0.6

## Some questions 
These are probably not accurate. But I wanted to keep them around & maybe answer them again.

when is 'start' checked?
    When the top 'started' list is empty and 'unstarted' is non-empty
when are 'match' and 'stop' checked?
    A directive's 'match' and 'stop' are checked if it begins the loop on the top started stack
    'stop' is checked after 'match'
    neither 'match' nor 'stop' are checked on the same loop that 'start' is checked.
    'stop' is checked whether 'match' passes or not
    'stop' is propagated upward at the end of lexing (before or after onLexerEnd()? )
How do I customize tree output?
    Possibly a custom Ast class. Should be specifiable in `ast.new`


## Changes Prior to v0.5 
- set_previous feature
- ast_set feature
- rewind() feature to move the pointer back 
- Wrote Sample code & a draft document regarding a new design for lexer. One that moves away from state-based into expectations-based
- Some changes and improvements to lexer & grammar
    - Grammar's flow for building regexes is improved
    - Lexer has minor changes to its implementation, especially in regard to automatically popping state & clearing buffers. 
- PhpGramamr2 handles properties, constants, methods, functions, strings, and some other things. 
- Implemented AST caching for files. File to parse checks `sha1_file`. `filemtime` is checked for each grammar. Does not check `lexer`, `ast`, `token`, or the base `Grammar` class files.
- Write some docs. Clean up status notes
- Updated existing grammars to work with refactored
- Refactored lexer & Grammar & added new features.
- Wrote most of an introduction
- Small DocBlockGrammar fix
- Some bug fixes with lexing & state
- (php grammar)Catch namespace, class, method, docblock, and property
- Create Docblock grammar
- Write bash grammar to capture docblocks & function names
- docblock parsing (to get attributes, basically)
- PhpGrammar successfully prototyped & catching docblocks, properties, and methods for PHP
- Ast getTree() 
- Generalized Ast
- Refactored tests
- Make its own repo
- Convert current run script to a tlftest


## v0.3 architecture
This is out of date. We no longer use a `state` approach. Instead, each directive uses `then`s to point to the next directives to watch for

### The lexer manages
- `state`: The name of what's being processed at the moment. State is kept on a stack.
    - `state` may be an asterisk (`'*'`) or asterisk in array (`['*']`) to be valid for all states
    - Ex: After `/**` is found, we enter `state=='docblock'`.
        - When `*/` is reached, we `pop` the state & return the parent state. Something like `class_body`, if the docblock was found inside a `class Something { /** docblock here */ }`
    - When the `state` changes from one loop to the next, the list of valid regexes is updated
- `token`: The text we're processing with convenience methods to get the current buffer, add a char to the buffer, etc
- `head`: The `ast` at the top of the stack.
    - The initial ast is always on the bottom of the stack & is the first `head` that is used
    - Grammars append new `ast`s to the stack & can pop them off.
        - Currently, this must be done programmatically in php. There is not a declarative solution.
- `valid_regex_list`: The list of directives to check for the current state
- `success_regex`: The directive who's pattern matched the current buffer
- `grammar`: Directives & methods that allow you to do ast building & parsing with the lexer 
- `directive`: A regex to match & instructions about what to do when the regex is matched
    - Formerly, directives were simply called regexes

### Setting up the lexer environment
1. Lexer is initialized
2. Grammars are added to the lexer. Additional work is done during their `__construct`ors
    - Grammar must do additional processing for regex declarations. See Grammar.php for up-to-date implementation info
        - Convert all non-array values to arrays (except `set_state`)
        - check for `onRegexName()` method on the grammar and set it to `onMatch`
            - also checks `on_regexName`
        - Set `state=>['*']` if it wasn't set
        - Set `name=> `, the key that identified this regex entry in the grammar.
    - Grammar supports a `regex_end` feature which is not supported by the Lexer. Each `regex_end` entry is converted into a standalone `regex` with flags:
        - `name=>'endofreg:the_original_regexes_name'`
        - `regex=> ` the regex array found at `regex_end`
        - `state=> ` Whatever `set_state` is on the original regex
        - `pop_state => true`
        - `onMatch => ` For a regex with name `"string_open"`, Method `onendString_open()` if the method exists on the current grammar
    - the `regex_end` feature is now better used as `'end'=>[/*normal regex declaration*/]` where everything in `end` is copied into its own regex entry
3. An `Ast` is created to be the root
    - `lex($filePath)` creates an ast & sets attributes to that ast
    - For `lex($filePath)`, the cache is checked & a new lex is only done if the file or any of the grammars are different from last time it was run (or if `$lexer->useCache` is `false`).
4. The ast is set as the `head` 
5. A `Token` is created from the passed in `string` (file contents in the case of `lex($filePath)`)
6. For each grammar `onLexerStart($lexer, $ast, $token)` is called


### lexing begins
1. using a while loop, set `$token = $token->next()`, which returns itself with an updated buffer, or `false`, if there are no more characters to process
    - `next()` adds one character to the buffer at a time.
2. Each `valid_regex` for the current state is now checked. 
    - Warning: No more `valid_regex`es are checked after the first one matches
3. The first regex that matches is stored as a `success_regex`
    - The `success_regex` contains some or all of:
        - `cur_match`, the current results of `preg_match`ing.  where `[0]` is the full match, `[1]` is the first set of parentheses & so on

        - `regex=>[/regex1/, /regex2/]`. Only one regex has to match & and processing stops after the first regex is matched
        - `state=>[state1, state_2]`. The state `$lexer` must be in for this regex to be checked
        - `state_not=>[state3, state_4]`. If `$lexer->getState()` is one of these, do not check this regex. For every other state, check this regex (unless `state=>` is also given.)
        - `onMatch =>` the function to call when this regex is matched 
        - `set_state` => `new_state`. to call `$lexer->setState('new_state')` when this regex is matched
        - `buffer.clear => true` to call `$token->clearBuffer()` when regex is matched
        - `pop_state => true` to call `$lexer->popState()` and `$token->clearBuffer()`
4. Every `success_regex` now begins processing
5. if `$debug` is on (hardcoded rn), then print state information.
6. set `cur_match` to `$token->setMatch($cur_match)`
8. Call `onMatch` function, if it was set
7. Process every other directive
7. Set `$lexer->state` to `set_state` if key present on the directive
8. Print additional state information if `$debug==true`
9. Call `onLexerEnd()` on each grammar
# PhpGrammar Architecture
The Php Grammar uses the Lexer's declarative features to capture a small set of basic information, then routes to appropriate PHP functions for additional handling. There are `words` and `operators`. `words` are basically any string of alphanumeric characters, including underscore and backslash. `operators` are basically any symbol (or series of symbols) that have a particular meaning in the language.

There is a `Handlers` trait which takes the basic information & routes it to an appropriate method. Operations are mapped from symbol to a string (like `=` is `assign`). Then operations are routed like `$this->op_assign()`. Words like `$this->op_function` (when the word `function` hits). 

There is an `$xpn` (expression) ast used as a simple object to hold meta data / state information. 
- `$xpn->declaration` is automatically appended to by whitespace, words, operators (maybe docblocks??? maybe comments ??). 
- `$xpn->words` is automatically appended to each time a word is encountered.
- `$xpn->last_op` is the last operation recorded & is set automatically after an operation is done being handled.
- `$xpn->waiting_for` is set by specific handlers for specific words/operators & checked by subsequent handlers to see if the state is correct.
- `$xpn->head` ... is sometimes set as an ast for something to be acted upon, but is not added to the regular ast stack. Idr the use case.

Both declaration & words are reset to an empty array frequently by specific handlers.


## Old notes from developing the idea of the current arcitechture
I'm thinking of a new paradigm where I catch EVERYTHING & at 'stoppers' I will process what has been captured. Essentially I will capture "words" which are .... and encapsulated sequence of characters. `" i am a string"` is one `word` because that's a single unit for parsing.

in `public int $abc = "I am a thing";`, the words are:
- public
- int
- $abc
- =
- "I am a thing"

Then `;` is a `stopper`. Maybe `=` is a stopper, too.

The idea is that ... everything works out to be an expression made up of words and operators. 

```php
<?php
protected $whatever = 'cat';
/** abc */
static public function abc(bool $b): string {
    $abc = "cat";
    $def = "dog";
    return "zeep";
}
```
It's gonna build the same kind of AST, but now I get to think about it differently.
so, `protected $whatever =`.
When I hit `=`, I know I have an `assignment` operation
the left-hand words of that operation are `['protected', '$whatever']`;
The last word is the property name. All words before it are modifiers (which may include type).
# Php Language Features
This likely is not an exhaustive list & not necessarily everything here is handled by the PhpGrammar. Also, Docblocks are handled by their own grammar.


- `use NS\ClassName as ShortName` statements (maybe)
- `use TraitName` statements
    - done
- interfaces
- traits
- docblocks
    - description
    - attributes in style `@tag some_tag`
        - name
        - value (some_tag)
    - attribute in style `@tag(some_tag) a description`
        - name
        - value (some_tag)
        - description
    - The next expression/ast/thing. 
        - Currently, I'm using the `previous` mechanic to attach docblock to stuff. I don't really think there's a better way about this.
- comments
    - content
    - attributes in both styles (see docblocks)
    - The next expression/ast/thing, maybe???
- class (including anonymous classes)
    - properties
        - private/public/protected
        - static/not-static
        - name
        - docblock
        - default value
    - constants
        - private/public/protected
        - static/not-static
        - name
        - docblock
        - default value
    - methods
        - private/public/protected
        - static/not-static
        - name
        - docblock
        - arg list 
            - paramater names
            - default values
        - method body code
- functions
    - name
    - docblock
    - arg list
    - function body code
- HEREDOC - & discard it
- NOWDOC - & discard it
- string & discard it
- php8 attributes? Meh
## Cli command parsing
Options:
- call `$this->execCommand()`
    - If there is no namespace
- call `$grammars[namespace]->$command()`
    - if there is a namespace
- call `$targets[$namespace]->$command()`
    - if there is a namespace

Args options:
- `command` is an argument (only for `execCommand` / no namespace)
- `$phpArg` is `false` (do not run the command)
- `$phpArg` is `true` (run the command)
- `$phpArg` is a single argument appended to cli arguments (anything but `false`)
- `$phpArg` is an array of arguments. Give `...` as the last cli argument
- TODO `$phpArg` is an array of commands to run. Give `[]` as the last cli argument. `command` is prepended to each entry in the `$phpArg` array
- TODO `$phpArg` is an executable object+method+args. Pass `!` as the last cli argument, then use `_object:method arg1 arg2` like `_lexer:previous docblock`


So basically, we parse the `namespace:command` which gets us an object + method & MAY start an arg list. Then we parse the cli command args & add them to the list.
1: Create an args list from the cli args + php args
2: Get the object + method & modify args list as needed
3: Call object + method with the final args list


## Command Expansion
Add `command ...`, `command []`, and `command // abc dogs and cats` features
- default: `command abc=>[1,2,3]` is same as `command abc [1,2,3]`. (though arrays aren't allowed in the command shorthands. The array is a single argument)
- `...`: `command abc ...=>['d','e','f']` is same as `command abc d e f` 
- `[]`: `command abc []=>['a'=>true, 'b'=>'dog']` is same as `command abc a true` and `command abc b dog`
    - `command abc []=>['a','b']` is same as `command abc a` and `command abc b`
- `//`: `command abc // cats` is same as `command abc`. The `//` lets you write multiple matches, for example.
- `!`: `command def ! => '_lexer:previous docblock'` will call `command def $lexer->previous('docblock')`, essentially


## Directive Overrides 
I don't know if this is accurate, but I think it is & once verified, these notes can be used for documentation.

- Inheritance rules:
    - if raw `match` directive is first in src directive, then add it first
    - then add instructions from the child directive, in declared order
    - then add all other instructions from the source directive, in their declared order.
        - If child directive contains any keys found in source directive, then do not copy the value from the source directive. The child simply overwrites (but in the child's declared order)
<?php

namespace Tlf\Lexer\Test;


class PhpGrammarOld extends Tester {

    protected $thingies = [


        'Property.IntType'=>[
            'expect_failure'=>true,
            'start'=>['class_modifier', 'whitespace'],
            'input'=>' public int $blm = "an important movement.";',
            'expect'=>[
                'properties'=>[
                    0=>[
                        'type'=>'property',
                        'modifiers'=>'public ',
                        'docblock'=> '',
                        'name'=>'blm',
                        'declaration'=>'public int $blm = "an important movement.";',
                    ],
                ],
            ],
        ],

        'Property.NoType'=>[
            'start'=>['class_modifier', 'whitespace'],
            'input'=>' public $blm = "an important movement.";',
            'expect'=>[
                'properties'=>[
                    0=>[
                        'type'=>'property',
                        'modifiers'=>'public ',
                        'docblock'=> '',
                        'name'=>'blm',
                        'declaration'=>'public $blm = "an important movement.";',
                    ],
                ],
            ],
        ],

        'String.Nowdoc'=>[
            'start'=>'strings',
            'input'=>"<<<'PHP'\nyep yep\nPHP;",
            'expect.previous'=>[
                'string'=>"<<<'PHP'\nyep yep\nPHP",
            ]
        ],
        'String.Heredoc'=>[
            'start'=>'strings',
            'input'=>"<<<PHP\nyep yep\nPHP;",
            'expect.previous'=>[
                'string'=>"<<<PHP\nyep yep\nPHP",
            ]
        ],

        'String.EndsWithBackslash'=>[
            'start'=>'strings',
            'input'=>"'a\\\\'",
            'expect.previous'=>[
                'string'=>"'a\\\\'",
            ],
        ],
        'String.HasABackslash'=>[
            'start'=>'strings',
            'input'=>"'\\a'",
            'expect.previous'=>[
                'string'=>"'\\a'",
            ],
        ],
        'String.EscapedSingleQuote'=>[
            'start'=>'strings',
            'input'=>"'abc \\'quote start '",
            'expect.previous'=>[
                'string'=>"'abc \\'quote start '",
            ],
        ],
        'String.SingleQuotesInside'=>[
            'start'=>'strings',
            'input'=>'"abc \'quoted\' 123"',
            'expect.previous'=>[
                'string'=>'"abc \'quoted\' 123"',
            ],
        ],
        'String.DoubleQuotesInside'=>[
            'start'=>'strings',
            'input'=>"'abc \"quoted\" 123'",
            'expect.previous'=>[
                'string'=>"'abc \"quoted\" 123'",
            ],
        ],
        'String.Simple'=>[
            'start'=>'strings',
            'input'=>"'abc def 123'",
            'expect.previous'=>[
                'string'=>"'abc def 123'",
            ],
        ],

        'Method.ContainsNestedBlock'=>[
            'start'=>'class_modifier',
            'input'=>
                <<<PHP
                public function nest(){
                    if (true){
                        while(false){
                            echo "okay";
                        }
                    }
                }
                PHP,
            'expect'=>[
                'methods'=>[
                    0=>[
                        'type'=>'method',
                        'modifiers'=>'public function ',
                        'docblock'=>'',
                        'name'=>'nest',
                        'definition'=>'public function nest()',
                        'arglist'=>'',
                    ]
                ],
            ],
        ],

        'Php.Open.Docblock.Namespace'=>[
            'start'=>'php_open',
            'input'=>"<?php \n /** This is a namespace */ namespace abc;",
            'expect'=>[
                'namespace.docblock'=>[
                    'type'=>'docblock',
                    'description'=>'This is a namespace',
                ],
                'namespace'=>'abc',
            ],
        ],
        'Php.Open.Convoluted'=>[
            'start'=>'php_open',
            'input'=>"/*asdflku<\\?php<?php namespace abc;",
            'expect'=>[
                'namespace'=>'abc',
                'namespace.docblock'=>'',
            ],
        ],
        'Php.Open.Simple'=>[
            'start'=>'php_open',
            'input'=>"<?php namespace abc;",
            'expect'=>[
                'namespace'=>'abc',
                'namespace.docblock'=>'',
            ],
        ],

        'Class.Extends.IntoAst'=>[
            'expect_failure'=>true,
            'start'=>['class'],
            'input'=>'class Abc extends Def {',
            'expect'=>[
                'class'=>[[
                    'type'=>'class', 'docblock'=>null, 'namespace'=>'', 'name'=>'Abc', 'extends'=>'Def', 'declaration'=>'class Abc extends Def '
                ]],
            ]
        ],
        'Class.Extends.IntoDeclaration'=>[
            // 'expect_failure'=>true,
            'start'=>['class'],
            'input'=>'class Abc extends Def {',
            'expect'=>[
                'class'=>[[
                    'type'=>'class', 'docblock'=>null, 'namespace'=>'', 'name'=>'Abc', 'declaration'=>'class Abc extends Def '
                ]],
            ]
        ],
        
        'Class.Abstract'=>[
            'expect_failure'=>true,
            'start'=>['class'],
            'input'=>'abstract class Def {',
            'expect'=>[
                'class'=>[[
                    'type'=>'class', 'docblock'=>null, 'namespace'=>'', 'name'=>'Abc', 'declaration'=>'class Abc '
                ]],
            ],
        ],
        'Class.ExtendsWithNoSpaceAfterExtendedClass'=>[
            'start'=>['php_open'],
            'input'=>'<?php class Abc extends Alphabet{}',
            'expect'=>[
                'class'=>[[
                    'type'=>'class', 'docblock'=>null, 'namespace'=>'', 'name'=>'Abc', 'declaration'=>'class Abc extends Alphabet'
                ]],
            ],
        ],

        'Class.MinimalMinusASpace'=>[
            'start'=>['class'],
            'input'=>'class Abc{}',
            'expect'=>[
                'class'=>[[
                    'type'=>'class', 'docblock'=>null, 'namespace'=>'', 'name'=>'Abc', 'declaration'=>'class Abc'
                ]],
            ],
        ],
        'Class.Minimal'=>[
            'start'=>['class'],
            'input'=>'class Abc {',
            'expect'=>[
                'class'=>[[
                    'type'=>'class', 'docblock'=>null, 'namespace'=>'', 'name'=>'Abc', 'declaration'=>'class Abc '
                ]],
            ],
        ],
        'Namespace.WithDocblockAfterNs'=>[
            'expect_failure'=>true,
            'start'=>['namespace'],
            'input'=>"namespace/**docblock*/Abc\Def;",
            'expect'=>[
                "namespace"=> 'Abc\\Def',        
                'namespace.docblock'=>'docblock',
            ],
        ],
        'Namespace.WithNewLines'=>[
            'start'=>['namespace'],
            'input'=>"namespace \nAbc\n\\\\\nDef_09;",
            'expect'=>[
                "namespace"=> 'Abc\\Def_09',           
                'namespace.docblock'=>'',
            ],
        ],
        'Namespace.WithDocblocksAtTheEnd'=>[
            'start'=>['namespace'],
            'input'=>"namespace Abc\\/**docblock**/Def_09/**more docblock*/;",
            'expect'=>[
                'namespace.docblock'=>[
                    'type'=>'docblock',
                    'description'=>'more docblock',
                ],
                "namespace"=> 'Abc\\Def_09',          
            ],
        ],
        'Namespace.WithDocblocksInTheMiddle'=>[
            'start'=>['namespace'],
            'input'=>"namespace Abc\\/**docblock**/Def_09;",
            'expect'=>[
                'namespace.docblock'=>[
                    'type'=>'docblock',
                    'description'=>'docblock*',
                ],
                "namespace"=> 'Abc\\Def_09',
            ],
        ],
        'Namespace.SeparatedName'=>[
            'start'=>['namespace'],
            'input'=>"namespace Abc\\Def\_09;",
            'expect'=>[
                "namespace"=> 'Abc\\Def\\_09',
                'namespace.docblock'=>'',
            ],
        ],
        'Namespace.Simple'=>[
            'start'=>['namespace'],
            'input'=>"namespace AbcDef_09;",
            'expect'=>[
                "namespace"=> 'AbcDef_09',
                'namespace.docblock'=>'',
            ],
        ],
    ];

    public function testPhpDirectives(){
        $phpGram = new \Tlf\Lexer\PhpGrammar();
        $grammars = [
            $phpGram,
        ];
        $phpGram->buildDirectives();

        $this->runDirectiveTests($grammars, $this->thingies);
    }



    public function testPhpPhpGrammar16Jul21(){
        $dir = dirname(__DIR__).'/php/';
        $file = $dir.'PhpGrammar.16jul21.php';
        $targetTree = include($dir.'PhpGrammar.16jul21.tree.php');

        $lexer = new \Tlf\Lexer();
        $lexer->debug = true;

        // This is for devving v0.6:
        // $lexer->stop_loop = 2900;
        // $lexer->stop_loop = 4675;
        // $lexer->stop_loop = 4700; //just before 4700, problems start. There is a block closer thats being caught as a comment
//
        // $lexer->stop_loop = 5450; //between 5450 & 5500, we're getting stuck & execution just is not completing
        //5483 is where it gets stuck, due to a bug in docblock which has since been fixed

        if (isset($this->options['stop_loop'])){
            $lexer->stop_loop = (int)$this->options['stop_loop'];
        }

        
        // $lexer->stop_loop = 9999999;
        $lexer->useCache = false; // useCache only matters when lexing a file
        $lexer->addGrammar($phpGrammar = new \Tlf\Lexer\PhpGrammar());

        $ast = $lexer->lexFile($file);

        $tree = $ast->getTree(); // not what we normally want with json

        echo "\n\n\n --- file AST ---\n\n";

        print_r($tree);

        //
        // write the current tree to a file
        //
        file_put_contents($dir.'PhpGrammar.16jul21.tree2.php',var_export($tree,true));
        echo "\n----\n\n\n";
        $this->compare(
            $targetTree, 
            $tree
        );
    }
    public function testPhpStarterGrammar16Jul21(){
        $dir = dirname(__DIR__).'/php/';
        $file = $dir.'StarterGrammar.16jul21.php';
        $targetTree = include($dir.'StarterGrammar.16jul21.tree.php');

        $lexer = new \Tlf\Lexer();
        $lexer->debug = true;

        // This is for devving v0.6:
        // $lexer->stop_loop = 1400;
        // $lexer->stop_loop = 1415; // 1396 introduces a nested block in `onLexerStart()` method. Its an if block.
        // $lexer->stop_loop = 1450; //1446 is the nested block end
        // $lexer->stop_loop = 1466; //during the nested if block?
        // $lexer->stop_loop = 1475; //class declaration is messed up between 1450 & 1475
        // $lexer->stop_loop = 1500; // already has extra whitespace
        // $lexer->stop_loop = 1600; // We're already parsing trimBuffer() method & class declaration is messed up

        
        // $lexer->stop_loop = 9999999;
        $lexer->useCache = false; // useCache only matters when lexing a file
        $lexer->addGrammar($phpGrammar = new \Tlf\Lexer\PhpGrammar());

        $ast = $lexer->lexFile($file);

        $tree = $ast->getTree(); // not what we normally want with json

        echo "\n\n\n --- file AST ---\n\n";

        print_r($tree);

        //
        // write the current tree to a file
        //
        file_put_contents($dir.'StarterGrammar.16jul21.tree2.php',var_export($tree,true));
        echo "\n----\n\n\n";
        $this->compare(
            $targetTree, 
            $tree
        );
    }

    public function testPhpSampleClass(){
        $dir = dirname(__DIR__).'/php/';
        $file = $dir.'SampleClass.php';
        $targetTree = include($dir.'SampleClass.tree.php');

        $lexer = new \Tlf\Lexer();
        $lexer->debug = true;

        //the string rewrite
        // $lexer->stop_loop = 305; // on loop 293, we start listening for strings. string_double STOPS on loop 299
        //on loop 300, 

        // This is for devving v0.6:
        // $lexer->stop_loop = 18;
        // $lexer->stop_loop = 33;
        // $lexer->stop_loop = 21; 
        // $lexer->stop_loop = 31;
        // $lexer->stop_loop = 41;
        // $lexer->stop_loop = 51;
        // $lexer->stop_loop = 111; // catching 'class'
        // $lexer->stop_loop = 120;
        // $lexer->stop_loop = 135; // block starts at 132
        // $lexer->stop_loop = 150; // use trait is about 150
        // $lexer->stop_loop = 185; // 181 is new line for first comment
        // $lexer->stop_loop = 206; // process # second comment at 203
        // $lexer->stop_loop = 261; // Process first property's docblock
        // $lexer->stop_loop = 280; // 277 'modifier' starts
        // $lexer->stop_loop = 300; // first property processed on 299
        // $lexer->stop_loop = 335; // second property is complete
        // $lexer->stop_loop = 395; // static public property is finished by loop 385
        // $lexer->stop_loop = 445; // method docblock finishes on 441
        // $lexer->stop_loop = 460; // `public ` is captured on 454, starting method modifier
        // $lexer->stop_loop = 492; // method block (opening curly brace) starts on 473
        // $lexer->stop_loop = 525; // closing method curly brace is loop 516
        // $lexer->stop_loop = 553; // issues around `=` around 550
        // $lexer->stop_loop = 585; // see 542 for `const `. `=` is loop 551. string closes on 578
        // $lexer->stop_loop = 800;
        // $lexer->stop_loop = 1200;

        
        // $lexer->stop_loop = 9999999;
        $lexer->useCache = false; // useCache only matters when lexing a file
        $lexer->addGrammar($phpGrammar = new \Tlf\Lexer\PhpGrammar());

        $ast = $lexer->lexFile($file);

        $tree = $ast->getTree(); // not what we normally want with json

        echo "\n\n\n --- file AST ---\n\n";

        print_r($tree);

        //
        // write the current tree to a file
        //
        file_put_contents($dir.'SampleClass.tree2.php',var_export($tree,true));
        echo "\n----\n\n\n";
        $this->compare(
            $targetTree, 
            $tree
        );
    }

}
<?php

namespace Tlf\Lexer\Php;

trait BodyDirectives {

    protected $_body_directives = [

        'namespace'=> [
            'start'=>[
                'match'=>'/^namespace\s$/',
                // 'directive.stop_others'=>true,
                'rewind'=>1,
                'buffer.clear'=>true,
                //@todo change :whitespace back to :separator
                'then :whitespace'=>[
                    'stop'=>[
                        'directive.pop 1',
                        'then :separator',
                        'then :varchars' => [
                            'start'=>[
                                'rewind'=>1,
                                'this:holdNamespaceName',
                                'buffer.clear',
                                'stop',
                                // 'then :separator', // this was just for debug
                                'then :separator'=>[
                                    'stop'=>[
                                        'buffer.clear',
                                        // 'directive.pop 1',
                                    ]
                                ],
                                'then :+backslash'=>[
                                    'start'=>[
                                        'match'=> '\\',
                                        'stop',
                                        'directive.pop 1',
                                        'buffer.clear',
                                    ],
                                ],
                                'then :+semicolon'=>[
                                    'start'=>[
                                        'match'=>';',
                                        'rewind'=>1,
                                        'stop'=>true,
                                        'directive.pop'=>2,
                                    ],
                                ],
                                'halt',
                            ],
                            // 'stop'=>[
                                // 'stop',
                                // 'rewind 1',
                            // ],
                        ],
                    ],
                ],
            ],
            'stop' => [
                'match'=> ';',
                'this:saveNamespace',
                'buffer.clear'=>true,
            ],
        ],

        'function'=>[
            'start'=>'/^function$/',
            'onStart'=>[
                'buffer.clear'=>true,
                'ast.new'=>[
                    '_type'=>'function',
                    '_into'=>'functions',
                ]
            ],
        ],
        'interface'=>[
            'start'=>'/^interface$/',
            'onStart'=>[
                'buffer.clear'=>true,
                'ast.new'=>[
                    '_type'=>'interface',
                    '_into'=>'interfaces',
                ]
            ],
        ],
        // 'trait'=>[
            // 'start'=>'/^trait$/',
            // 'onStart'=>[
                // 'buffer.clear'=>true,
                // 'ast.new'=>[
                    // '_type'=>'trait',
                    // '_into'=>'traits',
                // ]
            // ],
        // ],

    //close directives
    ];

}
<?php

namespace Tlf\Lexer\Php;

trait ClassDirectives {

    protected $_class_directives = [

        'php_class_code'=>[
            'is'=>[
                ':separator',
                ':use_trait',
                ':class_modifier',
                // ':php_close',
                // ':php8_attribute',

            ],
        ],

        'use_trait'=>[
            'start'=>[
                'match'=>'use ',
                'buffer.clear'=>true,
            ],
            'stop'=>[
                'match' => ';',
                'rewind'=>1,
                'this:captureUseTrait',
                'forward'=>1,
                'buffer.clear'=>true,
            ],
        ],

        'class'=>[
            'stop'=>[
                'inherit :block.stop match',
                // 'directive.pop 1',
                'stop',
                'buffer.clear',
            ],
            'start'=>[
                'match'=>'/^(class|trait)[^a-zA-Z0-9_]$/',
                'rewind'=>1,
                'ast.new'=>[
                    '_type'=>'_token:buffer',
                    '_addto'=>'_token:buffer',
                    'docblock'=>'_lexer:unsetPrevious docblock',
                    'namespace'=>'_lexer:previous namespace.name',
                    'declaration'=>'_token:buffer',
                ],
                'buffer.clear'=>true,
                'then :separator'=>
                [
                    'start'=>[
                        'rewind 1 //okayokay',
                        'ast.append declaration',
                    ],
                    'stop'=>[
                        // 'inherit :separator.stop match',
                        // 'previous.append class.declaration !'=>'_lexer:unsetPrevious whitespace',
                        'rewind 1',
                        'ast.append declaration',
                        'forward 1',
                        'directive.pop 1',
                        'then :class_name',
                        'then :separator'=>[
                            'stop'=>[
                                'rewind 1',
                                'ast.append declaration',
                                'forward 1',
                            ],
                        ],
                    ]
                ]
            ]
        ],

        'class_name'=>[
            'start'=>[
                'inherit :varchars.start match',
                'start',
                'ast.append declaration !'=>'_lexer:previous php.varchars',
                'ast.set name !'=>'_lexer:unsetPrevious php.varchars',
                'buffer.clear',
                //@todo catch extends & implements
                'then :class_block',
                'then :separator'=>[
                    'start'=>[
                        'rewind 1',
                        'ast.append declaration',
                        'buffer.clear',
                        'forward 1',
                    ],
                    'stop'=>[
                        'rewind 1',
                        'ast.append declaration',
                        'forward 1',
                    ],
                ],
            ],
        ],

        'class_block'=>[
            'start'=>[
                'inherit :block.start match',
                'start',
                'rewind'=>1,
                'ast.append declaration',
                'forward 1',
                'buffer.clear'=>true,
                'then :php_class_code',
                'then.pop :block.stop',
            ],
            'stop'=>[
                'rewind 1',
                'buffer.clear'=>true,
                'directive.pop 2',
            ],
        ],

    // close the directive
    ];

}

<?php

namespace Tlf\Lexer\Php;

trait ClassDirectives {

    protected $_class_directives = [

        'php_class_code'=>[
            'is'=>[
                ':separator',
                ':use_trait',
                ':class_modifier',
                // ':php_close',
                // ':php8_attribute',

            ],
        ],

        'use_trait'=>[
            'start'=>[
                'match'=>'use ',
                'buffer.clear'=>true,
            ],
            'stop'=>[
                'match' => ';',
                'rewind'=>1,
                'this:captureUseTrait',
                'forward'=>1,
                'buffer.clear'=>true,
            ],
        ],

        'class'=>[
            'stop'=>[
                'inherit :block.stop match',
                // 'directive.pop 1',
                'stop',
                'buffer.clear',
            ],
            'start'=>[
                'match'=>'/^class[^a-zA-Z0-9_]$/',
                'rewind'=>1,
                'ast.new'=>[
                    '_type'=>'class',
                    '_addto'=>'class',
                    'docblock'=>'_lexer:unsetPrevious docblock',
                    'namespace'=>'_lexer:previous namespace.name',
                    'declaration'=>'_token:buffer',
                ],
                'buffer.clear'=>true,
                'then :separator'=>
                [
                    'start'=>[
                        'rewind 1 //okayokay',
                        'ast.append declaration',
                    ],
                    'stop'=>[
                        // 'inherit :separator.stop match',
                        // 'previous.append class.declaration !'=>'_lexer:unsetPrevious whitespace',
                        'rewind 1',
                        'ast.append declaration',
                        'forward 1',
                        'directive.pop 1',
                        'then :class_name',
                        'then :separator'=>[
                            'stop'=>[
                                'rewind 1',
                                'ast.append declaration',
                                'forward 1',
                            ],
                        ],
                    ]
                ]
            ]
        ],

        'class_name'=>[
            'start'=>[
                'inherit :varchars.start match',
                'start',
                'ast.append declaration !'=>'_lexer:previous php.varchars',
                'ast.set name !'=>'_lexer:unsetPrevious php.varchars',
                'buffer.clear',
                //@todo catch extends & implements
                'then :class_block',
                'then :separator'=>[
                    'start'=>[
                        'rewind 1',
                        'ast.append declaration',
                        'buffer.clear',
                        'forward 1',
                    ],
                    'stop'=>[
                        'rewind 1',
                        'ast.append declaration',
                        'forward 1',
                    ],
                ],
            ],
        ],

        'class_block'=>[
            'start'=>[
                'inherit :block.start match',
                'start',
                'rewind'=>1,
                'ast.append declaration',
                'forward 1',
                'buffer.clear'=>true,
                'then :php_class_code',
                'then.pop :block.stop',
            ],
            'stop'=>[
                'rewind 1',
                'buffer.clear'=>true,
                'directive.pop 2',
            ],
        ],

    // close the directive
    ];

}

<?php

namespace Tlf\Lexer\Php;

trait ClassDirectives {

    protected $_class_directives = [

        'php_class_code'=>[
            'is'=>[
                ':separator',
                ':use_trait',
                ':modifier',
                // ':php_close',
                // ':php8_attribute',

            ],
        ],

        'use_trait'=>[
            'start'=>[
                'match'=>'use ',
                'buffer.clear'=>true,
            ],
            'stop'=>[
                'match' => ';',
                'rewind'=>1,
                'this:captureUseTrait',
                'forward'=>1,
                'buffer.clear'=>true,
            ],
        ],

        'class'=>[
            'stop'=>[
                'stop',
                'rewind 1',
            ],
            'start'=>[
                'match'=>'/^class[^a-zA-Z0-9_]$/',
                'rewind'=>1,
                'previous.append'=>'class.declaration',
                'ast.new'=>[
                    '_type'=>'class',
                    '_addto'=>'class',
                    'docblock'=>'_lexer:unsetPrevious docblock',
                    'namespace'=>'_lexer:previous namespace.name',
                ],
                'buffer.clear'=>true,
                'then :separator'=>
                [
                    'start'=>[
                        'rewind'=>1,
                        'previous.append'=>'class.declaration',
                        'forward 1',
                    ],
                    'stop'=>[
                        'rewind 1',
                        'previous.append'=>'class.declaration',
                        'directive.pop 1',
                        'then :varchars'=>[
                            'start'=>[
                                'rewind'=>1,
                                'buffer.notin keyword',
                                'ast.set'=>'name',
                                'previous.append'=>'class.declaration',
                                'buffer.clear'=>true,
                                'stop',
                                'directive.pop 1',
                                'then :separator' =>[
                                    'start'=>[
                                        // 'rewind'=>1,
                                        'previous.append'=>'class.declaration',
                                        // 'forward'=>1,
                                    ],
                                ],
                                // 'then :class_implements',
                                // 'then :class_extends',
                                'then :block'=>[
                                    'start'=>[
                                        'rewind'=>1,
                                        'this:handleClassDeclaration',
                                        'forward 1',
                                        'buffer.clear'=>true,
                                        'then :php_class_code',
                                        'then :block.stop'=>[
                                            'start'=>[
                                                'directive.pop 1',
                                                'rewind'=>1,
                                            ],
                                        ],
                                    ],
                                    'stop'=>[
                                        'buffer.clear'=>true,
                                        'directive.pop 1',
                                        'stop',
                                    ]
                                ],
                            ],
                        ],
                        'then :separator'=>[],
                    ],
                ]
            ]
        ],


    // close the directive
    ];

}

<?php

namespace Tlf\Lexer\Php;

trait ClassMemberDirectives {

    protected $_class_member_directives = [

        'class_modifier'=> [
            'start'=>[
                'match'=>'/(static|public|protected|private) /',
                'rewind'=>1,
                'previous.append'=>['modifier'],
                'buffer.clear'=>true,
                'directive.stop_others'=>true,
                'then :class_modifier'=>[
                    'start'=>[
                        'rewind'=>1,
                        'previous.append'=>['modifier'],
                        'buffer.clear'=>true,
                        // 'directive.pop 1',
                        'stop',
                        'halt',
                    ]
                ],
                'then :separator'=>[
                    'stop'=>[
                        'rewind 1',
                        'previous.append'=>['modifier'],
                        'forward 1',
                    ],
                ],
                'then :class_const',
                'then :class_property',
                'then :varchars'=>[
                    'start'=>[
                        'rewind'=>1,
                        'previous.append'=>['modifier'],
                        'buffer.notin keyword',
                        'previous.set'=>'method.name',
                        // 'previous.append'=>['class.name', 'method.definition'],
                        'stop',
                        'directive.pop 1',
                        'then :class_method',
                        'then :separator'=>[
                            'stop'=>[
                                'previous.append'=>['method.definition'],
                            ]
                        ],
                    ]
                ],
                // 'then []'=>[
                    // ':separator',
                    // ':class_const',
                    // ':class_property',
                    // ':class_method',
                // ],
            ],
            'stop'=>[
                'stop',
                'rewind'=>1,
            ],
        ],

        
        'class_method'=>[
            'start'=>[
                'match'=>'(',
                'previous.append'=>'method.definition',
                'rewind'=>1,
                'ast.new'=>[
                    '_addto'=>'methods',
                    '_type'=>'method',
                    'modifiers'=>'_lexer:previous modifier',
                    'docblock'=>'_lexer:unsetPrevious docblock',
                    'name'=>'_lexer:unsetPrevious class.name',
                ],
                'forward'=>1,
                'buffer.clear'=>true,
                'then :argslist_close',
                'then :strings'=>[
                    'start'=>[
                        'previous.append'=>['method.definition','method.arglist'],
                        'buffer.clear'
                    ],
                    'stop'=>[
                        'previous.append'=>['method.definition','method.arglist'],
                        'buffer.clear'=>true,
                    ],
                ],
            ]
        ],

        'argslist_close'=>[
            'start'=>[
                'match' => ')',
                'rewind 1',
                'previous.append method.arglist',
                'forward 1',
                'previous.append method.definition',
                'buffer.clear',
                'stop',
                'directive.pop 1',
                'then :block' => [
                    'start'=>[
                        'rewind 1',
                        'buffer.clear',
                        'this:storeMethodDefinition',
                        'forward'=>1,
                        'buffer.clear true',
                        'then :block'=>[
                            'stop'=>[
                                'buffer.clear',
                            ]
                        ],
                        'then :block.stop'=>[
                            'start'=>[
                                'rewind'=>1,
                                'directive.pop 1',
                            ]
                        ],
                        'then :separator',
                        'then :strings'=>[
                            'stop'=>[
                                'buffer.clear'=>true,
                            ]
                        ],
                    ],
                    'stop'=>[
                        'directive.pop 2',
                        'ast.pop',
                        'buffer.clear'=>true,
                    ],
                ],
            ],
        ],

        'class_property'=>[
            'start'=>[
                'match'=>'$',
                'ast.new'=>[
                    '_addto'=>'properties',
                    '_type'=>'property',
                    'modifiers'=>'_lexer:previous modifier',
                    'docblock'=>'_lexer:unsetPrevious docblock'
                ],
                'rewind'=>1,
                'buffer.clear true'=>true,
                'forward'=>1,
                'previous.append'=>['property.declaration'],
                'buffer.clear'=>true,
                'then :varchars'=>[
                    'start'=>[ // capture property name
                        'rewind'=>1,
                        'previous.append'=>['property.declaration'],
                        'ast.set'=>'name',
                        'directive.pop 1',
                        'buffer.clear'=>true,
                        'then :separator'=>[
                            'start'=>[
                                'previous.append'=>['property.declaration'],
                            ],
                        ],
                        'then :+equals'=>[
                            'start'=>[
                                'match'=>'=',
                                'previous.append'=>['property.declaration'],
                                'buffer.clear'=>true,
                                'then :separator'=>[
                                    'stop'=>[
                                        'rewind 1',
                                        'previous.append'=>['property.declaration'],
                                        'forward 1',
                                    ],
                                ],
                                'then :strings'=>[
                                    'stop'=>[
                                        'previous.append'=>['property.declaration'],
                                        'buffer.clear'=>true,
                                    ],
                                ],
                                'then :+semicolon'=>[
                                    'start'=>[
                                        'match'=>';',
                                        'previous.append'=>['property.declaration'],
                                        'rewind'=>1,
                                        // 'ast.set'=>'declaration',
                                        'this:setPropertyDeclaration',
                                        'forward'=>1,
                                        'buffer.clear'=>true,
                                        'directive.pop'=>3,
                                        'ast.pop'=>true,
                                    ]
                                ]
                            ]
                        ],
                        'then :+semicolon'=>[
                            'start'=>[
                                'match'=>';',
                                'previous.append'=>['property.declaration'],
                                'rewind'=>1,
                                // 'ast.set'=>'declaration',
                                'this:setPropertyDeclaration',
                                'forward'=>1,
                                'buffer.clear'=>true,
                                'directive.pop'=>2,
                                'ast.pop'=>true,
                            ],
                        ],
                    ],
                ],
            ],
        ],

        'class_const'=>[
            'stop'=>[
                'stop',
                'rewind 1',
            ],
            'start'=>[
                'match'=>'const ',
                'ast.new'=>[
                    '_type'=>'const',
                    '_addto'=>'consts',
                    'docblock'=>'_lexer:unsetPrevious docblock',
                    'definition'=>'_token:buffer',
                    'modifiers'=>'_lexer:unsetPrevious modifier',
                ],
                'buffer.clear',
                'then :varchars'=>[ //catch the const's name
                    'start'=>[
                        'rewind 1',
                        'buffer.notin keyword',
                        'ast.append'=>'definition',
                        'ast.set'=>'name',
                        'buffer.clear'=>true,
                        // 'directive.pop 1',
                        'stop',
                        // 'halt',
                        'then :+equals-forconst'=>[
                            'start'=>[
                                'match'=>'=',
                                'ast.append'=>'definition',
                                'buffer.clear',
                                'then :separator'=>[
                                    'stop'=>[
                                        'ast.append'=>'definition',
                                    ],
                                ],
                                'then :strings'=>[
                                    'start'=>[
                                        'buffer.clear',
                                    ],
                                    'stop'=>[
                                        'ast.append'=>'definition',
                                        'buffer.clear',
                                    ],
                                ],
                                'then :+semicolon'=>[
                                    'start'=>[
                                        'match'=>';',
                                        'ast.append'=>'definition',
                                        'directive.pop 4',
                                        'buffer.clear',
                                    ],
                                ]
                            ],
                            'stop'=>[
                                'stop',
                                'rewind 1',
                            ]
                        ],
                    ],
                ]
            ]
        ],

    // close the directive
    ];

}

<?php

namespace Tlf\Lexer\Php;

trait LanguageDirectives {

    protected $_language_directives = [
        'php_code'=>[
            'is'=>[
                ':php_close',
                ':separator',
                ':function',
                ':namespace',
                ':class',
                ':interface',
                // ':trait',
                ':expression',
            ],
        ],

        'strings'=>[
            'is'=>[
                ':string_single',
                ':string_double',
                ':heredoc',
            ],
        ],


        'string_backslash'=>[
            'start'=>[
                'match'=>'/\\\\.$/',
                'stop',
                'halt.all',
            ],
        ],

        'string_instructions'=>[
            'start'=>[
                'rewind 1',
                'buffer.clear',
                'forward 1',
                'then :string_backslash',
            ],
            'stop'=>[
                'previous.set string',
                'rewind 1',
                // 'buffer.clear',
                'directive.pop',
            ]
        ],

        'string_single'=>[
            'start'=>[
                'match'=>"'",
                'inherit :string_instructions.start',
                'then :string_single.stop'=>[
                    'start'=>[
                        'inherit :string_instructions.stop',
                    ]
                ],
            ],
            'stop'=>[
                'match'=>"'",
            ],
        ],

        'string_double'=>[
            'start'=>[
                'match'=>'"',
                'inherit :string_instructions.start',
                'then :string_double.stop'=>[
                    'start'=>[
                        'inherit :string_instructions.stop',
                    ]
                ],
            ],
            'stop'=>[
                'match'=>'"',
            ],
        ],


        'heredoc'=>[
            // also capturing nowdoc
            'start'=>[
                'match'=>'<<<',
                'then :heredoc_key'
            ],
            'stop'=>[
                'rewind 1',
                'stop',
            ],
        ],

        'heredoc_key'=>[
            'start'=>[
                'match'=>'/\'?([a-zA-Z\_0-9]+)\'?[^a-zA-Z0-9_]/',
                'rewind 1',
                'previous.set heredoc_key !'=>'_token:match 1',
            ],
            'stop'=>[
                'match !'=>'_lexer:previous heredoc_key',
                'previous.set string',
                // 'buffer.clear'
                'directive.pop',
                // 'print' => "\n\n\n---\n",
                // 'die !' => '_lexer:previous string',
            ]
        ],

        'php_close'=>[
            'start'=> [
                'match'=>'?>',
                'buffer.clear'=>true,
                // 'then []'=>[
                    'then :php_open',
                    'then :php_echo',
                    'then :html',
                // ],
            ],
        ],


        'php_open'=>[
            'start'=>[
                // 'match <?php',
                'match'=>'<?php',
                'token:clearBuffer',
                'then :php_code',
            ],
            'stop'=>true
        ],

        'php_echo'=>[
            'regex'=>'/\<\?=>)$/',
            'then'=>[
                ':expression'=>[
                    'then'=>[
                        ':separator',
                        ':php_close',
                    ],
                ],

            ],
        ],

        'expression'=>[
            //don't start if something else starts... how??
            'start'=>[
               'match'=>';',
               'buffer.clear',
               'stop'
            ]
        ],
        



        'varchars' => [
            'start'=>[
                'match'=>'/^[a-zA-Z0-9_]+[^a-zA-Z0-9_]$/',
                'rewind'=>1,
                'buffer.notin keyword',
                'stop',
                'previous.set'=>'php.varchars',
                'buffer.clear'
            ],
        ],

        'separator'=>[
            'is'=>[
                'docblock:/*',
                ':comment',
                ':whitespace',
            ],
        ],

        'block'=>[
            'start' => '{',
            'stop'=> [
                'match'=>'}',
                'lexer:unsetPrevious docblock'
            ]
        ],


    //close directives list
    ];

}

<?php

namespace Tlf\Lexer\Php;

trait OtherDirectives {

    protected $_other_directives = [
        // 'html'=>[
        //     //this whole array essentially becomes the regexes array from the Html grammar. Except whats declared here overrides what's declared there.
        //     'grammar'=>'Html',
        //     //to automatically setup the html grammar to run this...
        //     //But then how does the html grammar know when it needs to stop?
        //
        //
        //     // This 'directives'=> ... will be added the root of $htmlGrammar->regexes.
        //     // Maybe as _directives to indicate special function
        //     // These will be checked every single time a char is added to the html
        //     // every single time...
        //     '_directives'=>[':php_open','php_echo'],
        // ],

        // @todo I need to apply php_close to almost everything...

        'whitespace'=>[
            //is 'i' dotall? & does that make it catch newlines?
            'start'=>[
                'match' =>'/(\s+)$/i',
                'lexer:unsetPrevious whitespace',
            ],
            'stop'=>[
                'match'=> '/[^\s]$/i',
                'rewind 1 //whitespace-stop',
                'previous.set whitespace',
                'buffer.clear',
            ],
        ],

        // 'docblock'=>[
            // 'start'=>[
                // 'match'=>'/(\/\*\*?)/',
                // 'then :docstar',
            // ],
            // 'stop'=> [
                // 'match'=>'/\\*\\//',
                // 'this:processDocBlock',
                // 'buffer.clear',
            // ],
        // ],

        'comment'=>[
            'start'=>[
                'match'=> '/(\\/\\/|\#)/',
                'buffer.clear'=>true,
            ],

            'stop'=>[
                'match'=>'/(\r\n|\n)$/',
                'this:processComment',
                'buffer.clear',
            ]
        ],

        'docstar'=>[
            'start'=>[
                'match'=>'/\*/',
                'stop',
                'directive.pop 1'
            ],
        ],

    ];
}
<?php

namespace Tlf\Lexer;

/**
 *
 * This is not for actual parsing yet. This is for design work. The $directives array & 'php_open' and 'namespace' are design aspects I'm interested in implementing at some point... maybe
 *
 */
class PhpGrammar extends Grammar {

    use Php\LanguageDirectives;
    use Php\ClassDirectives;
    use Php\ClassMemberDirectives;
    use Php\BodyDirectives;
    use Php\OtherDirectives;

    protected $directives;

    public $notin = [
        'keyword'=>[
            // 'match'=>'/this-regex-available on php.net keywords page/',
            '__halt_compiler', 'abstract', 'and', 'array', 'as', 'break', 'callable', 'case', 'catch', 'class', 'clone', 'const', 'continue', 'declare', 'default', 'die', 'do', 'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'eval', 'exit', 'extends', 'final', 'for', 'foreach', 'function', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'isset', 'list', 'namespace', 'new', 'or', 'print', 'private', 'protected', 'public', 'require', 'require_once', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'unset', 'use', 'var', 'while', 'xor'
        ],
    ];

    public function getNamespace(){return 'php';}

    public function buildDirectives(){
        $this->directives = array_merge(
            $this->_language_directives,
            $this->_body_directives,
            $this->_class_directives,
            $this->_class_member_directives,
            $this->_other_directives,
        );
    }

    public function onGrammarAdded($lexer){
        $this->buildDirectives();
        $lexer->addDirective($this->getDirectives(':php_open')['php_open']);
    }

    public function onLexerStart($lexer,$file,$token){
        $lexer->addGrammar(new DocblockGrammar());
        // $this->buildDirectives();
        // $lexer->addDirective($this->getDirectives(':html')[':html']);
        // $lexer->stackDirectiveList('phpgrammar:html', 'phpgrammar:php_open');
        // $lexer->setDirective([$this->getDirective('html')]);

        if ($file->type=='file'){
            $file->set('namespace', '');
        }
    }

    public function holdNamespaceName($lexer, $file, $token){
        $prev = $lexer->previous('namespace.name');
        if ($prev == null)$prev = [];
        $prev[] = $token->buffer();
        $lexer->setPrevious('namespace.name', $prev);
    }

    public function saveNamespace($lexer, $file, $token){
        $namespace = $lexer->previous('namespace.name');
        $namespace = implode('\\',$namespace);
        $file->set('namespace.docblock', $lexer->unsetPrevious('docblock'));
        $file->set('namespace', $namespace);
        $lexer->setPrevious('namespace.name', $namespace);
    }

    public function handleClassDeclaration($lexer, $class, $token){
        $class->set('declaration', $lexer->unsetPrevious('class.declaration'));
    }

    public function processDocBlock($lexer, $ast, $token){
        $lexer->setPrevious('docblock', $token->buffer());
    }
    public function captureUseTrait($lexer, $ast, $token){
        $ast->add('traits',$token->buffer());
    }
    public function processComment($lexer, $ast, $token){
        $comment = trim($token->buffer());
        $ast->add('comments', $comment);
        $lexer->previous('comment', $comment);
    }



    // public function end_docblock($lexer, $unknownAst, $token){
    //     $block = $token->buffer();
    //     $block = trim($block);
    //     $block = trim(substr($block,strlen('/**'),-1));
    //     $block = preg_replace('/^\s*\*+/m','',$block);
    //     $block = \Tlf\Scrawl\Utility::trimTextBlock($block);
    //     $block = trim($block);
    //     // if (substr($block,0,3)=='/**')$block = substr($block,3);
    //
    //         $docLex = new \Tlf\Lexer();
    //         $docLex->addGrammar(new \Tlf\Lexer\DocBlockGrammar());
    //
    //         $docAst = new \Tlf\Lexer\Ast('docblock');
    //         $docAst->set('src', $block);
    //         $docLex->setHead($docAst);
    //
    //         $docAst = $docLex->lexAst($docAst, $block);
    //
    //     $lexer->setPrevious('docblock', $docAst);
    //     $unknownAst->add('childDocblock', $docAst);
    //     $token->setBuffer($token->match(0));
    // }



    /**
     * Do nothing, apparently? I thought it was supposed to append to previous('whitespace'). Idunno
     */
    public function appendToWhitespace($lexer, $ast, $token, $directive){
        // $whitespace = $lexer->previous('whitespace') ?? '';
        // $lexer->setPrevious('whitespace', $whitespace.$directive->_matches[0]);
        // $lexer->setPrevious('whitespace', $whitespace.$token->buffer());
    }

    /**
     * Combine the stored modifier with the stored property declaration
     */
    public function setPropertyDeclaration($lexer, $ast, $token, $directive){
        $ast->set('declaration',
            $lexer->unsetPrevious('modifier')
            .$lexer->unsetPrevious('property.declaration')
        );
    }

    /**
     * 
     */
    public function storeMethodDefinition($lexer, $ast, $token, $directive){
        $ast->set('definition', 
            $lexer->unsetPrevious('modifier')
            .$lexer->unsetPrevious('method.definition')
        );
        $ast->set('arglist', $lexer->unsetPrevious('method.arglist') );
        $name = $lexer->unsetPrevious('method.name');
        $ast->set('name', $name);
        //remove the method name from the modifiers.
        $modifiers = $ast->get('modifiers');
        $ast->set('modifiers', substr($modifiers,0, -strlen($name)));
    }
}
<?php

namespace Tlf\Lexer;

class Ast {

    protected $_path;
    protected $_name;
    protected $_ext;


    public $_source;
    protected $_tree = [];
    public $_type;

    public function __construct($type, $startingTree=[]){
        $this->_type = $type;
        $this->_tree = $startingTree ?? [];
        $this->set('type',$type);
    }

    /**
     * Removes an ast if it is setto/addedto this ast. If $key points to an empty array, then $key is unset from this ast
     *
     * @param $key The key $ast was setto/addedto
     * @param $ast The ast to remove
     */
    public function removeAst($key, $ast){
        $value = $this->_tree[$key];
        if (is_array($value)){
            foreach ($value as $i=>$target){
                if ($target===$ast)unset($this->tree[$key][$i]);
            }
        if ($this->tree[$key]===[])unset($this->tree[$key]);
        } else if ($value===$ast){
            unset($this->tree[$key]);
        }

    }

    /**
     * Set $value to $key, overwriting any previously set value
     */
    public function set($key,$value){
        $this->_tree[$key] = $value;
    }

    public function append($key, $value){
        $this->_tree[$key] = $this->_tree[$key] . $value;
    }

    /**
     * @param $keyValues a `key=>value` array to call `$this->set($key, $value)` on each entry
     */
    public function setAll(array $keyValues){
        foreach ($keyValues as $key=>$value){
            $this->set($key,$value);
        }
    }

    /**
     * Add $value to an array
     * @param $key the key that we'll be pushing $value onto
     * @param $value the value to append
     * @param $subKey a subkey for an assoc array
     */
    public function add($key,$value, $subKey=false){
        // if (!isset($this->_tree[$key]))$this->_tree[$key] = [];
        if ($subKey===false)
            $this->_tree[$key][] = $value;
        else 
            $this->_tree[$key][$subKey] = $value;
    }
    /**
     * Alias for add 
     */
    public function push($key, $value, $subKey=false){
        $this->add($key, $value, $subKey);
    }


    /**
     * Check if key is set on this ast.
     * @return true if yes, false otherwise
     */
    public function has(string $key): bool{
        return isset($this->_tree[$key]);
    }

    public function get($key){
        return $this->_tree[$key] ?? null;
    }

    /**
     * Get the current tree as-is (asts are still asts)
     */
    public function getAll(){
        return $this->_tree;
    }

    protected $passthrough = [];
    public function addPassthrough($ast){
        $this->passthrough[] = $ast;
    }
    /**
     * Get the tree as a pure array
     */
    public function getTree($sourceTree=null){
        static $a = 0;
        $srcTreeIsNull = is_null($sourceTree);
        $sourceTree = $sourceTree ?? $this->_tree;
        $tree = [];
        foreach ($sourceTree as $key=>$value){
            if (is_array($value)){
                $tree[$key] =  $this->getTree($value);
                // $tree[$key] = 'array';
                // $tree[$key] = json_encode($value);
            } else if ($value instanceof Ast){
                $tree[$key] = $value->getTree();
            } else {
                $tree[$key] = $value;

            }
        }
        if ($srcTreeIsNull){
            foreach ($this->passthrough as $pt){
                $ptTree = $pt->getTree();
                unset($ptTree['type']);
                foreach ($ptTree as $k=>$v){
                    // if ($k=='methods'){
                        // $a++;
                        // echo "\n\n\n\n\n-----";
                        // var_dump($this);
                        // echo "\n\n\n\n\n-----";
                        // var_dump($ptTree);
                        // echo "\n\n\n\n\n-----";
                        // if ($a==2)exit;
                    // }
                    if (is_object($v))$v = $v->getTree();
                    // $tree[$k] = '--'.$this->type.':'.$k.'--'.$a++;
                    $tree[$k] = $v;
                }
            }
        }
        return $tree;
    }

    public function setTree($astTree){
        $this->_tree = $astTree;
    }

    public function __get($prop){
        return $this->get($prop);
    }
    public function __set($prop, $value){
        $this->set($prop, $value);
    }
    public function __isset($prop){
        return isset($this->_tree[$prop]);
    }

    static public function __set_state($array){
        return $array;
    }
}
<?php

namespace Tlf\Lexer;

class ArrayAst extends Ast {

    public function getTree($sourceTree = null){
        $val = $this->get('value') ?? [];
        foreach ($val as $i=>$v){
            if (is_object($v)){
                $val[$i] = $v->getTree();
            }
        }
        return $val;
    }

}
<?php

namespace Tlf\Lexer;

class JsonAst extends Ast {

    public function getJsonData(){

        if ($this->type=='json'){
            $tree = $this->tree;
            $rootAst = $tree['root'] ?? null;
            if ($rootAst===null)return $rootAst;
            return $rootAst->getJsonData();
        } else if ($this->type=='array'){
            $root = [];
            foreach ($this->value as $k=>$v){
                if ($v instanceof \Tlf\Lexer\JsonAst){
                    $root[$k] = $v->getJsonData();
                } else if ($v instanceof \Tlf\Lexer\Ast){
                    $root[$k] = $v->getTree();
                } else {
                    $root[$k] = $v;
                }
            }
            return $root;
        } 

        throw new \Exception("\nWe don't currently handle output for '".$this->type."'");
    }

}
<?php

namespace Tlf\Lexer;

class StringAst extends Ast {

    public function getTree($sourceTree = null){
        return $this->get('value');
    }

}
<?php

namespace Tlf\Lexer;

/**
 *
 * This is not for actual parsing yet. This is for design work. The $directives array & 'php_open' and 'namespace' are design aspects I'm interested in implementing at some point... maybe
 */
class BashGrammar extends Grammar {

    // use Bash\LanguageDirectives;
    use Bash\OtherDirectives;

    protected $expect = ['html', 'php_open'];
    /**
     * Filled by traits
     */
    public $directives;

    public $notin = [
        'asfdasdfkeyword'=>[
            // 'match'=>'/this-regex-available on php.net keywords page/',
            '__halt_compiler', 'abstract', 'and', 'array', 'as', 'break', 'callable', 'case', 'catch', 'class', 'clone', 'const', 'continue', 'declare', 'default', 'die', 'do', 'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'eval', 'exit', 'extends', 'final', 'for', 'foreach', 'function', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'isset', 'list', 'namespace', 'new', 'or', 'print', 'private', 'protected', 'public', 'require', 'require_once', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'unset', 'use', 'var', 'while', 'xor'
        ],
    ];

    public function getNamespace(){return 'bashgrammar';}

    public function __construct(){
        $this->directives = array_merge(
            // $this->_language_directives,
            $this->_other_directives,
        );
    }

    public function onLexerStart($lexer,$file,$token){
        // $lexer->addDirective($this->getDirectives(':bash')['php_open']);
    }

    public function handleDocblockEnd($lexer, $ast, $token, $directive){
        $block = $token->buffer();
        // $remLen = strlen($token->match(0));
        // $block = substr($block,0,-$remLen);
        $clean_input = preg_replace('/^\s*#+/m','',$block);
        // $block = preg_replace('/^\s*#+/m','* ',$block);
        // $block = "/**\n".$block."\n*/";

        $db_grammar = new \Tlf\Lexer\DocblockGrammar();
        $ast = $db_grammar->buildAstWithAttributes(explode("\n",$clean_input));
        // $lexer->setHead($ast);

        // $lexer->getHead()->docblocks = $lexer->getHead($ast)->docblocks ?? [];
        // $lexer->getHead()->docblocks[] = $ast;
        // $lexer->getHead()->add('dockblocks', $ast);
        $lexer->setPrevious('docblock', $ast);
    }

    public function handleFunction($lexer, $ast, $token, $directive){
        // $func_name = $token->match(1);
        $func = new \Tlf\Lexer\Ast('function');
        $func->name = $token->match(1);
        $func->docblock = $lexer->previous('docblock');
        $lexer->getHead()->add('function', $func);
    }

}
<?php

namespace Tlf\Lexer;

/**
 *
 *
 * @bug if there are curly braces in a command or something, functions will be found that are not there.
 */
class BashGrammar extends Grammar {


    protected $regexes = [

        'docblockStart'=>[
            'regex'=>'/(##.*)/',
            'state'=>[null, 'comment'],
        ],
        'docblockEnd'=>[
            'regex'=>'/(^\s*[^\#])/m',
            'state'=>['docblock'],
        ],
        'function'=>[
            'regex'=>'/(?:function\s+)?([a-zA-Z\_0-9]*)(?:(?:\s*\(\))|\s+)\{/',
            'state'=>[null],
        ],
        'comment'=>[
            'regex'=> '/#[^#]/',
            'state'=>[null],
        ],
        'commentEnd'=>[
            'regex'=> '/#[^\n]*\n/m',
            'state'=>['comment'],
        ]
    ];

    public function onLexerStart($lexer,$file,$token){
        // $file->set('namespace','');
    }

    public function lexComment($lexer, $fileAst, $token){
        // echo "LEX COMMENT\n";
        // echo "PreState: ".$lexer->getState()."\n";
        $lexer->setState('comment');
        // echo "State: ".$lexer->getState()."\n";
        // echo "Comment Start: ".$token->buffer();
        // echo "\n";
    }
    public function lexCommentEnd($lexer, $fileAst, $token){
        // echo "LEX COMMENT END\n";
        if ($lexer->getState()!='comment')return;
        // echo "PreState: ".$lexer->getState()."\n";
        $token->clearBuffer();
        $lexer->popState();

        // echo "State: ".$lexer->getState()."\n";
        // echo "Comment End: ".$token->match(0);
        // echo "\n";
    }


    public function lexDocblockStart($lexer, $ast, $token){
        if ($lexer->getState()=='comment')$lexer->popState();
        $token->clearBuffer();
        $token->setBuffer($token->match(1));
        $lexer->setState('docblock');
    }
    public function lexDocblockEnd($lexer, $ast, $token){
        $block = $token->buffer();
        $remLen = strlen($token->match(0));
        $block = substr($block,0,-$remLen);
        $block = preg_replace('/^\s*#+/m','',$block);
        $block = \Tlf\Scrawl\Utility::trimTextBlock($block);

            $docLex = new \Tlf\Lexer();
            $docLex->addGrammar(new \Tlf\Lexer\DocBlockGrammar());

            $docAst = new \Tlf\Lexer\Ast('docblock');
            $docAst->set('src', $block);
            $docLex->setHead($docAst);

            $docAst = $docLex->lexAst($docAst, $block);

        $lexer->setPrevious('docblock', $docAst);
        $ast->add('childDocblock', $docAst);
        $token->setBuffer($token->match(0));
        $lexer->setState(null);
    }
    public function lexFunction($lexer, $file, $token){

        // echo "State: ".$lexer->getState()."\n";
        // echo "Function: ".$token->match(0);
        // echo "\n";

        $class = new Ast('function');
        $class->set('name',$token->match(1));
        $class->set('docblock', $lexer->unsetPrevious('docblock'));
        $file->add('function',$class);


        $token->clearBuffer();
    }
}
<?php

namespace Tlf\Lexer\Bash;

trait OtherDirectives {

    protected $_other_directives = [
        'bash'=>[
            'is'=>[
                ':comment',
                ':docblock',
                ':function',
            ],
        ],

        'docblock'=>[
            'start'=>[
                'match'=>'##',
                'rewind 2',
                'buffer.clear',
                'forward 2',
            ],
            'stop'=>[
                'match'=>'/(^\s*[^\#])/m',
                'rewind 2',
                'this:handleDocblockEnd',
                'buffer.clear',
                // 'forward 2'
            ]
        ],

        'function'=>[
            'start'=>[
                'match'=>'/(?:function\s+)?([a-zA-Z\_0-9]*)(?:(?:\s*\(\))|\s+)\{/',
                'this:handleFunction',
                'stop',
                'buffer.clear',
                'lexer:unsetPrevious docblock'
            ]
        ],

        'comment'=>[
            'start'=>[
                'match'=>'/#[^\#]/',
                'rewind 2',
                'buffer.clear',
                'forward 1',
                'ast.new'=>[
                    '_addto'=>'comments',
                    '_type'=>'comment',
                    'src'=>'_token:buffer',
                ],
                'buffer.clear //again',
            ],

            // I definitely need a comment parsing directive
            
            'match'=>[
                //then I have to decide whether I want to allow them with no parentheses.
                //And I do. It should work with or without.
                //So, heck. That complicates things a lot
                'match'=>'/@[a-zA-Z0-9]/',
                'rewind 1',
                'ast.append src',
                'rewind 1 // again',
                'ast.append description',
                'forward 2',
                'buffer.clear',
                'then :+'=>[
                    'start'=>[
                        //just immediately start
                        'match'=>'',
                        'rewind 1',
                    ],
                    'stop'=>[

                        'match'=>'/(\\r|\\n)/',
                        'rewind 1',
                        'ast.append src',
                        'buffer.clear',
                    ]
                ],

            ],
            'stop'=>[
                'match'=>'/(\\r|\\n)/',
                'rewind'=>1,
                'ast.append src',
                'ast.append description',
                'forward'=>1,
                'buffer.clear',
                'ast.pop',
                // 'directive.',
            ],
        ],
    ];
}
<?php

namespace Tlf\Lexer;

/**
 * I ran into a lot of issues while writing this grammar, so I took a completely different approach.
 *
 * I think there's some useful stuff here, but if a new Docblock Grammar is to be written, I think this should all be scrapped & a new setup designe.
 *
 * Be sure to read the notes in ` I ran into a lot of issues while writing this grammar, so I took a completely different approach.
 *
 * I think there's some useful stuff here, but if a new Docblock Grammar is to be written, I think this should all be scrapped & a new setup designe.
 *
 * Be sure to read the notes in `.dev` folder before developing this further!
 */
class DocblockGrammar_Defunct extends Grammar {

    public $directives = [
        '/*'=>[
            'start'=>[
                'match'=>'/\\/\*/',
                'buffer.clear',
                'ast.new'=>[
                    '_type'=>'docblock',
                    '_addto'=>false,
                    // '_setHead'=>false,
                    '_setPrevious'=>'docblock',
                ],
                'then :@',
                'then :\n',
                'then :*',
                'then :!*',
                'then :*/'=>[
                    'start'=>[
                        'rewind 2',
                        'ast.append description',
                        'buffer.clear',
                    ],
                ],
            ],
            'stop'=>[
                'match'=> '*/',
                // 'stop',
                // 'directive.pop 1',
                'lexer:popHead'
            ]
        ],
        '*/'=>[
            'start'=>[
                'match'=>'*/',
                'directive.pop 1',
                'rewind 1',
            ]
        ],
        '\n'=>[
            'start'=>[
                'match'=>'/(\r|\n)/',
                'then :*',
                'then :!*',
            ],
        ],
        '*'=>[
            'start'=>[
                'match'=>"/\*[^\/]/",
                // 'rewind 1',
                'rewind 2',
                'buffer.clearNext 1',
                'buffer.appendChar'=>' ',
                'forward 1',
                'stop',
            ]
        ],
        '!*'=>[
            'start'=>[
                'match'=>'/[^\s\*]$/',
                'rewind 1',
                'buffer.clear',
                'then :\n' =>[
                    'start'=>[
                        // 'rewind 1',
                        'ast.append description',
                        'buffer.clear',
                        // 'forward 1',
                    ]
                ],
                'then :@',
                'then :*/'=>[
                    'start'=>[
                        'rewind 2',
                        'ast.append description',
                        'buffer.clear'
                    ],
                ],
            ],
            'stop'=>[
                'match'=>'*/',
                'rewind 1',
            ],
        ],
        '@'=>[
            'start'=>[
                'match'=>'@',
            ]
        ]

    ];

    public function onGrammarAdded($lexer){
    }
    public function onLexerStart($lexer, $ast, $token){
    }
    public function onLexerEnd($lexer, $ast, $token){

    }
}
<?php

namespace Tlf\Lexer;

class DocblockGrammar extends Grammar {

    public $directives = [

        '/*'=>[
            'start'=>[
                'match'=>'/\\/\*/',
                'buffer.clear',
            ],
            'stop'=>[
                'match'=>'*/',
                // 'directive.pop 1',
                'rewind 2',
                'this:processDocblock',
                'forward 2',
                'buffer.clear',
            ]
        ],
    ];

    public function getNamespace(){
        return 'docblock';
    }

    public function onGrammarAdded($lexer){
    }
    public function onLexerStart($lexer, $ast, $token){
    }
    public function onLexerEnd($lexer, $ast, $token){
        $prev = $lexer->previous('docblock');
        if ($prev!==null){
            $ast->add('docblock', $prev);
        }
    }

    public function processDocblock($lexer, $ast, $token, $directive){
// echo "\n\n\n-----------\n\n";
        // echo 'are we here?';
// echo "\n\n\n-----------\n\n";
// exit;
        // if ($lexer->loop_count==5483){
            // var_dump($lexer->loop_count);
            // var_dump("k");
            // echo "\n\n\n";
            // var_dump($token->buffer());
            // exit;
        // }
        // if (false){
        //     var_dump($lexer->loop_count);
        //     var_dump("k");
        //     echo "\n\n\n";
        //     var_dump($token->buffer());
        //     // exit;
        // }
        $body = $token->buffer();
        $lines = $this->cleanIndentation($body);


        $ast = $this->buildAstWithAttributes($lines);

        $lexer->setPrevious('docblock',$ast);
        if ($lexer->getHead()->_type=='expression'){
            $lexer->getHead()->set('docblock', $ast);
        }
    }

    public function buildAstWithAttributes($lines){
        // echo "\n\n\n++\n";
        $docblock = new Ast('docblock');
        $docblock->set('description', '');
        $curAttr = false;

        $head = $docblock;
        $key = 'description';
        $newLine = false;
        foreach ($lines as $index=>$line){
            if ($index>0)$newLine = true;
            if (preg_match('/^\s*\@([a-zA-Z\_0-9]+)[^a-zA-Z\_0-9]/',$line, $match)){
    
                if ($head->type=='attribute'){
                    $desc = $head->get('description');
                    $descLines = explode("\n", $desc);
                    // var_dump($descLines);
                    // exit;
                    while (count($descLines)>0&&trim($lastLine = array_pop($descLines)) == ''){
                        // var_dump($lastLine);
                    }
                    if (trim($lastLine)!=false){
                        $descLines[] = $lastLine;
                    }
                    $head->set('description', implode("\n", $descLines));
                }

                $line = substr($line, strlen($match[0])-1);
                $line = trim($line);
                $head = $match[1];
                $isAttr = true;
                $attr = new Ast('attribute');
                $attr->set('name', $match[1]);
                $attr->set('description', '');
                $head = $attr;
                $docblock->add('attribute', $attr);
                $newLine = false;
            }

            if ($newLine)$line = "\n$line";
            $head->append('description', $line);
        }

        // echo "\n\n\n++\n";
        return $docblock;
    }
    /**
     * Remove indentation and * from docblock body 
     */
    public function cleanIndentation($body){
        if (substr($body,0)=='*')$body = substr($body,1);
        // remove * from lines that only have whitespace and *
        $body = preg_replace("/^(\s*)\*(\s*)$/m", '\1 \2', $body);
        // remove * from all lines
        $body = preg_replace("/^(\s*)\*(\s*)/m", '\1 \2', $body);

        $body = \Tlf\Lexer\Utility::trim_indents($body);

        return explode("\n", $body);
    }
}
<?php

namespace Tlf\Lexer;

class Grammar {

    protected $blankCount = 0;

    /** The actual array of directives, built during onGrammarAdded() */
    public $directives = [];

    /**
     * the lexer currently running
     */
    protected \Tlf\Lexer $lexer;

    public function lexer_started($lexer, $ast, $token){
        $this->lexer = $lexer;
    }
    public function setLexer($lexer){
        $this->lexer = $lexer;
    }

    /**
     * Get a namespace prefix to use for specifying what directive to target
     * @return the class name, but lowercase, no namespace
     * @override
     */
    public function getNamespace(){
        $class = get_class($this);
        $parts = explode('\\',$class);
        $class = array_pop($parts);
        return strtolower($class);
    }

    /**
     * Get the class to use for any new ASTs where the directive does not specify.
     * @return a string class name. 
     *
     * @override to change from `\Tlf\Lexer\Ast`
     */
    public function getAstClass(): string {
        $astClass = \Tlf\Lexer\Ast::class;
        return $astClass;
    }

    /**
     * Get an array of directives from the list of directive names
     *
     * @return a key=>value array of directives.
     */
    public function getDirectives($directiveName, array $overrides=[]){

        if ($directiveName[0]!=':'){
            $parts = explode(':',$directiveName);
            if (count($parts)!=2){
                throw new \Exception("Directive '$directiveName' must contain one colon like `grammar:directive`. leave grammar blank for current grammar.");
            }
            $grammar = $this->lexer->getGrammar($parts[0]);
            $directiveName = ':'.$parts[1];
            if ($grammar!==$this){
                return $grammar->getDirectives($directiveName);
            }
        }


        // echo "\n\n---\n";
        // var_dump($directiveName);
        // var_dump($overrides);
        // echo "\n\n";
        // exit;
        //

        if (substr($directiveName,0,1)!==':'){
            echo "\n\n'$directiveName' needs to start with a colon...\n\n";
            throw new \Exception("So fix it...");
        }

        $overrides = $this->normalizeDirective($overrides);

        $directiveName = substr($directiveName, 1);
        $sourceDirective = $this->directives[$directiveName] ?? $this->getDotDirective($directiveName) ?? null;

        if ($sourceDirective===null){
            if (substr($directiveName,0,6)=='_blank'){
                $sourceDirective = [];
                if (strlen($directiveName)==6){
                    $directiveName = $directiveName .'-'.$this->blankCount++;
                }
            } else if ($directiveName[0]=='+'){
                $sourceDirective = [];
                $directiveName = $directiveName .'-'.$this->blankCount++;
            }
        } 
        if ($sourceDirective===null){
            throw new \Exception("Directive '$directiveName' not available on '".get_class($this)."'");
        }

        $sourceDirective = $this->normalizeDirective($sourceDirective);
        $overriddenDirective = $this->getOverriddenDirective($overrides, $sourceDirective);
        $overriddenDirective->_name = $directiveName;
        $overriddenDirective->_grammar = $this;

        if (!isset($overriddenDirective->is))return [$directiveName=>$overriddenDirective];


        return $this->expandDirectiveWithIs($overriddenDirective, (array)$overrides);
    }

    /** 
     *
     * Get multiple directives this one is pointing to.
     *
     * @roadmap(current) Version 1: Load all the targets as source directives, then process overrides with $directive as the overrides
     * @roadmap(next) Version 2: Load all the targets as source directives, using their own array values as overrides over the source, then process that as the source and $directive as the override
     * @roadmap(future, maybe) Version 3: The parent directive (who defines the 'is')... It's key/values are treated as overrides. The 'is' targets are loaded as source directives, and the parent key=>values (except 'is') are applied as the overrides to make a new source directive. Then the 'is' targets own array values are aplied as the overrides to make another new source directive. Then $directive is applied on each to make ANOTHER new source directive. These ones are returned.
     *
     *
     */
    public function expandDirectiveWithIs(object $directive, $overridesDirective = []){
        $isDirectiveName = $directive->_name;
        $d = $directive;

        $maxCount = 1;
        if (isset($directive->_name))$maxCount++;
        if (isset($directive->_grammar))$maxCount++;
        $out = [];
        // if (count((array)$d)>$maxCount){
            // // print_r($d->stop);
            // // print_r($overridesDirective);
            // throw new \Exception("'$isDirectiveName' cannot be processed because it has instructions other than 'is'");
        // }
        foreach ($d->is as $key=>$override){
            if (count($override)>0){
                throw new \Exception("We don't yet process overrides on 'is' entries.");
            }

            $subDirectives = $this->getDirectives($key, (array)$overridesDirective);
            foreach ($subDirectives as $directiveToAdd){
                $out[$directiveToAdd->_name] = $directiveToAdd;
            }
        }

        return $out;
    }

    /**
     *
     * - Inheritance rules:
     *   - if raw `match` directive is first in src directive, then add it first
     *   - then add instructions from the child directive, in declared order
     *   - then add all other instructions from the source directive, in their declared order.
     *   - If child directive contains any keys found in source directive, then do not copy the value from the source directive. The child simply overwrites (but in the child's declared order)
     *   
     * @param $newDirective The new directive / overrides, but not yet filled by the source
     * @param $sourceDirective the original directive
     */
    public function getOverriddenDirective(object $overridesDirective, object $sourceDirective){
        // $source = (array)$sourceDirective;
        $newDirective = [];

        foreach ($sourceDirective as $isn=>$instructionList){
            $firstInstruction = array_slice($sourceDirective->$isn,0,1);
            if (isset($firstInstruction['match'])
                &&!isset($overridesDirective->$isn['match'])
            ){
                $newDirective[$isn]['match'] = $firstInstruction['match'];
            }
        }

        foreach ($overridesDirective as $isn=>$instructionList){
            if ($isn[0]=='_')continue;
            if (!isset($newDirective[$isn]))$newDirective[$isn] = [];
            $newDirective[$isn] = $newDirective[$isn] + $instructionList;
        }

        foreach ($sourceDirective as $isn=>$instructionList){
            foreach ($instructionList as $instruction=>$value){
                if (!isset($newDirective[$isn][$instruction]))$newDirective[$isn][$instruction] = $value;
            }
        }

        return (object)$newDirective;
    }

    /**
     * - Arrayify instructions that need to be arrayified.
     * - Convert bool value-keys like 'buffer.clear' to 'buffer.clear'=>true
     */
    public function normalizeDirective($d){
        if (!is_object($d))$d = (object)$d;
        $instructionSetNames = ['start', 'match', 'stop'];
        $arrayify = [
            'match',
        ];
        foreach ($instructionSetNames as $isn){
            if (!isset($d->$isn))continue;
            $in = $d->$isn;
            $out = [];
            if (!is_array($in))$in = ['match'=>$in];
            foreach ($in as $key=>$value){
                if (is_int($key)){
                    if (substr($value,0,5)=='then '){
                        $out[$value] = [];
                    } else {
                        $out[$value] = true;
                    }
                    continue;
                }
                // convert values to array
                if (in_array($key, $arrayify)&&!is_array($value)){
                    $out[$key] = [$value];
                    continue;
                } 

                $out[$key] = $value;
            }
            $d->$isn = $out;
        }

        $alternateSetAutoValues = [
            'is'=>[],
        ];

        foreach ($alternateSetAutoValues as $setName=>$autoValue){
            if (!isset($d->$setName))continue;
            foreach ($d->$setName as $key=>$value){
                if (is_int($key)){
                    $newKey = $value;
                    $newValue = $autoValue;
                } else {
                    $newKey = $key;
                    $newValue = $value;
                }
                unset($d->$setName[$key]);
                $d->$setName[$newKey] = $newValue;
            }
        }


        return $d;
    }

    /**
     * Get a directive that has a dot-form like `:string.stop` to get a new directive who's `start` is `:string`'s `stop`
     * @return a single directive
     */
    protected function getDotDirective($key){
        $parts = explode('.',$key);
        if (count($parts)<=1)return null;
        if (count($parts)>2){
            throw new \Exception("We haven't implementented nested directive names, so '$key' won't work yet.");
        }

        $directiveName = $parts[0];
        $target = $parts[1];

        $directive = $this->directives[$parts[0]] ?? null;
        if ($target=='stop'){
            $newDirective = [
                'start'=>$directive['stop']??null,
                'onStart'=>$directive['onStop']??[],
            ];
            return $newDirective;
        } 

        throw new \Exception("We don't have special handling for '$target' yet. Caused by directive '$directiveName'");
    }

    /**
     * Called before any characters are added to the token
     *
     * @usage Set placeholder values
     * @param Tlf\Lexer $lexer the lexer
     * @param Tlf\Lexer\Ast $ast The root ast. Usually a 'file' type ast with 'ext', 'name', and 'path' set
     * @param Tlf\Lexer\Token $token a token with an empty buffer
     *
     * @export(DocBlock.onLexerStart)
     */
    public function onLexerStart(\Tlf\Lexer $lexer,\Tlf\Lexer\Ast $ast,\Tlf\Lexer\Token $token){

    }
    public function onLexerEnd(\Tlf\Lexer $lexer,\Tlf\Lexer\Ast $ast, ?\Tlf\Lexer\Token $token){
    }
    public function onGrammarAdded(\Tlf\Lexer $lexer){
    }

}
<?php

namespace Tlf\Lexer;

/**
 *
 */
class Helper {

    /**
     * Array of grammar classes
     * @key file extension (or identifier) of the language or whatever text is being parsed
     * @value class name of a `\Tlf\Lexer\Grammar` instance
     */
    public array $grammars = [
        'docblock'=>'Tlf\\Lexer\DocblockGrammar',
        'php'=>'Tlf\\Lexer\\PhpGrammar',
        'bash'=>'Tlf\\Lexer\\BashGrammar',
    ];
    
    /**
     * Create a 
     */
    public function getAstFromFile(string $file_path): \Tlf\Lexer\Ast {
        $lexer = $this->get_lexer_for_file($file_path);

        // ob_start();
        $ast = $lexer->lexFile($file_path);
        // ob_end_clean();

        return $ast;
    }

    /**
     * Get a Lexer initialized with the correct grammars.
     *
     * @param $language_ext the file extension for the language that is being scanned.
     */
    public function get_lexer_for(string $language_ext): \Tlf\Lexer {
        $language_ext = strtolower($language_ext);
        if (!isset($this->grammars[$language_ext])){
            $grammars = implode(", ", array_keys($this->grammars));
            throw new \Exception("A grammar is not available for '$language_ext'. Available grammars are: $grammars");
        }
        $grammar_class = $this->grammars[$language_ext];
        $grammar = new $grammar_class();

        $lexer = new \Tlf\Lexer();
        // $lexer->useCache = true;
        // $lexer->debug = false;
        $lexer->addGrammar($grammar, null, true);

        return $lexer;
    }
    public function get_lexer_for_file(string $file_path): \Tlf\Lexer {
        $ext = pathinfo($file_path, PATHINFO_EXTENSION);
        return $this->get_lexer_for($ext);
    }
}
<?php

namespace Tlf;


/**
 * Used to process a string into an Asymmetrical Syntax Tree (AST)
 *
 */
class Lexer {

    use LexerTrait\Internals;
    use LexerTrait\Cache;
    Use LexerTrait\Directives;
    Use LexerTrait\InstructionProcessor;
    Use LexerTrait\Instructions;
    use LexerTrait\MappedMethods;

    public float $version = \Tlf\Lexer\Versions::_old;

    /**
     * set true to show debug messages
     */
    public bool $debug = false;

    /**
     * The loop we're on. 0 means not started. 1 means we're executing the first loop. 2 means 2nd loop, etc.
     */
    public int $loop_count = 0;

    /**
     * Whether to load from & save to the cache or not.
     */
    public bool $useCache = true;

    /**
     * The token currently being processed
     */
    public $token = null;

    /**
     * array of grammar class names & their file's last mtime
     */
    protected $grammarListForCache = null;

    /**
     * the loop to stop processing on. Used for debugging, when writing a grammar.
     */
    public $stop_loop = -1;

    /**
     * A string that can be set & checked by handlers, to determine what operations should be completed.
     */
    public ?string $signal = null;

    /**
     * stop lexing
     */
    public function abort(){
        $this->stop_loop = $this->loop_count;
    }

    public function haltAll(){
        $this->haltAll = true;
    }

    public function continueAll(){
        $this->haltAll = false;
    }

    public function haltInstructions(){
        $this->haltInstructions = true;
    } 
    public function continueInstructions(){
        $this->haltInstructions = false;
    }

    public function previous($key){
        return $this->previous[$key] ?? null;
    }
    public function setPrevious($key, $value){
        $old = $this->previous($key);
        $this->previous[$key] = $value;
        return $old;
    }
    public function appendToPrevious($key, $value){
        $old = $this->previous($key);
        if (is_array($this->previous[$key]??null))$this->previous[$key][] = $value;
        else $this->previous[$key] = ($this->previous[$key]??'') . $value;
        return $old;
    }
    public function unsetPrevious($key){
        $prev = $this->previous($key);
        unset($this->previous[$key]);
        return $prev;
    }

    public function clearBuffer(){
        $buffer = $this->buffer;
        $this->buffer = '';
        return $buffer;
    }

    public function getToken(){
        return $this->token;
    }

    /**
     * @param $grammar A grammar
     * @param $name pass to override default namespace
     * @param $executeOnAdd `false` to skip calling `onGrammarAdded`
     */
    public function addGrammar(object $grammar, string $namespace=null, $executeOnAdd=true){
        $grammar->setLexer($this);
        $this->grammars[strtolower($namespace ?? $grammar->getNamespace())] = $grammar;
        if ($executeOnAdd)$grammar->onGrammarAdded($this);
    }
    public function getGrammar(string $namespace){
        return $this->grammars[strtolower($namespace)];
    }

    /**
     * Append an ast to top of stack.
     *
     * @see See Internals::$head
     */
    public function setHead($ast) {
        $this->head[] = $ast;
    }
    /**
     * Get top-level ast and remove it from the stack. If only one ast, then return it and leave at bottom of stack.
     * 
     * @see Internals::$head
     *
     * @return Tlf\Lexer\Ast from top of stack
     */
    public function popHead(): \Tlf\Lexer\Ast {
        if (count($this->head)>1)
            return array_pop($this->head);

        return $this->head[0];
    }
    /**
     * Get top-level AST from stack. 
     *
     * See Internals::$head
     * 
     * @return Tlf\Lexer\Ast from top of stack
     */
    public function getHead(): \Tlf\Lexer\Ast {
        return $this->head[count($this->head)-1];
    }
    /**
     * Get bottom-level AST from stack.
     *
     * See Internals::$head
     */
    public function rootAst(): \Tlf\Lexer\Ast {
        return $this->head[0];
    }

    /*
     * Create a 'file' ast & call 'lexAst'. Asts generated by this function are cached. Chache is invalidated when the source of the active grammars or the file being processed changes.
     *
     * @param $file an absolute file path
     */
    public function lexFile($file): \Tlf\Lexer\Ast {
        $debug = true;
        if ($ast=$this->getCachedAst($file)){
            echo "\nAst loaded from cache for file '$file'\n";
            // exit;
            return $ast;
        }
        if ($debug){
            echo "\n\n\n\n/////////////////////////////////";
            echo "\n/////////////////////////////////";
            echo "\nParse File '$file'";
            echo "\n/////////////////////////////////";
            echo "\n/////////////////////////////////";
            echo "\n\n\n\n";
        }
        $ast = new Lexer\Ast('file');
        // $ast->set('source', file_get_contents($file));
        $ast->set('ext', pathinfo($file,PATHINFO_EXTENSION));
        $ast->set('name', pathinfo($file,PATHINFO_FILENAME));
        $ast->set('path', $file);
        // $this->setHead($ast);

        $str = file_get_contents($ast->get('path'));
        $ast = $this->lex($str, $ast);

        $this->cacheFileAst($file, $ast);
        return $ast;
    }

}
<?php

namespace Tlf\LexerTrait;

/**
 * Handles caching of asts & grammar lists
 */
trait Cache {

    /**
     * Static cache so different instances of Lexer don't use all the memory, since cacheMap files are fairly large.
     */
    static protected $_cacheMap;

    /**
     * Copy of .cache/map.json
     */
    protected $cacheMap = null;

    public function getCachedAst($filePath){
        if ($this->useCache===false)return false;
        $cacheDir = dirname(__DIR__, 2).'/.cache/';
        if (!is_file($cacheDir.'/map.json'))return false;
        $this->cacheMap = &static::$_cacheMap[$cacheDir.'/map.json'];
        if ($this->cacheMap == null){
            // $mem = memory_get_usage();
            // $max = ini_get('memory_limit');
            // $filesize = filesize($cacheDir.'/map.json');
            // ob_end_clean();
            //
            // echo "\n\n";
            // var_dump("Mem: $mem ");
            // var_dump("Max: $max");
            // var_dump("File: $filesize");
            // echo "\n\n";
            // 
            // string(12) "Mem: 645656 "
            // string(9) "Max: 128M"
            //string(12) "File: 139698"

            // exit;
            $content = file_get_contents($cacheDir.'/map.json');
            $this->cacheMap = json_decode($content,true);
        }
        if (!isset($this->cacheMap['files'][$filePath]))return false;
        $file = $this->cacheMap['files'][$filePath];

        if (sha1_file($filePath)!=$file['sha1'])return false;
        
        $grammarList = $this->getGrammarListForCache();
        if ($grammarList != $file['grammarList']) return false;

        $astTree = include($file['cachedAstPath']);
        if (!is_array($astTree))return false;

        $ast = new \Tlf\Lexer\Ast('file');
        $ast->setTree($astTree);
        
        return $ast;
    }

    public function cacheFileAst($filePath, $ast){
        if ($this->useCache===false)return;
        $tree = $ast->getTree();

        $cacheDir = dirname(__DIR__, 2).'/.cache/';
        if (!is_dir($cacheDir))mkdir($cacheDir);
        if (!is_dir($cacheDir.'/fileast/'))mkdir($cacheDir.'/fileast/');
        if (!is_file($cacheDir.'/map.json'))file_put_contents($cacheDir.'/map.json',json_encode([]));
        $map = $this->cacheMap ?? json_decode(file_get_contents($cacheDir.'/map.json'),true);

        if (isset($map['files'][$filePath]['cachedAstPath'])){
            if (is_file($cachedPath = $map['files'][$filePath]['cachedAstPath'])){
                unlink($cachedPath);
            }
        }

        $map['files'][$filePath]['sha1'] = sha1_file($filePath);
        $map['files'][$filePath]['grammarList'] = $this->getGrammarListForCache();
        if (!is_dir($cacheDir.'/fileast'))mkdir($cacheDir.'/fileast');
        $cachedAstPath = $cacheDir.'/fileast/'.uniqid().'.php';
        $map['files'][$filePath]['cachedAstPath'] = $cachedAstPath;

        file_put_contents($cachedAstPath,
            '<?php return '
                . var_export($tree,true)
            .';'
        );
        
        $this->cacheMap = $map;
        file_put_contents($cacheDir.'/map.json', json_encode($map, JSON_PRETTY_PRINT));
    }

    public function getGrammarListForCache(){
        if ($this->grammarListForCache!=null)return $this->grammarListForCache;
        $grammarList = [];
        foreach ($this->grammars as $g){
            $grammarList[get_class($g)] = filemtime((new \ReflectionClass($g))->getFileName());
        }
        ksort($grammarList);

        $this->grammarListForCache = $grammarList;
        return $grammarList;
    }
}
<?php

namespace Tlf\LexerTrait;

/**
 * Manages the state of directives, including the different levels of directives and starting/stopping directives.
 */
trait Directives {

    /**
     * A stack of directives. Each layer of the stack has a 'started', 'unstarted', and 'directives' list.
     */
    public $directiveStack = [];


    public function newDirectivesLayer(){
        $this->directiveStack[] = [
            // 'directives'=>[],
            'unstarted'=>[],
            'started'=>[],
        ];
    }

    public function getTopDirectives(){
        return $this->topDirectivesList();
    }
    protected function &topDirectivesList(){
        return $this->directiveStack[count($this->directiveStack)-1];
    }
    /**
     *
     * @param $directive a previously unstarted directive
     */
    public function directiveStarted(object $directive){
        $list = &$this->topDirectivesList();
        if (!isset($list['unstarted'][$directive->_name])){
            $name = $directive->_name;
            echo "\n  -- '$name' cannot be started because it isn't in unstarted.";
            return;
        }
        $list['started'][$directive->_name] = $directive;
        unset($list['unstarted'][$directive->_name]);
    }
    /**
     * Move a directive from started stack to unstarted
     *
     * @param $directive a directive that was stopped 
     */
    public function directiveStopped(object $directive){
        $list = &$this->topDirectivesList();
        if (!isset($list['started'][$directive->_name])){
            $name = $directive->_name;
            echo "\n  -- '$name' cannot be stopped because it isn't started.";
            return;
        }
        $list['unstarted'][$directive->_name] = $directive;
        unset($list['started'][$directive->_name]);
    }
    /**
     * Adds a directed to the list of unstarted directives on the top directive list.
     * @note If the directive stack is empty, creates a new directive layer
     */
    public function addDirective(object $directive){
        if (count($this->directiveStack)===0)$this->newDirectivesLayer();

        $list = &$this->topDirectivesList();
        $list['unstarted'][$directive->_name] = $directive;
    }

    public function popDirectivesLayer(){
        if (count($this->directiveStack)>0){
            array_pop($this->directiveStack);
            return;
        }
        throw new \Exception("\n\nThere must be at least one directive layer in order to pop one.\n");
    }

}
<?php

namespace Tlf\LexerTrait;

/**
 * Contains logic to process & execute directive instructions
 *
 */
trait InstructionProcessor {

    /**
     * when true, no more instructions will be processed for the current directive.
     */
    protected $haltInstructions = false;
    /**
     * when true, no more directives will be processed during the current loop
     */
    protected $haltAll = false;

    /**
     * Combine cli-style arguments with a php variable
     * - Pass `...` for each php var indice to be an argument
     * - Pass `// any comment` to do comments
     * - TODO: Pass `!` to expand the php var as a call like `_lexer:previous docblock`
     * - TODO: Pass `[]` to expand the php var into multiple separate instructions
     *
     * @arg $cliArgs the cli arguments (not the namespace:command)
     * @arg $phpArg the php variable declared in the instruction
     * @return an array of arguments
     */
    public function getInstructionArgs(array $cliArgs, $phpArg){
        $allArgs = []; 

        $appendPhpArg = true;

        foreach ($cliArgs as $arg){
            if ($arg=='...'){
                $allArgs = [...$allArgs, ...$phpArg];
                $appendPhpArg = false;
            } else if ($arg == '//'){
                break; 
            } 
            else if ($arg == '[]'){
                //expand php var so we run multiple commands
                throw new \Exception("`[]` is reserved for future features and cannot be used as a directive instruction argument yet.");
            }
            else if ($arg == '!'){
                $appendPhpArg = false;
                $allArgs[] = $this->executeMethodString($phpArg);
                //treat the phparg as a `_namespace:method arg1 arg2` call
                // throw new \Exception("`!` is reserved for future features and cannot be used as a directive instruction argument yet.");
            } 
            else {
                $allArgs[] = $arg;
            }
        }

        if ($phpArg===false||!$appendPhpArg)return $allArgs;

        $allArgs[] = $phpArg;
        return $allArgs;
    }

    /**
     * Execute the command
     * @param $command a string command like `namespace:command`
     * @param $args array of arguments
     * @return void
     */
    public function executeInstruction(string $command, array $args, $directive, $instructionSetName, &$list){
        $isn = $instructionSetName;

        //@export_start(Commands.NamespaceTargets)
        $namespaceTargets = [
            'lexer'=>$this,
            'token'=>$this->token,
            'ast'=>$this->getHead(),
        ];
        $grammarTargets = $this->grammars;
        $grammarTargets['this'] = $directive->_grammar ?? null;
        //@export_end(Commands.NamespaceTargets)

        $commandParts = explode(':', $command);


        if ($this->debug){
            $this->debug_instruction_set($command, $commandParts, $args);
        }


        if (count($commandParts)==1){
            $namespace = 'this';
            $method = 'execCommand';
            // $args = [$command, $args, $directive, $instructionSetName, $list];
            $this->execCommand($command, $args, $directive, $isn, $list);
            return;
        } 
        $namespace = $commandParts[0];
        $method = $commandParts[1];


        if (isset($namespaceTargets[$namespace])){
            $object = $namespaceTargets[$namespace];
            $object->$method(...$args);
            return;
        } 
        
        if (isset($grammarTargets[$namespace])){
            $object = $grammarTargets[$namespace];
            /** @tip Grammar methods receive `($lexer, $headAst, $token, $directive)` if no other args are present. */
            $object->$method($this, $this->getHead(), $this->token, $directive, $args);
            return;
        }

        throw new \Exception("No object found for '$namespace' in command '$command'.");
    }


    /**
     *
     * @param $directive a directive
     * @param $instructionSetName the name of the instruction set like 'start', 'match', or 'stop'
     */
    public function processInstructions(object $directive, string $instructionSetName, &$list){

        $instructions = $directive->$instructionSetName ?? null;
        if ($instructions==null)return;
        if ($this->debug){
            //terminal green, the message, then terminal color off
            echo "\n\033[0;32mProcess ".$directive->_name."[$instructionSetName]\033[0m";
        }
        
        /**
         * Parse and execute instructions
         *
         * @input $instructions an array of instructions on a directive. Keys starting with an underscore (`_`) are for meta data and are not processed 
         * @param $cliCommandString the string portion of an instruction. Can be a key, or can be the value for a numeric indice.
         * @param $phpArg if $cliCommandString is an array key, then $phpArg is its value. Otherwise, $phpArg is boolean `true`
         */
        foreach ($instructions as $cliCommandString=>$phpArg){
            if ($this->haltInstructions){
                break;
            } elseif ($phpArg===false
                ||$cliCommandString[0]=='_'){
                /** @tip the $phpArg being false means 'dont run this command' */
                /** @tip Keys starting with `_` are meta data and are skipped */ 
                // if ($this->debug){
                    // echo "\n  skip $cliCommandString";
                // }
                continue;
            }

            $cliCommandArgs = explode(' ',$cliCommandString);
            $args = $this->getInstructionArgs(array_slice($cliCommandArgs,1), $phpArg);


            // var_dump("EXECUTE ".$cliCommandArgs[0]);
            $this->executeInstruction($cliCommandArgs[0], $args, $directive, $instructionSetName, $list);
            // var_dump("DONE EXECUTE ".$cliCommandArgs[0]);
            // if ($this->haltInstructions){
                // break;
            // }
        }
    }

    public function debug_instruction_set($cliCommandString, $cliCommandParts, $args){
        $debug_str = '';
        $debug_args_src = $args;
        $debug_args = [];
        foreach ($debug_args_src as $debug_index=>$debug_value){
            if (is_array($debug_value)){
                $debug_args_str = '';
                foreach ($debug_value as $sub_index=>$sub_value){
                    if (!is_int($sub_index)){
                        $debug_args_str .= $sub_index.'=>';
                    }
                    if (is_array($sub_value)){$sub_value = '[array('.count($sub_value).')]';}
                    else if (strlen($sub_value)>15){
                        $sub_value = substr($sub_value,0,15).'...';
                    } 
                    if (is_string($sub_value))$sub_value = '"'.$sub_value.'"';
                    $debug_args_str .= $sub_value.', ';
                }
                $debug_args[] = $debug_args_str;
            } else if (is_object($debug_value)){
                $debug_args[] = get_class($debug_value);
            } else {
                $debug_args[] = $debug_value;
            }
        }
        $debug_values_str = implode(", ", $debug_args);
        $debug_arg_count = count($debug_args_src);
        echo "\n  $cliCommandString [args($debug_arg_count)] $debug_values_str"; 
        // print_r($allArgs);
        // exit;
    }
}
<?php

namespace Tlf\LexerTrait;

/**
 * Handles executing individual instructions/commands.
 * @todo move the mapped methods into their own trait
 */
trait Instructions {

    /**
     * @todo Add extensibility feature to add to the method map & the switch/case
     */
    public function execCommand($command, $args, $directive, $instructionSetName,  &$directiveList){

        $methodMap = $this->getCmdMethodMap();
        if (isset($methodMap[$command])){
            $method = $methodMap[$command];
            $this->$method($args, $directive, $instructionSetName, $directiveList);
            return;
        }
        $this->executeSwitchCommand($command, $args, $directive, $instructionSetName, $directiveList);

    }

    /**
     * Execute a simple command thats defined inside our switch/case
     *
     * @param $command a string like `halt`, `match`, or one of many others
     * @param $args an array of arguments for the command
     * @param $directive the directive currently being executed
     * @param $isn the instruction set name currently being executed on the directive. Like `start` or `stop`
     * @return boolean true if the command execution was successful, false otherwise
     */
    public function executeSwitchCommand($command, $args, $directive, $isn, &$directiveList){
        $arg1 = $args[0] ?? false;
        $token = $this->token;
        $ast = $this->getHead();
        $debug = $this->debug;


        //@export_start(Commands.SwitchCase)
        switch ($command){
            ///
            // comands for debugging
            ///
            case "debug.die":
            case "die":
                var_dump($args);
                exit;
                break;
            case "debug.print":
            case "print":
                var_dump($args);
                break;
            /**
             * Run commands of another directive. Does not run 'match' by default
             *
             * @arg :directive.isn
             * @arg literal string 'match' to keep the match command from the inherited directive
             *
             * @example directive.inherit :varchars.start
             */
            case "directive.inherit":
            case "inherit":
                $arg2 = $args[1]??'';
                $parts = explode('.', $arg1);
                $name = $parts[0];
                $isn = $parts[1];
                $directives = $directive->_grammar->getDirectives($name);
                foreach ($directives as $d){
                    if ($arg2!=='match'){
                        unset($d->$isn['match']);
                    }
                    // print_r($d
                    $this->processInstructions($d, $isn, $directiveList);
                    if ($arg2==='match'&&isset($d->$isn['_matches'])){
                        $directive->$isn['_matches'] = $d->$isn['_matches'];
                    }
                }
                echo "\n\033[0;32mContinue ".$directive->_name."\033[0m";
                break;
            //
            // commands with non-namespaced shorthands
            //
            case "directive.start":
            case "start":
                $this->directiveStarted($directive);
                break;
            case "directive.stop":
            case "stop":
                $this->directiveStopped($directive);
                break;
            case "token.rewind":
            case "rewind":
                $token->rewind($arg1);
                break;
            case "token.forward":
            case "forward":
                $token->forward($arg1);
                break;
            /**
             * Halt execution of current directive (don't run its following instructions). Useful for preventing overrides from being executed
             */
            case "directive.halt":
            case "halt":
                $this->haltInstructions();
                break;
            case "halt.all":
                // @TODO maybe I should also haltInstruction, but ... I shouldn't break things.
                $this->haltAll();
                break;
            //
            // namespaced commands
            //
            case "previous.append":
                if (!is_array($arg1))$arg1 = [$arg1];
                foreach ($arg1 as $index=>$keyForPrevious){
                    $this->appendToPrevious($keyForPrevious, $token->buffer());
                }
                break;
            case "previous.set":
                $value = $args[1] ?? $token->buffer();
                if ($value ===true)$value = $token->buffer();
                $this->setPrevious($arg1, $value);
                break;
            case "directive.stop_others":
                foreach ($directiveList['started'] as $started){
                    if ($started!=$directive){
                        $this->directiveStopped($started, $list);
                    }
                }
                break;
            case "directive.pop":
                $arg1 = (int)$arg1;
                if ($arg1===0)echo "\n    --no directives popped.";
                while ($arg1-- > 0){
                    $this->popDirectivesLayer();
                }
                break;

            //
            // buffer commands
            //
            case "buffer.clear":
                $token->clearBuffer();
                break;
            case "buffer.clearNext":
                $amount = (int)$arg1;
                $remove = 0;
                while ($amount-->0){
                    if ($token->next())$remove++;
                }
                $token->setBuffer(substr($token->buffer(),0,-$remove));
                break;
            case "buffer.appendChar":
                $token->setBuffer($token->buffer() . $arg1);
                break;
            //
            // ast commands
            //
            case "ast.pop":
                $this->popHead();
                break;
            case "ast.set":
                if (isset($args[1])){
                    $value = $this->executeMethodString($args[1]);
                } else $value = $token->buffer();
                $this->getHead()->set($arg1, $value);
                break;
            /**
             * Save the currrent buffer to the given key
             * @arg key to push to
             */
            case "ast.push":
                $key = $arg1;
                $toPush = $token->buffer();
                $ast = $this->getHead();
                $ast->add($key,$toPush);
                break;
            case "ast.append":
                $key = $arg1;
                if (isset($args[1])&&is_string($args[1])){
                    var_dump($args[1]);
                    $value = $this->executeMethodString($args[1]);
                } else $value = $token->buffer();
                $ast = $this->getHead();
                $src = $ast->get($key);
                $new = $src . $value;
                $ast->set($key, $new);
                break;

            default:
                throw new \Exception("\nAction '$command' not handled yet. Maybe it needs to be a callable. Prepend `this:` to call a method on your grammar.");
        }
        //@export_end(Commands.SwitchCase)
    }

    /**
     *
     * Convert `_object:method arg1 arg2` to a call to `$object->method(arg1,arg2)`
     *
     * @param $input any input from an instruction.
     * @return the $input or value returned by calling the object method
     *
     * @throws if the input starts with `_` but does not reference a valid object+method
     * @example `_lexer:previous docblock` will call & return `$lexer->previous('docblock')`
     */
    public function executeMethodString($input){
        if ($input[0]!='_')return $input;
        $command = substr($input,1);
        $parts = explode(":",$command);
        if (count($parts)==1)return $input;
        $objects = [
            'lexer'=>$this,
            'token'=>$this->token,
            'ast'=>$this->getHead(),
        ];

        $object = $objects[$parts[0]] ?? null;
        if ($object==null)throw new \Exception("No object found for '$input");
        $argParts = explode(' ',$parts[1]);
        $method = array_shift($argParts);
        if (!method_exists($object,$method))throw new \Exception("Method for '$input' not found");
        $realValue = $object->$method(...$argParts);
        return $realValue;
    }

}

<?php

namespace Tlf\LexerTrait;

/**
 * Contains the internals for lexing.
 */
trait Internals {

    /**
     * That last loop on which 'then' was executed.
     * Used to control directive layer stacking.
     */
    public int $last_then_loop = -1;
    /**
     * All the grammars that have been added
     */
    protected $grammars = [];
    /**
     * Stack of ast objects. Top one is passed to lex functions
     */
    protected array $head = [];
    /**
     * Calling $lexer->previous('docblock') will get the previous docblock
     * $lexer->setPrevious('docblock', value) will set the previous docblock
     * ['nameOfPrevItem'
     */
    public $previous = ['docblock'=>null];

    /**
     * Processes an ast, setting it as the root (first head), executing grammar onLexerStart & onLexerEnd
     * @param $str a string to lexify
     * @param $ast an ast to use as root. An 'str' ast will be created if none is supplied.
     */
    public function lex($str, $ast=null){
        if ($ast===null){
            $ast = new \Tlf\Lexer\Ast('str');
            $ast->set('src', $str);
        }
        $debug = $this->debug;
        $this->setHead($ast);
        $token = new \Tlf\Lexer\Token($str);
        $this->token = $token;

        foreach ($this->grammars as $grammar){
            $grammar->lexer_started($this, $ast, $token);
            $grammar->onLexerStart($this,$ast,$token);
        }
        
        $this->loop_count = 0;

        // This while loop could be put into a single function. 
        // If I add threading, it might become necessary.
        while($token = $token->next()){
            ++$this->loop_count;

            $list = &$this->topDirectivesList();

            if ($debug){
                $this->debug_loop($token,$list);
            }

            $toProcess = $list['unstarted'];
            $instructionSets = ['start'];
            if (count($list['started'])>0){
                $toProcess = $list['started'];
                $instructionSets = ['match', 'stop'];
            }

            $this->haltAll = false;
            foreach ($toProcess as $directive){
                foreach ($instructionSets as $instructionSetName){
                    $this->haltInstructions = false;
                    if ($this->haltAll)break 2;
                    $this->processInstructions($directive, $instructionSetName, $list);
                }
            }
            $this->haltAll = false;

            if ($this->stop_loop==$this->loop_count){
                echo "\n\n\n\n\n\n";
                print_r($this->head[0]->getTree());
                echo "\n----Stop_loop count was reached!----\n\n";
                echo "\n\n";
                exit;
            }
        }

        foreach ($this->grammars as $grammar){
            $grammar->onLexerEnd($this, $ast, $lastToken??null);
        }
        return $this->rootAst();
        // return $ast;
    }

    /**
     * Check if a target passes
     * @return false or a $matches array, like you get from preg_match
     */
    protected function doesATargetPass($directive, $matchTargetList, string $toMatch){
        // $instructions = $directive->$instructionSetName ?? false;
        // if ($instructions == false)return false;
        // $matchTargetList = $instructions['match'] ?? [];

        // $toMatch = $this->token->buffer();
        // echo "\n\n-++++--\n";
        $matches = [$toMatch];
        foreach ($matchTargetList as $target){
            $target = $this->fillInTarget($target, $directive);
            if (
                $target===true
                ||substr($target,0,1)=='/'&&preg_match($target, $toMatch, $matches)
                ||substr($toMatch,-strlen($target))==$target&&$matches=[$target, $target]
            ){
                return $matches;
            }
        }
        return false;
    }

    /**
     * Get a corrected target regex/string/bool 
     *
     * @param $target a regex/string/bool value. Regex/string in form of '/a$1c/' or `['/a',1,'c/']` is valid
     * @return string or bool, corrected target with any placeholders replaced by matches
     */
    protected function fillInTarget($target, $directive){
        if (is_bool($target))return $target;
        if (is_array($target)){
            $out = '';
            foreach ($target as $value){
                if (is_int($value))$value = $previousMatches[$value];
                $out .= $value;
            }
            return $out;
        }

        if ($directive->_fillReg??false)return $target;

        $reg = '/\$[0-9]/';
        $newTarget = preg_replace_callback($reg, 
            function($matches) use ($directive){
                $index = (int)substr($matches[0],1);
                $replacement = $directive->_matches[$index];
                $replacement = preg_quote($replacement, '/');
                return $replacement;
            },
            $target 
        );
        return $newTarget;
    }

    /**
     * Print debug information for the current loop.
     */
    protected function debug_loop($token, $list){
        if ($this->debug){
            $newChar=str_replace("\n",'\\n',substr($token->buffer(),-1));
            $bufferEnd=substr($token->buffer(),-20);
            $bufferEnd=str_replace("\n",'\\n',$bufferEnd);
            echo "\n\n\033[45m----- +$newChar+ Loop ".$this->loop_count." `$bufferEnd` -----\033[0m\n";
            echo "Signal: ".$this->signal;
            echo "\nToken: ".
                "\n  New Char: ".$newChar
                ."\n  Buffer Len: ".strlen($token->buffer())
                ."\n  Buffer End: ".$bufferEnd
                ."\n  Next Chars: ".substr($token->remainder(),0,5)
                ."\n  Chars Remaining: ".strlen($token->remainder());

            echo "\nAst Stack has ".count($this->head)." entries.";
            foreach ($this->head as $debug_ast_index=>$debug_ast){
                $keys = $debug_ast->getAll();
                unset($keys['type']);
                $keys = array_keys($keys);
                echo "\n  lvl${debug_ast_index}: "
                    .'('.$debug_ast->type.')'
                    .' with entries: '.implode(', ', $keys);
            }

            echo "\nDirective Stack has ".count($this->directiveStack)." layers.";
            foreach ($this->directiveStack as $index=>$layer){
                echo "\n  lvl${index}: "
                    ." (unstarted) "
                    .implode(", ",array_keys($layer['unstarted']));

                echo "\n         (started) "
                    .implode(", ",array_keys($layer['started']));
            }
            if (($listCount=count($list['started']))>0){
                echo "\nCheck 'match' and 'stop' on ${listCount} directives";
            } else {
                $listCount = count($list['unstarted']);
                echo "\nCheck 'start' on $listCount directives";
            }

        }

    }

}
<?php

namespace Tlf\LexerTrait;

trait MappedMethods {


    public function getCmdMethodMap(){
        return 
        //@export_start(Commands.MethodMap)
        [
            'directive.then'=>'cmdThen',
            'then'=>'cmdThen',
            'then.pop'=>'cmdThenPop',

            'match'=>'cmdMatch',
            'buffer.match'=>'cmdMatch',

            'buffer.notin'=>'cmdBuffer_notin',

            'ast.new'=>'cmdAst_new',
        ];
        //@export_end(Commands.MethodMap)
    }

    /**
     *
     * @param $args array
     * @param $directive ARRAY OR STRING???
     * @param $isn instruction set name ('start', 'match', or 'stop') 
     * @param &$directiveList array ... I think this can be either the 'started' or 'unstarted', depending which is active.
     */
    public function cmdMatch($args, $directive, $isn, &$directiveList){
        $token = $this->token;
        $debug = $this->debug;

        // echo "\n\n\n\n\n\n---------\n\n";
        // $directive = (object)(array)$directive;
        // unset($directive->_grammar);
        // var_dump($directive);
        // echo "\n\n\n----\n\n";
        // var_dump($args);
        
        if (is_string($args[0])){
            $args[0] = [$args[0]];
        }

        // echo "\n\n\n";

        $matches = $this->doesATargetPass($directive, $args[0], $token->buffer());
        $token->setMatch($matches);
        // print_r($matches);
        if ($matches!==false){
            // $passed[$isn][$directive->_name] = $directive;
            $directive->$isn['_matches'] = $matches;
            if ($isn=='start'){
                $this->directiveStarted($directive, $directiveList);
            } else if ($isn=='stop'){
                $this->directiveStopped($directive, $directiveList);
            }
        } else {
            $this->haltInstructions();
        }
        if ($debug){
            if ($matches===false){
                echo '  [[fail]]';
            } else {
                echo "\033[42m".'[[pass]]'."\033[0m";
            }
        }
    }

    /**
     * Add a directive to the stack & immediately pop the directive layer when it is matched (instead of the directive's normal functioning).
     *
     * @example then.pop :directive_name.stop 2 //this will pop 2 directives when directive_name.stop matches.
     * @experimental there's an automatic rewind component of this feature & that will likely change. Currently, I'm rewinding by the lenght of $matches[1] (the first capture group). 
     */
    public function cmdThenPop($args, $directive, $isn, &$directiveList){
        if ($this->last_then_loop<$this->loop_count){
            $this->newDirectivesLayer();
        }
        $this->last_then_loop = $this->loop_count;

        $targetDirectiveName = $args[0];
        $popAmount = $args[1];
        $rewindLen = strlen($directive->start['_matches'][1]);
        $overrides = [
            'start'=>[
                'rewind'=>$rewindLen,
                'stop',
                'directive.pop'=>$popAmount,
                'halt',
            ],
        ];

        $grammar = $directive->_grammar;


        $directives = $grammar->getDirectives($targetDirectiveName, $overrides);
        foreach ($directives as $d){
            $this->addDirective($d);
        }
    }

    /**
     * Add a directive to the directive stack
     *
     * @example then :directive_name
     */
    public function cmdThen($args, $directive, $isn, &$directiveList){
        if ($this->last_then_loop<$this->loop_count){
            $this->newDirectivesLayer();
        }
        $this->last_then_loop = $this->loop_count;

        // echo "\n\n--";
        // print_r($args);
        // echo "\n\n";
        // exit;
        $targetDirectiveName = $args[0];
        $overrides = $args[1];


        // $grammar = $this->grammars[$directive->_grammar];
        $grammar = $directive->_grammar;


        $directives = $grammar->getDirectives($targetDirectiveName, $overrides);
        foreach ($directives as $d){
            $this->addDirective($d);
        }
    }



    /**
     * Checks if the current buffer matches any strings in `$grammar->notin['arg1']` and invalidates a match if the buffer matches
     *
     * @param $args the list of arguments
     * 
     * @example `notin keyword` checks `$grammar->notin
     * @arg the group of words to check in
     */
    public function cmdBuffer_notin($args, $directive, $isn, &$directiveList){

        $token = $this->token;

        $type = $args[0] ?? false;
        $list = $directive->_grammar->notin[$type] ?? [];
        if (in_array($token->buffer(), $list)){
            echo "\n     - '".$token->buffer()."' is a $type, so match fails"; 
            $this->haltInstructions();   
            // unset($passed[$isn][$directive->_name]);
            unset($directive->$isn['_matches']);
            if ($isn=='start'){
                $this->directiveStopped($directive, $list);
            } else if ($isn=='stop'){
                $this->directiveStarted($directive, $list);
            }
            $token->clearBuffer();
        }
    }


    public function cmdAst_new($args, $directive, $isn, &$list){
        $info = $args[0];
        $type = $info['type'] ?? $info['_type'];
        $type = $this->executeMethodString($type);
        if (isset($info['_class'])){
            $astClass = $info['_class'];
        } else {
            // $ownGrammar = $this->grammars[$directive->_grammar];
            $ownGrammar = $directive->_grammar;
            $astClass = $ownGrammar->getAstClass($directive);
        }
        $ast = new $astClass($type);
        if (isset($info['_setto'])){
            $_setto = $this->executeMethodString($info['_setto']);
            $this->getHead()->set($_setto, $ast);
            unset($info['_setto']);
        } else if (isset($info['_addto'])){
            if ($info['_addto']!==false){
                $_addto = $this->executeMethodString($info['_addto']);
                $this->getHead()->add($_addto, $ast);
            }
            unset($info['_addto']);
        } else {
            $this->getHead()->add($type, $ast);
        }

        if (isset($info['_setPrevious']) && $info['_setPrevious'] != false){
            $this->setPrevious($info['_setPrevious'], $ast);
        }


        foreach ($info as $key=>$value){
            if (is_string($value)){
                $realValue = $this->executeMethodString($value);
            } else $realValue=$value;
            $info[$key] = $realValue;
        }

        $setHead = isset($info['_setHead']) ? $info['_setHead'] : true;
        // @todo maybe unset '_class' too
        unset($info['_type'], $info['_setPrevious'], $info['_setHead']);
        $ast->setAll($info);

        if ($setHead){
            $this->setHead($ast);
        }

    }
}
<?php

namespace Tlf\Lexer;

class Utility {

    /**
     * Trim trailing whitespace from each line
     */
    static public function trim_trailing_whitespace(string $str){
        $regex = '/\s+$/m';
        $clean = preg_replace($regex, '', $str);
        return $clean;
    }

    /**
     * Remove leading indents from every line, but keep relative indents
     * @return string
     */
    static public function trim_indents(string $str){
        //separate first line
        $str = str_replace("\r\n", "\n", $str);
        $lines = explode("\n", $str);
        $firstLine = array_shift($lines);
        while (count($lines)>0&&trim($lines[0]) === ''){
            array_shift($lines);
        }

        // find smallest indent
        $smallestIndent = 9999;
        foreach ($lines as $index=>$line){
            if (trim($line)=='')continue;
            preg_match('/^(\s*)/', $line, $match);
            $indent = $match[1];
            if ($smallestIndent==-1)$smallestIndent = strlen($indent);
            else if ($smallestIndent>strlen($indent))$smallestIndent = strlen($indent);
        }
        // remove indent
        foreach ($lines as $index=>$line){
            if (strlen($line) < $smallestIndent)$lines[$index] = '';
            else $lines[$index] = substr($line,$smallestIndent);
        }
        // re-insert first line
        if (strlen($firstLine=trim($firstLine))>0){
            array_unshift($lines, trim($firstLine));
        }

        //remove trailing blank lines
        $lastLine = false;
        while (count($lines)>0 &&
            trim($lastLine = array_pop($lines))===''
        ){
            // if (trim($lastLine)=='')continue;
        }
        if (is_string($lastLine)){
            $lines[] = $lastLine;
        }

        return implode("\n", $lines);
    }
}
<?php

namespace Tlf\Lexer;

class Versions {

    /**
     * All code from before adding versioning
     */
    const _old = 0.1;
    /**
     * First versioned code. Adds parsing of statements, like assigning variables, calling methods, etc.
     */
    const _1   = 1.0;
}
<?php

namespace Tlf\Lexer\Ast;

class ClassAst extends \Tlf\Lexer\Ast {

    public function getTree($sourceTree = null){
        $val = $this->get('value') ?? [];
        foreach ($val as $i=>$v){
            if (is_object($v)){
                $val[$i] = $v->getTree();
            }
        }
        return $val;
    }


    public function getCode(string $language): string{
        //var_dump($this);
        //exit;

        $code = '';
        switch($language){
            case 'php':
                $code = $this->get_php_code();
                break;
            case 'javascript': 
                $code = $this->get_javascript_code();
                break;
            default:
                throw new \Exception("Language '$language' is not valid");
        }
        return $code;
    }

    public function get_php_code(): string {
        $t = (object)$this->_tree;
        $class_definition = "";
        if (!empty($t->namespace))$class_definition .= "\nnamespace {$t->namespace}";
        //var_dump($t);
        //var_dump($this->_tree);

        $class_definition .= "\nclass {$t->name} extends {$t->extends} {";

        foreach ($t->properties as $property){
            $p = new PropertyAst($property['type'],$property);
            $class_definition .= "\n".$p->get_php_code();
        }

        $class_definition .= "\n\n}";

        return $class_definition;
    }

    public function get_javascript_code(): string {
        $t = (object)$this->_tree;
        $class_definition = "";
        if (!empty($t->namespace))$class_definition .= "\n// ERROR, TODO: Cannot convert namespace '{$t->namespace}' to javascript.";

        $class_definition .= "\nclass {$t->name}";

        if (isset($t->extends))$class_definition .= " extends {$t->extends}";

        $class_definition .= " {\n";

        foreach ($t->properties as $property){
            $p = new PropertyAst($property['type'],$property);
            $class_definition .= "\n".$p->get_javascript_code();
        }

        $class_definition .= "\n\n}";

        return $class_definition;
    }

}
<?php

namespace Tlf\Lexer\Ast;

class DocblockAst extends \Tlf\Lexer\Ast {

    public function getTree($sourceTree = null){
        $val = $this->get('value') ?? [];
        foreach ($val as $i=>$v){
            if (is_object($v)){
                $val[$i] = $v->getTree();
            }
        }
        return $val;
    }


    public function getCode(string $language): string{
        //var_dump($this);
        //exit;

        $code = '';
        switch($language){
            case 'php':
                $code = $this->get_php_code();
                break;
            case 'javascript': 
                $code = $this->get_javascript_code();
                break;
            default:
                throw new \Exception("Language '$language' is not valid");
        }
        return $code;
    }

    public function get_php_code(): string {
        $t = (object)$this->_tree;

        $lines = [];

        $lines[] = $t->description;

        $code = 
            "\n/**\n * "
            .implode("\n * ", $lines)
            ."\n */";

        return $code;
    }

    public function get_javascript_code(): string {

        return $this->get_php_code();
    }

}
<?php

namespace Tlf\Lexer\Ast;

class PropertyAst extends \Tlf\Lexer\Ast {

    public function getTree($sourceTree = null){
        $val = $this->get('value') ?? [];
        foreach ($val as $i=>$v){
            if (is_object($v)){
                $val[$i] = $v->getTree();
            }
        }
        return $val;
    }


    public function getCode(string $language): string{
        //var_dump($this);
        //exit;

        $code = '';
        switch($language){
            case 'php':
                $code = $this->get_php_code();
                break;
            case 'javascript': 
                $code = $this->get_javascript_code();
                break;
            default:
                throw new \Exception("Language '$language' is not valid");
        }
        return $code;
    }

    public function get_php_code(): string {
        $t = (object)$this->_tree;
        //var_dump($t);
        //exit;

        //$definition = <<<PHP
            //$modifiers $type \$$name $set $value;
        //PHP;

        $parts = [];
        foreach ($t->modifiers as $m){
            $parts[] = $m;
        }

        if (!empty($m->datatype))$parts[] = $m->datatype;
        
        $parts[] = "\${$t->name}";

        if (isset($t->value))$parts[] = "= ".var_export($t->value,true);

        $statement = implode(" ",$parts);

        $docblock = "";
        if (!empty($t->docblock)&&$t->docblock!=[]){
            $docblock = new DocblockAst($t->docblock['type'], $t->docblock);
            $statement = $docblock->get_php_code() . "\n" . $statement;
        }

        $statement .= ";";

        return $statement;
    }

    public function get_javascript_code(): string {
        $t = (object)$this->_tree;
        //var_dump($t);
        //exit;

        //$definition = <<<PHP
            //$modifiers $type \$$name $set $value;
        //PHP;

        $statement = "";
        $errors = [];

        $parts = [];
        foreach ($t->modifiers as $m){
            $errors[] = "\n//ERROR, TODO: property modifier '{$m}' cannot be output as javascript code on property {$t->name}.";
        }

        if (!empty($m->datatype))$errors[] = "\n//ERROR, TODO: datatype '{$t->datatype}' cannot be output in javascript on property {$t->name}";
        
        $parts[] = "{$t->name}";

        if (isset($t->value))$parts[] = "= ".var_export($t->value, true);


        $docbloc_code = "";
        if (!empty($t->docblock)&&$t->docblock!=[]){
            $docblock = new DocblockAst($t->docblock['type'], $t->docblock);
            $docbloc_code = $docblock->get_javascript_code();
        }
        $statement = 
            implode("\n", $errors)."\n"
            .$docbloc_code."\n"
            .implode(" ",$parts)
            .';';

        return $statement;
    }

}
<?php

namespace Tlf\Lexer\PhpNew;

trait CoreDirectives {

    public $_core_directives = [
        'php_open'=>[
            // I could support short open, but I'm not going to right now
            'start'=>[
                'match'=>'<?php', 
                'buffer.clear',
                'then :php_code',
            ],
            'stop'=>[
                'match' => '?>',
                'buffer.clear',
            ]
        ],
        'php_code'=>[
            'start'=>[
                'rewind 1',
                'then :word',
                'then :operation',
                'then :whitespace',
                'then :comment',
                'then docblock:/*',
                'then :string',
                'then :+php_stop'=>[
                    'start'=>[
                        'match'=>'?>',
                        'directive.pop 2',
                        'rewind 2',
                        'buffer.clear',
                    ]
                ],
            ],
            'stop'=>[
                'debug.die'=>'php_code.stop should never execute, because the stopping is handled by the \'start\' of another directive',
                // 'match'=>'? >',
                // 'directive.pop 1',
                // 'rewind 2',
                // 'buffer.clear',
            ]
        ],

        'operation'=>[
            'start'=>[
                'this:operation_match',
                'match'=>'/./', // easiest way to do the propert starting & everything
                'this:handleOperation',
                'buffer.clear',
                'stop',
            ]
        ],
        'word'=>[
            'start'=>[
                // 'match'=>'/([a-zA-Z0-9\_\\\\])[^a-zA-Z0-9\_\\\\]$/',
                'match'=>'/^[a-zA-Z0-9\_\\\\]$/',
            ],
            'stop'=>[
                'match'=>'/[^a-zA-Z0-9\_\\\\]$/',
                'rewind 1',
                'this:handleWord',
                'buffer.clear',
            ],
        ],

        'whitespace'=>[
            //is 'i' dotall? & does that make it catch newlines?
            'start'=>[
                'match' =>'/^\s$/i',
                'lexer:unsetPrevious whitespace',
            ],
            'stop'=>[
                'match'=> '/[^\s]$/i',
                'rewind 1',
                'this:handleWhitespace',
                'buffer.clear',
            ],
        ],

        'comment'=>[
            'start'=>[
                'match'=> '/(\\/\\/|\#)/',
                'buffer.clear'=>true,
            ],

            'stop'=>[
                'match'=>'/(\r\n|\n)$/',
                'this:handleComment',
                'buffer.clear',
            ]
        ],
    ];
}
<?php

namespace Tlf\Lexer\PhpNew;

trait Handlers {

    //
    //
    //Helper methods
    //
    //

    /**
     * add a docblock to the ast if there is a previous docblock set. unset the previous docblock.
     *
     * @param $ast an object
     */
    public function docblock(object $ast){
        if ($docblock = $this->lexer->unsetPrevious('docblock')){
            $ast->docblock = $docblock;
        }
    }


    public function setArgDeclaration($arg){
        $lexer = $this->lexer;
        $xpn = $lexer->previous('xpn');
        $declaration = $xpn->declaration;
        $pos = count($declaration);
        while (--$pos>=0&&$declaration[$pos]!='('&&$declaration[$pos]!=','){}
        if ($pos>0)$declaration = array_slice($declaration,$pos+1);
        $arg->declaration = trim(implode('',$declaration));
        $lexer->popHead();
        $xpn->words = [];

    }

    public function closeArg($arg){
        $lexer = $this->lexer;
        $xpn = $lexer->previous('xpn');
        $declaration = $xpn->declaration;
        $pos = count($declaration);
        while (--$pos>=0&&$declaration[$pos]!='('&&$declaration[$pos]!=','){}
        if ($pos>0)$declaration = array_slice($declaration,$pos+1);
        $arg->declaration = trim(implode('',$declaration));
        if ($xpn->waiting_for == 'value'){
            $arg->value = implode('',$xpn->words);
            $xpn->waiting_for = null;
        }
        $lexer->popHead();
        $xpn->words = [];
    }


    //
    //
    // operation / word routers
    //
    //

    public function handleComment($lexer, $ast, $token, $directive){
        $ast->push('comments', trim($token->buffer()));
    }

    /**
     * move the string_backslash directive to the front of the directives list
     */
    public function handleStringBackslash($lexer, $ast, $token, $directive){
        // print_r($directive);
        // exit;
        $stack = &$lexer->directiveStack[count($lexer->directiveStack)-1]['unstarted'];
// echo "\n\n\n-----------\n\n";
        // print_r(array_keys($stack));
// echo "\n\n\n-----------\n\n";
        $backslash = $stack['string_backslash'];
        unset($stack['string_backslash']);
        $new_stack = [];
        $new_stack['string_backslash'] = $backslash;
        foreach ($stack as $key=>$value){
            $new_stack[$key] = $value;
        }
        $stack = $new_stack;
        return;
        $string_backslash_hopefully = array_pop($stack);
        array_unshift($stack, $string_backslash_hopefully);
        print_r(array_keys($stack));
        exit;


    }
    public function handleString($lexer, $ast, $token, $directive){
        // $lexer->abort();
        if (substr($token->buffer(),-2,1)=='\\'){
            echo "\n\n\n\n\nThere was a string backslash error!\n\n\n\n\n";
            $lexer->abort();
            // exit;
            return;
        }
        $string = $token->buffer();
        $xpn = $lexer->previous('xpn');
        $xpn->push('declaration', $string);
        $xpn->push('words', $string);
    }

    public function handleWhitespace($lexer, $ast, $token, $directive){
        $whitespace = $token->buffer();
        $xpn = $lexer->previous('xpn');
        $xpn->push('declaration', $whitespace);
    }

    public function handleWord($lexer, $ast, $token, $directive){
        $word = $token->buffer();
        $xpn = $lexer->previous('xpn');
        $xpn->push('declaration', $word);
        $xpn->push('words', $word);

        $method = 'wd_'.$word;

        // @bug if a variable name `$word` has a matching function `wd_$word`, then the variable will not be recognized
        // This means variables have special allowance & the word that is detected cannot be handled normally
        // it has to be passed to unhandled_wd
        // so where does that logic belong?
        // Probably just call it from `wd_namespace()` bc `wd_namespace()` should know when it is viable


        if (method_exists($this,$method)){
            if ($lexer->debug){
                echo "\n    call ".$method.'()';
            }
            $this->$method($lexer,$xpn,$ast);
        } else {
            if ($lexer->debug){
                echo "\n    unhandled_wd '$word'";
            }
            $this->unhandled_wd($lexer, $xpn, $ast, $word);
        }

        $xpn->last_word = $word;
    }

    /**
     * Convert an expression into an informational ast
     */
    public function handleOperation($lexer, $ast, $token, $directive){
        $xpn = $lexer->previous('xpn');
        //I'm gonna have to also handle multi-character operations like:
            // == === && ||
            // ... (vararg)
        $map = $this->get_operations();
        $char = $token->buffer();
        if (!isset($map[$char])){
            $lexer->haltInstructions();
            $lexer->directiveStopped($directive);
            $token->next();
            echo "\n     --Invalid operator: $char";
            return;
            // echo "\n\n--ERROR--\n\n";
            // echo "Char '$char' does not have any operations associated with it. Available operations are:";
            // print_r($map);
            // throw new \Exception("Invalid character matched");
        }


        $method = 'op_'.$map[$char];

        if ($lexer->debug){
            echo "\n    call '$method'";
        }
        if (!method_exists($this,$method)){
            return;
        }

        $this->$method($lexer, $ast, $xpn);
        // $this->$method($lexer, $expression, $token, $directive);
    
        $lexer->unsetPrevious('docblock');
        $lexer->previous('xpn')->last_op = $map[$char];
    }
}
<?php

namespace Tlf\Lexer\PhpNew;

use \Tlf\Lexer\Versions;

trait Operations {

    // public function op_none(){return false;}
    public function operation_match($lexer, $ast, $token, $directive){
        $buff = $token->buffer();
        $next = $token->remainder()[0] ?? ' ';
        $buffNext = $buff . $next;
        $buffNextNext = $buff . $next . ($token->remainder()[1] ?? ' ');
        $ops = $this->get_operations();

        // does $buff + next == an operation? Then we stop and match fails
        // Does $buff == an operation? then we stop and match succeeds
        if (isset($ops[$buffNext])
            ||isset($ops[$buffNextNext])
            ||!isset($ops[$buff])
            ||$ops[$buff]=='none'){
            $lexer->haltInstructions();
            return;
        }
    }

    public function get_operations(){

        $map = [

            // (i think) 'none' disables default operation handling 
            // this is good if it has it's own directive
            //
            '/*'=>'none',
            '//'=>'none',
            '?>'=>'none', // without this, the `?` gets handled & php_stop never does
            '<<<' => 'none', // has a directive in StringDirectives

            // '&&'=>'none',
            // '||'=>'none',
            '&&'=>'and',
            '||'=>'or',

            //comparison
            '!='=>'does not equal',
            '!=='=>'strictly does not equal',
            '=>'=>'array_keyed',
            '<='=>'is_lt_equal',
            '>='=>'is_gt_equal',
            '=='=>'is_equal',
            '>'=>'is_gt',
            '<'=>'is_lt',
            
            //math
            '+'=>'math',
            '-'=>'math',
            '*'=>'math',
            '**'=>'math',
            '/'=>'math',

            //other
            '='=>'assign',
            ';'=>'terminate',
            ':'=>'return_type',
            '$'=>'var',
            ','=>'comma',
            '.'=>'concat',
            '&'=>'reference',
            '->'=>'method_call',
            '::'=>'static_call',
            '!'=>'not',
            '|'=>'binary_thing',
            '++'=>'increment',
            '--'=>'decrement',
            '??'=>'null coalesce',
            '?'=>'nullable type',
            '@'=>'suppress error',

            //scope
            '{'=>'block_start',
            '}'=>'block_end',
            '('=>'arglist_open',
            ')'=>'arglist_close',
            '['=>'array_open',
            ']'=>'array_close',

        ];

        return $map;
    }


    public function op_array_open($lexer, $ast, $xpn){
        $array = new \Tlf\Lexer\StringAst('array');
        $ast->set('value', $array);
        // $array->abc = 'okay';
        $xpn->push('declaration', '[');
        $xpn->push('words','[');
        $lexer->setHead($array);
    }
    public function op_array_close($lexer, $ast, $xpn){
        $lexer->popHead();
        $xpn->push('words',']');
        $xpn->push('declaration', ']');
    }

    public function op_array_keyed($lexer, $ast, $xpn){
        $xpn->push('words', '=>');
        $xpn->push('declaration', '=>');
    }

    public function op_math($lexer, $ast, $xpn){
        $xpn->push('words', $lexer->getToken()->buffer());
        $xpn->push('declaration', $lexer->getToken()->buffer());
    }

    public function op_reference($lexer, $ast, $xpn){
        if ($ast->type == 'method'){
            $xpn->push('declaration', '&');
            $xpn->push('words', '&');
            $ast->return_by_reference = true;
            $lexer->getToken()->clearBuffer();
        }
    }

    public function op_var($lexer, $ast, $xpn){
        $xpn->push('declaration','$');

        if ($lexer->version >= Versions::_1){
            if ($lexer->signal=='expect_var_assign_target'){
                $new_ast = new \Tlf\Lexer\Ast('var');
                $ast->set('set_to', $new_ast);
                $new_ast->type = 'var';
                $lexer->signal = 'expect_var_name_in_assignment';
                $lexer->setHead($new_ast);

                return;
            } else if ($ast->type=='method_body'
                // || $ast->type=='file'
            ){
                $varAst = new \Tlf\Lexer\Ast('var');
                $varAst->set('line_number', $lexer->getToken()->line_number);
                $xpn->words = [];
                $this->docblock($varAst);
                $ast->push('statements', $varAst);
                $lexer->setHead($varAst);

                // $varNameAst = new \Tlf\Lexer\StringAst('var_name');
                // $lexer->setHead($varNameAst);
                // $varAst->set('name', $varNameAst);

                $lexer->signal = "expect_var_name";
                return;
            }
        }

        //how do I know if it is a(n):
        // - argument
            // if I'm inside a method/function, its an argument
        // - property
            // if i'm inside a class ast, then its a property
        // - variable
            // If i'm anywhere else, its a variable
        // - Other cases? 
            // like inside a use() statement for an anonymous function

        $headAst = $lexer->getHead();
        if ($headAst->type=='class_body'){
            $prop = new \Tlf\Lexer\Ast('property');
            $prop->modifiers = $xpn->words;
            $this->docblock($prop);
            $lexer->setHead($prop);
            $headAst->push('properties', $prop);
            $prop->name = new \Tlf\Lexer\StringAst('property_name');
            $lexer->setHead($prop->name);
        } else if ($headAst->type=='method_arglist'){
            $prop = new \Tlf\Lexer\Ast('arg');
            if (count($xpn->words??[])>0){
                $prop->arg_types = $xpn->words;
            }
            $xpn->words = [];
            $this->docblock($prop);
            $headAst->push('value', $prop);
            $lexer->setHead($prop);

            $propName = new \Tlf\Lexer\StringAst('arg_name');
            $lexer->setHead($propName);
            $prop->set('name', $propName);
        } 
            
    }

    public function op_comma($lexer, $ast, $xpn){
        $head = $lexer->getHead();
        if ($head->type == 'arg'){
            $this->setArgDeclaration($ast);
        } else if ($head->type=='var_assign'){
            $head->value = implode('',$xpn->words);
            $lexer->popHead();
            $this->setArgDeclaration($lexer->getHead());
            $lexer->popHead();
        } else if ($head->type=='array'){
            $xpn->push('words', ',');
        }
        $xpn->push('declaration', ',');
    }
    public function op_concat($lexer, $ast, $xpn){
        $xpn->push('words', '.');
        $xpn->push('declaration', '.');
    }

    public function op_terminate($lexer, $ast, $xpn){

        if ($lexer->version >= Versions::_1){
            if ($lexer->signal == 'expect_op_terminate'){
                $xpn->push('declaration', ';');
                $ast->set('declaration', implode('',$xpn->declaration));
                $lexer->popHead();
                return;
            }
        }

        // $head->declaration = trim(implode('', $xpn->declaration).';');
        $declaration = trim(implode('', $xpn->declaration??[]).';');
        if ($ast->type=='var_assign'){
            $ast->value = implode('',$xpn->words);
            $lexer->popHead();
            $lexer->getHead()->declaration = $declaration;
            $lexer->popHead();
        } else if ($ast->type == 'property'){
            $ast->declaration = $declaration;
            $lexer->popHead();
        } else if ($ast->type == 'namespace' || $ast->type=='use_trait'){
            $ast->set('name', implode('',$xpn->words));
            $ast->declaration = $declaration;
            if ($ast->type=='use_trait')$lexer->popHead(); 
        } 

        // $newXpn = new \Tlf\Lexer\Ast('expression');
        // $lexer->setPrevious('xpn', $newXpn);
        $xpn->declaration = [];
        $xpn->words = [];
    }

    public function op_block_start($lexer, $ast, $xpn){


    
        // echo ("\n\n\nAST TYPE({): ".$ast->type."\n\n\n");
        $ast = $lexer->getHead();


        if ($ast->type == 'return_types'){
            $lexer->popHead();
            $ast = $lexer->getHead();
        }

        if ($ast->type == 'method' || $ast->type=='function'){
            // $body = new \Tlf\Lexer\ArrayAst('method_body');
            $body = new \Tlf\Lexer\StringAst('method_body');
            $lexer->setHead($body);
            $ast->set('body', $body);
            $ast->declaration = trim(implode('', $xpn->declaration));
            $xpn->declaration = [];
            $xpn->words = [];
            $lexer->setPrevious('method_start', $lexer->token->index+1);
            // $index = $lexer->token->index+1;
// echo "\n\n\n-----------\n\n";
            // var_dump($lexer->token->source);
// echo "\n\n\n-----------\n\n";
            // var_dump($index);
            // exit;
        } else if ($ast->type=='class' || $ast->type=='class_implements' || $ast->type == 'trait'){
            // echo 'okay, now stop';
            // exit;
            $body = new \Tlf\Lexer\Ast('class_body');
            $lexer->setHead($body);
            $ast->addPassthrough($body);
            $ast->declaration = trim(implode('',$xpn->declaration));
            $xpn->declaration = [];
            $xpn->words = [];
        } else if ($ast->type=='method_body' || $ast->type == 'block_body'){
            $body = new \Tlf\Lexer\ArrayAst('block_body');
            $lexer->setHead($body);
        }


    }
    public function op_block_end($lexer, $ast, $xpn){
        // echo ("\n\n\nAST TYPE(}): ".$ast->type."\n\n\n");
        if ($ast->type == 'method_body'){
            $start = $lexer->unsetPrevious('method_start');
            $end = $lexer->token->index - $start; 
            $body = substr($lexer->token->source,$start,$end);
            $body = \Tlf\Lexer\Utility::trim_indents($body);
            $body = \Tlf\Lexer\Utility::trim_trailing_whitespace($body);
            $ast->value = $body;
            $lexer->popHead();
            $lexer->popHead();
        } else if ($ast->type=='class_body'){
            $lexer->popHead();
            $lexer->popHead();
        } else if ($ast->type=='block_body'){
            // $lexer->popHead();
            $lexer->popHead();
            $lexer->setPrevious('xpn', new \Tlf\Lexer\Ast('expression'));
            // var_dump($xpn);
            // exit;
        } 
        // else if ($ast->type=='function'){
        //     $xpn->declaration = [];
        //     $xpn->last_word = null;
        //     $xpn->words = [];
        //     // var_dump($xpn);
        //     // exit;
        //     $lexer->popHead();
        // }
        // else {
            // echo 'else block end';
            // exit;
        // }

    }

    public function op_assign($lexer, $ast, $xpn){

        if ($lexer->version >= Versions::_1){
            if ($lexer->signal == 'expect_var_assign'){
                $xpn->push('declaration', '=');
                $xpn->set('words', []);
                $lexer->signal = 'expect_var_assign_target';
                return;
            }
        }

        $ast = $lexer->getHead();
        if ($ast->type!='arg'&&$ast->type!='property' && $ast->type!='var'
            &&$ast->type!='const'
            || isset($ast->value))return;

        if ($ast->type=='var'){
            $xpn->push('declaration', '=');
            $xpn->set('words',[]);
            
        } else {

            $xpn->push('declaration', '=');
            $xpn->set('words',[]);
            $var_assign = new \Tlf\Lexer\StringAst('var_assign');
            $lexer->setHead($var_assign);
            $ast->set('value', $var_assign);
        }

    }

    public function op_arglist_open($lexer, $ast, $xpn){
        if ($ast->type!='method' && $ast->type!='use_vars'){
            $xpn->parenthesisCount = $xpn->parenthesisCount + 1;
            $xpn->push('declaration', '(');
            $xpn->push('words', '(');
            return;
        }
        $arglist = new \Tlf\Lexer\ArrayAst('method_arglist');
        $ast->set('args', $arglist);
        $xpn->push('declaration', '(');
        $xpn->words = [];
        $lexer->setHead($arglist);
    }

    public function op_arglist_close($lexer, $ast, $xpn) {

        if ($xpn->parenthesisCount > 0){
            $xpn->parenthesisCount = $xpn->parenthesisCount - 1;
            $xpn->push('declaration', ')');
            $xpn->push('words', ')');
            // if ($xpn->parenthesisCount == 0){
                // var_dump($xpn->getTree());
                // exit;
            // }
            return;
        }


        $head = $lexer->getHead();
        if ($head->type == 'method_arglist'){
            $lexer->popHead();
        } else if ($head->type == 'arg'){
            $this->setArgDeclaration($ast);
            $lexer->popHead();
            if ($lexer->getHead()->type == 'use_vars'){
                $lexer->popHead();
            }
        } else if ($head->type == 'var_assign'){
            $head->value = implode('', $xpn->words);
            $lexer->popHead();
            $this->setArgDeclaration($lexer->getHead());
            $lexer->popHead();
        } 

        $xpn->push('declaration', ')');
    }

    public function op_return_type($lexer, $ast, $xpn){
        if ($lexer->getHead()->type=='method' || $lexer->getHead()->type=='function'){
            $xpn->push('declaration',':');
            $ast = new \Tlf\Lexer\ArrayAst('return_types');
            $lexer->getHead()->set('return_types', $ast);
            $lexer->setHead($ast);
        }
    }
}
<?php

namespace Tlf\Lexer;

/**
 *
 * This is not for actual parsing yet. This is for design work. The $directives array & 'php_open' and 'namespace' are design aspects I'm interested in implementing at some point... maybe
 *
 */
class PhpGrammar extends Grammar {

    use PhpNew\Handlers;
    use PhpNew\Operations;
    use PhpNew\Words;

    // use PhpNew\LanguageDirectives;
    // use PhpNew\ClassDirectives;
    // use PhpNew\ClassMemberDirectives;
    // use PhpNew\BodyDirectives;
    use PhpNew\StringDirectives;
    use PhpNew\CoreDirectives;

    public $directives;

    public $notin = [
        'keyword'=>[
            // 'match'=>'/this-regex-available on php.net keywords page/',
            '__halt_compiler', 'abstract', 'and', 'array', 'as', 'break', 'callable', 'case', 'catch', 'class', 'clone', 'const', 'continue', 'declare', 'default', 'die', 'do', 'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'eval', 'exit', 'extends', 'final', 'for', 'foreach', 'function', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'isset', 'list', 'namespace', 'new', 'or', 'print', 'private', 'protected', 'public', 'require', 'require_once', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'unset', 'use', 'var', 'while', 'xor'
        ],
    ];

    public function getNamespace(){return 'phpnew';}

    public function buildDirectives(){
        $this->directives = array_merge(
            // $this->_language_directives,
            // $this->_body_directives,
            // $this->_class_directives,
            // $this->_class_member_directives,
            $this->_string_directives,
            $this->_core_directives,
        );
    }

    public function onGrammarAdded($lexer){
        $this->buildDirectives();
        $lexer->addDirective($this->getDirectives(':php_open')['php_open']);
    }

    public function onLexerStart($lexer,$file,$token){
        $lexer->addGrammar(new DocblockGrammar());

        $token->append(' ');

        $xpn = new Ast('expression');
        $lexer->setPrevious('xpn', $xpn);

        // $this->buildDirectives();
        // $lexer->addDirective($this->getDirectives(':html')[':html']);
        // $lexer->stackDirectiveList('phpgrammar:html', 'phpgrammar:php_open');
        // $lexer->setDirective([$this->getDirective('html')]);

        if ($file->type=='file'){
            $file->set('namespace', '');
        }
    }



}
# Php Grammar Overview
This is a cursory overview of the structure & general logic flow of the PhpGrammar 

The PhpGrammar uses a bunch of traits. 

All calls into php start with something defined in the directives.

Directives are defined in `CoreDirectives.php` and `StringDirectives.php`

Basically the `php_open` directive lists all the other directives that can be matched inside the root of php code (after `<?php`). These are things like `word`, `operation`, `string`, and `comment`.

The `word` directive is activated (`start`ed) when the token matches `'/^[a-zA-Z0-9\_\\\\]$/`. It is subsequently stopped upon matching the same, then we `rewind 1`, call `PhpGrammar->handleWord(...)` (which is in the `Handlers.php` trait), then clear the buffer.

`operation` matches for various symbols, and calls `handleOperation()`.

There are various other handlers in `Handlers.php` Some of them just do the one thing they need to do, like `handleWhitespace` just pushes the whitespace onto the declaration of the previous expression. `handleComment` for (`//` & `#` type comments) just pushes the token's buffer onto 'comments' on the head ast.

The directives themselves do additional operations before and/or after the php handler. `comment` directive will clear the buffer when the match starts, and will clear the buffer at the end, after `handleComment` is called. This means `handleComment` does not have to clear the buffer. The directive handles it.

It gets more complex with `handleWord` and `handleOperation` which are defined in `Handlers.php` trait. These call methods defined in the traits in `Words.php` and `Operations.php`. `trait Handlers` basically just calls `wd_'matched_string'` for words and `op_'matched_string'` for operations. Ex `wd_namespace` is called if the buffer is exactly `namespace`. `unhandled_wd` is called if there is no function named `wd_matched_string`.

`trait Operation` is the same way, except it is `op_word`. the `word` here comes from `Operations::get_operations()` which turns an array map where the key is the symbols and the value is the `word`. So the `word` can be things like `does_not_equal` for `!=` or `+ - * ** /` are all just `math`, so `op_math` gets called, if it is defined.

Some operations are set like `++` maps to `increment` or `function op_increment` but `function op_increment` does not exist. In this case, we just return. There is no php handler for unhandled operations. However, these unhandled operations will still be matched by the `operation` directive, and the buffer will be cleared after `handleOperation` returns.

<?php

namespace Tlf\Lexer\PhpNew;

trait StringDirectives {

    public $_string_directives = [
        'string'=>[
            'is'=>[
                ':string_single',
                ':string_double',
                ':heredoc',
            ],
        ],


        'string_backslash'=>[
            'start'=>[
                'match'=>'/\\\\.$/',
                'stop',
                'halt.all',
                'this:handleStringBackslash',
            ],
        ],

        'string_instructions'=>[
            'start'=>[
                'rewind 1',
                'buffer.clear',
                'forward 1',
                'then :string_backslash',
            ],
            'stop'=>[
                // 'ast.push word',
                // 'previous.set string',
                'this:handleString',
                'rewind 1',
                // 'buffer.clear',
                'directive.pop',
            ]
        ],

        'string_single'=>[
            'start'=>[
                'match'=>"/^'$/",
                'inherit :string_instructions.start',
                'then :string_single.stop'=>[
                    'start'=>[
                        'inherit :string_instructions.stop',
                    ]
                ],
            ],
            'stop'=>[
                'match'=>"'",
                'buffer.clear',
            ],
        ],

        'string_double'=>[
            'start'=>[
                'match'=>'/^"$/',
                'inherit :string_instructions.start',
                'then :string_double.stop'=>[
                    'start'=>[
                        'inherit :string_instructions.stop',
                    ]
                ],
            ],
            'stop'=>[
                'match'=>'"',
                'buffer.clear',
            ],
        ],


        'heredoc'=>[
            // also capturing nowdoc
            'start'=>[
                'match'=>'<<<',
                'then :heredoc_key'
            ],
            'stop'=>[
                'rewind 1',
                'stop',
            ],
        ],

        'heredoc_key'=>[
            'start'=>[
                'match'=>'/\'?([a-zA-Z\_0-9]+)\'?[^a-zA-Z0-9_]/',
                'rewind 1',
                'previous.set heredoc_key !'=>'_token:match 1',
            ],
            'stop'=>[
                'match !'=>'_lexer:previous heredoc_key',
                'previous.set string',
                'buffer.clear',
                'directive.pop',
                // 'print' => "\n\n\n---\n",
                // 'die !' => '_lexer:previous string',
            ]
        ],

    ];

}
<?php

namespace Tlf\Lexer\PhpNew;

use \Tlf\Lexer\Versions;

trait Words {

    public function unhandled_wd($lexer, $xpn, $ast, $word){

        if ($lexer->version >= Versions::_1){
            if ($lexer->signal == 'expect_var_name'){
                $ast->set('name', $word);
                $lexer->signal = 'expect_var_assign';
                return;
            }  else if ($lexer->signal == 'expect_var_name_in_assignment'){
                $ast->set('name', $word);
                $lexer->signal = 'expect_op_terminate';
                $lexer->popHead();
                // $xpn->push('declaration', $word);
                return;
            }
        }

        
        if ($ast->type=='property_name'||$ast->type=='arg_name'
            ||$ast->type=='var_name'
        ){
            // set variable/property name
            $ast->set('value', $word);
            $lexer->popHead();
        } 
        else if ($ast->type == 'method' && !isset($ast->name) 
            || $ast->type == 'function' && !isset($ast->name)){
            // set method/function name
            $ast->set('name', $word);
            $xpn->words = [];
            $xpn->last_word = null;
        } else if ($ast->type=='return_types'){
            // add a return type
            $ast->push('value', $word);
        }  else if ($ast->type == 'class' && !isset($ast->name)){
            // set class name
            $ast->set('name',$word);
            if (isset($ast->fqn))$ast->fqn .= $word;
            $xpn->words = [];
        } 
        // else if ($ast->type == 'class' && !isset($ast->name)){
        //     // set enum name
        //     $ast->set('name',$word);
        //     if (isset($ast->fqn))$ast->fqn .= $word;
        //     $xpn->words = [];
        // }
        else if ($ast->type=='class_extends'){
            // set the name of a class being extended??
            $ast->value = $word;
            $lexer->popHead();
        } else if ($ast->type == 'trait' && !isset($ast->name)){
            // set trait name
            $ast->set('name',$word);
            if (isset($ast->fqn))$ast->fqn .= $word;
            $xpn->words = [];
        } else if ($ast->type=='const_name'){
            // set const name
            $ast->value = $word;
            $lexer->popHead();
        }
    }

    public function wd_function($lexer, $xpn, $ast){
        if ($ast->type == 'class_body'){
            // its a method
            $method = new \Tlf\Lexer\Ast('method');
            $method->args = [];
            $this->docblock($method);
            $words = $xpn->words;
            array_pop($words); // remove 'function' 
            $method->modifiers = $words;
            $xpn->words = [];
            $lexer->setHead($method);
            // $ast->push('methods', $ast->get('type'));
            $ast->push('methods', $method);
        } else if (($ast->type=='file'||$ast->type=='namespace')
            &&( is_null($xpn->last_op)
                || $xpn->last_op == 'terminate'
                ||$xpn->last_op == 'block_end'
                ||$xpn->last_op == 'block_start'
            )

        ){

            $method = new \Tlf\Lexer\Ast('function');
            $method->args = [];
            $this->docblock($method);
            // $words = $xpn->words;
            // array_pop($words); // remove 'function'
            // $method->modifiers = $words;
            $xpn->words = [];
            $lexer->setHead($method);
            // $ast->push('methods', $ast->get('type'));
            $ast->push('functions', $method);



            // // var_dump($xpn->last_op);
            // // var_dump($xpn);
            // // exit;
            // // its a method
            // $function = new \Tlf\Lexer\Ast('function');
            // $function->args = [];
            // $this->docblock($function);
            // // $words = $xpn->words;
            // // array_pop($words); // remove 'function'
            // // $function->modifiers = $words;
            // $xpn->words = [];
            // $lexer->setHead($function);
            // // $ast->push('methods', $ast->get('type'));
            // $ast->push('functions', $function);
            // // $ast->set('body', new \Tlf\Lexer\StringAst('function_body'));
        }

    }
    
    public function wd_const($lexer,$xpn, $ast){
        if ($ast->type!='class_body')return;

        $const = new \Tlf\Lexer\Ast('const');
        $const->name = new \Tlf\Lexer\StringAst('const_name');
        $ast->push('const',$const);
        $lexer->setHead($const);
        $lexer->setHead($const->name);
        if (count($xpn->words)>1){
            $const->modifiers = array_slice($xpn->words,0,-1);
        }
        $xpn->words = [];

    }

    public function wd_namespace($lexer, $xpn, $ast){
        if ($ast->type!='file' && $ast->type != 'str'){
            $this->unhandled_wd($lexer, $xpn, $ast,$lexer->token->buffer());
            return;
        }

        $ns = new \Tlf\Lexer\Ast('namespace');
        $this->docblock($ns);
        $ast->set('namespace', $ns);
        $lexer->setHead($ns);
        $xpn->words = [];
    }

    public function wd_use($lexer, $xpn, $ast){



        if ($ast->type == 'function'){
            // echo "\n\n\n-----------\n\n";
            // var_dump($ast);
            // exit;
            $use_vars = new \Tlf\Lexer\Ast('use_vars');
            // $t
            $ast->push('use_vars', $use_vars);
            $lexer->setHead($use_vars);
            // $xpn->words = [];

        }

        // use_trait
        if ($ast->type=='file' || $ast->type == 'str' || $ast->type == 'namespace'){
            $trait = new \Tlf\Lexer\Ast('use_trait');
            $this->docblock($trait);
            $ast->push('traits', $trait);
            $lexer->setHead($trait);
            $xpn->words = [];
            return;
        }

    }

    // public function wd_enum($lexer,$xpn, $ast){
        // if ($ast->type!='file'&&$ast->type!='namespace')return;
        // $good_op =( is_null($xpn->last_op)
                // || $xpn->last_op == 'terminate'
                // ||$xpn->last_op == 'block_end'
                // ||$xpn->last_op == 'block_start');
        // if (!$good_op)return;
//
//
        // $enum = new \Tlf\Lexer\Ast('enum');
        // $this->docblock($enum);
//
        // if (count($xpn->words)>1){
            // $enum->modifiers = array_slice($xpn->words,0,-1);
        // }
        // if ($ast->type=='namespace'&&$ast->name!=''){
            // $enum->namespace = $ast->name;
            // $enum->fqn = $ast->name.'\\';
        // } else {
            // $enum->fqn = '';
            // $enum->namespace = '';
        // }
        // $xpn->words = [];
        // $lexer->setHead($enum);
        // $ast->add('enum', $enum);
    // }

    public function wd_class($lexer, $xpn, $ast){
        if ($ast->type!='file'&&$ast->type!='namespace')return;
        // var_dump($xpn);
        // exit;

        $good_op =( is_null($xpn->last_op)
                || $xpn->last_op == 'terminate'
                ||$xpn->last_op == 'block_end'
                ||$xpn->last_op == 'block_start');
        if (!$good_op)return;

        $class = new \Tlf\Lexer\Ast('class');
        $this->docblock($class);
        // echo 'zeep';
        // exit;

        if (count($xpn->words)>1){
            $class->modifiers = array_slice($xpn->words,0,-1);
        }
        if ($ast->type=='namespace'&&$ast->name!=''){
            $class->namespace = $ast->name;
            $class->fqn = $ast->name.'\\';
        } else {
            $class->fqn = '';
            $class->namespace = '';
        }
        $xpn->words = [];
        $lexer->setHead($class);
        $ast->add('class', $class);
    }

    public function wd_trait($lexer, $xpn, $ast){
        if ($ast->type!='file'&&$ast->type!='namespace')return;

        $trait = new \Tlf\Lexer\Ast('trait');
        $this->docblock($trait);

        if ($ast->type=='namespace'&&$ast->name!=''){
            $trait->fqn = $ast->name.'\\';
            $trait->namespace = $ast->name;
        } else {
            $trait->fqn = '';
            $trait->namespace = '';
        }
        $xpn->words = [];
        $lexer->setHead($trait);
        $ast->add('trait', $trait);

    }

    public function wd_extends($lexer, $xpn, $ast){
        if ($ast->type!='class')return;

        $extends = new \Tlf\Lexer\StringAst('class_extends');
        $ast->set('extends', $extends);
        $lexer->setHead($extends);
    }

}

<?php

namespace Tlf\Lexer;

class Token {

    /** the source string */
    public $source;

    protected $remainder = false;
    protected $buffer = false;
    /** start position in source. First time next() is called, index becomes 0*/
    public $index = -1;
    protected $len = 0;

    protected $prevToken;
    protected $matches =[];
    protected $match;

    /**
     * The line number currently being processed. 
     * Ticks up WHEN next() adds a \n, so line number will be increased while \n at top of buffer.
     * Ticks down WHEN rewind() is called, for EACH \n in the rewound chars.
     */
    public int $line_number = 0;

    public function __construct($source){
        $this->source = $source;
        $this->remainder = $source;
        $this->len = strlen($source);
    
    }

    public function buffer(){
        return $this->buffer;
    }
    public function remainder(){
        return $this->remainder;
    }
    /**
     *
     * Set a new buffer. May corrupt the token, but remainder is unchanged.
     *
     * @todo update the token when the buffer is changed. (such as prevToken? index?)
     * @param $newBuffer the full text of the buffer
     */
    public function setBuffer($newBuffer){
        $buffer = $this->buffer;
        $this->buffer = $newBuffer;
        return $buffer;
    }
    public function append($str){
        $this->remainder .= $str;
        $this->len += strlen($str);
    }
    /**
     * @alias for `setBuffer('')`
     */
    public function clearBuffer(){
        return $this->setBuffer('');
    }

    public function next(){
        $this->index++;
        $next = substr($this->remainder,0,1);
        if ($next=="\n")$this->line_number++;
        $this->remainder = substr($this->remainder,1);
        $this->buffer .= $next;

        if ($this->index==$this->len)return false;
        

        return $this;
    }

    /**
     * Remove $amount characters from the buffer & prepend them to $remainder.
     * @warning Its technically not a rewind, since you could change the buffer, then rewind() And have a different set of $remaining characters
     */
    public function rewind(int $amount){
        $chars = substr($this->buffer, -$amount);

        $num_newlines = count(explode("\n", $chars)) - 1;
        // echo "\n\nREWIND\n\n";
        $this->line_number -= $num_newlines;

        $this->buffer = substr($this->buffer, 0, -$amount);
        $this->index = $this->index - $amount;
        $this->remainder = $chars . $this->remainder;
    }

    /**
     * Move the pointer forward by `$amount` chars by repeatedly calling `$this->next()`
     */
    public function forward(int $amount){
        $i=0;
        while ($i++ < $amount)$this->next();
    }

    /**
     *
     * @return array or string or null
     */
    public function match($index=false){
        $ret = $index===false ? $this->match : $this->match[$index]??null;
        // echo "\n\n";
        // var_dump($ret);
        // echo "\n\n";
        // exit;
        return $ret;
    }
    public function setMatch($match){
        $prevMatch = $match;
        $this->match = $match;
        return $prevMatch;
    }

}
<?php

namespace Tlf\Lexer;

/**
 *
 * This is an incomplete grammar, mainly used for testing & building v0.5 of the lexer. It gets "quoted values" and nested arrays.
 *
 */
class JsonGrammar extends Grammar {

    public function getNamespace(){return 'json';}
    public function getAstClass():string{
        return \Tlf\Lexer\JsonAst::class;
    }

    public function onLexerStart($lexer,$file,$token){
        // $lexer->stackDirectiveList('phpgrammar:html', 'phpgrammar:php_open');
        // $lexer->setDirective([$this->getDirective('html')]);
        $directiveList = $this->getDirectives(':file');
        foreach ($directiveList as $d){
            $lexer->addDirective($d);
        }

    }

    public function appendValueToAst($lexer, $ast, $token){
        $ast->add('value', $token->buffer());
    }

    public $directives = [

        'file'=>[
            // it automatically starts
            // and immediately rewinds one
            // so each of its 'then's can see the first character
            'onStart'=>[
                'rewind'=>1,
                'then'=>[
                    ':object',
                    ':array',
                    ':whitespace',
                ],
            ],
        ],
        // @todo I need to apply php_close to almost everything...
    
        'object' => [
            'start'=>'{',
            'onStart'=>[
                'buffer.clear'=>true,
                'ast.new'=>[
                    '_setto'=>'root',
                    'type'=>'object',
                ],
            ],
            'stop'=>'}',
            'onStop'=>
            [
                'pop_head'=>true,
                'pop_directive'=>true,
                'buffer.clear'=>true,
            ],

            'then'=>[
                ':key'=>[],
                ':whitespace'=>[],
            ]
        ],

        'array' => [ 
            'start'=>'[',
            'onStart'=>[
                'buffer.clear'=>true,
                //ast.head =>[ // to say new & set as head?
                'ast.new'=>[
                    '_setto'=> 'root',
                    //automatically sets as head?
                    'type'=>"array",
                ],
                'then'=>[
                    //':array.stop', // it would add a duplicate?
                    ':array'=>[
                        'onStart'=>[
                            'buffer.clear'=>true,
                            //ast.head =>[ // to say new & set as head?
                            'ast.new'=>[
                                '_addto'=>'value',
                                //automatically sets as head?
                                'type'=>"array",
                            ],
                        ],
                        'onStop'=>[
                            'pop_head'=>true,
                            'buffer.clear'=>true,
                            'pop_directive'=>false,
                            'then'=>[
                                ':whitespace',
                                ':comma',
                                ':array.stop'=>[
                                    'onStart'=>[
                                        'pop_directive'=>true,
                                        'pop_head'=>false,
                                        // 'rewind'=>1,
                                        // 'badbubble'=>true,
                                    ]
                                ],
                            ]
                        ],
                    ],
                    ':whitespace',
                    ':value'=>[
                        'onStop'=>[
                            'rewind'=>1,
                            'this:appendValueToAst',
                            'forward'=>1,
                            'buffer.clear'=>true,
                            // 'pop_directive'=>true,

                            'then'=>[
                                ':whitespace',
                                ':comma'=>[
                                    // 'onStart'=>[
                                        // 'then'=>[
                                            // ''
                                        // ],
                                    // ]
                                ],
                                ':array.stop'=>[
                                    'onStart'=>[
                                        'pop_head'=>false,
                                        'pop_directive'=>true,
                                        'rewind'=>1,
                                        // 'bubble'=>true,
                                    ]
                                ],
                            ],

                        ],
                    ],
                    ':array.stop'=>[
                        'onStart'=>[
                            'pop_head'=>false,
                            'pop_directive'=>true,
                            'rewind'=>1,
                            // 'bubble'=>true,
                        ]
                    ],
                ],
            ],
            'stop'=>']',
            'onStop'=>[
                'pop_head'=>true,
                'pop_directive'=>true,
                'buffer.clear'=>true,
            ],

        ],


        'key'=>[
            // I think it takes other chars too... need to look up
            // 'start' => '/(\'|\")/',
            'start' => ["'", '"'],
                'onStart'=>[
                    'buffer.clear',
                ],
            'match'=>'/^$1([a-zA-Z0-9_\-]+)/',
            'stop'=>'/$1$/',
            'onStop'=>[
                // 'call'=> 'keyFound',
                //this could set the whole match stored to previous
                //So, like... whatever onStop would have had access to gets stored as previous('key')???
                'previous'=>'key',
                'pop_directive'=>true,
            ],

            'then'=>[
                ':whitespace',
                ':colon'=>[
                ],
            ]
        ],

        'value'=>[
            'is'=>[
                // ':bool_value',
                // ':numeric_value',
                ':str_value',
            ],
        ],

        // 'bool_value'=>[

        // ],
        // 'numeric_value'=>[

        // ],
        'str_value'=>[
            'start' => [
                    "'",
                    '"',
                ],
            'onStart'=>[
                'buffer.clear',
            ],
            // 'match'=>'/((?<!\\\\)[^$1])+/',
            // fill with the 1st match
            'match'=>[['/((?<!\\\\)[^' ,1, '])+/']],
            // fill with the 1st match
            'stop'=>[['/[^\\\\]',1,'$/']],
            'onStop'=>[
                // this will have to either save it to the object with the previous key
                // or append it to an array
                // I suppose previous(key) will be null if we're inside an array
                // 'call'=> 'store_value',
                'buffer.clear'=>true,
                // 'pop_directive'=>true,

                //because its only after the stop
                'then'=>[
                    ':comma'=>[
                    ],
                    ':whitespace',
                ]
            ],
        ],

        'comma'=>[
            'start'=>',',
            'onStart'=>[
                'buffer.clear'=>true,
                // 'stop'=>true,
                //pop this directive stack?
                'pop_directive'=>true,
            ],
        ],

        'colon'=>[
            'match'=> ':',
            'then'=> [
                ':whitespace'=> [

                ],
                ':value'=>[
                    'then'=>[
                        ':comma'=>[
                            'then'=>[
                                ':key',
                                ':object.stop'=>[
                                    'bubble'=>true,
                                ],
                            ]
                        ],

                    ],
                ],
            ],
        ],
        'whitespace'=>[
            // serves as start.
            // Since there's no 'stop', not matching will trigger onStop
            // is i dotall?
            'match'=>'/^\s+$/i',
            'onStop'=>[
                'buffer.clear'=>true,
            ],
        ],
    ];

}
<?php

namespace Tlf\Lexer;

/**
 * @warning This likely works flawlessly, due to its not using many features, but I haven't tested it since doing some minor redesigns & improvements to the lexer
 */
class OldBashGrammar extends Grammar {


    protected $regexes = [

        'docblockStart'=>[
            'regex'=>'/(##.*)/',
            'state'=>[null, 'comment'],
        ],
        'docblockEnd'=>[
            'regex'=>'/(^\s*[^\#])/m',
            'state'=>['docblock'],
        ],
        'function'=>[
            'regex'=>'/(?:function\s+)?([a-zA-Z\_0-9]*)(?:(?:\s*\(\))|\s+)\{/',
            'state'=>[null],
        ],
        'comment'=>[
            'regex'=> '/#[^#]/',
            'state'=>[null],
        ],
        'commentEnd'=>[
            'regex'=> '/#[^\n]*\n/m',
            'state'=>['comment'],
        ]
    ];

    public function onLexerStart($lexer,$file,$token){
        // $file->set('namespace','');
    }

    public function onComment($lexer, $fileAst, $token){
        // echo "LEX COMMENT\n";
        // echo "PreState: ".$lexer->getState()."\n";
        $lexer->setState('comment');
        // echo "State: ".$lexer->getState()."\n";
        // echo "Comment Start: ".$token->buffer();
        // echo "\n";
    }
    public function onCommentEnd($lexer, $fileAst, $token){
        // echo "LEX COMMENT END\n";
        if ($lexer->getState()!='comment')return;
        // echo "PreState: ".$lexer->getState()."\n";
        $token->clearBuffer();
        $lexer->popState();

        // echo "State: ".$lexer->getState()."\n";
        // echo "Comment End: ".$token->match(0);
        // echo "\n";
    }


    public function onDocblockStart($lexer, $ast, $token){
        if ($lexer->getState()=='comment')$lexer->popState();
        $token->clearBuffer();
        $token->setBuffer($token->match(1));
        $lexer->setState('docblock');
    }
    public function onDocblockEnd($lexer, $ast, $token){
        $block = $token->buffer();
        $remLen = strlen($token->match(0));
        $block = substr($block,0,-$remLen);
        $block = preg_replace('/^\s*#+/m','',$block);
        $block = \Tlf\Scrawl\Utility::trimTextBlock($block);

            $docLex = new \Tlf\Lexer();
            $docLex->addGrammar(new \Tlf\Lexer\DocBlockGrammar());

            $docAst = new \Tlf\Lexer\Ast('docblock');
            $docAst->set('src', $block);
            $docLex->setHead($docAst);

            $docAst = $docLex->lexAst($docAst, $block);

        $lexer->setPrevious('docblock', $docAst);
        $ast->add('childDocblock', $docAst);
        $token->setBuffer($token->match(0));
        $lexer->setState(null);
    }
    public function onFunction($lexer, $file, $token){

        // echo "State: ".$lexer->getState()."\n";
        // echo "Function: ".$token->match(0);
        // echo "\n";

        $class = new Ast('function');
        $class->set('name',$token->match(1));
        $class->set('docblock', $lexer->unsetPrevious('docblock'));
        $file->add('function',$class);


        $token->clearBuffer();
    }
}
<?php

namespace Tlf\Lexer\Test;

class Tester extends \Tlf\Tester {

    /**
     * you pass an array like this to runDirectiveTest($grammars, $thingies)
     *
     */
    protected $sample_thingies = [

        // name of test => 
        'Values.CloseArgList'=>[
            // starting ast
            'ast.type'=>'var_assign',
            // starting directive
            'start'=>['php_code'],
            // string to lexify
            'input'=>'"This")',
            // ast tree to expect
            'expect'=>[
                'value'=>'"This"',
                'declaration'=>'"This"',
            ],
        ],

        'Docblock.OneLine'=>[
            // starting directive
            'start'=>['/*'], 
            // string to lexify
            'input'=>"/* abc */",
            // check lexer->previous() for each key=>value()
            'expect.previous'=>[
                // `$lexer->previous('docblock') must == ['type'=>docblock,description=>abc]`
                "docblock"=> [
                    'type'=>'docblock',
                    'description'=>'abc',
                ],
            ],
        ],
    ];

    /**
     * See above sample
     *
     * @param $grammars an array of grammrs to run on the directives
     * @param $thingies an array of directive tests
     * 
     * @return an array of test results where key is test name & value is true/false for pass/fail
     */
    protected function runDirectiveTests($grammars, $thingies){
        $skipped = [];
        /** test descriptions that failed to pass*/
        $failures = [];
        $test_results = [];

        $success_count = 0;

        foreach ($thingies as $description=>$test){
            $startingAst = $test['ast']??null;
            if ($startingAst==null
                &&isset($test['ast.type'])
            ){
                $startingAst = ['type'=>$test['ast.type']];
            }
            $startingDirectives=$test['start'];
            if (!is_array($startingDirectives))$startingDirectives = [$startingDirectives];
            $inputString=$test['input']??file_get_contents($test['file']);

            // a sloppy way to add alternate expectations based upon 'previous'
            $expect=$test['expect'] ?? $test['expect.previous'];
            $compareTo = isset($test['expect']) ? 'tree' : 'previous';


            $run = $this->options['run']??null;
            if ($run===null||$run==$description
                || substr($run,-1)=='*' 
                    && substr($description, 0, (strlen($run) - 1) )
                        == substr($run,0,-1)
            ){
                $this->test($description);
                $lexer = new \Tlf\Lexer();
                if (isset($this->options['version'])){
                    $lexer->version = (float)$this->options['version'];
                } else {
                    $lexer->version = \Tlf\Lexer\Versions::_1;
                }
                if (isset($this->options['stop_loop'])){
                    $lexer->stop_loop = $this->options['stop_loop'];
                }
                foreach ($grammars as $g){
                    $lexer->addGrammar($g, null, false);
                }
                $lexer->addGrammar($grammars[0], 'this', false);

                if (isset($this->options['run']) && substr($run,-1)!='*')$lexer->debug = true;
                $tree = $this->parse($lexer, $inputString, $startingDirectives, $startingAst);

                if (($test['expect_failure']??false)===true){
                    $this->invert();
                    echo "\n  # This grammar feature isn't implemented yet";
                }


                if (isset($this->options['run']) && isset($this->options['print_full'])){
                    print_r($tree);
                    echo "\n\n\n";
                    exit;
                }

                // more of the sloppy way to add alternate expectations
                if ($compareTo=='tree'){
                    $succeeded = $this->compare($expect, $tree);
                    if (!$succeeded){
                        $failures[] = $description;
                    }
                } else if ($compareTo=='previous'){
                    foreach ($expect as $key=>$target){
                        $previous = $lexer->previous($key);
                        if ($previous instanceof \Tlf\Lexer\Ast){
                            $tree = $previous->getTree();
                        } else $tree = $previous;

                        $succeeded = $this->compare($target, $tree);
                        if (!$succeeded){
                            $failures[] = $description;
                        }
                        // $this->compare(var_export($target,true), var_export($tree, true));

                    }
                }


                if ($succeeded)$success_count++;

                if (($test['expect_failure']??false)===true){
                    $this->invert();
                }
                if (($test['is_bad_test']??false)!==false){
                    echo " \033[4;31m"."# BAD SUBTEST"."\033[0m\n";
                    echo '  '.$test['is_bad_test'];
                    echo "\n";
                    // echo "\n\n---------badd test -------------\n\n";
                }
                $test_results[$description] = $succeeded;
            } else {
                $skipped[] = $description;
            }
        }



        echo "\n\n";
        $skipCount = count($skipped);
        if ($skipCount>0){
            echo "$skipCount sub tests were skipped: ". implode(",  ", $skipped)."\n";
        }
        $failedCount = count($failures);
        if ($failedCount>0){
            echo "\n$failedCount sub tests failed: ". implode(",  ", $failures)."\n";
        }

        echo "\n";

        echo "\n$success_count subtests passed";

        echo "\n\n";
        
        echo "Specify `-run \"Test Description\"` to only run what you need";
        echo "\nSpecify `-print_full` print the full ast result when using `-run`";

        return $test_results;
    }

    /**
     * parse input and return an ast tree (without the ast type & the source)
     * @param $lexer a lexer instance
     * @param $toLex the text to lex
     * @param $startingDirectives an array of starting directives like `['php_code']`
     * @param $startingAst (optional) an array like `'type'=>'some_type'`
     */
    protected function parse(\Tlf\Lexer $lexer, string $toLex, array $startingDirectives, ?array $startingAst){
        foreach ($startingDirectives as $name){
            $parts = explode(':',$name);
            $namespace = count($parts)===2 ? $parts[0] : 'this';
            $grammar = $lexer->getGrammar($namespace);
            foreach ($grammar->getDirectives(':'.$name) as $directive){
                $lexer->addDirective($directive);
            }
        }
        
        if ($startingAst!=null){
            $startingAst = new \Tlf\Lexer\Ast($startingAst['type'], $startingAst);
        }

        $ast = $lexer->lex($toLex,$startingAst);

        $tree = $ast->getTree();
        unset($tree['type'], $tree['src']);

        return $tree;
    }
}

#!/usr/bin/env bash


function core(){
    run core help
}

function core_setup_new_project(){
    run core setup
}

function core_scrawl(){
    fPath="$cli_lib_dir/vendor/taeluf/code-scrawl/bin/scrawl"
    if [[ -f  "$fPath" ]];then
        $fPath
    else
        echo "Code Scrawl was not found at '$fPath', so you'll have to run it manually. Check out https://tluf.me/code-scrawl"
    fi
}

##
#
# @arg binDir the absolute path to the bindirectory that should be added to PATH in ~/.bashrc
function core_install(){
    ## just add the current library to the .bashrc

    step "Add '$1' to PATH via ~/.bashrc" bashrc_path_append "$1"
}

##
# @arg binDir an asbolute path to add to ~/.bashrc
#
function bashrc_path_append(){
    echo "export PATH=\"$1:\$PATH\"" >> ~/.bashrc
}

##
#
# Each step is optional
#
# - Move the cli library to ~/.vendor/bash-cli and symlink to it
# - Add `vendor/` to gitignore file
# - Write the 'run' script for the new project into its `bin` dir and append the project's bin dir to PATH in ~/.bashrc
# - Write the 'install' script for the new project into its root dir
# - Create the directory structure used for a library
# - Output sample group.bash files, internal files, and help files, along with alias functions being present
#
function core_setup(){
    pwd="$(pwd)"
    prompt_yes_or_no "Setup new bash cli project at '$pwd'?" || return

    step "Move cli library to ~/.vendor/bash-cli and symlink?" sys_install_and_symlink 

    step "Add 'vendor/' to .gitignore?" add_vendor_to_git_ignore 

    step "Write 'run' script?" write_run_script

    step "Create directory structure?" create_dir_structure
    step "Write Sample scripts?" write_sample_scripts

    step "Copy install script and instructions?" copy_install_files

    step_run
}

function sys_install_and_symlink(){
    mkdir -p ~/.vendor
    cur_path="$(realpath "$cli_lib_dir")"
    path="$(realpath ~/.vendor/bash-cli)"
    if [[ "$cur_path" == "$path" ]];then
        msg
        msg_notice "Cli library already in ~/.vendor"   
        msg
        return
    fi

    if [[ -d ~/.vendor/bash-cli/ ]];then
        if prompt_yes_or_no "Delete existing '$path' directory?" ;then
            rm -rf ~/.vendor/bash-cli 
            mv "$cur_path" ~/.vendor/bash-cli
        else
            rm -rf "$cur_path"
        fi
    else
        mv "$cur_path" ~/.vendor/bash-cli
    fi

    ln -s ~/.vendor/bash-cli "$cur_path"
}

function add_vendor_to_git_ignore(){
    echo "vendor/" >> "$pwd/.gitignore"
}

function write_run_script(){
    scriptName=""
    while [[ -z "$scriptName" ]];do
        prompt "Name of your script? ${cInstruct}(q-quit)" scriptName
        if [[ "$scriptName" == "q" ]];then
            msg_status "quit"
        fi
    done

    mkdir -p "$pwd/bin"
    if [[ -f "$pwd/bin/$scriptName" ]];then
        mv "$pwd/bin/$scriptName" "$pwd/bin/$scriptName.$(uniqid).bak"
    fi
    cp "$cli_lib_dir/setup/bin/run" "$pwd/bin/$scriptName"
    msg "$pwd/bin/$scriptName" written

    if prompt_yes_or_no "Add '$pwd/bin' to PATH via ~/.bashrc?";then
        echo "export PATH=\"$pwd/bin:\$PATH\"" >> ~/.bashrc
    fi
}

function create_dir_structure(){
    mkdir -p "$pwd/code/core"
    mkdir -p "$pwd/code/lib"
    mkdir -p "$pwd/code/help"
}

function copy_install_files(){
    cp "$cli_lib_dir/setup/Install.src.md" "$pwd/Install.src.md"
    cp "$cli_lib_dir/setup/install" "$pwd/install"

    msg_instruct "See '$pwd/Install.src.md' for end-user install instructions"

}

function write_sample_scripts(){
    files=(core/core.bash lib/example.bash "help/core.bash")
    for f in "${files[@]}"; do
        path="$pwd/code/$f"
        if [[ ! -f "$path" ]];then
            cp "$cli_lib_dir/setup/$f" "$path"
        fi
    done
}
#!/usr/bin/env bash

function pre_comment(){
    echo "nothing"
}

# comment one

function post_comment(){
    echo "nothing"
}




##
# Description
# @arg $1 a path
function echo_path(){
    echo "Path:$path";
}




##
# Description
# @arg $1 a path
function echo_path(){
    # comment 1
    echo "Path:$1";
}

# comment 2

function echo_string(){
    # comment 3
    echo "String:$1";
}

<?php

namespace Tlf\Lexer\Test;


class BashGrammar extends \Taeluf\Tester {

    public function testABash5(){
        echo "\nThere is no passing condition for this test. It just prints.\n\n";
        $file = dirname(__DIR__).'/extra/Sample5.bash';
        $lexer = new \Tlf\Lexer();
        $lexer->addGrammar(new \Tlf\Lexer\BashGrammar());
        $ast = $lexer->lex($file);
        unset($ast->source);
        $tree = $ast->getTree();
        print_r($tree);
        // exit;
        //
        return false;
    }

    public function testABash4(){
        echo "\nThere is no passing condition for this test. It just prints.\n\n";
        $file = dirname(__DIR__).'/extra/Sample4.bash';
        $lexer = new \Tlf\Lexer();
        $lexer->addGrammar(new \Tlf\Lexer\BashGrammar());
        $ast = $lexer->lex($file);
        unset($ast->source);
        $tree = $ast->getTree();
        print_r($tree);
        // exit;
        //
        return false;
    }

    public function testABash3(){
        echo "\nThere is no passing condition for this test. It just prints.\n\n";
        $file = dirname(__DIR__).'/extra/Sample3.bash';
        $lexer = new \Tlf\Lexer();
        $lexer->addGrammar(new \Tlf\Lexer\BashGrammar());
        $ast = $lexer->lex($file);
        unset($ast->source);
        $tree = $ast->getTree();
        print_r($tree);
        // exit;
        //
        return false;
    }

    public function testABash2(){
        echo "\nThere is no passing condition for this test. It just prints.\n\n";
        $file = dirname(__DIR__).'/extra/Sample2.bash';
        $lexer = new \Tlf\Lexer();
        $lexer->addGrammar(new \Tlf\Lexer\BashGrammar());
        $ast = $lexer->lex($file);
        unset($ast->source);
        $tree = $ast->getTree();
        print_r($tree);
        // exit;
        //
        return false;
    }

    public function testABash(){
        echo "\nThere is no passing condition for this test. It just prints.\n\n";
        $file = dirname(__DIR__).'/extra/Sample.bash';
        $lexer = new \Tlf\Lexer();
        $lexer->addGrammar(new \Tlf\Lexer\BashGrammar());
        $ast = $lexer->lex($file);
        unset($ast->source);
        $tree = $ast->getTree();
        print_r($tree);
        // exit;
        //
        return false;
    }

}
<?php

namespace Tlf\Lexer\Test;

/**
 * Super cleanly written tests for use in Documentation
 */
class Documentation extends \Taeluf\Tester {




    /**
     *
     */
    public function testParsingJson(){
        //@export_start(ParsingJson)
        $json = '["Cool",["yes","please"],"okay"]';
        $lexer = new \Tlf\Lexer();
        // $lexer->debug = true;
        // $lexer->useCache = false; // useCache only matters when lexing a file
        $lexer->addGrammar($jsonGrammar = new \Tlf\Lexer\JsonGrammar());

        //this is the root ast
        $ast = new \Tlf\Lexer\JsonAst("json"); //"json" is the type
        $ast->source = $json; //Not required, but I like keeping source in the ast root.
        $ast = $lexer->lexAst($ast, $json);

        // $tree = $ast->getTree(); // not what we normally want with json
        $data = $ast->getJsonData(); // custom method on the JsonAst class
        //@export_end(ParsingJson)


        $this->compare(json_decode($json), $data);
    }

}
<?php

namespace Tlf\Lexer\Test;

class JsonGrammar extends \Taeluf\Tester {

    public function testJsonNestedArray(){

        $data = [
            'value',
            ['yes', 'please'],
            "okay",
        ];
        $json = json_encode($data);
        // $json = json_encode($data).",\"okay\"]";

        echo "the json:\n";
        echo $json;
        echo "\nend the json:\n";

        $lexer = new \Tlf\Lexer();
        $lexer->debug = true;
        $lexer->useCache = false;
        $lexer->addGrammar($jsonGrammar = new \Tlf\Lexer\JsonGrammar());

        $ast = new \Tlf\Lexer\JsonAst("json");
        $ast->source = $json;

        
        echo "\n\n----Begin Lexing!\n\n";

        $ast = $lexer->lexAst($ast, $json);

        echo "\n\n----Lexing done!\n\n";

        unset($ast->source);
        $tree = $ast->getTree();

        print_r($tree);

        echo "\n\n----Tree Printed!\n\n";

        echo "\nJson Output array:\n\n";

        $array = $ast->getJsonData();

        echo "\nJson Output array printed!\n\n";

        $this->compare($data, $array);
    }

    public function testJsonArray(){

        $data = [
            'value',
            // 3.07,
            // true,
            "okay",
        ];
        $json = json_encode($data);


        $lexer = new \Tlf\Lexer();
        $lexer->useCache = false;
        $lexer->debug = true;
        $lexer->addGrammar($jsonGrammar = new \Tlf\Lexer\JsonGrammar());

        $ast = new \Tlf\Lexer\JsonAst("json");
        $ast->source = $json;

        
        echo "\n\n----Begin Lexing!\n\n";

        $ast = $lexer->lexAst($ast, $json);

        echo "\n\n----Lexing done!\n\n";

        unset($ast->source);
        $tree = $ast->getTree();

        print_r($tree);

        echo "\n\n----Tree Printed!\n\n";

        echo "\nJson Output array:\n\n";

        $array = $ast->getJsonData();

        echo "\nJson Output array printed!\n\n";

        $this->compare(['value','okay'], $array);
    }
}
#!/usr/bin/env bash

import core/core-update
import core/core-unsorted
import core/core-revert
# import core/core-url

## 
# Get aliases for core_ functions
#
function core_aliases(){
    declare -n al="$1"
    al=()
    
    ## Aliases to other groups
    al+=(s:"switch")
    al+=(del:"delete")
    al+=(dep:"depend")
    # al+=(check:"check")

    ## Aliases to "extra"
    al+=(url:"extra url")
    al+=(check:"extra check")
    al+=(status:"extra check")
    al+=(ignore:"extra ignore")
}

function core_tip_check(){
    echo "Check the status of your project"
}

function core_tip(){
    echo "Core commands for git bent. Stuff you need all the time??"
}

function core(){
    # run core help
    do_fancy_help "core"
}

function core_tip_help(){
    echo "View all functions and extended help"
}
# function core_help(){
    # run help
    # return
#    # echo "CORE HELP"
    # do_fancy_help "core"
#
#
    # return
##    @export_start(Internal.prompt_choose_function)
    # prompt_choose_function \
        # "# bent [command]" \
            # "run help" "help" "View all functions and extended help" \
            # "run core save" "save" "Save & upload your project" \
            # "run core upload" "upload" "upload your project (doesn't save first)" \
            # "run core update" "update" "Download all changes" \
            # "'" \
            # "run core tag" "tag" "Create a numbered release of your project" \
            # "run core revert" "revert" "Rollback to a previous save of your project" \
            # "run core merge" "merge" "Merge current branch into another branch" \
            # "run core check" "check" "Check the status of your project" \
            # "run core url" "url" "Get special urls to git hosts" \
            # "run core ignore" "ignore" "Download a .gitignore file from Github's gitignore repo" \
        # \
    # ;
##    @export_end(Internal.prompt_choose_function)
# }

function core_tip_save(){
    echo "Save & upload your project"
}
##
# Save your project
# @shorthand s, commit
#
function core_save(){
    is_project_dir || return;

    commitMsg="${@}"

    files_with_conflicts conflictingFiles
    if [[ "${#conflictingFiles[@]}" -gt 0 ]]; then
        msg_notice "Merge Conflicts in:"
        # msg
        for cf in "${conflictingFiles[@]}";do
            msg "  ${cf#*/}"
        done
        msg
        prompt_yes_or_no "Continue?" || return;
    fi

    # @TODO Ask which changed files should be saved

    changes="$(str_trim "$(changed_files)")"

    if [[ "$changes" == "" ]]; then
        msg "No changes, nothing to save."
        prompt_yes_or_no "Nothing to save. Upload anyway?" na \
            || return;
        run core upload
        return;
    fi

    msg
    header "Current Status"
    msg_status "$(project_dir)"
    run extra check

    msg

    changes=""
    if [[ "$commitMsg" == "" ]];then
        prompt_or_quit "Commit Msg ${cOff}or blank" changes -e \
            || return;
    else
        changes="$commitMsg"
    fi

    if [[ "$changes" == "" ]]; then
        changes="[no commit msg given]"
    fi
    git add -A
    git commit -m "${changes}"

    # @TODO integrate configs into save, upload? prompt
    # if I had a 'config' feature, I'd do 'config save_upload_answer prompt_answer', which would load the config named 'save_upload_answer' and store it in 'prompt_answer'
    # which would stop this prompt from happening
    # Possibly offer "yes, no, always, never" as options & save always/never to config
    # & `config "core save" "save_upload_answer" prompt_answer`
        # enables `bent config core save` to directly edit those config values
    prompt_yes_or_no "Upload?" \
        || return;
    run core upload
}

function core_tip_upload(){
    echo "Upload your project (without saving first)"
}
function core_upload(){
    is_project_dir || return;
    # @TODO only provide -u origin cur_branch when remote is not set, to avoid the message:
        # "Branch 'test-git-operations' set up to track remote branch 'test-git-operations' from 'origin'."

    run extra check 

    git push -u origin "$(cur_branch)" 

    run extra check 
}

function core_tip_tag(){
    echo "Tag your project to make a packaged release"
}
function core_tag(){
    is_project_dir || return;

    curBranch=$(project_dir)

    changed_files_array changedFiles
    if [[ "${#changedFiles[@]}" -gt 0 ]];then
        msg_notice "There are ${#changedFiles[@]} files with uncommitted changes"
    fi

    msg_header "Branch to tag"
    prompt_choose_branch branch || return

    prompt_or_quit "Tag name/version number (ex: 1.0.0)" release \
        || return;

    prompt_or_quit "Describe this tag/version: " description \
        || return

    git tag -a "$release" -m "$description" "$branch"
    git push --tags
    # git push origin :$branch
}
#!/usr/bin/env bash


# function log_help(){
#
    # prompt_choose_function \
        # "# bent log [command] " \
        # "run log" "log" "Show previous saves" \
        # "run log diff" "diff" "Show previous saves along with changed files" \
    # ;
# }


##
# List commits
#
function log(){
    is_project_dir || return;
    # @TODO prompt and ask if they'd like to see file-level changes
    # @TODO Show instructions on navigating & exiting the output, then prompt (for [enter]) before continuing
    git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit

    msg_instruct "[bent log diff] to see more"
}

##
# List changes between commits
#
function log_diff(){
    is_project_dir || return;
    # @TODO merge into history(), via prompt...
    git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit -p
}
#!/usr/bin/env bash

function help(){

    sub="$1"
    if [[ -n "$sub" ]];then
        import "core/$sub"
        if is_function "${sub}_help" ;then
            msg_header "[bent help $sub]"
            run "$sub" "help"
            return;
        else
            msg_notice "No help menu for '${sub}'"
        fi
    fi

    msg_instruct "bent [command_group] [command]${cOff} - for 'core' group, just 'bent [command]'"
    msg_instruct "bent [command_group]${cOff} for help or ${cInstruct}bent [command_group] help${cOff}"

    prompt_choose_function \
        "# bent help [command]" \
            "run help jargon" "jargon" "Learn the jargon" \
            "run help cli" "cli" "Learn some cli basics" \
            \
        "# bent [command_group]" \
            "run help core" "core" "Core commands like save & upload. bent [command] instead of bent core [command]" \
            "run help new" "new" "Create a new project, version, or feature" \
            "run help switch" "switch" "Switch between versions, projects, or features" \
            "run help show" "show" "Show stuff" \
            "run help log" "log" "View commit history" \
            "run help delete" "delete" "Delete a project version" \
            "run help setup" "setup" "Setup Stuff" \
            "run help move" "move" "Move a project to a new host" \
            "run help ssh" "ssh" "Work with ssh keys" \
    ;
}

function help_jargon(){
    msg_header "This help under development"

    msg_ulist  \
        "git: A type of version control, that keeps track of changes to your code. Two others are mercurial and svn." \
        "repo, repository: A project directory that is stored in version control" \
        "branch: A version of your project." \
        "There's more, but that's all I'm doing for now" \
    ;
}

function help_cli(){
    msg_notice "General cli help has not yet been written"
    # @TODO write general cli help
}

function help_bent(){
    msg_notice "General help info about Git Bent has not been written yet"
    # @TODO write general help about Git Bent, like using q to quit prompts & how commands work & such. Maybe it could include contact info?
}
#!/usr/bin/env bash


ssh_keygen(){
    # is_project_dir || return;

    header "UNPOLISHED FEATURE"
    msg "  This feature is imperect, but it should work"

	# @TODO Add option for BitBucket, GitLab, Gitea
	# @TODO Improve language to use less jargon
	# @TODO Allow exiting with q/n/c 
	# @TODO report location of the key
	# @TODO allow naming the SSH key
	# @TODO add colors to the instructions
	# @TODO add instruction on how to load ssh keys

    # Setup SSH Key
    msg
    msg
    msg "An SSH key will securely sign you in without using your online password. \n    It saves you typing & is more secure.\n"
    prompt_yes_or_no "Configure an SSH key now? (y-yes/n-no)" \
        || return;

    #@TODO figure out why gitlab ssh key isn't working
    ssh_url=$(url ssh_key)

    cd ~/.ssh

    msg "\n1. Go to ${ssh_url}\n2. Click 'New SSH Key'\n3. Enter 'GitBent' for the title.\n4. Follow Prompts Below for the key.\n";
    
    msg_instruct "[ctrl-c] to exit this setup"
    prompt_or_quit "[enter] to continue" na -e \
        || return;

    sshFile="git_key_$RANDOM";

    msg "The SSH Key will be encrypted if you enter a password here. You SHOULD use a password. If you use a simple password, such as a PIN number, then it is very important that your computer is secure.\n"

    # read -sp "Enter encryption password (or leave blank): " sshPassword
    # echo ""
    # read -sp "Confirm encryption password: " sshPasswordConfirm
    # if [[ $sshPasswordConfirm != $sshPassword ]]; then
    #     echo "The passwords did not match. Run \`bent setup\` again."
    #     return;
    # fi
    msg ""
    msg "  --this might take a second or two--   "
    # if [[ $sshPassword == "" ]]; then
    #     echo "doing without password"
    #     keygen=$(echo "${sshFile}" | ssh-keygen -t rsa -b 4096 -C "git ${gitEmail}")
    # else 
    #     echo "Using password {$sshPassword}"
    #     command="ssh-keygen -t rsa -b 4096 -P \"${sshPassword}\" -f ${sshFile} -C \"git ${gitEmail}\"";
    #     echo $command;
    #     keygen=$command;
    # fi
    # ssh-keygen -t rsa -b 4096 -f ${sshFile} -C "git ${gitEmail}"
    ssh-keygen -t ed25519 -f "${sshFile}" -C "<comment>" -C "git ${gitEmail}"
    unset sshPassword;
    unset sshPassswordConfirm;
    
    msg ""
    msg "\n--Copy the public key file & put it online--"
    msg "  1. [enter] to print it here.\n  2. Highlight the long block of text\n  3. [ctrl+shift+c] to copy it (or right-click & copy)"
    msg "  4. Go back to the online SSH Key screen\n  5. Paste it into the 'key' field"
    msg ""
    prompt_or_quit "[enter] to continue" na -e \
        || return;
    msg ""
    msg ""
    pub="${sshFile}.pub"
    cat $pub;
    msg ""

    prompt_or_quit "[enter] to continue" na -e \
        || return;
    msg ""
    msg "  0. The long text above (including 'ssh-ed25519' and the comment at the end) should now be pasted into the 'Key' field online."
    msg "  1. Click 'Add SSH Key' online (skip for GitLab)."
    msg "  2. If you used an encryption password earlier, you will be prompted for it next."
    msg ""
    prompt_or_quit "[enter] to finish" na -e \
        || return;
    msg ""
    ssh-add ${sshFile}
    msg ""
    msg ""
    msg "Your git environment is setup now! Run \`bent help\` to get started managing your projects, their versions, and backups. "
    msg ""
    # echo $gitUser;
}


#!/usr/bin/env bash

cur_branch(){
    local branch;
    branch="$(git branch --show-current)";
    echo $branch;
}

is_cur_branch_behind(){
    curBranch="$(cur_branch)"
    git for-each-ref --format="%(refname:short) %(upstream:short)" refs/heads | \
    while read local remote
    do
        [ -z "$remote" ] && continue
        if [[ "$local" != "$curBranch" ]];then
            continue
        fi
        git rev-list --left-right ${local}...${remote} -- 2>/dev/null >/tmp/git_upstream_status_delta || continue
        # AHEAD=$(grep -c '^<' /tmp/git_upstream_status_delta)
        BEHIND=$(grep -c '^>' /tmp/git_upstream_status_delta)
        if [[ $BEHIND = 0 ]];then
            return 1;
        fi;
        return 0;
    done
}

cur_branch_behind_count(){
    local count;
    curBranch="$(cur_branch)"
    git for-each-ref --format="%(refname:short) %(upstream:short)" refs/heads | \
    while read local remote
    do
        [ -z "$remote" ] && continue
        if [[ "$local" != "$curBranch" ]];then
            continue
        fi
        git rev-list --left-right ${local}...${remote} -- 2>/dev/null >/tmp/git_upstream_status_delta || continue
        # AHEAD=$(grep -c '^<' /tmp/git_upstream_status_delta)
        count=$(grep -c '^>' /tmp/git_upstream_status_delta)
        echo "$count";
        return;
    done
}


branches_status(){

    # This was found on stackoverflow, but I lost the url. It will be modified
    # 
    # by http://github.com/jehiah
    # this prints out some branch status (similar to the '... ahead' info you get from git status)

    # example:
    # $ git branch-status
    # test (ahead 1) | (behind 112) origin/master
    # main (ahead 2) | (behind 0) origin/master
    # Method found on 

    # Another noteable resource is: https://stackoverflow.com/questions/17719829/check-if-local-git-repo-is-ahead-behind-remote

    curBranch="$(cur_branch)"
    git for-each-ref --format="%(refname:short) %(upstream:short)" refs/heads | \
    while read local remote
    do
        [ -z "$remote" ] && continue
        marker=""
        if [[ "$local" = "$curBranch" ]];then
            marker="*"
        fi
        git rev-list --left-right ${local}...${remote} -- 2>/dev/null >/tmp/git_upstream_status_delta || continue
        AHEAD=$(grep -c '^<' /tmp/git_upstream_status_delta)
        BEHIND=$(grep -c '^>' /tmp/git_upstream_status_delta)
        msg "${marker}${local}\n  - [ahead $AHEAD] [behind $BEHIND]"
        # on $remote"
    done
}

function branch_list_unique(){
    local -n output_branchList=${1};
    declare -A output_build_branchList
    output_branchList=()

    while read branch
    do
        isRemote=false
        branch="${branch#\'}"
        branch="${branch%\'}"
        name="${branch#refs/heads/}"
        if [[ "${name}" == "${branch}" ]];then
            name="${name#refs/remotes/origin/}"
            isRemote=true
        fi
        if [[ -z "${output_build_branchList["$name"]}" \
            && -z "${output_build_branchList["remote:$name"]}"  ]];then
            if $isRemote; then
                name="remote: ${name}"
            fi
            output_build_branchList["$name"]="$name"
            output_branchList+=("${name}")
        fi
    done <<< $(git for-each-ref --shell --format="%(refname)"  --sort='-authordate:iso8601' --sort='refname:rstrip=-2' )
    # ${@:1})

}
<?php

namespace CatsAre_Green76\Abc\SomethingOrAnother;

?>
class abc extends Baby {

    // function ohnothisishtml

}
<?php

/**
 * docblock for `class abc extends Baby`
 */
abstract   class   abc   extends   Baby   implements   Cats\AndY\Pajamas {


    static public $some_paramater = "abc yes!";

    private $somethingPrivate;

    static protected $complex_paramater_default_value = "I ; ?> am <?php doing { ' crazy stuff";

    const default_visibility_constant = FALSE;
    protected const protected_constant = FALSE;
    private const private_array_contstant = ['abc'];
    public const public_complex_constant = ['a;bc = ', 'something; else?>'];

    /**This is a single-line docblock for the class method*/
    // function firstcomment
    // {
    // }
    # This is a comment too! uses a hashtag
    static public function thisIsAMethod2 ($arg1 = ['ab"c','d"e\'f',"j'h\"k"]):array{
        // function commentalso
        // {
        // }


        /** 
         * Docblock for the named function declared inside the class method
         */
        function abc(){
            echo "cats";
        }
    }
    /**
     * " This isn't a string
     * ' This also isn't a string
     * interface def extends FunnyBusiness implements \Candy\Cats {
     * // this is part of a docblock
     * }
     *
     * @attribute1 some thing about it
     * @attrib2 Some different thing
     */

}
<?php

namespace Tlf\Lexer\Test;

/**
 *
 * This is not for actual parsing yet. This is for design work. The $directives array & 'php_open' and 'namespace' are design aspects I'm interested in implementing at some point... maybe
 *
 */
class PhpGrammar_16Jul21 extends Grammar {

    use Php\LanguageDirectives;
    use Php\ClassDirectives;
    use Php\ClassMemberDirectives;
    use Php\BodyDirectives;
    use Php\OtherDirectives;

    protected $directives;

    public $notin = [
        'keyword'=>[
            // 'match'=>'/this-regex-available on php.net keywords page/',
            '__halt_compiler', 'abstract', 'and', 'array', 'as', 'break', 'callable', 'case', 'catch', 'class', 'clone', 'const', 'continue', 'declare', 'default', 'die', 'do', 'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'eval', 'exit', 'extends', 'final', 'for', 'foreach', 'function', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'isset', 'list', 'namespace', 'new', 'or', 'print', 'private', 'protected', 'public', 'require', 'require_once', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'unset', 'use', 'var', 'while', 'xor'
        ],
    ];

    public function getNamespace(){return 'php';}

    public function buildDirectives(){
        $this->directives = array_merge(
            $this->_language_directives,
            $this->_body_directives,
            $this->_class_directives,
            $this->_class_member_directives,
            $this->_other_directives,
        );
    }

    public function onGrammarAdded($lexer){
        $this->buildDirectives();
        $lexer->addDirective($this->getDirectives(':php_open')['php_open']);
    }

    public function onLexerStart($lexer,$file,$token){
        $lexer->addGrammar(new DocblockGrammar());
        // $this->buildDirectives();
        // $lexer->addDirective($this->getDirectives(':html')[':html']);
        // $lexer->stackDirectiveList('phpgrammar:html', 'phpgrammar:php_open');
        // $lexer->setDirective([$this->getDirective('html')]);

        if ($file->type=='file'){
            $file->set('namespace', '');
        }
    }

    public function holdNamespaceName($lexer, $file, $token){
        $prev = $lexer->previous('namespace.name');
        if ($prev == null)$prev = [];
        $prev[] = $token->buffer();
        $lexer->setPrevious('namespace.name', $prev);
    }

    public function saveNamespace($lexer, $file, $token){
        $namespace = $lexer->previous('namespace.name');
        $namespace = implode('\\',$namespace);
        $file->set('namespace.docblock', $lexer->unsetPrevious('docblock'));
        $file->set('namespace', $namespace);
        $lexer->setPrevious('namespace.name', $namespace);
    }

    public function handleClassDeclaration($lexer, $class, $token){
        $class->set('declaration', $lexer->unsetPrevious('class.declaration'));
    }

    public function processDocBlock($lexer, $ast, $token){
        $lexer->setPrevious('docblock', $token->buffer());
    }
    public function captureUseTrait($lexer, $ast, $token){
        $ast->add('traits',$token->buffer());
    }
    public function processComment($lexer, $ast, $token){
        $comment = trim($token->buffer());
        $ast->add('comments', $comment);
        $lexer->previous('comment', $comment);
    }



    // public function end_docblock($lexer, $unknownAst, $token){
    //     $block = $token->buffer();
    //     $block = trim($block);
    //     $block = trim(substr($block,strlen('/**'),-1));
    //     $block = preg_replace('/^\s*\*+/m','',$block);
    //     $block = \Tlf\Scrawl\Utility::trimTextBlock($block);
    //     $block = trim($block);
    //     // if (substr($block,0,3)=='/**')$block = substr($block,3);
    //
    //         $docLex = new \Tlf\Lexer();
    //         $docLex->addGrammar(new \Tlf\Lexer\DocBlockGrammar());
    //
    //         $docAst = new \Tlf\Lexer\Ast('docblock');
    //         $docAst->set('src', $block);
    //         $docLex->setHead($docAst);
    //
    //         $docAst = $docLex->lexAst($docAst, $block);
    //
    //     $lexer->setPrevious('docblock', $docAst);
    //     $unknownAst->add('childDocblock', $docAst);
    //     $token->setBuffer($token->match(0));
    // }



    /**
     * Do nothing, apparently? I thought it was supposed to append to previous('whitespace'). Idunno
     */
    public function appendToWhitespace($lexer, $ast, $token, $directive){
        // $whitespace = $lexer->previous('whitespace') ?? '';
        // $lexer->setPrevious('whitespace', $whitespace.$directive->_matches[0]);
        // $lexer->setPrevious('whitespace', $whitespace.$token->buffer());
    }

    /**
     * Combine the stored modifier with the stored property declaration
     */
    public function setPropertyDeclaration($lexer, $ast, $token, $directive){
        $ast->set('declaration',
            $lexer->unsetPrevious('modifier')
            .$lexer->unsetPrevious('property.declaration')
        );
    }

    /**
     * 
     */
    public function storeMethodDefinition($lexer, $ast, $token, $directive){
        $ast->set('definition', 
            $lexer->unsetPrevious('modifier')
            .$lexer->unsetPrevious('method.definition')
        );
        $ast->set('arglist', $lexer->unsetPrevious('method.arglist') );
        $name = $lexer->unsetPrevious('method.name');
        $ast->set('name', $name);
        //remove the method name from the modifiers.
        $modifiers = $ast->get('modifiers');
        $ast->set('modifiers', substr($modifiers,0, -strlen($name)));
    }
}
<?php

return 
array (
  'type' => 'file',
  'ext' => 'php',
  'name' => 'PhpGrammar.16jul21',
  'path' => '/home/reed/.disk/Dev/php/Lexer/test/php/PhpGrammar.16jul21.php',
  'namespace' => 'Tlf\\Lexer\\Test',
  'namespace.docblock' => NULL,
  'class' => 
  array (
    0 => 
    array (
      'type' => 'class',
      'docblock' => 
      array (
        'type' => 'docblock',
        'description' => 'This is not for actual parsing yet. This is for design work. The $directives array & \'php_open\' and \'namespace\' are design aspects I\'m interested in implementing at some point... maybe',
      ),
      'namespace' => 'Tlf\\Lexer\\Test',
      'declaration' => 'class PhpGrammar_16Jul21 extends Grammar ',
      'name' => 'PhpGrammar_16Jul21',
      'traits' => 
      array (
        0 => 'Php\\LanguageDirectives',
        1 => 'Php\\ClassDirectives',
        2 => 'Php\\ClassMemberDirectives',
        3 => 'Php\\BodyDirectives',
        4 => 'Php\\OtherDirectives',
      ),
      'properties' => 
      array (
        0 => 
        array (
          'type' => 'property',
          'modifiers' => 'protected ',
          'docblock' => NULL,
          'name' => 'directives',
          'declaration' => 'protected $directives;',
        ),
        1 => 
        array (
          'type' => 'property',
          'modifiers' => 'public ',
          'docblock' => NULL,
          'name' => 'notin',
          'comments' => 
          array (
            0 => '\'match\'=>\'/this-regex-available on php.net keywords page/\',',
          ),
          'declaration' => 'public $notin = [
        \'keyword\'=>[
             \'match\'=>\'/this-regex-available on php.net keywords page/\',            \'__halt_compiler\', \'abstract\', \'and\', \'array\', \'as\', \'break\', \'callable\', \'case\', \'catch\', \'class\', \'clone\', \'const\', \'continue\', \'declare\', \'default\', \'die\', \'do\', \'echo\', \'else\', \'elseif\', \'empty\', \'enddeclare\', \'endfor\', \'endforeach\', \'endif\', \'endswitch\', \'endwhile\', \'eval\', \'exit\', \'extends\', \'final\', \'for\', \'foreach\', \'function\', \'global\', \'goto\', \'if\', \'implements\', \'include\', \'include_once\', \'instanceof\', \'insteadof\', \'interface\', \'isset\', \'list\', \'namespace\', \'new\', \'or\', \'print\', \'private\', \'protected\', \'public\', \'require\', \'require_once\', \'return\', \'static\', \'switch\', \'throw\', \'trait\', \'try\', \'unset\', \'use\', \'var\', \'while\', \'xor\'
        ],
    ];',
        ),
      ),
      'methods' => 
      array (
        0 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'getNamespace',
          'definition' => 'public function getNamespace()',
          'arglist' => '',
        ),
        1 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'buildDirectives',
          'definition' => 'public function buildDirectives()',
          'arglist' => '',
        ),
        2 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'onGrammarAdded',
          'definition' => 'public function onGrammarAdded($lexer)',
          'arglist' => '$lexer',
        ),
        3 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'onLexerStart',
          'definition' => 'public function onLexerStart($lexer,$file,$token)',
          'arglist' => '$lexer,$file,$token',
          'comments' => 
          array (
            0 => '$this->buildDirectives();',
            1 => '$lexer->addDirective($this->getDirectives(\':html\')[\':html\']);',
            2 => '$lexer->stackDirectiveList(\'phpgrammar:html\', \'phpgrammar:php_open\');',
            3 => '$lexer->setDirective([$this->getDirective(\'html\')]);',
          ),
        ),
        4 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'holdNamespaceName',
          'definition' => 'public function holdNamespaceName($lexer, $file, $token)',
          'arglist' => '$lexer, $file, $token',
        ),
        5 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'saveNamespace',
          'definition' => 'public function saveNamespace($lexer, $file, $token)',
          'arglist' => '$lexer, $file, $token',
        ),
        6 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'handleClassDeclaration',
          'definition' => 'public function handleClassDeclaration($lexer, $class, $token)',
          'arglist' => '$lexer, $class, $token',
        ),
        7 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'processDocBlock',
          'definition' => 'public function processDocBlock($lexer, $ast, $token)',
          'arglist' => '$lexer, $ast, $token',
        ),
        8 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'captureUseTrait',
          'definition' => 'public function captureUseTrait($lexer, $ast, $token)',
          'arglist' => '$lexer, $ast, $token',
        ),
        9 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'processComment',
          'definition' => 'public function processComment($lexer, $ast, $token)',
          'arglist' => '$lexer, $ast, $token',
        ),
        10 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'Do nothing, apparently? I thought it was supposed to append to previous(\'whitespace\'). Idunno',
          ),
          'name' => 'appendToWhitespace',
          'definition' => 'public function appendToWhitespace($lexer, $ast, $token, $directive)',
          'arglist' => '$lexer, $ast, $token, $directive',
          'comments' => 
          array (
            0 => '$whitespace = $lexer->previous(\'whitespace\') ?? \'\';',
            1 => '$lexer->setPrevious(\'whitespace\', $whitespace.$directive->_matches[0]);',
            2 => '$lexer->setPrevious(\'whitespace\', $whitespace.$token->buffer());',
          ),
        ),
        11 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'Combine the stored modifier with the stored property declaration',
          ),
          'name' => 'setPropertyDeclaration',
          'definition' => 'public function setPropertyDeclaration($lexer, $ast, $token, $directive)',
          'arglist' => '$lexer, $ast, $token, $directive',
        ),
        12 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => '',
          ),
          'name' => 'storeMethodDefinition',
          'definition' => 'public function storeMethodDefinition($lexer, $ast, $token, $directive)',
          'arglist' => '$lexer, $ast, $token, $directive',
          'comments' => 
          array (
            0 => 'remove the method name from the modifiers.',
          ),
        ),
      ),
      'comments' => 
      array (
        0 => 'public function end_docblock($lexer, $unknownAst, $token){',
        1 => '$block = $token->buffer();',
        2 => '$block = trim($block);',
        3 => '$block = trim(substr($block,strlen(\'/**\'),-1));',
        4 => '$block = preg_replace(\'/^\\s*\\*+/m\',\'\',$block);',
        5 => '$block = \\Tlf\\Scrawl\\Utility::trimTextBlock($block);',
        6 => '$block = trim($block);',
        7 => '// if (substr($block,0,3)==\'/**\')$block = substr($block,3);',
        8 => '',
        9 => '$docLex = new \\Tlf\\Lexer();',
        10 => '$docLex->addGrammar(new \\Tlf\\Lexer\\DocBlockGrammar());',
        11 => '',
        12 => '$docAst = new \\Tlf\\Lexer\\Ast(\'docblock\');',
        13 => '$docAst->set(\'src\', $block);',
        14 => '$docLex->setHead($docAst);',
        15 => '',
        16 => '$docAst = $docLex->lexAst($docAst, $block);',
        17 => '',
        18 => '$lexer->setPrevious(\'docblock\', $docAst);',
        19 => '$unknownAst->add(\'childDocblock\', $docAst);',
        20 => '$token->setBuffer($token->match(0));',
        21 => '}',
      ),
    ),
  ),
)
;
array (
  'type' => 'file',
  'ext' => 'php',
  'name' => 'PhpGrammar.16jul21',
  'path' => '/home/reed/.disk/Dev/php/Lexer/test/php/PhpGrammar.16jul21.php',
  'namespace' => 'Tlf\\Lexer\\Test',
  'namespace.docblock' => NULL,
  'class' => 
  array (
    0 => 
    array (
      'type' => 'class',
      'docblock' => 
      array (
        'type' => 'docblock',
        'description' => 'This is not for actual parsing yet. This is for design work. The $directives array & \'php_open\' and \'namespace\' are design aspects I\'m interested in implementing at some point... maybe',
      ),
      'namespace' => 'Tlf\\Lexer\\Test',
      'declaration' => 'class PhpGrammar_16Jul21 extends Grammar ',
      'name' => 'PhpGrammar_16Jul21',
      'traits' => 
      array (
        0 => 'Php\\LanguageDirectives',
        1 => 'Php\\ClassDirectives',
        2 => 'Php\\ClassMemberDirectives',
        3 => 'Php\\BodyDirectives',
        4 => 'Php\\OtherDirectives',
      ),
      'properties' => 
      array (
        0 => 
        array (
          'type' => 'property',
          'modifiers' => 'protected ',
          'docblock' => NULL,
          'name' => 'directives',
          'declaration' => 'protected $directives;',
        ),
        1 => 
        array (
          'type' => 'property',
          'modifiers' => 'public ',
          'docblock' => NULL,
          'name' => 'notin',
          'comments' => 
          array (
            0 => '\'match\'=>\'/this-regex-available on php.net keywords page/\',',
          ),
          'declaration' => 'public $notin = [
        \'keyword\'=>[
             \'match\'=>\'/this-regex-available on php.net keywords page/\',            \'__halt_compiler\', \'abstract\', \'and\', \'array\', \'as\', \'break\', \'callable\', \'case\', \'catch\', \'class\', \'clone\', \'const\', \'continue\', \'declare\', \'default\', \'die\', \'do\', \'echo\', \'else\', \'elseif\', \'empty\', \'enddeclare\', \'endfor\', \'endforeach\', \'endif\', \'endswitch\', \'endwhile\', \'eval\', \'exit\', \'extends\', \'final\', \'for\', \'foreach\', \'function\', \'global\', \'goto\', \'if\', \'implements\', \'include\', \'include_once\', \'instanceof\', \'insteadof\', \'interface\', \'isset\', \'list\', \'namespace\', \'new\', \'or\', \'print\', \'private\', \'protected\', \'public\', \'require\', \'require_once\', \'return\', \'static\', \'switch\', \'throw\', \'trait\', \'try\', \'unset\', \'use\', \'var\', \'while\', \'xor\'
        ],
    ];',
        ),
      ),
      'methods' => 
      array (
        0 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'getNamespace',
          'definition' => 'public function getNamespace()',
          'arglist' => '',
        ),
        1 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'buildDirectives',
          'definition' => 'public function buildDirectives()',
          'arglist' => '',
        ),
        2 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'onGrammarAdded',
          'definition' => 'public function onGrammarAdded($lexer)',
          'arglist' => '$lexer',
        ),
        3 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'onLexerStart',
          'definition' => 'public function onLexerStart($lexer,$file,$token)',
          'arglist' => '$lexer,$file,$token',
          'comments' => 
          array (
            0 => '$this->buildDirectives();',
            1 => '$lexer->addDirective($this->getDirectives(\':html\')[\':html\']);',
            2 => '$lexer->stackDirectiveList(\'phpgrammar:html\', \'phpgrammar:php_open\');',
            3 => '$lexer->setDirective([$this->getDirective(\'html\')]);',
          ),
        ),
        4 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'holdNamespaceName',
          'definition' => 'public function holdNamespaceName($lexer, $file, $token)',
          'arglist' => '$lexer, $file, $token',
        ),
        5 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'saveNamespace',
          'definition' => 'public function saveNamespace($lexer, $file, $token)',
          'arglist' => '$lexer, $file, $token',
        ),
        6 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'handleClassDeclaration',
          'definition' => 'public function handleClassDeclaration($lexer, $class, $token)',
          'arglist' => '$lexer, $class, $token',
        ),
        7 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'processDocBlock',
          'definition' => 'public function processDocBlock($lexer, $ast, $token)',
          'arglist' => '$lexer, $ast, $token',
        ),
        8 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'captureUseTrait',
          'definition' => 'public function captureUseTrait($lexer, $ast, $token)',
          'arglist' => '$lexer, $ast, $token',
        ),
        9 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'processComment',
          'definition' => 'public function processComment($lexer, $ast, $token)',
          'arglist' => '$lexer, $ast, $token',
        ),
        10 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'Do nothing, apparently? I thought it was supposed to append to previous(\'whitespace\'). Idunno',
          ),
          'name' => 'appendToWhitespace',
          'definition' => 'public function appendToWhitespace($lexer, $ast, $token, $directive)',
          'arglist' => '$lexer, $ast, $token, $directive',
          'comments' => 
          array (
            0 => '$whitespace = $lexer->previous(\'whitespace\') ?? \'\';',
            1 => '$lexer->setPrevious(\'whitespace\', $whitespace.$directive->_matches[0]);',
            2 => '$lexer->setPrevious(\'whitespace\', $whitespace.$token->buffer());',
          ),
        ),
        11 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'Combine the stored modifier with the stored property declaration',
          ),
          'name' => 'setPropertyDeclaration',
          'definition' => 'public function setPropertyDeclaration($lexer, $ast, $token, $directive)',
          'arglist' => '$lexer, $ast, $token, $directive',
        ),
        12 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => '',
          ),
          'name' => 'storeMethodDefinition',
          'definition' => 'public function storeMethodDefinition($lexer, $ast, $token, $directive)',
          'arglist' => '$lexer, $ast, $token, $directive',
          'comments' => 
          array (
            0 => 'remove the method name from the modifiers.',
          ),
        ),
      ),
      'comments' => 
      array (
        0 => 'public function end_docblock($lexer, $unknownAst, $token){',
        1 => '$block = $token->buffer();',
        2 => '$block = trim($block);',
        3 => '$block = trim(substr($block,strlen(\'/**\'),-1));',
        4 => '$block = preg_replace(\'/^\\s*\\*+/m\',\'\',$block);',
        5 => '$block = \\Tlf\\Scrawl\\Utility::trimTextBlock($block);',
        6 => '$block = trim($block);',
        7 => '// if (substr($block,0,3)==\'/**\')$block = substr($block,3);',
        8 => '',
        9 => '$docLex = new \\Tlf\\Lexer();',
        10 => '$docLex->addGrammar(new \\Tlf\\Lexer\\DocBlockGrammar());',
        11 => '',
        12 => '$docAst = new \\Tlf\\Lexer\\Ast(\'docblock\');',
        13 => '$docAst->set(\'src\', $block);',
        14 => '$docLex->setHead($docAst);',
        15 => '',
        16 => '$docAst = $docLex->lexAst($docAst, $block);',
        17 => '',
        18 => '$lexer->setPrevious(\'docblock\', $docAst);',
        19 => '$unknownAst->add(\'childDocblock\', $docAst);',
        20 => '$token->setBuffer($token->match(0));',
        21 => '}',
      ),
    ),
  ),
)<?php

namespace Cats\Whatever;

/**
 * This is the best class anyone has ever written.
 */
class Sample extends cats {

    use Some\Demons;

    // First comment 
    # Second Comment

    /**
     * Why would you name a giraffe Bob?
     */
    protected $giraffe = "Bob";
    private $cat = "Jeff";
    static public $dog = "PandaBearDog";

    /**
     * dogs
     *
     * @return dogs
     */
    public function dogs($a= "abc"){
        echo "yep yep";
    }


    public const Doygle = "Hoygle Floygl";

}
array (
  'type' => 'file',
  'ext' => 'php',
  'name' => 'SampleClass',
  'path' => '/home/reed/.disk/Dev/php/Lexer/test/php-new/SampleClass.php',
  'namespace' => 'Cats\\Whatever',
  'namespace.docblock' => NULL,
  'class' => 
  array (
    0 => 
    array (
      'type' => 'class',
      'docblock' => 
      array (
        'type' => 'docblock',
        'description' => 'This is the best class anyone has ever written.',
      ),
      'namespace' => 'Cats\\Whatever',
      'declaration' => 'class Sample extends cats ',
      'name' => 'Sample',
      'traits' => 
      array (
        0 => 'Some\\Demons',
      ),
      'comments' => 
      array (
        0 => 'First comment',
        1 => 'Second Comment',
      ),
      'properties' => 
      array (
        0 => 
        array (
          'type' => 'property',
          'modifiers' => 'protected ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'Why would you name a giraffe Bob?',
          ),
          'name' => 'giraffe',
          'declaration' => 'protected $giraffe = "Bob";',
        ),
        1 => 
        array (
          'type' => 'property',
          'modifiers' => 'private ',
          'docblock' => NULL,
          'name' => 'cat',
          'declaration' => 'private $cat = "Jeff";',
        ),
        2 => 
        array (
          'type' => 'property',
          'modifiers' => 'static public ',
          'docblock' => NULL,
          'name' => 'dog',
          'declaration' => 'static public $dog = "PandaBearDog";',
        ),
      ),
      'methods' => 
      array (
        0 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'dogs
',
            'attribute' => 
            array (
              0 => 
              array (
                'type' => 'attribute',
                'name' => 'return',
                'description' => 'dogs',
              ),
            ),
          ),
          'name' => 'dogs',
          'definition' => 'public function dogs($a= "abc")',
          'arglist' => '$a= "abc"',
        ),
      ),
      'consts' => 
      array (
        0 => 
        array (
          'type' => 'const',
          'docblock' => NULL,
          'definition' => 'const Doygle = "Hoygle Floygl";',
          'modifiers' => 'public ',
          'name' => 'Doygle',
        ),
      ),
    ),
  ),
)array (
  'type' => 'file',
  'ext' => 'php',
  'name' => 'SampleClass',
  'path' => '/home/reed/data/owner/Reed/projects/php/Lexer/test/php-new/SampleClass.php',
  'namespace' => 
  array (
    'type' => 'namespace',
    'name' => 'Cats\\Whatever',
    'declaration' => 'namespace Cats\\Whatever;',
    'class' => 
    array (
      0 => 
      array (
        'type' => 'class',
        'namespace' => 'Cats\\Whatever',
        'fqn' => 'Cats\\Whatever\\Sample',
        'name' => 'Sample',
        'extends' => 'cats',
        'declaration' => 'class Sample extends cats',
        'traits' => 
        array (
          0 => 
          array (
            'type' => 'use_trait',
            'name' => 'Some\\Demons',
            'declaration' => 'use Some\\Demons;',
          ),
        ),
        'comments' => 
        array (
          0 => 'First comment',
          1 => 'Second Comment',
        ),
        'properties' => 
        array (
          0 => 
          array (
            'type' => 'property',
            'modifiers' => 
            array (
              0 => 'protected',
            ),
            'docblock' => 
            array (
              'type' => 'docblock',
              'description' => 'Why would you name a giraffe Bob?',
            ),
            'name' => 'giraffe',
            'value' => '"Bob"',
            'declaration' => 'protected $giraffe = "Bob";',
          ),
          1 => 
          array (
            'type' => 'property',
            'modifiers' => 
            array (
              0 => 'private',
            ),
            'name' => 'cat',
            'value' => '"Jeff"',
            'declaration' => 'private $cat = "Jeff";',
          ),
          2 => 
          array (
            'type' => 'property',
            'modifiers' => 
            array (
              0 => 'static',
              1 => 'public',
            ),
            'name' => 'dog',
            'value' => '"PandaBearDog"',
            'declaration' => 'static public $dog = "PandaBearDog";',
          ),
        ),
        'methods' => 
        array (
          0 => 
          array (
            'type' => 'method',
            'args' => 
            array (
              0 => 
              array (
                'type' => 'arg',
                'name' => 'a',
                'value' => '"abc"',
                'declaration' => '$a= "abc"',
              ),
            ),
            'docblock' => 
            array (
              'type' => 'docblock',
              'description' => 'dogs
',
              'attribute' => 
              array (
                0 => 
                array (
                  'type' => 'attribute',
                  'name' => 'return',
                  'description' => 'dogs',
                ),
              ),
            ),
            'modifiers' => 
            array (
              0 => 'public',
            ),
            'name' => 'dogs',
            'body' => 
            array (
            ),
            'declaration' => 'public function dogs($a= "abc")',
          ),
        ),
        'const' => 
        array (
          0 => 
          array (
            'type' => 'const',
            'name' => 'Doygle',
            'modifiers' => 
            array (
              0 => 'public',
            ),
            'value' => '"Hoygle Floygl"',
            'declaration' => 'public const Doygle = "Hoygle Floygl";',
          ),
        ),
      ),
    ),
  ),
)<?php

namespace Tlf\Lexer\Test;

/** An extremely simple grammar that builds sets of arglist from `(arg1,arg2,c) (list2_arg1,arg2)` */
class StarterGrammar_16Jul21 extends Grammar {

    // use Starter\LanguageDirectives;
    use Starter\OtherDirectives;

    /** The actual array of directives, built during onGrammarAdded() */
    protected $directives;

    /** Defaults to 'startergrammar' */
    public function getNamespace(){return 'starter';}

    /** Combine the directives from traits */
    public function buildDirectives(){
        $this->directives = array_merge(
            // $this->_language_directives,
            $this->_other_directives,
        );
    }

    public function onGrammarAdded(\Tlf\Lexer $lexer){
        $this->buildDirectives();
        /** The first directive(s) to listen for. We're looking for an opening `(` */
        $lexer->addDirective($this->getDirectives(':parenthesis')['parenthesis']);
        // you can add more directives
    }

    public function onLexerStart(\Tlf\Lexer $lexer,\Tlf\Lexer\Ast $ast,\Tlf\Lexer\Token $token){
        // $lexer->addGrammar(new DocblockGrammar()); //if your language uses docblocks

        /** Just an example of setting an empty namespace at the start, so that all files have a namespace, even if its empty. */
        if ($ast->type=='file'){
            $ast->set('namespace', '');
        }
    }

    /** A method this grammar uses as an instruction to trim() the buffer */
    public function trimBuffer(\Tlf\Lexer $lexer, \Tlf\Lexer\Ast $ast, \Tlf\Lexer\Token $token, \stdClass $directive, array $args){
        $token->setBuffer(trim($token->buffer()));
    }
}
<?php

return 
array (
  'type' => 'file',
  'ext' => 'php',
  'name' => 'StarterGrammar.16jul21',
  'path' => '/home/reed/.disk/Dev/php/Lexer/test/php/StarterGrammar.16jul21.php',
  'namespace' => 'Tlf\\Lexer\\Test',
  'namespace.docblock' => NULL,
  'class' => 
  array (
    0 => 
    array (
      'type' => 'class',
      'docblock' => 
      array (
        'type' => 'docblock',
        'description' => 'An extremely simple grammar that builds sets of arglist from `(arg1,arg2,c) (list2_arg1,arg2)`',
      ),
      'namespace' => 'Tlf\\Lexer\\Test',
      'declaration' => 'class StarterGrammar_16Jul21 extends Grammar ',
      'name' => 'StarterGrammar_16Jul21',
      'comments' => 
      array (
        0 => 'use Starter\\LanguageDirectives;',
      ),
      'traits' => 
      array (
        0 => 'Starter\\OtherDirectives',
      ),
      'properties' => 
      array (
        0 => 
        array (
          'type' => 'property',
          'modifiers' => 'protected ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'The actual array of directives, built during onGrammarAdded()',
          ),
          'name' => 'directives',
          'declaration' => 'protected $directives;',
        ),
      ),
      'methods' => 
      array (
        0 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'Defaults to \'startergrammar\'',
          ),
          'name' => 'getNamespace',
          'definition' => 'public function getNamespace()',
          'arglist' => '',
        ),
        1 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'Combine the directives from traits',
          ),
          'name' => 'buildDirectives',
          'definition' => 'public function buildDirectives()',
          'arglist' => '',
          'comments' => 
          array (
            0 => '$this->_language_directives,',
          ),
        ),
        2 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'onGrammarAdded',
          'definition' => 'public function onGrammarAdded(\\Tlf\\Lexer $lexer)',
          'arglist' => '\\Tlf\\Lexer $lexer',
          'comments' => 
          array (
            0 => 'you can add more directives',
          ),
        ),
        3 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'onLexerStart',
          'definition' => 'public function onLexerStart(\\Tlf\\Lexer $lexer,\\Tlf\\Lexer\\Ast $ast,\\Tlf\\Lexer\\Token $token)',
          'arglist' => '\\Tlf\\Lexer $lexer,\\Tlf\\Lexer\\Ast $ast,\\Tlf\\Lexer\\Token $token',
          'comments' => 
          array (
            0 => '$lexer->addGrammar(new DocblockGrammar()); //if your language uses docblocks',
          ),
        ),
        4 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'A method this grammar uses as an instruction to trim() the buffer',
          ),
          'name' => 'trimBuffer',
          'definition' => 'public function trimBuffer(\\Tlf\\Lexer $lexer, \\Tlf\\Lexer\\Ast $ast, \\Tlf\\Lexer\\Token $token, \\stdClass $directive, array $args)',
          'arglist' => '\\Tlf\\Lexer $lexer, \\Tlf\\Lexer\\Ast $ast, \\Tlf\\Lexer\\Token $token, \\stdClass $directive, array $args',
        ),
      ),
    ),
  ),
)
;
array (
  'type' => 'file',
  'ext' => 'php',
  'name' => 'StarterGrammar.16jul21',
  'path' => '/home/reed/.disk/Dev/php/Lexer/test/php/StarterGrammar.16jul21.php',
  'namespace' => 'Tlf\\Lexer\\Test',
  'namespace.docblock' => NULL,
  'class' => 
  array (
    0 => 
    array (
      'type' => 'class',
      'docblock' => 
      array (
        'type' => 'docblock',
        'description' => 'An extremely simple grammar that builds sets of arglist from `(arg1,arg2,c) (list2_arg1,arg2)`',
      ),
      'namespace' => 'Tlf\\Lexer\\Test',
      'declaration' => 'class StarterGrammar_16Jul21 extends Grammar ',
      'name' => 'StarterGrammar_16Jul21',
      'comments' => 
      array (
        0 => 'use Starter\\LanguageDirectives;',
      ),
      'traits' => 
      array (
        0 => 'Starter\\OtherDirectives',
      ),
      'properties' => 
      array (
        0 => 
        array (
          'type' => 'property',
          'modifiers' => 'protected ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'The actual array of directives, built during onGrammarAdded()',
          ),
          'name' => 'directives',
          'declaration' => 'protected $directives;',
        ),
      ),
      'methods' => 
      array (
        0 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'Defaults to \'startergrammar\'',
          ),
          'name' => 'getNamespace',
          'definition' => 'public function getNamespace()',
          'arglist' => '',
        ),
        1 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'Combine the directives from traits',
          ),
          'name' => 'buildDirectives',
          'definition' => 'public function buildDirectives()',
          'arglist' => '',
          'comments' => 
          array (
            0 => '$this->_language_directives,',
          ),
        ),
        2 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'onGrammarAdded',
          'definition' => 'public function onGrammarAdded(\\Tlf\\Lexer $lexer)',
          'arglist' => '\\Tlf\\Lexer $lexer',
          'comments' => 
          array (
            0 => 'you can add more directives',
          ),
        ),
        3 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'onLexerStart',
          'definition' => 'public function onLexerStart(\\Tlf\\Lexer $lexer,\\Tlf\\Lexer\\Ast $ast,\\Tlf\\Lexer\\Token $token)',
          'arglist' => '\\Tlf\\Lexer $lexer,\\Tlf\\Lexer\\Ast $ast,\\Tlf\\Lexer\\Token $token',
          'comments' => 
          array (
            0 => '$lexer->addGrammar(new DocblockGrammar()); //if your language uses docblocks',
          ),
        ),
        4 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'A method this grammar uses as an instruction to trim() the buffer',
          ),
          'name' => 'trimBuffer',
          'definition' => 'public function trimBuffer(\\Tlf\\Lexer $lexer, \\Tlf\\Lexer\\Ast $ast, \\Tlf\\Lexer\\Token $token, \\stdClass $directive, array $args)',
          'arglist' => '\\Tlf\\Lexer $lexer, \\Tlf\\Lexer\\Ast $ast, \\Tlf\\Lexer\\Token $token, \\stdClass $directive, array $args',
        ),
      ),
    ),
  ),
)<?php

namespace CatsAre_Green76\Abc\SomethingOrAnother;

?>
class abc extends Baby {

    // function ohnothisishtml

}
<?php

/**
 * docblock for `class abc extends Baby`
 */
abstract   class   abc   extends   Baby   implements   Cats\AndY\Pajamas {


    static public $some_paramater = "abc yes!";

    private $somethingPrivate;

    static protected $complex_paramater_default_value = "I ; ?> am <?php doing { ' crazy stuff";

    const default_visibility_constant = FALSE;
    protected const protected_constant = FALSE;
    private const private_array_contstant = ['abc'];
    public const public_complex_constant = ['a;bc = ', 'something; else?>'];

    /**This is a single-line docblock for the class method*/
    // function firstcomment
    // {
    // }
    # This is a comment too! uses a hashtag
    static public function thisIsAMethod2 ($arg1 = ['ab"c','d"e\'f',"j'h\"k"]):array{
        // function commentalso
        // {
        // }


        /** 
         * Docblock for the named function declared inside the class method
         */
        function abc(){
            echo "cats";
        }
    }
    /**
     * " This isn't a string
     * ' This also isn't a string
     * interface def extends FunnyBusiness implements \Candy\Cats {
     * // this is part of a docblock
     * }
     *
     * @attribute1 some thing about it
     * @attrib2 Some different thing
     */

}
<?php

namespace Tlf\Lexer\Test;

/**
 *
 * This is not for actual parsing yet. This is for design work. The $directives array & 'php_open' and 'namespace' are design aspects I'm interested in implementing at some point... maybe
 *
 */
class PhpGrammar_16Jul21 extends Grammar {

    use Php\LanguageDirectives;
    use Php\ClassDirectives;
    use Php\ClassMemberDirectives;
    use Php\BodyDirectives;
    use Php\OtherDirectives;

    protected $directives;

    public $notin = [
        'keyword'=>[
            // 'match'=>'/this-regex-available on php.net keywords page/',
            '__halt_compiler', 'abstract', 'and', 'array', 'as', 'break', 'callable', 'case', 'catch', 'class', 'clone', 'const', 'continue', 'declare', 'default', 'die', 'do', 'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor', 'endforeach', 'endif', 'endswitch', 'endwhile', 'eval', 'exit', 'extends', 'final', 'for', 'foreach', 'function', 'global', 'goto', 'if', 'implements', 'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'isset', 'list', 'namespace', 'new', 'or', 'print', 'private', 'protected', 'public', 'require', 'require_once', 'return', 'static', 'switch', 'throw', 'trait', 'try', 'unset', 'use', 'var', 'while', 'xor'
        ],
    ];

    public function getNamespace(){return 'php';}

    public function buildDirectives(){
        $this->directives = array_merge(
            $this->_language_directives,
            $this->_body_directives,
            $this->_class_directives,
            $this->_class_member_directives,
            $this->_other_directives,
        );
    }

    public function onGrammarAdded($lexer){
        $this->buildDirectives();
        $lexer->addDirective($this->getDirectives(':php_open')['php_open']);
    }

    public function onLexerStart($lexer,$file,$token){
        $lexer->addGrammar(new DocblockGrammar());
        // $this->buildDirectives();
        // $lexer->addDirective($this->getDirectives(':html')[':html']);
        // $lexer->stackDirectiveList('phpgrammar:html', 'phpgrammar:php_open');
        // $lexer->setDirective([$this->getDirective('html')]);

        if ($file->type=='file'){
            $file->set('namespace', '');
        }
    }

    public function holdNamespaceName($lexer, $file, $token){
        $prev = $lexer->previous('namespace.name');
        if ($prev == null)$prev = [];
        $prev[] = $token->buffer();
        $lexer->setPrevious('namespace.name', $prev);
    }

    public function saveNamespace($lexer, $file, $token){
        $namespace = $lexer->previous('namespace.name');
        $namespace = implode('\\',$namespace);
        $file->set('namespace.docblock', $lexer->unsetPrevious('docblock'));
        $file->set('namespace', $namespace);
        $lexer->setPrevious('namespace.name', $namespace);
    }

    public function handleClassDeclaration($lexer, $class, $token){
        $class->set('declaration', $lexer->unsetPrevious('class.declaration'));
    }

    public function processDocBlock($lexer, $ast, $token){
        $lexer->setPrevious('docblock', $token->buffer());
    }
    public function captureUseTrait($lexer, $ast, $token){
        $ast->add('traits',$token->buffer());
    }
    public function processComment($lexer, $ast, $token){
        $comment = trim($token->buffer());
        $ast->add('comments', $comment);
        $lexer->previous('comment', $comment);
    }



    // public function end_docblock($lexer, $unknownAst, $token){
    //     $block = $token->buffer();
    //     $block = trim($block);
    //     $block = trim(substr($block,strlen('/**'),-1));
    //     $block = preg_replace('/^\s*\*+/m','',$block);
    //     $block = \Tlf\Scrawl\Utility::trimTextBlock($block);
    //     $block = trim($block);
    //     // if (substr($block,0,3)=='/**')$block = substr($block,3);
    //
    //         $docLex = new \Tlf\Lexer();
    //         $docLex->addGrammar(new \Tlf\Lexer\DocBlockGrammar());
    //
    //         $docAst = new \Tlf\Lexer\Ast('docblock');
    //         $docAst->set('src', $block);
    //         $docLex->setHead($docAst);
    //
    //         $docAst = $docLex->lexAst($docAst, $block);
    //
    //     $lexer->setPrevious('docblock', $docAst);
    //     $unknownAst->add('childDocblock', $docAst);
    //     $token->setBuffer($token->match(0));
    // }



    /**
     * Do nothing, apparently? I thought it was supposed to append to previous('whitespace'). Idunno
     */
    public function appendToWhitespace($lexer, $ast, $token, $directive){
        // $whitespace = $lexer->previous('whitespace') ?? '';
        // $lexer->setPrevious('whitespace', $whitespace.$directive->_matches[0]);
        // $lexer->setPrevious('whitespace', $whitespace.$token->buffer());
    }

    /**
     * Combine the stored modifier with the stored property declaration
     */
    public function setPropertyDeclaration($lexer, $ast, $token, $directive){
        $ast->set('declaration',
            $lexer->unsetPrevious('modifier')
            .$lexer->unsetPrevious('property.declaration')
        );
    }

    /**
     * 
     */
    public function storeMethodDefinition($lexer, $ast, $token, $directive){
        $ast->set('definition', 
            $lexer->unsetPrevious('modifier')
            .$lexer->unsetPrevious('method.definition')
        );
        $ast->set('arglist', $lexer->unsetPrevious('method.arglist') );
        $name = $lexer->unsetPrevious('method.name');
        $ast->set('name', $name);
        //remove the method name from the modifiers.
        $modifiers = $ast->get('modifiers');
        $ast->set('modifiers', substr($modifiers,0, -strlen($name)));
    }
}
<?php

return 
array (
  'type' => 'file',
  'ext' => 'php',
  'name' => 'PhpGrammar.16jul21',
  'path' => '/home/reed/.disk/Dev/php/Lexer/test/php/PhpGrammar.16jul21.php',
  'namespace' => 'Tlf\\Lexer\\Test',
  'namespace.docblock' => NULL,
  'class' => 
  array (
    0 => 
    array (
      'type' => 'class',
      'docblock' => 
      array (
        'type' => 'docblock',
        'description' => 'This is not for actual parsing yet. This is for design work. The $directives array & \'php_open\' and \'namespace\' are design aspects I\'m interested in implementing at some point... maybe',
      ),
      'namespace' => 'Tlf\\Lexer\\Test',
      'declaration' => 'class PhpGrammar_16Jul21 extends Grammar ',
      'name' => 'PhpGrammar_16Jul21',
      'traits' => 
      array (
        0 => 'Php\\LanguageDirectives',
        1 => 'Php\\ClassDirectives',
        2 => 'Php\\ClassMemberDirectives',
        3 => 'Php\\BodyDirectives',
        4 => 'Php\\OtherDirectives',
      ),
      'properties' => 
      array (
        0 => 
        array (
          'type' => 'property',
          'modifiers' => 'protected ',
          'docblock' => NULL,
          'name' => 'directives',
          'declaration' => 'protected $directives;',
        ),
        1 => 
        array (
          'type' => 'property',
          'modifiers' => 'public ',
          'docblock' => NULL,
          'name' => 'notin',
          'comments' => 
          array (
            0 => '\'match\'=>\'/this-regex-available on php.net keywords page/\',',
          ),
          'declaration' => 'public $notin = [
        \'keyword\'=>[
             \'match\'=>\'/this-regex-available on php.net keywords page/\',            \'__halt_compiler\', \'abstract\', \'and\', \'array\', \'as\', \'break\', \'callable\', \'case\', \'catch\', \'class\', \'clone\', \'const\', \'continue\', \'declare\', \'default\', \'die\', \'do\', \'echo\', \'else\', \'elseif\', \'empty\', \'enddeclare\', \'endfor\', \'endforeach\', \'endif\', \'endswitch\', \'endwhile\', \'eval\', \'exit\', \'extends\', \'final\', \'for\', \'foreach\', \'function\', \'global\', \'goto\', \'if\', \'implements\', \'include\', \'include_once\', \'instanceof\', \'insteadof\', \'interface\', \'isset\', \'list\', \'namespace\', \'new\', \'or\', \'print\', \'private\', \'protected\', \'public\', \'require\', \'require_once\', \'return\', \'static\', \'switch\', \'throw\', \'trait\', \'try\', \'unset\', \'use\', \'var\', \'while\', \'xor\'
        ],
    ];',
        ),
      ),
      'methods' => 
      array (
        0 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'getNamespace',
          'definition' => 'public function getNamespace()',
          'arglist' => '',
        ),
        1 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'buildDirectives',
          'definition' => 'public function buildDirectives()',
          'arglist' => '',
        ),
        2 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'onGrammarAdded',
          'definition' => 'public function onGrammarAdded($lexer)',
          'arglist' => '$lexer',
        ),
        3 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'onLexerStart',
          'definition' => 'public function onLexerStart($lexer,$file,$token)',
          'arglist' => '$lexer,$file,$token',
          'comments' => 
          array (
            0 => '$this->buildDirectives();',
            1 => '$lexer->addDirective($this->getDirectives(\':html\')[\':html\']);',
            2 => '$lexer->stackDirectiveList(\'phpgrammar:html\', \'phpgrammar:php_open\');',
            3 => '$lexer->setDirective([$this->getDirective(\'html\')]);',
          ),
        ),
        4 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'holdNamespaceName',
          'definition' => 'public function holdNamespaceName($lexer, $file, $token)',
          'arglist' => '$lexer, $file, $token',
        ),
        5 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'saveNamespace',
          'definition' => 'public function saveNamespace($lexer, $file, $token)',
          'arglist' => '$lexer, $file, $token',
        ),
        6 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'handleClassDeclaration',
          'definition' => 'public function handleClassDeclaration($lexer, $class, $token)',
          'arglist' => '$lexer, $class, $token',
        ),
        7 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'processDocBlock',
          'definition' => 'public function processDocBlock($lexer, $ast, $token)',
          'arglist' => '$lexer, $ast, $token',
        ),
        8 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'captureUseTrait',
          'definition' => 'public function captureUseTrait($lexer, $ast, $token)',
          'arglist' => '$lexer, $ast, $token',
        ),
        9 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'processComment',
          'definition' => 'public function processComment($lexer, $ast, $token)',
          'arglist' => '$lexer, $ast, $token',
        ),
        10 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'Do nothing, apparently? I thought it was supposed to append to previous(\'whitespace\'). Idunno',
          ),
          'name' => 'appendToWhitespace',
          'definition' => 'public function appendToWhitespace($lexer, $ast, $token, $directive)',
          'arglist' => '$lexer, $ast, $token, $directive',
          'comments' => 
          array (
            0 => '$whitespace = $lexer->previous(\'whitespace\') ?? \'\';',
            1 => '$lexer->setPrevious(\'whitespace\', $whitespace.$directive->_matches[0]);',
            2 => '$lexer->setPrevious(\'whitespace\', $whitespace.$token->buffer());',
          ),
        ),
        11 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'Combine the stored modifier with the stored property declaration',
          ),
          'name' => 'setPropertyDeclaration',
          'definition' => 'public function setPropertyDeclaration($lexer, $ast, $token, $directive)',
          'arglist' => '$lexer, $ast, $token, $directive',
        ),
        12 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => '',
          ),
          'name' => 'storeMethodDefinition',
          'definition' => 'public function storeMethodDefinition($lexer, $ast, $token, $directive)',
          'arglist' => '$lexer, $ast, $token, $directive',
          'comments' => 
          array (
            0 => 'remove the method name from the modifiers.',
          ),
        ),
      ),
      'comments' => 
      array (
        0 => 'public function end_docblock($lexer, $unknownAst, $token){',
        1 => '$block = $token->buffer();',
        2 => '$block = trim($block);',
        3 => '$block = trim(substr($block,strlen(\'/**\'),-1));',
        4 => '$block = preg_replace(\'/^\\s*\\*+/m\',\'\',$block);',
        5 => '$block = \\Tlf\\Scrawl\\Utility::trimTextBlock($block);',
        6 => '$block = trim($block);',
        7 => '// if (substr($block,0,3)==\'/**\')$block = substr($block,3);',
        8 => '',
        9 => '$docLex = new \\Tlf\\Lexer();',
        10 => '$docLex->addGrammar(new \\Tlf\\Lexer\\DocBlockGrammar());',
        11 => '',
        12 => '$docAst = new \\Tlf\\Lexer\\Ast(\'docblock\');',
        13 => '$docAst->set(\'src\', $block);',
        14 => '$docLex->setHead($docAst);',
        15 => '',
        16 => '$docAst = $docLex->lexAst($docAst, $block);',
        17 => '',
        18 => '$lexer->setPrevious(\'docblock\', $docAst);',
        19 => '$unknownAst->add(\'childDocblock\', $docAst);',
        20 => '$token->setBuffer($token->match(0));',
        21 => '}',
      ),
    ),
  ),
)
;
array (
  'type' => 'file',
  'ext' => 'php',
  'name' => 'PhpGrammar.16jul21',
  'path' => '/home/reed/data/owner/Reed/projects/php/Lexer/test/php/PhpGrammar.16jul21.php',
  'namespace' => 'Tlf\\Lexer\\Test',
  'namespace.docblock' => NULL,
  'class' => 
  array (
    0 => 
    array (
      'type' => 'class',
      'docblock' => 
      array (
        'type' => 'docblock',
        'description' => 'This is not for actual parsing yet. This is for design work. The $directives array & \'php_open\' and \'namespace\' are design aspects I\'m interested in implementing at some point... maybe',
      ),
      'namespace' => 'Tlf\\Lexer\\Test',
      'declaration' => 'class PhpGrammar_16Jul21 extends Grammar ',
      'name' => 'PhpGrammar_16Jul21',
      'traits' => 
      array (
        0 => 'Php\\LanguageDirectives',
        1 => 'Php\\ClassDirectives',
        2 => 'Php\\ClassMemberDirectives',
        3 => 'Php\\BodyDirectives',
        4 => 'Php\\OtherDirectives',
      ),
      'properties' => 
      array (
        0 => 
        array (
          'type' => 'property',
          'modifiers' => 'protected ',
          'docblock' => NULL,
          'name' => 'directives',
          'declaration' => 'protected $directives;',
        ),
        1 => 
        array (
          'type' => 'property',
          'modifiers' => 'public ',
          'docblock' => NULL,
          'name' => 'notin',
          'comments' => 
          array (
            0 => '\'match\'=>\'/this-regex-available on php.net keywords page/\',',
          ),
          'declaration' => 'public $notin = [
        \'keyword\'=>[
             \'match\'=>\'/this-regex-available on php.net keywords page/\',            \'__halt_compiler\', \'abstract\', \'and\', \'array\', \'as\', \'break\', \'callable\', \'case\', \'catch\', \'class\', \'clone\', \'const\', \'continue\', \'declare\', \'default\', \'die\', \'do\', \'echo\', \'else\', \'elseif\', \'empty\', \'enddeclare\', \'endfor\', \'endforeach\', \'endif\', \'endswitch\', \'endwhile\', \'eval\', \'exit\', \'extends\', \'final\', \'for\', \'foreach\', \'function\', \'global\', \'goto\', \'if\', \'implements\', \'include\', \'include_once\', \'instanceof\', \'insteadof\', \'interface\', \'isset\', \'list\', \'namespace\', \'new\', \'or\', \'print\', \'private\', \'protected\', \'public\', \'require\', \'require_once\', \'return\', \'static\', \'switch\', \'throw\', \'trait\', \'try\', \'unset\', \'use\', \'var\', \'while\', \'xor\'
        ],
    ];',
        ),
      ),
      'methods' => 
      array (
        0 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'getNamespace',
          'definition' => 'public function getNamespace()',
          'arglist' => '',
        ),
        1 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'buildDirectives',
          'definition' => 'public function buildDirectives()',
          'arglist' => '',
        ),
        2 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'onGrammarAdded',
          'definition' => 'public function onGrammarAdded($lexer)',
          'arglist' => '$lexer',
        ),
        3 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'onLexerStart',
          'definition' => 'public function onLexerStart($lexer,$file,$token)',
          'arglist' => '$lexer,$file,$token',
          'comments' => 
          array (
            0 => '$this->buildDirectives();',
            1 => '$lexer->addDirective($this->getDirectives(\':html\')[\':html\']);',
            2 => '$lexer->stackDirectiveList(\'phpgrammar:html\', \'phpgrammar:php_open\');',
            3 => '$lexer->setDirective([$this->getDirective(\'html\')]);',
          ),
        ),
        4 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'holdNamespaceName',
          'definition' => 'public function holdNamespaceName($lexer, $file, $token)',
          'arglist' => '$lexer, $file, $token',
        ),
        5 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'saveNamespace',
          'definition' => 'public function saveNamespace($lexer, $file, $token)',
          'arglist' => '$lexer, $file, $token',
        ),
        6 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'handleClassDeclaration',
          'definition' => 'public function handleClassDeclaration($lexer, $class, $token)',
          'arglist' => '$lexer, $class, $token',
        ),
        7 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'processDocBlock',
          'definition' => 'public function processDocBlock($lexer, $ast, $token)',
          'arglist' => '$lexer, $ast, $token',
        ),
        8 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'captureUseTrait',
          'definition' => 'public function captureUseTrait($lexer, $ast, $token)',
          'arglist' => '$lexer, $ast, $token',
        ),
        9 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'processComment',
          'definition' => 'public function processComment($lexer, $ast, $token)',
          'arglist' => '$lexer, $ast, $token',
        ),
        10 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'Do nothing, apparently? I thought it was supposed to append to previous(\'whitespace\'). Idunno',
          ),
          'name' => 'appendToWhitespace',
          'definition' => 'public function appendToWhitespace($lexer, $ast, $token, $directive)',
          'arglist' => '$lexer, $ast, $token, $directive',
          'comments' => 
          array (
            0 => '$whitespace = $lexer->previous(\'whitespace\') ?? \'\';',
            1 => '$lexer->setPrevious(\'whitespace\', $whitespace.$directive->_matches[0]);',
            2 => '$lexer->setPrevious(\'whitespace\', $whitespace.$token->buffer());',
          ),
        ),
        11 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'Combine the stored modifier with the stored property declaration',
          ),
          'name' => 'setPropertyDeclaration',
          'definition' => 'public function setPropertyDeclaration($lexer, $ast, $token, $directive)',
          'arglist' => '$lexer, $ast, $token, $directive',
        ),
        12 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => '',
          ),
          'name' => 'storeMethodDefinition',
          'definition' => 'public function storeMethodDefinition($lexer, $ast, $token, $directive)',
          'arglist' => '$lexer, $ast, $token, $directive',
          'comments' => 
          array (
            0 => 'remove the method name from the modifiers.',
          ),
        ),
      ),
      'comments' => 
      array (
        0 => 'public function end_docblock($lexer, $unknownAst, $token){',
        1 => '$block = $token->buffer();',
        2 => '$block = trim($block);',
        3 => '$block = trim(substr($block,strlen(\'/**\'),-1));',
        4 => '$block = preg_replace(\'/^\\s*\\*+/m\',\'\',$block);',
        5 => '$block = \\Tlf\\Scrawl\\Utility::trimTextBlock($block);',
        6 => '$block = trim($block);',
        7 => '// if (substr($block,0,3)==\'/**\')$block = substr($block,3);',
        8 => '',
        9 => '$docLex = new \\Tlf\\Lexer();',
        10 => '$docLex->addGrammar(new \\Tlf\\Lexer\\DocBlockGrammar());',
        11 => '',
        12 => '$docAst = new \\Tlf\\Lexer\\Ast(\'docblock\');',
        13 => '$docAst->set(\'src\', $block);',
        14 => '$docLex->setHead($docAst);',
        15 => '',
        16 => '$docAst = $docLex->lexAst($docAst, $block);',
        17 => '',
        18 => '$lexer->setPrevious(\'docblock\', $docAst);',
        19 => '$unknownAst->add(\'childDocblock\', $docAst);',
        20 => '$token->setBuffer($token->match(0));',
        21 => '}',
      ),
    ),
  ),
)<?php

namespace Cats\Whatever;

/**
 * This is the best class anyone has ever written.
 */
class Sample extends cats {

    use Some\Demons;

    // First comment 
    # Second Comment

    /**
     * Why would you name a giraffe Bob?
     */
    protected $giraffe = "Bob";
    private $cat = "Jeff";
    static public $dog = "PandaBearDog";

    /**
     * dogs
     *
     * @return dogs
     */
    public function dogs($a= "abc"){
        echo "yep yep";
    }


    public const Doygle = "Hoygle Floygl";

}
<?php

return
array (
  'type' => 'file',
  'ext' => 'php',
  'name' => 'SampleClass',
  'path' => '/home/reed/.disk/Dev/php/Lexer/test/php/SampleClass.php',
  'namespace' => 'Cats\\Whatever',
  'namespace.docblock' => '',
  'class' => 
  array (
    0 => 
    array (
      'type' => 'class',
      'docblock' => 
      array (
        'type' => 'docblock',
        'description' => 'This is the best class anyone has ever written.',
      ),
      'namespace'=>'Cats\\Whatever',
      'declaration' => 'class Sample extends cats ',
      'name' => 'Sample',
      'traits' => 
      array (
        0 => 'Some\\Demons',
      ),
      'comments' => 
      array (
        0 => 'First comment',
        1 => 'Second Comment',
      ),
      'properties' => 
      array (
        0 => 
        array (
          'type' => 'property',
          'modifiers' => 'protected ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'Why would you name a giraffe Bob?',
          ),
          'name' => 'giraffe',
          'declaration' => 'protected $giraffe = "Bob";',
        ),
        1 => 
        array (
          'type' => 'property',
          'modifiers' => 'private ',
          'docblock' => NULL,
          'name' => 'cat',
          'declaration' => 'private $cat = "Jeff";',
        ),
        2 => 
        array (
          'type' => 'property',
          'modifiers' => 'static public ',
          'docblock' => NULL,
          'name' => 'dog',
          'declaration' => 'static public $dog = "PandaBearDog";',
        ),
      ),
      'methods' => 
      array (
        0 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'dogs
',
            'attribute' => 
            array (
              0 => 
              array (
                'type' => 'attribute',
                'name' => 'return',
                'description' => 'dogs',
              ),
            ),
          ),
          'name' => 'dogs',
          'definition' => 'public function dogs($a= "abc")',
          'arglist' => '$a= "abc"',
        ),
      ),
      'consts' => 
      array (
        0 => 
        array (
          'type' => 'const',
          'docblock' => NULL,
          'definition' => 'const Doygle = "Hoygle Floygl";',
          'modifiers' => 'public ',
          'name' => 'Doygle',
        ),
      ),
    ),
  ),
)
;
array (
  'type' => 'file',
  'ext' => 'php',
  'name' => 'SampleClass',
  'path' => '/home/reed/data/owner/Reed/projects/php/Lexer/test/php/SampleClass.php',
  'namespace' => 'Cats\\Whatever',
  'namespace.docblock' => NULL,
  'class' => 
  array (
    0 => 
    array (
      'type' => 'class',
      'docblock' => 
      array (
        'type' => 'docblock',
        'description' => 'This is the best class anyone has ever written.',
      ),
      'namespace' => 'Cats\\Whatever',
      'declaration' => 'class Sample extends cats ',
      'name' => 'Sample',
      'traits' => 
      array (
        0 => 'Some\\Demons',
      ),
      'comments' => 
      array (
        0 => 'First comment',
        1 => 'Second Comment',
      ),
      'properties' => 
      array (
        0 => 
        array (
          'type' => 'property',
          'modifiers' => 'protected ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'Why would you name a giraffe Bob?',
          ),
          'name' => 'giraffe',
          'declaration' => 'protected $giraffe = "Bob";',
        ),
        1 => 
        array (
          'type' => 'property',
          'modifiers' => 'private ',
          'docblock' => NULL,
          'name' => 'cat',
          'declaration' => 'private $cat = "Jeff";',
        ),
        2 => 
        array (
          'type' => 'property',
          'modifiers' => 'static public ',
          'docblock' => NULL,
          'name' => 'dog',
          'declaration' => 'static public $dog = "PandaBearDog";',
        ),
      ),
      'methods' => 
      array (
        0 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'dogs
',
            'attribute' => 
            array (
              0 => 
              array (
                'type' => 'attribute',
                'name' => 'return',
                'description' => 'dogs',
              ),
            ),
          ),
          'name' => 'dogs',
          'definition' => 'public function dogs($a= "abc")',
          'arglist' => '$a= "abc"',
        ),
      ),
      'consts' => 
      array (
        0 => 
        array (
          'type' => 'const',
          'docblock' => NULL,
          'definition' => 'const Doygle = "Hoygle Floygl";',
          'modifiers' => 'public ',
          'name' => 'Doygle',
        ),
      ),
    ),
  ),
)<?php

namespace Tlf\Lexer\Test;

/** An extremely simple grammar that builds sets of arglist from `(arg1,arg2,c) (list2_arg1,arg2)` */
class StarterGrammar_16Jul21 extends Grammar {

    // use Starter\LanguageDirectives;
    use Starter\OtherDirectives;

    /** The actual array of directives, built during onGrammarAdded() */
    protected $directives;

    /** Defaults to 'startergrammar' */
    public function getNamespace(){return 'starter';}

    /** Combine the directives from traits */
    public function buildDirectives(){
        $this->directives = array_merge(
            // $this->_language_directives,
            $this->_other_directives,
        );
    }

    public function onGrammarAdded(\Tlf\Lexer $lexer){
        $this->buildDirectives();
        /** The first directive(s) to listen for. We're looking for an opening `(` */
        $lexer->addDirective($this->getDirectives(':parenthesis')['parenthesis']);
        // you can add more directives
    }

    public function onLexerStart(\Tlf\Lexer $lexer,\Tlf\Lexer\Ast $ast,\Tlf\Lexer\Token $token){
        // $lexer->addGrammar(new DocblockGrammar()); //if your language uses docblocks

        /** Just an example of setting an empty namespace at the start, so that all files have a namespace, even if its empty. */
        if ($ast->type=='file'){
            $ast->set('namespace', '');
        }
    }

    /** A method this grammar uses as an instruction to trim() the buffer */
    public function trimBuffer(\Tlf\Lexer $lexer, \Tlf\Lexer\Ast $ast, \Tlf\Lexer\Token $token, \stdClass $directive, array $args){
        $token->setBuffer(trim($token->buffer()));
    }
}
<?php

return 
array (
  'type' => 'file',
  'ext' => 'php',
  'name' => 'StarterGrammar.16jul21',
  'path' => '/home/reed/.disk/Dev/php/Lexer/test/php/StarterGrammar.16jul21.php',
  'namespace' => 'Tlf\\Lexer\\Test',
  'namespace.docblock' => NULL,
  'class' => 
  array (
    0 => 
    array (
      'type' => 'class',
      'docblock' => 
      array (
        'type' => 'docblock',
        'description' => 'An extremely simple grammar that builds sets of arglist from `(arg1,arg2,c) (list2_arg1,arg2)`',
      ),
      'namespace' => 'Tlf\\Lexer\\Test',
      'declaration' => 'class StarterGrammar_16Jul21 extends Grammar ',
      'name' => 'StarterGrammar_16Jul21',
      'comments' => 
      array (
        0 => 'use Starter\\LanguageDirectives;',
      ),
      'traits' => 
      array (
        0 => 'Starter\\OtherDirectives',
      ),
      'properties' => 
      array (
        0 => 
        array (
          'type' => 'property',
          'modifiers' => 'protected ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'The actual array of directives, built during onGrammarAdded()',
          ),
          'name' => 'directives',
          'declaration' => 'protected $directives;',
        ),
      ),
      'methods' => 
      array (
        0 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'Defaults to \'startergrammar\'',
          ),
          'name' => 'getNamespace',
          'definition' => 'public function getNamespace()',
          'arglist' => '',
        ),
        1 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'Combine the directives from traits',
          ),
          'name' => 'buildDirectives',
          'definition' => 'public function buildDirectives()',
          'arglist' => '',
          'comments' => 
          array (
            0 => '$this->_language_directives,',
          ),
        ),
        2 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'onGrammarAdded',
          'definition' => 'public function onGrammarAdded(\\Tlf\\Lexer $lexer)',
          'arglist' => '\\Tlf\\Lexer $lexer',
          'comments' => 
          array (
            0 => 'you can add more directives',
          ),
        ),
        3 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'onLexerStart',
          'definition' => 'public function onLexerStart(\\Tlf\\Lexer $lexer,\\Tlf\\Lexer\\Ast $ast,\\Tlf\\Lexer\\Token $token)',
          'arglist' => '\\Tlf\\Lexer $lexer,\\Tlf\\Lexer\\Ast $ast,\\Tlf\\Lexer\\Token $token',
          'comments' => 
          array (
            0 => '$lexer->addGrammar(new DocblockGrammar()); //if your language uses docblocks',
          ),
        ),
        4 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'A method this grammar uses as an instruction to trim() the buffer',
          ),
          'name' => 'trimBuffer',
          'definition' => 'public function trimBuffer(\\Tlf\\Lexer $lexer, \\Tlf\\Lexer\\Ast $ast, \\Tlf\\Lexer\\Token $token, \\stdClass $directive, array $args)',
          'arglist' => '\\Tlf\\Lexer $lexer, \\Tlf\\Lexer\\Ast $ast, \\Tlf\\Lexer\\Token $token, \\stdClass $directive, array $args',
        ),
      ),
    ),
  ),
)
;
array (
  'type' => 'file',
  'ext' => 'php',
  'name' => 'StarterGrammar.16jul21',
  'path' => '/home/reed/data/owner/Reed/projects/php/Lexer/test/php/StarterGrammar.16jul21.php',
  'namespace' => 'Tlf\\Lexer\\Test',
  'namespace.docblock' => NULL,
  'class' => 
  array (
    0 => 
    array (
      'type' => 'class',
      'docblock' => 
      array (
        'type' => 'docblock',
        'description' => 'An extremely simple grammar that builds sets of arglist from `(arg1,arg2,c) (list2_arg1,arg2)`',
      ),
      'namespace' => 'Tlf\\Lexer\\Test',
      'declaration' => 'class StarterGrammar_16Jul21 extends Grammar ',
      'name' => 'StarterGrammar_16Jul21',
      'comments' => 
      array (
        0 => 'use Starter\\LanguageDirectives;',
      ),
      'traits' => 
      array (
        0 => 'Starter\\OtherDirectives',
      ),
      'properties' => 
      array (
        0 => 
        array (
          'type' => 'property',
          'modifiers' => 'protected ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'The actual array of directives, built during onGrammarAdded()',
          ),
          'name' => 'directives',
          'declaration' => 'protected $directives;',
        ),
      ),
      'methods' => 
      array (
        0 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'Defaults to \'startergrammar\'',
          ),
          'name' => 'getNamespace',
          'definition' => 'public function getNamespace()',
          'arglist' => '',
        ),
        1 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'Combine the directives from traits',
          ),
          'name' => 'buildDirectives',
          'definition' => 'public function buildDirectives()',
          'arglist' => '',
          'comments' => 
          array (
            0 => '$this->_language_directives,',
          ),
        ),
        2 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'onGrammarAdded',
          'definition' => 'public function onGrammarAdded(\\Tlf\\Lexer $lexer)',
          'arglist' => '\\Tlf\\Lexer $lexer',
          'comments' => 
          array (
            0 => 'you can add more directives',
          ),
        ),
        3 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => NULL,
          'name' => 'onLexerStart',
          'definition' => 'public function onLexerStart(\\Tlf\\Lexer $lexer,\\Tlf\\Lexer\\Ast $ast,\\Tlf\\Lexer\\Token $token)',
          'arglist' => '\\Tlf\\Lexer $lexer,\\Tlf\\Lexer\\Ast $ast,\\Tlf\\Lexer\\Token $token',
          'comments' => 
          array (
            0 => '$lexer->addGrammar(new DocblockGrammar()); //if your language uses docblocks',
          ),
        ),
        4 => 
        array (
          'type' => 'method',
          'modifiers' => 'public function ',
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'A method this grammar uses as an instruction to trim() the buffer',
          ),
          'name' => 'trimBuffer',
          'definition' => 'public function trimBuffer(\\Tlf\\Lexer $lexer, \\Tlf\\Lexer\\Ast $ast, \\Tlf\\Lexer\\Token $token, \\stdClass $directive, array $args)',
          'arglist' => '\\Tlf\\Lexer $lexer, \\Tlf\\Lexer\\Ast $ast, \\Tlf\\Lexer\\Token $token, \\stdClass $directive, array $args',
        ),
      ),
    ),
  ),
)<?php

/**
 * A class that does nothing
 */
class DocumentationExample extends \Nothing {

    /** 
     * A method that does nothing.
     */
    public function one(){}
    public function two(){}
}
<?php
return 
array (
  'type' => 'file',
  'ext' => 'php',
  'name' => 'DocumentationExample',
  'path' => '/home/reed/data/projects/php/Lexer/test/input/php/DocumentationExample.php',
  'namespace' => '',
  'class' => 
  array (
    0 => 
    array (
      'type' => 'class',
      'docblock' => 
      array (
        'type' => 'docblock',
        'description' => 'A class that does nothing',
      ),
      'fqn' => 'DocumentationExample',
      'namespace' => '',
      'name' => 'DocumentationExample',
      'extends' => '\\Nothing',
      'declaration' => 'class DocumentationExample extends \\Nothing',
      'methods' => 
      array (
        0 => 
        array (
          'type' => 'method',
          'args' => 
          array (
          ),
          'docblock' => 
          array (
            'type' => 'docblock',
            'description' => 'A method that does nothing.',
          ),
          'modifiers' => 
          array (
            0 => 'public',
          ),
          'name' => 'one',
          'body' => '',
          'declaration' => 'public function one()',
        ),
        1 => 
        array (
          'type' => 'method',
          'args' => 
          array (
          ),
          'modifiers' => 
          array (
            0 => 'public',
          ),
          'name' => 'two',
          'body' => '',
          'declaration' => 'public function two()',
        ),
      ),
    ),
  ),
);
?>
{
    "docblock": 3,
    "consts": 0,
    "properties": 0,
    "methods": 23,
    "comments": 0,
    "--comment":{
        "zero":"there are 4 docblocks, but one is inside a block, so it's not caught rn"
    }
}
{
    "consts": 0,
    "properties": 3,
    "methods": 1,
    "comments": 2,
    "docblock": 3
}
{
    "consts": 0,
    "properties": 0,
    "methods": 0,
    "comments": 0,

    "class": 2,
    "functions": 2,
    "docblocks": 0,
    "comments": 1
}
{
    "consts": 0,
    "properties": 1,
    "methods": 18,
    "comments": 0,
    "class": 1
}
{
    "consts": 0,
    "properties": 2,
    "methods": 4,
    "class": 1
}
{
    "consts": 0,
    "properties": 1,
    "methods": 1,
    "comments": 0,
    "class": 1
}
{
    "class": 1,
    "consts": 0,
    "properties": 1,
    "methods": 13,
    "comments": 0
}
{
    "properties": 4,
    "methods": 12,
    "comments":0,
    "consts":0,

    "docblock": 15,

    "--comment": "actually 11 comments"

}
{
        "properties": 0,
        "methods": 15,
        "comments":3,
        "consts":0,

        "docblock": 10,

        "--comment":"there are actually 31 comments once body parsing is completed"

}
{
    "properties": 2,
    "methods": 6,
    "comments":0,
    "consts":0,
    "docblock": 9,
    "--comment": "there are 9 comments, but zero now bc they're all in the body"
}
{
    "properties": 4,
    "methods": 15,
    "comments":6,
    "consts":0,
    "docblock": 13,
    
    "--comment": "actually 26 comments, and 14 docblocks"
}
{
    "properties": 0,
    "methods": 1,
    "docblock": 1
}
<?php

class Sample extends cats {

    public function cats(){}
    public function dogs($arg){}
    public function dogs2($arg=1){}
    public function dogs_3($arg='yes'){}
    /** bears are so cute */
    public function bears(){}
    /** bears are so cute */
    public function bears_are_best(){
    
    }
    public function bears_do_stuff(){
        echo "love bears";
    }

    public function bears_cuddle_stuff(){
        $str = "resist the temptation to cuddle a bear. not safe. big sad";
        echo $str;
    }

    public function bears_nest(){
        $cats = 'run away from bears';
        if ($cats == 'idk'){
            echo "this is a block";
        }
    }

    /**
     * Replaces inline PHP code with placeholder, indexes the placeholder, and returns the modified code
     *
     * @param  mixed $srcCode - The source code
     * 
     * @return string - source code with all PHP replaced by codeIds
     */
    public function cleanSource($srcCode): string {
        $parser = new PHPParser($srcCode);
        $parsed = $parser->pieces();
    }

    public function makes_it_11(){}

    public function output(): string{
        // print_r($this->code);
        // // echo $this->code[0]->;
        // exit;
        // print_r($this->placeholder);
        $code = implode("\n",$this->code);
        // return $code;
        $ph = [];
        foreach ($this->placeholder as $id=>$codeArray){
            $ph[$id] = implode('',$codeArray);
        }
        $last = $code;
        while($last != $code = str_replace(array_keys($ph),$ph,$code))$last=$code;
        return $code;
    }

    public function ok_13(){}

    public function writeTo(string $file, $chmodTo=null): bool {
        $output = $this->output();
        if (is_dir(dirname($file))){
            mkdir(dirname($file),0771,true);
            // chmod(dirname($file),0770);
        }
        $didPut = file_put_contents($file,$output);
        if ($chmodTo!==null){
            // chmod($file,$chmodTo);
        }
        if ($didPut===false)return false;
        else return true;
    }

    public function yep_15(){}

    public function __construct($html)
    {
        parent::__construct();

        $this->srcHTML = $html;

        $parser = new PHTML\PHPParser($html);
        $enc = $parser->pieces();
        $this->php = $enc->php;
        $this->cleanSrc = $enc->html;
        $this->cleanSrc = $this->cleanHTML($this->cleanSrc);
        $hideXmlErrors=true;
        libxml_use_internal_errors($hideXmlErrors);
        $this->registerNodeClass('DOMElement', '\\Taeluf\\PHTML\\Node');
        $this->registerNodeClass('DOMText', '\\Taeluf\\PHTML\\TextNode');
        // $this->registerNodeClass('DOMText', 'RBText');

        $html = '<root>'.$this->cleanSrc.'</root>';
        $this->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
        $this->formatOutput = true;
        libxml_use_internal_errors(false);

    }    

    public function okay_17(){}

    public function output2($withPHP=true){
        // echo "\n".'-start output call-'."\n";
        $list = $this->childNodes[0]->childNodes;

        $hiddenTagsNodes = $this->xpath('//*[@hideOwnTag]');
        foreach ($hiddenTagsNodes as $htn){
            if ($htn->hideOwnTag==false||$htn->hideOwnTag=='false'){
                unset($htn->hideOwnTag);
                continue;
            }
            $parent = $htn->parentNode;
            $childNodeList = $htn->children;
            foreach ($childNodeList as $child){
                $htn->removeChild($child);
                $parent->insertBefore($child, $htn);
            }
            $parent->removeChild($htn);
        }
        $html = '';
        foreach ($list as $item){
            $html .= $this->saveHTML($item);
        }

        /** Run the php-code-replacer as long as there is a placeholder (while preventing infinite looping) */
        $html = $this->fill_php($html, $withPHP);
        
        $html = $this->restoreHtml($html);

        return $html;
    }

    public function now_19(){}

    public function fill_php($html, $withPHP=true){
        $maxIters = 25;
        $iters = 0;
        while ($iters++<$maxIters&&preg_match('/php([a-zA-Z]{26})php/', $html, $match)){
            foreach ($this->php as $id=>$code){
                if ($withPHP)$html = str_replace($id,$code,$html);
                else $html = str_replace($id,'',$html);
            }
        }

        if (($phpAttrVal=$this->phpAttrValue)!=null){
            $html = str_replace("=\"$phpAttrVal\"", '', $html);
        }
        return $html;
    }


    public function ugh_21(){}


    public function create(string $tableName, array $colDefinitions, bool $recreateIfExists=false){
        $colStatements = [];
        foreach ($colDefinitions as $col => $definition){
            $statement = '`'.$col.'` '. $definition;
            $colStatements[] = $statement;
        }
        $colsSql = implode(", ", $colStatements);
        $drop = $recreateIfExists ? "DROP TABLE IF EXISTS `{$tableName}`;\n" : '';
        $sql =
        <<<SQL
            {$drop}
            CREATE TABLE IF NOT EXISTS `{$tableName}`
            (
            {$colsSql}
            )
            ;
            
        SQL;

        $this->exec($sql);
    }

    public function its_23(){}
}
<?php

namespace Cats\Whatever;

/**
 * This is the best class anyone has ever written.
 */
class Sample extends cats {

    use Some\Demons;

    // First comment 
    # Second Comment

    /**
     * Why would you name a giraffe Bob?
     */
    protected $giraffe = "Bob";
    private $cat = "Jeff";
    static public $dog = "PandaBearDog";

    /**
     * dogs
     *
     * @return dogs
     */
    public function dogs($a= "abc"){
        echo "yep yep";
    }


    public const Doygle = "Hoygle Floygl";

}
<?php

namespace Tlf\Lexer\Test\Scrawl;

class Integrate extends \Tlf\Tester {




    public function testIdk(){
        $scrawl = new \Tlf\Scrawl2();
        $scrawl->dir_root = $this->file('');
        $php_ext = new \Tlf\Scrawl\FileExt\Php($scrawl);
        $ast = $php_ext->parse_file('test/run/Integrate.php');

        var_dump($ast);
        exit;
        print_r($ast->getTree());
        exit;
    }


    public function testGetAllClasses(){
        // goals:
        // 1. test all_classes template
        // 2. write api docs to disk for every php file in the code dirs, matching the directory structure on disk

        $class1 = <<<PHP
            <?php
            class Abc {
                function def(){}
            }
        PHP;
        $class2 = <<<PHP
            <?php
            class Ghi {
                function jkl(){}
            }
        PHP;
        $class3 = <<<PHP
            <?php
            class Mno{
                function pqr(){}
            }
        PHP;

        $scrawl = new \Tlf\Scrawl2();
        $php_ext = new \Tlf\Scrawl\FileExt\Php($scrawl);
        $ast1 = $php_ext->parse_str($class1);
        $ast2 = $php_ext->parse_str($class2);
        $ast3 = $php_ext->parse_str($class3);

        $php_ext->set_ast($ast1);
        $php_ext->set_ast($ast2);
        $php_ext->set_ast($ast3);

        $classes = $php_ext->get_all_classes();

        $this->compare(
            'Abc',
            $classes['Abc']['fqn'],
        );
        $this->compare(
            'Ghi',
            $classes['Ghi']['fqn'],
        );
        $this->compare(
            'Mno',
            $classes['Mno']['fqn'],
        );

    }







    public function testPhpExtWithScrawl(){
        echo "this is an old test from the beginning of the rewrite ... probably don't need it anymore. I don't think it was ever passing";
        $this->disable();
        return;
        $str = $this->php_code;
        $scrawl = new \Tlf\Scrawl2();

        $scrawl->extensions['code']['php'][] = new \Tlf\Scrawl\FileExt\Php();

        $res = $scrawl->parse_str($str, 'php');
        print_r($res);
        exit;

        print_r($scrawl->get('ast'));


        return;

        $scrawl->extensions['file']['php'];
        $scrawl->addExtension('file');

        $outputs = $scrawl->process_str($str, '.php');

        // this should have
        // ast = ... the ast ...
        // tags = 
        print_r($outputs);

        // i should use the lexer to build the ast explicitly
        $class_ast = null; 
        $method_ast = null;
        $this->compare(
            [
                'ast'=>[
                    'class'=>['Abc'=>$class_ast] // ast as from lexer
                ],
                'tags'=>[
                    'feature'=>['name'=>'no feature', 'target'=>'ast.class.Abc']
                ],
                'flat'=>[
                    'ast.class.Abc'=>$class_ast,
                    'ast.class.Abc.method.ghi'=>$method_ast,
                ],
            ],
            $outputs
        );

        return;
        // this shouldn't do anything bc i haven't added any extensions
        print_r($scrawl->getOutputs());
    }

}
<?php

namespace Tlf\Scrawl\Ext\MdVerb;

class MainVerbs {

    /**
     * a scrawl instance
     */
    public \Tlf\Scrawl $scrawl;

    public function __construct(\Tlf\Scrawl $scrawl){
        $this->scrawl = $scrawl;
    }

    /**
     * add callbacks to `$md_ext->handlers`
     */
    public function setup_handlers(\Tlf\Scrawl\Ext\MdVerbs $md_ext){
        $handlers = [
            'import'=>'at_import',
            'file' => 'at_file',
            'template'=> 'at_template',
            'easy_link'=> 'at_easy_link',
            'hard_link'=> 'at_hard_link',
            'see_file'=> 'at_see_file',
            'see'=> 'at_see_file',
        ];
        foreach ($handlers as $verb=>$func_name){
            $md_ext->handlers[$verb] = [$this, $func_name];
        }
    }

    // public function okay(){}

    /**
     * Load a template
     * @usage @template(template_name, arg1, arg2)
     */
    public function at_template(string $templateName, ...$templateArgs){
        return $this->scrawl->get_template($templateName, $templateArgs);
    }

    /**
     * Import something previously exported with @export or @export_start/@export_end
     *
     * @usage @import(Namespace.Key)
     * @output whatever was exported by @export or @export_start/_end
     */
    public function at_import(string $key){
        $output = $this->scrawl->get('export',$key);

        if ($output===null){
            $this->scrawl->warn('@import', '@import('.$key.') failed');
            $replacement = '# Import key "'.$key.'" not found.';
        } else {
            $replacement = $output;
        }
        return $replacement;
    }

    /**
     * Copy a file's content into your markdown.
     *
     * @usage @file(rel/path/to/file.ext)
     * @output the file's content, `trim`med.
     */
    public function at_file(string $relFilePath){
        $file = $this->scrawl->dir_root.'/'.$relFilePath;

        if (!is_file($file)){
            $this->scrawl->warn('@file', "@file($relFilePath) failed. File does not exist.");
            return "'$file' is not a file.";
        }

        return trim(file_get_contents($file));
    }

    /**
     * Get a link to a file in your repo
     *
     * @usage @see_file(relative/file/path)
     * @output `[relative/file/path](urlPath)`
     */
    public function at_see_file(string $relFilePath){
        $path = $this->scrawl->dir_root.'/'.$relFilePath;
        if (!is_file($path) && !is_dir($path)){
            $this->scrawl->warn("@see_file","@see_file($relFilePath): File does not exist");
        }
        $urlPath = $relFilePath;
        if ($urlPath[0]!='/')$urlPath = '/'.$urlPath;
        $link = '['.$relFilePath.']('.$urlPath.')';
        return $link;
    }


    /** just returns a regular markdown link. In future, may check validity of link or do some kind of logging 
     *
     * @usage @hard_link(https://url.com, LinkName)
     * @output [LinkName](https://url.com)
     */
    public function at_hard_link(string $url, string $name=null){
        if ($name==null) $name = $url;
        return '['.$name.']('.$url.')';
    }

    /**
     *
     *
     * @usage @easy_link(twitter, TaelufDev)
     * @output [TaelufDef](https://twitter.com/TaelufDev)
     * @todo support a third param 'LinkName' so the target and link name need not be identical
     */ 
    public function at_easy_link(string $service, string $target){
        $sites = [
            'twitter'=>'https://twitter.com/',
            'gitlab'=>'https://gitlab.com/',
            'github'=>'https://github.com/',
            'facebook'=>'https://facebook.com/',
            'tlf'=>'https://tluf.me/',
        ];

        $host = $sites[strtolower($service)] ?? null;
        if ($host==null){
            $this->scrawl->warn('@easy_link', "@easy_link($service,$target): Service '$service' is not valid. Options are "
                .implode(', ', array_keys($sites))
            );
            return "--service '$service' not found--";
        }
        $url = $host.$target;
        $linkName = $target;
        $mdLink = "[$linkName]($url)";
        return $mdLink;
    }

}
<?php

namespace Tlf;

class Scrawl2 {


    /**
     * @param $string a string to parse ... template source or file source, idk
     * @param $file_ext a file extension like 'php' or 'md' (to indicate type)
     */
    public function process_str(string $string, string $file_ext){

        $extensions = $this->extensions['file'][$file_ext];

        foreach ($extensions as $ext){

        }

    } 

    public function addExtension(object $ext){
        //something
    }

}
<?php

namespace Tlf;

class Scrawl2 {



    /** array for get/set */
    public array $stuff = [];

    public array $extensions = [
        'code'=>[],
    ];

    /** absolute path to your documentation dir */
    public ?string $dir_docs = null;

    /** absolute path to the root of your project */
    public ?string $dir_root = null;

    public array $template_dirs = [

    ];

    /** if true, append two spaces to every line so all new lines are parsed as new lines */
    public bool $markdown_preserveNewLines = true;

    /** if true, add an html comment to md docs saying not to edit directly */
    public bool $markdown_prependGenNotice = true;

    /**
     * @parma $options `key=>value` array to set properties
     */
    public function __construct(array $options=[]){
        $this->template_dirs[] = __DIR__.'/Template/';
        $this->options = $options;
        foreach ($this->options as $k=>$o){
            $k = str_replace('.','_',$k);
            $this->$k = $o;
        }

    }

    public function get_template(string $name, array $args){

        foreach ($this->template_dirs as $path){
            if (file_exists($file = $path.'/'.$name.'.md.php')){}
            else if (file_exists($file=$path.'/'.$name.'.php')){}
            else continue;
            $out = (function(array $args, string $file) {
                ob_start();
                require($file);
                $out = ob_get_clean();
                return $out;
            })($args, $file);
            return $out;
        }
        
        $this->warn("@template", $msg="Template '$name' does not exist.");
        return $msg;
    }

    /**
     * @param $string a string to parse ... template source or file source, idk
     * @param $file_ext a file extension like 'php' or 'md' (to indicate type)
     */
    public function process_str(string $string, string $file_ext){

        $extensions = $this->extensions['file'][$file_ext];

        foreach ($extensions as $ext){
            /**
             * I'm over designing
             * what am i over designing for?
             * i'm trying to make it so extensions are highly customizable
             * like i want to be able to make multiple extensions that handle php files
             * like maybe i want a php file extension that just ... finds all occurences of some particular string ...
             * So i think that's a reasonable goal
             * but then how do i integrate that all together?
             *
             * This one just needs to return an ast ...
             * so then maybe i need an additional extension that handles ASTs ...
             * or i could make the php extension do all the ast processing (getting docblock attributes)
             * which makes sense bc the php extension will produce different ast than any other language-based extension ... or even a diff php extension using a different lexer & ast generator
             *
             * so i probably should just make this do all the things (this being the php extension)
             * 
             * yeah, cuz right now i'm using onSourceFilesDone() to loop over ALL api outputs (which are ast outputs)
             * and generate some docs
             * which like ... yeah ... there's a point for that
             *
             * I think I could just have the extension do it's thing all at once
             * 
             * add a second function that takes in an ast and generates a file?
             *
             * Yeah ... bc that looping code doesn't have any more context
             *
             * I'm just looking for the simplest & most testable implementation
             *
             */
        }

    } 

    public function addExtension(object $ext){
        //something
    }

    public function get(string $group, string $key){
        if (!isset($this->stuff[$group])){
            $this->warn("Group not set", $group);
            return null;
        } else if (!isset($this->stuff[$group][$key])){
            $this->warn("Group.Key not set", "$group.$key");
            return null;
        }
        return $this->stuff[$group][$key];
    }
    public function get_group(string $group){
        if (!isset($this->stuff[$group])){
            $this->warn("Group not set", $group);
            return null;
        }
        return $this->stuff[$group];
    }


    public function set(string $group, string $key, $value){
        $this->stuff[$group][$key] = $value;
    }

    public function parse_str($str, $ext){
        $out = [];
        foreach ($this->extensions['code'][$ext] as $ext){
            $out = $ext->parse_str($str); 
        }
        return $out;
    }

    /**
     * save a file to disk in the documents directory
     */
    public function write_doc(string $rel_path, string $content){
        $content = $this->prepare_md_content($content);
        $rel_path = str_replace('../','/', $rel_path);
        $path = $this->dir_docs.'/'.$rel_path;
        $dir = dirname($path);
        if (!is_dir($dir))mkdir($dir,0755,true);
        if (is_file($path)){
            $this->warn('Overwrite',$rel_path);
        } else {
            $this->good('Write',$rel_path);
        }
        file_put_contents($path, $content);
    }

    /**
     * Read a file from disk, from the project root
     */
    public function read_file(string $rel_path){
        return file_get_contents($this->dir_root.'/'.$rel_path);
    }


    /**
     * Output a message to cli (may do logging later, idk)
     */
    public function report(string $msg){
        echo "\n$msg";
    }

    /**
     * Output a message to cli, header highlighted in red
     */
    public function warn($header, $message){
        echo "\033[0;31m$header:\033[0m $message\033[0;31m\033[0m\n";
    }

    /**
     * Output a message to cli, header highlighted in red
     */
    public function good($header, $message){
        echo "\033[0;32m$header:\033[0m $message\033[0;31m\033[0m\n";
    }

    /** apply small fixes to markdown */
    public function prepare_md_content(string $markdown){

        if ($this->markdown_preserveNewLines){
            $markdown  = str_replace("\n","  \n",$markdown);
        }

        if ($this->markdown_prependGenNotice){
            // @TODO give relative path to source file
            $markdown = "<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  \n".$markdown;
        }
        
        return $markdown;
    }
}
<?php

function abc(){
}

class Abc {
}

?>

# File <?=$File->relPath?>  

## Functions
<?php
foreach ($File->function??[] as $function){
    $function = (object)$function;
    $descript = $function->docblock['tip'] ?? $function->docblock['description'] ?? '';
    $name = $function->name;
    echo "- `$name`: $descript\n";
}

return;
?>

## Properties
<?php
foreach ($Class->property as $prop){
    $prop = (object)$prop;
    $def = $prop->definition;
    $descript = $prop->docblock;
    echo "- `${def}` ${descript}\n";
}

?>

## Methods 
<?php
foreach ($Class->method as $method){
    $method = (object)$method;
    $def = $method->declaration;
    // $descript = $method->description;
    $descript = $method->docblock;
    echo "- `${def}` ${descript}\n";
}

?>

## Static Properties 
<?php
foreach ($Class->staticProps as $prop){
    $def = $prop->definition;
    $descript = $prop->description;
    echo "- `${def}` ${descript}\n";
}

?>

## Static functions
<?php
foreach ($Class->staticFunctions as $func){
    $def = $func->definition;
    $descript = $func->description;
    echo "- `${def}` ${descript}\n";
}

?>

<?php

print_r($Class);

class Def {
}

function yep(){
}

?>
<?php

namespace Tlf;

/**
 * A lil tiny database class
 */
class LilDb {

    /**
     * a pdo instance
     */
    public \PDO $pdo;

    /**
     * Convenience method to initialize with pdo
     * @return Tlf\LilDb
     */
    static public function new(string $user, string $password, string $db, $host='localhost') {
        $pdo = new \PDO("mysql:dbname=${db};host=${host}", $user, $password);
        $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
        $ldb = new static($pdo);
        return $ldb;
    }

    /**
     * Convenience method to initialize sqlite db in memory
     * @return Tlf\LilDb
     */
    static public function sqlite(string $dbName = ':memory:'){
        $pdo = new \PDO('sqlite:'.$dbName);
        $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
        $ldb = new static($pdo);
        return $ldb;
    }
    /**
     * Convenience method to initialize mysql db in memory
     */
    static public function mysql($dbName = ':memory:'){
        $pdo = new \PDO('mysql:'.$dbName);
        $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
        $ldb = new static($pdo);
        return $ldb;
    }

    /**
     * Initialize with a db handle
     * @param $pdo a pdo instance
     */
    public function __construct(\PDO $pdo){
        $this->pdo = $pdo;
    }


    /**
     * Create a new table if it doesn't exist.
     *
     * @param2 $colDefinitions array of columns like: `['col_name'=>'VARCHAR(80)', 'col_two'=> 'integer']`
     * @param3 $recreateIfExists true/false to include `DROP TABLE IF EXISTS table_name`
     */
    public function create(string $tableName, array $colDefinitions, bool $recreateIfExists=false){
        $colStatements = [];
        foreach ($colDefinitions as $col => $definition){
            $statement = '`'.$col.'` '. $definition;
            $colStatements[] = $statement;
        }
        $colsSql = implode(", ", $colStatements);
        $drop = $recreateIfExists ? "DROP TABLE IF EXISTS `{$tableName}`;\n" : '';
        $sql =
        <<<SQL
            {$drop}
            CREATE TABLE IF NOT EXISTS `{$tableName}`
            (
            {$colsSql}
            )
            ;
            
        SQL;

        $this->exec($sql);
    }
    /**
     * Execute an Sql statement & get rows back
     * @throws if the statement fails to prepare
     */
    public function query(string $sql, array $binds=[]) {
        $pdo = $this->pdo;
        $stmt = $pdo->prepare($sql);
        if ($stmt===false){
            $error = var_export($pdo->errorInfo(),true);
            throw new \Exception("Sql problem: \n".$error."\n\n");
        }
        $stmt->execute($binds);
        $rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
        return $rows;
    }

    /**
     * Get rows from a table with the given $whereCols
     */
    public function select(string $tableName, array $whereCols=[]) {
        $sql = "SELECT * FROM `${tableName}` ";
        $binds = static::keysToBinds($whereCols);
        if (count($whereCols)>0){
            $whereStr = "Where ".static::whereSqlFromCols($whereCols);
            $sql .= $whereStr;
        }

        $rows = $this->query($sql, $binds);
        return $rows;
    }

    /**
     * Insert a row into the database
     * @throws Exception if the insert fails
     * @return the newly inserted id
     */
    public function insert(string $table, array $row){
        $pdo = $this->pdo;
        $cols = [];
        $binds = [];
        foreach ($row as $key=>$value){
            $cols[] = $key;
            $binds[":{$key}"] = $value;
        }
        $colsStr = '`'.implode('`, `',$cols).'`';
        $bindsStr = implode(', ', array_keys($binds));
        $query = "INSERT INTO `${table}`(${colsStr}) 
                VALUES (${bindsStr})
            ";
        $stmt = $pdo->prepare($query);
        if ($stmt===false){
            throw new \Exception("Could not insert values into databse.". print_r($pdo->errorInfo(),true));
        } 
        $stmt->execute($binds);
        if ($stmt->errorCode()!=='00000'){
            print_r($stmt->errorInfo());
            throw new \Exception("There was an error inserting data");
        }
        return $pdo->lastInsertId();
    }

    public function insertAll(string $table, array $rowSet){
        foreach ($rowSet as $row){
            $lastInsertId = $this->insert($table, (array)$row);
        }
        return $lastInsertId;
    }

    /**
     * Update an existing row. Shorthand for `updateWhere()` with the id column set as the where values.
     */
    public function update(string $table, array $newRowValues, string $idColumnName='id'){
        return $this->updateWhere($table, $newRowValues, [$idColumnName=>$newRowValues[$idColumnName]]);
    }

    /**
     *
     * @param $whereVals To update ALL rows, pass `[]`
     */
    public function updateWhere(string $table, array $newRowValues, array $whereVals){
        $valueBinds = [];
        $setSql = [];
        foreach ($newRowValues as $col=>$value){
            $valueBinds[$bindKey=':'.$col.'_value'] = $value;
            $setSql[] = "`$col` = $bindKey";
        }
        $setSql = implode(",\n", $setSql);

        $whereSql = static::whereSqlFromCols($whereVals);
        if (strlen(trim($whereSql))>0)$whereSql = "WHERE\n${whereSql}";

        $sql = <<<SQL
            UPDATE `${table}` 
            SET $setSql
            ${whereSql}
        SQL;

        $binds = array_merge($valueBinds, $whereVals);
        $binds  = static::keysToBinds($binds);
        $this->execute($sql,$binds);
    }

    /**
     * Delete rows from a table
     * @return true if any rows were deleted. false otherwise
     */
    public function delete(string $table, array $whereCols){
        $sql = static::whereSqlFromCols($whereCols);

        if ($sql!=null)$sql = 'WHERE '.$sql;
        $sql = "DELETE FROM `${table}` ${sql}";

        $stmt = $this->execute($sql, $whereCols);
        // var_dump($stmt->errorCode());
        // exit;
        // var_dump($stmt->rowCount());
        // exit;
        if ($stmt->errorCode()=='00000'
            &&$stmt->rowCount()>0)return true;
        return false;
        // return $stmt;
    }


    /**
     * Execute an Sql statement & get a PDOStatement back
     * @throws if the statement fails to prepare
     * @return PDOStatement
     */
    public function execute(string $sql, array $binds=[]) {
        $pdo = $this->pdo;
        $stmt = $pdo->prepare($sql);
        if ($stmt===false){
            $error = var_export($pdo->errorInfo(),true);
            throw new \Exception("Sql problem: \n".$error."\n\n");
        }
        $stmt->execute($binds);
        return $stmt;
    }
    /**
     * Alias for `execute()`
     * @return PDOStatement
     */
    public function exec(string $sql, array $binds=[]) {
        return $this->execute($sql, $binds);
    }

    /** get the pdo object 
    */
    public function getPdo(){
        return $this->pdo;
    }

    /** get the pdo object 
    */
    public function pdo(){
        return $this->pdo;
    }

    /**
     * Convert key=>value array into a 'WHERE' sql.
     *
     * @param $columns `['key'=>$val, ':key2'=>$val]`. `$val` can be string, array, or numeric.
     * @return string sql for a WHERE statement. Does not include `WHERE`
     * @exampleOutput: `key = :val1 AND key2 LIKE :val2, AND key3 IN (:val3_1,:val3_2)`. 
     */
    static public function whereSqlFromCols(array $columns){
        $binds = static::keysToBinds($columns);
        //generate sql
        $pieces = [];
        $copy = $binds;
        foreach ($copy as $k=>$v){
            $col = substr($k,1);
            if (is_string($v)){
                $pieces[] = "`$col` LIKE $k";
            } else if (is_array($v)){
                unset($binds[$k]);
                $inList = [];
                foreach ($v as $index=>$inValue){
                    $inKey = $k.$index;
                    $binds[$inKey] = $inValue;
                    $inList[] = $inKey;
                }
                $pieces[] = "`$col` IN (".implode(', ',$inList).")";
            } else {
                $pieces[] = "`$col` = $k";
            }
        }
        $sql = implode(' AND ', $pieces);
        return $sql;
    }

    /**
     * Convert an array `['key'=>$val, ':key2'=>$val]` into binds: `[':key'=>$val, ':key2'=>$val]`.
     *
     * @return array where keys are prefixed with a colon (:)
     */
    static public function keysToBinds(array $keyedValues){
        $binds = [];
        foreach ($keyedValues as $k=>$v){
            if (!is_string($k)){
                $binds[] = $v;
            } else if (substr($k,0,1)==':'){
                $binds[$k] = $v;
            } else {
                $binds[':'.$k] = $v;
            }
        }
        return $binds;
    }
}
<?php

namespace Tlf;

/**
 * A minimal class for handling sql migration. Create a migrations dir. Then create dirs like `v1`, `v2` & create files `up.sql`, `down.sql` in each versioned dir. Migrating from 1 to 2 will execute `v2/up.sql`. From 3 down to 1 will execute `v2/down.sql` and `v1/down.sql`. You may also make files like `v1/up-1.sql`, `v1/up-2.sql` to execute multiple files in order.
 *
 * @tagline Easy to use SQL Migrations from versioned directories
 */
class LilMigrations {

    /**
     * a pdo instance
     */
    public \PDO $pdo;

    /**
     * the dir for migrations scripts.
     */
    public string $dir;

    /**
     * In $dir, there should be directories named 'v1', 'v2', 'v3', and so on.
     * In the v1/v2/v3 dirs, there should be up.sql & down.sql files with valid SQL statements for whatever database you're using
     *
     * @param $pdo a pdo instance
     * @param $dir a directory path
     */
    public function __construct(\PDO $pdo, string $dir){
        $this->pdo = $pdo;
        $this->dir = $dir;
    }

    /**
     * Convenience method to initialize sqlite db in memory
     * @return Tlf\LilDb
     */
    static public function sqlite(string $dbName = ':memory:'){
        $pdo = new \PDO('sqlite:'.$dbName);
        $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
        $ldb = new static($pdo);
        return $ldb;
    }


    /**
     *
     * Migrate from old version to new
     *
     * @param $old the current version of the database
     * @param $new the new version of the database to go to
     */
    public function migrate(int $old, int $new){

        if ($old < $new){
            for ($i=$old+1; $i <= $new; $i++){
                $this->run_migration_version($i, 'up');
            }
        } else if ($old > $new) {
            for ($i=$old-1; $i >= $new; $i--){
                $this->run_migration_version($i, 'down');
            }
        } else {
            $this->run_migration_version($i, 'up');
        }
    }

    public function run_migration_version($version, $up_or_down){
        $i = $version;
        $file = $up_or_down;

        $v_dir = "v$i/";
        $migrate_dir = $this->dir.'/'.$v_dir;
        $files = is_dir($migrate_dir) ? scandir($migrate_dir) : false;
        if ($files==false){
            echo "\nMigrations dir $v_dir does not exist. Continuing.";
            return;
        }
        $files = array_filter($files, 
            function($v) use ($file){
                if (substr($v,0,strlen($file))==$file)return true;
                return false;
            });

        //@todo test the file sorting
        // // for testing
        // rsort($files);
        //
        // $files = ['up-9.sql', 'up-2.sql', 'up-13.sql', 'up-0.sql', 'up.sql', 'up-1.sql'];
        usort($files,
            function($v1, $v2){
                $pos1 = strpos($v1,'-');
                if ($pos1==false)$index1 = -1;
                else $index1 = (int)substr($v1,$pos1+1,-4);


                $pos2 = strpos($v2,'-');
                if ($pos2==false)$index2 = -1;
                else $index2 = (int)substr($v2,$pos2+1,-4);

                return $index1-$index2;
            }
        );

        foreach ($files as $f){
            $rel = $v_dir.$f;
            $exec_file = $this->dir.'/'.$rel;
            $exec_file = $this->dir.'/'.$rel;
            if (!file_exists($exec_file)){
                echo "\nFile '$rel' was not found for migrations.";
                continue;
            }
            echo "\nExecute '$rel'";
            $sql = file_get_contents($exec_file);
            $this->pdo->exec($sql);

            if ($this->pdo->errorCode()!='00000'){
                echo "\nSQL Error in '$rel':\n";
                print_r($this->pdo->errorInfo());
                return;
            }
        }

    }
}
<?php

namespace Tlf;

/** This is a minimal version of LilMigrations for debugging the properties issue */
class LilMigrationsBug {

    public $prop = 'okay';

    public function ok(){
        function() use ($file){
            return;
        };
        $abc = 'def';
    }
}
<?php

namespace Phad\Test\Integration;

/**
 * This class appears to test both form compilation and form submission
 *
 * @notice Several of these tests incidentally test the submit target/redirect feature.
 */
class Forms extends \Phad\Tester {

    protected array $blogTableColumns = ['id'=>'INTEGER PRIMARY KEY','title'=>'VARCHAR(200)', 'body'=>'VARCHAR(2000)'];

    public function testDeleteItem(){
        $lildb = \Tlf\LilDb::sqlite();
        $pdo = $lildb->pdo();
        $phad = $this->phad();
        $phad->pdo = $pdo;
        $lildb->create('blog',['id'=>'integer', 'title'=>'varchar(90)']);
        $lildb->insert('blog',['id'=>1,'title'=>'title 1']);
        $lildb->insert('blog',['id'=>2,'title'=>'title 2']);
        $lildb->insert('blog',['id'=>3,'title'=>'title 3']);


        $form = new \Phad\View('Form/Deleteable', $this->file('test/input/views/'), 
            ['id'=>2, 'phad'=>$phad]);
        $form->force_compile = true;
        $form->delete();

        $blogs = $lildb->select('blog');
        $this->compare(
            [ ['id'=>1,'title'=>'title 1'],
              ['id'=>3,'title'=>'title 3'],
            ],
            $blogs
        );

    }

    public function testErrorMessage(){
        $pdo = $this->getPdo();
        $phad = $this->phad();
        $phad->pdo = $pdo;
        $view = $phad->view('Form/SimpleBlogWithError');

        $_SERVER['HTTP_HOST'] = 'localhost';
        $_SERVER['HTTPS'] = 'non-empty-value';

        $BlogRow = ['body'=>'smol body', 'title'=>''];

        $out = $view->submit($BlogRow);
        
        $msg = $phad->validationErrorMessage($phad->failed_submit_columns);
        $this->test('Error Message Written');
            $this->str_not_contains($out, ['<error>','</error>']);
            $this->str_contains($out, '<div class="my-error-class">'.$msg.'</div>');

        $this->test('Headers empty');
            $this->compare(
                [],
                $phad->getHeaders(),
            );
    }

    public function testSubmitDocumentation(){
        $_SERVER['HTTP_HOST'] = 'localhost';
        $_SERVER['HTTPS'] = 'non-empty-value';

        $ldb = \Tlf\LilDb::sqlite();
        $pdo = $ldb->pdo();
        
        $ldb->create('blog', $this->blogTableColumns);

        $phad = $this->phad();
        $phad->pdo = $pdo;
        $view = $phad->view('Form/SimpleBlogNoTarget');

        //if `id` were set, an UPDATE would be done instead.
        $BlogRow = ['title'=>'Fine Title', 'body'=>'I have to be at least 50 characters. But that isn\'t very long.'];
        $out = $view->submit($BlogRow);
        $BlogRow['id'] = $pdo->lastInsertId();

        $headers = $phad->getHeaders();
        //you can foreach(as $h){ header(...$h) }
        //@export_end(Forms.ManualSubmission)

        $this->test('Headers');
            $this->compare(
                [['Location: https://localhost/', true]],
                $phad->getHeaders(),
            );

        $this->test('Data Was Inserted');
            $this->compare(
                [$BlogRow],
                $ldb->query('SELECT * FROM blog')
            );
    }

    public function testControllerOnSubmitDocumentation(){
        $phad = new class() extends \Phad {
            public function onSubmit($ItemData, &$ItemRow){
                if ($ItemData->name!='Blog')return true;
                $ItemRow['slug'] = str_replace(' ', '-', strtolower($ItemRow['title']));
                return true;
            }
        };
        $pdo = $this->getPdo();
        $phad = $this->phad($phad);
        $phad->pdo = $pdo;
        $phad->target_url = '/blog/{slug}/{id}/';
        $cols = $this->blogTableColumns;
        $cols['slug'] = 'VARCHAR(100)';
        $this->createTable($pdo, 'blog', $cols);

        $_SERVER['HTTP_HOST'] = 'localhost';
        $_SERVER['HTTPS'] = 'non-empty-value';

 
        $BlogRow = 
            [
            'title'=>'Fine Title', 
            'body'=>'I have to be at least fifty characters. That shouldn\'t be much of a problem, though it does require a bit more typing. And if I had something original to say, that would make it better.'
            ];
        /** anonymous class to use as our controller */
        /** passing our custom controller & submitting manually */
        $view = $phad->view('Form/SimpleBlogNoTarget');
        /** $BlogRow is just an array with 'title' & 'body' **/
        $output = $view->submit($BlogRow);
        
        $BlogRow['id'] = $pdo->lastInsertId();
        $BlogRow['slug'] = 'fine-title';

        $this->test('There should be no output');
            $this->handleDidPass(strlen(trim($output))===0);

        $this->test('Headers');
            $this->compare(
                [['Location: https://localhost/blog/fine-title/'.$BlogRow['id'].'/', true]],
                $phad->getHeaders(),
            );

        $this->test('Data Was Inserted');
            $this->compare(
                $BlogRow,
                $this->queryOne($pdo, 'SELECT * FROM blog'),
            );
    }

    public function testWithInlineOnSubmit(){
        $pdo = $this->getPdo();
        $phad = $this->phad();
        $phad->pdo = $pdo;
        $phad->target_url = '/blog/{slug}/{id}/';
        $cols = $this->blogTableColumns;
        $cols['slug'] = 'VARCHAR(100)';
        $this->createTable($pdo, 'blog', $cols);

        $_SERVER['HTTP_HOST'] = 'localhost';
        $_SERVER['HTTPS'] = 'non-empty-value';

 
        $BlogRow = 
            [
            'title'=>'Fine Title', 
            'body'=>'I have to be at least fifty characters. That shouldn\'t be much of a problem, though it does require a bit more typing. And if I had something original to say, that would make it better.'
            ];

        $view = $phad->view('Form/BlogWithOnSubmit');
        $output = $view->submit($BlogRow);
        
        $BlogRow['id'] = $pdo->lastInsertId();
        $BlogRow['slug'] = 'fine-title';

        $this->test('Backend Prop is removed');
            $this->str_not_contains($phad->view('Form/BlogWithOnSubmit', $BlogRow), 'type="backend"');

        $this->test('<onsubmit> tag was removed');
            $this->str_not_contains($phad->view('Form/BlogWithOnSubmit', $BlogRow), '<onsubmit>');

        $this->test('There should be no output');
            $this->handleDidPass(strlen(trim($output))===0);

        $this->test('Headers');
            $this->compare(
                [['Location: https://localhost/blog/fine-title/'.$BlogRow['id'].'/', true]],
                $phad->getHeaders(),
            );

        $this->test('Data Was Inserted');
            $this->compare(
                $BlogRow,
                $this->queryOne($pdo, 'SELECT * FROM blog'),
            );
    }
    public function testInsertWithValidOption(){
        $pdo = $this->getPdo();
        $phad = $this->phad();
        $phad->pdo = $pdo;
        $view = $phad->view('Form/BlogWithCategories');
        $cols = $this->blogTableColumns;
        $cols['category'] = 'VARCHAR(100)';
        $this->createTable($pdo, 'blog', $cols);

        $_SERVER['HTTP_HOST'] = 'localhost';
        $_SERVER['HTTPS'] = 'non-empty-value';

        $BlogRow = ['title'=>'Police Brutality super sucks', 'body'=>'Its been well documented that police brutality is a reality, yet there\'s still overwhelming controversy about what we should do with our society. Some say: Let the police to what they gotta do. Others say: Lets rethink this society that\'s built upon punishing people who misbehave & actually help people instead. Mayb ewe could redirect some of the MASSIVE tax dollars that go to police departments to actually help someone. That\'s me. I say that. - Reed',
            'category'=>'Police Brutality'];

        $out = $view->submit($BlogRow);
        
        $BlogRow['id'] = $pdo->lastInsertId();

        $this->test('There should be no output');
            $this->handleDidPass(strlen(trim($out))===0);

        $this->test('Headers');
            $this->compare(
                [['Location: https://localhost/blog/'.$BlogRow['title'].'/', true]],
                $phad->getHeaders(),
            );

        $this->test('Data Was Inserted');
            $this->compare(
                $BlogRow,
                $this->queryOne($pdo, 'SELECT * FROM blog'),
            );
    }

    public function testUpdateRedirectsToTarget(){
        // $phad = $this->phad();
        $pdo = $this->getPdo();
        // $phad->pdo = $pdo;
        $this->createTable($pdo, 'blog', $this->blogTableColumns);

        $_SERVER['HTTP_HOST'] = 'localhost';
        $_SERVER['HTTPS'] = 'non-empty-value';

        
        $phad = new class() extends \Phad {
            public function t(){
                echo "\ntttttttttttttttt\n";
            }
            public function objectFromRow($ItemData, $BlogRow){
                $Blog = (object)$BlogRow;
                $Blog->slug = str_replace(' ', '-', strtolower($Blog->title));
                return $Blog;
            }
        };
        $phad = $this->phad($phad);
        $phad->target_url = '/blog/{slug}/{id}/';
        $phad->pdo = $pdo;

        $view = $phad->view('Form/SimpleBlogNoTarget', ['phad'=>$phad]);

        $BlogRow = 
            [
            'title'=>'Fine Title', 
            'body'=>'I have to be at least fifty characters. That shouldn\'t be much of a problem, though it does require a bit more typing. And if I had something original to say, that would make it better.'
            ];

        $out = $view->submit($BlogRow);
        
        $BlogRow['id'] = $pdo->lastInsertId();

        $this->test('There should be no output');
            $this->handleDidPass(strlen(trim($out))===0);

        $this->test('Headers');
            $this->compare(
                [['Location: https://localhost/blog/fine-title/'.$BlogRow['id'].'/', true]],
                $phad->getHeaders(),
            );

        $this->test('Data Was Inserted');
            $this->compare(
                $BlogRow,
                $this->queryOne($pdo, 'SELECT * FROM blog'),
            );
    }

    public function testUpdateValid(){
        $_SERVER['HTTP_HOST'] = 'localhost';
        $_SERVER['HTTPS'] = 'non-empty-value';
        $ldb = \Tlf\LilDb::sqlite();
        $phad = $this->phad();
        $phad->pdo = $ldb->pdo();
        $view = $phad->view('Form/SimpleBlog');
        $ldb->create('blog', $this->blogTableColumns);

        $BlogRow = ['id'=>0, 'title'=>'Fine Title', 'body'=>'I have to be at least fifty characters. That shouldn\'t be much of a problem, though it does require a bit more typing. And if I had something original to say, that would make it better.'];
        $ldb->insert('blog', $BlogRow);
        $UpdatedBlog = $BlogRow;
        $UpdatedBlog['title'] = 'New Title';



        $out = $view->submit($UpdatedBlog);

        $this->test('Headers');
            $this->compare(
                [['Location: https://localhost/blog/'.$UpdatedBlog['title'].'/', true]],
                $phad->getHeaders(),
            );

        $this->test('Data Was Updated');
            $this->compare(
                [$UpdatedBlog],
                $ldb->query('SELECT * FROM blog')
            );
        
        $this->test('No Output Present');
            $this->compare(
                '',
                trim($out)
            );
    }

    public function testInsertValid(){
        $phad = $this->phad();
        $phad->pdo = $this->getPdo();
        $view = $phad->view('Form/SimpleBlog');
        $this->createTable($phad->pdo, 'blog', $this->blogTableColumns);

        $_SERVER['HTTP_HOST'] = 'localhost';
        $_SERVER['HTTPS'] = 'non-empty-value';

        $BlogRow = ['title'=>'Fine Title', 'body'=>'I have to be at least fifty characters. That shouldn\'t be much of a problem, though it does require a bit more typing. And if I had something original to say, that would make it better.'];

        $out = $view->submit($BlogRow);
        
        $BlogRow['id'] = $phad->pdo->lastInsertId();

        $this->test('There should be no output');
            $this->handleDidPass(strlen(trim($out))===0);

        $this->test('Headers');
            $this->compare(
                [['Location: https://localhost/blog/'.$BlogRow['title'].'/', true]],
                $phad->getHeaders(),
            );

        $this->test('Data Was Inserted');
            $this->compare(
                $BlogRow,
                $this->queryOne($phad->pdo, 'SELECT * FROM blog'),
            );
    }

    /**
     * @test that a partially filled in form is returned when submission fails.
     */
    public function testSubmitInvalid(){
        $phad = $this->phad();
        $phad->force_compile = false;
        $this->createTable($phad->pdo, 'blog', $this->blogTableColumns);

        // View contains: 
        // <textarea name="body" maxlength="2000" minlength="50"></textarea>
        $view = $phad->view('Form/SimpleBlog');


        // should fail because body is less than 50 chars
        $Blog = ['title'=>'Fine Title', 'body'=>'body too short'];
        $out = $view->submit($Blog);
        $Blog = (object)$Blog;


        echo $out;
        
        $this->test('Form cleaned up');
            $this->str_not_contains($view, ['item=']);

        $this->test('Submitted Blog Content');
            $this->str_contains($out, 'value="'.$Blog->title.'"');
            $this->str_contains($out, '>'.$Blog->body.'</textarea>');
    }

    public function testDisplayWithNoObject(){
        $view = $this->view('Form/SimpleBlog');

        $Blog = ['title'=>'Fine Title', 'body'=>'body too short'];
        $out = $view->outputWithEmptyObject($Blog);
        $Blog = (object)$Blog;

        
        echo $out;

        $this->test('Form cleaned up');
            $this->str_not_contains($out, ['item=']);
        $this->test('Target Attribute Removed');
            $this->str_not_contains($out, 'target="');

        $this->test('Submitted Blog Content');
            $this->str_contains($out, 'value=""');
            $this->str_contains($out, '></textarea>');

    }

    /**
     * @test getting each selectable-option from a form's compiled view
     */
    public function testHasSelectOptions(){
        $view = $this->view('Form/BlogWithCategories');
        $ItemData = $view->getItemData();

        $expect = [
            'title' => 
            [
                'type' => 'text',
                'maxlength' => '75',
                'tagName' => 'input',
            ],
            'body' => 
            [
                'maxlength' => '2000',
                'minlength' => '50',
                'tagName' => 'textarea',
            ],
            'category'=>
            [
                'tagName'=> 'select',
                'options'=>[
                    "social-justice",
                    "policy",
                    "Police Brutality",
                    "Election",
                ],
            ],
            'id'=>
            [
                'tagName'=>'input',
                'type'=>'hidden',
            ]
        ];
        $this->compare($expect, $ItemData->properties);
    }

    /**
     * @test getting info about properties from the compiled view.
     */
    public function testHasPropertiesData(){
        $view = $this->view('Form/SimpleBlog');
        $ItemData = $view->getItemData();

        $expect = [
            'title' => 
            [
                'type' => 'text',
                'maxlength' => '75',
                'tagName' => 'input',
            ],
            'body' => 
            [
                'maxlength' => '2000',
                'minlength' => '50',
                'tagName' => 'textarea',
            ],
            'id'=>
            [
                'tagName'=>'input',
                'type'=>'hidden',
            ]
        ];
        $this->compare($expect, $ItemData->properties);
    }
}
<?php

namespace Taeluf\PHTML;

class Compiler {
    

    /**
     * An array of code to output.
     * Likely contains placeholder which will be replaced. 
     * May contain objects which implement __toString
     */
    protected $code = [];

    /**
     * The content of a PHP file for compilation
     */
    protected $src;
    /**
     * An array of placeholder code with codeId => [prependedCode, code, appendedCode]... there can be any number of entries for each codeId
     * Code may be string or an object which implements __toString
     * codeIds are either sha sums (alpha-numeric, i think) or randmoized alpha
     */
    protected $placeholder = [];
    /**
     * The parsed source code, with the PHP code replaced by placeholders
     */
    protected $htmlSource;

    public function __construct(){

    }
    /**
     * Replaces inline PHP code with placeholder, indexes the placeholder, and returns the modified code
     *
     * @param  mixed $srcCode - The source code
     * 
     * @return string - source code with all PHP replaced by codeIds
     */
    public function cleanSource($srcCode): string{
        $parser = new PHPParser($srcCode);
        
        $parsed = $parser->pieces();
        foreach ($parsed->php as $id=>$code){
            $this->placeholder[$id] = [$code];
        }
        return $parsed->html;
    }
    /**
     * 1. Generates an id
     * 2. indexes the passed-in-code with that id
     * 3. Returns the id.
     *
     * @param  mixed $phpCodeWithOpenCloseTags - Code, as it would be found in a PHP file. AKA PHP code MUST include open/close tags
     * @return string the codeId. Either a random alpha-string OR an sha_sum, which I think is alpha-numeric
     */
    public function placeholderFor($phpCodeWithOpenCloseTags): string{

        $code = $phpCodeWithOpenCloseTags;
        $id = $this->freshId();
        $this->placeholder[$id] = [$code];
        return $id;
    }
    
    /**
     * Appends code to the output-to-be
     *
     * @param  mixed $code - Code to append. PHP code must be wrapped in open/close tags
     * @return void
     */
    public function appendCode($code){
        $this->code[] = $code;
    }    
    /**
     * Prepends code to the output-to-be
     *
     * @param  mixed $code - Code to prepend. PHP code must be wrapped in open/close tags
     * @return void
     */
    public function prependCode($code){
        // $this->code[] = $code;
        array_unshift($this->code,$code);
    }    
    /**
     * Prepend code immediately prior to the given placeholder
     *
     * @param  mixed $placeholder - a placeholder from placeholderFor()
     * @param  mixed $code - a block of code. PHP must be wrapped in open/close tags
     * @return void
     */
    public function placeholderPrepend($placeholder,$code){
        array_unshift($this->placeholder[$placeholder],$code);
    }
        
    /**
     * Append code immediately after the given placeholder
     *
     * @param  mixed $placeholder - a placeholder from placeholderFor()
     * @param  mixed $code - a block of code. PHP must be wrapped in open/close tags
     * @return void
     */
    public function placeholderAppend($placeholder,$code){
        $this->placeholder[$placeholder][] = $code;
    }
    
    /**
     * Compile the code into a string & return it. 
     * output() can be called several times as it does NOT affect the state of the compiler.
     *
     * @return string
     */
    public function output(): string{
        // print_r($this->code);
        // // echo $this->code[0]->;
        // exit;
        // print_r($this->placeholder);
        $code = implode("\n",$this->code);
        // return $code;
        $ph = [];
        foreach ($this->placeholder as $id=>$codeArray){
            $ph[$id] = implode('',$codeArray);
        }
        $last = $code;
        while($last != $code = str_replace(array_keys($ph),$ph,$code))$last=$code;
        return $code;
    }
    
    /**
     * Writes the compiled output to the given file
     *
     * @param string $file - an absolute filepath
     * @param $chmodTo - REMOVED DOES NOTHING
     * 
     *          0644 or whatever. If null, chmod will not be run.
     *          See https://www.php.net/manual/en/function.chmod.php
     *          Permissions are as follows:
     *              Value    Permission Level
     *               200        Owner Write
     *               400        Owner Read
     *               100        Owner Execute
     *                40         Group Read
     *                20         Group Write
     *                10         Group Execute
     *                 4         Global Read
     *                 2         Global Write
     *                 1         Global Execute
     * @return boolean true if file_put_contents succeeds. False otherwise.
     */
    public function writeTo(string $file, $chmodTo=null): bool {
        $output = $this->output();
        if (!is_dir(dirname($file))){
            mkdir(dirname($file),0771,true);
            // chmod(dirname($file),0770);
        }
        $didPut = file_put_contents($file,$output);
        if ($chmodTo!==null){
            // chmod($file,$chmodTo);
        }
        if ($didPut===false)return false;
        else return true;
    }
    
    /**
     * Get an absolute file path which can be included to execute the given code
     * 
     * 1. $codeId = sha1($code)
     * 2. file_put_contents("$compileDir/$codeId.php", $code)
     * 3. return the path of the new file
     * 
     * - Will create the directory (non-recursive) if not exists
     *
     * @param  mixed $compileDir - the directory in which the file should be written
     * @param  mixed $code - the block of code. PHP code must be wrapped in open/close tags to be executed
     * @return string an absolute file path to a php file
     */
    public function fileForCode($compileDir,$code): string{
        // $codeId = $this->freshId(30);
        $codeId = sha1($code);
        $file = $compileDir.'/'.$codeId.'.php';
        if (!file_exists($compileDir))mkdir($compileDir,0770,true);
        file_put_contents($file,$code);
        return $file;
    }
    
    /**
     * Generate a random string of lowercase letters
     *
     * @param  mixed $length The desired length of the random string. Default is 26 to avoid any clashing
     * @return string the random string
     */
    protected function freshId($length = 26): string {
        $characters = 'abcdefghijklmnopqrstuvwxyz';
        $charactersLength = strlen($characters);
        $randomString = '';
        for ($i = 0; $i < $length; $i++) {
            $randomString .= $characters[rand(0, $charactersLength - 1)];
        }
        return $randomString;
    }    
    /**
     * Get the code for the given code id.
     * 
     * Placeholder code is stored as an array to enable the placeholderPrepend|Append functions, so I make it available as an array if you want.
     * 
     *
     * @param  string $codeId - the id generated by placeholderFor()
     * @param  bool $asArray - TRUE to get the code as it's array parts. FALSE to implode the array (no newlines) & return that
     * @return mixed an array of code pieces that make up this codeid or a string of the code
     */
    public function codeForId(string $codeId,bool $asArray=false){
        $codeArr = $this->placeholder[$codeId];
        if ($asArray)return $codeArr;
        else return implode('',$codeArr);
    }
}
<?php

namespace Taeluf\PHTML;

/**
* less sucky HTML DOM Element
*
* This class extends PHP's DOMElement to make it suck less
*
* The original version of this file was a pre-made script by the author below.
* The only meaningful pieces of code I kept are the two `if 'innerHTML'` blocks of code.
* No license information was available in the copied code and I don't remember what it said on the author's website.
*
* The original package had the following notes from the author:
* 
*	- Authored by: Keyvan Minoukadeh - http://www.keyvan.net - keyvan@keyvan.net
*   - See: http://fivefilters.org (the project this was written for)
*
* 
*/
class Node extends \DOMElement
{


    // public $hideOwnTag = false;

	// protected $children = [];
    //

	public function __construct(){
		parent::__construct();

		// $children = [];
        // foreach ($this->childNodes as $childNode){
            // $children[] = $childNode;
        // }
        // $this->children = $children;
	}

    /** is this node the given tag
    */
    public function is(string $tagName): bool{
        if (strtolower($this->tagName)==strtolower($tagName))return true;
        return false;
    }

    /**
     * @alias for DOMDocument::hasAttribute();
     */
    public function has(string $attribute): bool {
        return $this->hasAttribute($attribute);
    }

    /** get an array of DOMAttrs on this node
     */
	public function attributes(){
		$attrs = $this->attributes;
		$list = [];
		foreach ($attrs as $attr){
			$list[] = $attr;
		}
		return $list;
	}

    /** return an array of attributes ['attributeName'=>'value', ...];
     */
    public function attributesAsArray(){
        $list = [];
        foreach ($this->attributes as $attr){
            $list[$attr->name] = $attr->value;
        }
        return $list;
    }

	/**
	* Used for setting innerHTML like it's done in JavaScript:
	* @code
	* $div->innerHTML = '<h2>Chapter 2</h2><p>The story begins...</p>';
	* @endcode
	*/
	public function __set($name, $value) {
		if (strtolower($name) == 'innerhtml') {
			// first, empty the element
			for ($x=$this->childNodes->length-1; $x>=0; $x--) {
				$this->removeChild($this->childNodes->item($x));
			}
			// $value holds our new inner HTML
			if ($value != '') {
				$f = $this->ownerDocument->createDocumentFragment();
				// appendXML() expects well-formed markup (XHTML)
				$result = @$f->appendXML($value); // @ to suppress PHP warnings
				if ($result) {
					if ($f->hasChildNodes()) $this->appendChild($f);
				} else {
					// $value is probably ill-formed
					$f = new DOMDocument();
					$value = mb_convert_encoding($value, 'HTML-ENTITIES', 'UTF-8');
					// Using <htmlfragment> will generate a warning, but so will bad HTML
					// (and by this point, bad HTML is what we've got).
					// We use it (and suppress the warning) because an HTML fragment will 
					// be wrapped around <html><body> tags which we don't really want to keep.
					// Note: despite the warning, if loadHTML succeeds it will return true.
					$result = @$f->loadHTML('<htmlfragment>'.$value.'</htmlfragment>');
					if ($result) {
						$import = $f->getElementsByTagName('htmlfragment')->item(0);
						foreach ($import->childNodes as $child) {
							$importedNode = $this->ownerDocument->importNode($child, true);
							$this->appendChild($importedNode);
						}
					} else {
						// oh well, we tried, we really did. :(
						// this element is now empty
					}
				}
			}
		} else {
			$this->setAttribute($name,$value);
			return;
			$trace = debug_backtrace();
			trigger_error('Undefined property via __set(): '.$name.' in '.$trace[0]['file'].' on line '.$trace[0]['line'], E_USER_NOTICE);
		}
	}

    /**
     * if the node has the named attribute, it will be removed. Otherwise, nothing happens
     */
  public function __unset($name){
        if ($this->hasAttribute($name))$this->removeAttribute($name);
  }
    public function __isset($name){
        return $this->hasAttribute($name);
    }
	/**
	* Used for getting innerHTML like it's done in JavaScript:
	* @code
	* $string = $div->innerHTML;
	* @endcode
	*/	
	public function __get($name)
	{
        if (method_exists($this, $getter = 'get'.strtoupper($name))){
            return $this->$getter();
        } else if ($name=='doc'){
            return $this->ownerDocument;
        } else if (strtolower($name) == 'innerhtml') {
                $inner = '';
                foreach ($this->childNodes as $child) {
                    $inner .= $this->ownerDocument->saveXML($child);
                }
                return $inner;
            } else if ($name=='form'&&strtolower($this->tagName)=='input'){
            $parent = $this->parentNode ?? null;
            while ($parent!=null&&strtolower($parent->tagName)!='form')$parent = $parent->parentNode ?? null;
            return $parent;
        } else if ($name=='inputs' && strtolower($this->tagName)=='form'){
            $inputList = $this->doc->xpath('//input', $this);
            // var_dump($inputList);
            // exit;
            return $inputList;
        } else if ($name=='children'){
            $children = [];
            for ($i=0;$i<$this->childNodes->count();$i++){
                $children[] = $this->childNodes->item($i);
            }
            return $children;
        }
        else if ($this->hasAttribute($name)){
            return $this->getAttribute($name);
        } else {
            return null;
        }
		// $trace = debug_backtrace();
		// trigger_error('Undefined property via __get(): '.$name.' in '.$trace[0]['file'].' on line '.$trace[0]['line'], E_USER_NOTICE);
		// return null;
	}

    public function __toString()
    {

        return $this->ownerDocument->saveHTML($this);
        // return '['.$this->tagName.']';
    }

    public function xpath($xpath){
        return $this->doc->xpath($xpath, $this);
    }

	/**
	 * Adds a hidden input to a form node
	 * If a hidden input already exists with that name, do nothing
	 * If a hidden input does not exist with that name, create and append it
	 *
	 * @param  mixed $key
	 * @param  mixed $value
	 * @throws \BadMethodCallException if this method is called on a non-form node
	 * @return void
	 */
	public function addHiddenInput($inputName, $value){
		if (strtolower($this->tagName)!='form')throw new \BadMethodCallException("addHiddenInput can only be called on a Form node");
        $xPath = new \DOMXpath($this->ownerDocument);
        $inputs = $xPath->query('//input[@name="'.$inputName.'"][@type="hidden"]');
        if (count($inputs)>0)return;
		$input = $this->ownerDocument->createElement('input');
		$input->setAttribute('name',$inputName);
		$input->setAttribute('value',$value);
		$input->setAttribute('type','hidden');
		$this->appendChild($input);
	}
	
	/**
	 * Find out if this node has a true value for the given attribute name.
	 * Literally just returns $this->hasAttribute($attributeName)
	 * 
	 * I wanted to implement an attribute="false" option... but that goes against the standards of HTML5, so that idea is on hold.
	 * 
	 * See https://stackoverflow.com/questions/4139786/what-does-it-mean-in-html-5-when-an-attribute-is-a-boolean-attribute 
	 *
	 * @param  mixed $attributeName The name of the attribute we're checking for.
	 * @return bool
	 */
	public function boolAttribute($attributeName){
		return $this->hasAttribute($attributeName);
	}

    public function getInnerText(){
        return $this->textContent;
    }

    public function __call($method, $args){
        if (substr($method,0,2)=='is'){
            $prop = lcfirst(substr($method,2));
            if ($this->has($prop)&&$this->$prop != 'false')return true;
            return false;
        }

        throw new \BadMethodCallException("Method '$method' does not exist on ".get_class($this));
    }
}

<?php

namespace Taeluf\PHTML;

/**
 * Parses .php files into:
 *  1. A string with placeholders for the PHP code
 *  2. An array of PHP code, identified by their placeholders
 * 
 */
class PHPParser {
    
    /**
     * The source HTML + PHP code
     *
     * @var string
     */
    protected string $src;
    /**
     * The parsed pieces of code in the format:
     *  [
     *      'html' => '<div>A string of code with php placeholders like <b>phpadsfwefhaksldfjaskdlfjaskldfjasldfkphp</b> </div> and trailing text...',
     *      'php'  => [
     *          'phpadsfwefhaksldfjaskdlfjaskldfjasldfkphp' => '<?="Something echod";?>', 
     *          'phpid2'=>'<?php // another code block/?>'
     *      ]
     *  ]
     * The array is simply (object) cast
     */
    protected object $pieces;
    
    /**
     * Create a new PHP parser instance from a string
     *
     * @param  mixed $htmlPHPString - a block of HTML + PHP code. PHP code will be inside open (<?php or <?=) and close (?>) tags
     * @return void
     */
    public function __construct(string $htmlPHPString){
        $this->src = $htmlPHPString;
        $this->pieces = $this->separatePHP();
    }

        
    /**
     * Return the parsed pieces. See doc for protected $pieces
     *
     * @return object
     */
    public function pieces(): object{
        return $this->pieces;
    }
    /** Separate the source code into it's pieces. See the protected $pieces docs
     *
     * @return object just an array cast to object
     */
    protected function separatePHP(): object{
        $tokens = $this->tokens();
        $str = '';
        $inPHP = false;
        $phpCode = '';
        $phpList = [];
        foreach ($tokens as $index => $token){
            $token = (object)$token;
            if ($token->type=='T_OPEN_TAG'
                ||$token->type=='T_OPEN_TAG_WITH_ECHO'){
                $inPHP = true;
            }
            if (!$inPHP){
                $str .= $token->code;
            }
            if ($inPHP){
                $phpCode .= $token->code;
            }
            if ($token->type=='T_CLOSE_TAG'){
                $id = 'php'.$this->randomAlpha().'php';
                $phpList[$id] = $phpCode;
                $phpCode = '';
                $str .= $id;
                $inPHP = false;
            }
        }
        return (object)[
            'php'=>$phpList,
            'html'=>$str
        ];

    }
        
    /**
     * Generates a random string of characters a-z, all lowercase & returns them
     *  this is used for the PHP placeholders
     * 
     * @param int $length
     * @return string
     */
    protected function randomAlpha($length = 26): string {
        return static::getRandomAlpha($length);
    }
    /**
     * Generates a random string of characters a-z, all lowercase & returns them
     *  this is used for the PHP placeholders
     * 
     * @param int $length
     * @return string
     */
    static public function getRandomAlpha($length = 26): string {
        $characters = 'abcdefghijklmnopqrstuvwxyz';
        $charactersLength = strlen($characters);
        $randomString = '';
        for ($i = 0; $i < $length; $i++) {
            $randomString .= $characters[rand(0, $charactersLength - 1)];
        }
        return $randomString;
    }
    
        
    /**
     * Tokenize the src code into a slightly better format than token_get_all
     *
     * @return array of tokens
     */
    protected function tokens(): array{
        $content = $this->src;
        $tokens = token_get_all($content);
        $niceTokens = [];

        $delLine = null;
        foreach ($tokens as $index=>$token){
            $tok = [];
            if (!is_array($token)){
                $lastTok = array_slice($niceTokens,-1)[0];
                $tok['type'] = "UNNAMED_TOKEN";
                $tok['code'] = $token;
                $tok['line'] = $lastTok['line'];
            } else {
                $tok['type'] = token_name($token[0]);
                $tok['code'] = $token[1];
                $tok['line'] = $token[2];
            }
            // This is old code for an idea I had
            // if ($tok['type']=='T_STRING'&&$tok['code']=='PHPPlus'){
                // $next = $tokens[$index+1];
                // if (is_array($next)&&$next[1]=='::'){
                    // $delLine = $tok['line'];
                    // echo 'del line is '.$delLine."\n\n";
                // }
            // }
            $niceTokens[] = $tok;
        }
        foreach ($niceTokens as $index=>$token){
            if ($token['line']===$delLine){
                unset($niceTokens[$index]);
            }
        }
        return $niceTokens;
    }

}
<?php

namespace Taeluf;

/**
 * Makes DUMDocument... less terrible, but still not truly good
 * 
 */
class Phtml extends \DOMDocument {
    
    /**
     * The source HTML + PHP code
     *
     * @var string
     */
    protected string $src;    
    // /**
    //  * True if the source html had a '<html>' tag
    //  * Except we're not implementing that???
    //  * @var bool
    //  */
    // protected bool $isHTMLDoc = false;

    /**
     * The source code with all the PHP replaced by placeholders
     */
    protected string $cleanSrc;
        
    /**
     * [ 'phpplaceholder' => $phpCode, 'placeholder2' => $morePHP ]
     *
     */
    protected array $php;

    /**
     * A random string used when adding php code to a node's tag declaration. This string is later removed during output()
     */
    protected $phpAttrValue;
    
    /**
     * Create a DOMDocument, passing your HTML + PHP to __construct. 
     * 
     *
     * @param mixed $html a block of HTML + PHP code. It does not have to have PHP. PHP will be handled gracefully.
     * @return void
     */
    public function __construct($html)
    {
        parent::__construct();

        $this->srcHTML = $html;

        $parser = new PHTML\PHPParser($html);
        $enc = $parser->pieces();
        $this->php = $enc->php;
        $this->cleanSrc = $enc->html;
        $this->cleanSrc = $this->cleanHTML($this->cleanSrc);
        $hideXmlErrors=true;
        libxml_use_internal_errors($hideXmlErrors);
        $this->registerNodeClass('DOMElement', '\\Taeluf\\PHTML\\Node');
        $this->registerNodeClass('DOMText', '\\Taeluf\\PHTML\\TextNode');
        // $this->registerNodeClass('DOMText', 'RBText');

        $html = '<root>'.$this->cleanSrc.'</root>';
        $this->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
        $this->formatOutput = true;
        libxml_use_internal_errors(false);

    }    


    public function placeholder(string $string): string{
        $placeholder = PHTML\PHPParser::getRandomAlpha();
        $placeholder = 'php'.$placeholder.'php';
        $this->php[$placeholder] = $string;
        return $placeholder;
    }

    /**
     * Get the code that's represented by the placeholder
     * @return the stored code or null
     */
    public function codeFromPlaceholder(string $placeholder): ?string {
        $code = $this->php[trim($placeholder)] ?? null;
        return $code;
    }

    /**
     * Get a placeholder for the given block of code
     * Intention is to parse a single '<?php //piece of php code ?>' and not '<?php //stuff ?><?php //more stuff?>'
     * When used as intended, will return a single 'word' that is the placeholder for the given code
     *
     * @param  mixed $enclosedPHP an HTML + PHP string
     * @return string the parsed block of content where PHP code blocks are replaced by placeholders.
     */
    public function phpPlaceholder(string $enclosedPHP): string{
        $parser = new PHTML\PHPParser($enclosedPHP);
        $enc = $parser->pieces();

        // This block doesn't work because it's over-eager. A workaround to just add code, regardless of open/close tags, would be good.
        // if (count($enc->php)==0){
            // $code = \PHTML\PHPParser::getRandomAlpha();
            // $enc->php = ["php${code}php"=>$enclosedPhp];
            // $enc->html = $code;
        // }
        $this->php = array_merge($this->php,$enc->php);
        return $enc->html;
    }

    /**
     * Decode the given code by replacing PHP placeholders with the PHP code itself
     *
     * @param  mixed $str
     * @return void
     */
    public function fillWithPHP(string $codeWithPlaceholders): string{
        $decoded = str_replace(array_keys($this->php),$this->php,$codeWithPlaceholders);
        return $decoded;
    }    
    /**
     * See output()
     *
     * @return string 
     */
    public function __toString()
    {
        return $this->output();
    }

    /**
     * Return the decoded document as as tring. All PHP will be back in its place
     *
     * @param  mixed $withPHP passing FALSE means placeholders will still be present & PHP code will not be
     * @return string the final document with PHP where it belongs
     */
    public function output($withPHP=true){
        // echo "\n".'-start output call-'."\n";
        $list = $this->childNodes[0]->childNodes;

        $hiddenTagsNodes = $this->xpath('//*[@hideOwnTag]');
        foreach ($hiddenTagsNodes as $htn){
            if ($htn->hideOwnTag==false||$htn->hideOwnTag=='false'){
                unset($htn->hideOwnTag);
                continue;
            }
            $parent = $htn->parentNode;
            $childNodeList = $htn->children;
            foreach ($childNodeList as $child){
                $htn->removeChild($child);
                $parent->insertBefore($child, $htn);
            }
            $parent->removeChild($htn);
        }
        $html = '';
        foreach ($list as $item){
            $html .= $this->saveHTML($item);
        }

        /** Run the php-code-replacer as long as there is a placeholder (while preventing infinite looping) */
        $html = $this->fill_php($html, $withPHP);
        
        $html = $this->restoreHtml($html);

        return $html;
    }

    public function fill_php($html, $withPHP=true){
        $maxIters = 25;
        $iters = 0;
        while ($iters++<$maxIters&&preg_match('/php([a-zA-Z]{26})php/', $html, $match)){
            foreach ($this->php as $id=>$code){
                if ($withPHP)$html = str_replace($id,$code,$html);
                else $html = str_replace($id,'',$html);
            }
        }

        if (($phpAttrVal=$this->phpAttrValue)!=null){
            $html = str_replace("=\"$phpAttrVal\"", '', $html);
        }
        return $html;
    }
    
    /**
     * get the results of an xpath query
     *
     * @param  mixed $xpath the xpath query, such as: //tagname[@attributename="value"]
     *                  If you use a refnode, prepend '.' at the beginning of your xpath query string
     * @param  mixed $refNode a parent-node to search under
     * @return array the resulting DomNodeList is converted to an array & returned
     */
    public function xpath($xpath,$refNode=null){
        $xp = new \DOMXpath($this);
        if ($refNode==null)$list =  $xp->query($xpath);
        else $list = $xp->query($xpath,$refNode);
        $arr = [];
        foreach ($list as $item){
            $arr[] = $item;
        }
        return $arr;
    }

    /**
     * Set an attribute that will place PHP code inside the tag declartion of a node. 
     * Basically: `<node phpCodePlaceholder>`, which pHtml will later convert to `<node <?='some_stuff'?>>`. 
     * This avoids problems caused by attributes requiring a `=""`, which `DOMDocument` automatically places.
     *
     * @param $phpCode A block of php code with opening & closing tags like <?='some stuff'?>
     * @return \Taeluf\PHTML\ValuelessAttribute
     */
    public function addPhpToTag($node, $phpCode){
        $this->phpAttrValue = $this->phpAttrValue  ??  PHTML\PHPParser::getRandomAlpha();

        $placeholder = $this->phpPlaceholder($phpCode);
        $node->setAttribute($placeholder, $this->phpAttrValue);
        return $placeholder;
    }

    public function insertCodeBefore(\DOMNode $node, $phpCode){
        // $placeholder = $this->phpPlaceholder($phpCode);
        $placeholder = $this->placeholder($phpCode);
        $text = new \DOMText($placeholder);
        return $node->parentNode->insertBefore($text, $node);
    }

    public function insertCodeAfter(\DOMNode $node, $phpCode){
        $placeholder = $this->placeholder($phpCode);
        $text = new \DOMText($placeholder);
        if ($node->nextSibling!==null)return $node->parentNode->insertBefore($text,$node->nextSibling);

        return $node->parentNode->insertBefore($text);
    }

    public function cleanHTML($html){
        // fix doctype
        $html = preg_replace('/\<\!DOCTYPE(.*)\>/i', '<tlfphtml-doctype$1></tlfphtml-doctype>',$html);
        // fix <html> tag
        $html = preg_replace('/<html([ >])/','<tlfphtml-html$1',$html);
        $html = str_ireplace('</html>', '</tlfphtml-html>', $html);

        // fix <head> tag
        $html = preg_replace('/<head([ >])/', '<tlfphtml-head$1',$html);
        $html = str_ireplace('</head>', '</tlfphtml-head>',$html);
        return $html;
    }

    public function restoreHtml($html){
        $html = preg_replace('/\<tlfphtml\-doctype(.*)\>\<\/tlfphtml\-doctype\>/i', '<!DOCTYPE$1>',$html);
        // fix <html> tag
        $html = str_ireplace('<tlfphtml-html','<html',$html);
        $html = str_ireplace('</tlfphtml-html>', '</html>', $html);

        // fix <head> tag
        $html = str_ireplace('<tlfphtml-head', '<head', $html);
        $html = str_ireplace('</tlfphtml-head>', '</head>', $html);
        return $html; 
    }

    public function __get($param){
        if ($param == 'form'){
            return $this->xpath('//form')[0] ?? null;
        }
    }
}
<?php

namespace Taeluf\PHTML;

class TextNode extends \DOMText {


    /** is this node the given tag
    */
    public function is(string $tagName): bool{
        if (strtolower($this->nodeName)==strtolower($tagName))return true;
        return false;
    }

}
{
    "type": "php_open",
    "language": "php",
    "src": "    html\n    <?php\n    echo \"yes!\";\n    class Abc {\n        public function coolio(){\n            echo \"whoo!\";\n        }\n    }"
}Array
(
    [type] => php_open
    [language] => php
    [src] =>     html
    <?php
    echo "yes!";
    class Abc {
        public function coolio(){
            echo "whoo!";
        }
    }
)

- +Property.Assign.Concat(pass): ` public $global_warming = "angers"."me"."greatly";`
- +Property.Two(pass): ` public $blm = "Yes!";private $cat="yep"; `
- +Property.Assign(pass): ` public $blm = "Yes!"; `
- +Property.Typed(pass): ` public int $blm;`
- +Property.Static(pass): ` static public $blm;`
- +Property.Simple(pass): ` public $blm;`
- +Arg.Assign.Concat.BeforeComma(pass): ` $global_warming = "angers"."me"."greatly", int $okay)`
- +Arg.Assign.Concat(pass): ` $global_warming = "angers"."me"."greatly")`
- +Arg.Two(pass): ` string $blm = "abc", bool $dog = true )`
- +Arg.Assign(pass): ` string $blm = "abc" )`
- +Arg.Typed(pass): ` string $blm )`
- +Arg.Simple(pass): `$blm)`
- +Namespace.Docblock(pass): `/** docs */ namespace AbcDef_09;`
- +Namespace.MultiLayer.IntermediateDocblocks(pass): `namespace/*k*/Abc\Def\_09;`
- +Namespace.MultiLayer(pass): `namespace Abc\Def\_09;`
- +Namespace.Simple(pass): `namespace AbcDef_09;`
- -Method.SimpleBody(fail): `    public function is_the_us_imperialist():bool {
        $var = new \Value();
        return true;
    } `
- +Method.ReturnReference(pass): `public function &abc() {`
- -Method.WithNestedBlock.2(fail): `    public function is_the_us_imperialist():bool {
        if ($you_buy_into_imperialist_propaganda){
            return false;
        } 
        return true;
    } 
    public function is_the_us_nice():bool {
        if ($you_are_rich){
            return true;
        } 
        return false;
    } `
- -Method.WithNestedBlock(fail): `    public function is_the_us_imperialist():bool {
        if ($you_buy_into_imperialist_propaganda){
            return false;
        } 
        return true;
    } `
- +Method.WithReturnType(pass): `static public function abc(bool $b): string {`
- +Method.TwoArgs(pass): `/* whoo */ private function abc($arg1, $arg2) {`
- +Method.OneArg(pass): `/* whoo */ public function abc(string $def=96) {`
- +Method.Simple.OneArg(pass): `public function abc($def) {`
- +Method.Static(pass): `static public function abc() {`
- +Method.Simple(pass): `public function abc() {`
- +Class.InNamespace(pass): `namespace Abc; class Def {}`
- +Class.Final.EmptyBody(pass): `final class Abc {

}`
- +Class.Implements(pass): `class Abc extends \Def\Ghi implements iAbc, iDef {`
- +Class.Extends(pass): `class Abc extends \Def\Ghi {`
- +Class.Abstract(pass): `abstract class Abc {`
- +Class.OpenInFile(pass): `class Abc {`
- +Class.OpenInNamespace(pass): `class Abc {`
- -Integration.Class.Methods.WithNestedBlock(fail): `    class A {
        public function is_the_us_imperialist():bool {
            if ($you_buy_into_imperialist_propaganda){
                if (true){
                    return false;
                }
            } 
            return true;
        } 
        public function is_the_us_nice():bool {
            if ($you_are_rich){
                if (true){
                    return true;
                }
            } 
            return false;
        } 
    } //`
- +Integration.Class.Final.Method(pass): `final class Abc {
    public function abc() {    }}`
- +Integration.Class.Bug.ModifiersMethods(pass): `abstract class Abc {
    public function `
- +Integration.Class.Method.2(pass): `class Abc {
    public function abc() {
    }    private function def() {
    }
}final class Def {
    public function abc() {
    }    protected function def() {
    }
}`
- +Integration.Trait.Method(pass): `trait Abc {
    public function abc() {    }}`
- +Integration.Class.Method(pass): `class Abc {
    public function abc() {    }}`
- +Trait.InNamespace(pass): `namespace Abc; trait Def {}`
- +Trait.EmptyBody(pass): `trait Abc {

}`
- +Trait.OpenInFile(pass): `trait Abc {`
- +Trait.OpenInNamespace(pass): `trait Abc {`
- +Open.Class(pass): `<html><div><?php class Abc {} `
- +Open.Close.Open(pass): `<html><div><?php ?></div><?php namespace Abc; `
- +Open.Simple(pass): `<html><div><?php namespace Abc;`
- +Const.Two(pass): ` const blm = "Yes!";private const cat="yep"; `
- +Const.Private(pass): `private const blm = 86;`
- +Const.Simple(pass): `const blm = "This"."is".'a'."const";`
- +Const.NoValue(pass): `const blm `
- +UseTrait.Docblock(pass): `/** docs */ use AbcDef_09;`
- +UseTrait.WithNamespace.IntermediateDocblocks(pass): `use/*k*/Abc\Def\_09;`
- +UseTrait.WithNamespace(pass): `use Abc\Def\_09;`
- +UseTrait.Simple(pass): `use AbcDef_09;`
- +Values.Arithmetic.Nesting(pass): `(1*2+(4*6/((1+2)+(3**2)))+3 - 12) / 3 ** 2 + 987;`
- +Values.Arithmetic(pass): `(1*2)+3 - 12 / 3 ** 2 + 987;`
- +Values.Arithmetic.Add(pass): `1 + 2;`
- +Values.Array.WithConcats(pass): `["a"."b"."c",22,"c"];`
- +Values.Array.Keyed(pass): `["a"=>1,22,"c"=>'third element'];`
- +Values.Array.IntStringValues(pass): `["a",22,"c"];`
- +Values.Array.StringValues(pass): `["a","b","c"];`
- +Values.Array.DoubleValue(pass): `[1.33,2,3];`
- +Values.Array.IntValues(pass): `[1,2,3];`
- +Values.BothQuotesConcat(pass): `"This"."is".'a'."const";`
- +Values.SingleQuotesConcat(pass): `'This'.'is'.'a'.'thing';`
- +Values.DoubleQuotesConcat(pass): `"This"."is"."a"."thing";`
- +Values.Double(pass): `1.87;`
- +Values.Int(pass): `1;`
- +Values.SemicolonStop(pass): `"This";`
- +Values.CommaSeparatedArg(pass): `"This",`
- +Values.CloseArgList(pass): `"This")`
- -Bug.namespace(fail): `    public function namespace_add(string $namespace) {
        $this->namespace[] = $namespace;
    } `
- +Function.Anon(pass): `    function protect_womens_rights() use ($abc){
        return;
    } `
- -Function.SimpleBody(fail): `    function is_the_us_imperialist():bool {
        $var = new \Value();
        return true;
    } `
- -Var.Assign.Variable(fail): `$bear = $red_racoon;`
- -Var.Assign.String(fail): `$bear = "barry";`{
    "type": "file",
    "namespace": {
        "type": "namespace",
        "name": "Tlf\\Lexer\\Test\\Main",
        "declaration": "namespace Tlf\\Lexer\\Test\\Main;",
        "class": [
            {
                "type": "class",
                "docblock": {
                    "type": "docblock",
                    "description": "Test features of the grammar class, not lexing, and not any language-specific grammars"
                },
                "namespace": "Tlf\\Lexer\\Test\\Main",
                "fqn": "Tlf\\Lexer\\Test\\Main\\Grammar",
                "name": "Grammar",
                "extends": "\\Tlf\\Tester",
                "declaration": "class Grammar extends \\Tlf\\Tester",
                "methods": [
                    {
                        "type": "method",
                        "args": [],
                        "docblock": {
                            "type": "docblock",
                            "description": "Get directives as they would be defined & those same directives as they would be after normaliztion\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "test",
                                    "description": ""
                                },
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "multi dimensional array"
                                },
                                {
                                    "type": "attribute",
                                    "name": "child",
                                    "description": ".index1 is the input directive, as one would define it"
                                },
                                {
                                    "type": "attribute",
                                    "name": "child",
                                    "description": ".index2 is the expected output directive, as returned from the normalize method"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "getNormalizeDirectives",
                        "body": "",
                        "declaration": "public function getNormalizeDirectives()"
                    }
                ]
            }
        ]
    }
}Array
(
    [type] => file
    [namespace] => Array
        (
            [type] => namespace
            [name] => Tlf\Lexer\Test\Main
            [declaration] => namespace Tlf\Lexer\Test\Main;
            [class] => Array
                (
                    [0] => Array
                        (
                            [type] => class
                            [docblock] => Array
                                (
                                    [type] => docblock
                                    [description] => Test features of the grammar class, not lexing, and not any language-specific grammars
                                )

                            [namespace] => Tlf\Lexer\Test\Main
                            [fqn] => Tlf\Lexer\Test\Main\Grammar
                            [name] => Grammar
                            [extends] => \Tlf\Tester
                            [declaration] => class Grammar extends \Tlf\Tester
                            [methods] => Array
                                (
                                    [0] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Get directives as they would be defined & those same directives as they would be after normaliztion

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => test
                                                                    [description] => 
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => multi dimensional array
                                                                )

                                                            [2] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => child
                                                                    [description] => .index1 is the input directive, as one would define it
                                                                )

                                                            [3] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => child
                                                                    [description] => .index2 is the expected output directive, as returned from the normalize method
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => getNormalizeDirectives
                                            [body] => 
                                            [declaration] => public function getNormalizeDirectives()
                                        )

                                )

                        )

                )

        )

)
{
    "type": "file",
    "namespace": "",
    "class": [
        {
            "type": "class",
            "fqn": "Sample",
            "namespace": "",
            "name": "Sample",
            "extends": "cats",
            "declaration": "class Sample extends cats",
            "methods": [
                {
                    "type": "method",
                    "args": [],
                    "modifiers": [
                        "public"
                    ],
                    "name": "cats",
                    "body": "",
                    "declaration": "public function cats()"
                },
                {
                    "type": "method",
                    "args": [
                        {
                            "type": "arg",
                            "name": "arg",
                            "declaration": "$arg"
                        }
                    ],
                    "modifiers": [
                        "public"
                    ],
                    "name": "dogs",
                    "body": "",
                    "declaration": "public function dogs($arg)"
                },
                {
                    "type": "method",
                    "args": [
                        {
                            "type": "arg",
                            "name": "arg",
                            "value": "1",
                            "declaration": "$arg=1"
                        }
                    ],
                    "modifiers": [
                        "public"
                    ],
                    "name": "dogs2",
                    "body": "",
                    "declaration": "public function dogs2($arg=1)"
                },
                {
                    "type": "method",
                    "args": [
                        {
                            "type": "arg",
                            "name": "arg",
                            "value": "'yes'",
                            "declaration": "$arg='yes'"
                        }
                    ],
                    "modifiers": [
                        "public"
                    ],
                    "name": "dogs_3",
                    "body": "",
                    "declaration": "public function dogs_3($arg='yes')"
                },
                {
                    "type": "method",
                    "args": [],
                    "docblock": {
                        "type": "docblock",
                        "description": "bears are so cute"
                    },
                    "modifiers": [
                        "public"
                    ],
                    "name": "bears",
                    "body": "",
                    "declaration": "public function bears()"
                },
                {
                    "type": "method",
                    "args": [],
                    "docblock": {
                        "type": "docblock",
                        "description": "bears are so cute"
                    },
                    "modifiers": [
                        "public"
                    ],
                    "name": "bears_are_best",
                    "body": "",
                    "declaration": "public function bears_are_best()"
                },
                {
                    "type": "method",
                    "args": [],
                    "modifiers": [
                        "public"
                    ],
                    "name": "bears_do_stuff",
                    "body": "echo \"love bears\";",
                    "declaration": "public function bears_do_stuff()"
                },
                {
                    "type": "method",
                    "args": [],
                    "modifiers": [
                        "public"
                    ],
                    "name": "bears_cuddle_stuff",
                    "body": "$str = \"resist the temptation to cuddle a bear. not safe. big sad\";\necho $str;",
                    "declaration": "public function bears_cuddle_stuff()"
                },
                {
                    "type": "method",
                    "args": [],
                    "modifiers": [
                        "public"
                    ],
                    "name": "bears_nest",
                    "body": "$cats = 'run away from bears';\nif ($cats == 'idk'){\n    echo \"this is a block\";\n}",
                    "declaration": "public function bears_nest()"
                },
                {
                    "type": "method",
                    "args": [
                        {
                            "type": "arg",
                            "name": "srcCode",
                            "declaration": "$srcCode"
                        }
                    ],
                    "docblock": {
                        "type": "docblock",
                        "description": "Replaces inline PHP code with placeholder, indexes the placeholder, and returns the modified code\n",
                        "attribute": [
                            {
                                "type": "attribute",
                                "name": "param",
                                "description": "mixed $srcCode - The source code"
                            },
                            {
                                "type": "attribute",
                                "name": "return",
                                "description": "string - source code with all PHP replaced by codeIds"
                            }
                        ]
                    },
                    "modifiers": [
                        "public"
                    ],
                    "name": "cleanSource",
                    "return_types": [
                        "string"
                    ],
                    "body": "$parser = new PHPParser($srcCode);\n$parsed = $parser->pieces();",
                    "declaration": "public function cleanSource($srcCode): string"
                },
                {
                    "type": "method",
                    "args": [],
                    "modifiers": [
                        "public"
                    ],
                    "name": "makes_it_11",
                    "body": "",
                    "declaration": "public function makes_it_11()"
                },
                {
                    "type": "method",
                    "args": [],
                    "modifiers": [
                        "public"
                    ],
                    "name": "output",
                    "return_types": [
                        "string"
                    ],
                    "body": "\/\/ print_r($this->code);\n\/\/ \/\/ echo $this->code[0]->;\n\/\/ exit;\n\/\/ print_r($this->placeholder);\n$code = implode(\"\\n\",$this->code);\n\/\/ return $code;\n$ph = [];\nforeach ($this->placeholder as $id=>$codeArray){\n    $ph[$id] = implode('',$codeArray);\n}\n$last = $code;\nwhile($last != $code = str_replace(array_keys($ph),$ph,$code))$last=$code;\nreturn $code;",
                    "declaration": "public function output(): string"
                },
                {
                    "type": "method",
                    "args": [],
                    "modifiers": [
                        "public"
                    ],
                    "name": "ok_13",
                    "body": "",
                    "declaration": "public function ok_13()"
                },
                {
                    "type": "method",
                    "args": [
                        {
                            "type": "arg",
                            "arg_types": [
                                "string"
                            ],
                            "name": "file",
                            "declaration": "string $file"
                        },
                        {
                            "type": "arg",
                            "name": "chmodTo",
                            "value": "null",
                            "declaration": "$chmodTo=null"
                        }
                    ],
                    "modifiers": [
                        "public"
                    ],
                    "name": "writeTo",
                    "return_types": [
                        "bool"
                    ],
                    "body": "$output = $this->output();\nif (is_dir(dirname($file))){\n    mkdir(dirname($file),0771,true);\n    \/\/ chmod(dirname($file),0770);\n}\n$didPut = file_put_contents($file,$output);\nif ($chmodTo!==null){\n    \/\/ chmod($file,$chmodTo);\n}\nif ($didPut===false)return false;\nelse return true;",
                    "declaration": "public function writeTo(string $file, $chmodTo=null): bool"
                },
                {
                    "type": "method",
                    "args": [],
                    "modifiers": [
                        "public"
                    ],
                    "name": "yep_15",
                    "body": "",
                    "declaration": "public function yep_15()"
                },
                {
                    "type": "method",
                    "args": [
                        {
                            "type": "arg",
                            "name": "html",
                            "declaration": "$html"
                        }
                    ],
                    "modifiers": [
                        "public"
                    ],
                    "name": "__construct",
                    "body": "parent::__construct();\n$this->srcHTML = $html;\n$parser = new PHTML\\PHPParser($html);\n$enc = $parser->pieces();\n$this->php = $enc->php;\n$this->cleanSrc = $enc->html;\n$this->cleanSrc = $this->cleanHTML($this->cleanSrc);\n$hideXmlErrors=true;\nlibxml_use_internal_errors($hideXmlErrors);\n$this->registerNodeClass('DOMElement', '\\\\Taeluf\\\\PHTML\\\\Node');\n$this->registerNodeClass('DOMText', '\\\\Taeluf\\\\PHTML\\\\TextNode');\n\/\/ $this->registerNodeClass('DOMText', 'RBText');\n$html = '<root>'.$this->cleanSrc.'<\/root>';\n$this->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);\n$this->formatOutput = true;\nlibxml_use_internal_errors(false);",
                    "declaration": "public function __construct($html)"
                },
                {
                    "type": "method",
                    "args": [],
                    "modifiers": [
                        "public"
                    ],
                    "name": "okay_17",
                    "body": "",
                    "declaration": "public function okay_17()"
                },
                {
                    "type": "method",
                    "args": [
                        {
                            "type": "arg",
                            "name": "withPHP",
                            "value": "true",
                            "declaration": "$withPHP=true"
                        }
                    ],
                    "modifiers": [
                        "public"
                    ],
                    "name": "output2",
                    "body": "\/\/ echo \"\\n\".'-start output call-'.\"\\n\";\n$list = $this->childNodes[0]->childNodes;\n$hiddenTagsNodes = $this->xpath('\/\/*[@hideOwnTag]');\nforeach ($hiddenTagsNodes as $htn){\n    if ($htn->hideOwnTag==false||$htn->hideOwnTag=='false'){\n        unset($htn->hideOwnTag);\n        continue;\n    }\n    $parent = $htn->parentNode;\n    $childNodeList = $htn->children;\n    foreach ($childNodeList as $child){\n        $htn->removeChild($child);\n        $parent->insertBefore($child, $htn);\n    }\n    $parent->removeChild($htn);\n}\n$html = '';\nforeach ($list as $item){\n    $html .= $this->saveHTML($item);\n}\n\/** Run the php-code-replacer as long as there is a placeholder (while preventing infinite looping) *\/\n$html = $this->fill_php($html, $withPHP);\n$html = $this->restoreHtml($html);\nreturn $html;",
                    "declaration": "public function output2($withPHP=true)"
                },
                {
                    "type": "method",
                    "args": [],
                    "modifiers": [
                        "public"
                    ],
                    "name": "now_19",
                    "body": "",
                    "declaration": "public function now_19()"
                },
                {
                    "type": "method",
                    "args": [
                        {
                            "type": "arg",
                            "name": "html",
                            "declaration": "$html"
                        },
                        {
                            "type": "arg",
                            "name": "withPHP",
                            "value": "true",
                            "declaration": "$withPHP=true"
                        }
                    ],
                    "modifiers": [
                        "public"
                    ],
                    "name": "fill_php",
                    "body": "$maxIters = 25;\n$iters = 0;\nwhile ($iters++<$maxIters&&preg_match('\/php([a-zA-Z]{26})php\/', $html, $match)){\n    foreach ($this->php as $id=>$code){\n        if ($withPHP)$html = str_replace($id,$code,$html);\n        else $html = str_replace($id,'',$html);\n    }\n}\nif (($phpAttrVal=$this->phpAttrValue)!=null){\n    $html = str_replace(\"=\\\"$phpAttrVal\\\"\", '', $html);\n}\nreturn $html;",
                    "declaration": "public function fill_php($html, $withPHP=true)"
                },
                {
                    "type": "method",
                    "args": [],
                    "modifiers": [
                        "public"
                    ],
                    "name": "ugh_21",
                    "body": "",
                    "declaration": "public function ugh_21()"
                },
                {
                    "type": "method",
                    "args": [
                        {
                            "type": "arg",
                            "arg_types": [
                                "string"
                            ],
                            "name": "tableName",
                            "declaration": "string $tableName"
                        },
                        {
                            "type": "arg",
                            "arg_types": [
                                "array"
                            ],
                            "name": "colDefinitions",
                            "declaration": "array $colDefinitions"
                        },
                        {
                            "type": "arg",
                            "arg_types": [
                                "bool"
                            ],
                            "name": "recreateIfExists",
                            "value": "false",
                            "declaration": "bool $recreateIfExists=false"
                        }
                    ],
                    "modifiers": [
                        "public"
                    ],
                    "name": "create",
                    "body": "$colStatements = [];\nforeach ($colDefinitions as $col => $definition){\n    $statement = '`'.$col.'` '. $definition;\n    $colStatements[] = $statement;\n}\n$colsSql = implode(\", \", $colStatements);\n$drop = $recreateIfExists ? \"DROP TABLE IF EXISTS `{$tableName}`;\\n\" : '';\n$sql =\n<<<SQL\n    {$drop}\n    CREATE TABLE IF NOT EXISTS `{$tableName}`\n    (\n    {$colsSql}\n    )\n    ;\nSQL;\n$this->exec($sql);",
                    "declaration": "public function create(string $tableName, array $colDefinitions, bool $recreateIfExists=false)"
                },
                {
                    "type": "method",
                    "args": [],
                    "modifiers": [
                        "public"
                    ],
                    "name": "its_23",
                    "body": "",
                    "declaration": "public function its_23()"
                }
            ]
        }
    ]
}Array
(
    [type] => file
    [namespace] => 
    [class] => Array
        (
            [0] => Array
                (
                    [type] => class
                    [fqn] => Sample
                    [namespace] => 
                    [name] => Sample
                    [extends] => cats
                    [declaration] => class Sample extends cats
                    [methods] => Array
                        (
                            [0] => Array
                                (
                                    [type] => method
                                    [args] => Array
                                        (
                                        )

                                    [modifiers] => Array
                                        (
                                            [0] => public
                                        )

                                    [name] => cats
                                    [body] => 
                                    [declaration] => public function cats()
                                )

                            [1] => Array
                                (
                                    [type] => method
                                    [args] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [type] => arg
                                                    [name] => arg
                                                    [declaration] => $arg
                                                )

                                        )

                                    [modifiers] => Array
                                        (
                                            [0] => public
                                        )

                                    [name] => dogs
                                    [body] => 
                                    [declaration] => public function dogs($arg)
                                )

                            [2] => Array
                                (
                                    [type] => method
                                    [args] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [type] => arg
                                                    [name] => arg
                                                    [value] => 1
                                                    [declaration] => $arg=1
                                                )

                                        )

                                    [modifiers] => Array
                                        (
                                            [0] => public
                                        )

                                    [name] => dogs2
                                    [body] => 
                                    [declaration] => public function dogs2($arg=1)
                                )

                            [3] => Array
                                (
                                    [type] => method
                                    [args] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [type] => arg
                                                    [name] => arg
                                                    [value] => 'yes'
                                                    [declaration] => $arg='yes'
                                                )

                                        )

                                    [modifiers] => Array
                                        (
                                            [0] => public
                                        )

                                    [name] => dogs_3
                                    [body] => 
                                    [declaration] => public function dogs_3($arg='yes')
                                )

                            [4] => Array
                                (
                                    [type] => method
                                    [args] => Array
                                        (
                                        )

                                    [docblock] => Array
                                        (
                                            [type] => docblock
                                            [description] => bears are so cute
                                        )

                                    [modifiers] => Array
                                        (
                                            [0] => public
                                        )

                                    [name] => bears
                                    [body] => 
                                    [declaration] => public function bears()
                                )

                            [5] => Array
                                (
                                    [type] => method
                                    [args] => Array
                                        (
                                        )

                                    [docblock] => Array
                                        (
                                            [type] => docblock
                                            [description] => bears are so cute
                                        )

                                    [modifiers] => Array
                                        (
                                            [0] => public
                                        )

                                    [name] => bears_are_best
                                    [body] => 
                                    [declaration] => public function bears_are_best()
                                )

                            [6] => Array
                                (
                                    [type] => method
                                    [args] => Array
                                        (
                                        )

                                    [modifiers] => Array
                                        (
                                            [0] => public
                                        )

                                    [name] => bears_do_stuff
                                    [body] => echo "love bears";
                                    [declaration] => public function bears_do_stuff()
                                )

                            [7] => Array
                                (
                                    [type] => method
                                    [args] => Array
                                        (
                                        )

                                    [modifiers] => Array
                                        (
                                            [0] => public
                                        )

                                    [name] => bears_cuddle_stuff
                                    [body] => $str = "resist the temptation to cuddle a bear. not safe. big sad";
echo $str;
                                    [declaration] => public function bears_cuddle_stuff()
                                )

                            [8] => Array
                                (
                                    [type] => method
                                    [args] => Array
                                        (
                                        )

                                    [modifiers] => Array
                                        (
                                            [0] => public
                                        )

                                    [name] => bears_nest
                                    [body] => $cats = 'run away from bears';
if ($cats == 'idk'){
    echo "this is a block";
}
                                    [declaration] => public function bears_nest()
                                )

                            [9] => Array
                                (
                                    [type] => method
                                    [args] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [type] => arg
                                                    [name] => srcCode
                                                    [declaration] => $srcCode
                                                )

                                        )

                                    [docblock] => Array
                                        (
                                            [type] => docblock
                                            [description] => Replaces inline PHP code with placeholder, indexes the placeholder, and returns the modified code

                                            [attribute] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => attribute
                                                            [name] => param
                                                            [description] => mixed $srcCode - The source code
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => attribute
                                                            [name] => return
                                                            [description] => string - source code with all PHP replaced by codeIds
                                                        )

                                                )

                                        )

                                    [modifiers] => Array
                                        (
                                            [0] => public
                                        )

                                    [name] => cleanSource
                                    [return_types] => Array
                                        (
                                            [0] => string
                                        )

                                    [body] => $parser = new PHPParser($srcCode);
$parsed = $parser->pieces();
                                    [declaration] => public function cleanSource($srcCode): string
                                )

                            [10] => Array
                                (
                                    [type] => method
                                    [args] => Array
                                        (
                                        )

                                    [modifiers] => Array
                                        (
                                            [0] => public
                                        )

                                    [name] => makes_it_11
                                    [body] => 
                                    [declaration] => public function makes_it_11()
                                )

                            [11] => Array
                                (
                                    [type] => method
                                    [args] => Array
                                        (
                                        )

                                    [modifiers] => Array
                                        (
                                            [0] => public
                                        )

                                    [name] => output
                                    [return_types] => Array
                                        (
                                            [0] => string
                                        )

                                    [body] => // print_r($this->code);
// // echo $this->code[0]->;
// exit;
// print_r($this->placeholder);
$code = implode("\n",$this->code);
// return $code;
$ph = [];
foreach ($this->placeholder as $id=>$codeArray){
    $ph[$id] = implode('',$codeArray);
}
$last = $code;
while($last != $code = str_replace(array_keys($ph),$ph,$code))$last=$code;
return $code;
                                    [declaration] => public function output(): string
                                )

                            [12] => Array
                                (
                                    [type] => method
                                    [args] => Array
                                        (
                                        )

                                    [modifiers] => Array
                                        (
                                            [0] => public
                                        )

                                    [name] => ok_13
                                    [body] => 
                                    [declaration] => public function ok_13()
                                )

                            [13] => Array
                                (
                                    [type] => method
                                    [args] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [type] => arg
                                                    [arg_types] => Array
                                                        (
                                                            [0] => string
                                                        )

                                                    [name] => file
                                                    [declaration] => string $file
                                                )

                                            [1] => Array
                                                (
                                                    [type] => arg
                                                    [name] => chmodTo
                                                    [value] => null
                                                    [declaration] => $chmodTo=null
                                                )

                                        )

                                    [modifiers] => Array
                                        (
                                            [0] => public
                                        )

                                    [name] => writeTo
                                    [return_types] => Array
                                        (
                                            [0] => bool
                                        )

                                    [body] => $output = $this->output();
if (is_dir(dirname($file))){
    mkdir(dirname($file),0771,true);
    // chmod(dirname($file),0770);
}
$didPut = file_put_contents($file,$output);
if ($chmodTo!==null){
    // chmod($file,$chmodTo);
}
if ($didPut===false)return false;
else return true;
                                    [declaration] => public function writeTo(string $file, $chmodTo=null): bool
                                )

                            [14] => Array
                                (
                                    [type] => method
                                    [args] => Array
                                        (
                                        )

                                    [modifiers] => Array
                                        (
                                            [0] => public
                                        )

                                    [name] => yep_15
                                    [body] => 
                                    [declaration] => public function yep_15()
                                )

                            [15] => Array
                                (
                                    [type] => method
                                    [args] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [type] => arg
                                                    [name] => html
                                                    [declaration] => $html
                                                )

                                        )

                                    [modifiers] => Array
                                        (
                                            [0] => public
                                        )

                                    [name] => __construct
                                    [body] => parent::__construct();
$this->srcHTML = $html;
$parser = new PHTML\PHPParser($html);
$enc = $parser->pieces();
$this->php = $enc->php;
$this->cleanSrc = $enc->html;
$this->cleanSrc = $this->cleanHTML($this->cleanSrc);
$hideXmlErrors=true;
libxml_use_internal_errors($hideXmlErrors);
$this->registerNodeClass('DOMElement', '\\Taeluf\\PHTML\\Node');
$this->registerNodeClass('DOMText', '\\Taeluf\\PHTML\\TextNode');
// $this->registerNodeClass('DOMText', 'RBText');
$html = '<root>'.$this->cleanSrc.'</root>';
$this->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$this->formatOutput = true;
libxml_use_internal_errors(false);
                                    [declaration] => public function __construct($html)
                                )

                            [16] => Array
                                (
                                    [type] => method
                                    [args] => Array
                                        (
                                        )

                                    [modifiers] => Array
                                        (
                                            [0] => public
                                        )

                                    [name] => okay_17
                                    [body] => 
                                    [declaration] => public function okay_17()
                                )

                            [17] => Array
                                (
                                    [type] => method
                                    [args] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [type] => arg
                                                    [name] => withPHP
                                                    [value] => true
                                                    [declaration] => $withPHP=true
                                                )

                                        )

                                    [modifiers] => Array
                                        (
                                            [0] => public
                                        )

                                    [name] => output2
                                    [body] => // echo "\n".'-start output call-'."\n";
$list = $this->childNodes[0]->childNodes;
$hiddenTagsNodes = $this->xpath('//*[@hideOwnTag]');
foreach ($hiddenTagsNodes as $htn){
    if ($htn->hideOwnTag==false||$htn->hideOwnTag=='false'){
        unset($htn->hideOwnTag);
        continue;
    }
    $parent = $htn->parentNode;
    $childNodeList = $htn->children;
    foreach ($childNodeList as $child){
        $htn->removeChild($child);
        $parent->insertBefore($child, $htn);
    }
    $parent->removeChild($htn);
}
$html = '';
foreach ($list as $item){
    $html .= $this->saveHTML($item);
}
/** Run the php-code-replacer as long as there is a placeholder (while preventing infinite looping) */
$html = $this->fill_php($html, $withPHP);
$html = $this->restoreHtml($html);
return $html;
                                    [declaration] => public function output2($withPHP=true)
                                )

                            [18] => Array
                                (
                                    [type] => method
                                    [args] => Array
                                        (
                                        )

                                    [modifiers] => Array
                                        (
                                            [0] => public
                                        )

                                    [name] => now_19
                                    [body] => 
                                    [declaration] => public function now_19()
                                )

                            [19] => Array
                                (
                                    [type] => method
                                    [args] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [type] => arg
                                                    [name] => html
                                                    [declaration] => $html
                                                )

                                            [1] => Array
                                                (
                                                    [type] => arg
                                                    [name] => withPHP
                                                    [value] => true
                                                    [declaration] => $withPHP=true
                                                )

                                        )

                                    [modifiers] => Array
                                        (
                                            [0] => public
                                        )

                                    [name] => fill_php
                                    [body] => $maxIters = 25;
$iters = 0;
while ($iters++<$maxIters&&preg_match('/php([a-zA-Z]{26})php/', $html, $match)){
    foreach ($this->php as $id=>$code){
        if ($withPHP)$html = str_replace($id,$code,$html);
        else $html = str_replace($id,'',$html);
    }
}
if (($phpAttrVal=$this->phpAttrValue)!=null){
    $html = str_replace("=\"$phpAttrVal\"", '', $html);
}
return $html;
                                    [declaration] => public function fill_php($html, $withPHP=true)
                                )

                            [20] => Array
                                (
                                    [type] => method
                                    [args] => Array
                                        (
                                        )

                                    [modifiers] => Array
                                        (
                                            [0] => public
                                        )

                                    [name] => ugh_21
                                    [body] => 
                                    [declaration] => public function ugh_21()
                                )

                            [21] => Array
                                (
                                    [type] => method
                                    [args] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [type] => arg
                                                    [arg_types] => Array
                                                        (
                                                            [0] => string
                                                        )

                                                    [name] => tableName
                                                    [declaration] => string $tableName
                                                )

                                            [1] => Array
                                                (
                                                    [type] => arg
                                                    [arg_types] => Array
                                                        (
                                                            [0] => array
                                                        )

                                                    [name] => colDefinitions
                                                    [declaration] => array $colDefinitions
                                                )

                                            [2] => Array
                                                (
                                                    [type] => arg
                                                    [arg_types] => Array
                                                        (
                                                            [0] => bool
                                                        )

                                                    [name] => recreateIfExists
                                                    [value] => false
                                                    [declaration] => bool $recreateIfExists=false
                                                )

                                        )

                                    [modifiers] => Array
                                        (
                                            [0] => public
                                        )

                                    [name] => create
                                    [body] => $colStatements = [];
foreach ($colDefinitions as $col => $definition){
    $statement = '`'.$col.'` '. $definition;
    $colStatements[] = $statement;
}
$colsSql = implode(", ", $colStatements);
$drop = $recreateIfExists ? "DROP TABLE IF EXISTS `{$tableName}`;\n" : '';
$sql =
<<<SQL
    {$drop}
    CREATE TABLE IF NOT EXISTS `{$tableName}`
    (
    {$colsSql}
    )
    ;
SQL;
$this->exec($sql);
                                    [declaration] => public function create(string $tableName, array $colDefinitions, bool $recreateIfExists=false)
                                )

                            [22] => Array
                                (
                                    [type] => method
                                    [args] => Array
                                        (
                                        )

                                    [modifiers] => Array
                                        (
                                            [0] => public
                                        )

                                    [name] => its_23
                                    [body] => 
                                    [declaration] => public function its_23()
                                )

                        )

                )

        )

)
{
    "type": "file",
    "namespace": {
        "type": "namespace",
        "name": "Cats\\Whatever",
        "declaration": "namespace Cats\\Whatever;",
        "class": [
            {
                "type": "class",
                "docblock": {
                    "type": "docblock",
                    "description": "This is the best class anyone has ever written."
                },
                "namespace": "Cats\\Whatever",
                "fqn": "Cats\\Whatever\\Sample",
                "name": "Sample",
                "extends": "cats",
                "declaration": "class Sample extends cats",
                "comments": [
                    "First comment",
                    "Second Comment"
                ],
                "properties": [
                    {
                        "type": "property",
                        "modifiers": [
                            "protected"
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Why would you name a giraffe Bob?"
                        },
                        "name": "giraffe",
                        "value": "\"Bob\"",
                        "declaration": "protected $giraffe = \"Bob\";"
                    },
                    {
                        "type": "property",
                        "modifiers": [
                            "private"
                        ],
                        "name": "cat",
                        "value": "\"Jeff\"",
                        "declaration": "private $cat = \"Jeff\";"
                    },
                    {
                        "type": "property",
                        "modifiers": [
                            "static",
                            "public"
                        ],
                        "name": "dog",
                        "value": "\"PandaBearDog\"",
                        "declaration": "static public $dog = \"PandaBearDog\";"
                    }
                ],
                "methods": [
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "a",
                                "value": "\"abc\"",
                                "declaration": "$a= \"abc\""
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "dogs\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "dogs"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "dogs",
                        "body": "echo \"yep yep\";",
                        "declaration": "public function dogs($a= \"abc\")"
                    }
                ],
                "const": [
                    {
                        "type": "const",
                        "name": "Doygle",
                        "modifiers": [
                            "public"
                        ],
                        "value": "\"Hoygle Floygl\"",
                        "declaration": "public const Doygle = \"Hoygle Floygl\";"
                    }
                ]
            }
        ]
    }
}Array
(
    [type] => file
    [namespace] => Array
        (
            [type] => namespace
            [name] => Cats\Whatever
            [declaration] => namespace Cats\Whatever;
            [class] => Array
                (
                    [0] => Array
                        (
                            [type] => class
                            [docblock] => Array
                                (
                                    [type] => docblock
                                    [description] => This is the best class anyone has ever written.
                                )

                            [namespace] => Cats\Whatever
                            [fqn] => Cats\Whatever\Sample
                            [name] => Sample
                            [extends] => cats
                            [declaration] => class Sample extends cats
                            [comments] => Array
                                (
                                    [0] => First comment
                                    [1] => Second Comment
                                )

                            [properties] => Array
                                (
                                    [0] => Array
                                        (
                                            [type] => property
                                            [modifiers] => Array
                                                (
                                                    [0] => protected
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Why would you name a giraffe Bob?
                                                )

                                            [name] => giraffe
                                            [value] => "Bob"
                                            [declaration] => protected $giraffe = "Bob";
                                        )

                                    [1] => Array
                                        (
                                            [type] => property
                                            [modifiers] => Array
                                                (
                                                    [0] => private
                                                )

                                            [name] => cat
                                            [value] => "Jeff"
                                            [declaration] => private $cat = "Jeff";
                                        )

                                    [2] => Array
                                        (
                                            [type] => property
                                            [modifiers] => Array
                                                (
                                                    [0] => static
                                                    [1] => public
                                                )

                                            [name] => dog
                                            [value] => "PandaBearDog"
                                            [declaration] => static public $dog = "PandaBearDog";
                                        )

                                )

                            [methods] => Array
                                (
                                    [0] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => a
                                                            [value] => "abc"
                                                            [declaration] => $a= "abc"
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => dogs

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => dogs
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => dogs
                                            [body] => echo "yep yep";
                                            [declaration] => public function dogs($a= "abc")
                                        )

                                )

                            [const] => Array
                                (
                                    [0] => Array
                                        (
                                            [type] => const
                                            [name] => Doygle
                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [value] => "Hoygle Floygl"
                                            [declaration] => public const Doygle = "Hoygle Floygl";
                                        )

                                )

                        )

                )

        )

)
{
    "type": "file",
    "namespace": "",
    "functions": [
        {
            "type": "function",
            "args": [],
            "name": "abc",
            "body": "",
            "declaration": "function abc()"
        },
        {
            "type": "function",
            "args": [],
            "name": "yep",
            "body": "",
            "declaration": "function yep()"
        }
    ],
    "class": [
        {
            "type": "class",
            "fqn": "Abc",
            "namespace": "",
            "name": "Abc",
            "declaration": "class Abc"
        },
        {
            "type": "class",
            "fqn": "Def",
            "namespace": "",
            "name": "Def",
            "declaration": "class Def"
        }
    ],
    "value": null,
    "comments": [
        "$descript = $method->description;"
    ]
}Array
(
    [type] => file
    [namespace] => 
    [functions] => Array
        (
            [0] => Array
                (
                    [type] => function
                    [args] => Array
                        (
                        )

                    [name] => abc
                    [body] => 
                    [declaration] => function abc()
                )

            [1] => Array
                (
                    [type] => function
                    [args] => Array
                        (
                        )

                    [name] => yep
                    [body] => 
                    [declaration] => function yep()
                )

        )

    [class] => Array
        (
            [0] => Array
                (
                    [type] => class
                    [fqn] => Abc
                    [namespace] => 
                    [name] => Abc
                    [declaration] => class Abc
                )

            [1] => Array
                (
                    [type] => class
                    [fqn] => Def
                    [namespace] => 
                    [name] => Def
                    [declaration] => class Def
                )

        )

    [value] => 
    [comments] => Array
        (
            [0] => $descript = $method->description;
        )

)
{
    "type": "file",
    "namespace": {
        "type": "namespace",
        "name": "Tlf",
        "declaration": "namespace Tlf;",
        "class": [
            {
                "type": "class",
                "docblock": {
                    "type": "docblock",
                    "description": "A lil tiny database class"
                },
                "namespace": "Tlf",
                "fqn": "Tlf\\LilDb",
                "name": "LilDb",
                "declaration": "class LilDb",
                "properties": [
                    {
                        "type": "property",
                        "modifiers": [
                            "public",
                            "\\PDO"
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "a pdo instance"
                        },
                        "name": "pdo",
                        "declaration": "public \\PDO $pdo;"
                    }
                ],
                "methods": [
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "user",
                                "declaration": "string $user"
                            },
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "password",
                                "declaration": "string $password"
                            },
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "db",
                                "declaration": "string $db"
                            },
                            {
                                "type": "arg",
                                "name": "host",
                                "value": "'localhost'",
                                "declaration": "$host='localhost'"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Convenience method to initialize with pdo",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "Tlf\\LilDb"
                                }
                            ]
                        },
                        "modifiers": [
                            "static",
                            "public"
                        ],
                        "name": "new",
                        "body": "$pdo = new \\PDO(\"mysql:dbname=${db};host=${host}\", $user, $password);\n$pdo->setAttribute(\\PDO::ATTR_ERRMODE, \\PDO::ERRMODE_EXCEPTION);\n$ldb = new static($pdo);\nreturn $ldb;",
                        "declaration": "static public function new(string $user, string $password, string $db, $host='localhost')"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "dbName",
                                "value": "':memory:'",
                                "declaration": "string $dbName = ':memory:'"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Convenience method to initialize sqlite db in memory",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "Tlf\\LilDb"
                                }
                            ]
                        },
                        "modifiers": [
                            "static",
                            "public"
                        ],
                        "name": "sqlite",
                        "body": "$pdo = new \\PDO('sqlite:'.$dbName);\n$pdo->setAttribute(\\PDO::ATTR_ERRMODE, \\PDO::ERRMODE_EXCEPTION);\n$ldb = new static($pdo);\nreturn $ldb;",
                        "declaration": "static public function sqlite(string $dbName = ':memory:')"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "dbName",
                                "value": "':memory:'",
                                "declaration": "$dbName = ':memory:'"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Convenience method to initialize mysql db in memory"
                        },
                        "modifiers": [
                            "static",
                            "public"
                        ],
                        "name": "mysql",
                        "body": "$pdo = new \\PDO('mysql:'.$dbName);\n$pdo->setAttribute(\\PDO::ATTR_ERRMODE, \\PDO::ERRMODE_EXCEPTION);\n$ldb = new static($pdo);\nreturn $ldb;",
                        "declaration": "static public function mysql($dbName = ':memory:')"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "\\PDO"
                                ],
                                "name": "pdo",
                                "declaration": "\\PDO $pdo"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Initialize with a db handle",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "$pdo a pdo instance"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "__construct",
                        "body": "$this->pdo = $pdo;",
                        "declaration": "public function __construct(\\PDO $pdo)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "tableName",
                                "declaration": "string $tableName"
                            },
                            {
                                "type": "arg",
                                "arg_types": [
                                    "array"
                                ],
                                "name": "colDefinitions",
                                "declaration": "array $colDefinitions"
                            },
                            {
                                "type": "arg",
                                "arg_types": [
                                    "bool"
                                ],
                                "name": "recreateIfExists",
                                "value": "false",
                                "declaration": "bool $recreateIfExists=false"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Create a new table if it doesn't exist.\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param2",
                                    "description": "$colDefinitions array of columns like: `['col_name'=>'VARCHAR(80)', 'col_two'=> 'integer']`"
                                },
                                {
                                    "type": "attribute",
                                    "name": "param3",
                                    "description": "$recreateIfExists true\/false to include `DROP TABLE IF EXISTS table_name`"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "create",
                        "body": "$colStatements = [];\nforeach ($colDefinitions as $col => $definition){\n    $statement = '`'.$col.'` '. $definition;\n    $colStatements[] = $statement;\n}\n$colsSql = implode(\", \", $colStatements);\n$drop = $recreateIfExists ? \"DROP TABLE IF EXISTS `{$tableName}`;\\n\" : '';\n$sql =\n<<<SQL\n    {$drop}\n    CREATE TABLE IF NOT EXISTS `{$tableName}`\n    (\n    {$colsSql}\n    )\n    ;\nSQL;\n$this->exec($sql);",
                        "declaration": "public function create(string $tableName, array $colDefinitions, bool $recreateIfExists=false)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "sql",
                                "declaration": "string $sql"
                            },
                            {
                                "type": "arg",
                                "arg_types": [
                                    "array"
                                ],
                                "name": "binds",
                                "value": "[]",
                                "declaration": "array $binds=[]"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Execute an Sql statement & get rows back",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "throws",
                                    "description": "if the statement fails to prepare"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "query",
                        "body": "$pdo = $this->pdo;\n$stmt = $pdo->prepare($sql);\nif ($stmt===false){\n    $error = var_export($pdo->errorInfo(),true);\n    throw new \\Exception(\"Sql problem: \\n\".$error.\"\\n\\n\");\n}\n$stmt->execute($binds);\n$rows = $stmt->fetchAll(\\PDO::FETCH_ASSOC);\nreturn $rows;",
                        "declaration": "public function query(string $sql, array $binds=[])"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "tableName",
                                "declaration": "string $tableName"
                            },
                            {
                                "type": "arg",
                                "arg_types": [
                                    "array"
                                ],
                                "name": "whereCols",
                                "value": "[]",
                                "declaration": "array $whereCols=[]"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Get rows from a table with the given $whereCols"
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "select",
                        "body": "$sql = \"SELECT * FROM `${tableName}` \";\n$binds = static::keysToBinds($whereCols);\nif (count($whereCols)>0){\n    $whereStr = \"Where \".static::whereSqlFromCols($whereCols);\n    $sql .= $whereStr;\n}\n$rows = $this->query($sql, $binds);\nreturn $rows;",
                        "declaration": "public function select(string $tableName, array $whereCols=[])"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "table",
                                "declaration": "string $table"
                            },
                            {
                                "type": "arg",
                                "arg_types": [
                                    "array"
                                ],
                                "name": "row",
                                "declaration": "array $row"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Insert a row into the database",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "throws",
                                    "description": "Exception if the insert fails"
                                },
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "the newly inserted id"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "insert",
                        "body": "$pdo = $this->pdo;\n$cols = [];\n$binds = [];\nforeach ($row as $key=>$value){\n    $cols[] = $key;\n    $binds[\":{$key}\"] = $value;\n}\n$colsStr = '`'.implode('`, `',$cols).'`';\n$bindsStr = implode(', ', array_keys($binds));\n$query = \"INSERT INTO `${table}`(${colsStr})\n        VALUES (${bindsStr})\n    \";\n$stmt = $pdo->prepare($query);\nif ($stmt===false){\n    throw new \\Exception(\"Could not insert values into databse.\". print_r($pdo->errorInfo(),true));\n}\n$stmt->execute($binds);\nif ($stmt->errorCode()!=='00000'){\n    print_r($stmt->errorInfo());\n    throw new \\Exception(\"There was an error inserting data\");\n}\nreturn $pdo->lastInsertId();",
                        "declaration": "public function insert(string $table, array $row)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "table",
                                "declaration": "string $table"
                            },
                            {
                                "type": "arg",
                                "arg_types": [
                                    "array"
                                ],
                                "name": "rowSet",
                                "declaration": "array $rowSet"
                            }
                        ],
                        "modifiers": [
                            "public"
                        ],
                        "name": "insertAll",
                        "body": "foreach ($rowSet as $row){\n    $lastInsertId = $this->insert($table, (array)$row);\n}\nreturn $lastInsertId;",
                        "declaration": "public function insertAll(string $table, array $rowSet)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "table",
                                "declaration": "string $table"
                            },
                            {
                                "type": "arg",
                                "arg_types": [
                                    "array"
                                ],
                                "name": "newRowValues",
                                "declaration": "array $newRowValues"
                            },
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "idColumnName",
                                "value": "'id'",
                                "declaration": "string $idColumnName='id'"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Update an existing row. Shorthand for `updateWhere()` with the id column set as the where values."
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "update",
                        "body": "return $this->updateWhere($table, $newRowValues, [$idColumnName=>$newRowValues[$idColumnName]]);",
                        "declaration": "public function update(string $table, array $newRowValues, string $idColumnName='id')"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "table",
                                "declaration": "string $table"
                            },
                            {
                                "type": "arg",
                                "arg_types": [
                                    "array"
                                ],
                                "name": "newRowValues",
                                "declaration": "array $newRowValues"
                            },
                            {
                                "type": "arg",
                                "arg_types": [
                                    "array"
                                ],
                                "name": "whereVals",
                                "declaration": "array $whereVals"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "$whereVals To update ALL rows, pass `[]`"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "updateWhere",
                        "body": "$valueBinds = [];\n$setSql = [];\nforeach ($newRowValues as $col=>$value){\n    $valueBinds[$bindKey=':'.$col.'_value'] = $value;\n    $setSql[] = \"`$col` = $bindKey\";\n}\n$setSql = implode(\",\\n\", $setSql);\n$whereSql = static::whereSqlFromCols($whereVals);\nif (strlen(trim($whereSql))>0)$whereSql = \"WHERE\\n${whereSql}\";\n$sql = <<<SQL\n    UPDATE `${table}`\n    SET $setSql\n    ${whereSql}\nSQL;\n$binds = array_merge($valueBinds, $whereVals);\n$binds  = static::keysToBinds($binds);\n$this->execute($sql,$binds);",
                        "declaration": "public function updateWhere(string $table, array $newRowValues, array $whereVals)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "table",
                                "declaration": "string $table"
                            },
                            {
                                "type": "arg",
                                "arg_types": [
                                    "array"
                                ],
                                "name": "whereCols",
                                "declaration": "array $whereCols"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Delete rows from a table",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "true if any rows were deleted. false otherwise"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "delete",
                        "body": "$sql = static::whereSqlFromCols($whereCols);\nif ($sql!=null)$sql = 'WHERE '.$sql;\n$sql = \"DELETE FROM `${table}` ${sql}\";\n$stmt = $this->execute($sql, $whereCols);\n\/\/ var_dump($stmt->errorCode());\n\/\/ exit;\n\/\/ var_dump($stmt->rowCount());\n\/\/ exit;\nif ($stmt->errorCode()=='00000'\n    &&$stmt->rowCount()>0)return true;\nreturn false;\n\/\/ return $stmt;",
                        "declaration": "public function delete(string $table, array $whereCols)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "sql",
                                "declaration": "string $sql"
                            },
                            {
                                "type": "arg",
                                "arg_types": [
                                    "array"
                                ],
                                "name": "binds",
                                "value": "[]",
                                "declaration": "array $binds=[]"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Execute an Sql statement & get a PDOStatement back",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "throws",
                                    "description": "if the statement fails to prepare"
                                },
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "PDOStatement"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "execute",
                        "body": "$pdo = $this->pdo;\n$stmt = $pdo->prepare($sql);\nif ($stmt===false){\n    $error = var_export($pdo->errorInfo(),true);\n    throw new \\Exception(\"Sql problem: \\n\".$error.\"\\n\\n\");\n}\n$stmt->execute($binds);\nreturn $stmt;",
                        "declaration": "public function execute(string $sql, array $binds=[])"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "sql",
                                "declaration": "string $sql"
                            },
                            {
                                "type": "arg",
                                "arg_types": [
                                    "array"
                                ],
                                "name": "binds",
                                "value": "[]",
                                "declaration": "array $binds=[]"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Alias for `execute()`",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "PDOStatement"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "exec",
                        "body": "return $this->execute($sql, $binds);",
                        "declaration": "public function exec(string $sql, array $binds=[])"
                    },
                    {
                        "type": "method",
                        "args": [],
                        "docblock": {
                            "type": "docblock",
                            "description": "get the pdo object"
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "getPdo",
                        "body": "return $this->pdo;",
                        "declaration": "public function getPdo()"
                    },
                    {
                        "type": "method",
                        "args": [],
                        "docblock": {
                            "type": "docblock",
                            "description": "get the pdo object"
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "pdo",
                        "body": "return $this->pdo;",
                        "declaration": "public function pdo()"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "array"
                                ],
                                "name": "columns",
                                "declaration": "array $columns"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Convert key=>value array into a 'WHERE' sql.\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "$columns `['key'=>$val, ':key2'=>$val]`. `$val` can be string, array, or numeric."
                                },
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "string sql for a WHERE statement. Does not include `WHERE`"
                                },
                                {
                                    "type": "attribute",
                                    "name": "exampleOutput",
                                    "description": ": `key = :val1 AND key2 LIKE :val2, AND key3 IN (:val3_1,:val3_2)`."
                                }
                            ]
                        },
                        "modifiers": [
                            "static",
                            "public"
                        ],
                        "name": "whereSqlFromCols",
                        "body": "$binds = static::keysToBinds($columns);\n\/\/generate sql\n$pieces = [];\n$copy = $binds;\nforeach ($copy as $k=>$v){\n    $col = substr($k,1);\n    if (is_string($v)){\n        $pieces[] = \"`$col` LIKE $k\";\n    } else if (is_array($v)){\n        unset($binds[$k]);\n        $inList = [];\n        foreach ($v as $index=>$inValue){\n            $inKey = $k.$index;\n            $binds[$inKey] = $inValue;\n            $inList[] = $inKey;\n        }\n        $pieces[] = \"`$col` IN (\".implode(', ',$inList).\")\";\n    } else {\n        $pieces[] = \"`$col` = $k\";\n    }\n}\n$sql = implode(' AND ', $pieces);\nreturn $sql;",
                        "declaration": "static public function whereSqlFromCols(array $columns)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "array"
                                ],
                                "name": "keyedValues",
                                "declaration": "array $keyedValues"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Convert an array `['key'=>$val, ':key2'=>$val]` into binds: `[':key'=>$val, ':key2'=>$val]`.\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "array where keys are prefixed with a colon (:)"
                                }
                            ]
                        },
                        "modifiers": [
                            "static",
                            "public"
                        ],
                        "name": "keysToBinds",
                        "body": "$binds = [];\nforeach ($keyedValues as $k=>$v){\n    if (!is_string($k)){\n        $binds[] = $v;\n    } else if (substr($k,0,1)==':'){\n        $binds[$k] = $v;\n    } else {\n        $binds[':'.$k] = $v;\n    }\n}\nreturn $binds;",
                        "declaration": "static public function keysToBinds(array $keyedValues)"
                    }
                ]
            }
        ]
    }
}Array
(
    [type] => file
    [namespace] => Array
        (
            [type] => namespace
            [name] => Tlf
            [declaration] => namespace Tlf;
            [class] => Array
                (
                    [0] => Array
                        (
                            [type] => class
                            [docblock] => Array
                                (
                                    [type] => docblock
                                    [description] => A lil tiny database class
                                )

                            [namespace] => Tlf
                            [fqn] => Tlf\LilDb
                            [name] => LilDb
                            [declaration] => class LilDb
                            [properties] => Array
                                (
                                    [0] => Array
                                        (
                                            [type] => property
                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                    [1] => \PDO
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => a pdo instance
                                                )

                                            [name] => pdo
                                            [declaration] => public \PDO $pdo;
                                        )

                                )

                            [methods] => Array
                                (
                                    [0] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => user
                                                            [declaration] => string $user
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => password
                                                            [declaration] => string $password
                                                        )

                                                    [2] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => db
                                                            [declaration] => string $db
                                                        )

                                                    [3] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => host
                                                            [value] => 'localhost'
                                                            [declaration] => $host='localhost'
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Convenience method to initialize with pdo
                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => Tlf\LilDb
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => static
                                                    [1] => public
                                                )

                                            [name] => new
                                            [body] => $pdo = new \PDO("mysql:dbname=${db};host=${host}", $user, $password);
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$ldb = new static($pdo);
return $ldb;
                                            [declaration] => static public function new(string $user, string $password, string $db, $host='localhost')
                                        )

                                    [1] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => dbName
                                                            [value] => ':memory:'
                                                            [declaration] => string $dbName = ':memory:'
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Convenience method to initialize sqlite db in memory
                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => Tlf\LilDb
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => static
                                                    [1] => public
                                                )

                                            [name] => sqlite
                                            [body] => $pdo = new \PDO('sqlite:'.$dbName);
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$ldb = new static($pdo);
return $ldb;
                                            [declaration] => static public function sqlite(string $dbName = ':memory:')
                                        )

                                    [2] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => dbName
                                                            [value] => ':memory:'
                                                            [declaration] => $dbName = ':memory:'
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Convenience method to initialize mysql db in memory
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => static
                                                    [1] => public
                                                )

                                            [name] => mysql
                                            [body] => $pdo = new \PDO('mysql:'.$dbName);
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$ldb = new static($pdo);
return $ldb;
                                            [declaration] => static public function mysql($dbName = ':memory:')
                                        )

                                    [3] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => \PDO
                                                                )

                                                            [name] => pdo
                                                            [declaration] => \PDO $pdo
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Initialize with a db handle
                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => $pdo a pdo instance
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => __construct
                                            [body] => $this->pdo = $pdo;
                                            [declaration] => public function __construct(\PDO $pdo)
                                        )

                                    [4] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => tableName
                                                            [declaration] => string $tableName
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => array
                                                                )

                                                            [name] => colDefinitions
                                                            [declaration] => array $colDefinitions
                                                        )

                                                    [2] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => bool
                                                                )

                                                            [name] => recreateIfExists
                                                            [value] => false
                                                            [declaration] => bool $recreateIfExists=false
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Create a new table if it doesn't exist.

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param2
                                                                    [description] => $colDefinitions array of columns like: `['col_name'=>'VARCHAR(80)', 'col_two'=> 'integer']`
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param3
                                                                    [description] => $recreateIfExists true/false to include `DROP TABLE IF EXISTS table_name`
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => create
                                            [body] => $colStatements = [];
foreach ($colDefinitions as $col => $definition){
    $statement = '`'.$col.'` '. $definition;
    $colStatements[] = $statement;
}
$colsSql = implode(", ", $colStatements);
$drop = $recreateIfExists ? "DROP TABLE IF EXISTS `{$tableName}`;\n" : '';
$sql =
<<<SQL
    {$drop}
    CREATE TABLE IF NOT EXISTS `{$tableName}`
    (
    {$colsSql}
    )
    ;
SQL;
$this->exec($sql);
                                            [declaration] => public function create(string $tableName, array $colDefinitions, bool $recreateIfExists=false)
                                        )

                                    [5] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => sql
                                                            [declaration] => string $sql
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => array
                                                                )

                                                            [name] => binds
                                                            [value] => []
                                                            [declaration] => array $binds=[]
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Execute an Sql statement & get rows back
                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => throws
                                                                    [description] => if the statement fails to prepare
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => query
                                            [body] => $pdo = $this->pdo;
$stmt = $pdo->prepare($sql);
if ($stmt===false){
    $error = var_export($pdo->errorInfo(),true);
    throw new \Exception("Sql problem: \n".$error."\n\n");
}
$stmt->execute($binds);
$rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
return $rows;
                                            [declaration] => public function query(string $sql, array $binds=[])
                                        )

                                    [6] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => tableName
                                                            [declaration] => string $tableName
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => array
                                                                )

                                                            [name] => whereCols
                                                            [value] => []
                                                            [declaration] => array $whereCols=[]
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Get rows from a table with the given $whereCols
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => select
                                            [body] => $sql = "SELECT * FROM `${tableName}` ";
$binds = static::keysToBinds($whereCols);
if (count($whereCols)>0){
    $whereStr = "Where ".static::whereSqlFromCols($whereCols);
    $sql .= $whereStr;
}
$rows = $this->query($sql, $binds);
return $rows;
                                            [declaration] => public function select(string $tableName, array $whereCols=[])
                                        )

                                    [7] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => table
                                                            [declaration] => string $table
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => array
                                                                )

                                                            [name] => row
                                                            [declaration] => array $row
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Insert a row into the database
                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => throws
                                                                    [description] => Exception if the insert fails
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => the newly inserted id
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => insert
                                            [body] => $pdo = $this->pdo;
$cols = [];
$binds = [];
foreach ($row as $key=>$value){
    $cols[] = $key;
    $binds[":{$key}"] = $value;
}
$colsStr = '`'.implode('`, `',$cols).'`';
$bindsStr = implode(', ', array_keys($binds));
$query = "INSERT INTO `${table}`(${colsStr})
        VALUES (${bindsStr})
    ";
$stmt = $pdo->prepare($query);
if ($stmt===false){
    throw new \Exception("Could not insert values into databse.". print_r($pdo->errorInfo(),true));
}
$stmt->execute($binds);
if ($stmt->errorCode()!=='00000'){
    print_r($stmt->errorInfo());
    throw new \Exception("There was an error inserting data");
}
return $pdo->lastInsertId();
                                            [declaration] => public function insert(string $table, array $row)
                                        )

                                    [8] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => table
                                                            [declaration] => string $table
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => array
                                                                )

                                                            [name] => rowSet
                                                            [declaration] => array $rowSet
                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => insertAll
                                            [body] => foreach ($rowSet as $row){
    $lastInsertId = $this->insert($table, (array)$row);
}
return $lastInsertId;
                                            [declaration] => public function insertAll(string $table, array $rowSet)
                                        )

                                    [9] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => table
                                                            [declaration] => string $table
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => array
                                                                )

                                                            [name] => newRowValues
                                                            [declaration] => array $newRowValues
                                                        )

                                                    [2] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => idColumnName
                                                            [value] => 'id'
                                                            [declaration] => string $idColumnName='id'
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Update an existing row. Shorthand for `updateWhere()` with the id column set as the where values.
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => update
                                            [body] => return $this->updateWhere($table, $newRowValues, [$idColumnName=>$newRowValues[$idColumnName]]);
                                            [declaration] => public function update(string $table, array $newRowValues, string $idColumnName='id')
                                        )

                                    [10] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => table
                                                            [declaration] => string $table
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => array
                                                                )

                                                            [name] => newRowValues
                                                            [declaration] => array $newRowValues
                                                        )

                                                    [2] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => array
                                                                )

                                                            [name] => whereVals
                                                            [declaration] => array $whereVals
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => 
                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => $whereVals To update ALL rows, pass `[]`
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => updateWhere
                                            [body] => $valueBinds = [];
$setSql = [];
foreach ($newRowValues as $col=>$value){
    $valueBinds[$bindKey=':'.$col.'_value'] = $value;
    $setSql[] = "`$col` = $bindKey";
}
$setSql = implode(",\n", $setSql);
$whereSql = static::whereSqlFromCols($whereVals);
if (strlen(trim($whereSql))>0)$whereSql = "WHERE\n${whereSql}";
$sql = <<<SQL
    UPDATE `${table}`
    SET $setSql
    ${whereSql}
SQL;
$binds = array_merge($valueBinds, $whereVals);
$binds  = static::keysToBinds($binds);
$this->execute($sql,$binds);
                                            [declaration] => public function updateWhere(string $table, array $newRowValues, array $whereVals)
                                        )

                                    [11] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => table
                                                            [declaration] => string $table
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => array
                                                                )

                                                            [name] => whereCols
                                                            [declaration] => array $whereCols
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Delete rows from a table
                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => true if any rows were deleted. false otherwise
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => delete
                                            [body] => $sql = static::whereSqlFromCols($whereCols);
if ($sql!=null)$sql = 'WHERE '.$sql;
$sql = "DELETE FROM `${table}` ${sql}";
$stmt = $this->execute($sql, $whereCols);
// var_dump($stmt->errorCode());
// exit;
// var_dump($stmt->rowCount());
// exit;
if ($stmt->errorCode()=='00000'
    &&$stmt->rowCount()>0)return true;
return false;
// return $stmt;
                                            [declaration] => public function delete(string $table, array $whereCols)
                                        )

                                    [12] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => sql
                                                            [declaration] => string $sql
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => array
                                                                )

                                                            [name] => binds
                                                            [value] => []
                                                            [declaration] => array $binds=[]
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Execute an Sql statement & get a PDOStatement back
                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => throws
                                                                    [description] => if the statement fails to prepare
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => PDOStatement
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => execute
                                            [body] => $pdo = $this->pdo;
$stmt = $pdo->prepare($sql);
if ($stmt===false){
    $error = var_export($pdo->errorInfo(),true);
    throw new \Exception("Sql problem: \n".$error."\n\n");
}
$stmt->execute($binds);
return $stmt;
                                            [declaration] => public function execute(string $sql, array $binds=[])
                                        )

                                    [13] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => sql
                                                            [declaration] => string $sql
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => array
                                                                )

                                                            [name] => binds
                                                            [value] => []
                                                            [declaration] => array $binds=[]
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Alias for `execute()`
                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => PDOStatement
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => exec
                                            [body] => return $this->execute($sql, $binds);
                                            [declaration] => public function exec(string $sql, array $binds=[])
                                        )

                                    [14] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => get the pdo object
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => getPdo
                                            [body] => return $this->pdo;
                                            [declaration] => public function getPdo()
                                        )

                                    [15] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => get the pdo object
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => pdo
                                            [body] => return $this->pdo;
                                            [declaration] => public function pdo()
                                        )

                                    [16] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => array
                                                                )

                                                            [name] => columns
                                                            [declaration] => array $columns
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Convert key=>value array into a 'WHERE' sql.

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => $columns `['key'=>$val, ':key2'=>$val]`. `$val` can be string, array, or numeric.
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => string sql for a WHERE statement. Does not include `WHERE`
                                                                )

                                                            [2] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => exampleOutput
                                                                    [description] => : `key = :val1 AND key2 LIKE :val2, AND key3 IN (:val3_1,:val3_2)`.
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => static
                                                    [1] => public
                                                )

                                            [name] => whereSqlFromCols
                                            [body] => $binds = static::keysToBinds($columns);
//generate sql
$pieces = [];
$copy = $binds;
foreach ($copy as $k=>$v){
    $col = substr($k,1);
    if (is_string($v)){
        $pieces[] = "`$col` LIKE $k";
    } else if (is_array($v)){
        unset($binds[$k]);
        $inList = [];
        foreach ($v as $index=>$inValue){
            $inKey = $k.$index;
            $binds[$inKey] = $inValue;
            $inList[] = $inKey;
        }
        $pieces[] = "`$col` IN (".implode(', ',$inList).")";
    } else {
        $pieces[] = "`$col` = $k";
    }
}
$sql = implode(' AND ', $pieces);
return $sql;
                                            [declaration] => static public function whereSqlFromCols(array $columns)
                                        )

                                    [17] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => array
                                                                )

                                                            [name] => keyedValues
                                                            [declaration] => array $keyedValues
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Convert an array `['key'=>$val, ':key2'=>$val]` into binds: `[':key'=>$val, ':key2'=>$val]`.

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => array where keys are prefixed with a colon (:)
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => static
                                                    [1] => public
                                                )

                                            [name] => keysToBinds
                                            [body] => $binds = [];
foreach ($keyedValues as $k=>$v){
    if (!is_string($k)){
        $binds[] = $v;
    } else if (substr($k,0,1)==':'){
        $binds[$k] = $v;
    } else {
        $binds[':'.$k] = $v;
    }
}
return $binds;
                                            [declaration] => static public function keysToBinds(array $keyedValues)
                                        )

                                )

                        )

                )

        )

)
{
    "type": "file",
    "namespace": {
        "type": "namespace",
        "name": "Tlf",
        "declaration": "namespace Tlf;",
        "class": [
            {
                "type": "class",
                "docblock": {
                    "type": "docblock",
                    "description": "A minimal class for handling sql migration. Create a migrations dir. Then create dirs like `v1`, `v2` & create files `up.sql`, `down.sql` in each versioned dir. Migrating from 1 to 2 will execute `v2\/up.sql`. From 3 down to 1 will execute `v2\/down.sql` and `v1\/down.sql`. You may also make files like `v1\/up-1.sql`, `v1\/up-2.sql` to execute multiple files in order.\n",
                    "attribute": [
                        {
                            "type": "attribute",
                            "name": "tagline",
                            "description": "Easy to use SQL Migrations from versioned directories"
                        }
                    ]
                },
                "namespace": "Tlf",
                "fqn": "Tlf\\LilMigrations",
                "name": "LilMigrations",
                "declaration": "class LilMigrations",
                "properties": [
                    {
                        "type": "property",
                        "modifiers": [
                            "public",
                            "\\PDO"
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "a pdo instance"
                        },
                        "name": "pdo",
                        "declaration": "public \\PDO $pdo;"
                    },
                    {
                        "type": "property",
                        "modifiers": [
                            "public",
                            "string"
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "the dir for migrations scripts."
                        },
                        "name": "dir",
                        "declaration": "public string $dir;"
                    }
                ],
                "methods": [
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "\\PDO"
                                ],
                                "name": "pdo",
                                "declaration": "\\PDO $pdo"
                            },
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "dir",
                                "declaration": "string $dir"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "In $dir, there should be directories named 'v1', 'v2', 'v3', and so on.\nIn the v1\/v2\/v3 dirs, there should be up.sql & down.sql files with valid SQL statements for whatever database you're using\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "$pdo a pdo instance"
                                },
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "$dir a directory path"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "__construct",
                        "body": "$this->pdo = $pdo;\n$this->dir = $dir;",
                        "declaration": "public function __construct(\\PDO $pdo, string $dir)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "dbName",
                                "value": "':memory:'",
                                "declaration": "string $dbName = ':memory:'"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Convenience method to initialize sqlite db in memory",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "Tlf\\LilDb"
                                }
                            ]
                        },
                        "modifiers": [
                            "static",
                            "public"
                        ],
                        "name": "sqlite",
                        "body": "$pdo = new \\PDO('sqlite:'.$dbName);\n$pdo->setAttribute(\\PDO::ATTR_ERRMODE, \\PDO::ERRMODE_EXCEPTION);\n$ldb = new static($pdo);\nreturn $ldb;",
                        "declaration": "static public function sqlite(string $dbName = ':memory:')"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "int"
                                ],
                                "name": "old",
                                "declaration": "int $old"
                            },
                            {
                                "type": "arg",
                                "arg_types": [
                                    "int"
                                ],
                                "name": "new",
                                "declaration": "int $new"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Migrate from old version to new\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "$old the current version of the database"
                                },
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "$new the new version of the database to go to"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "migrate",
                        "body": "if ($old < $new){\n    for ($i=$old+1; $i <= $new; $i++){\n        $this->run_migration_version($i, 'up');\n    }\n} else if ($old > $new) {\n    for ($i=$old-1; $i >= $new; $i--){\n        $this->run_migration_version($i, 'down');\n    }\n} else {\n    $this->run_migration_version($i, 'up');\n}",
                        "declaration": "public function migrate(int $old, int $new)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "version",
                                "declaration": "$version"
                            },
                            {
                                "type": "arg",
                                "name": "up_or_down",
                                "declaration": "$up_or_down"
                            }
                        ],
                        "modifiers": [
                            "public"
                        ],
                        "name": "run_migration_version",
                        "body": "$i = $version;\n$file = $up_or_down;\n$v_dir = \"v$i\/\";\n$migrate_dir = $this->dir.'\/'.$v_dir;\n$files = is_dir($migrate_dir) ? scandir($migrate_dir) : false;\nif ($files==false){\n    echo \"\\nMigrations dir $v_dir does not exist. Continuing.\";\n    return;\n}\n$files = array_filter($files,\n    function($v) use ($file){\n        if (substr($v,0,strlen($file))==$file)return true;\n        return false;\n    });\n\/\/@todo test the file sorting\n\/\/ \/\/ for testing\n\/\/ rsort($files);\n\/\/\n\/\/ $files = ['up-9.sql', 'up-2.sql', 'up-13.sql', 'up-0.sql', 'up.sql', 'up-1.sql'];\nusort($files,\n    function($v1, $v2){\n        $pos1 = strpos($v1,'-');\n        if ($pos1==false)$index1 = -1;\n        else $index1 = (int)substr($v1,$pos1+1,-4);\n        $pos2 = strpos($v2,'-');\n        if ($pos2==false)$index2 = -1;\n        else $index2 = (int)substr($v2,$pos2+1,-4);\n        return $index1-$index2;\n    }\n);\nforeach ($files as $f){\n    $rel = $v_dir.$f;\n    $exec_file = $this->dir.'\/'.$rel;\n    $exec_file = $this->dir.'\/'.$rel;\n    if (!file_exists($exec_file)){\n        echo \"\\nFile '$rel' was not found for migrations.\";\n        continue;\n    }\n    echo \"\\nExecute '$rel'\";\n    $sql = file_get_contents($exec_file);\n    $this->pdo->exec($sql);\n    if ($this->pdo->errorCode()!='00000'){\n        echo \"\\nSQL Error in '$rel':\\n\";\n        print_r($this->pdo->errorInfo());\n        return;\n    }\n}",
                        "declaration": "public function run_migration_version($version, $up_or_down)"
                    }
                ]
            }
        ]
    }
}Array
(
    [type] => file
    [namespace] => Array
        (
            [type] => namespace
            [name] => Tlf
            [declaration] => namespace Tlf;
            [class] => Array
                (
                    [0] => Array
                        (
                            [type] => class
                            [docblock] => Array
                                (
                                    [type] => docblock
                                    [description] => A minimal class for handling sql migration. Create a migrations dir. Then create dirs like `v1`, `v2` & create files `up.sql`, `down.sql` in each versioned dir. Migrating from 1 to 2 will execute `v2/up.sql`. From 3 down to 1 will execute `v2/down.sql` and `v1/down.sql`. You may also make files like `v1/up-1.sql`, `v1/up-2.sql` to execute multiple files in order.

                                    [attribute] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [type] => attribute
                                                    [name] => tagline
                                                    [description] => Easy to use SQL Migrations from versioned directories
                                                )

                                        )

                                )

                            [namespace] => Tlf
                            [fqn] => Tlf\LilMigrations
                            [name] => LilMigrations
                            [declaration] => class LilMigrations
                            [properties] => Array
                                (
                                    [0] => Array
                                        (
                                            [type] => property
                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                    [1] => \PDO
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => a pdo instance
                                                )

                                            [name] => pdo
                                            [declaration] => public \PDO $pdo;
                                        )

                                    [1] => Array
                                        (
                                            [type] => property
                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                    [1] => string
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => the dir for migrations scripts.
                                                )

                                            [name] => dir
                                            [declaration] => public string $dir;
                                        )

                                )

                            [methods] => Array
                                (
                                    [0] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => \PDO
                                                                )

                                                            [name] => pdo
                                                            [declaration] => \PDO $pdo
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => dir
                                                            [declaration] => string $dir
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => In $dir, there should be directories named 'v1', 'v2', 'v3', and so on.
In the v1/v2/v3 dirs, there should be up.sql & down.sql files with valid SQL statements for whatever database you're using

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => $pdo a pdo instance
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => $dir a directory path
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => __construct
                                            [body] => $this->pdo = $pdo;
$this->dir = $dir;
                                            [declaration] => public function __construct(\PDO $pdo, string $dir)
                                        )

                                    [1] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => dbName
                                                            [value] => ':memory:'
                                                            [declaration] => string $dbName = ':memory:'
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Convenience method to initialize sqlite db in memory
                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => Tlf\LilDb
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => static
                                                    [1] => public
                                                )

                                            [name] => sqlite
                                            [body] => $pdo = new \PDO('sqlite:'.$dbName);
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$ldb = new static($pdo);
return $ldb;
                                            [declaration] => static public function sqlite(string $dbName = ':memory:')
                                        )

                                    [2] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => int
                                                                )

                                                            [name] => old
                                                            [declaration] => int $old
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => int
                                                                )

                                                            [name] => new
                                                            [declaration] => int $new
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Migrate from old version to new

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => $old the current version of the database
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => $new the new version of the database to go to
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => migrate
                                            [body] => if ($old < $new){
    for ($i=$old+1; $i <= $new; $i++){
        $this->run_migration_version($i, 'up');
    }
} else if ($old > $new) {
    for ($i=$old-1; $i >= $new; $i--){
        $this->run_migration_version($i, 'down');
    }
} else {
    $this->run_migration_version($i, 'up');
}
                                            [declaration] => public function migrate(int $old, int $new)
                                        )

                                    [3] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => version
                                                            [declaration] => $version
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => up_or_down
                                                            [declaration] => $up_or_down
                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => run_migration_version
                                            [body] => $i = $version;
$file = $up_or_down;
$v_dir = "v$i/";
$migrate_dir = $this->dir.'/'.$v_dir;
$files = is_dir($migrate_dir) ? scandir($migrate_dir) : false;
if ($files==false){
    echo "\nMigrations dir $v_dir does not exist. Continuing.";
    return;
}
$files = array_filter($files,
    function($v) use ($file){
        if (substr($v,0,strlen($file))==$file)return true;
        return false;
    });
//@todo test the file sorting
// // for testing
// rsort($files);
//
// $files = ['up-9.sql', 'up-2.sql', 'up-13.sql', 'up-0.sql', 'up.sql', 'up-1.sql'];
usort($files,
    function($v1, $v2){
        $pos1 = strpos($v1,'-');
        if ($pos1==false)$index1 = -1;
        else $index1 = (int)substr($v1,$pos1+1,-4);
        $pos2 = strpos($v2,'-');
        if ($pos2==false)$index2 = -1;
        else $index2 = (int)substr($v2,$pos2+1,-4);
        return $index1-$index2;
    }
);
foreach ($files as $f){
    $rel = $v_dir.$f;
    $exec_file = $this->dir.'/'.$rel;
    $exec_file = $this->dir.'/'.$rel;
    if (!file_exists($exec_file)){
        echo "\nFile '$rel' was not found for migrations.";
        continue;
    }
    echo "\nExecute '$rel'";
    $sql = file_get_contents($exec_file);
    $this->pdo->exec($sql);
    if ($this->pdo->errorCode()!='00000'){
        echo "\nSQL Error in '$rel':\n";
        print_r($this->pdo->errorInfo());
        return;
    }
}
                                            [declaration] => public function run_migration_version($version, $up_or_down)
                                        )

                                )

                        )

                )

        )

)
{
    "type": "file",
    "namespace": {
        "type": "namespace",
        "name": "Tlf",
        "declaration": "namespace Tlf;",
        "class": [
            {
                "type": "class",
                "docblock": {
                    "type": "docblock",
                    "description": "This is a minimal version of LilMigrations for debugging the properties issue"
                },
                "namespace": "Tlf",
                "fqn": "Tlf\\LilMigrationsBug",
                "name": "LilMigrationsBug",
                "declaration": "class LilMigrationsBug",
                "properties": [
                    {
                        "type": "property",
                        "modifiers": [
                            "public"
                        ],
                        "name": "prop",
                        "value": "'okay'",
                        "declaration": "public $prop = 'okay';"
                    }
                ],
                "methods": [
                    {
                        "type": "method",
                        "args": [],
                        "modifiers": [
                            "public"
                        ],
                        "name": "ok",
                        "body": "function() use ($file){\n    return;\n};\n$abc = 'def';",
                        "declaration": "public function ok()"
                    }
                ]
            }
        ]
    }
}Array
(
    [type] => file
    [namespace] => Array
        (
            [type] => namespace
            [name] => Tlf
            [declaration] => namespace Tlf;
            [class] => Array
                (
                    [0] => Array
                        (
                            [type] => class
                            [docblock] => Array
                                (
                                    [type] => docblock
                                    [description] => This is a minimal version of LilMigrations for debugging the properties issue
                                )

                            [namespace] => Tlf
                            [fqn] => Tlf\LilMigrationsBug
                            [name] => LilMigrationsBug
                            [declaration] => class LilMigrationsBug
                            [properties] => Array
                                (
                                    [0] => Array
                                        (
                                            [type] => property
                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => prop
                                            [value] => 'okay'
                                            [declaration] => public $prop = 'okay';
                                        )

                                )

                            [methods] => Array
                                (
                                    [0] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => ok
                                            [body] => function() use ($file){
    return;
};
$abc = 'def';
                                            [declaration] => public function ok()
                                        )

                                )

                        )

                )

        )

)
{
    "type": "file",
    "namespace": {
        "type": "namespace",
        "name": "Phad\\Test\\Integration",
        "declaration": "namespace Phad\\Test\\Integration;",
        "class": [
            {
                "type": "class",
                "docblock": {
                    "type": "docblock",
                    "description": "This class appears to test both form compilation and form submission\n",
                    "attribute": [
                        {
                            "type": "attribute",
                            "name": "notice",
                            "description": "Several of these tests incidentally test the submit target\/redirect feature."
                        }
                    ]
                },
                "namespace": "Phad\\Test\\Integration",
                "fqn": "Phad\\Test\\Integration\\Forms",
                "name": "Forms",
                "extends": "\\Phad\\Tester",
                "declaration": "class Forms extends \\Phad\\Tester",
                "properties": [
                    {
                        "type": "property",
                        "modifiers": [
                            "protected",
                            "array"
                        ],
                        "name": "blogTableColumns",
                        "value": "['id'=>'INTEGER PRIMARY KEY','title'=>'VARCHAR(200)','body'=>'VARCHAR(2000)']",
                        "declaration": "protected array $blogTableColumns = ['id'=>'INTEGER PRIMARY KEY','title'=>'VARCHAR(200)', 'body'=>'VARCHAR(2000)'];"
                    }
                ],
                "methods": [
                    {
                        "type": "method",
                        "args": [],
                        "modifiers": [
                            "public"
                        ],
                        "name": "testDeleteItem",
                        "body": "$lildb = \\Tlf\\LilDb::sqlite();\n$pdo = $lildb->pdo();\n$phad = $this->phad();\n$phad->pdo = $pdo;\n$lildb->create('blog',['id'=>'integer', 'title'=>'varchar(90)']);\n$lildb->insert('blog',['id'=>1,'title'=>'title 1']);\n$lildb->insert('blog',['id'=>2,'title'=>'title 2']);\n$lildb->insert('blog',['id'=>3,'title'=>'title 3']);\n$form = new \\Phad\\View('Form\/Deleteable', $this->file('test\/input\/views\/'),\n    ['id'=>2, 'phad'=>$phad]);\n$form->force_compile = true;\n$form->delete();\n$blogs = $lildb->select('blog');\n$this->compare(\n    [ ['id'=>1,'title'=>'title 1'],\n      ['id'=>3,'title'=>'title 3'],\n    ],\n    $blogs\n);",
                        "declaration": "public function testDeleteItem()"
                    },
                    {
                        "type": "method",
                        "args": [],
                        "modifiers": [
                            "public"
                        ],
                        "name": "testErrorMessage",
                        "body": "$pdo = $this->getPdo();\n$phad = $this->phad();\n$phad->pdo = $pdo;\n$view = $phad->view('Form\/SimpleBlogWithError');\n$_SERVER['HTTP_HOST'] = 'localhost';\n$_SERVER['HTTPS'] = 'non-empty-value';\n$BlogRow = ['body'=>'smol body', 'title'=>''];\n$out = $view->submit($BlogRow);\n$msg = $phad->validationErrorMessage($phad->failed_submit_columns);\n$this->test('Error Message Written');\n    $this->str_not_contains($out, ['<error>','<\/error>']);\n    $this->str_contains($out, '<div class=\"my-error-class\">'.$msg.'<\/div>');\n$this->test('Headers empty');\n    $this->compare(\n        [],\n        $phad->getHeaders(),\n    );",
                        "declaration": "public function testErrorMessage()"
                    },
                    {
                        "type": "method",
                        "args": [],
                        "modifiers": [
                            "public"
                        ],
                        "name": "testSubmitDocumentation",
                        "body": "$_SERVER['HTTP_HOST'] = 'localhost';\n$_SERVER['HTTPS'] = 'non-empty-value';\n$ldb = \\Tlf\\LilDb::sqlite();\n$pdo = $ldb->pdo();\n$ldb->create('blog', $this->blogTableColumns);\n$phad = $this->phad();\n$phad->pdo = $pdo;\n$view = $phad->view('Form\/SimpleBlogNoTarget');\n\/\/if `id` were set, an UPDATE would be done instead.\n$BlogRow = ['title'=>'Fine Title', 'body'=>'I have to be at least 50 characters. But that isn\\'t very long.'];\n$out = $view->submit($BlogRow);\n$BlogRow['id'] = $pdo->lastInsertId();\n$headers = $phad->getHeaders();\n\/\/you can foreach(as $h){ header(...$h) }\n\/\/@export_end(Forms.ManualSubmission)\n$this->test('Headers');\n    $this->compare(\n        [['Location: https:\/\/localhost\/', true]],\n        $phad->getHeaders(),\n    );\n$this->test('Data Was Inserted');\n    $this->compare(\n        [$BlogRow],\n        $ldb->query('SELECT * FROM blog')\n    );",
                        "declaration": "public function testSubmitDocumentation()"
                    },
                    {
                        "type": "method",
                        "args": [],
                        "modifiers": [
                            "public"
                        ],
                        "name": "testControllerOnSubmitDocumentation",
                        "body": "$phad = new class() extends \\Phad {\n    public function onSubmit($ItemData, &$ItemRow){\n        if ($ItemData->name!='Blog')return true;\n        $ItemRow['slug'] = str_replace(' ', '-', strtolower($ItemRow['title']));\n        return true;\n    }\n};\n$pdo = $this->getPdo();\n$phad = $this->phad($phad);\n$phad->pdo = $pdo;\n$phad->target_url = '\/blog\/{slug}\/{id}\/';\n$cols = $this->blogTableColumns;\n$cols['slug'] = 'VARCHAR(100)';\n$this->createTable($pdo, 'blog', $cols);\n$_SERVER['HTTP_HOST'] = 'localhost';\n$_SERVER['HTTPS'] = 'non-empty-value';\n$BlogRow =\n    [\n    'title'=>'Fine Title',\n    'body'=>'I have to be at least fifty characters. That shouldn\\'t be much of a problem, though it does require a bit more typing. And if I had something original to say, that would make it better.'\n    ];\n\/** anonymous class to use as our controller *\/\n\/** passing our custom controller & submitting manually *\/\n$view = $phad->view('Form\/SimpleBlogNoTarget');\n\/** $BlogRow is just an array with 'title' & 'body' **\/\n$output = $view->submit($BlogRow);\n$BlogRow['id'] = $pdo->lastInsertId();\n$BlogRow['slug'] = 'fine-title';\n$this->test('There should be no output');\n    $this->handleDidPass(strlen(trim($output))===0);\n$this->test('Headers');\n    $this->compare(\n        [['Location: https:\/\/localhost\/blog\/fine-title\/'.$BlogRow['id'].'\/', true]],\n        $phad->getHeaders(),\n    );\n$this->test('Data Was Inserted');\n    $this->compare(\n        $BlogRow,\n        $this->queryOne($pdo, 'SELECT * FROM blog'),\n    );",
                        "declaration": "public function testControllerOnSubmitDocumentation()"
                    },
                    {
                        "type": "method",
                        "args": [],
                        "modifiers": [
                            "public"
                        ],
                        "name": "testWithInlineOnSubmit",
                        "body": "$pdo = $this->getPdo();\n$phad = $this->phad();\n$phad->pdo = $pdo;\n$phad->target_url = '\/blog\/{slug}\/{id}\/';\n$cols = $this->blogTableColumns;\n$cols['slug'] = 'VARCHAR(100)';\n$this->createTable($pdo, 'blog', $cols);\n$_SERVER['HTTP_HOST'] = 'localhost';\n$_SERVER['HTTPS'] = 'non-empty-value';\n$BlogRow =\n    [\n    'title'=>'Fine Title',\n    'body'=>'I have to be at least fifty characters. That shouldn\\'t be much of a problem, though it does require a bit more typing. And if I had something original to say, that would make it better.'\n    ];\n$view = $phad->view('Form\/BlogWithOnSubmit');\n$output = $view->submit($BlogRow);\n$BlogRow['id'] = $pdo->lastInsertId();\n$BlogRow['slug'] = 'fine-title';\n$this->test('Backend Prop is removed');\n    $this->str_not_contains($phad->view('Form\/BlogWithOnSubmit', $BlogRow), 'type=\"backend\"');\n$this->test('<onsubmit> tag was removed');\n    $this->str_not_contains($phad->view('Form\/BlogWithOnSubmit', $BlogRow), '<onsubmit>');\n$this->test('There should be no output');\n    $this->handleDidPass(strlen(trim($output))===0);\n$this->test('Headers');\n    $this->compare(\n        [['Location: https:\/\/localhost\/blog\/fine-title\/'.$BlogRow['id'].'\/', true]],\n        $phad->getHeaders(),\n    );\n$this->test('Data Was Inserted');\n    $this->compare(\n        $BlogRow,\n        $this->queryOne($pdo, 'SELECT * FROM blog'),\n    );",
                        "declaration": "public function testWithInlineOnSubmit()"
                    },
                    {
                        "type": "method",
                        "args": [],
                        "modifiers": [
                            "public"
                        ],
                        "name": "testInsertWithValidOption",
                        "body": "$pdo = $this->getPdo();\n$phad = $this->phad();\n$phad->pdo = $pdo;\n$view = $phad->view('Form\/BlogWithCategories');\n$cols = $this->blogTableColumns;\n$cols['category'] = 'VARCHAR(100)';\n$this->createTable($pdo, 'blog', $cols);\n$_SERVER['HTTP_HOST'] = 'localhost';\n$_SERVER['HTTPS'] = 'non-empty-value';\n$BlogRow = ['title'=>'Police Brutality super sucks', 'body'=>'Its been well documented that police brutality is a reality, yet there\\'s still overwhelming controversy about what we should do with our society. Some say: Let the police to what they gotta do. Others say: Lets rethink this society that\\'s built upon punishing people who misbehave & actually help people instead. Mayb ewe could redirect some of the MASSIVE tax dollars that go to police departments to actually help someone. That\\'s me. I say that. - Reed',\n    'category'=>'Police Brutality'];\n$out = $view->submit($BlogRow);\n$BlogRow['id'] = $pdo->lastInsertId();\n$this->test('There should be no output');\n    $this->handleDidPass(strlen(trim($out))===0);\n$this->test('Headers');\n    $this->compare(\n        [['Location: https:\/\/localhost\/blog\/'.$BlogRow['title'].'\/', true]],\n        $phad->getHeaders(),\n    );\n$this->test('Data Was Inserted');\n    $this->compare(\n        $BlogRow,\n        $this->queryOne($pdo, 'SELECT * FROM blog'),\n    );",
                        "declaration": "public function testInsertWithValidOption()"
                    },
                    {
                        "type": "method",
                        "args": [],
                        "modifiers": [
                            "public"
                        ],
                        "name": "testUpdateRedirectsToTarget",
                        "body": "\/\/ $phad = $this->phad();\n$pdo = $this->getPdo();\n\/\/ $phad->pdo = $pdo;\n$this->createTable($pdo, 'blog', $this->blogTableColumns);\n$_SERVER['HTTP_HOST'] = 'localhost';\n$_SERVER['HTTPS'] = 'non-empty-value';\n$phad = new class() extends \\Phad {\n    public function t(){\n        echo \"\\ntttttttttttttttt\\n\";\n    }\n    public function objectFromRow($ItemData, $BlogRow){\n        $Blog = (object)$BlogRow;\n        $Blog->slug = str_replace(' ', '-', strtolower($Blog->title));\n        return $Blog;\n    }\n};\n$phad = $this->phad($phad);\n$phad->target_url = '\/blog\/{slug}\/{id}\/';\n$phad->pdo = $pdo;\n$view = $phad->view('Form\/SimpleBlogNoTarget', ['phad'=>$phad]);\n$BlogRow =\n    [\n    'title'=>'Fine Title',\n    'body'=>'I have to be at least fifty characters. That shouldn\\'t be much of a problem, though it does require a bit more typing. And if I had something original to say, that would make it better.'\n    ];\n$out = $view->submit($BlogRow);\n$BlogRow['id'] = $pdo->lastInsertId();\n$this->test('There should be no output');\n    $this->handleDidPass(strlen(trim($out))===0);\n$this->test('Headers');\n    $this->compare(\n        [['Location: https:\/\/localhost\/blog\/fine-title\/'.$BlogRow['id'].'\/', true]],\n        $phad->getHeaders(),\n    );\n$this->test('Data Was Inserted');\n    $this->compare(\n        $BlogRow,\n        $this->queryOne($pdo, 'SELECT * FROM blog'),\n    );",
                        "declaration": "public function testUpdateRedirectsToTarget()"
                    },
                    {
                        "type": "method",
                        "args": [],
                        "modifiers": [
                            "public"
                        ],
                        "name": "testUpdateValid",
                        "body": "$_SERVER['HTTP_HOST'] = 'localhost';\n$_SERVER['HTTPS'] = 'non-empty-value';\n$ldb = \\Tlf\\LilDb::sqlite();\n$phad = $this->phad();\n$phad->pdo = $ldb->pdo();\n$view = $phad->view('Form\/SimpleBlog');\n$ldb->create('blog', $this->blogTableColumns);\n$BlogRow = ['id'=>0, 'title'=>'Fine Title', 'body'=>'I have to be at least fifty characters. That shouldn\\'t be much of a problem, though it does require a bit more typing. And if I had something original to say, that would make it better.'];\n$ldb->insert('blog', $BlogRow);\n$UpdatedBlog = $BlogRow;\n$UpdatedBlog['title'] = 'New Title';\n$out = $view->submit($UpdatedBlog);\n$this->test('Headers');\n    $this->compare(\n        [['Location: https:\/\/localhost\/blog\/'.$UpdatedBlog['title'].'\/', true]],\n        $phad->getHeaders(),\n    );\n$this->test('Data Was Updated');\n    $this->compare(\n        [$UpdatedBlog],\n        $ldb->query('SELECT * FROM blog')\n    );\n$this->test('No Output Present');\n    $this->compare(\n        '',\n        trim($out)\n    );",
                        "declaration": "public function testUpdateValid()"
                    },
                    {
                        "type": "method",
                        "args": [],
                        "modifiers": [
                            "public"
                        ],
                        "name": "testInsertValid",
                        "body": "$phad = $this->phad();\n$phad->pdo = $this->getPdo();\n$view = $phad->view('Form\/SimpleBlog');\n$this->createTable($phad->pdo, 'blog', $this->blogTableColumns);\n$_SERVER['HTTP_HOST'] = 'localhost';\n$_SERVER['HTTPS'] = 'non-empty-value';\n$BlogRow = ['title'=>'Fine Title', 'body'=>'I have to be at least fifty characters. That shouldn\\'t be much of a problem, though it does require a bit more typing. And if I had something original to say, that would make it better.'];\n$out = $view->submit($BlogRow);\n$BlogRow['id'] = $phad->pdo->lastInsertId();\n$this->test('There should be no output');\n    $this->handleDidPass(strlen(trim($out))===0);\n$this->test('Headers');\n    $this->compare(\n        [['Location: https:\/\/localhost\/blog\/'.$BlogRow['title'].'\/', true]],\n        $phad->getHeaders(),\n    );\n$this->test('Data Was Inserted');\n    $this->compare(\n        $BlogRow,\n        $this->queryOne($phad->pdo, 'SELECT * FROM blog'),\n    );",
                        "declaration": "public function testInsertValid()"
                    },
                    {
                        "type": "method",
                        "args": [],
                        "docblock": {
                            "type": "docblock",
                            "description": "",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "test",
                                    "description": "that a partially filled in form is returned when submission fails."
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "testSubmitInvalid",
                        "body": "$phad = $this->phad();\n$phad->force_compile = false;\n$this->createTable($phad->pdo, 'blog', $this->blogTableColumns);\n\/\/ View contains:\n\/\/ <textarea name=\"body\" maxlength=\"2000\" minlength=\"50\"><\/textarea>\n$view = $phad->view('Form\/SimpleBlog');\n\/\/ should fail because body is less than 50 chars\n$Blog = ['title'=>'Fine Title', 'body'=>'body too short'];\n$out = $view->submit($Blog);\n$Blog = (object)$Blog;\necho $out;\n$this->test('Form cleaned up');\n    $this->str_not_contains($view, ['item=']);\n$this->test('Submitted Blog Content');\n    $this->str_contains($out, 'value=\"'.$Blog->title.'\"');\n    $this->str_contains($out, '>'.$Blog->body.'<\/textarea>');",
                        "declaration": "public function testSubmitInvalid()"
                    },
                    {
                        "type": "method",
                        "args": [],
                        "modifiers": [
                            "public"
                        ],
                        "name": "testDisplayWithNoObject",
                        "body": "$view = $this->view('Form\/SimpleBlog');\n$Blog = ['title'=>'Fine Title', 'body'=>'body too short'];\n$out = $view->outputWithEmptyObject($Blog);\n$Blog = (object)$Blog;\necho $out;\n$this->test('Form cleaned up');\n    $this->str_not_contains($out, ['item=']);\n$this->test('Target Attribute Removed');\n    $this->str_not_contains($out, 'target=\"');\n$this->test('Submitted Blog Content');\n    $this->str_contains($out, 'value=\"\"');\n    $this->str_contains($out, '><\/textarea>');",
                        "declaration": "public function testDisplayWithNoObject()"
                    },
                    {
                        "type": "method",
                        "args": [],
                        "docblock": {
                            "type": "docblock",
                            "description": "",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "test",
                                    "description": "getting each selectable-option from a form's compiled view"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "testHasSelectOptions",
                        "body": "$view = $this->view('Form\/BlogWithCategories');\n$ItemData = $view->getItemData();\n$expect = [\n    'title' =>\n    [\n        'type' => 'text',\n        'maxlength' => '75',\n        'tagName' => 'input',\n    ],\n    'body' =>\n    [\n        'maxlength' => '2000',\n        'minlength' => '50',\n        'tagName' => 'textarea',\n    ],\n    'category'=>\n    [\n        'tagName'=> 'select',\n        'options'=>[\n            \"social-justice\",\n            \"policy\",\n            \"Police Brutality\",\n            \"Election\",\n        ],\n    ],\n    'id'=>\n    [\n        'tagName'=>'input',\n        'type'=>'hidden',\n    ]\n];\n$this->compare($expect, $ItemData->properties);",
                        "declaration": "public function testHasSelectOptions()"
                    },
                    {
                        "type": "method",
                        "args": [],
                        "docblock": {
                            "type": "docblock",
                            "description": "",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "test",
                                    "description": "getting info about properties from the compiled view."
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "testHasPropertiesData",
                        "body": "$view = $this->view('Form\/SimpleBlog');\n$ItemData = $view->getItemData();\n$expect = [\n    'title' =>\n    [\n        'type' => 'text',\n        'maxlength' => '75',\n        'tagName' => 'input',\n    ],\n    'body' =>\n    [\n        'maxlength' => '2000',\n        'minlength' => '50',\n        'tagName' => 'textarea',\n    ],\n    'id'=>\n    [\n        'tagName'=>'input',\n        'type'=>'hidden',\n    ]\n];\n$this->compare($expect, $ItemData->properties);",
                        "declaration": "public function testHasPropertiesData()"
                    }
                ]
            }
        ]
    }
}Array
(
    [type] => file
    [namespace] => Array
        (
            [type] => namespace
            [name] => Phad\Test\Integration
            [declaration] => namespace Phad\Test\Integration;
            [class] => Array
                (
                    [0] => Array
                        (
                            [type] => class
                            [docblock] => Array
                                (
                                    [type] => docblock
                                    [description] => This class appears to test both form compilation and form submission

                                    [attribute] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [type] => attribute
                                                    [name] => notice
                                                    [description] => Several of these tests incidentally test the submit target/redirect feature.
                                                )

                                        )

                                )

                            [namespace] => Phad\Test\Integration
                            [fqn] => Phad\Test\Integration\Forms
                            [name] => Forms
                            [extends] => \Phad\Tester
                            [declaration] => class Forms extends \Phad\Tester
                            [properties] => Array
                                (
                                    [0] => Array
                                        (
                                            [type] => property
                                            [modifiers] => Array
                                                (
                                                    [0] => protected
                                                    [1] => array
                                                )

                                            [name] => blogTableColumns
                                            [value] => ['id'=>'INTEGER PRIMARY KEY','title'=>'VARCHAR(200)','body'=>'VARCHAR(2000)']
                                            [declaration] => protected array $blogTableColumns = ['id'=>'INTEGER PRIMARY KEY','title'=>'VARCHAR(200)', 'body'=>'VARCHAR(2000)'];
                                        )

                                )

                            [methods] => Array
                                (
                                    [0] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => testDeleteItem
                                            [body] => $lildb = \Tlf\LilDb::sqlite();
$pdo = $lildb->pdo();
$phad = $this->phad();
$phad->pdo = $pdo;
$lildb->create('blog',['id'=>'integer', 'title'=>'varchar(90)']);
$lildb->insert('blog',['id'=>1,'title'=>'title 1']);
$lildb->insert('blog',['id'=>2,'title'=>'title 2']);
$lildb->insert('blog',['id'=>3,'title'=>'title 3']);
$form = new \Phad\View('Form/Deleteable', $this->file('test/input/views/'),
    ['id'=>2, 'phad'=>$phad]);
$form->force_compile = true;
$form->delete();
$blogs = $lildb->select('blog');
$this->compare(
    [ ['id'=>1,'title'=>'title 1'],
      ['id'=>3,'title'=>'title 3'],
    ],
    $blogs
);
                                            [declaration] => public function testDeleteItem()
                                        )

                                    [1] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => testErrorMessage
                                            [body] => $pdo = $this->getPdo();
$phad = $this->phad();
$phad->pdo = $pdo;
$view = $phad->view('Form/SimpleBlogWithError');
$_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['HTTPS'] = 'non-empty-value';
$BlogRow = ['body'=>'smol body', 'title'=>''];
$out = $view->submit($BlogRow);
$msg = $phad->validationErrorMessage($phad->failed_submit_columns);
$this->test('Error Message Written');
    $this->str_not_contains($out, ['<error>','</error>']);
    $this->str_contains($out, '<div class="my-error-class">'.$msg.'</div>');
$this->test('Headers empty');
    $this->compare(
        [],
        $phad->getHeaders(),
    );
                                            [declaration] => public function testErrorMessage()
                                        )

                                    [2] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => testSubmitDocumentation
                                            [body] => $_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['HTTPS'] = 'non-empty-value';
$ldb = \Tlf\LilDb::sqlite();
$pdo = $ldb->pdo();
$ldb->create('blog', $this->blogTableColumns);
$phad = $this->phad();
$phad->pdo = $pdo;
$view = $phad->view('Form/SimpleBlogNoTarget');
//if `id` were set, an UPDATE would be done instead.
$BlogRow = ['title'=>'Fine Title', 'body'=>'I have to be at least 50 characters. But that isn\'t very long.'];
$out = $view->submit($BlogRow);
$BlogRow['id'] = $pdo->lastInsertId();
$headers = $phad->getHeaders();
//you can foreach(as $h){ header(...$h) }
//@export_end(Forms.ManualSubmission)
$this->test('Headers');
    $this->compare(
        [['Location: https://localhost/', true]],
        $phad->getHeaders(),
    );
$this->test('Data Was Inserted');
    $this->compare(
        [$BlogRow],
        $ldb->query('SELECT * FROM blog')
    );
                                            [declaration] => public function testSubmitDocumentation()
                                        )

                                    [3] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => testControllerOnSubmitDocumentation
                                            [body] => $phad = new class() extends \Phad {
    public function onSubmit($ItemData, &$ItemRow){
        if ($ItemData->name!='Blog')return true;
        $ItemRow['slug'] = str_replace(' ', '-', strtolower($ItemRow['title']));
        return true;
    }
};
$pdo = $this->getPdo();
$phad = $this->phad($phad);
$phad->pdo = $pdo;
$phad->target_url = '/blog/{slug}/{id}/';
$cols = $this->blogTableColumns;
$cols['slug'] = 'VARCHAR(100)';
$this->createTable($pdo, 'blog', $cols);
$_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['HTTPS'] = 'non-empty-value';
$BlogRow =
    [
    'title'=>'Fine Title',
    'body'=>'I have to be at least fifty characters. That shouldn\'t be much of a problem, though it does require a bit more typing. And if I had something original to say, that would make it better.'
    ];
/** anonymous class to use as our controller */
/** passing our custom controller & submitting manually */
$view = $phad->view('Form/SimpleBlogNoTarget');
/** $BlogRow is just an array with 'title' & 'body' **/
$output = $view->submit($BlogRow);
$BlogRow['id'] = $pdo->lastInsertId();
$BlogRow['slug'] = 'fine-title';
$this->test('There should be no output');
    $this->handleDidPass(strlen(trim($output))===0);
$this->test('Headers');
    $this->compare(
        [['Location: https://localhost/blog/fine-title/'.$BlogRow['id'].'/', true]],
        $phad->getHeaders(),
    );
$this->test('Data Was Inserted');
    $this->compare(
        $BlogRow,
        $this->queryOne($pdo, 'SELECT * FROM blog'),
    );
                                            [declaration] => public function testControllerOnSubmitDocumentation()
                                        )

                                    [4] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => testWithInlineOnSubmit
                                            [body] => $pdo = $this->getPdo();
$phad = $this->phad();
$phad->pdo = $pdo;
$phad->target_url = '/blog/{slug}/{id}/';
$cols = $this->blogTableColumns;
$cols['slug'] = 'VARCHAR(100)';
$this->createTable($pdo, 'blog', $cols);
$_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['HTTPS'] = 'non-empty-value';
$BlogRow =
    [
    'title'=>'Fine Title',
    'body'=>'I have to be at least fifty characters. That shouldn\'t be much of a problem, though it does require a bit more typing. And if I had something original to say, that would make it better.'
    ];
$view = $phad->view('Form/BlogWithOnSubmit');
$output = $view->submit($BlogRow);
$BlogRow['id'] = $pdo->lastInsertId();
$BlogRow['slug'] = 'fine-title';
$this->test('Backend Prop is removed');
    $this->str_not_contains($phad->view('Form/BlogWithOnSubmit', $BlogRow), 'type="backend"');
$this->test('<onsubmit> tag was removed');
    $this->str_not_contains($phad->view('Form/BlogWithOnSubmit', $BlogRow), '<onsubmit>');
$this->test('There should be no output');
    $this->handleDidPass(strlen(trim($output))===0);
$this->test('Headers');
    $this->compare(
        [['Location: https://localhost/blog/fine-title/'.$BlogRow['id'].'/', true]],
        $phad->getHeaders(),
    );
$this->test('Data Was Inserted');
    $this->compare(
        $BlogRow,
        $this->queryOne($pdo, 'SELECT * FROM blog'),
    );
                                            [declaration] => public function testWithInlineOnSubmit()
                                        )

                                    [5] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => testInsertWithValidOption
                                            [body] => $pdo = $this->getPdo();
$phad = $this->phad();
$phad->pdo = $pdo;
$view = $phad->view('Form/BlogWithCategories');
$cols = $this->blogTableColumns;
$cols['category'] = 'VARCHAR(100)';
$this->createTable($pdo, 'blog', $cols);
$_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['HTTPS'] = 'non-empty-value';
$BlogRow = ['title'=>'Police Brutality super sucks', 'body'=>'Its been well documented that police brutality is a reality, yet there\'s still overwhelming controversy about what we should do with our society. Some say: Let the police to what they gotta do. Others say: Lets rethink this society that\'s built upon punishing people who misbehave & actually help people instead. Mayb ewe could redirect some of the MASSIVE tax dollars that go to police departments to actually help someone. That\'s me. I say that. - Reed',
    'category'=>'Police Brutality'];
$out = $view->submit($BlogRow);
$BlogRow['id'] = $pdo->lastInsertId();
$this->test('There should be no output');
    $this->handleDidPass(strlen(trim($out))===0);
$this->test('Headers');
    $this->compare(
        [['Location: https://localhost/blog/'.$BlogRow['title'].'/', true]],
        $phad->getHeaders(),
    );
$this->test('Data Was Inserted');
    $this->compare(
        $BlogRow,
        $this->queryOne($pdo, 'SELECT * FROM blog'),
    );
                                            [declaration] => public function testInsertWithValidOption()
                                        )

                                    [6] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => testUpdateRedirectsToTarget
                                            [body] => // $phad = $this->phad();
$pdo = $this->getPdo();
// $phad->pdo = $pdo;
$this->createTable($pdo, 'blog', $this->blogTableColumns);
$_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['HTTPS'] = 'non-empty-value';
$phad = new class() extends \Phad {
    public function t(){
        echo "\ntttttttttttttttt\n";
    }
    public function objectFromRow($ItemData, $BlogRow){
        $Blog = (object)$BlogRow;
        $Blog->slug = str_replace(' ', '-', strtolower($Blog->title));
        return $Blog;
    }
};
$phad = $this->phad($phad);
$phad->target_url = '/blog/{slug}/{id}/';
$phad->pdo = $pdo;
$view = $phad->view('Form/SimpleBlogNoTarget', ['phad'=>$phad]);
$BlogRow =
    [
    'title'=>'Fine Title',
    'body'=>'I have to be at least fifty characters. That shouldn\'t be much of a problem, though it does require a bit more typing. And if I had something original to say, that would make it better.'
    ];
$out = $view->submit($BlogRow);
$BlogRow['id'] = $pdo->lastInsertId();
$this->test('There should be no output');
    $this->handleDidPass(strlen(trim($out))===0);
$this->test('Headers');
    $this->compare(
        [['Location: https://localhost/blog/fine-title/'.$BlogRow['id'].'/', true]],
        $phad->getHeaders(),
    );
$this->test('Data Was Inserted');
    $this->compare(
        $BlogRow,
        $this->queryOne($pdo, 'SELECT * FROM blog'),
    );
                                            [declaration] => public function testUpdateRedirectsToTarget()
                                        )

                                    [7] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => testUpdateValid
                                            [body] => $_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['HTTPS'] = 'non-empty-value';
$ldb = \Tlf\LilDb::sqlite();
$phad = $this->phad();
$phad->pdo = $ldb->pdo();
$view = $phad->view('Form/SimpleBlog');
$ldb->create('blog', $this->blogTableColumns);
$BlogRow = ['id'=>0, 'title'=>'Fine Title', 'body'=>'I have to be at least fifty characters. That shouldn\'t be much of a problem, though it does require a bit more typing. And if I had something original to say, that would make it better.'];
$ldb->insert('blog', $BlogRow);
$UpdatedBlog = $BlogRow;
$UpdatedBlog['title'] = 'New Title';
$out = $view->submit($UpdatedBlog);
$this->test('Headers');
    $this->compare(
        [['Location: https://localhost/blog/'.$UpdatedBlog['title'].'/', true]],
        $phad->getHeaders(),
    );
$this->test('Data Was Updated');
    $this->compare(
        [$UpdatedBlog],
        $ldb->query('SELECT * FROM blog')
    );
$this->test('No Output Present');
    $this->compare(
        '',
        trim($out)
    );
                                            [declaration] => public function testUpdateValid()
                                        )

                                    [8] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => testInsertValid
                                            [body] => $phad = $this->phad();
$phad->pdo = $this->getPdo();
$view = $phad->view('Form/SimpleBlog');
$this->createTable($phad->pdo, 'blog', $this->blogTableColumns);
$_SERVER['HTTP_HOST'] = 'localhost';
$_SERVER['HTTPS'] = 'non-empty-value';
$BlogRow = ['title'=>'Fine Title', 'body'=>'I have to be at least fifty characters. That shouldn\'t be much of a problem, though it does require a bit more typing. And if I had something original to say, that would make it better.'];
$out = $view->submit($BlogRow);
$BlogRow['id'] = $phad->pdo->lastInsertId();
$this->test('There should be no output');
    $this->handleDidPass(strlen(trim($out))===0);
$this->test('Headers');
    $this->compare(
        [['Location: https://localhost/blog/'.$BlogRow['title'].'/', true]],
        $phad->getHeaders(),
    );
$this->test('Data Was Inserted');
    $this->compare(
        $BlogRow,
        $this->queryOne($phad->pdo, 'SELECT * FROM blog'),
    );
                                            [declaration] => public function testInsertValid()
                                        )

                                    [9] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => 
                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => test
                                                                    [description] => that a partially filled in form is returned when submission fails.
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => testSubmitInvalid
                                            [body] => $phad = $this->phad();
$phad->force_compile = false;
$this->createTable($phad->pdo, 'blog', $this->blogTableColumns);
// View contains:
// <textarea name="body" maxlength="2000" minlength="50"></textarea>
$view = $phad->view('Form/SimpleBlog');
// should fail because body is less than 50 chars
$Blog = ['title'=>'Fine Title', 'body'=>'body too short'];
$out = $view->submit($Blog);
$Blog = (object)$Blog;
echo $out;
$this->test('Form cleaned up');
    $this->str_not_contains($view, ['item=']);
$this->test('Submitted Blog Content');
    $this->str_contains($out, 'value="'.$Blog->title.'"');
    $this->str_contains($out, '>'.$Blog->body.'</textarea>');
                                            [declaration] => public function testSubmitInvalid()
                                        )

                                    [10] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => testDisplayWithNoObject
                                            [body] => $view = $this->view('Form/SimpleBlog');
$Blog = ['title'=>'Fine Title', 'body'=>'body too short'];
$out = $view->outputWithEmptyObject($Blog);
$Blog = (object)$Blog;
echo $out;
$this->test('Form cleaned up');
    $this->str_not_contains($out, ['item=']);
$this->test('Target Attribute Removed');
    $this->str_not_contains($out, 'target="');
$this->test('Submitted Blog Content');
    $this->str_contains($out, 'value=""');
    $this->str_contains($out, '></textarea>');
                                            [declaration] => public function testDisplayWithNoObject()
                                        )

                                    [11] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => 
                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => test
                                                                    [description] => getting each selectable-option from a form's compiled view
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => testHasSelectOptions
                                            [body] => $view = $this->view('Form/BlogWithCategories');
$ItemData = $view->getItemData();
$expect = [
    'title' =>
    [
        'type' => 'text',
        'maxlength' => '75',
        'tagName' => 'input',
    ],
    'body' =>
    [
        'maxlength' => '2000',
        'minlength' => '50',
        'tagName' => 'textarea',
    ],
    'category'=>
    [
        'tagName'=> 'select',
        'options'=>[
            "social-justice",
            "policy",
            "Police Brutality",
            "Election",
        ],
    ],
    'id'=>
    [
        'tagName'=>'input',
        'type'=>'hidden',
    ]
];
$this->compare($expect, $ItemData->properties);
                                            [declaration] => public function testHasSelectOptions()
                                        )

                                    [12] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => 
                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => test
                                                                    [description] => getting info about properties from the compiled view.
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => testHasPropertiesData
                                            [body] => $view = $this->view('Form/SimpleBlog');
$ItemData = $view->getItemData();
$expect = [
    'title' =>
    [
        'type' => 'text',
        'maxlength' => '75',
        'tagName' => 'input',
    ],
    'body' =>
    [
        'maxlength' => '2000',
        'minlength' => '50',
        'tagName' => 'textarea',
    ],
    'id'=>
    [
        'tagName'=>'input',
        'type'=>'hidden',
    ]
];
$this->compare($expect, $ItemData->properties);
                                            [declaration] => public function testHasPropertiesData()
                                        )

                                )

                        )

                )

        )

)
{
    "type": "file",
    "namespace": {
        "type": "namespace",
        "name": "Taeluf\\PHTML",
        "declaration": "namespace Taeluf\\PHTML;",
        "class": [
            {
                "type": "class",
                "namespace": "Taeluf\\PHTML",
                "fqn": "Taeluf\\PHTML\\Compiler",
                "name": "Compiler",
                "declaration": "class Compiler",
                "properties": [
                    {
                        "type": "property",
                        "modifiers": [
                            "protected"
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "An array of code to output.\nLikely contains placeholder which will be replaced. \nMay contain objects which implement __toString"
                        },
                        "name": "code",
                        "value": "[]",
                        "declaration": "protected $code = [];"
                    },
                    {
                        "type": "property",
                        "modifiers": [
                            "protected"
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "The content of a PHP file for compilation"
                        },
                        "name": "src",
                        "declaration": "protected $src;"
                    },
                    {
                        "type": "property",
                        "modifiers": [
                            "protected"
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "An array of placeholder code with codeId => [prependedCode, code, appendedCode]... there can be any number of entries for each codeId\nCode may be string or an object which implements __toString\ncodeIds are either sha sums (alpha-numeric, i think) or randmoized alpha"
                        },
                        "name": "placeholder",
                        "value": "[]",
                        "declaration": "protected $placeholder = [];"
                    },
                    {
                        "type": "property",
                        "modifiers": [
                            "protected"
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "The parsed source code, with the PHP code replaced by placeholders"
                        },
                        "name": "htmlSource",
                        "declaration": "protected $htmlSource;"
                    }
                ],
                "methods": [
                    {
                        "type": "method",
                        "args": [],
                        "modifiers": [
                            "public"
                        ],
                        "name": "__construct",
                        "body": "",
                        "declaration": "public function __construct()"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "srcCode",
                                "declaration": "$srcCode"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Replaces inline PHP code with placeholder, indexes the placeholder, and returns the modified code\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "mixed $srcCode - The source code"
                                },
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "string - source code with all PHP replaced by codeIds"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "cleanSource",
                        "return_types": [
                            "string"
                        ],
                        "body": "$parser = new PHPParser($srcCode);\n$parsed = $parser->pieces();\nforeach ($parsed->php as $id=>$code){\n    $this->placeholder[$id] = [$code];\n}\nreturn $parsed->html;",
                        "declaration": "public function cleanSource($srcCode): string"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "phpCodeWithOpenCloseTags",
                                "declaration": "$phpCodeWithOpenCloseTags"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "1. Generates an id\n2. indexes the passed-in-code with that id\n3. Returns the id.\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "mixed $phpCodeWithOpenCloseTags - Code, as it would be found in a PHP file. AKA PHP code MUST include open\/close tags"
                                },
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "string the codeId. Either a random alpha-string OR an sha_sum, which I think is alpha-numeric"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "placeholderFor",
                        "return_types": [
                            "string"
                        ],
                        "body": "$code = $phpCodeWithOpenCloseTags;\n$id = $this->freshId();\n$this->placeholder[$id] = [$code];\nreturn $id;",
                        "declaration": "public function placeholderFor($phpCodeWithOpenCloseTags): string"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "code",
                                "declaration": "$code"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Appends code to the output-to-be\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "mixed $code - Code to append. PHP code must be wrapped in open\/close tags"
                                },
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "void"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "appendCode",
                        "body": "$this->code[] = $code;",
                        "declaration": "public function appendCode($code)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "code",
                                "declaration": "$code"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Prepends code to the output-to-be\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "mixed $code - Code to prepend. PHP code must be wrapped in open\/close tags"
                                },
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "void"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "prependCode",
                        "body": "\/\/ $this->code[] = $code;\narray_unshift($this->code,$code);",
                        "declaration": "public function prependCode($code)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "placeholder",
                                "declaration": "$placeholder"
                            },
                            {
                                "type": "arg",
                                "name": "code",
                                "declaration": "$code"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Prepend code immediately prior to the given placeholder\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "mixed $placeholder - a placeholder from placeholderFor()"
                                },
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "mixed $code - a block of code. PHP must be wrapped in open\/close tags"
                                },
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "void"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "placeholderPrepend",
                        "body": "array_unshift($this->placeholder[$placeholder],$code);",
                        "declaration": "public function placeholderPrepend($placeholder,$code)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "placeholder",
                                "declaration": "$placeholder"
                            },
                            {
                                "type": "arg",
                                "name": "code",
                                "declaration": "$code"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Append code immediately after the given placeholder\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "mixed $placeholder - a placeholder from placeholderFor()"
                                },
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "mixed $code - a block of code. PHP must be wrapped in open\/close tags"
                                },
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "void"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "placeholderAppend",
                        "body": "$this->placeholder[$placeholder][] = $code;",
                        "declaration": "public function placeholderAppend($placeholder,$code)"
                    },
                    {
                        "type": "method",
                        "args": [],
                        "docblock": {
                            "type": "docblock",
                            "description": "Compile the code into a string & return it. \noutput() can be called several times as it does NOT affect the state of the compiler.\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "string"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "output",
                        "return_types": [
                            "string"
                        ],
                        "body": "\/\/ print_r($this->code);\n\/\/ \/\/ echo $this->code[0]->;\n\/\/ exit;\n\/\/ print_r($this->placeholder);\n$code = implode(\"\\n\",$this->code);\n\/\/ return $code;\n$ph = [];\nforeach ($this->placeholder as $id=>$codeArray){\n    $ph[$id] = implode('',$codeArray);\n}\n$last = $code;\nwhile($last != $code = str_replace(array_keys($ph),$ph,$code))$last=$code;\nreturn $code;",
                        "declaration": "public function output(): string"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "file",
                                "declaration": "string $file"
                            },
                            {
                                "type": "arg",
                                "name": "chmodTo",
                                "value": "null",
                                "declaration": "$chmodTo=null"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Writes the compiled output to the given file\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "string $file - an absolute filepath"
                                },
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "$chmodTo - REMOVED DOES NOTHING\n\n         0644 or whatever. If null, chmod will not be run.\n         See https:\/\/www.php.net\/manual\/en\/function.chmod.php\n         Permissions are as follows:\n             Value    Permission Level\n              200        Owner Write\n              400        Owner Read\n              100        Owner Execute\n               40         Group Read\n               20         Group Write\n               10         Group Execute\n                4         Global Read\n                2         Global Write\n                1         Global Execute"
                                },
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "boolean true if file_put_contents succeeds. False otherwise."
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "writeTo",
                        "return_types": [
                            "bool"
                        ],
                        "body": "$output = $this->output();\nif (!is_dir(dirname($file))){\n    mkdir(dirname($file),0771,true);\n    \/\/ chmod(dirname($file),0770);\n}\n$didPut = file_put_contents($file,$output);\nif ($chmodTo!==null){\n    \/\/ chmod($file,$chmodTo);\n}\nif ($didPut===false)return false;\nelse return true;",
                        "declaration": "public function writeTo(string $file, $chmodTo=null): bool"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "compileDir",
                                "declaration": "$compileDir"
                            },
                            {
                                "type": "arg",
                                "name": "code",
                                "declaration": "$code"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Get an absolute file path which can be included to execute the given code\n\n1. $codeId = sha1($code)\n2. file_put_contents(\"$compileDir\/$codeId.php\", $code)\n3. return the path of the new file\n\n- Will create the directory (non-recursive) if not exists\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "mixed $compileDir - the directory in which the file should be written"
                                },
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "mixed $code - the block of code. PHP code must be wrapped in open\/close tags to be executed"
                                },
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "string an absolute file path to a php file"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "fileForCode",
                        "return_types": [
                            "string"
                        ],
                        "body": "\/\/ $codeId = $this->freshId(30);\n$codeId = sha1($code);\n$file = $compileDir.'\/'.$codeId.'.php';\nif (!file_exists($compileDir))mkdir($compileDir,0770,true);\nfile_put_contents($file,$code);\nreturn $file;",
                        "declaration": "public function fileForCode($compileDir,$code): string"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "length",
                                "value": "26",
                                "declaration": "$length = 26"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Generate a random string of lowercase letters\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "mixed $length The desired length of the random string. Default is 26 to avoid any clashing"
                                },
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "string the random string"
                                }
                            ]
                        },
                        "modifiers": [
                            "protected"
                        ],
                        "name": "freshId",
                        "return_types": [
                            "string"
                        ],
                        "body": "$characters = 'abcdefghijklmnopqrstuvwxyz';\n$charactersLength = strlen($characters);\n$randomString = '';\nfor ($i = 0; $i < $length; $i++) {\n    $randomString .= $characters[rand(0, $charactersLength - 1)];\n}\nreturn $randomString;",
                        "declaration": "protected function freshId($length = 26): string"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "codeId",
                                "declaration": "string $codeId"
                            },
                            {
                                "type": "arg",
                                "arg_types": [
                                    "bool"
                                ],
                                "name": "asArray",
                                "value": "false",
                                "declaration": "bool $asArray=false"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Get the code for the given code id.\n\nPlaceholder code is stored as an array to enable the placeholderPrepend|Append functions, so I make it available as an array if you want.\n\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "string $codeId - the id generated by placeholderFor()"
                                },
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "bool $asArray - TRUE to get the code as it's array parts. FALSE to implode the array (no newlines) & return that"
                                },
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "mixed an array of code pieces that make up this codeid or a string of the code"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "codeForId",
                        "body": "$codeArr = $this->placeholder[$codeId];\nif ($asArray)return $codeArr;\nelse return implode('',$codeArr);",
                        "declaration": "public function codeForId(string $codeId,bool $asArray=false)"
                    }
                ]
            }
        ]
    }
}Array
(
    [type] => file
    [namespace] => Array
        (
            [type] => namespace
            [name] => Taeluf\PHTML
            [declaration] => namespace Taeluf\PHTML;
            [class] => Array
                (
                    [0] => Array
                        (
                            [type] => class
                            [namespace] => Taeluf\PHTML
                            [fqn] => Taeluf\PHTML\Compiler
                            [name] => Compiler
                            [declaration] => class Compiler
                            [properties] => Array
                                (
                                    [0] => Array
                                        (
                                            [type] => property
                                            [modifiers] => Array
                                                (
                                                    [0] => protected
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => An array of code to output.
Likely contains placeholder which will be replaced. 
May contain objects which implement __toString
                                                )

                                            [name] => code
                                            [value] => []
                                            [declaration] => protected $code = [];
                                        )

                                    [1] => Array
                                        (
                                            [type] => property
                                            [modifiers] => Array
                                                (
                                                    [0] => protected
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => The content of a PHP file for compilation
                                                )

                                            [name] => src
                                            [declaration] => protected $src;
                                        )

                                    [2] => Array
                                        (
                                            [type] => property
                                            [modifiers] => Array
                                                (
                                                    [0] => protected
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => An array of placeholder code with codeId => [prependedCode, code, appendedCode]... there can be any number of entries for each codeId
Code may be string or an object which implements __toString
codeIds are either sha sums (alpha-numeric, i think) or randmoized alpha
                                                )

                                            [name] => placeholder
                                            [value] => []
                                            [declaration] => protected $placeholder = [];
                                        )

                                    [3] => Array
                                        (
                                            [type] => property
                                            [modifiers] => Array
                                                (
                                                    [0] => protected
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => The parsed source code, with the PHP code replaced by placeholders
                                                )

                                            [name] => htmlSource
                                            [declaration] => protected $htmlSource;
                                        )

                                )

                            [methods] => Array
                                (
                                    [0] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => __construct
                                            [body] => 
                                            [declaration] => public function __construct()
                                        )

                                    [1] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => srcCode
                                                            [declaration] => $srcCode
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Replaces inline PHP code with placeholder, indexes the placeholder, and returns the modified code

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => mixed $srcCode - The source code
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => string - source code with all PHP replaced by codeIds
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => cleanSource
                                            [return_types] => Array
                                                (
                                                    [0] => string
                                                )

                                            [body] => $parser = new PHPParser($srcCode);
$parsed = $parser->pieces();
foreach ($parsed->php as $id=>$code){
    $this->placeholder[$id] = [$code];
}
return $parsed->html;
                                            [declaration] => public function cleanSource($srcCode): string
                                        )

                                    [2] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => phpCodeWithOpenCloseTags
                                                            [declaration] => $phpCodeWithOpenCloseTags
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => 1. Generates an id
2. indexes the passed-in-code with that id
3. Returns the id.

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => mixed $phpCodeWithOpenCloseTags - Code, as it would be found in a PHP file. AKA PHP code MUST include open/close tags
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => string the codeId. Either a random alpha-string OR an sha_sum, which I think is alpha-numeric
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => placeholderFor
                                            [return_types] => Array
                                                (
                                                    [0] => string
                                                )

                                            [body] => $code = $phpCodeWithOpenCloseTags;
$id = $this->freshId();
$this->placeholder[$id] = [$code];
return $id;
                                            [declaration] => public function placeholderFor($phpCodeWithOpenCloseTags): string
                                        )

                                    [3] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => code
                                                            [declaration] => $code
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Appends code to the output-to-be

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => mixed $code - Code to append. PHP code must be wrapped in open/close tags
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => void
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => appendCode
                                            [body] => $this->code[] = $code;
                                            [declaration] => public function appendCode($code)
                                        )

                                    [4] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => code
                                                            [declaration] => $code
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Prepends code to the output-to-be

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => mixed $code - Code to prepend. PHP code must be wrapped in open/close tags
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => void
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => prependCode
                                            [body] => // $this->code[] = $code;
array_unshift($this->code,$code);
                                            [declaration] => public function prependCode($code)
                                        )

                                    [5] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => placeholder
                                                            [declaration] => $placeholder
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => code
                                                            [declaration] => $code
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Prepend code immediately prior to the given placeholder

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => mixed $placeholder - a placeholder from placeholderFor()
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => mixed $code - a block of code. PHP must be wrapped in open/close tags
                                                                )

                                                            [2] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => void
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => placeholderPrepend
                                            [body] => array_unshift($this->placeholder[$placeholder],$code);
                                            [declaration] => public function placeholderPrepend($placeholder,$code)
                                        )

                                    [6] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => placeholder
                                                            [declaration] => $placeholder
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => code
                                                            [declaration] => $code
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Append code immediately after the given placeholder

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => mixed $placeholder - a placeholder from placeholderFor()
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => mixed $code - a block of code. PHP must be wrapped in open/close tags
                                                                )

                                                            [2] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => void
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => placeholderAppend
                                            [body] => $this->placeholder[$placeholder][] = $code;
                                            [declaration] => public function placeholderAppend($placeholder,$code)
                                        )

                                    [7] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Compile the code into a string & return it. 
output() can be called several times as it does NOT affect the state of the compiler.

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => string
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => output
                                            [return_types] => Array
                                                (
                                                    [0] => string
                                                )

                                            [body] => // print_r($this->code);
// // echo $this->code[0]->;
// exit;
// print_r($this->placeholder);
$code = implode("\n",$this->code);
// return $code;
$ph = [];
foreach ($this->placeholder as $id=>$codeArray){
    $ph[$id] = implode('',$codeArray);
}
$last = $code;
while($last != $code = str_replace(array_keys($ph),$ph,$code))$last=$code;
return $code;
                                            [declaration] => public function output(): string
                                        )

                                    [8] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => file
                                                            [declaration] => string $file
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => chmodTo
                                                            [value] => null
                                                            [declaration] => $chmodTo=null
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Writes the compiled output to the given file

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => string $file - an absolute filepath
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => $chmodTo - REMOVED DOES NOTHING

         0644 or whatever. If null, chmod will not be run.
         See https://www.php.net/manual/en/function.chmod.php
         Permissions are as follows:
             Value    Permission Level
              200        Owner Write
              400        Owner Read
              100        Owner Execute
               40         Group Read
               20         Group Write
               10         Group Execute
                4         Global Read
                2         Global Write
                1         Global Execute
                                                                )

                                                            [2] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => boolean true if file_put_contents succeeds. False otherwise.
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => writeTo
                                            [return_types] => Array
                                                (
                                                    [0] => bool
                                                )

                                            [body] => $output = $this->output();
if (!is_dir(dirname($file))){
    mkdir(dirname($file),0771,true);
    // chmod(dirname($file),0770);
}
$didPut = file_put_contents($file,$output);
if ($chmodTo!==null){
    // chmod($file,$chmodTo);
}
if ($didPut===false)return false;
else return true;
                                            [declaration] => public function writeTo(string $file, $chmodTo=null): bool
                                        )

                                    [9] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => compileDir
                                                            [declaration] => $compileDir
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => code
                                                            [declaration] => $code
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Get an absolute file path which can be included to execute the given code

1. $codeId = sha1($code)
2. file_put_contents("$compileDir/$codeId.php", $code)
3. return the path of the new file

- Will create the directory (non-recursive) if not exists

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => mixed $compileDir - the directory in which the file should be written
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => mixed $code - the block of code. PHP code must be wrapped in open/close tags to be executed
                                                                )

                                                            [2] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => string an absolute file path to a php file
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => fileForCode
                                            [return_types] => Array
                                                (
                                                    [0] => string
                                                )

                                            [body] => // $codeId = $this->freshId(30);
$codeId = sha1($code);
$file = $compileDir.'/'.$codeId.'.php';
if (!file_exists($compileDir))mkdir($compileDir,0770,true);
file_put_contents($file,$code);
return $file;
                                            [declaration] => public function fileForCode($compileDir,$code): string
                                        )

                                    [10] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => length
                                                            [value] => 26
                                                            [declaration] => $length = 26
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Generate a random string of lowercase letters

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => mixed $length The desired length of the random string. Default is 26 to avoid any clashing
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => string the random string
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => protected
                                                )

                                            [name] => freshId
                                            [return_types] => Array
                                                (
                                                    [0] => string
                                                )

                                            [body] => $characters = 'abcdefghijklmnopqrstuvwxyz';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
    $randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
                                            [declaration] => protected function freshId($length = 26): string
                                        )

                                    [11] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => codeId
                                                            [declaration] => string $codeId
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => bool
                                                                )

                                                            [name] => asArray
                                                            [value] => false
                                                            [declaration] => bool $asArray=false
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Get the code for the given code id.

Placeholder code is stored as an array to enable the placeholderPrepend|Append functions, so I make it available as an array if you want.


                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => string $codeId - the id generated by placeholderFor()
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => bool $asArray - TRUE to get the code as it's array parts. FALSE to implode the array (no newlines) & return that
                                                                )

                                                            [2] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => mixed an array of code pieces that make up this codeid or a string of the code
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => codeForId
                                            [body] => $codeArr = $this->placeholder[$codeId];
if ($asArray)return $codeArr;
else return implode('',$codeArr);
                                            [declaration] => public function codeForId(string $codeId,bool $asArray=false)
                                        )

                                )

                        )

                )

        )

)
{
    "type": "file",
    "namespace": {
        "type": "namespace",
        "name": "Taeluf\\PHTML",
        "declaration": "namespace Taeluf\\PHTML;",
        "class": [
            {
                "type": "class",
                "docblock": {
                    "type": "docblock",
                    "description": "less sucky HTML DOM Element\n\nThis class extends PHP's DOMElement to make it suck less\n\nThe original version of this file was a pre-made script by the author below.\nThe only meaningful pieces of code I kept are the two `if 'innerHTML'` blocks of code.\nNo license information was available in the copied code and I don't remember what it said on the author's website.\n\nThe original package had the following notes from the author:\n\n- Authored by: Keyvan Minoukadeh - http:\/\/www.keyvan.net - keyvan@keyvan.net\n  - See: http:\/\/fivefilters.org (the project this was written for)"
                },
                "namespace": "Taeluf\\PHTML",
                "fqn": "Taeluf\\PHTML\\Node",
                "name": "Node",
                "extends": "\\DOMElement",
                "declaration": "class Node extends \\DOMElement",
                "comments": [
                    "public $hideOwnTag = false;",
                    "protected $children = [];",
                    ""
                ],
                "methods": [
                    {
                        "type": "method",
                        "args": [],
                        "modifiers": [
                            "public"
                        ],
                        "name": "__construct",
                        "body": "parent::__construct();\n\/\/ $children = [];\n      \/\/ foreach ($this->childNodes as $childNode){\n          \/\/ $children[] = $childNode;\n      \/\/ }\n      \/\/ $this->children = $children;",
                        "declaration": "public function __construct()"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "tagName",
                                "declaration": "string $tagName"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "is this node the given tag"
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "is",
                        "return_types": [
                            "bool"
                        ],
                        "body": "if (strtolower($this->tagName)==strtolower($tagName))return true;\nreturn false;",
                        "declaration": "public function is(string $tagName): bool"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "attribute",
                                "declaration": "string $attribute"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "alias",
                                    "description": "for DOMDocument::hasAttribute();"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "has",
                        "return_types": [
                            "bool"
                        ],
                        "body": "return $this->hasAttribute($attribute);",
                        "declaration": "public function has(string $attribute): bool"
                    },
                    {
                        "type": "method",
                        "args": [],
                        "docblock": {
                            "type": "docblock",
                            "description": "get an array of DOMAttrs on this node"
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "attributes",
                        "body": "$attrs = $this->attributes;\n$list = [];\nforeach ($attrs as $attr){\n\t$list[] = $attr;\n}\nreturn $list;",
                        "declaration": "public function attributes()"
                    },
                    {
                        "type": "method",
                        "args": [],
                        "docblock": {
                            "type": "docblock",
                            "description": "return an array of attributes ['attributeName'=>'value', ...];"
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "attributesAsArray",
                        "body": "$list = [];\nforeach ($this->attributes as $attr){\n    $list[$attr->name] = $attr->value;\n}\nreturn $list;",
                        "declaration": "public function attributesAsArray()"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "name",
                                "declaration": "$name"
                            },
                            {
                                "type": "arg",
                                "name": "value",
                                "declaration": "$value"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Used for setting innerHTML like it's done in JavaScript:\n@code\n$div->innerHTML = '<h2>Chapter 2<\/h2><p>The story begins...<\/p>';\n@endcode"
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "__set",
                        "body": "if (strtolower($name) == 'innerhtml') {\n\t\/\/ first, empty the element\n\tfor ($x=$this->childNodes->length-1; $x>=0; $x--) {\n\t\t$this->removeChild($this->childNodes->item($x));\n\t}\n\t\/\/ $value holds our new inner HTML\n\tif ($value != '') {\n\t\t$f = $this->ownerDocument->createDocumentFragment();\n\t\t\/\/ appendXML() expects well-formed markup (XHTML)\n\t\t$result = @$f->appendXML($value); \/\/ @ to suppress PHP warnings\n\t\tif ($result) {\n\t\t\tif ($f->hasChildNodes()) $this->appendChild($f);\n\t\t} else {\n\t\t\t\/\/ $value is probably ill-formed\n\t\t\t$f = new DOMDocument();\n\t\t\t$value = mb_convert_encoding($value, 'HTML-ENTITIES', 'UTF-8');\n\t\t\t\/\/ Using <htmlfragment> will generate a warning, but so will bad HTML\n\t\t\t\/\/ (and by this point, bad HTML is what we've got).\n\t\t\t\/\/ We use it (and suppress the warning) because an HTML fragment will\n\t\t\t\/\/ be wrapped around <html><body> tags which we don't really want to keep.\n\t\t\t\/\/ Note: despite the warning, if loadHTML succeeds it will return true.\n\t\t\t$result = @$f->loadHTML('<htmlfragment>'.$value.'<\/htmlfragment>');\n\t\t\tif ($result) {\n\t\t\t\t$import = $f->getElementsByTagName('htmlfragment')->item(0);\n\t\t\t\tforeach ($import->childNodes as $child) {\n\t\t\t\t\t$importedNode = $this->ownerDocument->importNode($child, true);\n\t\t\t\t\t$this->appendChild($importedNode);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t\/\/ oh well, we tried, we really did. :(\n\t\t\t\t\/\/ this element is now empty\n\t\t\t}\n\t\t}\n\t}\n} else {\n\t$this->setAttribute($name,$value);\n\treturn;\n\t$trace = debug_backtrace();\n\ttrigger_error('Undefined property via __set(): '.$name.' in '.$trace[0]['file'].' on line '.$trace[0]['line'], E_USER_NOTICE);\n}",
                        "declaration": "public function __set($name, $value)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "name",
                                "declaration": "$name"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "if the node has the named attribute, it will be removed. Otherwise, nothing happens"
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "__unset",
                        "body": "if ($this->hasAttribute($name))$this->removeAttribute($name);",
                        "declaration": "public function __unset($name)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "name",
                                "declaration": "$name"
                            }
                        ],
                        "modifiers": [
                            "public"
                        ],
                        "name": "__isset",
                        "body": "return $this->hasAttribute($name);",
                        "declaration": "public function __isset($name)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "name",
                                "declaration": "$name"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Used for getting innerHTML like it's done in JavaScript:\n@code\n$string = $div->innerHTML;\n@endcode"
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "__get",
                        "body": "      if (method_exists($this, $getter = 'get'.strtoupper($name))){\n          return $this->$getter();\n      } else if ($name=='doc'){\n          return $this->ownerDocument;\n      } else if (strtolower($name) == 'innerhtml') {\n              $inner = '';\n              foreach ($this->childNodes as $child) {\n                  $inner .= $this->ownerDocument->saveXML($child);\n              }\n              return $inner;\n          } else if ($name=='form'&&strtolower($this->tagName)=='input'){\n          $parent = $this->parentNode ?? null;\n          while ($parent!=null&&strtolower($parent->tagName)!='form')$parent = $parent->parentNode ?? null;\n          return $parent;\n      } else if ($name=='inputs' && strtolower($this->tagName)=='form'){\n          $inputList = $this->doc->xpath('\/\/input', $this);\n          \/\/ var_dump($inputList);\n          \/\/ exit;\n          return $inputList;\n      } else if ($name=='children'){\n          $children = [];\n          for ($i=0;$i<$this->childNodes->count();$i++){\n              $children[] = $this->childNodes->item($i);\n          }\n          return $children;\n      }\n      else if ($this->hasAttribute($name)){\n          return $this->getAttribute($name);\n      } else {\n          return null;\n      }\n\/\/ $trace = debug_backtrace();\n\/\/ trigger_error('Undefined property via __get(): '.$name.' in '.$trace[0]['file'].' on line '.$trace[0]['line'], E_USER_NOTICE);\n\/\/ return null;",
                        "declaration": "public function __get($name)"
                    },
                    {
                        "type": "method",
                        "args": [],
                        "modifiers": [
                            "public"
                        ],
                        "name": "__toString",
                        "body": "return $this->ownerDocument->saveHTML($this);\n\/\/ return '['.$this->tagName.']';",
                        "declaration": "public function __toString()"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "xpath",
                                "declaration": "$xpath"
                            }
                        ],
                        "modifiers": [
                            "public"
                        ],
                        "name": "xpath",
                        "body": "return $this->doc->xpath($xpath, $this);",
                        "declaration": "public function xpath($xpath)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "inputName",
                                "declaration": "$inputName"
                            },
                            {
                                "type": "arg",
                                "name": "value",
                                "declaration": "$value"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Adds a hidden input to a form node\nIf a hidden input already exists with that name, do nothing\nIf a hidden input does not exist with that name, create and append it\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "mixed $key"
                                },
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "mixed $value"
                                },
                                {
                                    "type": "attribute",
                                    "name": "throws",
                                    "description": "\\BadMethodCallException if this method is called on a non-form node"
                                },
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "void"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "addHiddenInput",
                        "body": "if (strtolower($this->tagName)!='form')throw new \\BadMethodCallException(\"addHiddenInput can only be called on a Form node\");\n      $xPath = new \\DOMXpath($this->ownerDocument);\n      $inputs = $xPath->query('\/\/input[@name=\"'.$inputName.'\"][@type=\"hidden\"]');\n      if (count($inputs)>0)return;\n$input = $this->ownerDocument->createElement('input');\n$input->setAttribute('name',$inputName);\n$input->setAttribute('value',$value);\n$input->setAttribute('type','hidden');\n$this->appendChild($input);",
                        "declaration": "public function addHiddenInput($inputName, $value)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "attributeName",
                                "declaration": "$attributeName"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Find out if this node has a true value for the given attribute name.\nLiterally just returns $this->hasAttribute($attributeName)\n\nI wanted to implement an attribute=\"false\" option... but that goes against the standards of HTML5, so that idea is on hold.\n\nSee https:\/\/stackoverflow.com\/questions\/4139786\/what-does-it-mean-in-html-5-when-an-attribute-is-a-boolean-attribute \n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "mixed $attributeName The name of the attribute we're checking for."
                                },
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "bool"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "boolAttribute",
                        "body": "return $this->hasAttribute($attributeName);",
                        "declaration": "public function boolAttribute($attributeName)"
                    },
                    {
                        "type": "method",
                        "args": [],
                        "modifiers": [
                            "public"
                        ],
                        "name": "getInnerText",
                        "body": "return $this->textContent;",
                        "declaration": "public function getInnerText()"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "method",
                                "declaration": "$method"
                            },
                            {
                                "type": "arg",
                                "name": "args",
                                "declaration": "$args"
                            }
                        ],
                        "modifiers": [
                            "public"
                        ],
                        "name": "__call",
                        "body": "if (substr($method,0,2)=='is'){\n    $prop = lcfirst(substr($method,2));\n    if ($this->has($prop)&&$this->$prop != 'false')return true;\n    return false;\n}\nthrow new \\BadMethodCallException(\"Method '$method' does not exist on \".get_class($this));",
                        "declaration": "public function __call($method, $args)"
                    }
                ]
            }
        ]
    }
}Array
(
    [type] => file
    [namespace] => Array
        (
            [type] => namespace
            [name] => Taeluf\PHTML
            [declaration] => namespace Taeluf\PHTML;
            [class] => Array
                (
                    [0] => Array
                        (
                            [type] => class
                            [docblock] => Array
                                (
                                    [type] => docblock
                                    [description] => less sucky HTML DOM Element

This class extends PHP's DOMElement to make it suck less

The original version of this file was a pre-made script by the author below.
The only meaningful pieces of code I kept are the two `if 'innerHTML'` blocks of code.
No license information was available in the copied code and I don't remember what it said on the author's website.

The original package had the following notes from the author:

- Authored by: Keyvan Minoukadeh - http://www.keyvan.net - keyvan@keyvan.net
  - See: http://fivefilters.org (the project this was written for)
                                )

                            [namespace] => Taeluf\PHTML
                            [fqn] => Taeluf\PHTML\Node
                            [name] => Node
                            [extends] => \DOMElement
                            [declaration] => class Node extends \DOMElement
                            [comments] => Array
                                (
                                    [0] => public $hideOwnTag = false;
                                    [1] => protected $children = [];
                                    [2] => 
                                )

                            [methods] => Array
                                (
                                    [0] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => __construct
                                            [body] => parent::__construct();
// $children = [];
      // foreach ($this->childNodes as $childNode){
          // $children[] = $childNode;
      // }
      // $this->children = $children;
                                            [declaration] => public function __construct()
                                        )

                                    [1] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => tagName
                                                            [declaration] => string $tagName
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => is this node the given tag
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => is
                                            [return_types] => Array
                                                (
                                                    [0] => bool
                                                )

                                            [body] => if (strtolower($this->tagName)==strtolower($tagName))return true;
return false;
                                            [declaration] => public function is(string $tagName): bool
                                        )

                                    [2] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => attribute
                                                            [declaration] => string $attribute
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => 
                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => alias
                                                                    [description] => for DOMDocument::hasAttribute();
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => has
                                            [return_types] => Array
                                                (
                                                    [0] => bool
                                                )

                                            [body] => return $this->hasAttribute($attribute);
                                            [declaration] => public function has(string $attribute): bool
                                        )

                                    [3] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => get an array of DOMAttrs on this node
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => attributes
                                            [body] => $attrs = $this->attributes;
$list = [];
foreach ($attrs as $attr){
	$list[] = $attr;
}
return $list;
                                            [declaration] => public function attributes()
                                        )

                                    [4] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => return an array of attributes ['attributeName'=>'value', ...];
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => attributesAsArray
                                            [body] => $list = [];
foreach ($this->attributes as $attr){
    $list[$attr->name] = $attr->value;
}
return $list;
                                            [declaration] => public function attributesAsArray()
                                        )

                                    [5] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => name
                                                            [declaration] => $name
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => value
                                                            [declaration] => $value
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Used for setting innerHTML like it's done in JavaScript:
@code
$div->innerHTML = '<h2>Chapter 2</h2><p>The story begins...</p>';
@endcode
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => __set
                                            [body] => if (strtolower($name) == 'innerhtml') {
	// first, empty the element
	for ($x=$this->childNodes->length-1; $x>=0; $x--) {
		$this->removeChild($this->childNodes->item($x));
	}
	// $value holds our new inner HTML
	if ($value != '') {
		$f = $this->ownerDocument->createDocumentFragment();
		// appendXML() expects well-formed markup (XHTML)
		$result = @$f->appendXML($value); // @ to suppress PHP warnings
		if ($result) {
			if ($f->hasChildNodes()) $this->appendChild($f);
		} else {
			// $value is probably ill-formed
			$f = new DOMDocument();
			$value = mb_convert_encoding($value, 'HTML-ENTITIES', 'UTF-8');
			// Using <htmlfragment> will generate a warning, but so will bad HTML
			// (and by this point, bad HTML is what we've got).
			// We use it (and suppress the warning) because an HTML fragment will
			// be wrapped around <html><body> tags which we don't really want to keep.
			// Note: despite the warning, if loadHTML succeeds it will return true.
			$result = @$f->loadHTML('<htmlfragment>'.$value.'</htmlfragment>');
			if ($result) {
				$import = $f->getElementsByTagName('htmlfragment')->item(0);
				foreach ($import->childNodes as $child) {
					$importedNode = $this->ownerDocument->importNode($child, true);
					$this->appendChild($importedNode);
				}
			} else {
				// oh well, we tried, we really did. :(
				// this element is now empty
			}
		}
	}
} else {
	$this->setAttribute($name,$value);
	return;
	$trace = debug_backtrace();
	trigger_error('Undefined property via __set(): '.$name.' in '.$trace[0]['file'].' on line '.$trace[0]['line'], E_USER_NOTICE);
}
                                            [declaration] => public function __set($name, $value)
                                        )

                                    [6] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => name
                                                            [declaration] => $name
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => if the node has the named attribute, it will be removed. Otherwise, nothing happens
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => __unset
                                            [body] => if ($this->hasAttribute($name))$this->removeAttribute($name);
                                            [declaration] => public function __unset($name)
                                        )

                                    [7] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => name
                                                            [declaration] => $name
                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => __isset
                                            [body] => return $this->hasAttribute($name);
                                            [declaration] => public function __isset($name)
                                        )

                                    [8] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => name
                                                            [declaration] => $name
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Used for getting innerHTML like it's done in JavaScript:
@code
$string = $div->innerHTML;
@endcode
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => __get
                                            [body] =>       if (method_exists($this, $getter = 'get'.strtoupper($name))){
          return $this->$getter();
      } else if ($name=='doc'){
          return $this->ownerDocument;
      } else if (strtolower($name) == 'innerhtml') {
              $inner = '';
              foreach ($this->childNodes as $child) {
                  $inner .= $this->ownerDocument->saveXML($child);
              }
              return $inner;
          } else if ($name=='form'&&strtolower($this->tagName)=='input'){
          $parent = $this->parentNode ?? null;
          while ($parent!=null&&strtolower($parent->tagName)!='form')$parent = $parent->parentNode ?? null;
          return $parent;
      } else if ($name=='inputs' && strtolower($this->tagName)=='form'){
          $inputList = $this->doc->xpath('//input', $this);
          // var_dump($inputList);
          // exit;
          return $inputList;
      } else if ($name=='children'){
          $children = [];
          for ($i=0;$i<$this->childNodes->count();$i++){
              $children[] = $this->childNodes->item($i);
          }
          return $children;
      }
      else if ($this->hasAttribute($name)){
          return $this->getAttribute($name);
      } else {
          return null;
      }
// $trace = debug_backtrace();
// trigger_error('Undefined property via __get(): '.$name.' in '.$trace[0]['file'].' on line '.$trace[0]['line'], E_USER_NOTICE);
// return null;
                                            [declaration] => public function __get($name)
                                        )

                                    [9] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => __toString
                                            [body] => return $this->ownerDocument->saveHTML($this);
// return '['.$this->tagName.']';
                                            [declaration] => public function __toString()
                                        )

                                    [10] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => xpath
                                                            [declaration] => $xpath
                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => xpath
                                            [body] => return $this->doc->xpath($xpath, $this);
                                            [declaration] => public function xpath($xpath)
                                        )

                                    [11] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => inputName
                                                            [declaration] => $inputName
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => value
                                                            [declaration] => $value
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Adds a hidden input to a form node
If a hidden input already exists with that name, do nothing
If a hidden input does not exist with that name, create and append it

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => mixed $key
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => mixed $value
                                                                )

                                                            [2] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => throws
                                                                    [description] => \BadMethodCallException if this method is called on a non-form node
                                                                )

                                                            [3] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => void
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => addHiddenInput
                                            [body] => if (strtolower($this->tagName)!='form')throw new \BadMethodCallException("addHiddenInput can only be called on a Form node");
      $xPath = new \DOMXpath($this->ownerDocument);
      $inputs = $xPath->query('//input[@name="'.$inputName.'"][@type="hidden"]');
      if (count($inputs)>0)return;
$input = $this->ownerDocument->createElement('input');
$input->setAttribute('name',$inputName);
$input->setAttribute('value',$value);
$input->setAttribute('type','hidden');
$this->appendChild($input);
                                            [declaration] => public function addHiddenInput($inputName, $value)
                                        )

                                    [12] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => attributeName
                                                            [declaration] => $attributeName
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Find out if this node has a true value for the given attribute name.
Literally just returns $this->hasAttribute($attributeName)

I wanted to implement an attribute="false" option... but that goes against the standards of HTML5, so that idea is on hold.

See https://stackoverflow.com/questions/4139786/what-does-it-mean-in-html-5-when-an-attribute-is-a-boolean-attribute 

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => mixed $attributeName The name of the attribute we're checking for.
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => bool
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => boolAttribute
                                            [body] => return $this->hasAttribute($attributeName);
                                            [declaration] => public function boolAttribute($attributeName)
                                        )

                                    [13] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => getInnerText
                                            [body] => return $this->textContent;
                                            [declaration] => public function getInnerText()
                                        )

                                    [14] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => method
                                                            [declaration] => $method
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => args
                                                            [declaration] => $args
                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => __call
                                            [body] => if (substr($method,0,2)=='is'){
    $prop = lcfirst(substr($method,2));
    if ($this->has($prop)&&$this->$prop != 'false')return true;
    return false;
}
throw new \BadMethodCallException("Method '$method' does not exist on ".get_class($this));
                                            [declaration] => public function __call($method, $args)
                                        )

                                )

                        )

                )

        )

)
{
    "type": "file",
    "namespace": {
        "type": "namespace",
        "name": "Taeluf\\PHTML",
        "declaration": "namespace Taeluf\\PHTML;",
        "class": [
            {
                "type": "class",
                "docblock": {
                    "type": "docblock",
                    "description": "Parses .php files into:\n 1. A string with placeholders for the PHP code\n 2. An array of PHP code, identified by their placeholders"
                },
                "namespace": "Taeluf\\PHTML",
                "fqn": "Taeluf\\PHTML\\PHPParser",
                "name": "PHPParser",
                "declaration": "class PHPParser",
                "properties": [
                    {
                        "type": "property",
                        "modifiers": [
                            "protected",
                            "string"
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "The source HTML + PHP code\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "var",
                                    "description": "string"
                                }
                            ]
                        },
                        "name": "src",
                        "declaration": "protected string $src;"
                    },
                    {
                        "type": "property",
                        "modifiers": [
                            "protected",
                            "object"
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "The parsed pieces of code in the format:\n [\n     'html' => '<div>A string of code with php placeholders like <b>phpadsfwefhaksldfjaskdlfjaskldfjasldfkphp<\/b> <\/div> and trailing text...',\n     'php'  => [\n         'phpadsfwefhaksldfjaskdlfjaskldfjasldfkphp' => '<?=\"Something echod\";?>', \n         'phpid2'=>'<?php \/\/ another code block\/?>'\n     ]\n ]\nThe array is simply (object) cast"
                        },
                        "name": "pieces",
                        "declaration": "protected object $pieces;"
                    }
                ],
                "methods": [
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "htmlPHPString",
                                "declaration": "string $htmlPHPString"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Create a new PHP parser instance from a string\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "mixed $htmlPHPString - a block of HTML + PHP code. PHP code will be inside open (<?php or <?=) and close (?>) tags"
                                },
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "void"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "__construct",
                        "body": "$this->src = $htmlPHPString;\n$this->pieces = $this->separatePHP();",
                        "declaration": "public function __construct(string $htmlPHPString)"
                    },
                    {
                        "type": "method",
                        "args": [],
                        "docblock": {
                            "type": "docblock",
                            "description": "Return the parsed pieces. See doc for protected $pieces\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "object"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "pieces",
                        "return_types": [
                            "object"
                        ],
                        "body": "return $this->pieces;",
                        "declaration": "public function pieces(): object"
                    },
                    {
                        "type": "method",
                        "args": [],
                        "docblock": {
                            "type": "docblock",
                            "description": "Separate the source code into it's pieces. See the protected $pieces docs",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "object just an array cast to object"
                                }
                            ]
                        },
                        "modifiers": [
                            "protected"
                        ],
                        "name": "separatePHP",
                        "return_types": [
                            "object"
                        ],
                        "body": "$tokens = $this->tokens();\n$str = '';\n$inPHP = false;\n$phpCode = '';\n$phpList = [];\nforeach ($tokens as $index => $token){\n    $token = (object)$token;\n    if ($token->type=='T_OPEN_TAG'\n        ||$token->type=='T_OPEN_TAG_WITH_ECHO'){\n        $inPHP = true;\n    }\n    if (!$inPHP){\n        $str .= $token->code;\n    }\n    if ($inPHP){\n        $phpCode .= $token->code;\n    }\n    if ($token->type=='T_CLOSE_TAG'){\n        $id = 'php'.$this->randomAlpha().'php';\n        $phpList[$id] = $phpCode;\n        $phpCode = '';\n        $str .= $id;\n        $inPHP = false;\n    }\n}\nreturn (object)[\n    'php'=>$phpList,\n    'html'=>$str\n];",
                        "declaration": "protected function separatePHP(): object"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "length",
                                "value": "26",
                                "declaration": "$length = 26"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Generates a random string of characters a-z, all lowercase & returns them\n this is used for the PHP placeholders\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "int $length"
                                },
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "string"
                                }
                            ]
                        },
                        "modifiers": [
                            "protected"
                        ],
                        "name": "randomAlpha",
                        "return_types": [
                            "string"
                        ],
                        "body": "return static::getRandomAlpha($length);",
                        "declaration": "protected function randomAlpha($length = 26): string"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "length",
                                "value": "26",
                                "declaration": "$length = 26"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Generates a random string of characters a-z, all lowercase & returns them\n this is used for the PHP placeholders\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "int $length"
                                },
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "string"
                                }
                            ]
                        },
                        "modifiers": [
                            "static",
                            "public"
                        ],
                        "name": "getRandomAlpha",
                        "return_types": [
                            "string"
                        ],
                        "body": "$characters = 'abcdefghijklmnopqrstuvwxyz';\n$charactersLength = strlen($characters);\n$randomString = '';\nfor ($i = 0; $i < $length; $i++) {\n    $randomString .= $characters[rand(0, $charactersLength - 1)];\n}\nreturn $randomString;",
                        "declaration": "static public function getRandomAlpha($length = 26): string"
                    },
                    {
                        "type": "method",
                        "args": [],
                        "docblock": {
                            "type": "docblock",
                            "description": "Tokenize the src code into a slightly better format than token_get_all\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "array of tokens"
                                }
                            ]
                        },
                        "modifiers": [
                            "protected"
                        ],
                        "name": "tokens",
                        "return_types": [
                            "array"
                        ],
                        "body": "$content = $this->src;\n$tokens = token_get_all($content);\n$niceTokens = [];\n$delLine = null;\nforeach ($tokens as $index=>$token){\n    $tok = [];\n    if (!is_array($token)){\n        $lastTok = array_slice($niceTokens,-1)[0];\n        $tok['type'] = \"UNNAMED_TOKEN\";\n        $tok['code'] = $token;\n        $tok['line'] = $lastTok['line'];\n    } else {\n        $tok['type'] = token_name($token[0]);\n        $tok['code'] = $token[1];\n        $tok['line'] = $token[2];\n    }\n    \/\/ This is old code for an idea I had\n    \/\/ if ($tok['type']=='T_STRING'&&$tok['code']=='PHPPlus'){\n        \/\/ $next = $tokens[$index+1];\n        \/\/ if (is_array($next)&&$next[1]=='::'){\n            \/\/ $delLine = $tok['line'];\n            \/\/ echo 'del line is '.$delLine.\"\\n\\n\";\n        \/\/ }\n    \/\/ }\n    $niceTokens[] = $tok;\n}\nforeach ($niceTokens as $index=>$token){\n    if ($token['line']===$delLine){\n        unset($niceTokens[$index]);\n    }\n}\nreturn $niceTokens;",
                        "declaration": "protected function tokens(): array"
                    }
                ]
            }
        ]
    }
}Array
(
    [type] => file
    [namespace] => Array
        (
            [type] => namespace
            [name] => Taeluf\PHTML
            [declaration] => namespace Taeluf\PHTML;
            [class] => Array
                (
                    [0] => Array
                        (
                            [type] => class
                            [docblock] => Array
                                (
                                    [type] => docblock
                                    [description] => Parses .php files into:
 1. A string with placeholders for the PHP code
 2. An array of PHP code, identified by their placeholders
                                )

                            [namespace] => Taeluf\PHTML
                            [fqn] => Taeluf\PHTML\PHPParser
                            [name] => PHPParser
                            [declaration] => class PHPParser
                            [properties] => Array
                                (
                                    [0] => Array
                                        (
                                            [type] => property
                                            [modifiers] => Array
                                                (
                                                    [0] => protected
                                                    [1] => string
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => The source HTML + PHP code

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => var
                                                                    [description] => string
                                                                )

                                                        )

                                                )

                                            [name] => src
                                            [declaration] => protected string $src;
                                        )

                                    [1] => Array
                                        (
                                            [type] => property
                                            [modifiers] => Array
                                                (
                                                    [0] => protected
                                                    [1] => object
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => The parsed pieces of code in the format:
 [
     'html' => '<div>A string of code with php placeholders like <b>phpadsfwefhaksldfjaskdlfjaskldfjasldfkphp</b> </div> and trailing text...',
     'php'  => [
         'phpadsfwefhaksldfjaskdlfjaskldfjasldfkphp' => '<?="Something echod";?>', 
         'phpid2'=>'<?php // another code block/?>'
     ]
 ]
The array is simply (object) cast
                                                )

                                            [name] => pieces
                                            [declaration] => protected object $pieces;
                                        )

                                )

                            [methods] => Array
                                (
                                    [0] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => htmlPHPString
                                                            [declaration] => string $htmlPHPString
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Create a new PHP parser instance from a string

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => mixed $htmlPHPString - a block of HTML + PHP code. PHP code will be inside open (<?php or <?=) and close (?>) tags
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => void
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => __construct
                                            [body] => $this->src = $htmlPHPString;
$this->pieces = $this->separatePHP();
                                            [declaration] => public function __construct(string $htmlPHPString)
                                        )

                                    [1] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Return the parsed pieces. See doc for protected $pieces

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => object
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => pieces
                                            [return_types] => Array
                                                (
                                                    [0] => object
                                                )

                                            [body] => return $this->pieces;
                                            [declaration] => public function pieces(): object
                                        )

                                    [2] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Separate the source code into it's pieces. See the protected $pieces docs
                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => object just an array cast to object
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => protected
                                                )

                                            [name] => separatePHP
                                            [return_types] => Array
                                                (
                                                    [0] => object
                                                )

                                            [body] => $tokens = $this->tokens();
$str = '';
$inPHP = false;
$phpCode = '';
$phpList = [];
foreach ($tokens as $index => $token){
    $token = (object)$token;
    if ($token->type=='T_OPEN_TAG'
        ||$token->type=='T_OPEN_TAG_WITH_ECHO'){
        $inPHP = true;
    }
    if (!$inPHP){
        $str .= $token->code;
    }
    if ($inPHP){
        $phpCode .= $token->code;
    }
    if ($token->type=='T_CLOSE_TAG'){
        $id = 'php'.$this->randomAlpha().'php';
        $phpList[$id] = $phpCode;
        $phpCode = '';
        $str .= $id;
        $inPHP = false;
    }
}
return (object)[
    'php'=>$phpList,
    'html'=>$str
];
                                            [declaration] => protected function separatePHP(): object
                                        )

                                    [3] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => length
                                                            [value] => 26
                                                            [declaration] => $length = 26
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Generates a random string of characters a-z, all lowercase & returns them
 this is used for the PHP placeholders

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => int $length
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => string
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => protected
                                                )

                                            [name] => randomAlpha
                                            [return_types] => Array
                                                (
                                                    [0] => string
                                                )

                                            [body] => return static::getRandomAlpha($length);
                                            [declaration] => protected function randomAlpha($length = 26): string
                                        )

                                    [4] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => length
                                                            [value] => 26
                                                            [declaration] => $length = 26
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Generates a random string of characters a-z, all lowercase & returns them
 this is used for the PHP placeholders

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => int $length
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => string
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => static
                                                    [1] => public
                                                )

                                            [name] => getRandomAlpha
                                            [return_types] => Array
                                                (
                                                    [0] => string
                                                )

                                            [body] => $characters = 'abcdefghijklmnopqrstuvwxyz';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
    $randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
                                            [declaration] => static public function getRandomAlpha($length = 26): string
                                        )

                                    [5] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Tokenize the src code into a slightly better format than token_get_all

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => array of tokens
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => protected
                                                )

                                            [name] => tokens
                                            [return_types] => Array
                                                (
                                                    [0] => array
                                                )

                                            [body] => $content = $this->src;
$tokens = token_get_all($content);
$niceTokens = [];
$delLine = null;
foreach ($tokens as $index=>$token){
    $tok = [];
    if (!is_array($token)){
        $lastTok = array_slice($niceTokens,-1)[0];
        $tok['type'] = "UNNAMED_TOKEN";
        $tok['code'] = $token;
        $tok['line'] = $lastTok['line'];
    } else {
        $tok['type'] = token_name($token[0]);
        $tok['code'] = $token[1];
        $tok['line'] = $token[2];
    }
    // This is old code for an idea I had
    // if ($tok['type']=='T_STRING'&&$tok['code']=='PHPPlus'){
        // $next = $tokens[$index+1];
        // if (is_array($next)&&$next[1]=='::'){
            // $delLine = $tok['line'];
            // echo 'del line is '.$delLine."\n\n";
        // }
    // }
    $niceTokens[] = $tok;
}
foreach ($niceTokens as $index=>$token){
    if ($token['line']===$delLine){
        unset($niceTokens[$index]);
    }
}
return $niceTokens;
                                            [declaration] => protected function tokens(): array
                                        )

                                )

                        )

                )

        )

)
{
    "type": "file",
    "namespace": {
        "type": "namespace",
        "name": "Taeluf",
        "declaration": "namespace Taeluf;",
        "class": [
            {
                "type": "class",
                "docblock": {
                    "type": "docblock",
                    "description": "Makes DUMDocument... less terrible, but still not truly good"
                },
                "namespace": "Taeluf",
                "fqn": "Taeluf\\Phtml",
                "name": "Phtml",
                "extends": "\\DOMDocument",
                "declaration": "class Phtml extends \\DOMDocument",
                "properties": [
                    {
                        "type": "property",
                        "modifiers": [
                            "protected",
                            "string"
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "The source HTML + PHP code\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "var",
                                    "description": "string"
                                }
                            ]
                        },
                        "name": "src",
                        "declaration": "protected string $src;"
                    },
                    {
                        "type": "property",
                        "modifiers": [
                            "protected",
                            "string"
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "The source code with all the PHP replaced by placeholders"
                        },
                        "name": "cleanSrc",
                        "declaration": "protected string $cleanSrc;"
                    },
                    {
                        "type": "property",
                        "modifiers": [
                            "protected",
                            "array"
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "[ 'phpplaceholder' => $phpCode, 'placeholder2' => $morePHP ]"
                        },
                        "name": "php",
                        "declaration": "protected array $php;"
                    },
                    {
                        "type": "property",
                        "modifiers": [
                            "protected"
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "A random string used when adding php code to a node's tag declaration. This string is later removed during output()"
                        },
                        "name": "phpAttrValue",
                        "declaration": "protected $phpAttrValue;"
                    }
                ],
                "comments": [
                    "\/**",
                    "* True if the source html had a '<html>' tag",
                    "* Except we're not implementing that???",
                    "* @var bool",
                    "*\/",
                    "protected bool $isHTMLDoc = false;"
                ],
                "methods": [
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "html",
                                "declaration": "$html"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Create a DOMDocument, passing your HTML + PHP to __construct. \n\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "mixed $html a block of HTML + PHP code. It does not have to have PHP. PHP will be handled gracefully."
                                },
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "void"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "__construct",
                        "body": "parent::__construct();\n$this->srcHTML = $html;\n$parser = new PHTML\\PHPParser($html);\n$enc = $parser->pieces();\n$this->php = $enc->php;\n$this->cleanSrc = $enc->html;\n$this->cleanSrc = $this->cleanHTML($this->cleanSrc);\n$hideXmlErrors=true;\nlibxml_use_internal_errors($hideXmlErrors);\n$this->registerNodeClass('DOMElement', '\\\\Taeluf\\\\PHTML\\\\Node');\n$this->registerNodeClass('DOMText', '\\\\Taeluf\\\\PHTML\\\\TextNode');\n\/\/ $this->registerNodeClass('DOMText', 'RBText');\n$html = '<root>'.$this->cleanSrc.'<\/root>';\n$this->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);\n$this->formatOutput = true;\nlibxml_use_internal_errors(false);",
                        "declaration": "public function __construct($html)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "string",
                                "declaration": "string $string"
                            }
                        ],
                        "modifiers": [
                            "public"
                        ],
                        "name": "placeholder",
                        "return_types": [
                            "string"
                        ],
                        "body": "$placeholder = PHTML\\PHPParser::getRandomAlpha();\n$placeholder = 'php'.$placeholder.'php';\n$this->php[$placeholder] = $string;\nreturn $placeholder;",
                        "declaration": "public function placeholder(string $string): string"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "placeholder",
                                "declaration": "string $placeholder"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Get the code that's represented by the placeholder",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "the stored code or null"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "codeFromPlaceholder",
                        "return_types": [
                            "string"
                        ],
                        "body": "$code = $this->php[trim($placeholder)] ?? null;\nreturn $code;",
                        "declaration": "public function codeFromPlaceholder(string $placeholder): string"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "enclosedPHP",
                                "declaration": "string $enclosedPHP"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Get a placeholder for the given block of code\nIntention is to parse a single '<?php \/\/piece of php code ?>' and not '<?php \/\/stuff ?><?php \/\/more stuff?>'\nWhen used as intended, will return a single 'word' that is the placeholder for the given code\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "mixed $enclosedPHP an HTML + PHP string"
                                },
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "string the parsed block of content where PHP code blocks are replaced by placeholders."
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "phpPlaceholder",
                        "return_types": [
                            "string"
                        ],
                        "body": "$parser = new PHTML\\PHPParser($enclosedPHP);\n$enc = $parser->pieces();\n\/\/ This block doesn't work because it's over-eager. A workaround to just add code, regardless of open\/close tags, would be good.\n\/\/ if (count($enc->php)==0){\n    \/\/ $code = \\PHTML\\PHPParser::getRandomAlpha();\n    \/\/ $enc->php = [\"php${code}php\"=>$enclosedPhp];\n    \/\/ $enc->html = $code;\n\/\/ }\n$this->php = array_merge($this->php,$enc->php);\nreturn $enc->html;",
                        "declaration": "public function phpPlaceholder(string $enclosedPHP): string"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "codeWithPlaceholders",
                                "declaration": "string $codeWithPlaceholders"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Decode the given code by replacing PHP placeholders with the PHP code itself\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "mixed $str"
                                },
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "void"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "fillWithPHP",
                        "return_types": [
                            "string"
                        ],
                        "body": "$decoded = str_replace(array_keys($this->php),$this->php,$codeWithPlaceholders);\nreturn $decoded;",
                        "declaration": "public function fillWithPHP(string $codeWithPlaceholders): string"
                    },
                    {
                        "type": "method",
                        "args": [],
                        "docblock": {
                            "type": "docblock",
                            "description": "See output()\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "string"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "__toString",
                        "body": "return $this->output();",
                        "declaration": "public function __toString()"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "withPHP",
                                "value": "true",
                                "declaration": "$withPHP=true"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Return the decoded document as as tring. All PHP will be back in its place\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "mixed $withPHP passing FALSE means placeholders will still be present & PHP code will not be"
                                },
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "string the final document with PHP where it belongs"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "output",
                        "body": "\/\/ echo \"\\n\".'-start output call-'.\"\\n\";\n$list = $this->childNodes[0]->childNodes;\n$hiddenTagsNodes = $this->xpath('\/\/*[@hideOwnTag]');\nforeach ($hiddenTagsNodes as $htn){\n    if ($htn->hideOwnTag==false||$htn->hideOwnTag=='false'){\n        unset($htn->hideOwnTag);\n        continue;\n    }\n    $parent = $htn->parentNode;\n    $childNodeList = $htn->children;\n    foreach ($childNodeList as $child){\n        $htn->removeChild($child);\n        $parent->insertBefore($child, $htn);\n    }\n    $parent->removeChild($htn);\n}\n$html = '';\nforeach ($list as $item){\n    $html .= $this->saveHTML($item);\n}\n\/** Run the php-code-replacer as long as there is a placeholder (while preventing infinite looping) *\/\n$html = $this->fill_php($html, $withPHP);\n$html = $this->restoreHtml($html);\nreturn $html;",
                        "declaration": "public function output($withPHP=true)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "html",
                                "declaration": "$html"
                            },
                            {
                                "type": "arg",
                                "name": "withPHP",
                                "value": "true",
                                "declaration": "$withPHP=true"
                            }
                        ],
                        "modifiers": [
                            "public"
                        ],
                        "name": "fill_php",
                        "body": "$maxIters = 25;\n$iters = 0;\nwhile ($iters++<$maxIters&&preg_match('\/php([a-zA-Z]{26})php\/', $html, $match)){\n    foreach ($this->php as $id=>$code){\n        if ($withPHP)$html = str_replace($id,$code,$html);\n        else $html = str_replace($id,'',$html);\n    }\n}\nif (($phpAttrVal=$this->phpAttrValue)!=null){\n    $html = str_replace(\"=\\\"$phpAttrVal\\\"\", '', $html);\n}\nreturn $html;",
                        "declaration": "public function fill_php($html, $withPHP=true)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "xpath",
                                "declaration": "$xpath"
                            },
                            {
                                "type": "arg",
                                "name": "refNode",
                                "value": "null",
                                "declaration": "$refNode=null"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "get the results of an xpath query\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "mixed $xpath the xpath query, such as: \/\/tagname[@attributename=\"value\"]\n                 If you use a refnode, prepend '.' at the beginning of your xpath query string"
                                },
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "mixed $refNode a parent-node to search under"
                                },
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "array the resulting DomNodeList is converted to an array & returned"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "xpath",
                        "body": "$xp = new \\DOMXpath($this);\nif ($refNode==null)$list =  $xp->query($xpath);\nelse $list = $xp->query($xpath,$refNode);\n$arr = [];\nforeach ($list as $item){\n    $arr[] = $item;\n}\nreturn $arr;",
                        "declaration": "public function xpath($xpath,$refNode=null)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "node",
                                "declaration": "$node"
                            },
                            {
                                "type": "arg",
                                "name": "phpCode",
                                "declaration": "$phpCode"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "Set an attribute that will place PHP code inside the tag declartion of a node. \nBasically: `<node phpCodePlaceholder>`, which pHtml will later convert to `<node <?='some_stuff'?>>`. \nThis avoids problems caused by attributes requiring a `=\"\"`, which `DOMDocument` automatically places.\n",
                            "attribute": [
                                {
                                    "type": "attribute",
                                    "name": "param",
                                    "description": "$phpCode A block of php code with opening & closing tags like <?='some stuff'?>"
                                },
                                {
                                    "type": "attribute",
                                    "name": "return",
                                    "description": "\\Taeluf\\PHTML\\ValuelessAttribute"
                                }
                            ]
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "addPhpToTag",
                        "body": "$this->phpAttrValue = $this->phpAttrValue  ??  PHTML\\PHPParser::getRandomAlpha();\n$placeholder = $this->phpPlaceholder($phpCode);\n$node->setAttribute($placeholder, $this->phpAttrValue);\nreturn $placeholder;",
                        "declaration": "public function addPhpToTag($node, $phpCode)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "\\DOMNode"
                                ],
                                "name": "node",
                                "declaration": "\\DOMNode $node"
                            },
                            {
                                "type": "arg",
                                "name": "phpCode",
                                "declaration": "$phpCode"
                            }
                        ],
                        "modifiers": [
                            "public"
                        ],
                        "name": "insertCodeBefore",
                        "body": "\/\/ $placeholder = $this->phpPlaceholder($phpCode);\n$placeholder = $this->placeholder($phpCode);\n$text = new \\DOMText($placeholder);\nreturn $node->parentNode->insertBefore($text, $node);",
                        "declaration": "public function insertCodeBefore(\\DOMNode $node, $phpCode)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "\\DOMNode"
                                ],
                                "name": "node",
                                "declaration": "\\DOMNode $node"
                            },
                            {
                                "type": "arg",
                                "name": "phpCode",
                                "declaration": "$phpCode"
                            }
                        ],
                        "modifiers": [
                            "public"
                        ],
                        "name": "insertCodeAfter",
                        "body": "$placeholder = $this->placeholder($phpCode);\n$text = new \\DOMText($placeholder);\nif ($node->nextSibling!==null)return $node->parentNode->insertBefore($text,$node->nextSibling);\nreturn $node->parentNode->insertBefore($text);",
                        "declaration": "public function insertCodeAfter(\\DOMNode $node, $phpCode)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "html",
                                "declaration": "$html"
                            }
                        ],
                        "modifiers": [
                            "public"
                        ],
                        "name": "cleanHTML",
                        "body": "\/\/ fix doctype\n$html = preg_replace('\/\\<\\!DOCTYPE(.*)\\>\/i', '<tlfphtml-doctype$1><\/tlfphtml-doctype>',$html);\n\/\/ fix <html> tag\n$html = preg_replace('\/<html([ >])\/','<tlfphtml-html$1',$html);\n$html = str_ireplace('<\/html>', '<\/tlfphtml-html>', $html);\n\/\/ fix <head> tag\n$html = preg_replace('\/<head([ >])\/', '<tlfphtml-head$1',$html);\n$html = str_ireplace('<\/head>', '<\/tlfphtml-head>',$html);\nreturn $html;",
                        "declaration": "public function cleanHTML($html)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "html",
                                "declaration": "$html"
                            }
                        ],
                        "modifiers": [
                            "public"
                        ],
                        "name": "restoreHtml",
                        "body": "$html = preg_replace('\/\\<tlfphtml\\-doctype(.*)\\>\\<\\\/tlfphtml\\-doctype\\>\/i', '<!DOCTYPE$1>',$html);\n\/\/ fix <html> tag\n$html = str_ireplace('<tlfphtml-html','<html',$html);\n$html = str_ireplace('<\/tlfphtml-html>', '<\/html>', $html);\n\/\/ fix <head> tag\n$html = str_ireplace('<tlfphtml-head', '<head', $html);\n$html = str_ireplace('<\/tlfphtml-head>', '<\/head>', $html);\nreturn $html;",
                        "declaration": "public function restoreHtml($html)"
                    },
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "name": "param",
                                "declaration": "$param"
                            }
                        ],
                        "modifiers": [
                            "public"
                        ],
                        "name": "__get",
                        "body": "if ($param == 'form'){\n    return $this->xpath('\/\/form')[0] ?? null;\n}",
                        "declaration": "public function __get($param)"
                    }
                ]
            }
        ]
    }
}Array
(
    [type] => file
    [namespace] => Array
        (
            [type] => namespace
            [name] => Taeluf
            [declaration] => namespace Taeluf;
            [class] => Array
                (
                    [0] => Array
                        (
                            [type] => class
                            [docblock] => Array
                                (
                                    [type] => docblock
                                    [description] => Makes DUMDocument... less terrible, but still not truly good
                                )

                            [namespace] => Taeluf
                            [fqn] => Taeluf\Phtml
                            [name] => Phtml
                            [extends] => \DOMDocument
                            [declaration] => class Phtml extends \DOMDocument
                            [properties] => Array
                                (
                                    [0] => Array
                                        (
                                            [type] => property
                                            [modifiers] => Array
                                                (
                                                    [0] => protected
                                                    [1] => string
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => The source HTML + PHP code

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => var
                                                                    [description] => string
                                                                )

                                                        )

                                                )

                                            [name] => src
                                            [declaration] => protected string $src;
                                        )

                                    [1] => Array
                                        (
                                            [type] => property
                                            [modifiers] => Array
                                                (
                                                    [0] => protected
                                                    [1] => string
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => The source code with all the PHP replaced by placeholders
                                                )

                                            [name] => cleanSrc
                                            [declaration] => protected string $cleanSrc;
                                        )

                                    [2] => Array
                                        (
                                            [type] => property
                                            [modifiers] => Array
                                                (
                                                    [0] => protected
                                                    [1] => array
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => [ 'phpplaceholder' => $phpCode, 'placeholder2' => $morePHP ]
                                                )

                                            [name] => php
                                            [declaration] => protected array $php;
                                        )

                                    [3] => Array
                                        (
                                            [type] => property
                                            [modifiers] => Array
                                                (
                                                    [0] => protected
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => A random string used when adding php code to a node's tag declaration. This string is later removed during output()
                                                )

                                            [name] => phpAttrValue
                                            [declaration] => protected $phpAttrValue;
                                        )

                                )

                            [comments] => Array
                                (
                                    [0] => /**
                                    [1] => * True if the source html had a '<html>' tag
                                    [2] => * Except we're not implementing that???
                                    [3] => * @var bool
                                    [4] => */
                                    [5] => protected bool $isHTMLDoc = false;
                                )

                            [methods] => Array
                                (
                                    [0] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => html
                                                            [declaration] => $html
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Create a DOMDocument, passing your HTML + PHP to __construct. 


                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => mixed $html a block of HTML + PHP code. It does not have to have PHP. PHP will be handled gracefully.
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => void
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => __construct
                                            [body] => parent::__construct();
$this->srcHTML = $html;
$parser = new PHTML\PHPParser($html);
$enc = $parser->pieces();
$this->php = $enc->php;
$this->cleanSrc = $enc->html;
$this->cleanSrc = $this->cleanHTML($this->cleanSrc);
$hideXmlErrors=true;
libxml_use_internal_errors($hideXmlErrors);
$this->registerNodeClass('DOMElement', '\\Taeluf\\PHTML\\Node');
$this->registerNodeClass('DOMText', '\\Taeluf\\PHTML\\TextNode');
// $this->registerNodeClass('DOMText', 'RBText');
$html = '<root>'.$this->cleanSrc.'</root>';
$this->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$this->formatOutput = true;
libxml_use_internal_errors(false);
                                            [declaration] => public function __construct($html)
                                        )

                                    [1] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => string
                                                            [declaration] => string $string
                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => placeholder
                                            [return_types] => Array
                                                (
                                                    [0] => string
                                                )

                                            [body] => $placeholder = PHTML\PHPParser::getRandomAlpha();
$placeholder = 'php'.$placeholder.'php';
$this->php[$placeholder] = $string;
return $placeholder;
                                            [declaration] => public function placeholder(string $string): string
                                        )

                                    [2] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => placeholder
                                                            [declaration] => string $placeholder
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Get the code that's represented by the placeholder
                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => the stored code or null
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => codeFromPlaceholder
                                            [return_types] => Array
                                                (
                                                    [0] => string
                                                )

                                            [body] => $code = $this->php[trim($placeholder)] ?? null;
return $code;
                                            [declaration] => public function codeFromPlaceholder(string $placeholder): string
                                        )

                                    [3] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => enclosedPHP
                                                            [declaration] => string $enclosedPHP
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Get a placeholder for the given block of code
Intention is to parse a single '<?php //piece of php code ?>' and not '<?php //stuff ?><?php //more stuff?>'
When used as intended, will return a single 'word' that is the placeholder for the given code

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => mixed $enclosedPHP an HTML + PHP string
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => string the parsed block of content where PHP code blocks are replaced by placeholders.
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => phpPlaceholder
                                            [return_types] => Array
                                                (
                                                    [0] => string
                                                )

                                            [body] => $parser = new PHTML\PHPParser($enclosedPHP);
$enc = $parser->pieces();
// This block doesn't work because it's over-eager. A workaround to just add code, regardless of open/close tags, would be good.
// if (count($enc->php)==0){
    // $code = \PHTML\PHPParser::getRandomAlpha();
    // $enc->php = ["php${code}php"=>$enclosedPhp];
    // $enc->html = $code;
// }
$this->php = array_merge($this->php,$enc->php);
return $enc->html;
                                            [declaration] => public function phpPlaceholder(string $enclosedPHP): string
                                        )

                                    [4] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => codeWithPlaceholders
                                                            [declaration] => string $codeWithPlaceholders
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Decode the given code by replacing PHP placeholders with the PHP code itself

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => mixed $str
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => void
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => fillWithPHP
                                            [return_types] => Array
                                                (
                                                    [0] => string
                                                )

                                            [body] => $decoded = str_replace(array_keys($this->php),$this->php,$codeWithPlaceholders);
return $decoded;
                                            [declaration] => public function fillWithPHP(string $codeWithPlaceholders): string
                                        )

                                    [5] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => See output()

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => string
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => __toString
                                            [body] => return $this->output();
                                            [declaration] => public function __toString()
                                        )

                                    [6] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => withPHP
                                                            [value] => true
                                                            [declaration] => $withPHP=true
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Return the decoded document as as tring. All PHP will be back in its place

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => mixed $withPHP passing FALSE means placeholders will still be present & PHP code will not be
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => string the final document with PHP where it belongs
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => output
                                            [body] => // echo "\n".'-start output call-'."\n";
$list = $this->childNodes[0]->childNodes;
$hiddenTagsNodes = $this->xpath('//*[@hideOwnTag]');
foreach ($hiddenTagsNodes as $htn){
    if ($htn->hideOwnTag==false||$htn->hideOwnTag=='false'){
        unset($htn->hideOwnTag);
        continue;
    }
    $parent = $htn->parentNode;
    $childNodeList = $htn->children;
    foreach ($childNodeList as $child){
        $htn->removeChild($child);
        $parent->insertBefore($child, $htn);
    }
    $parent->removeChild($htn);
}
$html = '';
foreach ($list as $item){
    $html .= $this->saveHTML($item);
}
/** Run the php-code-replacer as long as there is a placeholder (while preventing infinite looping) */
$html = $this->fill_php($html, $withPHP);
$html = $this->restoreHtml($html);
return $html;
                                            [declaration] => public function output($withPHP=true)
                                        )

                                    [7] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => html
                                                            [declaration] => $html
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => withPHP
                                                            [value] => true
                                                            [declaration] => $withPHP=true
                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => fill_php
                                            [body] => $maxIters = 25;
$iters = 0;
while ($iters++<$maxIters&&preg_match('/php([a-zA-Z]{26})php/', $html, $match)){
    foreach ($this->php as $id=>$code){
        if ($withPHP)$html = str_replace($id,$code,$html);
        else $html = str_replace($id,'',$html);
    }
}
if (($phpAttrVal=$this->phpAttrValue)!=null){
    $html = str_replace("=\"$phpAttrVal\"", '', $html);
}
return $html;
                                            [declaration] => public function fill_php($html, $withPHP=true)
                                        )

                                    [8] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => xpath
                                                            [declaration] => $xpath
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => refNode
                                                            [value] => null
                                                            [declaration] => $refNode=null
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => get the results of an xpath query

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => mixed $xpath the xpath query, such as: //tagname[@attributename="value"]
                 If you use a refnode, prepend '.' at the beginning of your xpath query string
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => mixed $refNode a parent-node to search under
                                                                )

                                                            [2] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => array the resulting DomNodeList is converted to an array & returned
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => xpath
                                            [body] => $xp = new \DOMXpath($this);
if ($refNode==null)$list =  $xp->query($xpath);
else $list = $xp->query($xpath,$refNode);
$arr = [];
foreach ($list as $item){
    $arr[] = $item;
}
return $arr;
                                            [declaration] => public function xpath($xpath,$refNode=null)
                                        )

                                    [9] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => node
                                                            [declaration] => $node
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => phpCode
                                                            [declaration] => $phpCode
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => Set an attribute that will place PHP code inside the tag declartion of a node. 
Basically: `<node phpCodePlaceholder>`, which pHtml will later convert to `<node <?='some_stuff'?>>`. 
This avoids problems caused by attributes requiring a `=""`, which `DOMDocument` automatically places.

                                                    [attribute] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => param
                                                                    [description] => $phpCode A block of php code with opening & closing tags like <?='some stuff'?>
                                                                )

                                                            [1] => Array
                                                                (
                                                                    [type] => attribute
                                                                    [name] => return
                                                                    [description] => \Taeluf\PHTML\ValuelessAttribute
                                                                )

                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => addPhpToTag
                                            [body] => $this->phpAttrValue = $this->phpAttrValue  ??  PHTML\PHPParser::getRandomAlpha();
$placeholder = $this->phpPlaceholder($phpCode);
$node->setAttribute($placeholder, $this->phpAttrValue);
return $placeholder;
                                            [declaration] => public function addPhpToTag($node, $phpCode)
                                        )

                                    [10] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => \DOMNode
                                                                )

                                                            [name] => node
                                                            [declaration] => \DOMNode $node
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => phpCode
                                                            [declaration] => $phpCode
                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => insertCodeBefore
                                            [body] => // $placeholder = $this->phpPlaceholder($phpCode);
$placeholder = $this->placeholder($phpCode);
$text = new \DOMText($placeholder);
return $node->parentNode->insertBefore($text, $node);
                                            [declaration] => public function insertCodeBefore(\DOMNode $node, $phpCode)
                                        )

                                    [11] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => \DOMNode
                                                                )

                                                            [name] => node
                                                            [declaration] => \DOMNode $node
                                                        )

                                                    [1] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => phpCode
                                                            [declaration] => $phpCode
                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => insertCodeAfter
                                            [body] => $placeholder = $this->placeholder($phpCode);
$text = new \DOMText($placeholder);
if ($node->nextSibling!==null)return $node->parentNode->insertBefore($text,$node->nextSibling);
return $node->parentNode->insertBefore($text);
                                            [declaration] => public function insertCodeAfter(\DOMNode $node, $phpCode)
                                        )

                                    [12] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => html
                                                            [declaration] => $html
                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => cleanHTML
                                            [body] => // fix doctype
$html = preg_replace('/\<\!DOCTYPE(.*)\>/i', '<tlfphtml-doctype$1></tlfphtml-doctype>',$html);
// fix <html> tag
$html = preg_replace('/<html([ >])/','<tlfphtml-html$1',$html);
$html = str_ireplace('</html>', '</tlfphtml-html>', $html);
// fix <head> tag
$html = preg_replace('/<head([ >])/', '<tlfphtml-head$1',$html);
$html = str_ireplace('</head>', '</tlfphtml-head>',$html);
return $html;
                                            [declaration] => public function cleanHTML($html)
                                        )

                                    [13] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => html
                                                            [declaration] => $html
                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => restoreHtml
                                            [body] => $html = preg_replace('/\<tlfphtml\-doctype(.*)\>\<\/tlfphtml\-doctype\>/i', '<!DOCTYPE$1>',$html);
// fix <html> tag
$html = str_ireplace('<tlfphtml-html','<html',$html);
$html = str_ireplace('</tlfphtml-html>', '</html>', $html);
// fix <head> tag
$html = str_ireplace('<tlfphtml-head', '<head', $html);
$html = str_ireplace('</tlfphtml-head>', '</head>', $html);
return $html;
                                            [declaration] => public function restoreHtml($html)
                                        )

                                    [14] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [name] => param
                                                            [declaration] => $param
                                                        )

                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => __get
                                            [body] => if ($param == 'form'){
    return $this->xpath('//form')[0] ?? null;
}
                                            [declaration] => public function __get($param)
                                        )

                                )

                        )

                )

        )

)
{
    "type": "file",
    "namespace": {
        "type": "namespace",
        "name": "Taeluf\\PHTML",
        "declaration": "namespace Taeluf\\PHTML;",
        "class": [
            {
                "type": "class",
                "namespace": "Taeluf\\PHTML",
                "fqn": "Taeluf\\PHTML\\TextNode",
                "name": "TextNode",
                "extends": "\\DOMText",
                "declaration": "class TextNode extends \\DOMText",
                "methods": [
                    {
                        "type": "method",
                        "args": [
                            {
                                "type": "arg",
                                "arg_types": [
                                    "string"
                                ],
                                "name": "tagName",
                                "declaration": "string $tagName"
                            }
                        ],
                        "docblock": {
                            "type": "docblock",
                            "description": "is this node the given tag"
                        },
                        "modifiers": [
                            "public"
                        ],
                        "name": "is",
                        "return_types": [
                            "bool"
                        ],
                        "body": "if (strtolower($this->nodeName)==strtolower($tagName))return true;\nreturn false;",
                        "declaration": "public function is(string $tagName): bool"
                    }
                ]
            }
        ]
    }
}Array
(
    [type] => file
    [namespace] => Array
        (
            [type] => namespace
            [name] => Taeluf\PHTML
            [declaration] => namespace Taeluf\PHTML;
            [class] => Array
                (
                    [0] => Array
                        (
                            [type] => class
                            [namespace] => Taeluf\PHTML
                            [fqn] => Taeluf\PHTML\TextNode
                            [name] => TextNode
                            [extends] => \DOMText
                            [declaration] => class TextNode extends \DOMText
                            [methods] => Array
                                (
                                    [0] => Array
                                        (
                                            [type] => method
                                            [args] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [type] => arg
                                                            [arg_types] => Array
                                                                (
                                                                    [0] => string
                                                                )

                                                            [name] => tagName
                                                            [declaration] => string $tagName
                                                        )

                                                )

                                            [docblock] => Array
                                                (
                                                    [type] => docblock
                                                    [description] => is this node the given tag
                                                )

                                            [modifiers] => Array
                                                (
                                                    [0] => public
                                                )

                                            [name] => is
                                            [return_types] => Array
                                                (
                                                    [0] => bool
                                                )

                                            [body] => if (strtolower($this->nodeName)==strtolower($tagName))return true;
return false;
                                            [declaration] => public function is(string $tagName): bool
                                        )

                                )

                        )

                )

        )

)
<?php

namespace Tlf\Lexer\Test;

/**
 * These are tests that either aren't really tests or that probably don't have a place any more
 */
class DefunctTests extends \Tlf\Lexer\Test\Tester {

    /** convert a tree into json to see if i like the output better 
     *
     * This was never a test. Just a way to run some code.
     */
    public function testMakeJson(){
        $this->disable();
        return;
        $file = $this->file('test/input/php/');
        $tree = require($file.'tree/SampleClass.tree.php');
        $json = json_encode($tree, JSON_PRETTY_PRINT);
        file_put_contents($file.'tree/SampleClass.tree.json', $json);

    }
    /**
     * An old test I was using to design the new php grammar.
     * It is just a mess now and i don't want to mess with it.
     */
    public function testPhpGrammarNew_SampleClass(){

        echo "it's wrong. I don't know why, and I don't want to fix it.";
        $this->disable();

        return;


        // $dir = dirname(__DIR__).'/php-new/';
        // $dir = dirname()
        $dir = $this->file('test/input/php/lex/');
        $file = $dir.'SampleClass.php';
        $targetTree = file_get_contents($this->file('test/input/php/tree/').'SampleClass.js');
        $targetTree = json_decode($targetTree, true);

        $lexer = new \Tlf\Lexer();
        $lexer->debug = true;

        //the string rewrite
        // $lexer->stop_loop = 305; // on loop 293, we start listening for strings. string_double STOPS on loop 299
        //on loop 300, 

        // This is for devving v0.6:
        // $lexer->stop_loop = 18;
        // $lexer->stop_loop = 33;
        // $lexer->stop_loop = 21; 
        // $lexer->stop_loop = 31;
        // $lexer->stop_loop = 41;
        // $lexer->stop_loop = 51;
        // $lexer->stop_loop = 111; // catching 'class'
        // $lexer->stop_loop = 120;
        // $lexer->stop_loop = 135; // block starts at 132
        // $lexer->stop_loop = 150; // use trait is about 150
        // $lexer->stop_loop = 185; // 181 is new line for first comment
        // $lexer->stop_loop = 206; // process # second comment at 203
        // $lexer->stop_loop = 261; // Process first property's docblock
        // $lexer->stop_loop = 280; // 277 'modifier' starts
        // $lexer->stop_loop = 300; // first property processed on 299
        // $lexer->stop_loop = 335; // second property is complete
        // $lexer->stop_loop = 395; // static public property is finished by loop 385
        // $lexer->stop_loop = 445; // method docblock finishes on 441
        // $lexer->stop_loop = 460; // `public ` is captured on 454, starting method modifier
        // $lexer->stop_loop = 492; // method block (opening curly brace) starts on 473
        // $lexer->stop_loop = 525; // closing method curly brace is loop 516
        // $lexer->stop_loop = 553; // issues around `=` around 550
        // $lexer->stop_loop = 585; // see 542 for `const `. `=` is loop 551. string closes on 578
        // $lexer->stop_loop = 800;
        // $lexer->stop_loop = 1200;

        
        // $lexer->stop_loop = 9999999;
        $lexer->useCache = false; // useCache only matters when lexing a file
        $lexer->addGrammar($phpGrammar = new \Tlf\Lexer\PhpGrammarNew());

        $ast = $lexer->lexFile($file);

        $tree = $ast->getTree(); // not what we normally want with json

        echo "\n\n\n --- file AST ---\n\n";

        print_r($tree);

        //
        // write the current tree to a file
        //
        file_put_contents($dir.'SampleClass.tree2.php',var_export($tree,true));
        echo "\n----\n\n\n";
        $this->compare(
            $targetTree, 
            $tree
        );
    }
}
<?php

namespace Tlf\Lexer\Test;

class BashGrammar extends Tester {

    /**
     * Array of inputs to lex & test
     * @key name of test
     * @value array with keys 
     *
     * @param start the name of the directive to initialize the lexer with
     * @param input a string to parse (optionally can use input_file instead)
     * @param expect an array of what the output AST should be
     * @param input_file (optional) a file to load as input, relative to project root.
     */
    protected $thingies = [
        // whitespace, docblock, function, comment
        'ws_dblock_func_cmnt'=>[
            'start'=>'bash',
            'input_file'=>'test/input/bash/ws_dblock_func_cmnt.bash',
            'input'=>null,
            'expect'=>[
                'function'=>
                [
                    0=>[
                        'type' => 'function',
                        'name' => 'echo_path',
                        'docblock' => 
                        [
                            'type' => 'docblock',
                            'description' => "\n Description",
                            'attribute' => 
                            [
                                0 => 
                                [
                                    'type' => 'attribute',
                                    'name' => 'arg',
                                    'description' => '$1 a path',
                                ]

                            ]
                        ]
                    ],
                    1=>[
                        'type'=>'function',
                        'name'=>'echo_string',
                        'docblock'=>null
                    ]
                ],
                'comments'=>[
                    0=>[
                        'type'=>'comment',
                        'src'=> '# comment 1',
                        'description'=> ' comment 1',
                    ],
                    1=>[
                        'type'=>'comment',
                        'src'=> '# comment 2',
                        'description'=> ' comment 2',
                    ],
                    2=>[
                        'type'=>'comment',
                        'src'=> '# comment 3',
                        'description'=> ' comment 3',
                    ]
                ],
            ],
        ],
        'comments_functions'=>[
            'start'=>'bash',
            'input_file'=>'test/input/bash/comments_functions.bash',
            'input'=>null,
            'expect'=>[
                'comments'=>[
                    0=>[
                        'type'=>'comment',
                        'src'=>'#!/usr/bin/env bash',
                        'description'=>'!/usr/bin/env bash',
                    ],
                    1=>[
                        'type'=>'comment',
                        'src'=>'# comment one',
                        'description'=> ' comment one',
                    ]
                ],
                'function'=>[
                    0=>[ 'type'=>'function',
                        'name'=>'pre_comment',
                        'docblock'=>null
                    ],
                    1=>[ 'type'=>'function',
                        'name'=>'post_comment',
                        'docblock'=>null
                    ],
                ],
            ],
        ],
        'whitespace_docblock_function'=>[
            'start'=>'bash',
            'input_file'=>'test/input/bash/whitespace_docblock_function.bash',
            'input'=>null,
            'expect'=>[
                'function'=>
                [
                    0=>[
                        'type' => 'function',
                        'name' => 'echo_path',
                        'docblock' => 
                        [
                            'type' => 'docblock',
                            'description' => "\n Description",
                            'attribute' => 
                            [
                                0 => 
                                [
                                    'type' => 'attribute',
                                    'name' => 'arg',
                                    'description' => '$1 a path',
                                ]

                            ]

                        ]
                    ]
                ]
            ],
        ],
        'Docblock_Function'=>[
            'start'=>'bash',
            'input'=>"##\n# Commit all files & push to origin host\n#\n# @tip Save your project\n# @shorthand s, commit\n#"
                    ."\nfunction core_save(){\nmsg \"Pretend save function\"\n}",
            'expect'=>[
                'function'=>[
                    0=>[
                        'type'=>'function',
                        'name'=>'core_save',
                        'docblock'=>[
                            'type'=>'docblock',
                            'description'=> "\n Commit all files & push to origin host\n",
                            "attribute"=>[
                                0=>[
                                    'type'=>'attribute',
                                    'name'=>'tip',
                                    'description'=>'Save your project'
                                ],
                                1=>[
                                    'type'=>'attribute',
                                    'name'=>'shorthand',
                                    'description'=>"s, commit\n",
                                ]
                            ],
                        ]
                    ],
                ]
            ],
        ],
        'Comments'=>[
            'start'=>'comment',
            'input'=>"var=\"abc\"\n#I am a comment\nvarb=\"def\"",
            'expect'=>[
                "comments"=>[
                    0=>[
                        'type'=>'comment',
                        'src'=>'#I am a comment',
                        'description'=> "I am a comment",
                    ]
                ],
            ],
        ],
    ];

    public function testBashStuff(){
        $this->disable();
        foreach ($this->thingies as $description=>$test){
            $startingDirective=$test['start'];
            $inputString=$test['input']??file_get_contents($test['file']);
            $expect=$test['expect'];
            $this->test($description);
            if (!isset($this->options['run'])||$this->options['run']==$description){
                $output = $this->parse($inputString, $startingDirective);
                $this->compare($expect, $output);
            } else {
                echo "\n  '-run' specified for a different test";
            }
        }
    }

    public function testBashComment(){
        $this->disable();
        $description="I am a comment";
        $src = "#$description";
        $input = "var=\"abc\"\n$src\nvarb=\"def\"";
        $expect = [
            "comments"=>[
                0=>$description,
            ],
        ];

        $this->compare(
            $expect,
            $this->parse($input, "comment"),
        );
    }

    /**
     * Parse & test all tests listed in `$this->thingies[]`
     */
    public function testBashDirectives(){

        foreach ($this->thingies as $test_name=>$test_settings){
            if (isset($test_settings['input_file']))$this->thingies[$test_name]['input'] = file_get_contents($this->file($this->thingies[$test_name]['input_file']));
        }
        $bashGram = new \Tlf\Lexer\BashGrammar();
        $grammars = [
            $bashGram,
        ];
        // $docGram->buildDirectives();

        $this->runDirectiveTests($grammars, $this->thingies);
    }

    // protected function parse($stringInput, $startingDirective){
    //     $lexer = new \Tlf\Lexer();
    //     $lexer->debug = true;
    //     $bashGrammar=new \Tlf\Lexer\BashGrammar();
    //     $lexer->addGrammar($bashGrammar);
    //
    //     // print_r($bashGrammar->getDirectives(':comment')['comment']);
    //     // exit;
    //     //
    //     $startingDirectives = $bashGrammar->getDirectives(':comment');
    //     foreach ($startingDirectives as $se){
    //         $lexer->addDirective($se);
    //     }
    //
    //     $ast = $lexer->lexStr($stringInput);
    //
    //     $tree = $ast->getTree();
    //     unset($tree['type'], $tree['src']);
    //
    //     return $tree;
    // }
}
<?php

namespace Tlf\Lexer\Test;


class DocblockGrammar extends Tester {

    /**
     * @test bug where an attribute on a line with only whitespace after the attribute causes the program to stall
     */
    public function testBuildAstWithAttributesBug(){
        $lines = [
            '@one ',
            '@two okay',
        ];
        $db_grammar = new \Tlf\Lexer\DocblockGrammar();
        $ast = $db_grammar->buildAstWithAttributes($lines);
        $this->compare(
            array (
              'type' => 'docblock',
              'description' => '',
              'attribute' => 
              array (
                0 => 
                array (
                  'type' => 'attribute',
                  'name' => 'one',
                  'description' => '',
                ),
                1 => 
                array (
                  'type' => 'attribute',
                  'name' => 'two',
                  'description' => 'okay',
                ),
              ),
            ),
            $ast->getTree()
        );
        
    }

    public function testBuildAstWithAttributes(){
        $lines = [
            '@one good',
            '@two okay',
        ];
        $db_grammar = new \Tlf\Lexer\DocblockGrammar();
        $ast = $db_grammar->buildAstWithAttributes($lines);
        $this->compare(
            array (
              'type' => 'docblock',
              'description' => '',
              'attribute' => 
              array (
                0 => 
                array (
                  'type' => 'attribute',
                  'name' => 'one',
                  'description' => 'good',
                ),
                1 => 
                array (
                  'type' => 'attribute',
                  'name' => 'two',
                  'description' => 'okay',
                ),
              ),
            ),
            $ast->getTree()
        );
        
    }

    /**
     * Directives to test.
     *
     * See Tester clsas for details on how these are structured.
     */
    protected $thingies = [

        'Docblock.AttributeStalls'=>[
            'is_bad_test'=>'Good test: tests when a docblock contains an @attribute followed by whitespace on one line, then an @attribute on the next line, causing the program to stall & output nothing', 
            // 'ast.type'=>'class_body',
            'start'=>['/*'],
            'input'=>
                "/**\n* @one \n* @two okay \n*/",
            'expect.previous'=>[
                "docblock"=> [
                    'type'=>'docblock',
                    'description'=>"",
                    'attribute'=>[
                        0=>[
                            'type'=>'attribute',
                            'name'=>'one',
                            'description'=>'',
                        ],
                        1=>[
                            'type'=>'attribute',
                            'name'=>'two',
                            'description'=>'okay',
                        ],
                    ],
                ],
            ]

        ],
        'Docblock.Empty'=>[
            'start'=>['/*'],
            'input'=>"/**\n     *\n     */",
            'expect.previous'=>[
                "docblock"=>[
                    'type'=>'docblock',
                    'description'=>'',
                ]
            ]
        ],

        'Docblock.MultilineWithGaps'=>[
            'start'=>['/*'],
            'input'=>"/**\n *\n * first \n * \n * \n * second \n * \n * \n */",
            'expect.previous'=>[
                "docblock"=> [
                    'type'=>'docblock',
                    'description'=>"first \n\n\nsecond ",
                ],
            ],
        ],


        'Docblock.SameNameAttributes'=>[
            'start'=>['/*'],
            'input'=>"  /*\n* abc \n* @cat attr-describe\n  still describing def"
                    ."\n * \n*\n @cat (did) a thing\n*/",
            'expect.previous'=>[
                "docblock"=> [
                    'type'=>'docblock',
                    'description'=>" abc ",
                    'attribute'=>[
                        0=>[
                            'type'=>'attribute',
                            'name'=>'cat',
                            'description'=>"attr-describe\n still describing def",
                        ],
                        1=>[
                            'type'=>'attribute',
                            'name'=>'cat',
                            'description'=>"(did) a thing",
                        ],
                    ],
                ],
            ],
        ],

        'Docblock.TwoAttributes'=>[
            'start'=>['/*'],
            'input'=>"  /*\n* abc \n* @def attr-describe\n  still describing def"
                    ."\n * \n*\n @cat (did) a thing\n*/",
            'expect.previous'=>[
                "docblock"=> [
                    'type'=>'docblock',
                    'description'=>" abc ",
                    'attribute'=>[
                        0=>[
                            'type'=>'attribute',
                            'name'=>'def',
                            'description'=>"attr-describe\n still describing def",
                        ],
                        1=>[
                            'type'=>'attribute',
                            'name'=>'cat',
                            'description'=>"(did) a thing",
                        ],
                    ],
                ],
            ],
        ],

        'Docblock.WithAttribute'=>[
            'start'=>['/*'],
            'input'=>"  /*\n* abc \n* @def attr-describe\n  still describing def*/",
            'expect.previous'=>[
                "docblock"=> [
                    'type'=>'docblock',
                    'description'=>"abc ",
                    'attribute'=>[
                        0=>[
                            'type'=>'attribute',
                            'name'=>'def',
                            'description'=>"attr-describe\nstill describing def",
                        ],
                    ],
                ],
            ],
        ],
        'Docblock.VariedIndents'=>[
            'start'=>['/*'],
            'input'=>"  /*01\n  * abc \n    * def \n ghi*/",
            'expect.previous'=>[
                "docblock"=> [
                    'type'=>'docblock',
                    'description'=>"01\n   abc \n     def \nghi",
                ],
            ],
        ],

        'Docblock.IndentedLines'=>[
            'start'=>['/*'],
            'input'=>"  /* abc \n    * def \n*/",
            'expect.previous'=>[
                "docblock"=> [
                    'type'=>'docblock',
                    'description'=>"abc\ndef ",
                ],
            ],
        ],
        'Docblock.MultiLine2'=>[
            'start'=>['/*'],
            'input'=>"/*\n*\n*\n* abc \n* def \n*/",
            'expect.previous'=>[
                "docblock"=> [
                    'type'=>'docblock',
                    'description'=>"abc \ndef ",
                ],
            ],
        ],
        'Docblock.MultiLine'=>[
            'start'=>['/*'],
            'input'=>"/** abc \n* def */",
            'expect.previous'=>[
                "docblock"=> [
                    'type'=>'docblock',
                    'description'=>"abc\ndef ",
                ],
            ],
        ],
        'Docblock./**OneLine'=>[
            'start'=>['/*'],
            'input'=>"/** abc */",
            'expect.previous'=>[
                "docblock"=> [
                    'type'=>'docblock',
                    'description'=>'abc',
                ],
            ],
        ],
        'Docblock.OneLine'=>[
            'start'=>['/*'],
            'input'=>"/* abc */",
            'expect.previous'=>[
                "docblock"=> [
                    'type'=>'docblock',
                    'description'=>'abc',
                ],
            ],
        ],
    ];

    /**
     * Test a bunch of directives
     */ 
    public function testDocblockDirectives(){
        $docGram = new \Tlf\Lexer\DocblockGrammar();
        $grammars = [
            $docGram,
        ];
        // $docGram->buildDirectives();

        $this->runDirectiveTests($grammars, $this->thingies);
    }

}
<?php

namespace Tlf\Lexer\Test;


class PhpGrammar extends Tester {

    use Directives\Props;
    use Directives\Vars;
    use Directives\Args;
    use Directives\Methods;
    use Directives\Classes;
    use Directives\ClassIntegration;
    use Directives\Traits;
    use Directives\Namespaces;
    use Directives\UseTrait;
    use Directives\PhpOpenTags;
    use Directives\Consts;
    use Directives\Values;
    use Directives\Other;

    protected $directive_tests;

    public function prepare(){
        $this->directive_tests = array_merge(
            $this->_prop_tests, 
            $this->_arg_tests,
            $this->_namespace_tests,
            $this->_method_tests,
            $this->_class_tests,
            $this->_class_integration_tests,
            $this->_trait_tests,
            $this->_php_open_tags_tests,
            $this->_const_tests,
            $this->_use_trait_tests,
            $this->_values_tests,
            $this->_other_tests,
            $this->_var_tests,
        );
    }

    public function input_file($file){
        return $this->file('test/input/php/lex/').$file.'.php';
    }

    /**
     * Unit test individual directives from the `test/src/Php/*.php` files
     *
     * For a summary of the directives, run `phptest -test testShowMePhpFeatures`, then see `test/output/PhpFeatures.md`
     */
    public function testDirectives(){
        // i removed body from the ast ...
        // so this is probably making many fail

        $phpGram = new \Tlf\Lexer\PhpGrammar();
        $docblockGram = new \Tlf\Lexer\DocblockGrammar();
        $grammars = [
            $phpGram,
            $docblockGram,
        ];
        $phpGram->buildDirectives();


        $this->runDirectiveTests($grammars, $this->directive_tests);
    }


    public function testLilMigrationsBug(){
        // may 13, 2022
        // There is a bug with properties when there is an anonymous function with a `use` statement and there is a body to the function.
        // removing the use() statement OR removing the function body "fixes" it
        $this->assert_file('lildb/LilMigrationsBug', false, -1);
        // my solve was to capture the use statement, with the help of existing method_arglist instructions
    }

    public function testLilMigrations(){
        // see testLilMigrationsBug for more information why this is here.
        $this->assert_file('lildb/LilMigrations', false, -1);
    }

    public function testLilDb(){
        $this->assert_file('lildb/LilDb',false,-1);
    }
    public function testPhadFormsTest(){
        $this->assert_file('phad/FormsTest',false,);
    }

    public function testScrawlFnTemplate(){
        $this->assert_file('code-scrawl/functionListTemplate',false,);
    }

    /**
     * @todo clean this up and separate tests as needed. 
     * @todo fix counts that are failing
     */
    public function testMethodParseErrors(){
        $this->assert_file('MethodParseErrors',false);
    }

    public function testPhtmlNode(){
        // echo "The failure is comments. There are 31 comments, but its only finding 3 because body is not yet implemented";
        $this->assert_file('phtml/Node',false);
    }

    public function testPhtmlParser(){
        $this->assert_file('phtml/PHPParser',false);
    }

    public function testPhtml(){
        $this->assert_file('phtml/Phtml',false);
    }

    public function testPhtmlCompiler(){
        $this->assert_file('phtml/Compiler',false);
    }
    public function testPhtmlTextNode(){
        $this->assert_file('phtml/TextNode',false);
    }

    public function testSampleClass(){
        $this->assert_file('SampleClass', false);
    }


    /**
     * Get an ast tree from a file
     * @see assert_file()
     */
    public function parse_file($file, $debug, $stop_loop){
        $file = $this->input_file($file);
        $input = file_get_contents($file);


        $phpGram = new \Tlf\Lexer\PhpGrammar();
        $phpGram->directives = array_merge(
            $phpGram->_string_directives,
            $phpGram->_core_directives,
        );
        $lexer = new \Tlf\Lexer();
        $lexer->stop_loop = $stop_loop;
        $lexer->debug = $debug;
        $lexer->addGrammar($phpGram, null, false);
        $lexer->addDirective($phpGram->getDirectives(':php_open')['php_open']);

        $ast = new \Tlf\Lexer\Ast('file');
        $ast = $lexer->lex($input, $ast);

        $tree = $ast->getTree();

        return $tree;
    }
    /**
     * @param $file the file inside test/output/php/tree
     * @param $tree the ast to write to disk
     */
    public function output_tree(string $file, array $tree){
        $out = $this->file('test/output/php/tree/').$file;
        $json = json_encode($tree, JSON_PRETTY_PRINT);
        $tree_print = print_r($tree,true);

        $dir = dirname($out);
        if (!is_dir($dir))mkdir($dir, 0754, true);

        // i like the highlighting better when i make it .js
        file_put_contents($out.'.printr.js', $tree_print);
        file_put_contents($out.'.js', $json);
    }

    /**
     * get the expected counts from `test/php/counts/$file.json`
     */
    public function get_counts($file){
        $expect_file = $this->file('test/input/php/counts/').$file.'.json';
        if (!file_exists($expect_file))return;
        $expect = json_decode(file_get_contents($expect_file),true);
        return $expect;
    }

    /**
     * Assert that the ast tree contains the given counts of items
     */
    public function assert_counts(array $ast_tree, array $target_counts){
        $actual_counts = $this->get_tree_counts($ast_tree, []);
        foreach ($target_counts as $key=>$count){
            $this->test($key.' counts');
            $this->compare($count, $actual_counts[$key]??0);
        }

        echo "\n\nTarget Counts:\n";
        print_r($target_counts);
        echo "\nActual Counts:\n";
        print_r($actual_counts);
    }

    /**
     *
     * Run tests on the given file. (currently just tree counts)
     *
     * 1. Parses the input file into an ast tree
     * 2. Loads InputFile.expect.js, which contains things like the expected number of consts, methods, and comments
     * 3. Compares the output ast against the expected counts
     * 4. Writes the ast tree to `test/input/php/tree/{$file}.js` & `.../{$file.printr.js}`
     *    - this is just for visual verification (i think)
     *    - this should be changed to the output dir
     * 
     * @param $file a relative path to a file in `test/input/php/lex/`
     * @param $debug true/false to enable debugging
     * @param $stop_loop -1 never to stop or an integer to stop at the given loop
     *
     */
    public function assert_file($file, bool $debug=true, int $stop_loop = -1){
        echo "\nParse $file\n";

        $tree = $this->parse_file($file,$debug,$stop_loop);

        $this->output_tree($file, $tree);

        $counts = $this->get_counts($file);

        unset($counts['--comment']);
        $this->assert_counts($tree, $counts);

    }



    /**
     * This is not really a test. 
     * 
     * It writes file `test/output/PhpFeatures.md` showing a synopsis of which directives passed / failed & what their input was
     *
     * The output is like:
     *  -FailedTestname: input string that was lexed
     *  +PassedTestName: input string that was lexed
     */
    public function testShowMePhpFeatures(){
        $this->disable();

        ob_start();
        $phpGram = new \Tlf\Lexer\PhpGrammar();
        $docblockGram = new \Tlf\Lexer\DocblockGrammar();
        $grammars = [
            $phpGram,
            $docblockGram,
        ];
        $phpGram->buildDirectives();

        $test_results = $this->runDirectiveTests($grammars, $this->directive_tests);
        ob_end_clean();

        $fh = fopen($this->file('test/output/PhpFeatures.md'),'w');
        foreach ($this->directive_tests as $name=>$test){
            $status = 'fail';
            $s = '-';
            if ($test_results[$name]){
                $s = '+';
                $status = 'pass';
            }
            $str = "\n$s$name: ".$test['input'];
            echo $str;
            $str = "\n- $s$name($status): `".$test['input'].'`';
            fwrite($fh, $str);
        }
        fclose($fh);
    }


    /**
     * test an individual file (or all files in a directory) as needed
     *
     * @usage `phptest -test RunFile -file NameOfFileOrDir` where the file (or dir) must be within `test/input/php/lex/`
     */
    public function testRunFile(){
        $file = $this->options['file'] ?? '';
        if ($file==''){
            echo "To use this: phptest -test RunFile -file NameOfFileOrDir";
            $this->disable();
            return;
        }
        $path = $this->input_file($filek);
        if (is_file($path)){
            // echo 'zeep';
            // exit;
            $this->assert_file(substr($file,0,-4), false);
        } else {
            foreach (scandir($path) as $sub_file){
                if (substr($sub_file,-4)!='.php')continue;
                var_dump($file.'/'.$sub_file);
                exit;
                $this->assert_file(substr($file.'/'.$sub_file));
            }
        }


        return;
        if (isset($this->options['file'])){
            $file = $this->options['file'];
            var_dump($file);
            exit;
        }
    }


    /**
     * Test the test function
     */
    public function testGetTreeCounts(){
        $counts = [
            'class'=>3,
            'methods'=>3,
            'name'=>2,
            'namespace'=>1,
            'declaration'=>3,
            'type'=>4,
        ];
        $tree = [
            'namespace'=>[
                'type'=>'namespace',
                'class'=>[
                    0=>[
                        'name'=>'SomeClass',
                        'methods'=>[
                            0=>[
                                'type'=>'method',
                                'declaration'=>'function(){}',
                            ],
                            1=>[
                                'type'=>'method',
                                'declaration'=>'function(){}',
                            ],
                        ]
                    ],
                    1=>[
                        'name'=>'SomeClass2',
                        'methods'=>[
                            0=>[
                                'type'=>'method',
                                'declaration'=>'function(){}',
                            ],
                        ]
                    ],
                ],
            ],
        ];
        $final = $this->get_tree_counts($tree, []);
        print_r($final);
        $this->compare(
            $final,
            [
                'namespace'=>1,
                'type'=>4,
                'class'=>2,
                'name'=>2,
                'methods'=>3,
                'declaration'=>3
            ],
        );
    }

    /**
     * get an array of counts across an entire array.
     * Each key increases by one when it is found,
     * except when the value is an array containing numeric indices,
     * then the count[key] increases by count(value)
     * @return the counts
     */
    public function get_tree_counts($array, $counts){
        
        // every time i encounter a string key:
        // if the value is an array with numeric indices,
            // increase the count[key] by count(array value)
            // visit each child
        // if the value is an array with string keys, 
            // increase count[key] by 1
            // visit each child
        // if the value is not an array
            // increase count[key] by 1
        foreach ($array as $key=>$value){
            if (!isset($counts[$key]))$counts[$key] = 0;
            if (is_array($value)&&$this->has_numeric_indices($value)){
                $counts[$key] += count($value);
                $counts = $this->get_tree_counts($value, $counts);
            } else if (is_array($value)){
                $counts[$key] += 1;
                $counts = $this->get_tree_counts($value, $counts);
            } else {
                $counts[$key] += 1;
            }
            if (is_int($key))unset($counts[$key]);
        }

        return $counts;
    }

    /**
     * @return true if all the array's keys are numeric, false otherwise
     */
    public function has_numeric_indices(array $array): bool{
        $keys = array_keys($array);
        $keys = implode('',$keys);
        if (is_numeric($keys))return true;
        return false;
    }
}
<?php

namespace Tlf\Lexer\Test\Debug;


class PhpGrammar extends \Tlf\Lexer\Test\Tester {



    public function testMethodBodyIsString(){
        echo "This test is disabled because I'm currently not implementing the body capture ... it was a mess & that's a whole heck of an issue to figure out.";
        // this test probably belongs in debug()
        $this->disable();
        // this involves the test/input/php/lex/code-scrawl/IntegrationTest.php file 
        // which keeps showing ast objects in the output
        // where there should be a body string
        //
        return;


        $lexer = new \Tlf\Lexer();

        $abs_path = $this->file('test/input/php/lex/code-scrawl/IntegrationTest.php');
        
        $phpGram = new \Tlf\Lexer\PhpGrammar();
        $lexer = new \Tlf\Lexer();
        $lexer->useCache = false;
        $lexer->debug = false;
        $lexer->addGrammar($phpGram);

        // the first directive we're listening for
        $lexer->addDirective($phpGram->getDirectives(':php_open')['php_open']);


        // ob_start();
        // runs the lexer with $ast as the head
        $ast = $lexer->lexFile($abs_path);
        // ob_end_clean();

        // echo 'oh';
        // exit;

        print_r($ast->getTree());
        // exit;

    }

    /**
     * A block nested within a method caused the next method declaration to be incorect, so test all methods are correctly parsed in code-scrawl/Scraw2.php 
     */
    public function testScrawl2(){
        // See Issue 1, Scrawl2

        $ast = $this->get_ast('code-scrawl/Scrawl2.php');
        $methods = $this->get_ast_methods($ast);

        $target = [
            '__construct' => 'public function __construct(array $options=[])',
            'get_template' => 'public function get_template(string $name, array $args)',
            'process_str' => 'public function process_str(string $string, string $file_ext)',
            'addExtension' => 'public function addExtension(object $ext)',
            'get' => 'public function get(string $group, string $key)',
            'get_group' => 'public function get_group(string $group)',
            'set' => 'public function set(string $group, string $key, $value)',
            'parse_str' => 'public function parse_str($str, $ext)',
            'write_doc' => 'public function write_doc(string $rel_path, string $content)',
            'read_file' => 'public function read_file(string $rel_path)',
            'report' => 'public function report(string $msg)',
            'warn' => 'public function warn($header, $message)',
            'good' => 'public function good($header, $message)',
            'prepare_md_content' => 'public function prepare_md_content(string $markdown)',
        ];

        $this->compare_arrays($target,
            $methods['Tlf\\Scrawl2']
        );
    }


    /**
     *
     * Get the ast of a file in `test/input/php/lex/`
     *
     * @param $file relative path inside `test/input/php/lex/`
     * @param $debug true/false
     * @param $stop_loop loop to stop on. `-1` to not stop
     * @return an array ast 
     */
    public function get_ast($file, $debug=true, $stop_loop=-1): array{
        $in = $this->file('test/input/php/lex/');
        // $out = $this->file('test/input/php/tree/');
        $input = file_get_contents($in.$file);

        $phpGram = new \Tlf\Lexer\PhpGrammar();
        $phpGram->directives = array_merge(
            $phpGram->_string_directives,
            $phpGram->_core_directives,
        );
        $lexer = new \Tlf\Lexer();
        $lexer->stop_loop = $stop_loop;
        $lexer->debug = $debug;
        $lexer->addGrammar($phpGram, null, false);
        $lexer->addDirective($phpGram->getDirectives(':php_open')['php_open']);

        $ast = new \Tlf\Lexer\Ast('file');
        $ast = $lexer->lex($input, $ast);

        $tree = $ast->getTree();

        return $tree;
    }

    /**
     * Get the method names & declaration from an class ast
     *
     * @return `key=>value` array of `class_name=>[method_name=>method_declaration, m2=>declaration]`
     */
    public function get_ast_methods(array $ast): array{
        $all = [];
        $classes = array_merge($ast['class'] ?? [], $ast['namespace']['class'] ?? []);
        
        foreach ($classes as $c){

            foreach ($c['methods'] as $m){
                $all[$c['fqn']][$m['name']] = $m['declaration'];
            }
        }

        return $all;
    }

}
<?php

namespace Tlf\Lexer\Test\Document;


class Idk extends \Tlf\Lexer\Test\Tester {

    public function testLexPhp(){
        //@export_start(Test.Doc.LexPhpString)

        // initialize lexer & grammar
        $lexer = new \Tlf\Lexer();
        $phpGrammar = new \Tlf\Lexer\PhpGrammar();
        $lexer->addGrammar($phpGrammar);

        // Add starting directive to the lexer
        $starting_directives = $phpGrammar->getDirectives(':php_open');
        // there's only one... i don't know why it's like this...
        $lexer->addDirective($starting_directives['php_open']);

        // typically, either "file" or "str"
        $starting_ast = new \Tlf\Lexer\Ast($ast_type="file", $initial_tree=[]);

        // read a file & generate an ast. May load from cache.
        $file = $this->file('test/input/php/DocumentationExample.php');
        $ast = $lexer->lexFile($file);

        // or you can lex a string, but then you don't get caching 
        //$string = file_get_contents($this->file('test/input/php/DocumentationExample.php'));
        //$ast = $lexer->lex($string, $ast)

        // convert ast to array
        $tree = $ast->getTree();
        //@export_end(Test.Doc.LexPhpString)
        
        $this->compare($tree, require($this->file('test/input/php/DocumentationExampleTree.php')));
    }

    public function testLexString(){
        //@export_start(Test.Doc.LexString)
        $lexer = new \Tlf\Lexer();
        $docGrammar = new \Tlf\Lexer\DocblockGrammar();
        $lexer->addGrammar($docGrammar);
        $lexer->addDirective($docGrammar->getDirectives(':/*')['/*']);
        $str = "/** I am docblock */";
        $ast = $lexer->lex($str);

        $tree = $ast->getTree();
        $actual = $tree['docblock'][0];
        $expect = [
            'type'=>'docblock',
            'description'=>'I am docblock',
        ];
        //@export_end(Test.Doc.LexString)

        $this->compare($expect, $actual);
        
        $this->compare($ast->src, $str);
    }

    public function testLexAst(){

        echo "Uses old php grammar";
        $this->disable();
        return;


        //@export_start(Test.Doc.LexAst)
        $lexer = new \Tlf\Lexer();
        $phpGrammar = new \Tlf\Lexer\PhpGrammar();
        $lexer->addGrammar($phpGrammar);

        // set up the ast
        $ast = new \Tlf\Lexer\Ast('code');
        $ast->set ('language', 'php');
        $code = '<?php class Abc extends Alphabet {}';
        $ast->set('src', $code);


        $ast = $lexer->lex($code, $ast);
        $actual = $ast->getTree();
        $expect = [
            'type'=>'code',
            'language'=>'php',
            'src'=>$code,
            'class'=>[
                0=>[
                    'type'=>'class',
                    'docblock'=>'',
                    'namespace'=>'',
                    'name'=>'Abc',
                    'declaration'=>'class Abc extends Alphabet ',
                ],
            ],
        ];
        //@export_end(Test.Doc.LexAst)

        $this->compare($actual, $expect);
        $this->compare($ast->src, $code);
    }

    public function testLexFile(){

        echo "Uses old php grammar";
        $this->disable();
        return;

        $dir = dirname(__DIR__).'/php/';
        $file = $dir.'SampleClass.php';
        $targetTree = include($dir.'SampleClass.tree.php');

        //@export_start(Test.Doc.LexFile)
        $lexer = new \Tlf\Lexer();
        $lexer->useCache = false; // cache is disabled only for testing
        $lexer->addGrammar($phpGrammar = new \Tlf\Lexer\PhpGrammar());

        $ast = $lexer->lexFile(dirname(__DIR__).'/php/SampleClass.php');

        // An array detailing the file 
        $tree = $ast->getTree(); 
        //@export_end(Test.Doc.LexFile)

        $this->compare(
            $targetTree, 
            $tree
        );
    }

}
<?php

namespace Tlf\Lexer\Test\Document;

/**
 * This class is for writing documentation as code
 * So tests should be extremely clean & not seek to be unit tests, but seek to confirm broad functionality
 */
class PhpGrammar extends \Tlf\Lexer\Test\Tester {

    /**
     * Just an example of how to run the php grammar
     */
    public function testVerbose(){

        
        $input = 'const blm = "yes";';

        // php grammar uses the type of the head ast.
        $ast = new \Tlf\Lexer\Ast('class_body');

        $phpGram = new \Tlf\Lexer\PhpGrammar();
        $phpGram->directives = array_merge(
            $phpGram->_string_directives,
            $phpGram->_core_directives,
        );
        $lexer = new \Tlf\Lexer();
        $lexer->debug = true;
        // pass `true` instead of `false` to call `onGrammarAdded()`, which would prepare $phpGram->directives
        $lexer->addGrammar($phpGram, null, false);

        // adds directives to the top of the stack
        foreach ($phpGram->getDirectives(':php_code') as $directive){
            $lexer->addDirective($directive);
        }
        // alternate starting directive, if you're expecting a php open tag before php code
        // $lexer->addDirective($phpGram->getDirectives(':php_open')['php_open']);

        // runs the lexer with $ast as the head
        $ast = $lexer->lex($input, $ast);
        $tree = $ast->getTree();

        $expect = 
        [
            'type'=>'class_body',
            'const'=>[
                0=>[
                    'type'=>'const',
                    'name'=>'blm',
                    'value'=>'"yes"',
                    'declaration'=>'const blm = "yes";',
                ],
            ]
        ];
        $this->compare($expect,
            $tree
        );
    }
}
<?php

namespace Tlf\Lexer\Test\Main;

/**
 * For developing a new programming interface, possibly just a wrapper for the Lexer.
 */
class Api extends \Tlf\Tester {

    public function testMain(){
        $this->disable();
        // Lexer2 is being used in the cli
        return;
        $lexer = new \Tlf\Lexer2();
        // $lexer->enable_debugging($line_number_to_stop_on);
        $ast = $lexer->getAstFromFile('');
    }

}


<?php

namespace Tlf\Lexer\Test\Main;

/*
 * Test features of the grammar class, not lexing, and not any language-specific grammars
 */
class Grammar extends \Tlf\Tester {

    protected $grammar;

    public function prepare(){
        $this->grammar = new \Tlf\Lexer\Grammar();
    }


    /**
     * @test `$grammar->getDirectives($name, $overrides)`
     */
    public function testGetDirectives(){
        $grammar = new \Tlf\Lexer\Grammar();
        $grammar->directives = $this->getSourceDirectives();
        foreach ($this->getDirectivesToLookup() as $testName=>$pieces){
            if ($testName!='Is Directive'){
                //var_dump("")
                //exit;
                //@todo REMOVE THIS continue
                continue;
            }
            $this->test($testName);
            $lookupName = $pieces[0];
            $overrides = $pieces[1];
            $expectedList = $pieces[2];

            $actualList = $grammar->getDirectives($lookupName, $overrides);

            foreach ($actualList as $name=>$d){
                unset($d->_name);
                unset($d->_grammar);
                $actualList[$name] = (array)$d;
            }

            $this->compare($expectedList, $actualList);
        }
    }

    /**
     * Test grammar->normalizeDirective();
     * @test directive `:bear` normalizes to `:bear => []`
     * @test `:bear ...` normalizes to to `:bear => []`
     * @test `:dog=>['override']` is unchanged by normalization
     *
     * Rules:
     * @rule `"cmd var"` normalizes to `":cmd var" => []`
     * @rule `"cmd var" => []` does not change
     *
     */
    public function testDirectiveNormalization(){
        foreach ($this->getNormalizeDirectives() as $name=>$comparators){
            $this->test($name);
            $directive = $comparators[0];
            $expect = $comparators[1];
            $normal = $this->grammar->normalizeDirective($directive);
            $this->is_object($normal);
            $this->compare($expect, (array)$normal);
        }
    }


    /**
     * Test that an `is` directive expands into an array of the directives it names
     *
     * @test `is => [ ":target1", ":target2", ":target3" ]` expands into `[ $target1, $target2, $target3 ]` where `$target1` is a directive, possibly containing starts & stops
     */
    public function testExpandIsDirective(){
        $grammar = new \Tlf\Lexer\Grammar();
        $dRoot = $grammar->directives = $this->getSourceDirectives();
        
        $sourceDirective = (object)$grammar->directives['is_directive'];
        $sourceDirective->_name = 'is_directive';
        $sourceDirective->_grammar = 'grammar';
        $directiveList = $grammar->expandDirectiveWithIs($sourceDirective);

        foreach ($directiveList as $directiveName=>$directive){
            unset($directive->_name);
            unset($directive->_grammar);
            $directiveList[$directiveName] = (array)$directive;
        }

        $this->compare(
            [
                'is_target'=>$dRoot['is_target'],
                'is_target_2'=>$dRoot['is_target_2'],
                'is_target_3'=>$dRoot['is_target_3'],
            ],
            $directiveList
        );
    }

    /**
     * Rules:
     * @rule source + override = override, source 
     * @rule source[key] + override[key] = override[key]
     * @rule source[key //] + override[key] = override[key], source[key //]
     *
     *
     * @test `:source=>[]` overridden by `:override=>[]` yields `:override=>[], :source=>[]`
     * @test that `then :cat, match uhoh` overridden by `match // => abc, hide` yields `match //=>abc, hide, then :cat, match uhoh`
     * @test `then :cat` overridden by `hide nothing, match abc` yields `hide nothing, match abc, then :cat`
     * @test `match abc, then :cat` overriden by `hide nothing` yields `match, hide, then` (match goes first)
     * @test `match abc, then cats` overridden by `match dog, rewind 1` yields `match dog, rewind 1, then cats`
     */
    public function testDirectiveOverrides(){
    
        foreach ($this->getOverrideDirectives() as $testName=>$pieces){
            $source = (object)$pieces[0];
            $overrides = (object)$pieces[1];
            $expect = $pieces[2];
            $actual = $this->grammar->getOverriddenDirective($overrides, $source);
            $this->is_object($actual);
            $this->test($testName);
            $this->compare($expect, (array)$actual,true);
        }
    }



    /**
     *
     * @return multi dimensional array
     * @array.key is the thing being tested
     * @array.child is an array with 3 child arrays
     * @array.child.index1 is the name of the directive to load
     * @array.child.index2 is the the overrides
     * @array.child.index3 is the expected directive list to be returned
     */
    public function getDirectivesToLookup(){

        return [
            'Empty Directive'=>[
                ':empty_directive',
                [],
                ['empty_directive'=>[]],
            ],
            'Is Directive'=>[
                ':is_directive',
                [],
                [
                    'is_target'=>[
                        'stop'=>[
                            'match'=>['/is/'],
                        ],
                    ],
                    'is_target_2'=>[
                        'stop'=>[
                            'match'=>['/is_2/'],
                        ],
                    ],
                    'is_target_3'=>[
                        'stop'=>[
                            'match'=>['/is_3/'],
                        ],
                    ],
                ],
            ],
        ];
    }

    public function getSourceDirectives(){
        return [
            'empty_directive'=>[
            ],
            'is_directive'=>[
                'is'=>[
                    ':is_target'=>[],
                    ':is_target_2'=>[],
                    ':is_target_3'=>[],
                ],
            ],
            'is_target'=>[
                'stop'=>[
                    'match'=>['/is/'],
                ],
            ],
            'is_target_2'=>[
                'stop'=>[
                    'match'=>['/is_2/'],
                ],
            ],
            'is_target_3'=>[
                'stop'=>[
                    'match'=>['/is_3/'],
                ],
            ],
        ];
    }




    /**
     *
     * @return multi dimensional array
     * @array.key is the thing being tested
     * @array.child is an array with 3 child arrays
     * @array.child.index1 is the source/root directive
     * @array.child.index2 is the overrides
     * @array.child.index3 is the expected result
     *
     */
    public function getOverrideDirectives(){
        return [
            'Is overrides'=>[
                [
                    'is'=>[
                        ':source'=>[],
                    ],
                ],
                [
                    'is'=>[
                        ':override'=>[],
                    ],
                ],
                [
                    'is'=>[
                        ':override'=>[],
                        ':source'=>[],
                    ],
                ],
            ],
            'Source match is second'=>[


                [
                    'start'=>[
                        'then'=>[':cat'],
                        'match'=>['uhoh'],
                    ],
                ],
                [
                    'start'=>[
                        'match //'=>['abc'],
                        'hide'=>['nothing'],
                    ],
                ],
                [
                    'start'=>[
                        'match //'=>['abc'],
                        'hide'=>['nothing'],
                        'then'=>[':cat'],
                        'match'=>['uhoh'],
                    ]
                ],
            ],

            'Source nomatch' => [
                [
                    'start'=>[
                        'then'=>[':cat'],
                    ],
                ],
                [
                    'start'=>[
                        'hide'=>['nothing'],
                        'match'=>['abc'],
                    ],
                ],
                [
                    'start'=>[
                        'hide'=>['nothing'],
                        'match'=>['abc'],
                        'then'=>[':cat'],
                    ]
                ],
            ],

            'Source match, then overrides, then other source instructions'=>[
                [
                    'start'=>[
                        'match'=>['abc'],
                        'then'=>[':cat'],
                    ],
                ],
                [
                    'start'=>[
                        'hide'=>['nothing'],
                    ],
                ],
                [
                    'start'=>[
                        'match'=>['abc'],
                        'hide'=>['nothing'],
                        'then'=>[':cat'],
                    ]
                ],
            ],

            'Direct Key Overrides'=>[
                [
                    'stop'=>[
                        'match'=> ['abc'],
                        'then'=> ['cats'],
                    ]
                ],
                [
                    'stop'=>[
                        'match'=> ['dog'],
                        'rewind'=>1,
                    ]
                ],
                [
                    'stop'=>[
                        'match'=>['dog'],
                        'rewind'=>1,
                        'then'=>['cats'],
                    ],
                ],
            ]

        ];
    }


    /**
     *
     * Get directives as they would be defined & those same directives as they would be after normaliztion
     *
     * @test 
     * @return multi dimensional array
     * @child.index1 is the input directive, as one would define it
     * @child.index2 is the expected output directive, as returned from the normalize method
     */
    public function getNormalizeDirectives(){
        return [
            'Stop'=>[
                [
                    'stop'=>[
                        'then :cat',
                        'then :dog'=>['override'],
                        'then :bear ...',
                    ],
                ],
                [
                    'stop'=>[
                        'then :cat'=>[],
                        'then :dog'=>['override'],
                        'then :bear ...'=>[],
                    ],
                ],
            ],
            'Is'=>[
                [
                    //input
                    'is'=>[
                        ':cat',
                        ':dog'=>['override'],
                        ':bear',
                    ],
                ],
                [
                    //normalized
                    'is'=>[
                        ':cat'=>[],
                        ':dog'=>['override'],
                        ':bear'=>[],
                    ],
                ],
            ],
        ];
    }


    ////////////////////
    //
    ///// abandoned test code that i might return to eventually
    //
    ////////////////////


    /** I wrote this for thinking purposes, and I will probably use it for some testing maybe????
     * Might be able to delete it.
     */
    protected $sampleDirectiveList = [
            'grp'=>[
                'stop'=>[
                    //overrides target.stop.rewind & target_2.stop.rewind
                    'rewind'=>1
                ],
                'is'=>[
                    ':target'=>[
                        //overrides grp.stop.rewind & target.stop.rewind
                        'rewind'=>2,
                    ],
                    ':target_2'=>[],
                ]
            ],
            'target'=>[
                'stop'=>[
                    'match'=>'abc',
                    // overrides nothing
                    'rewind'=>3,
                ]
            ],
            'parent'=>[
                'stop'=>[
                    'then :grp'=>[
                        //highest priority. This always overrides whatever its loading
                        'rewind'=>4
                    ],
                ]
            ],

            'target_2'=>[],
        ];





    /**
     * Test that is directives accept overrides 
     * The functionality exists, i think, but the test is not implemented
     */
    public function testExpandIsDirectiveWithOverrides(){
        $this->disable();
        echo "\n\n";
            
            echo "This test is disabled because I haven't actually implemented it yet. Its currently a copy+paste from testExpandIsDirective() (no overrides) ";

        echo "\n\n";

        return false;
        $grammar = new \Tlf\Lexer\Grammar();
        $dRoot = $grammar->directives = $this->getSourceDirectives();
        
        $sourceDirective = (object)$grammar->directives['is_directive'];
        $sourceDirective->_name = 'is_directive';
        $sourceDirective->_grammar = 'grammar';
        $directiveList = $grammar->expandDirectiveWithIs($sourceDirective);


        foreach ($directiveList as $directiveName=>$directive){
            unset($directive->_name);
            unset($directive->_grammar);
            $directiveList[$directiveName] = (array)$directive;
        }

        $this->compare(
            [
                'is_target'=>$dRoot['is_target'],
                'is_target_2'=>$dRoot['is_target_2'],
                'is_target_3'=>$dRoot['is_target_3'],
            ],
            $directiveList
        );
    }
}
<?php

namespace Tlf\Lexer\Test;

/**
 * Tests otherwise unsorted
 */
class Main extends \Tlf\Tester {

    public function testTrimTrailingWhitespace(){
        $str = "abc   \ndef  \nokay ";
        $clean = \Tlf\Lexer\Utility::trim_trailing_whitespace($str);

        $this->compare(
            "abc\ndef\nokay",
            $clean
        );
    }
}
<?php

namespace Tlf\Lexer\Test\Main;

/**
 * Just a simple test with a simple grammar to make sure the lexer works
 */
class StarterGrammar extends \Tlf\Lexer\Test\Tester {

    public function testStarterGrammar(){
        //@---export_start(Test.Doc.LexString)
        $lexer = new \Tlf\Lexer();
        $lexer->debug = true;

        $starterGrammar = new \Tlf\Lexer\Test\Src\StarterGrammar();
        $lexer->addGrammar($starterGrammar);
        $str = "(a, b, c) (d, e,f)";
        $ast = $lexer->lex($str);

        $tree = $ast->getTree();
        $actual = $tree['argsets'];
        $expect = [
            [
                'type'=>'arglist',
                'args'=>['a','b','c'],
            ],
            [
                'type'=>'arglist',
                'args'=>['d','e','f'],
            ],
        ];
        //@---export_end(Test.Doc.LexString)

        $this->compare($expect, $actual);
        
        $this->compare($ast->src, $str);
    }
}
<?php

namespace Tlf\Lexer\Test\Translate;

/**
 * Tests output ASTs as code
 */
class Translate extends \Tlf\Tester {

    public function testOutputSampleClass(){
        $this->disable();

        $path = $this->file('test/output/php/tree/SampleClass.js');
        $data = json_decode(file_get_contents($path), true);
        $class_data = $data['namespace']['class'][0];
        var_dump($class_data);
        $ast = new \Tlf\Lexer\Ast\ClassAst('class', $class_data);


        $php = $ast->getCode('php');

        echo "\n\n\n\n------###### PHP #####\n$php\n--------------------\n\n\n\n";

        $js = $ast->getCode('javascript');

        echo "\n\n\n\n------###### JAVASCRIPT #####\n$js\n--------------------\n\n\n\n";

        //exit;

    }


    public function testOutputPhpAndJs(){

        $this->disable();


        $property_source = 'protected $giraffe = "Bob";';
        $property_ast = [
            'type'=>'property',
            'name'=>'giraffe',
            'modifiers' => ['protected'],
            'docblock'=> [
                'type'=>'docblock',
                'description' => 'Why would you name a giraffe Bob?',
            ],

            'value'=> "Bob",
        ];

        $class_ast = [
            'type'=>'class',
            'fqn'=> 'Sample',
            'namespace' => '',
            'name'=>'Sample',
            'extends' => 'cats',
            'methods' => [],
            'properties'=> [$property_ast],
            'const'=>[],
        ];

        $ast = new \Tlf\Lexer\Ast\ClassAst('class',$class_ast);

        $php = $ast->getCode('php');

        echo "\n\n\n\n------###### PHP #####\n$php\n--------------------\n\n\n\n";

        $js = $ast->getCode('javascript');

        echo "\n\n\n\n------###### JAVASCRIPT #####\n$js\n--------------------\n\n\n\n";

        //exit;

    }
}
<?php

namespace Tlf\Lexer\Test\Directives;

trait Args {
    protected $_arg_tests = [
        'Arg.Assign.Concat.BeforeComma'=>[
            'ast.type'=>'method_arglist',
            'start'=>['php_code'],
            'input'=>' $global_warming = "angers"."me"."greatly", int $okay)',
            'expect'=>[
                'value'=>[
                    0=>[
                        'type'=>'arg',
                        'name'=>'global_warming',
                        'declaration'=>'$global_warming = "angers"."me"."greatly"',
                        'value'=> '"angers"."me"."greatly"',
                    ],
                    1=>[
                        'type'=>'arg',
                        'arg_types'=>['int'],
                        'name'=>'okay',
                        'declaration'=>'int $okay',
                    ]
                ],
            ],
        ],
        'Arg.Assign.Concat'=>[
            'ast.type'=>'method_arglist',
            'start'=>['php_code'],
            'input'=>' $global_warming = "angers"."me"."greatly")',
            'expect'=>[
                'value'=>[
                    0=>[
                        'type'=>'arg',
                        'name'=>'global_warming',
                        'declaration'=>'$global_warming = "angers"."me"."greatly"',
                        'value'=> '"angers"."me"."greatly"',
                    ],
                ],
            ],
        ],
        'Arg.Two'=>[
            'ast.type'=>'method_arglist',
            'start'=>['php_code'],
            'input'=>' string $blm = "abc", bool $dog = true )',
            'expect'=>[
                'value'=>[
                    0=>[
                        'type'=>'arg',
                        'arg_types'=>['string'],
                        'name'=>'blm',
                        'declaration'=>'string $blm = "abc"',
                        'value'=>'"abc"',
                    ],
                    1=>[
                        'type'=>'arg',
                        'arg_types'=>['bool'],
                        'name'=>'dog',
                        'declaration'=>'bool $dog = true',
                        'value'=>'true',
                    ],
                ],
            ],
        ],
        'Arg.Assign'=>[
            'ast.type'=>'method_arglist',
            'start'=>['php_code'],
            'input'=>' string $blm = "abc" )',
            'expect'=>[
                'value'=>[
                    0=>[
                        'type'=>'arg',
                        'arg_types'=>['string'],
                        'name'=>'blm',
                        'declaration'=>'string $blm = "abc"',
                        'value'=>'"abc"',
                    ],
                ],
            ],
        ],

        'Arg.Typed'=>[
            'ast.type'=>'method_arglist',
            'start'=>['php_code'],
            'input'=>' string $blm )',
            'expect'=>[
                'value'=>[
                    0=>[
                        'type'=>'arg',
                        'arg_types'=>['string'],
                        'name'=>'blm',
                        'declaration'=>'string $blm',
                    ],
                ],
            ],
        ],

        'Arg.Simple'=>[
            'ast.type'=>'method_arglist',
            'start'=>['php_code'],
            'input'=>'$blm)',
            'expect'=>[
                'value'=>[
                    0=>[
                        'type'=>'arg',
                        'name'=>'blm',
                        'declaration'=>'$blm',
                    ],
                ],
            ],
        ],
    ];
}
<?php

namespace Tlf\Lexer\Test\Directives;

trait ClassIntegration {

    protected $_class_integration_tests = [

        'Integration.Class.Methods.WithNestedBlock'=>[
            'is_bad_test'=>'This test validates that we can handle nested blocks without messing up the ASTs.',
            'ast.type'=>'namespace',
            'start'=>['php_code'],
            'input'=>
                <<<PHP
                    class A {
                        public function is_the_us_imperialist():bool {
                            if (\$you_buy_into_imperialist_propaganda){
                                if (true){
                                    return false;
                                }
                            } 
                            return true;
                        } 
                        public function is_the_us_nice():bool {
                            if (\$you_are_rich){
                                if (true){
                                    return true;
                                }
                            } 
                            return false;
                        } 
                    } //
                PHP,
            'expect'=>[
                'class'=>[
                    0=>[
                        'type'=>'class',
                        'fqn'=>'A',
                        'namespace'=>'',
                        'name'=>'A',
                        'declaration'=>'class A',
                        'methods'=>[
                            0=>[
                                'type'=>'method',
                                'args'=>[],
                                'modifiers'=>['public'],
                                'name'=>'is_the_us_imperialist',
                                'return_types'=>['bool'],
                                'body'=>
                                    "if (\$you_buy_into_imperialist_propaganda){"
                                   ."\n    if (true){"
                                   ."\n        return false;"
                                   ."\n    }"
                                   ."\n}" 
                                   ."\nreturn true;",
                                'declaration'=>'public function is_the_us_imperialist():bool',
                            ],
                            1=>[
                                'type'=>'method',
                                'args'=>[],
                                'modifiers'=>['public'],
                                'name'=>'is_the_us_nice',
                                'return_types'=>['bool'],
                                'body'=>
                                    "if (\$you_are_rich){"
                                   ."\n    if (true){"
                                   ."\n        return true;"
                                   ."\n    }"
                                   ."\n}" 
                                   ."\nreturn false;",
                                'declaration'=>'public function is_the_us_nice():bool',
                            ],
                        ],
                    ]
                ]
            ],
        ],

        'Integration.Class.Final.Method'=>[
            'ast.type'=>'namespace',
            'start'=>['php_code'],
            'input'=>"final class Abc {\n"
                    ."    public function abc() {"
                    ."    }"
                    ."}",
            'expect'=>[
                'class'=>[
                    0=>[
                    'type'=>'class',
                    'fqn'=>'Abc',
                    'namespace'=>'',
                    'name'=>'Abc',
                    'modifiers'=>['final'],
                    'declaration'=> 'final class Abc',
                    'methods'=>[
                        0=>[
                            'type'=>'method',
                            'args'=>[],
                            'modifiers'=>['public'],
                            'name'=>'abc',
                            'body'=>'',
                            'declaration'=>'public function abc()',
                        ],
                    ],
                    ],
                ],
            ],
        ],

        'Integration.Class.Bug.ModifiersMethods'=>[
            'is_bad_test'=>'This test works as intended, and was implemented to help handle a bug where a class\'s methods were being added to its modifiers. This was caused by getTree() recursion with arrays & use of the passthrough feature.',
            'ast.type'=>'namespace',
            'start'=>['php_code'],
            'input'=>"abstract class Abc {\n"
                ."    public function ",
            'expect'=>[
                'class'=>[
                    0=>[
                    'type'=>'class',
                    'modifiers'=>['abstract'],
                    'fqn'=>'Abc',
                    'namespace'=>'',
                    'name'=>'Abc',
                    'declaration'=> 'abstract class Abc',
                    'methods'=>[
                        0=>[
                            'type'=>'method',
                            'args'=>[],
                            'modifiers'=>['public'],
                        ],
                    ],
                    ],
                ],
            ],
        ],

        'Integration.Class.Method.2'=>[
            'ast.type'=>'file',
            'start'=>['php_code'],
            'input'=>"class Abc {\n"
                    ."    public function abc() {"
                    ."\n    }"
                    ."    private function def() {"
                    ."\n    }"
                    ."\n}"
                    ."final class Def {\n"
                    ."    public function abc() {"
                    ."\n    }"
                    ."    protected function def() {"
                    ."\n    }"
                    ."\n}"
                    ,
            'expect'=>[
                'namespace'=>'',
                'class'=>[
                    0=>[
                    'type'=>'class',
                    'fqn'=>'Abc',
                    'namespace'=>'',
                    'name'=>'Abc',
                    'declaration'=> 'class Abc',
                    'methods'=>[
                            0=>[
                                'type'=>'method',
                                'args'=>[],
                                'modifiers'=>['public'],
                                'name'=>'abc',
                                'body'=>'',
                                'declaration'=>'public function abc()',
                            ],
                            1=>[
                                'type'=>'method',
                                'args'=>[],
                                'modifiers'=>['private'],
                                'name'=>'def',
                                'body'=>'',
                                'declaration'=>'private function def()',
                            ],
                        ],
                    ],
                    1=>[
                    'type'=>'class',
                    'fqn'=>'Def',
                    'namespace'=>'',
                    'name'=>'Def',
                    'modifiers'=>['final'],
                    'declaration'=> 'final class Def',
                    'methods'=>[
                            0=>[
                                'type'=>'method',
                                'args'=>[],
                                'modifiers'=>['public'],
                                'name'=>'abc',
                                'body'=>'',
                                'declaration'=>'public function abc()',
                            ],
                            1=>[
                                'type'=>'method',
                                'args'=>[],
                                'modifiers'=>['protected'],
                                'name'=>'def',
                                'body'=>'',
                                'declaration'=>'protected function def()',
                            ],
                        ],
                    ],
                ],
            ],
        ],

        'Integration.Trait.Method'=>[
            'ast.type'=>'namespace',
            'start'=>['php_code'],
            'input'=>"trait Abc {\n"
                    ."    public function abc() {"
                    ."    }"
                    ."}",
            'expect'=>[
                'trait'=>[
                    0=>[
                    'type'=>'trait',
                    'fqn'=>'Abc',
                    'namespace'=>'',
                    'name'=>'Abc',
                    'declaration'=> 'trait Abc',
                    'methods'=>[
                        0=>[
                            'type'=>'method',
                            'args'=>[],
                            'modifiers'=>['public'],
                            'name'=>'abc',
                            'body'=>'',
                            'declaration'=>'public function abc()',
                        ],
                    ],
                    ],
                ],
            ],
        ],

        'Integration.Class.Method'=>[
            'ast.type'=>'namespace',
            'start'=>['php_code'],
            'input'=>"class Abc {\n"
                    ."    public function abc() {"
                    ."    }"
                    ."}",
            'expect'=>[
                'class'=>[
                    0=>[
                    'type'=>'class',
                    'fqn'=>'Abc',
                    'namespace'=>'',
                    'name'=>'Abc',
                    'declaration'=> 'class Abc',
                    'methods'=>[
                        0=>[
                            'type'=>'method',
                            'args'=>[],
                            'modifiers'=>['public'],
                            'name'=>'abc',
                            'body'=>'',
                            'declaration'=>'public function abc()',
                        ],
                    ],
                    ],
                ],
            ],
        ],
    ];
}
<?php

namespace Tlf\Lexer\Test\Directives;

trait Classes {
    protected $_class_tests = [

        'Class.InNamespace'=>[
            'ast.type'=>'file',
            'start'=>['php_code'],
            'input'=>"namespace Abc; class Def {}",
            'expect'=>[
                'namespace'=>[
                    'type'=>'namespace',
                    'name'=>'Abc',
                    'declaration'=>'namespace Abc;',
                    'class'=>[
                        0=>[
                            'type'=>'class',
                            'namespace'=>'Abc',
                            'fqn'=>'Abc\\Def',
                            'name'=>'Def',
                            'declaration'=>'class Def',
                        ],
                    ],
                ],
            ]
        ],

        'Class.Final.EmptyBody'=>[
            'ast.type'=>'file',
            'start'=>['php_code'],
            'input'=>"final class Abc {\n\n}",
            'expect'=>[
                'namespace'=>'',
                'class'=>[
                    0=>[
                        'type'=>'class',
                        'modifiers'=>['final'],
                        'fqn'=>'Abc',
                        'namespace'=>'',
                        'name'=>'Abc',
                        'declaration'=>'final class Abc',
                    ],
                ],
            ]
        ],

        'Class.Implements'=>[
            'is_bad_test'=>"We don't yet catch what interfaces a class implements. We just shove it in the declaration",
            'ast.type'=>'namespace',
            'start'=>['php_code'],
            'input'=>'class Abc extends \Def\Ghi implements iAbc, iDef {',
            'expect'=>[
                'class'=>[
                    0=>[
                    'type'=>'class',
                    'fqn'=>'Abc',
                    'namespace'=>'',
                    'name'=>'Abc',
                    'extends'=>'\Def\Ghi',
                    'declaration'=> 'class Abc extends \Def\Ghi implements iAbc, iDef',
                    ],
                ],
            ],
        ],

        'Class.Extends'=>[
            'ast.type'=>'namespace',
            'start'=>['php_code'],
            'input'=>'class Abc extends \Def\Ghi {',
            'expect'=>[
                'class'=>[
                    0=>[
                    'type'=>'class',
                    'fqn'=>'Abc',
                    'namespace'=>'',
                    'name'=>'Abc',
                    'extends'=>'\Def\Ghi',
                    'declaration'=> 'class Abc extends \Def\Ghi',
                    ],
                ],
            ],
        ],
        'Class.Abstract'=>[
            'ast.type'=>'namespace',
            'start'=>['php_code'],
            'input'=>'abstract class Abc {',
            'expect'=>[
                'class'=>[
                    0=>[
                    'type'=>'class',
                    'modifiers'=>['abstract'],
                    'fqn'=>'Abc',
                    'namespace'=>'',
                    'name'=>'Abc',
                    'declaration'=> 'abstract class Abc',
                    ],
                ],
            ],
        ],
        'Class.OpenInFile'=>[
            'ast.type'=>'file',
            'start'=>['php_code'],
            'input'=>'class Abc {',
            'expect'=>[
                'namespace'=>'',
                'class'=>[
                    0=>[
                    'type'=>'class',
                    'fqn'=>'Abc',
                    'namespace'=>'',
                    'name'=>'Abc',
                    'declaration'=> 'class Abc',
                    ],
                ]
            ],
        ],
        'Class.OpenInNamespace'=>[
            'ast.type'=>'namespace',
            'start'=>['php_code'],
            'input'=>'class Abc {',
            'expect'=>[
                'class'=>[
                    0=>[
                    'type'=>'class',
                    'fqn'=>'Abc',
                    'namespace'=>'',
                    'name'=>'Abc',
                    'declaration'=> 'class Abc',
                    ],
                ],
            ],
        ],
    ];
}
<?php

namespace Tlf\Lexer\Test\Directives;

trait Consts  {

    protected $_const_tests= [

        'Const.Two'=>[
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>' const blm = "Yes!";private const cat="yep"; ',
            'expect'=>[
                'const'=>[
                    0=>[
                        'type'=>'const',
                        'name'=>'blm',
                        'value'=> '"Yes!"',
                        'declaration'=>'const blm = "Yes!";',
                    ],
                    1=>[
                        'type'=>'const',
                        'modifiers'=>['private'],
                        'name'=>'cat',
                        'value'=> '"yep"',
                        'declaration'=>'private const cat="yep";',
                    ],
                ],
            ],
        ],
        
        'Const.Private'=>[
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>'private const blm = 86;',
            'expect'=>[
                'const'=>[
                    0=>[
                        'type'=>'const',
                        'name'=>'blm',
                        'modifiers'=>['private'],
                        'value'=>'86',
                        'declaration'=>'private const blm = 86;',
                    ],
                ],
            ],
        ],

        'Const.Simple'=>[
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>'const blm = "yes";',
            'expect'=>[
                'const'=>[
                    0=>[
                        'type'=>'const',
                        'name'=>'blm',
                        'value'=>'"yes"',
                        'declaration'=>'const blm = "yes";',
                    ],
                ],
            ],
        ],

        'Const.NoValue'=>[
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>'const blm ',
            'expect'=>[
                'const'=>[
                    0=>[
                        'type'=>'const',
                        'name'=>'blm',
                    ],
                ],
            ],
        ],

    ];
}
<?php

namespace Tlf\Lexer\Test\Directives;

trait Methods {
    protected $_method_tests = [

        'Method.SimpleBody'=>[
            // 'expect_failure'=>true,
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>
                <<<PHP
                    public function is_the_us_imperialist():bool {
                        \$var = new \Value();
                        return true;
                    } 
                PHP,
            'expect'=>[
                'methods'=>[
                    0=>[
                        'type'=>'method',
                        'args'=>[],
                        'modifiers'=>['public'],
                        'name'=>'is_the_us_imperialist',
                        'return_types'=>['bool'],
                        'body'=>"\$var = new \\Value();\nreturn true;",
                        'declaration'=>'public function is_the_us_imperialist():bool',
                    ],
                ],
            ],
        ],
        'Method.ReturnReference'=>[
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>'public function &abc() {',
            'expect'=>[
                'methods'=>[
                    0=>[
                        'type'=>'method',
                        'args'=>[],
                        'modifiers'=>['public'],
                        'return_by_reference'=>true,
                        'name'=>'abc',
                        'body'=>[],
                        'declaration'=>'public function &abc()',
                    ],
                ],
            ],
        ],

        'Method.WithNestedBlock.2'=>[
            // 'expect_failure'=>true,
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>
                <<<PHP
                    public function is_the_us_imperialist():bool {
                        if (\$you_buy_into_imperialist_propaganda){
                            return false;
                        } 
                        return true;
                    } 
                    public function is_the_us_nice():bool {
                        if (\$you_are_rich){
                            return true;
                        } 
                        return false;
                    } 
                PHP,
            'expect'=>[
                'methods'=>[
                    0=>[
                        'type'=>'method',
                        'args'=>[],
                        'modifiers'=>['public'],
                        'name'=>'is_the_us_imperialist',
                        'return_types'=>['bool'],
                        'body'=>
                            "if (\$you_buy_into_imperialist_propaganda){"
                            ."\n    return false;"
                            ."\n}" 
                            ."\nreturn true;",
                        
                        'declaration'=>'public function is_the_us_imperialist():bool',
                    ],
                    1=>[
                        'type'=>'method',
                        'args'=>[],
                        'modifiers'=>['public'],
                        'name'=>'is_the_us_nice',
                        'return_types'=>['bool'],
                        'body'=>
                            "if (\$you_are_rich){"
                            ."\n    return true;"
                            ."\n}" 
                            ."\nreturn false;",
                        'declaration'=>'public function is_the_us_nice():bool',
                    ],
                ],
            ],
        ],

        'Method.WithNestedBlock'=>[
            // 'expect_failure'=>true,
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>
                <<<PHP
                    public function is_the_us_imperialist():bool {
                        if (\$you_buy_into_imperialist_propaganda){
                            return false;
                        } 
                        return true;
                    } 
                PHP,
            'expect'=>[
                'methods'=>[
                    0=>[
                        'type'=>'method',
                        'args'=>[],
                        'modifiers'=>['public'],
                        'name'=>'is_the_us_imperialist',
                        'return_types'=>['bool'],
                        "body"=>
                            "if (\$you_buy_into_imperialist_propaganda){"
                            ."\n    return false;"
                            ."\n}" 
                            ."\nreturn true;",
                        'declaration'=>'public function is_the_us_imperialist():bool',
                    ],
                ],
            ],
        ],

        'Method.WithReturnType'=>[
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>'static public function abc(bool $b): string {',
            'expect'=>[
                'methods'=>[
                    0=>[
                        'type'=>'method',
                        'args'=>[
                            0=>[
                                'type'=>'arg',
                                'arg_types'=>['bool'],
                                'name'=>'b',
                                'declaration'=>'bool $b',
                            ],
                        ],
                        'modifiers'=>['static', 'public'],
                        'name'=>'abc',
                        'return_types'=>['string'],
                        'body'=>'',
                        'declaration'=>'static public function abc(bool $b): string',
                    ],
                ],
            ],
        ],

       
        'Method.TwoArgs'=>[
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>'/* whoo */ private function abc($arg1, $arg2) {',
            'expect'=>[
                'methods'=>[
                    0=>[
                        'type'=>'method',
                        'args'=>[
                            0=>[
                                'type'=>'arg',
                                'name'=>'arg1',
                                'declaration'=>'$arg1',
                            ],
                            1=>[
                                'type'=>'arg',
                                'name'=>'arg2',
                                'declaration'=>'$arg2',
                            ],
                        ],
                        'docblock'=>['type'=>'docblock','description'=>'whoo'],
                        'modifiers'=>['private'],
                        'name'=>'abc',
                        'body'=>'',
                        'declaration'=>'private function abc($arg1, $arg2)',
                    ],
                ],
            ],
        ],

        'Method.OneArg'=>[
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>'/* whoo */ public function abc(string $def=96) {',
            'expect'=>[
                'methods'=>[
                    0=>[
                        'type'=>'method',
                        'args'=>[
                            0=>[
                                'type'=>'arg',
                                'arg_types'=>['string'],
                                'name'=>'def',
                                'declaration'=>'string $def=96',
                                'value'=>'96',
                            ],
                        ],
                        'docblock'=>['type'=>'docblock','description'=>'whoo'],
                        'modifiers'=>['public'],
                        'name'=>'abc',
                        'body'=>'',
                        'declaration'=>'public function abc(string $def=96)',
                    ],
                ],
            ],
        ],

        'Method.Simple.OneArg'=>[
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>'public function abc($def) {',
            'expect'=>[
                'methods'=>[
                    0=>[
                        'type'=>'method',
                        'args'=>[
                            0=>[
                                'type'=>'arg',
                                'name'=>'def',
                                'declaration'=>'$def',
                            ],
                        ],
                        'modifiers'=>['public'],
                        'name'=>'abc',
                        'body'=>'',
                        'declaration'=>'public function abc($def)',
                    ],
                ],
            ],
        ],

        'Method.Static'=>[
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>'static public function abc() {',
            'expect'=>[
                'methods'=>[
                    0=>[
                        'type'=>'method',
                        'args'=>[],
                        'modifiers'=>['static','public'],
                        'name'=>'abc',
                        'body'=>'',
                        'declaration'=>'static public function abc()',
                    ],
                ],
            ],
        ],

        'Method.Simple'=>[
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>'public function abc() {',
            'expect'=>[
                'methods'=>[
                    0=>[
                        'type'=>'method',
                        'args'=>[],
                        'modifiers'=>['public'],
                        'name'=>'abc',
                        'body'=>'',
                        'declaration'=>'public function abc()',
                    ],
                ],
            ],
        ],
    ];
}
<?php

namespace Tlf\Lexer\Test\Directives;

trait Namespaces {
    protected $_namespace_tests = [
        'Namespace.Docblock'=>[
            'start'=>['php_code'],
            'input'=>"/** docs */ namespace AbcDef_09;",
            'expect'=>[
                'namespace'=>[
                    'type'=>'namespace',
                    'docblock'=>[
                        'type'=>'docblock',
                        'description'=>'docs',
                    ],
                    'declaration'=>'namespace AbcDef_09;',
                    'name'=>'AbcDef_09',
                ],
            ],
        ],

        'Namespace.MultiLayer.IntermediateDocblocks'=>[
            'is_bad_test'=>'The declaration SHOULD have a space after `namespace`, but it doesn\'t. I don\'t plan to fix this. The test is passing because this bug is acceptable. ',
            'start'=>['php_code'],
            'input'=>"namespace/*k*/Abc\Def\_09;",
            'expect'=>[
                'namespace'=>[
                    'type'=>'namespace',
                    'declaration'=>'namespaceAbc\Def\_09;',
                    'name'=>'Abc\Def\_09',
                ],
            ],
        ],

        'Namespace.MultiLayer'=>[
            'start'=>['php_code'],
            'input'=>"namespace Abc\Def\_09;",
            'expect'=>[
                'namespace'=>[
                    'type'=>'namespace',
                    'declaration'=>'namespace Abc\Def\_09;',
                    'name'=>'Abc\Def\_09',
                ],
            ],
        ],

        'Namespace.Simple'=>[
            'start'=>['php_code'],
            'input'=>"namespace AbcDef_09;",
            'expect'=>[
                'namespace'=>[
                    'type'=>'namespace',
                    'declaration'=>'namespace AbcDef_09;',
                    'name'=>'AbcDef_09',
                ],
            ],
        ],
    ];
}
<?php

namespace Tlf\Lexer\Test\Directives;

trait Other {
/**
 *
 * This fails because \' is not being handled ... I think 
 *
 */
protected $_other_tests = [

        // BUG: `public function someFunc(string $namespae){}`  - the `$namespace` breaks it. `$znamespace` is fine. `nzamespace` is fine. `$this->namepsace` in the function body is fine. `$namespace` in the function body is fine.
        'Bug.namespace'=>[
            // 'expect_failure'=>true,
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>
                <<<PHP
                    public function namespace_add(string \$namespace) {
                        \$this->namespace[] = \$namespace;
                    } 
                PHP,
            'expect'=>[
                'methods'=>[
                    0=>[
                        'type'=>'method',
                        'args'=>[],
                        'modifiers'=>['public'],
                        'name'=>'namespace_add',
                        'return_types'=>[],
                        'body'=>"\$this->namespace[] = \$namespace;",
                        'declaration'=>'public function namespace_add(string $namespace)',
                    ],
                ],
            ],
        ],
    
        'Function.Anon'=>[
            // 'expect_failure'=>true,
            'ast.type'=>'namespace',
            'start'=>['php_code'],
            'input'=>
                <<<PHP
                    function protect_womens_rights() use (\$abc){
                        return;
                    } 
                PHP,
            'expect'=>[
                'functions'=>[
                    0=>[
                        'type'=>'function',
                        'args'=>[],
                        'name'=>'protect_womens_rights',
                        // 'return_types'=>[],

                        'use_vars'=>[
                            0=>[
                                'type'=>'use_vars',
                                'args'=>[
                                    0=>['type'=>'arg', 'name'=>'abc', 'declaration'=>'$abc']
                                ],
                            ]
                        ],
                        'body'=>"return;",
                        'declaration'=>'function protect_womens_rights() use ($abc)',
                    ],
                ],
            ],
        ],
    
        'Function.SimpleBody'=>[
            // 'expect_failure'=>true,
            'ast.type'=>'namespace',
            'start'=>['php_code'],
            'input'=>
                <<<PHP
                    function is_the_us_imperialist():bool {
                        \$var = new \Value();
                        return true;
                    } 
                PHP,
            'expect'=>[
                'functions'=>[
                    0=>[
                        'type'=>'function',
                        'args'=>[],
                        'name'=>'is_the_us_imperialist',
                        'return_types'=>['bool'],
                        'body'=>"\$var = new \\Value();\nreturn true;",
                        'declaration'=>'function is_the_us_imperialist():bool',
                    ],
                ],
            ],
        ],
        'Const.Simple'=>[
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>'const blm = "This"."is".\'a\'."const";',
            'expect'=>[
                'const'=>[
                    0=>[
                        'type'=>'const',
                        // 'modifiers'=>['public'],
                        'name'=>'blm',
                        // 'docblock'=> '',
                        'declaration'=>'const blm = "This"."is".\'a\'."const";',
                        'value'=>'"This"."is".\'a\'."const"',
                    ],
                ],
            ],
        ],
];
}
<?php

namespace Tlf\Lexer\Test\Directives;

trait PhpOpenTags {
    protected $_php_open_tags_tests = [

        'Open.Class'=>[
            'ast.type'=>'file',
            'start'=>['php_open'],
            'input'=>'<html><div><?php class Abc {} ',
            'expect'=>[
                'namespace'=>'',
                'class'=>[
                    0=>[
                        'type'=>'class',
                        'fqn'=>'Abc',
                        'namespace'=>'',
                        'name'=>'Abc',
                        'declaration'=>'class Abc',
                    ]
                ],
            ],
        ],
        'Open.Close.Open'=>[
            'ast.type'=>'file',
            'start'=>['php_open'],
            'input'=>'<html><div><?php ?></div><?php namespace Abc; ',
            'expect'=>[
                'namespace'=>[
                    'type'=>'namespace',
                    'name'=>'Abc',
                    'declaration'=>'namespace Abc;',
                ],
            ],
        ],
        'Open.Simple'=>[
            'ast.type'=>'file',
            'start'=>['php_open'],
            'input'=>'<html><div><?php namespace Abc;',
            'expect'=>[
                'namespace'=>[
                    'type'=>'namespace',
                    'name'=>'Abc',
                    'declaration'=>'namespace Abc;',
                ],
            ],
        ],
    ];
}
<?php

namespace Tlf\Lexer\Test\Directives;

trait Props {

    protected $_prop_tests = [

        'Property.Assign.Concat'=>[
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>' public $global_warming = "angers"."me"."greatly";',
            'expect'=>[
                'properties'=>[
                    0=>[
                        'type'=>'property',
                        'modifiers'=>['public'],
                        'name'=>'global_warming',
                        'declaration'=>'public $global_warming = "angers"."me"."greatly";',
                        'value'=> '"angers"."me"."greatly"',
                    ],
                ],
            ],
        ],

        'Property.Two'=>[
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>' public $blm = "Yes!";private $cat="yep"; ',
            'expect'=>[
                'properties'=>[
                    0=>[
                        'type'=>'property',
                        'modifiers'=>['public'],
                        'name'=>'blm',
                        'value'=> '"Yes!"',
                        'declaration'=>'public $blm = "Yes!";',
                    ],
                    1=>[
                        'type'=>'property',
                        'modifiers'=>['private'],
                        'name'=>'cat',
                        'declaration'=>'private $cat="yep";',
                        'value'=> '"yep"',
                    ],
                ],
            ],
        ],

        'Property.Assign'=>[
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>' public $blm = "Yes!"; ',
            'expect'=>[
                'properties'=>[
                    0=>[
                        'type'=>'property',
                        'modifiers'=>['public'],
                        'name'=>'blm',
                        'declaration'=>'public $blm = "Yes!";',
                        'value'=> '"Yes!"',
                    ],
                ],
            ],
        ],

        'Property.Typed'=>[
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>' public int $blm;',
            'expect'=>[
                'properties'=>[
                    0=>[
                        'type'=>'property',
                        'modifiers'=>['public', 'int'],
                        'name'=>'blm',
                        // 'docblock'=> '',
                        'declaration'=>'public int $blm;',
                    ],
                ],
            ],
        ],

        'Property.Static'=>[
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>' static public $blm;',
            'expect'=>[
                'properties'=>[
                    0=>[
                        'type'=>'property',
                        'modifiers'=>['static','public'],
                        'name'=>'blm',
                        // 'docblock'=> '',
                        'declaration'=>'static public $blm;',
                    ],
                ],
            ],
        ],

        'Property.Simple'=>[
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>' public $blm;',
            'expect'=>[
                'properties'=>[
                    0=>[
                        'type'=>'property',
                        'modifiers'=>['public'],
                        'name'=>'blm',
                        // 'docblock'=> '',
                        'declaration'=>'public $blm;',
                    ],
                ],
            ],
        ],
    ];
}
<?php

namespace Tlf\Lexer\Test\Directives;

trait Traits {

    protected $_trait_tests = [

        'Trait.InNamespace'=>[
            'ast.type'=>'file',
            'start'=>['php_code'],
            'input'=>"namespace Abc; trait Def {}",
            'expect'=>[
                'namespace'=>[
                    'type'=>'namespace',
                    'name'=>'Abc',
                    'declaration'=>'namespace Abc;',
                    'trait'=>[
                        0=>[
                            'type'=>'trait',
                            'fqn'=>'Abc\\Def',
                            'namespace'=>'Abc',
                            'name'=>'Def',
                            'declaration'=>'trait Def',
                        ],
                    ],
                ],
            ]
        ],

        'Trait.EmptyBody'=>[
            'ast.type'=>'file',
            'start'=>['php_code'],
            'input'=>"trait Abc {\n\n}",
            'expect'=>[
                'namespace'=>'',
                'trait'=>[
                    0=>[
                        'type'=>'trait',
                        'fqn'=>'Abc',
                        'namespace'=>'',
                        'name'=>'Abc',
                        'declaration'=>'trait Abc',
                    ],
                ],
            ]
        ],

        'Trait.OpenInFile'=>[
            'ast.type'=>'file',
            'start'=>['php_code'],
            'input'=>'trait Abc {',
            'expect'=>[
                'namespace'=>'',
                'trait'=>[
                    0=>[
                    'type'=>'trait',
                    'fqn'=>'Abc',
                    'namespace'=>'',
                    'name'=>'Abc',
                    'declaration'=> 'trait Abc',
                    ],
                ]
            ],
        ],

        'Trait.OpenInNamespace'=>[
            'ast.type'=>'namespace',
            'start'=>['php_code'],
            'input'=>'trait Abc {',
            'expect'=>[
                'trait'=>[
                    0=>[
                    'type'=>'trait',
                    'fqn'=>'Abc',
                    'namespace'=>'',
                    'name'=>'Abc',
                    'declaration'=> 'trait Abc',
                    ],
                ],
            ],
        ],

    ];
}
<?php

namespace Tlf\Lexer\Test\Directives;

trait UseTrait {
    protected $_use_trait_tests = [

        'UseTrait.Docblock'=>[
            'start'=>['php_code'],
            'input'=>"/** docs */ use AbcDef_09;",
            'expect'=>[
                'traits'=>[
                    0=>[
                        'type'=>'use_trait',
                        'docblock'=>[
                            'type'=>'docblock',
                            'description'=>'docs',
                        ],
                        'name'=>'AbcDef_09',
                        'declaration'=>'use AbcDef_09;',
                    ]
                ],
            ],
        ],

        'UseTrait.WithNamespace.IntermediateDocblocks'=>[
            'is_bad_test'=>'The declaration SHOULD have a space after `use`, but it doesn\'t. I don\'t plan to fix this. The test is passing because this bug is acceptable. ',
            'start'=>['php_code'],
            'input'=>"use/*k*/Abc\Def\_09;",
            'expect'=>[
                'traits'=>[
                    0=>[
                        'type'=>'use_trait',
                        'name'=>'Abc\Def\_09',
                        'declaration'=>'useAbc\Def\_09;',
                    ]
                ],
            ],
        ],

        'UseTrait.WithNamespace'=>[
            'start'=>['php_code'],
            'input'=>"use Abc\Def\_09;",
            'expect'=>[
                'traits'=>[
                    0=>[
                        'type'=>'use_trait',
                        'name'=>'Abc\Def\_09',
                        'declaration'=>'use Abc\Def\_09;',
                    ]
                ],
            ],
        ],

        'UseTrait.Simple'=>[
            'start'=>['php_code'],
            'input'=>"use AbcDef_09;",
            'expect'=>[
                'traits'=>[
                    0=>[
                        'type'=>'use_trait',
                        'name'=>'AbcDef_09',
                        'declaration'=>'use AbcDef_09;',
                    ]
                ],
            ],
        ],

    ];
}
<?php

namespace Tlf\Lexer\Test\Directives;

trait Values {

    protected $_values_tests= [


        'Values.Arithmetic.Nesting'=>[
            'ast.type'=>'var_assign',
            'start'=>['php_code'],
            // PEMDAS
            'input'=>'(1*2+(4*6/((1+2)+(3**2)))+3 - 12) / 3 ** 2 + 987;',
            'expect'=>[
                'value'=>'(1*2+(4*6/((1+2)+(3**2)))+3-12)/3**2+987',
                'declaration'=>'(1*2+(4*6/((1+2)+(3**2)))+3 - 12) / 3 ** 2 + 987;',
            ],
        ],
        'Values.Arithmetic'=>[
            'ast.type'=>'var_assign',
            'start'=>['php_code'],
            // PEMDAS
            'input'=>'(1*2)+3 - 12 / 3 ** 2 + 987;',
            'expect'=>[
                'value'=>'(1*2)+3-12/3**2+987',
                'declaration'=>'(1*2)+3 - 12 / 3 ** 2 + 987;',
            ],
        ],

        'Values.Arithmetic.Add'=>[
            'ast.type'=>'var_assign',
            'start'=>['php_code'],
            // PEMDAS
            'input'=>'1 + 2;',
            'expect'=>[
                'value'=>'1+2',
                'declaration'=>'1 + 2;',
            ],
        ],

        'Values.Array.WithConcats'=>[
            'ast.type'=>'var_assign',
            'start'=>['php_code'],
            'input'=>'["a"."b"."c",22,"c"];',
            'expect'=>[
                'value'=>'["a"."b"."c",22,"c"]',
                'declaration'=>'["a"."b"."c",22,"c"];',
            ],
        ],

        'Values.Array.Keyed'=>[
            'ast.type'=>'var_assign',
            'start'=>['php_code'],
            'input'=>'["a"=>1,22,"c"=>\'third element\'];',
            'expect'=>[
                'value'=>'["a"=>1,22,"c"=>\'third element\']',
                'declaration'=>'["a"=>1,22,"c"=>\'third element\'];',
            ],
        ],

        'Values.Array.IntStringValues'=>[
            'ast.type'=>'var_assign',
            'start'=>['php_code'],
            'input'=>'["a",22,"c"];',
            'expect'=>[
                'value'=>'["a",22,"c"]',
                'declaration'=>'["a",22,"c"];',
            ],
        ],

        'Values.Array.StringValues'=>[
            'ast.type'=>'var_assign',
            'start'=>['php_code'],
            'input'=>'["a","b","c"];',
            'expect'=>[
                'value'=>'["a","b","c"]',
                'declaration'=>'["a","b","c"];',
            ],
        ],

        'Values.Array.DoubleValue'=>[
            'ast.type'=>'var_assign',
            'start'=>['php_code'],
            'input'=>'[1.33,2,3];',
            'expect'=>[
                'value'=>'[1.33,2,3]',
                'declaration'=>'[1.33,2,3];',
            ],
        ],

        'Values.Array.IntValues'=>[
            'ast.type'=>'var_assign',
            'start'=>['php_code'],
            'input'=>'[1,2,3];',
            'expect'=>[
                'value'=>'[1,2,3]',
                'declaration'=>'[1,2,3];',
            ],
        ],

        'Values.BothQuotesConcat'=>[
            'ast.type'=>'var_assign',
            'start'=>['php_code'],
            'input'=>'"This"."is".\'a\'."const";',
            'expect'=>[
                'value'=>'"This"."is".\'a\'."const"',
                'declaration'=>'"This"."is".\'a\'."const";',
            ],
        ],

        'Values.SingleQuotesConcat'=>[
            'ast.type'=>'var_assign',
            'start'=>['php_code'],
            'input'=>"'This'.'is'.'a'.'thing';",
            'expect'=>[
                'value'=>"'This'.'is'.'a'.'thing'",
                'declaration'=>"'This'.'is'.'a'.'thing';",
            ],
        ],

        'Values.DoubleQuotesConcat'=>[
            'ast.type'=>'var_assign',
            'start'=>['php_code'],
            'input'=>'"This"."is"."a"."thing";',
            'expect'=>[
                'value'=>'"This"."is"."a"."thing"',
                'declaration'=>'"This"."is"."a"."thing";',
            ],
        ],

        'Values.Double'=>[
            'ast.type'=>'var_assign',
            'start'=>['php_code'],
            'input'=>'1.87;',
            'expect'=>[
                'value'=>'1.87',
                'declaration'=>'1.87;',
            ],
        ],

        'Values.Int'=>[
            'ast.type'=>'var_assign',
            'start'=>['php_code'],
            'input'=>'1;',
            'expect'=>[
                'value'=>'1',
                'declaration'=>'1;',
            ],
        ],

        "Values.SemicolonStop"=>[
            'ast.type'=>'var_assign',
            'start'=>['php_code'],
            'input'=>'"This";',
            'expect'=>[
                'value'=>'"This"',
                'declaration'=>'"This";',
            ],
        ],

        'Values.CommaSeparatedArg'=>[
            'ast.type'=>'var_assign',
            'start'=>['php_code'],
            'input'=>'"This",',
            'expect'=>[
                'value'=>'"This"',
                'declaration'=>'"This"',
            ],
        ],

        'Values.CloseArgList'=>[
            'ast.type'=>'var_assign',
            'start'=>['php_code'],
            'input'=>'"This")',
            'expect'=>[
                'value'=>'"This"',
                'declaration'=>'"This"',
            ],
        ],
    ];
}
<?php

namespace Tlf\Lexer\Test\Directives;

trait Vars {

    protected $_var_tests = [

        'Var.Assign.Variable'=>[
            'ast.type'=>'method_body',
            'start'=>['php_code'],
            'input'=>'$bear = $red_racoon;',
            'expect'=>[
                'statements'=>[
                    0=>[
                        'type'=>'var',
                        'line_number'=>0,
                        'name'=>'bear',
                        'set_to'=>[
                            'type'=>'var',
                            'name'=>'red_racoon',
                            'declaration'=>'$red_racoon',
                        ],
                        'declaration'=>'$bear = $red_racoon;',
                    ],
                ],
            ],
        ],

        'Var.Assign.String'=>[
            'ast.type'=>'method_body',
            'start'=>['php_code'],
            'input'=>'$bear = "barry";',
            'expect'=>[
                'statements'=>[
                    0=>[
                        'type'=>'var',
                        'line_number'=>0,
                        'name'=>'bear',
                        'value'=>'"barry"',
                        'declaration'=>'$bear = "barry";',
                    ],
                ],
            ],
        ],

    ];

    protected $old_prop_tests = [

        'Property.Assign.Concat'=>[
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>' public $global_warming = "angers"."me"."greatly";',
            'expect'=>[
                'properties'=>[
                    0=>[
                        'type'=>'property',
                        'modifiers'=>['public'],
                        'name'=>'global_warming',
                        'declaration'=>'public $global_warming = "angers"."me"."greatly";',
                        'value'=> '"angers"."me"."greatly"',
                    ],
                ],
            ],
        ],

        'Property.Two'=>[
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>' public $blm = "Yes!";private $cat="yep"; ',
            'expect'=>[
                'properties'=>[
                    0=>[
                        'type'=>'property',
                        'modifiers'=>['public'],
                        'name'=>'blm',
                        'value'=> '"Yes!"',
                        'declaration'=>'public $blm = "Yes!";',
                    ],
                    1=>[
                        'type'=>'property',
                        'modifiers'=>['private'],
                        'name'=>'cat',
                        'declaration'=>'private $cat="yep";',
                        'value'=> '"yep"',
                    ],
                ],
            ],
        ],

        'Property.Assign'=>[
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>' public $blm = "Yes!"; ',
            'expect'=>[
                'properties'=>[
                    0=>[
                        'type'=>'property',
                        'modifiers'=>['public'],
                        'name'=>'blm',
                        'declaration'=>'public $blm = "Yes!";',
                        'value'=> '"Yes!"',
                    ],
                ],
            ],
        ],

        'Property.Typed'=>[
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>' public int $blm;',
            'expect'=>[
                'properties'=>[
                    0=>[
                        'type'=>'property',
                        'modifiers'=>['public', 'int'],
                        'name'=>'blm',
                        // 'docblock'=> '',
                        'declaration'=>'public int $blm;',
                    ],
                ],
            ],
        ],

        'Property.Static'=>[
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>' static public $blm;',
            'expect'=>[
                'properties'=>[
                    0=>[
                        'type'=>'property',
                        'modifiers'=>['static','public'],
                        'name'=>'blm',
                        // 'docblock'=> '',
                        'declaration'=>'static public $blm;',
                    ],
                ],
            ],
        ],

        'Property.Simple'=>[
            'ast.type'=>'class_body',
            'start'=>['php_code'],
            'input'=>' public $blm;',
            'expect'=>[
                'properties'=>[
                    0=>[
                        'type'=>'property',
                        'modifiers'=>['public'],
                        'name'=>'blm',
                        // 'docblock'=> '',
                        'declaration'=>'public $blm;',
                    ],
                ],
            ],
        ],
    ];
}
<?php

namespace Tlf\Lexer\Test\Src\Starter;

trait OtherDirectives {

    protected $_other_directives = [

        'parenthesis'=>[
            'start'=>[
                'match'=>'(',
                'ast.new'=>[
                    '_type'=>'arglist',
                    '_addto'=>'argsets',
                ],
                'buffer.clear',
                'then :comma',
                'then.pop :parenthesis.stop 1',
            ],
            'stop'=>[
                'match'=>')',
                'inherit :comma.start',
                'ast.pop', 
            ]
        ],
        'comma'=>[
            'start'=>[
                'match'=>'/,$/', //any string starting with a `/` will be treated as regex
                'rewind 1',
                'this:trimBuffer',
                'ast.push args',
                'forward 1',
                'buffer.clear',
                'stop',
            ]
        ],

    ];

}
<?php

namespace Tlf\Lexer\Test\Src;

/** 
 * An extremely simple grammar that builds sets of arglist from `(arg1,arg2,c) (list2_arg1,arg2)` 
 *
 * Basically just a proof of concept 
 */
class StarterGrammar extends \Tlf\Lexer\Grammar {

    // use Starter\LanguageDirectives;
    use Starter\OtherDirectives;

    /** The actual array of directives, built during onGrammarAdded() */
    public $directives;

    /** Defaults to 'startergrammar' */
    public function getNamespace(){return 'starter';}

    /** Combine the directives from traits */
    public function buildDirectives(){
        $this->directives = array_merge(
            // $this->_language_directives,
            $this->_other_directives,
        );
    }

    public function onGrammarAdded(\Tlf\Lexer $lexer){
        $this->buildDirectives();
        /** The first directive(s) to listen for. We're looking for an opening `(` */
        $lexer->addDirective($this->getDirectives(':parenthesis')['parenthesis']);
        // you can add more directives
    }

    public function onLexerStart(\Tlf\Lexer $lexer,\Tlf\Lexer\Ast $ast,\Tlf\Lexer\Token $token){
        // $lexer->addGrammar(new DocblockGrammar()); //if your language uses docblocks

        /** Just an example of setting an empty namespace at the start, so that all files have a namespace, even if its empty. */
        if ($ast->type=='file'){
            $ast->set('namespace', '');
        }
    }

    /** A method this grammar uses as an instruction to trim() the buffer */
    public function trimBuffer(\Tlf\Lexer $lexer, \Tlf\Lexer\Ast $ast, \Tlf\Lexer\Token $token, \stdClass $directive, array $args){
        $token->setBuffer(trim($token->buffer()));
    }
}
# Unorganized Documentation

## Test config file
I previously supported a `.config/tlf-test.json` file AND a `/test/config.json` file (either or). Now it is just `test/config.json`. I might re-enable alternate location ... but not at this time.
MIT License

Copyright (c) 2020 Taeluf

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# Tester - Unit Testing for Php  
Unit testing library. [phpunit](https://phpunit.de) has more features & community.  
  
## Install  
```bash  
composer require taeluf/tester v0.3.x-dev   
```  
or in your `composer.json`  
```json  
{"require":{ "taeluf/tester": "v0.3.x-dev"}}  
```  
  
  
## Run Tests | CLI Interface  
Call `phptest` or `vendor/bin/phptest` from your project's root dir.   
  
A globally installed `phptest` will execute the `vendor/bin/phptest` copy if it exists.  
  
```bash  
phptest # simply run tests  
  
phptest init # Create test dir & example test files  
  
phptest server # launch test server using default settings  
phptest server server_name # launch a configured server  
phptest server -host.override "https://example.com" # typically server tests will use a localhost address. This overrides the host in all tests, even if you have a multi-server setup.  
  
phptest -test TestName # Run one test; display all output for the named test  
phptest -test TestName -test Another Test # Run all named tests  
phptest -class ClassName # Run all tests for a class. Do not include namespace. Can include multiple classes.  
  
phptest -custom_key SomeValue # For any tests that allow custom input from CLI.  
```  
  
Other Options:  
```bash  
-class ClassName -test TestName # Only run TestName for the given ClassName  
-prettyPrintArray true # Not sure if this works. To print array comparisons on multiple lines. By default output is condensed.  
-set_error_handler false # Not sure if this works. Enable the built-in error handler that causes all warnings, etc, to throw an exception.  
-bench.threshold 0.001 # Only print benchmark for tests taking longer than 1 ms to run. `0.001` is configurable.  
```  
  
## Example Test class  
See the available assertions below  
```php  
<?php  
  
namespace Tlf\Tester\Test\Runner;  
  
class NestedTest extends \Tlf\Tester {  
  
    /** called before tests are run */  
    public function prepare(){}  
  
    /** Test methods must prefix with `test` */  
    public function testAnything(){  
        $this->compare(true,true);  
    }  
}  
```  
  
## Sample config  
`test/config.json` is optional, but recommended. Any values not in your `config.json` will be filled by the defaults below.  
  
Default `config.json`:  
```json  
{  
    "dir.test":["test/run"],  
    "dir.exclude":[],  
    "file.require":[],  
  
    "results.writeHtml":false,  
  
    "bench.threshold": 0.0001,  
  
    "server.main": "main",  
    "server":{  
        "main": {   
            "dir":"test/Server",  
            "bootstrap":"bootstrap.php",  
            "deliver":"deliver.php",  
            "host": "http://localhost"  
        }  
    }  
}  
```  
  
## Assertions  
For docs/details, see [src/Tester/Assertions.php](/src/Tester/Assertions.php)  
  
```php  
isInstanceOf($object, $shouldBe)  
is_object($object)  
is_false($value)  
is_true($value)  
str_contains($str, $target, ...$strings)  
str_not_contains(string $str, $target, ...$strings)  
compare($target, $actual,$strict=false)  
compare_raw($target, $actual, $strict=false)  
compare_arrays($target, $actual, $strict=false)  
compare_objects($target, $actual, $strict=false)  
compare_json($target, $actual, $strict=false)  
str_contains_lines($str, $target)  
compare_lines($target, $actual)  
compare_dump($target, $actual)  
```  
  
There is also a magic `__call()` which will invoke an existing PHP function and use it's return value as an assertion.   
  
For example, `$this->in_array('value', $array_to_test);` will `pass` if PHP's `in_array()` method returns `true`  
  
## Alternate Installation  
This also requires [code-scrawl](https://tluf.me/code-scrawl) for development, which is not handled by this script.    
copy+paste this into a bash terminal  
```bash  
pwd="$(pwd)";  
command="phptest"  
downloadDir=~/.gitclone  
mkdir -p "$downloadDir"  
cd "$downloadDir"  
git clone https://gitlab.com/taeluf/php/php-tests.git ${command}   
echo "alias ${command}=\"${downloadDir}/${command}/code/phptest\"" >> ~/.bashrc  
chmod ug+x "${downloadDir}/${command}/code/phptest"  
cd "$pwd";  
source ~/.bashrc  
echo "You can now run \`${command}\`"  
```  
  
  
  
# PHP tester status / notes

## Nov 6, 2023 
create v1.0 branch. It will be strongly typed, refactored, and just cleaned up in general.

- move cli script to bin/phptest
- move command setup & config loading to the Runner. 
- added config/phptest.json as an option for config file location
- add types and docblocks to Runner
- docblock some configs in the runner
- move code dir to src/

## Oct 10, 2023
Rewrote the system for running and calling test servers. I wanted to add optional bootstrap loading, and it was a mess, so I cleaned up the implementation. This probably will cause some breaking changes, but all the built-in tests (including multi-server tests) passed.

Significantly updated README

## Apr 12, 2022
- Server: add curl_post() to get body, header_text, headers array & cookies array (cookies parsing to be implemented)

## Dec 8, 2021
- Doing major refactor of phptest ...
    - it is going well. I'm in code/Tester, code/Runner, and code/trait/Assertions. Mainly in Tester & Runner. I'm working on the run() loop. I just got test pass/fail printing how I want for individual test methods. But I'm getting an exception on line 127 of Runner. Run `phptest` to see the error. I just disabled the `startOb` & `endOb` that wraps `$tester->run()` (called in Runner) so the tester itself can output its results.
    - The rest of what I'm doing is in this vein ... having the printing closer to the actual happening. Simpler data structures. Easier to follow code.

- I need to:
    - print the class name from which tests are being run
    - make sure `-test` flag works
    - enable printing when only a specific test is being run (so it shows the full test's output)
    - Idunno... I think just finish the refactor

## Versions
- v0.3: Uses `taeluf/cli` library. adds server tests with help of `phptest server`. major refactor. new init setup
- v0.2: uses internal cli code. no server tests
- v0.1: Idunno

## Ideas
- Write default config file if not found
- Cache map of files to test & add `phptest scan` to re-scan (or `phptest --scan` to enable scanning)
- Assertions extensibility so its easy for any package to add its own assertions
#!/usr/bin/env php
<?php

//three ways to run:
//1. `phptest` system installed
//2. `vendor/bin/phptest` composer installed
//3. `phptest` system install calls `vendor/bin/phptest` composer installed


// if global phptest is called & phptest is also installed to the current package via composer
// then only run the package-level install
$vendor_install = getcwd().'/vendor/bin/phptest';
//vendor_install_2 accounts for the composer update that stopped symlinking & started include-ing the target bin script
$vendor_install2 = getcwd().'/vendor/taeluf/tester/bin/phptest';
if (file_exists($vendor_install)
    &&realpath(__FILE__)!=realpath($vendor_install)
    &&realpath(__FILE__)!=realpath($vendor_install2)
){
    $args = array_slice($argv,1);
    $args = array_map(function($v){
        return '"'.addslashes($v).'"';
    }, $args);
    $cmd = "$vendor_install ". implode(' ',$args);
    // because composer started using an include() instead of symlink, the #!/shebang line was occuring before `namespace Composer` & causing errors
    // so now we use `passthru` here to execute the vendor script rather than include it
    passthru($cmd);
    return;
}

// always require() the current package's autoloader
$cwd_autoload = getcwd().'/vendor/autoload.php';
if (!is_file($cwd_autoload)){
    echo "\n\nAutoloader file '$cwd_autoload' not found. "
        ."\n\nphptest must be run from the project root & autoload must be present at vendor/autoload.php"
        ."\n\n";
    return;
}
require($cwd_autoload);

// if global phptest is called & there is NOT a package-level install, then require the global install's autoloader
$global_test_autoload = dirname(__DIR__).'/vendor/autoload.php';
if (is_file($global_test_autoload)&&realpath($cwd_autoload)!=realpath($global_test_autoload)){
    require($global_test_autoload);
}

$dir = getcwd();

$cli = $runner = new \Tlf\Tester\Runner();

$cli->load_inputs(json_decode(file_get_contents(__DIR__.'/../src/defaults.json'),true));

$runner->load_configs($cli, $dir, $cli->args);

$runner->setup_commands($cli);

$cli->load_stdin();

$cli->args = $runner->initialize($cli, $cli->args);

//$runner->backward_compatability();
$runner->execute();
{
    "name": "taeluf/tester",
    "description": "A unit testing library for Php.",
    "type": "library",
    "license": "MIT",
    "autoload": {
        "classmap": ["src/"]
    },
    "require": {
        "taeluf/cli": "v0.1.x-dev",
        "taeluf/util": "v0.1.x-dev"
    },
    "require-dev": {
        "taeluf/code-scrawl": "v0.6.x-dev"
    },
    "bin":[
        "bin/phptest"
    ],
    "minimum-stability":"dev"
}
{
    "_readme": [
        "This file locks the dependencies of your project to a known state",
        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
        "This file is @generated automatically"
    ],
    "content-hash": "ea3f71ca5d56ef7a04f5d807c8160e53",
    "packages": [
        {
            "name": "taeluf/cli",
            "version": "v0.1.x-dev",
            "source": {
                "type": "git",
                "url": "git@gitlab.com:taeluf/php/cli.git",
                "reference": "d03a92e917940ed991989cf3adca803db281e5c5"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Fcli/repository/archive.zip?sha=d03a92e917940ed991989cf3adca803db281e5c5",
                "reference": "d03a92e917940ed991989cf3adca803db281e5c5",
                "shasum": ""
            },
            "require-dev": {
                "taeluf/code-scrawl": "v0.8.x-dev"
            },
            "default-branch": true,
            "bin": [
                "bin/tlf-cli"
            ],
            "type": "library",
            "autoload": {
                "files": [],
                "classmap": [
                    "src"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "time": "2023-11-29T03:43:03+00:00"
        },
        {
            "name": "taeluf/util",
            "version": "v0.1.x-dev",
            "source": {
                "type": "git",
                "url": "git@gitlab.com:taeluf/php/php-utilities.git",
                "reference": "95524064e9be1b587064c1661980fee20793a1a3"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Fphp-utilities/repository/archive.zip?sha=95524064e9be1b587064c1661980fee20793a1a3",
                "reference": "95524064e9be1b587064c1661980fee20793a1a3",
                "shasum": ""
            },
            "require-dev": {
                "taeluf/code-scrawl": "v0.8.x-dev",
                "taeluf/phtml": "v0.1.x-dev",
                "taeluf/tester": "v0.3.x-dev"
            },
            "default-branch": true,
            "type": "library",
            "autoload": {
                "classmap": [
                    "code"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "description": "Utility methods",
            "time": "2023-12-09T08:23:28+00:00"
        }
    ],
    "packages-dev": [
        {
            "name": "taeluf/better-regex",
            "version": "v0.3.x-dev",
            "source": {
                "type": "git",
                "url": "https://gitlab.com/taeluf/php/better-regex.git",
                "reference": "37164cb7aa2537b3623529ff68db6d85de343cd1"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Fbetter-regex/repository/archive.zip?sha=37164cb7aa2537b3623529ff68db6d85de343cd1",
                "reference": "37164cb7aa2537b3623529ff68db6d85de343cd1",
                "shasum": ""
            },
            "default-branch": true,
            "type": "library",
            "autoload": {
                "classmap": [
                    "code"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "support": {
                "issues": "https://gitlab.com/taeluf/php/better-regex/-/issues",
                "source": "https://gitlab.com/taeluf/php/better-regex/-/tree/v0.3"
            },
            "time": "2021-09-18T21:27:33+00:00"
        },
        {
            "name": "taeluf/code-scrawl",
            "version": "v0.6.x-dev",
            "source": {
                "type": "git",
                "url": "https://gitlab.com/taeluf/php/CodeScrawl.git",
                "reference": "0fb89ccab79df026272980a23684df1f5d5530f8"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2FCodeScrawl/repository/archive.zip?sha=0fb89ccab79df026272980a23684df1f5d5530f8",
                "reference": "0fb89ccab79df026272980a23684df1f5d5530f8",
                "shasum": ""
            },
            "require": {
                "taeluf/better-regex": "v0.3.x-dev",
                "taeluf/cli": "v0.1.x-dev",
                "taeluf/lexer": "v0.7.x-dev"
            },
            "require-dev": {
                "taeluf/tester": "v0.3.x-dev"
            },
            "bin": [
                "bin/scrawl"
            ],
            "type": "library",
            "autoload": {
                "classmap": [
                    "code/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "description": "A documentation generation framework with some built-in extensions for exporting comments and code, and importing into markdown. ",
            "support": {
                "issues": "https://gitlab.com/taeluf/php/CodeScrawl/-/issues",
                "source": "https://gitlab.com/taeluf/php/CodeScrawl/-/tree/v0.6"
            },
            "time": "2022-02-10T19:40:19+00:00"
        },
        {
            "name": "taeluf/lexer",
            "version": "v0.7.x-dev",
            "source": {
                "type": "git",
                "url": "https://gitlab.com/taeluf/php/lexer.git",
                "reference": "4e2006fc85243139d8233448d35cd769459a249e"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Flexer/repository/archive.zip?sha=4e2006fc85243139d8233448d35cd769459a249e",
                "reference": "4e2006fc85243139d8233448d35cd769459a249e",
                "shasum": ""
            },
            "require-dev": {
                "taeluf/tester": "v0.3.x-dev"
            },
            "type": "library",
            "autoload": {
                "classmap": [
                    "code"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "description": "A declarative lexer seamlessly hooking into php functions, building ASTs for multiple languages.",
            "support": {
                "issues": "https://gitlab.com/taeluf/php/lexer/-/issues",
                "source": "https://gitlab.com/taeluf/php/lexer/-/tree/v0.7"
            },
            "time": "2022-02-14T15:36:08+00:00"
        }
    ],
    "aliases": [],
    "minimum-stability": "dev",
    "stability-flags": {
        "taeluf/cli": 20,
        "taeluf/util": 20,
        "taeluf/code-scrawl": 20
    },
    "prefer-stable": false,
    "prefer-lowest": false,
    "platform": [],
    "platform-dev": [],
    "plugin-api-version": "2.6.0"
}
{
    "dir.docs": "doc",
    "dir.src": "docsrc",
    "dir.scan": ["src", "test"],
    "file.conf": ".config\/scrawl.json",
    "file.code.ext": "*",
    "file.template.ext": ".src.md",
    "deleteExistingDocs": true,
    "markdown.preserveNewLines": true,
    "markdown.prependGenNotice": true,
    "scrawl.ext": [],
    "autoload": {
        "classmap": []
    },
    "readme.copyFromDocs": true,
    "ext.PhpApiScraper": false,
    "lex": false
}
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
  
---  
  
# v0.2 Status.md (nov 24, 2021)  
  
## Latest  
- add handling for `testDirs` config so only php files in the configured test dirs are automatically `include`d  
- add `set_error_handler` config. set `false` to disable tester's built in handler.  
- set `$this->options` BEFORE calling `$this->prepare()`  
- add `dir.require` config which accepts an array & will `require_once` each `.php` file in the directory (NOT recursive)  
- Print newlines as literal `\n` in array output  
- add `file.require` option, which takes an array & automatically `require`s any files in that array (relative to the current working directory)  
- add `results.writeHtml` config. Set `false` to disable writing an html results file  
- Add automatic assertions, where you can just call any existing function & it is treated as an assertion. Except you call it like `$this->array_key_exists(...)` to use `array_key_exists(...)` as an assertion.  
- `phptest -test TestName` now ONLY runs the named test. You might be able to specify multiple `-test`s... but I haven't tested it.  
- Create `Assertions` trait to group assertions  
- fixed bug with a throw/catch not marking test as passed  
- Different location for config files allowed  
- Improved cli output  
- Added `-test TestName` option to cli invocation to display extended output of a single test in cli  
- Added `Databasing` trait to make some db operations a little easier.  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# Tester - Unit Testing for Php  
Unit testing library. [phpunit](https://phpunit.de) has more features & community.  
  
## Install  
```bash  
composer require taeluf/tester v0.3.x-dev   
```  
or in your `composer.json`  
```json  
{"require":{ "taeluf/tester": "v0.3.x-dev"}}  
```  
  
  
## Run Tests | CLI Interface  
Call `phptest` or `vendor/bin/phptest` from your project's root dir.   
  
A globally installed `phptest` will execute the `vendor/bin/phptest` copy if it exists.  
  
```bash  
phptest # simply run tests  
  
phptest init # Create test dir & example test files  
  
phptest server # launch test server using default settings  
phptest server server_name # launch a configured server  
phptest server -host.override "https://example.com" # typically server tests will use a localhost address. This overrides the host in all tests, even if you have a multi-server setup.  
  
phptest -test TestName # Run one test; display all output for the named test  
phptest -test TestName -test Another Test # Run all named tests  
phptest -class ClassName # Run all tests for a class. Do not include namespace. Can include multiple classes.  
  
phptest -custom_key SomeValue # For any tests that allow custom input from CLI.  
```  
  
Other Options:  
```bash  
-class ClassName -test TestName # Only run TestName for the given ClassName  
-prettyPrintArray true # Not sure if this works. To print array comparisons on multiple lines. By default output is condensed.  
-set_error_handler false # Not sure if this works. Enable the built-in error handler that causes all warnings, etc, to throw an exception.  
-bench.threshold 0.001 # Only print benchmark for tests taking longer than 1 ms to run. `0.001` is configurable.  
```  
  
## Example Test class  
See the available assertions below  
```php  
<?php  
  
namespace Tlf\Tester\Test\Runner;  
  
class NestedTest extends \Tlf\Tester {  
  
    /** called before tests are run */  
    public function prepare(){}  
  
    /** Test methods must prefix with `test` */  
    public function testAnything(){  
        $this->compare(true,true);  
    }  
}  
```  
  
## Sample config  
`test/config.json` is optional, but recommended. Any values not in your `config.json` will be filled by the defaults below.  
  
Default `config.json`:  
```json  
{  
    "dir.test":["test/run"],  
    "dir.exclude":[],  
    "file.require":[],  
  
    "results.writeHtml":false,  
  
    "bench.threshold": 0.0001,  
  
    "server.main": "main",  
    "server":{  
        "main": {   
            "dir":"test/Server",  
            "bootstrap":"bootstrap.php",  
            "deliver":"deliver.php",  
            "host": "http://localhost"  
        }  
    }  
}  
```  
  
## Assertions  
For docs/details, see [src/Tester/Assertions.php](/src/Tester/Assertions.php)  
  
```php  
isInstanceOf($object, $shouldBe)  
is_object($object)  
is_false($value)  
is_true($value)  
str_contains($str, $target, ...$strings)  
str_not_contains(string $str, $target, ...$strings)  
compare($target, $actual,$strict=false)  
compare_raw($target, $actual, $strict=false)  
compare_arrays($target, $actual, $strict=false)  
compare_objects($target, $actual, $strict=false)  
compare_json($target, $actual, $strict=false)  
str_contains_lines($str, $target)  
compare_lines($target, $actual)  
compare_dump($target, $actual)  
```  
  
There is also a magic `__call()` which will invoke an existing PHP function and use it's return value as an assertion.   
  
For example, `$this->in_array('value', $array_to_test);` will `pass` if PHP's `in_array()` method returns `true`  
  
## Alternate Installation  
This also requires [code-scrawl](https://tluf.me/code-scrawl) for development, which is not handled by this script.    
copy+paste this into a bash terminal  
```bash  
pwd="$(pwd)";  
command="phptest"  
downloadDir=~/.gitclone  
mkdir -p "$downloadDir"  
cd "$downloadDir"  
git clone https://gitlab.com/taeluf/php/php-tests.git ${command}   
echo "alias ${command}=\"${downloadDir}/${command}/code/phptest\"" >> ~/.bashrc  
chmod ug+x "${downloadDir}/${command}/code/phptest"  
cd "$pwd";  
source ~/.bashrc  
echo "You can now run \`${command}\`"  
```  
  
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
<!-- Project Classlist generated by ast/ApiReadme template. -->  
<!-- To Disable: Set api.generate_readme = false in your config.json -->  
# All Classes  
Browse 20 classes &amp; traits in this project. There are 7 source classes, 7 test classes, and 6 traits.  
  
*Note: As of Dec 23, 2023, only classes &amp; traits are listed. interfaces &amp; enums are not supported.*  
  
## Source Classes (not tests)  
- [`FakeServer`](src/FakeServer.php.md): Used to run a php script as if an HTTP request had been made.    
- [`Utility`](src/Utility.php.md): No description...    
- [`Tester`](src/Tester.php.md): Base class for test classes    
- [`Runner`](src/Runner.php.md): No description...    
- [`ExceptionCatcher`](src/ExceptionCatcher.php.md): No description...    
- [`CurlBrowser`](src/CurlBrowser.php.md): No description...    
- [`Tester`](src/BackwardCompatTester.php.md):     
  
  
## Traits  
- [`Utilities`](src/Tester/Utilities.php.md): Convenience methods to call from inside tests    
- [`Server`](src/Tester/Server.php.md): convenience methods for server-related tests  
    Server-related assertions may go here too    
- [`Other`](src/Tester/Other.php.md): Stuff that doesn't belong in other traits & isn't about the core execution of tests    
- [`Exceptions`](src/Tester/Exceptions.php.md): Assert exceptions    
- [`Databasing`](src/Tester/Databasing.php.md): Convenience methods for database work    
- [`Assertions`](src/Tester/Assertions.php.md): See the Exceptions trait for exception-based assertions  
    See the `Other` trait for invert(), disable(), and other methods that are important but are not assertions    
  
  
## Test Classes   
- [`Tester`](test/Tester.php.md): Base class for your test classes    
- [`Runner`](test/run/Runner.php.md): No description...    
- [`Server`](test/run/Server.php.md): No description...    
- [`Exceptions`](test/run/Exceptions.php.md): No description...    
- [`Compare`](test/run/Compare.php.md): No description...    
- [`Browser`](test/run/Browser.php.md): No description...    
- [`NestedTest`](test/input/Runner/run/Test.php.md): No description...    
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/BackwardCompatTester.php  
  
# class Taeluf\Tester  
  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function backward_compatability()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/CurlBrowser.php  
  
# class Tlf\Tester\CurlBrowser  
  
  
## Constants  
  
## Properties  
- `public string $default_host;` The default host to connect to, such as http://localhost:3183  
- `public array $responses = [];` Array of responses as built by `curl_get_response()`, in the order they were received  
  
## Methods   
- `public function __construct(string $default_host = null)`   
- `public function __toString()` the body of the last response  
- `public function last()`   
- `public function follow()` Follow the redirect sent with the last request  
- `public function get($path, $params=[], $headers[], $curl_opts  [])`   
- `public function post($path, $params=[], $headers[], $files[], $curl_opts  [])` @beta  
  
- `public function make_url(string $url, array $params=[]): string`   
- `public function parse_cookie_header($header_value): array`   
- `public function curl_add_files($ch, array $files, array $params)`   
- `public function curl_get_response($ch)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/ExceptionCatcher.php  
  
# class Tlf\Tester\ExceptionCatcher  
  
  
## Constants  
  
## Properties  
- `protected $strict;`   
- `protected $targetClass;`   
- `protected $contains = [];`   
  
## Methods   
- `public function __construct($expectingClass, $strict=false)`   
- `public function containing($msg)`   
- `public function shortenMessage($msg)`   
- `public function matches($exception)`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/FakeServer.php  
  
# class Tlf\Tester\FakeServer  
Used to run a php script as if an HTTP request had been made.  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function send_request(string $deliver_file, string $url, string $method = "GET", array $params  []): string` Set up the $_SERVER, $_GET, and $_POST global variables accordingly, require the $deliver_file, and return its output.   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Runner.php  
  
# class Tlf\Tester\Runner  
  
  
## Constants  
  
## Properties  
- `public $server_port = [];`   
  
## Methods   
- `public function setup_commands(\Tlf\Cli $cli)` Load all commands onto the cli  
- `public function initialize(\Tlf\Cli $cli, array $args): array` Initialize the runner and return array of cli arguments,   
  
- `public function load_configs(\Tlf\Cli $cli, string $dir, array $args)` Load config file from disk  
  
- `public function get_server_host(string $name='main'): string` get the server host   
- `public function get_host_port(string $server_name): int`   
- `public function print_config(\Tlf\Cli $cli, array $args)`   
- `public function start_server(\Tlf\Cli $cli, array  $args)` Start a localhost server for testing  
- `public function init(\Tlf\Cli $cli, array $args)` Copies sample test files into `getcwd().'/test'`  
- `public function require_directory(string $path)` Require every php file within a directory  
- `public function run_dir(\Tlf\Cli $cli, array $args): array` executes all tests inside test directories (config `dir.test`)  
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Tester.php  
  
# class Tlf\Tester  
Base class for test classes  
  
## Constants  
  
## Properties  
- `protected $catchers = [];`   
- `protected $assertions = ['pass'=> 0, 'fail'=>0];` Comparisons from a single test. Should be reset between tests.  
- `protected $enabled = true;`   
- `protected $options = [];`   
- `public $cli = null;` The cli class used to run the tests  
- `public string $current_test = null;` The string name of the method being called for the current test. Like `"testSomething"`  
  
## Methods   
- `public function __construct(array $options=[], $clinull)`   
- `public function throwError($errno, $errstr, $errfile, $errline)`   
- `public function onBeforeTest()`   
- `public function backward_compatability()`   
- `public function get_test_methods()` Get array of test methods names  
- `public function get_test_name($method_name): string` get a readable name from a test method name  
- `public function run_test_method($method)`   
- `public function print_test_results($test)`   
- `public function run()` Run tests  
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File src/Utility.php  
  
# class Tlf\Tester\Utility  
  
  
## Constants  
  
## Properties  
  
## Methods   
- `static public function xdotoolRefreshFirefox($switchBackToWindow = false)`   
- `static public function startOb()`   
- `static public function endOb($ob_level)`   
- `static public function getClassFromFile($file)` dependency on Util added on Dec 8, 2022.  
- `static public function getAllFiles($dir,$relativeTo='', $endingWith'')` Get all files in a directory. Does not return directories  
  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/Tester.php  
  
# class Tlf\Tester\Test\Tester  
Base class for your test classes  
  
## Constants  
  
## Properties  
  
## Methods   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/input/Runner/run/Test.php  
  
# class Tlf\Tester\Test\Runner\NestedTest  
  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function prepare()` called before tests are run  
- `public function testAnything()` Test methods must prefix with `test`  
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/run/Browser.php  
  
# class Tlf\Tester\Test\Browser  
  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function testPostFile()`   
- `public function testBrowserPost()`   
- `public function testBrowserFollow()`   
- `public function testBrowserGetParam()`   
- `public function testBrowserGet()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/run/Compare.php  
  
# class Tlf\Tester\Test\Compare  
  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function testCompareLines()`   
- `public function testUnsortedArray()`   
- `public function testComparePHPFileToString()`   
- `public function testCompareFileToStringStrict()`   
- `public function testCompareFileToStringLoose()`   
- `public function testComparestringsWithDiffPad()`   
- `public function testCompareStringsThatMatch()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/run/Exceptions.php  
  
# class Tlf\Tester\Test\Exceptions  
  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function testTriggerError()`   
- `public function testThrowException()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/run/Runner.php  
  
# class Tlf\Tester\Test\Runner  
  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function testRunnerResults()`   
  
<!-- DO NOT EDIT. This file generated from template by Code Scrawl https://tluf.me/php/code-scrawl/ -->  
# File test/run/Server.php  
  
# class Tlf\Tester\Test\Server  
  
  
## Constants  
  
## Properties  
  
## Methods   
- `public function testMultiServer1()`   
- `public function testMultiServer2()`   
- `public function testRequestMethod()`   
- `public function testFileUpload()`   
- `public function testPostRedirect()`   
- `public function testServer()`   
  

---

# v0.2 Status.md (nov 24, 2021)

## Latest
- add handling for `testDirs` config so only php files in the configured test dirs are automatically `include`d
- add `set_error_handler` config. set `false` to disable tester's built in handler.
- set `$this->options` BEFORE calling `$this->prepare()`
- add `dir.require` config which accepts an array & will `require_once` each `.php` file in the directory (NOT recursive)
- Print newlines as literal `\n` in array output
- add `file.require` option, which takes an array & automatically `require`s any files in that array (relative to the current working directory)
- add `results.writeHtml` config. Set `false` to disable writing an html results file
- Add automatic assertions, where you can just call any existing function & it is treated as an assertion. Except you call it like `$this->array_key_exists(...)` to use `array_key_exists(...)` as an assertion.
- `phptest -test TestName` now ONLY runs the named test. You might be able to specify multiple `-test`s... but I haven't tested it.
- Create `Assertions` trait to group assertions
- fixed bug with a throw/catch not marking test as passed
- Different location for config files allowed
- Improved cli output
- Added `-test TestName` option to cli invocation to display extended output of a single test in cli
- Added `Databasing` trait to make some db operations a little easier.
# Tester - Unit Testing for Php
Unit testing library. @hard_link(https://phpunit.de, phpunit) has more features & community.

## Install
@template(php/composer_install, taeluf/tester)

## Run Tests | CLI Interface
Call `phptest` or `vendor/bin/phptest` from your project's root dir. 

A globally installed `phptest` will execute the `vendor/bin/phptest` copy if it exists.

```bash
phptest # simply run tests

phptest init # Create test dir & example test files

phptest server # launch test server using default settings
phptest server server_name # launch a configured server
phptest server -host.override "https://example.com" # typically server tests will use a localhost address. This overrides the host in all tests, even if you have a multi-server setup.

phptest -test TestName # Run one test; display all output for the named test
phptest -test TestName -test Another Test # Run all named tests
phptest -class ClassName # Run all tests for a class. Do not include namespace. Can include multiple classes.

phptest -custom_key SomeValue # For any tests that allow custom input from CLI.
```

Other Options:
```bash
-class ClassName -test TestName # Only run TestName for the given ClassName
-prettyPrintArray true # Not sure if this works. To print array comparisons on multiple lines. By default output is condensed.
-set_error_handler false # Not sure if this works. Enable the built-in error handler that causes all warnings, etc, to throw an exception.
-bench.threshold 0.001 # Only print benchmark for tests taking longer than 1 ms to run. `0.001` is configurable.
```

## Example Test class
See the available assertions below
```php
@file(test/input/Runner/run/Test.php)
```

## Sample config
`test/config.json` is optional, but recommended. Any values not in your `config.json` will be filled by the defaults below.

Default `config.json`:
```json
@file(src/defaults.json)
```

## Assertions
For docs/details, see @see_file(src/Tester/Assertions.php)

```php
isInstanceOf($object, $shouldBe)
is_object($object)
is_false($value)
is_true($value)
str_contains($str, $target, ...$strings)
str_not_contains(string $str, $target, ...$strings)
compare($target, $actual,$strict=false)
compare_raw($target, $actual, $strict=false)
compare_arrays($target, $actual, $strict=false)
compare_objects($target, $actual, $strict=false)
compare_json($target, $actual, $strict=false)
str_contains_lines($str, $target)
compare_lines($target, $actual)
compare_dump($target, $actual)
```

There is also a magic `__call()` which will invoke an existing PHP function and use it's return value as an assertion. 

For example, `$this->in_array('value', $array_to_test);` will `pass` if PHP's `in_array()` method returns `true`

## Alternate Installation
This also requires @easy_link(tlf, code-scrawl) for development, which is not handled by this script.  
copy+paste this into a bash terminal
@template(bash/install, phptest, code/phptest)


<?php

namespace Taeluf;

/**
 * @todo delete this class
 */
class Tester extends \Tlf\Tester {

    public function backward_compatability(){
        parent::backward_compatability();

        echo "\n\n-------NOTICE--------";
        echo "\n       class Taeluf\\Tester is now class Tlf\\Tester     ";
        echo "\n     update ". get_class($this)." to extend from \\Tlf\\Tester";
        echo "\n     \\Taeluf\\Tester will be removed in v0.4";
        echo "\n";
    }
}
<?php

namespace Tlf\Tester;

class CurlBrowser {

    /**
     * The default host to connect to, such as http://localhost:3183
     */
    public string $default_host;


    /**
     * Array of responses as built by `curl_get_response()`, in the order they were received
     */
    public array $responses = [];

    public function __construct(?string $default_host = null){
        $this->default_host = $default_host;
    }

    /**
     * the body of the last response
     */
    public function __toString(){
        return end($this->responses)['body'];
    }


    /**
     * @return the last response or false if no responses
     */
    public function last(){
        return end($this->responses);
    }

    /**
     * Follow the redirect sent with the last request
     * @return true if a redirect happened, false if there was no `Location` header to goto
     */
    public function follow(){
        $response = end($this->responses);
        if (!isset($response['headers']['Location']))return false;

        $this->get($response['headers']['Location']);
         
        return true;
    }

    public function get($path, $params=[], $headers=[], $curl_opts = []){
        $ch = curl_init();

        $url = $this->make_url($path,$params);

        if (isset($headers['Cookie'])){
            $cookie = $headers['Cookie'];
            unset($headers['Cookie']);
            curl_setopt($ch, CURLOPT_COOKIE, $cookie);
        }

        $curl_headers = [];
        foreach ($headers as $key=>$value){
            if (is_int($key)){
                $curl_headers[] = $value;
                continue;
            }
            $curl_headers[] = $key.': '.$value;
        }

        curl_setopt_array($ch,
            [
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POST => false,
            CURLOPT_HEADER => true,
            CURLOPT_FOLLOWLOCATION => false,
            CURLOPT_HTTPHEADER => $curl_headers,
            ]
        );


        if (count($curl_opts) > 0 ){
            curl_setopt_array($ch, $curl_opts);
        }


        $response = $this->curl_get_response($ch);
        curl_close($ch);

        $this->responses[] = $response;
        return $response;
    }

    /**
     *
     * @beta
     *
     * @param $params POST params
     * @param $headers array like `['HeaderKey: header_value', 'Cookie'=> 'cookie_key=cookie_value;cookie2=value2;']` ... ONLY `Cookie` should have an array key. All other header keys should be in the array value and use a numeric index
     * @param $files ... idr
     * @param $curl_opts array of php `CURLOPT`s to set
     */
    public function post($path, $params=[], $headers=[], $files=[], $curl_opts = []){
        $ch = curl_init();

        $url = $this->make_url($path,[]);

        if (isset($headers['Cookie'])){
            $cookie = $headers['Cookie'];
            unset($headers['Cookie']);
            curl_setopt($ch, CURLOPT_COOKIE, $cookie);
        }
        $curl_headers = [];
        foreach ($headers as $key=>$value){
            if (is_int($key)){
                $curl_headers[] = $value;
                continue;
            }
            $curl_headers[] = $key.': '.$value;
        }

        foreach ($files as $key=>$f){
            if (!is_file($f)){
                throw new \Exception("File '$f' for key '$key' does not exist or is not a file.");
            }
            $cf = new \CURLFile($f, null, basename($f));
            $params[$key] = $cf;
        }
        if (is_string($params)){
            $post_fields = $params;
        }else if (count($files) > 0){
            $post_fields = $params;
        } else {
            $post_fields = http_build_query($params);
        }

        curl_setopt_array($ch,
            [
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POST => true,
            CURLOPT_POSTFIELDS => $post_fields,
            CURLOPT_HEADER => true,
            CURLOPT_FOLLOWLOCATION => false,
            CURLOPT_HTTPHEADER => $curl_headers,
            ]
        );

        if (count($curl_opts) > 0 ){
            foreach ($curl_opts as $key=>$value){
                curl_setopt($ch, $key, $value);
            }
            // curl_setopt_array($ch, $curl_opts);
        }

        $response = $this->curl_get_response($ch);
        curl_close($ch);
        $this->responses[] = $response;
        return $response;
    }

    /**
     * @param $url the url to connect to. if default_host is set, just needs a path
     * @param $params array of paramaters to encode into the url. If your url path includes `?params=whatever`, it will not play nicely with this.
     */
    public function make_url(string $url, array $params=[]): string {
        $parsed = parse_url($url);
        if (!isset($parsed[PHP_URL_HOST]))$url = $this->default_host.$url;

        if ($params!=[]) $url .= '?' . http_build_query($params);
        return $url;
    }


    /**
     * @param $header_value, for `Set-cookie: whatever whatever`, this should be `whatever whatever`
     * @return array parsed cookie
     *
     *
     * @issue has no handling for a cookie value containing a semi-colon or an equal sign
     */
    public function parse_cookie_header($header_value): array {
        $cookie = [];
        $parts = explode(';', $header_value);
        $parts = array_map('trim',$parts);

        $main = array_shift($parts);
        $main_parts = explode('=', $main);
        $cookie['name'] = $main_parts[0];
        $cookie['value'] = $main_parts[1];


        foreach ($parts as $str){
            $kv_parts = explode('=', $str);
            if (count($kv_parts)==1)$cookie[$str] = true;
            else $cookie[$kv_parts[0]] = $kv_parts[1];
        }
        return $cookie;
    }


    /**
     * @param $ch curl handle
     * @param $files array of key=>absolute file paths
     * @param $params array to use as CURLOPT_POSTFIELDS
     */
    public function curl_add_files($ch, array $files, array &$params){
        foreach ($files as $name=>$path){
            $mimetype = mime_content_type($path);
            // $mimetype = false;
            if ($mimetype==false){
                $ext = pathinfo($path,PATHINFO_EXTENSION);
                $list = require(dirname(__DIR__).'/mime_type_map.php');
                $mimetype = $list['mimes'][$ext][0];
            }
            $params[$name] = new \CURLFile($path, $mimetype, basename($path));
        }
    }

    public function curl_get_response($ch){
        $response = curl_exec($ch);

        $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);

        $header_text = substr($response,0,$header_size);

        $parts = explode("\n", $header_text);
        $parts = array_map('trim', $parts);
        $headers = [];
        $cookies = [];
        foreach ($parts as $line){
            $pos = strpos($line,':');
            if ($pos===false)continue;
            $key = substr($line,0,$pos);
            $value = trim(substr($line,$pos+1));
            if (isset($headers[$key])){
                if (!is_array($headers[$key]))$headers[$key] = [$headers[$key]];
                $headers[$key][] = $value;
            } else {
                $headers[$key] = $value;
            }
            if ($key=='Set-Cookie'){
                $cookie = $this->parse_cookie_header($value);
                $cookies[$cookie['name']] = $cookie;
            }
        }

        // TODO: parse Set-Cookie headers 

        $body = substr($response,$header_size);
        return [
            'header_text'=>$header_text,
            'body'=>$body,
            'headers'=>$headers,
            'cookies'=>$cookies,
        ];
    }
}
<?php

namespace Tlf\Tester;

class ExceptionCatcher {

    protected $strict;
    protected $targetClass;
    protected $contains = [];

    public function __construct($expectingClass, $strict=false){
        $this->strict = $strict;
        $this->targetClass = $expectingClass;
    }

    public function containing($msg){
        $this->contains[] = $msg;
        return $this;
    }

    public function shortenMessage($msg){
        $oneLine = implode(" ",array_map('trim',explode("\n",$msg)));
        $output = substr($oneLine,0,200);
        if (strlen($output)>200)$output .= '...';

        return $output;
    }

    public function matches($exception){
        //@TODO improve error output for exception testing. I'd like to report failures with details as well
        $strict = $this->strict;
        $eClass = get_class($exception);
        $eMessage = $exception->getMessage();
        if ($strict
            &&$eClass!=$this->targetClass)return false;
        else if (!($exception instanceof $this->targetClass))return false;

        foreach ($this->contains as $str){
            if (strpos($eMessage,$str)===false){
                return false;
            }
        }

        
        $output = $this->shortenMessage(var_export($this->contains,true));
        $eMessage = $this->shortenMessage(var_export($eMessage,true));



        echo "+++pass-exception+++";
        if ($strict)echo "\n strict classname comparison";
        echo "\nTarget:";
        echo "\n- Class: {$this->targetClass}";
        echo "\n- Containing: ".$output;
        echo "\n--";
        echo "\nActual:";
        echo "\n- Class: ".$eClass;
        echo "\n- Msg: ".$eMessage;

        echo "\n------------\n";
        return true;
    }

}
<?php

namespace Tlf\Tester;

/**
 * Used to run a php script as if an HTTP request had been made.
 */
class FakeServer {


    /**
     * Set up the $_SERVER, $_GET, and $_POST global variables accordingly, require the $deliver_file, and return its output. 
     */
    public function send_request(string $deliver_file, string $url, string $method = "GET", array $params = []): string {
        $orig_server = $_SERVER;
        $orig_GET = $_GET;
        $orig_POST = $_POST;

        try {
            // @todo support adding get params to uri
            $_SERVER['REQUEST_URI'] = $url;
            if ($method == "GET") $_GET = $params;
            else if ($method=="POST") $_POST = $params;

            ob_start();
            require($deliver_file);
            $output = ob_get_clean();

        } catch (\Exception $e){

            $_SERVER = $orig_server;
            $_GET = $orig_GET;
            $_POST = $orig_POST;
            throw $e;
        }

        $_SERVER = $orig_server;
        $_GET = $orig_GET;
        $_POST = $orig_POST;

        return $output;

    }

}
<?php

namespace Tlf\Tester;

class Runner extends \Tlf\Cli {

    public $server_port = [];

    /**
     * Load all commands onto the cli
     * @param $cli \Tlf\Cli cli lib
     */
    public function setup_commands(\Tlf\Cli $cli){
        $commands = [
            // command => [method_name, Help Text]
            'main'=>['run_dir', "Run Tests"],
            'init' => ['init', "Initialize test directory"],
            'server' => ['start_server', "Start test server. Optionally pass configured server name as first arg."],
            'print-config' => ['print_config', "Print runtime configuration (on-disk + defaults + cli args]"],

        ];

        foreach ($commands as $command => $method_help){
            $cli->load_command($command, [$this, $method_help[0]], $method_help[1]);
        }
    }

    /**
     * Initialize the runner and return array of cli arguments, 
     *
     * @param $cli \Tlf\Cli cli lib
     * @param $args array of cli args + configs
     * @return array of args to use for cli
     */
    public function initialize(\Tlf\Cli $cli, array $args): array {
    
        return $args;
    }

    /**
     * Load config file from disk
     * 
     * @param $cli \Tlf\Cli cli lib
     * @param $dir working directory from which to load a config file
     * @param $args array of cli args + configs
     */
    public function load_configs(\Tlf\Cli $cli, string $dir, array $args){
        $locations = [
            '.config/phptest.json',
            'config/phptest.json',
            'test/config.json',
        ];
        foreach ($locations as $file){
            $path = $dir.'/'.$file;
            if (is_file($path)){
                $configs = json_decode(file_get_contents($path),true);
                if (!is_array($configs)){
                    error_log("File '$file' does not contain valid json");
                } else {
                    $cli->load_inputs($configs);
                }
            }
        }
    }

    /**
     * get the server host 
     * @if called by `phptest server`, @then generate random port & write to file
     * @if called by running `->get()` tests, @then load port from file
     *
     */
    public function get_server_host(string $name='main'): string{

        $host = $this->args['host.override'] ?? $this->args['server'][$name]['host'] ?? 'http://localhost';
        if ($host=='http://localhost')$host .= ":".$this->get_host_port($name);
        else if ($host=='https://localhost')$host .= ":".$this->get_host_port($name);

        return $host;
    }

    public function get_host_port(string $server_name): int {
        if (!isset($this->args['server'][$server_name])){
            $this->report("Server '$server_name' is not configured. Cannot create/load host port.");
            throw new \Exception("Server '$server_name' is not configured. Cannot create/load host port.");
            return 0;
        }
        $server = $this->args['server'][$server_name];
        $dir = $this->pwd.'/'.$server['dir'];
        $port_file = $dir.'/.phptest-port';
        if (file_exists($port_file)){
            return (int)trim(file_get_contents($port_file));
        }


        if ($this->command != 'server'){
            $dir_name = $server['dir'];
            $msg = "Host is not stored. File '$dir_name/.phptest-port' should contain an integer port number.";
            $this->report($msg);
            throw new \Exception($msg);
        }

        $port = random_int(3001, 5000);
        file_put_contents($port_file, $port);
        return $port;
    }

    public function print_config(\Tlf\Cli $cli, array $args){
        echo "\n\n";
        echo json_encode($args, JSON_PRETTY_PRINT);
        echo "\n\n";
    }

    /**
     * Start a localhost server for testing
     * @warning this early implementation will change
     */
    public function start_server(\Tlf\Cli $cli, array  $args){
        $server_name = $args['--'][0] ?? $args['server.main'];
        if (!isset($args['server'][$server_name])){
            $this->report("Test server '$server_name' not configured.");
            return false;
        }
        $server = $args['server'][$server_name];
        $host = $this->get_server_host($server_name);
        $dir = $server['dir'];

        $dir = str_replace("//","/", $dir);
        if (substr($dir,0,1)=='/')$dir= substr($dir,1);
        if ($dir == "")$dir = "./";

        $deliver = $dir.'/'.($server['deliver'] ?? 'deliver.php');
        $deliver = str_replace("//","/", $deliver);

        $bootstrap = $dir.'/'.($server['bootstrap'] ?? 'bootstrap.php');

        $deliver_absolute = getcwd().'/'.$deliver;

        //var_dump($host);
        //var_dump($deliver);

        if (!file_exists($deliver_absolute)){
            $this->report("No Deliver script found for server '$server_name'");
            return false;
        }

        if (file_exists($bootstrap)){
            $this->report("`require()` $bootstrap");
            require($bootstrap);
        }

        $host = str_replace(["http://", "https://"], "", $host);

        $command = "php -S $host -t $dir $deliver";

        $this->report("Execute:\n  $command\n\n");
        system($command);
    }

    /**
     * Copies sample test files into `getcwd().'/test'`
     */
    public function init(\Tlf\Cli $cli, array $args){
        $dir = getcwd().'/test';
        $continue = readline("Initialize test dir at $dir? (y/n) ");
        if ($continue!=='y')return;
        mkdir($dir);
        mkdir($dir.'/run');
        mkdir($dir.'/src');
        mkdir($dir.'/input');
        mkdir($dir.'/Server');
        mkdir($dir.'/input/Compare');
        $files = [
            'run/Compare.php',
            'run/Server.php',
            "Tester.php",
            'input/Compare/Compare.php',
            'input/Compare/Compare.txt',
            'Server/deliver.php',
            'bootstrap.php',
            'config.json',
        ];
        foreach ($files as $f){
            $dest = $dir.'/'.$f;
            if (file_exists($dest)){
                echo "\nSkip: $dest";
            } else {
                echo "\nCreate: $dest";
                copy(dirname(__DIR__).'/test/'.$f, $dir.'/'.$f);
            }
        }
    }

    /**
     * Require every php file within a directory
     * @param $path string absolute path to directory
     */
    public function require_directory(string $path){
        foreach (scandir($path) as $f){
            if ($f=='.'||$f=='..')continue;
            if (is_dir($path.'/'.$f)){
                $this->require_directory($path.'/'.$f);
            } else if (substr($f,-4)=='.php'){
                (function() use ($path, $f){
                    require_once($path.'/'.$f);
                })();
            }
        }
    }

    /**
     * executes all tests inside test directories (config `dir.test`)
     *
     * @param $cli 
     * @param $args
     *
     * @return array<string key, mixed value> test info w/ entries pass, fail, disabled, tests_run, class, assersions_pass, assersions_fail
     *
     */
    public function run_dir(\Tlf\Cli $cli, array $args): array {
        $info = [
            'pass'=>0,
            'fail'=>0,
            'tests_run'=>0,
            'disabled'=>0,
            'assertions_pass'=>0,
            'assertions_fail'=>0,
        ];
        $dir = $cli->pwd;

        /** @config file.require array<int index, string rel_file_name> - Array of files to require before running tests.  */
        $required_files = $args['file.require'];
        /** @config dir.test string - relative path to directory containing tests */
        $dir_to_test = $args['dir.test'];
        /** @config dir.exclude array<int index, string rel_dir_path> - relative directory paths within the test dir that should not be run. Relative to current working directory. */
        $dirs_to_exclude = $args['dir.exclude'];
        /** @argv class array<int index, string class_name> - Classes to test. If set, no other classes will be run. If not set, all test classes are run */
        $classes_to_test = $args['class'] ?? [];
        // @bugfix for some reason args['class'] isn't an array ... it should be... idk when I broke it, but this is quickfix
        if (is_string($classes_to_test))$classes_to_test = [$classes_to_test];


        /////
        // load required files & directories
        /////
        foreach ($required_files as $file){
            $path = $dir.'/'.$file;
            // var_dump($path);
            if (is_dir($path)){
                $this->require_directory($path);               
            } else if (is_file($path)){
                (function() use ($path){
                    require_once($path);
                })();
            } else {
                $this->error("File '$file' does not exist in '{$cli->pwd}'");
            }
        }

        /////
        // build array of testable classes
        /////
        $phpFiles = $this->get_php_files($dir, $dir_to_test);

        $excludes = $dirs_to_exclude;
        /** array<string absolute_file_path, string class_name> */
        $test_files = [];
        foreach ($phpFiles as $relPath){
            if ($this->is_excluded($excludes, $relPath))continue;
            $filePath = $dir.'/'.$relPath;
            $class = $this->get_test_class($filePath);
            $class_base = substr($class??'', strrpos($class??'', '\\')+1);
            if (count($classes_to_test)>0&&!in_array($class_base, $classes_to_test))continue;
            $test_files[$filePath] = $class;
        }

        /////
        // Run tests & record results
        /////

        $tests = [];
        foreach ($test_files as $file=>$class){
            if (!is_string($class))continue;
            $results = $this->test_class($class, $args,$cli);
            if ($results===false)continue;

            $info['pass']+=$results['pass'];
            $info['fail']+=$results['fail'];
            $info['disabled']+=$results['disabled'];
            $info['tests_run']+=$results['tests_run'];
            $info['class'][$class] = $results;
            $info['assertions_pass']+=$results['assert_pass'];
            $info['assertions_fail']+=$results['assert_fail'];
            // print_r($results['assertion_count']);
        }

        echo "\n";

        echo "\nTests: ".$info['tests_run'];
        echo "\nPass: ".$info['pass'];
        echo "\nFail: ".$info['fail'];
        echo "\nDisabled: ".$info['disabled'];
        echo "\n\nAssertions Passed: ".$info['assertions_pass'];
        echo "\nAssertions Failed: ".$info['assertions_fail'];

        echo "\n";

        return $info;
    }

    /**
     * Run tests on a class
     *
     * @param $class string - fully qualified class name
     * @param $args array - cli args + configs
     * @param $cli \Tlf\Cli - cli lib
     *
     * @return array test results as an array
     */
    public function test_class(string $class, array $args,\Tlf\Cli  $cli): array {
        // $ob_level = Utility::startOb();
        //run the test class
        if (!class_exists($class??'',true))return false;
        $tester = new $class($args, $cli);
        $results = $tester->run();
        // $output = Utility::endOb($ob_level);
        return $results;
    }


    /**
     * Get all php files for testing. @see(get_test_class) is used to filter out files that don't contain a test class.
     *
     * @param string $dir the root directory for the project
     * @param array $sub_dirs the sub-directories where files should be searched for
     */
    public function get_php_files(string $dir, array $sub_dirs){
        // find all files that need testing
        $files = [];
        foreach ($sub_dirs as $sub_dir){
            $search_dir = $dir.'/'.$sub_dir;
            $files = array_merge($files, \Tlf\Tester\Utility::getAllFiles($search_dir,$dir,'.php'));
        }
        return $files;
    }

    /**
     * Check if a file is excluded from testing
     *
     * @param $excludes generally, the 'dir.excludes' config
     * @param $relPath the relative path of a file that we're checking for
     * @return bool true or false
     */
    public function is_excluded(array $excludes, string $relPath): bool{
        //check if file is excluded from testing
        foreach ($excludes as $e){
            $re = $relPath;
            if ($re[0]!='/')$re = '/'.$re;
            if ($e[0]!='/')$e = '/'.$e;
            if (substr($relPath,0,strlen($e))==$e)return true;
        }
        if (in_array($relPath, $excludes))return true;

        return false;
    }

    /**
     * Get name of class in file. The class in the file must be a subclass of \Tlf\Tester
     *
     * @param $filePath string the path to the file containing a test class
     * @return class name or null
     * @side_effect require_once the file
     */
    public function get_test_class(string $filePath): ?string {

        (function() use ($filePath){
            require_once($filePath); 
        })();
        $class = Utility::getClassFromFile($filePath);
        if ($class==null){
            $this->report("No class found in $filePath");
            return null;
        }
        if (!is_a($class, '\\Tlf\\Tester', true))return null;
        return $class;
    }

    /**
     * echo the message
     *
     * @param $msg string
     */
    public function report(string $msg){
        echo "\n$msg\n";
    }
}
<?php

namespace Tlf;

/**
 * Base class for test classes
 * @note main class file executes tests. Traits contain everything you use INSIDE a test
 */
class Tester {

    use Tester\Assertions;
    use Tester\Exceptions;
    use Tester\Databasing;
    use Tester\Utilities;
    use Tester\Server;
    use Tester\Other;

    protected $catchers = [];
    /**
     * Comparisons from a single test. Should be reset between tests.
     */
    protected $assertions = ['pass'=> 0, 'fail'=>0];
    protected $enabled = true;

    protected $options = [];

    /**
     * The cli class used to run the tests
     */
    public $cli = null;

    /**
     * The string name of the method being called for the current test. Like `"testSomething"`
     */
    public ?string $current_test = null;

    /**
     * @param $options usually args passed from the command line. 
     */
    public function __construct(array $options=[], $cli=null){
        $this->backward_compatability();
        if ($cli==null)$this->options = $options;
        else $this->options = &$cli->args;//$options;
        //$this->options
        if ($this->options['set_error_handler']??true){
            set_error_handler([$this,'throwError']);
        }
        $this->cli = $cli;

        if (!isset($this->options['test']))$this->options['test'] = [];
        if (!isset($this->options['class']))$this->options['class'] = [];

    }
    public function throwError($errno, $errstr, $errfile, $errline) {
        throw new \ErrorException($errstr, $errno, 0, $errfile, $errline);
    }


    /** @beta(may 4, 2022) 
     * @param $test_name the name of the test (the portion of the method name after `test`)
     */
    public function onBeforeTest(){}
    /**
     * @deprecated This method will be removed in v0.4
     */
    public function backward_compatability(){}


    /**
     * Get array of test methods names
     * @return array like `['testMethodOne', 'testMethodTwo']`
     */
    public function get_test_methods(){
        $list = [];
        foreach (get_class_methods($this) as $method){
            if ($method=='test')continue;
            if (substr($method,0,4)!='test')continue;
            $list[] = $method;
        }

        // @TODO allow multiple 'test' params to be passed. I think this worked previously, but now it's broken.
       
        //@bugfix args['test'] is supposed to be an array ... but I think I broke it at some point. So this is_string() check is to convert it to an array
        if (is_string($this->cli->args['test']))$this->cli->args['test'] = [$this->cli->args['test']];
        if (count($this->cli->args['test'])>0){
            $tests = array_flip($this->cli->args['test']);
            $list = array_filter($list,
                function($test_name) use ($tests){
                    return isset($tests[substr($test_name,4)]);
                }
            );
        }

        return $list;
    }

    /**
     * get a readable name from a test method name
     */
    public function get_test_name($method_name): string{
        $name = $method_name;
        if (substr($method_name,0,4)=='test')$name = substr($method_name,4);

        return $name;
    }

    public function run_test_method($method){
        $name = $this->get_test_name($method);
        $test = 
        [
            'method'=>$method, 
            'error'=>null, 
            'name'=>$name,
            'pass'=>false,
            'enabled'=>$this->enabled,
        ];
        $this->onBeforeTest($name);

        $this->assertions = ['pass'=>0, 'fail'=>0];
        $this->catchers = [];
        $bench_start = microtime(true);
        $ob_level = $this->startOb();
        try {
            $this->current_test = $method;
            $this->$method();
        } catch (\Throwable $t){
            $test['error'] = $t->__toString();
            echo $test['error'];
        } 
        $this->current_test = null;
        $test['enabled'] = $this->enabled;
        $test['assertions'] = $this->assertions;
        $test['output'] = $this->endOb($ob_level);
        $test['bench'] = $this->benchEnd($bench_start);

        if ($this->assertions['pass']>=1
            &&$this->assertions['fail']===0
            &&$test['error'] === null
        ){
            $test['pass'] = true;
        }
        return $test;
    }

    public function print_test_results($test){
        $status = $test['pass'] ? 'PASS' : 'FAIL';
        $symbol = $test['pass'] ? "\033[0;32m++\033[0m" : "\033[0;31m--\033[0m";
        // print_r($test);
        // exit;
        if (in_array($test['name'], $this->options['test'])){
            if ($test['enabled']!=true)$symbol = '/';
            $str = str_repeat($symbol, 15);
            echo "\n$str ".$test['name']."[start] $str\n";
            echo $test['output'];


            if (($c=count($this->catchers))>0){
                echo "\n\n  EXCEPTION FAIL:{$c} exceptions were not handled.";
            }

            $class = get_class($this);
            echo "\n$str ".$test['name']."[end] ($class) $str";

            return;
        }

        if ($test['enabled']!=true)$symbol = '//';
        // $assertions =
            // '+'.$test['assertions']['pass']
            // .', -'.$test['assertions']['fail'];
            // ;

        $bench = '';
        if ($test['bench']['diff']>$this->options['bench.threshold']){
            $ms = $test['bench']['diff'] * 1000;
            $ms = number_format($ms,4);
            $bench=' '.$ms.'ms';
        }

        $assertions = '';
        if ($test['pass']){
            $assertions = "  (+".$test['assertions']['pass'].')';
        } else {
            $assertions = "  (+".$test['assertions']['pass'].", -".$test['assertions']['fail'].')';
        }


        echo "\n  $symbol ".$test['name']. $bench . $assertions; //." ($assertions)";

    }
    /**
     * Run tests
     *
     * @param $methods an array of method names to run as tests or NULL to run all methods beginning with 'test'
     */
    public function run(){


        $class = explode('\\',get_class($this));
        $name = array_pop($class);
        echo "\n". array_pop($class).'\\'.$name.': ';
        $methods = $this->get_test_methods();
        $results = [
            'class'=>get_class($this),
            'tests_run'=>0,
            'pass'=>0,
            'fail'=>0,
            'disabled'=>0,
            'assert_pass'=>0,
            'assert_fail'=>0,
        ];
        $tests = [];

        if (count($methods)==0)return $results;
        $this->prepare();
        
        foreach ($methods as $method){
            $this->inverted = false;
            $this->enabled = true;
            
            try {
                $this->will_run_test($method);
            } catch (\Exception $e){
                $class = get_class($this);
                echo "  $class::will_run_test() threw exception."; // for test method '$method' on class '$class'";
                if (isset($this->cli->args['test'])&& !empty($this->cli->args['test'])){
                    echo "\nException: ".$e->getMessage();
                    echo "\nStackTrace: ". $e->getTraceAsString();
                }
                continue;
            }
            $test = $this->run_test_method($method);
            try {
                $this->did_run_test($method, $test);
            } catch (\Exception $e){
                $class = get_class($this);
                echo "  $class::did_run_test() threw exception"; // for test method '$method' on class '$class'";
                if (isset($this->cli->args['test']) && !empty($this->cli->args['test'])){
                    echo "\nException: ".$e->getMessage();
                    echo "\nStackTrace: ". $e->getTraceAsString();
                }
            }
            if ($test===false)continue;
            $this->print_test_results($test);

            $tests[] = $test;

            $results['tests_run']++;
            if ($test['enabled']!==true){
                $results['disabled']++;
            } else if ($test['pass']===true){
                $results['pass']++;
            } else {
                $results['fail']++;
            }

            $results['assert_pass']+=$test['assertions']['pass'];
            $results['assert_fail']+=$test['assertions']['fail'];

            // $test['enabled'] = $this->enabled;
            // print_r($test['assertions']);
            // exit;
        }

        $this->finish();
        // echo "\n  ".$results['fail'].' fail, '.$results['pass'].' pass';;

        // $results['tests'] = $tests;
        // $results = $this->assertions;
        // print_r($results);
        // exit;
//
        // print_r($this->assertions);
        // exit;
    
        return $results;
    }
    /**
     * @param $start_time a value from `microtime(true)`
     */
    public function benchEnd($start_time){
        $end = microtime(true);
        $diff = $end - $start_time;
        return [
            'start'=>$start_time,
            'end'=>$end,
            'diff'=>$diff
        ];
    }

    /**
     * @override to execute before a single test runs
     */
    public function will_run_test(string $method_name){}

    /**
     * @override to execute after a single test runs
     */
    public function did_run_test(string $method_name, array $test_result){}

}

<?php

namespace Tlf\Tester;

/**
 * See the Exceptions trait for exception-based assertions
 * See the `Other` trait for invert(), disable(), and other methods that are important but are not assertions
 */
trait Assertions {


    /**
     * Call pre-defined global functions as assertions
     *
     * @example Use PHP's `in_array()` function as a test: `$this->in_array('value', $array_to_test);`
     */
    public function __call($method, $args){
        if (!function_exists($method)){
            throw new \Exception("'$method' is not a valid assertion, but you can use any existing function (such as in_array()) as an assertion if it returns truthy/falsey values.");
        }

        $didPass = $method(...$args);
        $this->handleDidPass($didPass);
        $c = count($args);
        echo "'$method'([$c arguments]) ";

    }

    public function isInstanceOf($object, $shouldBe){
            $class = get_class($object);
        if ($object instanceof $shouldBe){
            $this->handleDidPass(true);
            echo "'$class' is instanceof '$shouldBe'";
        } else {
            $this->handleDidPass(false);
            echo "'$class' is NOT instanceof '$shouldBe'";
        }
    }
    public function is_object($object){
        if (is_object($object)){
            $this->handleDidPass(true);
            echo "Is an object";
        } else {
            $this->handleDidPass(false);
            echo "Is not an object";
        }
    }

    public function is_false($value){
        $this->handleDidPass($value === false);
        echo "is_false()";
    }
    public function is_true($value){
        $this->handleDidPass($value === true);
        echo "is_true()";
    }

    /**
     * @param $str the string to check within
     * @param $target a target string (or array of strings) to verify exist within $str
     * @param $strings additional strings to check exist within $str
     */
    public function str_contains($str, $target, ...$strings){
        if (count($strings)>0)$target = [$target,...$strings];
        if (is_array($target)){
            $success = true;
            foreach ($target as $strTarget){
                $oneSuccess = $this->str_contains($str,$strTarget);
                if (!$oneSuccess)$success = false;
            }
            return $success;
        }
        $pass = false;
        if (strpos($str,$target)!==false)$pass=true;

        $this->handleDidPass($pass);
        if ($pass){
            echo "String contains '$target'";
        } else {
            echo "String does not contain '$target'";
        }
        return $pass;
    }

    /**
     * Make sure `$str` does not contain `$target`
     */
    public function str_not_contains(string $str, $target, ...$strings){
        if (count($strings)>0)$target = [$target,...$strings];
        if (is_array($target)){
            $success = true;
            foreach ($target as $strTarget){
                $oneSuccess = $this->str_not_contains($str,$strTarget);
                if (!$oneSuccess)$success = false;
            }
            return $success;
        } else $target = (string)$target;
        $pass = true;
        if (strpos($str,$target)!==false)$pass=false;

        $this->handleDidPass($pass);
        if ($pass){
            echo "String does not contain '$target'";
        } else {
            echo "String contains '$target'";
        }
        return false;
    
    }

    /**
     * Compares bools, strings, files (prefix path with `file://`), arrays, objects, and whatever else. 
     *
     * @param $target the value you want
     * @param $actual the value you have
     * @param $strict true/false for strict (`===`) or non-strict (`==`) comparison. 
     */
    public function compare($target, $actual,$strict=false){
        if (!$strict&&is_string($target)&&substr($target,0,7)=='file://'){
            $file = substr($target,7);
            if (!is_file($file)){
                throw new \Exception("{$target} is not a file. ");
            }
            $ext = substr($file,-4);
            if ($ext=='.php'){
                ob_start();
                require($file);
                $target=ob_get_clean();
            }
            else $target=file_get_contents($file);
        }
        if (!$strict&&is_string($actual)&&substr($actual,0,7)=='file://'){
            $file = substr($actual,7);
            if (!is_file($file)){
                throw new \Exception("{$actual} is not a file. ");
            }
            $ext = substr($file,-4);
            if ($ext=='.php'){
                ob_start();
                require($file);
                $actual=ob_get_clean();
            }
            else $actual=file_get_contents($file);
        }


        if (!$strict&&is_string($target)&&is_string($actual)){
            $target = trim($target);
            $actual = trim($actual);
        }
        $pass = false;
        if ($strict&&($target===$actual))$pass = true;
        else if (!$strict&&$target==$actual)$pass = true;


        $target = $this->comparisonOutput($target);
        $actual = $this->comparisonOutput($actual);
        
        // echo "Strict: ".($strict ? 'true' : 'false');

        $this->handleDidPass($pass);
        if ($strict)echo " strict comparison";
        $this->targetVsActualOutput($target, $actual);

        return $pass;
    }

    /**
     * Simply compare the values 
     * @param $target the value you want
     * @param $actual the value you have
     * @param $strict TRUE to use `===`. FALSE to use `==`
     */
    public function compare_raw($target, $actual, $strict=false){
        $pass = $strict ? $target === $actual
                        : $target == $actual;

        ob_start();
        var_dump($target);
        $target_str = substr(ob_get_clean(), 0,500);
        ob_start();
        var_dump($actual);
        $actual_str = substr(ob_get_clean(), 0,500);

        $this->handleDidPass($pass);
        $this->targetVsActualOutput(
            $target_str,
            $actual_str
        );
        return $pass;
    }

    /**
     * Simply compare two arrays. Prints objects in the array as `ClassName#spl_object_id()`
     *
     * @param $target the array you want
     * @param $actual the array you have
     * @param $strict TRUE to use `===`. FALSE to use `==`
     */
    public function compare_arrays($target, $actual, $strict=false){
        $pass = $strict ? $target === $actual
                        : $target == $actual;

        $target_str = print_r($this->printable_array($target), true);
        $actual_str = print_r($this->printable_array($actual), true);

        $this->handleDidPass($pass);
        $this->targetVsActualOutput(
            $target_str,
            $actual_str
        );
        return $pass;
    }

    /**
     * Simply compare two objects. Prints objects as `ClassName#spl_object_id()`
     *
     * @param $target the object you want
     * @param $actual the object you have
     * @param $strict TRUE to use `===`. FALSE to use `==`
     */
    public function compare_objects($target, $actual, $strict=false){
        $pass = $strict ? $target === $actual
                        : $target == $actual;

        $target_str = !is_object($target) ? 'not-an-object' : get_class($target).'#'.spl_object_id($target);
        $actual_str = !is_object($actual) ? 'not-an-object:'.gettype($actual) : get_class($actual).'#'.spl_object_id($actual);

        $this->handleDidPass($pass);
        $this->targetVsActualOutput(
            $target_str,
            $actual_str
        );
        return $pass;
    }

    /**
     *
     * @return true if tests passes, false otherwise
     */
    public function compare_object_properties(object $object1, object $object2): bool {
        $diff = [];
        $same = [];

        $obj1_id = get_class($object1).'#'.spl_object_id($object1);
        $obj2_id = get_class($object2).'#'.spl_object_id($object2);

        $reflection1 = new \ReflectionObject($object1);
        $reflection2 = new \ReflectionObject($object2);

        // Get all properties, including private and protected ones
        $properties1 = $reflection1->getProperties();
        $properties2 = $reflection2->getProperties();

        foreach ($properties1 as $property) {
            $propertyName = $property->getName();

            // Make private and protected properties accessible
            $property->setAccessible(true);

            $v1 = $property->isInitialized($object1) ? $property->getValue($object1) : "UNDEFINED_OBJECT_PROPERTY";
            $v2 = $property->isInitialized($object2) ? $property->getValue($object2) : "UNDEFINED_OBJECT_PROPERTY";

            if ($v1!=$v2){
                $diff[$propertyName] = [
                    'obj1' => $property->getValue($object1),
                    'obj2' => $property->getValue($object2),
                ];
            } else {
                $same[$propertyName] = 'VALUES MATCH';
            }
        }

        foreach ($properties2 as $property) {
            $propertyName = $property->getName();
            if (isset($diff[$propertyName])
                ||isset($same[$propertyName])
                )continue;

            $v1 = $property->isInitialized($object1) ? $property->getValue($object1) : "UNDEFINED_OBJECT_PROPERTY";
            $v2 = $property->isInitialized($object2) ? $property->getValue($object2) : "UNDEFINED_OBJECT_PROPERTY";

            if ($v1!=$v2){
                $diff[$propertyName] = [
                    'old' => $property->getValue($object1),
                    'new' => $property->getValue($object2),
                ];
            } else {
                $same[$propertyName] = 'VALUES MATCH';
            }
        }

        if (count($diff) == 0){
            echo "\nZero diffs between object properties for $obj1_id and $obj2_id";
            $this->handleDidPass(true);
            return true;
        } 

        echo "\nDiffs exist between object properties on $obj1_id and $obj2_id:\n";
        print_r($diff);
        $this->handleDidPass(false);

        return false;
    }

    public function compare_json($target, $actual, $strict=false){
        if (is_string($target))$target = json_decode($target, true);
        if (is_string($actual))$actual = json_decode($actual, true);
        $this->compare($target, $actual, $strict);
    }


    /**
     * Trim all lines in $str and $target and compare the resulting strings.
     * @param $str The output you have
     * @param $target The output you want
     */
    public function str_contains_lines($str, $target){
        $filter = function($v){return trim($v)!='';};
        $target_lines = explode("\n", $target);
        $target_lines = array_filter($target_lines, $filter);
        $target_lines = array_map('trim', $target_lines);

        $actual_lines = explode("\n", $str);
        $actual_lines = array_filter($actual_lines, $filter);
        $actual_lines = array_map('trim',$actual_lines);

        $actual_lines = array_values($actual_lines);
        $target_lines = array_values($target_lines);

        $target_lines = implode("\n", $target_lines);
        $actual_lines = implode("\n", $actual_lines);
        // $this->targetVsActualOutput($target_lines, $actual_lines);
        $this->str_contains($actual_lines, $target_lines);

    }

    /**
     * Compare all non-empty lines after `trim()`ing each of them.
     * @param $target the lines you want
     * @param $actual the lines you have
     */
    public function compare_lines($target, $actual){
        $filter = function($v){return trim($v)!='';};
        $target_lines = explode("\n", $target);
        $target_lines = array_filter($target_lines, $filter);
        $target_lines = array_map('trim', $target_lines);

        $actual_lines = explode("\n", $actual);
        $actual_lines = array_filter($actual_lines, $filter);
        $actual_lines = array_map('trim',$actual_lines);

        $actual_lines = array_values($actual_lines);
        $target_lines = array_values($target_lines);

        $passed = $target_lines == $actual_lines;

        $this->handleDidPass($passed);
        $target_lines = implode("\n", $target_lines);
        $actual_lines = implode("\n", $actual_lines);
        $this->targetVsActualOutput($target_lines, $actual_lines);

    }
    /**
     * create a dump that converts objects to simple strings referencing their internal object id, so deep nesting is handled
     */
    public function compare_dump($target, $actual){
        $dumped_target = $this->dump_value($target);
        $dumped_actual = $this->dump_value($actual);
        $this->compare($dumped_target, $dumped_actual);
    }
}

<?php

namespace Tlf\Tester;


/**
 * Convenience methods for database work
 */
trait Databasing {

    /**
     *  Create a pdo mysql instance by loading db settings from a file.
     *  File should contain `mysql.dbname`, `mysql.host`, `mysql.user`, and `mysql.password`
     *  @param $json_file_path a path to a json file
     *  @return a PDO instance
     */
    public function getPdoFromSettingsFile(string $json_file_path): \PDO {
        $settings = json_decode(file_get_contents($json_file_path),true);
        $pdo = new \PDO('mysql:dbname='.$settings['mysql.dbname'].';host='.$settings['mysql.host'],
            $settings['mysql.user'],$settings['mysql.password']);
        return $pdo;
    }

    public function getPdo($dbName = ':memory:'){
        $pdo = new \PDO('sqlite:'.$dbName);
        return $pdo;
    }


    /**
     * Perform a query and return the rows 
     *
     * @param $pdo a pdo instance
     * @param $sql an sql string
     * @param $where_cols values to bind to the sql string
     * @return an associative array of the first row
     */
    public function dbQuery(\PDO $pdo, string $sql, array $where_cols = []){
        $stmt = $pdo->prepare($sql);
        $stmt->execute($where_cols);
        return $stmt->fetchAll(\PDO::FETCH_ASSOC);
    }
    /**
     * Select a single row by id
     * @param $pdo a PDO instance
     * @param $table the table name
     * @param $id the id to query for 
     *
     * @return the row
     */
    public function dbSelectById(\PDO $pdo, string $table, int $id){
        $stmt = $pdo->prepare("SELECT * FROM `{$table}` WHERE id = {$id}");
        $stmt->execute();
        return $stmt->fetchAll(\PDO::FETCH_ASSOC)[0];
    }

    /**
     * DELETE a single row by id
     * @param $pdo a PDO instance
     * @param $table the table name
     * @param $id the id to query for 
     * @return num rows affected
     */
    public function dbDeleteById(\PDO $pdo, string $table, int $id){
        $stmt = $pdo->prepare("DELETE FROM `{$table}` WHERE id = {$id}");
        $stmt->execute();
        // return $stmt->fetchAll(\PDO::FETCH_ASSOC)[0];
        return $stmt->rowCount();
    }


    /**
     * Insert a row into the database
     * @param $pdo a PDO instance
     * @param $tableName a string table name
     * @param $values an array of key=>value pairs
     * @return The inserted row (queries DB by id for the row AFTER the insert)
     */
    public function dbInsert($pdo, $tableName, $values){

        $cols = [];
        $binds = [];
        foreach ($values as $key=>$value){
            $cols[] = $key;
            $binds[":{$key}"] = $value;
        }
        $colsStr = '`'.implode('`, `',$cols).'`';
        $bindsStr = implode(', ', array_keys($binds));
        $query = "INSERT INTO `${tableName}`(${colsStr}) 
                VALUES (${bindsStr})
            ";
        $stmt = $pdo->prepare($query);
        if ($stmt===false){
            echo "PDO ErrorInfo:\n";
            print_r($pdo->errorInfo());
            // echo "\n";
            // return;
            throw new \Exception("Could not insert values into databse.");
        } 
        $stmt->execute($binds);

        return $this->dbSelectById($pdo, $tableName, $pdo->lastInsertId());
    }

    public function dbInsertAll($pdo, $tableName, $rows){

        $cols = [];
        $binds = [];
        $query = '';
        foreach ($rows as $index=>$row){
            $new_bind_keys = [];
            foreach ($row as $key=>$value){
                $binds[":{$key}_$index"] = $value;
                $new_bind_keys[] = ":{$key}_$index";
            }
            $bindsStr = implode(', ', $new_bind_keys);
            if ($index!=0)$query .=",\n";
            $query .= "(${bindsStr})";
        }

        foreach (array_slice($rows,0,1)[0] as $key=>$value){
            $cols[] = $key;
        }
        $colsStr = '`'.implode('`, `',$cols).'`';
        $query = "INSERT INTO `${tableName}`(${colsStr}) 
                VALUES $query
            ";

        $stmt = $pdo->prepare($query);
        if ($stmt===false){
            echo "PDO ErrorInfo:\n";
            print_r($pdo->errorInfo());
            // echo "\n";
            // return;
            throw new \Exception("Could not insert rows into databse.");
        } 
        $stmt->execute($binds);

        return $this->dbSelectById($pdo, $tableName, $pdo->lastInsertId());
    }

    /**
     * @param array $cols array of columns like: `['col_name'=>'VARCHAR(80)', 'col_two'=> 'integer']`
     */
    public function createTable(\PDO $pdo, string $tableName, array $cols, bool $dropIfExists=false){
        $colStatements = [];
        foreach ($cols as $col => $definition){
            $statement = '`'.$col.'` '. $definition;
            $colStatements[] = $statement;
        }
        $colsSql = implode(", ", $colStatements);
        $drop = $dropIfExists ? "DROP TABLE IF EXISTS `{$tableName}`;\n" : '';
        $sql =
        <<<SQL
            {$drop}
            CREATE TABLE `{$tableName}`
            (
            {$colsSql}
            )
            ;
            
        SQL;

        $this->dbExec($pdo, $sql);
    }
    /**
     * Returns the first row from the query result.
     * @todo don't fetchAll(). Only fetch first row.
     */
    public function queryOne(\PDO $pdo, string $sql, ?array $binds=null): ?array{
        $rows = $this->query($pdo, $sql, $binds);
        return $rows[0] ?? null;
    }
    public function query(\PDO $pdo, string $sql, ?array $binds=null): array{
        $pdo = $pdo;
        $stmt = $pdo->prepare($sql);
        if ($stmt===false){
            var_dump($pdo->errorInfo());
            throw new \Exception("Sql problem.");
        }
        $stmt->execute($binds);
        $rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
        return $rows;
    }

    public function dbExec($pdo, $sql, $binds=[]){
        $stmt = $pdo->prepare($sql);
        if ($stmt===false){
            var_dump($pdo->errorInfo());
            throw new \Exception("Sql problem.");
        }
        
        $stmt->execute($binds);
    }
}
<?php

namespace Tlf\Tester;

/**
 * Assert exceptions
 */
trait Exceptions {

    public function catch($exceptionClass,$strict=false){
        $catcher = new \Tlf\Tester\ExceptionCatcher($exceptionClass);
        $this->catchers[] = $catcher;
        return $catcher;
    }

    public function throw($e){
        $list = $this->catchers;
        foreach ($list as $index => $cat){
            if ($cat->matches($e)){
                //@TODO allow one catcher to be re-used & just require that each exception be caught by at least one.
                unset($this->catchers[$index]);
                ob_start();
                $this->handleDidPass(true);
                ob_get_clean();
                // "Exception was caught";
                return true;
            }
        }
        $this->handleDidPass(false);
        echo "Taeluf\\Tester: An exception was not handled...";
        throw $e;
    }


}
<?php

namespace Tlf\Tester;

/**
 * Stuff that doesn't belong in other traits & isn't about the core execution of tests
 */
trait Other {

    protected $inverted = false;

    /**
     * called before your tests
     */
    public function prepare(){}
    /**
     * called after a class's tests are finished running
     */
    public function finish(){}

    /**
     * Call `$tester->test('TestName')->compare($target,$actual)` to run a sub-test inside a test in your class
     * Chaining is not required
     * 
     * @export(Usage.test)
     */
    protected function test($subTestName){
        echo "\n\n****$subTestName****";
        return $this;
    }

    /**
     * Disable the current test
     */
    public function disable(){
        echo "  TEST DISABLED  ";
        $this->enabled = false;
    }

    /**
     * Invert test passage so failing tests actually passes them
     */
    public function invert(){
        $this->inverted = !$this->inverted;
        return $this->inverted;
    }


    public function print_r(array $array){
        print_r(
            $this->printable_array($array)
        );
    }

    /**
     * get a printable version of an array (replace objects with their class names)
     */
    public function printable_array(array $array): array {
        $out = [];
        foreach ($array as $key=>$value){
            if (is_object($value))$value = get_class($value).'#'.spl_object_id($value);
            if (is_array($value))$value = $this->printable_array($value);
            $out[$key] = $value;
        }
        return $out;
    }

    public function handleDidPass(bool $didPass, $print=true){
        $extra='';
        if ($this->inverted){
            $didPass = !$didPass;
            $extra=" (inverted)";
        }
        if ($print){
            echo "\n\n";
            if ($didPass)echo "+++pass+++$extra";
            else echo "---fail---$extra";
            echo "\n";
        }
        $passStr = $didPass ? 'pass': 'fail';
        $this->assertions[$passStr]++;
        return $didPass;
    }


    public function targetVsActualOutput($target, $actual){

        if (!is_string($target))$target = $this->comparisonOutput($target);
        if (!is_string($actual))$actual = $this->comparisonOutput($actual);

        // echo "\n";
        echo "Target:\n{$target}";
        echo "\n--\n";
        echo "Actual:\n{$actual}";
        echo "\n--------\n";
    }


    public function comparisonOutput($value){
        if (is_object($value)){
            return "Object of class ".get_class($value);
        }
        if (is_array($value)){

            array_walk_recursive($value, function(&$value){
                $value = str_replace(["\r","\n"],['\r','\n'], $value??'');
            });

            $pr = var_export($value, true);
            $maxLen= 1000;
            
            if (($this->options['prettyPrintArray'][0]??null)=='true'){
                $oneLine = $pr;
                $maxLen = 1500;
            } else {
                $oneLine = implode(" ",array_map('trim',explode("\n",$pr)));
                $oneLine = str_replace('\\\\n', '\n', $oneLine);
            }
            $value = substr($oneLine,0,$maxLen);
            if (strlen($oneLine)>$maxLen)$value .= '...';

            return $value;
        }

        if ($value===true)return 'true';
        else if ($value===false)return 'false';

        return $value;
    }
}
<?php

namespace Tlf\Tester;

/**
 * convenience methods for server-related tests
 * Server-related assertions may go here too
 *
 * @todo stop using file_get_contents() so I check for redirects & stuff
 */
trait Server {

    /**
     *
     * @param $server the server name
     * @return a string like `http://localhost:3000`
     */
    public function get_server(string $server='main'){
        $host = $this->cli->get_server_host($server);
        return $host;
    }
    
    /**
     *
     * @param $path the path component of a url 
     * @param $params an array of paramaters to pass in the url
     *
     * @note $path cannot contain query string if params are passed
     * @warning this early implementation will change
     *
     * @usage $response_content = $this->get('/', ['cat'=>'Jefurry']);
     */
    public function get($path, $params=[], $server='main'){
        $host = $this->cli->get_server_host($server);
        $url = $host.$path;
        if ($params!=[]) $url .= '?' . http_build_query($params);

        $ch = curl_init();

        curl_setopt_array($ch,
            [
            CURLOPT_URL => $url, 
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POST => false,
            // CURLOPT_POSTFIELDS => http_build_query($params),
            // CURLOPT_POSTFIELDS => $params,
            CURLOPT_FOLLOWLOCATION => true,
            ]
        );


        $output = curl_exec($ch);
        curl_close($ch);

        return $output;
    }



    /**
     *
     * @param $path the path component of a url 
     * @param $params an array of paramaters to pass via $_POST
     * @param $files key=>value array of files where key = short file name & value = local file path
     *
     * @note $params['key'] will be overwritten by $files['key'] for the upload
     * @note(jan 4, 2022) follows redirects ('Location:' header)
     *
     * @note $path cannot contain query string if params are passed
     *
     * @usage $response_content = $this->get('/', ['cat'=>'Jefurry']);
     */
    public function post($path, $params=[], $files=[], $server='main'){
        $host = $this->cli->get_server_host($server);
        $url = $host.$path;

        $ch = curl_init();

        $this->curl_add_files($ch, $files, $params);

        curl_setopt_array($ch,
            [
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POST => true,
            // CURLOPT_POSTFIELDS => http_build_query($params),
            CURLOPT_POSTFIELDS => $params,
            CURLOPT_FOLLOWLOCATION => true,
            // CURLOPT_HEADER=>true,
            // CURLINFO_HEADER_OUT=>true,
            ]
        );


        $output = curl_exec($ch);
        curl_close($ch);

        return $output;
    }

    /**
     *
     * @beta
     *
     * @param $headers array like `['HeaderKey: header_value', 'Cookie'=> 'cookie_key=cookie_value;cookie2=value2;']` ... ONLY `Cookie` should have an array key. All other header keys should be in the array value and use a numeric index
     * @return array with keys header_text, body, headers, cookies
     */
    public function curl_post($path, $params=[], $files=[], $server='main', $headers=[]){
        $ch = curl_init();

        $host = $this->cli->get_server_host();
        $url = $host.$path;
        
        // echo 'zip zap';
//
        // print_r($headers);
        // exit;

        if (isset($headers['Cookie'])){
            // var_dump($headers);
            // exit;
            $cookie = $headers['Cookie'];
            unset($headers['Cookie']);
            curl_setopt($ch, CURLOPT_COOKIE, $cookie);
        }
        curl_setopt_array($ch,
            [
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POST => true,
            // CURLOPT_POSTFIELDS => http_build_query($params),
            CURLOPT_POSTFIELDS => $params,
            CURLOPT_HEADER => true,
            CURLOPT_FOLLOWLOCATION => false,
            CURLOPT_HTTPHEADER => $headers,
            ]
        );

        $response = curl_exec($ch);
        $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
        curl_close($ch);

        $header_text = substr($response,0,$header_size);

        $parts = explode("\n", $header_text);
        $parts = array_map('trim', $parts);
        $headers = [];
        $cookies = [];
        foreach ($parts as $line){
            $pos = strpos($line,':');
            if ($pos===false)continue;
            $key = substr($line,0,$pos);
            $value = trim(substr($line,$pos+1));
            if (isset($headers[$key])){
                if (!is_array($headers[$key]))$headers[$key] = [$headers[$key]];
                $headers[$key][] = $value;
            } else {
                $headers[$key] = $value;
            }
            if ($key=='Set-Cookie'){
                $cookie = $this->parse_cookie_header($value);
                $cookies[$cookie['name']] = $cookie;
            }
        }

        // TODO: parse Set-Cookie headers 

        $body = substr($response,$header_size);
        return [
            'header_text'=>$header_text,
            'body'=>$body,
            'headers'=>$headers,
            'cookies'=>$cookies,
        ];
    }

    /**
     *
     * @beta(may 4, 2022)
     *
     * @see curl_post(). It is the same except no `$files` param here
     */
    public function curl_get($path, $params=[], $server='main', $headers=[]){
        $ch = curl_init();

        $host = $this->cli->get_server_host();
        $url = $host.$path;
        if ($params!=[]) $url .= '?' . http_build_query($params);

        // echo 'zip zap';
//
        // print_r($headers);
        // exit;

        if (isset($headers['Cookie'])){
            // var_dump($headers);
            // exit;
            $cookie = $headers['Cookie'];
            unset($headers['Cookie']);
            curl_setopt($ch, CURLOPT_COOKIE, $cookie);
        }
        curl_setopt_array($ch,
            [
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POST => false,
            // CURLOPT_POSTFIELDS => http_build_query($params),
            // CURLOPT_POSTFIELDS => $params,
            CURLOPT_HEADER => true,
            CURLOPT_FOLLOWLOCATION => false,
            CURLOPT_HTTPHEADER => $headers,
            ]
        );

        $response = curl_exec($ch);
        $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
        curl_close($ch);

        $header_text = substr($response,0,$header_size);

        $parts = explode("\n", $header_text);
        $parts = array_map('trim', $parts);
        $headers = [];
        $cookies = [];
        foreach ($parts as $line){
            $pos = strpos($line,':');
            if ($pos===false)continue;
            $key = substr($line,0,$pos);
            $value = trim(substr($line,$pos+1));
            if (isset($headers[$key])){
                if (!is_array($headers[$key]))$headers[$key] = [$headers[$key]];
                $headers[$key][] = $value;
            } else {
                $headers[$key] = $value;
            }
            if ($key=='Set-Cookie'){
                $cookie = $this->parse_cookie_header($value);
                $cookies[$cookie['name']] = $cookie;
            }
        }

        // TODO: parse Set-Cookie headers 

        $body = substr($response,$header_size);
        return [
            'header_text'=>$header_text,
            'body'=>$body,
            'headers'=>$headers,
            'cookies'=>$cookies,
        ];
    }


    /**
     * @param $header_value, for `Set-cookie: whatever whatever`, this should be `whatever whatever`
     * @return array parsed cookie
     *
     *
     * @issue has no handling for a cookie value containing a semi-colon or an equal sign
     */
    public function parse_cookie_header($header_value): array {
        $cookie = [];
        $parts = explode(';', $header_value);
        $parts = array_map('trim',$parts);

        $main = array_shift($parts);
        $main_parts = explode('=', $main);
        $cookie['name'] = $main_parts[0];
        $cookie['value'] = $main_parts[1];


        foreach ($parts as $str){
            $kv_parts = explode('=', $str);
            if (count($kv_parts)==1)$cookie[$str] = true;
            else $cookie[$kv_parts[0]] = $kv_parts[1];
        }
        return $cookie;
    }

    /**
     * @param $ch curl handle
     * @param $files array of key=>absolute file paths
     * @param $params array to use as CURLOPT_POSTFIELDS
     */
    public function curl_add_files($ch, array $files, array &$params){
        foreach ($files as $name=>$path){
            $mimetype = mime_content_type($path);
            // $mimetype = false;
            if ($mimetype==false){
                $ext = pathinfo($path,PATHINFO_EXTENSION);
                $list = require(dirname(__DIR__).'/mime_type_map.php');
                $mimetype = $list['mimes'][$ext][0];
            }
            $params[$name] = new \CURLFile($path, $mimetype, basename($path));
        }
    }
}
<?php

namespace Tlf\Tester;

/**
 * Convenience methods to call from inside tests
 */
trait Utilities {

    protected int $php_major_version = -1;
    protected int $php_minor_version = -1;

    public function php_major_version(){
        if ($this->php_major_version!=-1)return $this->php_major_version;
        $version = phpversion();
        $version_int = substr($version,0,1);
        $php_version = (int)$version_int;
        $this->php_major_version = $php_version;
        return $php_version;
    }

    public function php_minor_version(){
        if ($this->php_minor_version!=-1)return $this->php_minor_version;
        $version = phpversion();
        $version_int = substr($version,0,1).substr($version,2,1);
        $php_version = (int)$version_int;
        $this->php_minor_version = $php_version;
        return $php_version;
    }

    protected function startOb(){
        return \Tlf\Tester\Utility::startOb();
    }
    protected function endOb($ob_level){
        return \Tlf\Tester\Utility::endOb($ob_level);
    }

    /**
     * get path to a file inside the current working directory
     */
    public function file($rel_path){
        return $this->cli->pwd.'/'.$rel_path;
    }

    /**
     * Delete all files in a directory
     * @param $dir the directory to delete
     * @param $recursive pass true for recursive deletion
     */
    public function empty_dir($dir, $recursive=false){
        if (!is_dir($dir))return;
        foreach (scandir($dir) as $f){
            if ($f=='.' || $f == '..')continue;
            if (is_file($dir.'/'.$f)){
                unlink($dir.'/'.$f);
            } else if ($recursive===true&&is_dir($dir.'/'.$f)){
                $this->empty_dir($dir.'/'.$f);
            }
        }
    }

    /**
     * Get a dumped version of the value (handles objects & arrays nicely
     */
    public function dump_value($value){
        if (is_callable($value)&&is_array($value)
            &&is_object($value[0]))return get_class($value[0]).'#'.spl_object_id($value[0]).'->'.$value[1];
        if (is_object($value))return get_class($value).'#'.spl_object_id($value);
        if (is_array($value))return array_map([$this, 'dump_value'], $value);

        return $value;
    }
}
<?php

namespace Tlf\Tester;

class Utility {

    static public function xdotoolRefreshFirefox($switchBackToWindow = false){
        $args = $switchBackToWindow ? ' y' : '';
        system(__DIR__.'/reload.sh'.$args);

        \Taeluf\Tester\Utility::xdotoolRefreshFirefox($switchBackToWindow);
    }


    static public function startOb(){
        ob_start();
        $ob_level = ob_get_level();
        return $ob_level;
    }
    static public function endOb($ob_level){
        $output = '';

        while (ob_get_level()>$ob_level){
            $output .= ob_get_clean()."\n";
        }
        $output .= ob_get_clean();
        return $output;
    }



    /**
     * dependency on Util added on Dec 8, 2022.
     * @param $file an absolute path to a file
     * @return null if no class found or a string with the `Qualified\Clazz\Name`
     */
    static public function getClassFromFile($file){
        $class = \Tlf\Util::getClassFromFile($file);
        return $class;
    }
/**
 * Copyright 2021 Reed Sutman, Taeluf
 * MIT License
 * See tluf.me/utils
 *
 * Please retain this notice
 *
 * This recursive file getting function actually came from tluf.me/liaison
 */
/**
 * Utility class to work with files & directories
 * @todo move to my util repo & depend upon this class.
 */

    /**
     * Get all files in a directory. Does not return directories
     *
     * @param $dir the directory to search in
     * @param $relativeTo A /root/path to remove from file paths returned
     * @param $endingWith only get files that end with the given string, like `.php` or `.md`, etc
     * @return array of files
     */
    static public function getAllFiles($dir,$relativeTo='', $endingWith=''){
        $fPathsRelTo = $relativeTo;
        if (!is_dir($dir))return [];
        $dir = str_replace(['///','//'],'/','/'.$dir.'/');
        $fPathsRelTo = $fPathsRelTo ? str_replace(['///','//'],'/','/'.$fPathsRelTo.'/') : null;
        $dh = opendir($dir);
        $allFiles = [];
        while ($file=readdir($dh)){
            if ($file=='.'||$file=='..')continue;
            if (is_dir($dir.$file)){
                $subFiles = self::getAllFiles($dir.'/'.$file,$fPathsRelTo,$endingWith);
                $allFiles = array_merge($allFiles,$subFiles);
                continue;
            }
            $path = str_replace(['///','//'],'/',$dir.'/'.$file);
            if ($fPathsRelTo!==null){
                $path = '/'.substr($path,strlen($fPathsRelTo));
            }
            if ($endingWith!=''
                &&substr($path,-strlen($endingWith))!=$endingWith)continue;
            $allFiles[] = $path;
        }
        return $allFiles;
    }

}
{
    "dir.test":["test/run"],
    "dir.exclude":[],
    "file.require":[],

    "results.writeHtml":false,

    "bench.threshold": 0.0001,

    "server.main": "main",
    "server":{
        "main": { 
            "dir":"test/Server",
            "bootstrap":"bootstrap.php",
            "deliver":"deliver.php",
            "host": "http://localhost"
        }
    }
}
<?php

return $types = [
    'mimes' =>
    [
        'md' => [
            0 => 'text/markdown',
            1 => 'text/plain',
        ],
        'wof' =>
        [
            0 => 'application/font-woff',
        ],
        'php' =>
        [
            0 => 'application/php',
            1 => 'application/x-httpd-php',
            2 => 'application/x-httpd-php-source',
            3 => 'application/x-php',
            4 => 'text/php',
            5 => 'text/x-php',
        ],
        'otf' =>
        [
            0 => 'application/x-font-otf',
            1 => 'font/otf',
        ],
        'ttf' =>
        [
            0 => 'application/x-font-ttf',
            1 => 'font/ttf',
        ],
        'ttc' =>
        [
            0 => 'application/x-font-ttf',
            1 => 'font/collection',
        ],
        'zip' =>
        [
            0 => 'application/x-gzip',
            1 => 'application/zip',
        ],
        'amr' =>
        [
            0 => 'audio/amr',
        ],
        'mp3' =>
        [
            0 => 'audio/mpeg',
        ],
        'mpga' =>
        [
            0 => 'audio/mpeg',
        ],
        'mp2' =>
        [
            0 => 'audio/mpeg',
        ],
        'mp2a' =>
        [
            0 => 'audio/mpeg',
        ],
        'm2a' =>
        [
            0 => 'audio/mpeg',
        ],
        'm3a' =>
        [
            0 => 'audio/mpeg',
        ],
        'jpg' =>
        [
            0 => 'image/jpeg',
        ],
        'jpeg' =>
        [
            0 => 'image/jpeg',
        ],
        'jpe' =>
        [
            0 => 'image/jpeg',
        ],
        'bmp' =>
        [
            0 => 'image/x-ms-bmp',
            1 => 'image/bmp',
        ],
        'ez' =>
        [
            0 => 'application/andrew-inset',
        ],
        'aw' =>
        [
            0 => 'application/applixware',
        ],
        'atom' =>
        [
            0 => 'application/atom+xml',
        ],
        'atomcat' =>
        [
            0 => 'application/atomcat+xml',
        ],
        'atomsvc' =>
        [
            0 => 'application/atomsvc+xml',
        ],
        'ccxml' =>
        [
            0 => 'application/ccxml+xml',
        ],
        'cdmia' =>
        [
            0 => 'application/cdmi-capability',
        ],
        'cdmic' =>
        [
            0 => 'application/cdmi-container',
        ],
        'cdmid' =>
        [
            0 => 'application/cdmi-domain',
        ],
        'cdmio' =>
        [
            0 => 'application/cdmi-object',
        ],
        'cdmiq' =>
        [
            0 => 'application/cdmi-queue',
        ],
        'cu' =>
        [
            0 => 'application/cu-seeme',
        ],
        'davmount' =>
        [
            0 => 'application/davmount+xml',
        ],
        'dbk' =>
        [
            0 => 'application/docbook+xml',
        ],
        'dssc' =>
        [
            0 => 'application/dssc+der',
        ],
        'xdssc' =>
        [
            0 => 'application/dssc+xml',
        ],
        'ecma' =>
        [
            0 => 'application/ecmascript',
        ],
        'emma' =>
        [
            0 => 'application/emma+xml',
        ],
        'epub' =>
        [
            0 => 'application/epub+zip',
        ],
        'exi' =>
        [
            0 => 'application/exi',
        ],
        'pfr' =>
        [
            0 => 'application/font-tdpfr',
        ],
        'gml' =>
        [
            0 => 'application/gml+xml',
        ],
        'gpx' =>
        [
            0 => 'application/gpx+xml',
        ],
        'gxf' =>
        [
            0 => 'application/gxf',
        ],
        'stk' =>
        [
            0 => 'application/hyperstudio',
        ],
        'ink' =>
        [
            0 => 'application/inkml+xml',
        ],
        'inkml' =>
        [
            0 => 'application/inkml+xml',
        ],
        'ipfix' =>
        [
            0 => 'application/ipfix',
        ],
        'jar' =>
        [
            0 => 'application/java-archive',
        ],
        'ser' =>
        [
            0 => 'application/java-serialized-object',
        ],
        'class' =>
        [
            0 => 'application/java-vm',
        ],
        'mjs' =>
        [
            0 => 'application/javascript',
        ],
        'js' =>
        [
            0 => 'application/javascript',
        ],
        'json' =>
        [
            0 => 'application/json',
        ],
        'jsonml' =>
        [
            0 => 'application/jsonml+json',
        ],
        'lostxml' =>
        [
            0 => 'application/lost+xml',
        ],
        'hqx' =>
        [
            0 => 'application/mac-binhex40',
        ],
        'cpt' =>
        [
            0 => 'application/mac-compactpro',
        ],
        'mads' =>
        [
            0 => 'application/mads+xml',
        ],
        'mrc' =>
        [
            0 => 'application/marc',
        ],
        'mrcx' =>
        [
            0 => 'application/marcxml+xml',
        ],
        'ma' =>
        [
            0 => 'application/mathematica',
        ],
        'nb' =>
        [
            0 => 'application/mathematica',
        ],
        'mb' =>
        [
            0 => 'application/mathematica',
        ],
        'mathml' =>
        [
            0 => 'application/mathml+xml',
        ],
        'mbox' =>
        [
            0 => 'application/mbox',
        ],
        'mscml' =>
        [
            0 => 'application/mediaservercontrol+xml',
        ],
        'metalink' =>
        [
            0 => 'application/metalink+xml',
        ],
        'meta4' =>
        [
            0 => 'application/metalink4+xml',
        ],
        'mets' =>
        [
            0 => 'application/mets+xml',
        ],
        'mods' =>
        [
            0 => 'application/mods+xml',
        ],
        'm21' =>
        [
            0 => 'application/mp21',
        ],
        'mp21' =>
        [
            0 => 'application/mp21',
        ],
        'mp4s' =>
        [
            0 => 'application/mp4',
        ],
        'doc' =>
        [
            0 => 'application/msword',
        ],
        'dot' =>
        [
            0 => 'application/msword',
        ],
        'mxf' =>
        [
            0 => 'application/mxf',
        ],
        'bin' =>
        [
            0 => 'application/octet-stream',
        ],
        'dms' =>
        [
            0 => 'application/octet-stream',
        ],
        'lrf' =>
        [
            0 => 'application/octet-stream',
        ],
        'mar' =>
        [
            0 => 'application/octet-stream',
        ],
        'so' =>
        [
            0 => 'application/octet-stream',
        ],
        'dist' =>
        [
            0 => 'application/octet-stream',
        ],
        'distz' =>
        [
            0 => 'application/octet-stream',
        ],
        'pkg' =>
        [
            0 => 'application/octet-stream',
        ],
        'bpk' =>
        [
            0 => 'application/octet-stream',
        ],
        'dump' =>
        [
            0 => 'application/octet-stream',
        ],
        'elc' =>
        [
            0 => 'application/octet-stream',
        ],
        'deploy' =>
        [
            0 => 'application/octet-stream',
        ],
        'oda' =>
        [
            0 => 'application/oda',
        ],
        'opf' =>
        [
            0 => 'application/oebps-package+xml',
        ],
        'ogx' =>
        [
            0 => 'application/ogg',
        ],
        'omdoc' =>
        [
            0 => 'application/omdoc+xml',
        ],
        'onetoc' =>
        [
            0 => 'application/onenote',
        ],
        'onetoc2' =>
        [
            0 => 'application/onenote',
        ],
        'onetmp' =>
        [
            0 => 'application/onenote',
        ],
        'onepkg' =>
        [
            0 => 'application/onenote',
        ],
        'oxps' =>
        [
            0 => 'application/oxps',
        ],
        'xer' =>
        [
            0 => 'application/patch-ops-error+xml',
        ],
        'pdf' =>
        [
            0 => 'application/pdf',
        ],
        'pgp' =>
        [
            0 => 'application/pgp-encrypted',
        ],
        'asc' =>
        [
            0 => 'application/pgp-signature',
        ],
        'sig' =>
        [
            0 => 'application/pgp-signature',
        ],
        'prf' =>
        [
            0 => 'application/pics-rules',
        ],
        'p10' =>
        [
            0 => 'application/pkcs10',
        ],
        'p7m' =>
        [
            0 => 'application/pkcs7-mime',
        ],
        'p7c' =>
        [
            0 => 'application/pkcs7-mime',
        ],
        'p7s' =>
        [
            0 => 'application/pkcs7-signature',
        ],
        'p8' =>
        [
            0 => 'application/pkcs8',
        ],
        'ac' =>
        [
            0 => 'application/pkix-attr-cert',
        ],
        'cer' =>
        [
            0 => 'application/pkix-cert',
        ],
        'crl' =>
        [
            0 => 'application/pkix-crl',
        ],
        'pkipath' =>
        [
            0 => 'application/pkix-pkipath',
        ],
        'pki' =>
        [
            0 => 'application/pkixcmp',
        ],
        'pls' =>
        [
            0 => 'application/pls+xml',
        ],
        'ai' =>
        [
            0 => 'application/postscript',
        ],
        'eps' =>
        [
            0 => 'application/postscript',
        ],
        'ps' =>
        [
            0 => 'application/postscript',
        ],
        'cww' =>
        [
            0 => 'application/prs.cww',
        ],
        'pskcxml' =>
        [
            0 => 'application/pskc+xml',
        ],
        'rdf' =>
        [
            0 => 'application/rdf+xml',
        ],
        'rif' =>
        [
            0 => 'application/reginfo+xml',
        ],
        'rnc' =>
        [
            0 => 'application/relax-ng-compact-syntax',
        ],
        'rl' =>
        [
            0 => 'application/resource-lists+xml',
        ],
        'rld' =>
        [
            0 => 'application/resource-lists-diff+xml',
        ],
        'rs' =>
        [
            0 => 'application/rls-services+xml',
        ],
        'gbr' =>
        [
            0 => 'application/rpki-ghostbusters',
        ],
        'mft' =>
        [
            0 => 'application/rpki-manifest',
        ],
        'roa' =>
        [
            0 => 'application/rpki-roa',
        ],
        'rsd' =>
        [
            0 => 'application/rsd+xml',
        ],
        'rss' =>
        [
            0 => 'application/rss+xml',
        ],
        'rtf' =>
        [
            0 => 'application/rtf',
        ],
        'sbml' =>
        [
            0 => 'application/sbml+xml',
        ],
        'scq' =>
        [
            0 => 'application/scvp-cv-request',
        ],
        'scs' =>
        [
            0 => 'application/scvp-cv-response',
        ],
        'spq' =>
        [
            0 => 'application/scvp-vp-request',
        ],
        'spp' =>
        [
            0 => 'application/scvp-vp-response',
        ],
        'sdp' =>
        [
            0 => 'application/sdp',
        ],
        'setpay' =>
        [
            0 => 'application/set-payment-initiation',
        ],
        'setreg' =>
        [
            0 => 'application/set-registration-initiation',
        ],
        'shf' =>
        [
            0 => 'application/shf+xml',
        ],
        'smi' =>
        [
            0 => 'application/smil+xml',
        ],
        'smil' =>
        [
            0 => 'application/smil+xml',
        ],
        'rq' =>
        [
            0 => 'application/sparql-query',
        ],
        'srx' =>
        [
            0 => 'application/sparql-results+xml',
        ],
        'gram' =>
        [
            0 => 'application/srgs',
        ],
        'grxml' =>
        [
            0 => 'application/srgs+xml',
        ],
        'sru' =>
        [
            0 => 'application/sru+xml',
        ],
        'ssdl' =>
        [
            0 => 'application/ssdl+xml',
        ],
        'ssml' =>
        [
            0 => 'application/ssml+xml',
        ],
        'tei' =>
        [
            0 => 'application/tei+xml',
        ],
        'teicorpus' =>
        [
            0 => 'application/tei+xml',
        ],
        'tfi' =>
        [
            0 => 'application/thraud+xml',
        ],
        'tsd' =>
        [
            0 => 'application/timestamped-data',
        ],
        'plb' =>
        [
            0 => 'application/vnd.3gpp.pic-bw-large',
        ],
        'psb' =>
        [
            0 => 'application/vnd.3gpp.pic-bw-small',
        ],
        'pvb' =>
        [
            0 => 'application/vnd.3gpp.pic-bw-var',
        ],
        'tcap' =>
        [
            0 => 'application/vnd.3gpp2.tcap',
        ],
        'pwn' =>
        [
            0 => 'application/vnd.3m.post-it-notes',
        ],
        'aso' =>
        [
            0 => 'application/vnd.accpac.simply.aso',
        ],
        'imp' =>
        [
            0 => 'application/vnd.accpac.simply.imp',
        ],
        'acu' =>
        [
            0 => 'application/vnd.acucobol',
        ],
        'atc' =>
        [
            0 => 'application/vnd.acucorp',
        ],
        'acutc' =>
        [
            0 => 'application/vnd.acucorp',
        ],
        'air' =>
        [
            0 => 'application/vnd.adobe.air-application-installer-package+zip',
        ],
        'fcdt' =>
        [
            0 => 'application/vnd.adobe.formscentral.fcdt',
        ],
        'fxp' =>
        [
            0 => 'application/vnd.adobe.fxp',
        ],
        'fxpl' =>
        [
            0 => 'application/vnd.adobe.fxp',
        ],
        'xdp' =>
        [
            0 => 'application/vnd.adobe.xdp+xml',
        ],
        'xfdf' =>
        [
            0 => 'application/vnd.adobe.xfdf',
        ],
        'ahead' =>
        [
            0 => 'application/vnd.ahead.space',
        ],
        'azf' =>
        [
            0 => 'application/vnd.airzip.filesecure.azf',
        ],
        'azs' =>
        [
            0 => 'application/vnd.airzip.filesecure.azs',
        ],
        'azw' =>
        [
            0 => 'application/vnd.amazon.ebook',
        ],
        'acc' =>
        [
            0 => 'application/vnd.americandynamics.acc',
        ],
        'ami' =>
        [
            0 => 'application/vnd.amiga.ami',
        ],
        'apk' =>
        [
            0 => 'application/vnd.android.package-archive',
        ],
        'cii' =>
        [
            0 => 'application/vnd.anser-web-certificate-issue-initiation',
        ],
        'fti' =>
        [
            0 => 'application/vnd.anser-web-funds-transfer-initiation',
        ],
        'atx' =>
        [
            0 => 'application/vnd.antix.game-component',
        ],
        'mpkg' =>
        [
            0 => 'application/vnd.apple.installer+xml',
        ],
        'm3u8' =>
        [
            0 => 'application/vnd.apple.mpegurl',
        ],
        'swi' =>
        [
            0 => 'application/vnd.aristanetworks.swi',
        ],
        'iota' =>
        [
            0 => 'application/vnd.astraea-software.iota',
        ],
        'aep' =>
        [
            0 => 'application/vnd.audiograph',
        ],
        'mpm' =>
        [
            0 => 'application/vnd.blueice.multipass',
        ],
        'bmi' =>
        [
            0 => 'application/vnd.bmi',
        ],
        'rep' =>
        [
            0 => 'application/vnd.businessobjects',
        ],
        'cdxml' =>
        [
            0 => 'application/vnd.chemdraw+xml',
        ],
        'mmd' =>
        [
            0 => 'application/vnd.chipnuts.karaoke-mmd',
        ],
        'cdy' =>
        [
            0 => 'application/vnd.cinderella',
        ],
        'cla' =>
        [
            0 => 'application/vnd.claymore',
        ],
        'rp9' =>
        [
            0 => 'application/vnd.cloanto.rp9',
        ],
        'c4g' =>
        [
            0 => 'application/vnd.clonk.c4group',
        ],
        'c4d' =>
        [
            0 => 'application/vnd.clonk.c4group',
        ],
        'c4f' =>
        [
            0 => 'application/vnd.clonk.c4group',
        ],
        'c4p' =>
        [
            0 => 'application/vnd.clonk.c4group',
        ],
        'c4u' =>
        [
            0 => 'application/vnd.clonk.c4group',
        ],
        'c11amc' =>
        [
            0 => 'application/vnd.cluetrust.cartomobile-config',
        ],
        'c11amz' =>
        [
            0 => 'application/vnd.cluetrust.cartomobile-config-pkg',
        ],
        'csp' =>
        [
            0 => 'application/vnd.commonspace',
        ],
        'cdbcmsg' =>
        [
            0 => 'application/vnd.contact.cmsg',
        ],
        'cmc' =>
        [
            0 => 'application/vnd.cosmocaller',
        ],
        'clkx' =>
        [
            0 => 'application/vnd.crick.clicker',
        ],
        'clkk' =>
        [
            0 => 'application/vnd.crick.clicker.keyboard',
        ],
        'clkp' =>
        [
            0 => 'application/vnd.crick.clicker.palette',
        ],
        'clkt' =>
        [
            0 => 'application/vnd.crick.clicker.template',
        ],
        'clkw' =>
        [
            0 => 'application/vnd.crick.clicker.wordbank',
        ],
        'wbs' =>
        [
            0 => 'application/vnd.criticaltools.wbs+xml',
        ],
        'pml' =>
        [
            0 => 'application/vnd.ctc-posml',
        ],
        'ppd' =>
        [
            0 => 'application/vnd.cups-ppd',
        ],
        'car' =>
        [
            0 => 'application/vnd.curl.car',
        ],
        'pcurl' =>
        [
            0 => 'application/vnd.curl.pcurl',
        ],
        'dart' =>
        [
            0 => 'application/vnd.dart',
        ],
        'rdz' =>
        [
            0 => 'application/vnd.data-vision.rdz',
        ],
        'uvf' =>
        [
            0 => 'application/vnd.dece.data',
        ],
        'uvvf' =>
        [
            0 => 'application/vnd.dece.data',
        ],
        'uvd' =>
        [
            0 => 'application/vnd.dece.data',
        ],
        'uvvd' =>
        [
            0 => 'application/vnd.dece.data',
        ],
        'uvt' =>
        [
            0 => 'application/vnd.dece.ttml+xml',
        ],
        'uvvt' =>
        [
            0 => 'application/vnd.dece.ttml+xml',
        ],
        'uvx' =>
        [
            0 => 'application/vnd.dece.unspecified',
        ],
        'uvvx' =>
        [
            0 => 'application/vnd.dece.unspecified',
        ],
        'uvz' =>
        [
            0 => 'application/vnd.dece.zip',
        ],
        'uvvz' =>
        [
            0 => 'application/vnd.dece.zip',
        ],
        'fe_launch' =>
        [
            0 => 'application/vnd.denovo.fcselayout-link',
        ],
        'dna' =>
        [
            0 => 'application/vnd.dna',
        ],
        'mlp' =>
        [
            0 => 'application/vnd.dolby.mlp',
        ],
        'dpg' =>
        [
            0 => 'application/vnd.dpgraph',
        ],
        'dfac' =>
        [
            0 => 'application/vnd.dreamfactory',
        ],
        'kpxx' =>
        [
            0 => 'application/vnd.ds-keypoint',
        ],
        'ait' =>
        [
            0 => 'application/vnd.dvb.ait',
        ],
        'svc' =>
        [
            0 => 'application/vnd.dvb.service',
        ],
        'geo' =>
        [
            0 => 'application/vnd.dynageo',
        ],
        'mag' =>
        [
            0 => 'application/vnd.ecowin.chart',
        ],
        'nml' =>
        [
            0 => 'application/vnd.enliven',
        ],
        'esf' =>
        [
            0 => 'application/vnd.epson.esf',
        ],
        'msf' =>
        [
            0 => 'application/vnd.epson.msf',
        ],
        'qam' =>
        [
            0 => 'application/vnd.epson.quickanime',
        ],
        'slt' =>
        [
            0 => 'application/vnd.epson.salt',
        ],
        'ssf' =>
        [
            0 => 'application/vnd.epson.ssf',
        ],
        'es3' =>
        [
            0 => 'application/vnd.eszigno3+xml',
        ],
        'et3' =>
        [
            0 => 'application/vnd.eszigno3+xml',
        ],
        'ez2' =>
        [
            0 => 'application/vnd.ezpix-album',
        ],
        'ez3' =>
        [
            0 => 'application/vnd.ezpix-package',
        ],
        'fdf' =>
        [
            0 => 'application/vnd.fdf',
        ],
        'mseed' =>
        [
            0 => 'application/vnd.fdsn.mseed',
        ],
        'seed' =>
        [
            0 => 'application/vnd.fdsn.seed',
        ],
        'dataless' =>
        [
            0 => 'application/vnd.fdsn.seed',
        ],
        'gph' =>
        [
            0 => 'application/vnd.flographit',
        ],
        'ftc' =>
        [
            0 => 'application/vnd.fluxtime.clip',
        ],
        'fm' =>
        [
            0 => 'application/vnd.framemaker',
        ],
        'frame' =>
        [
            0 => 'application/vnd.framemaker',
        ],
        'maker' =>
        [
            0 => 'application/vnd.framemaker',
        ],
        'book' =>
        [
            0 => 'application/vnd.framemaker',
        ],
        'fnc' =>
        [
            0 => 'application/vnd.frogans.fnc',
        ],
        'ltf' =>
        [
            0 => 'application/vnd.frogans.ltf',
        ],
        'fsc' =>
        [
            0 => 'application/vnd.fsc.weblaunch',
        ],
        'oas' =>
        [
            0 => 'application/vnd.fujitsu.oasys',
        ],
        'oa2' =>
        [
            0 => 'application/vnd.fujitsu.oasys2',
        ],
        'oa3' =>
        [
            0 => 'application/vnd.fujitsu.oasys3',
        ],
        'fg5' =>
        [
            0 => 'application/vnd.fujitsu.oasysgp',
        ],
        'bh2' =>
        [
            0 => 'application/vnd.fujitsu.oasysprs',
        ],
        'ddd' =>
        [
            0 => 'application/vnd.fujixerox.ddd',
        ],
        'xdw' =>
        [
            0 => 'application/vnd.fujixerox.docuworks',
        ],
        'xbd' =>
        [
            0 => 'application/vnd.fujixerox.docuworks.binder',
        ],
        'fzs' =>
        [
            0 => 'application/vnd.fuzzysheet',
        ],
        'txd' =>
        [
            0 => 'application/vnd.genomatix.tuxedo',
        ],
        'ggb' =>
        [
            0 => 'application/vnd.geogebra.file',
        ],
        'ggt' =>
        [
            0 => 'application/vnd.geogebra.tool',
        ],
        'gex' =>
        [
            0 => 'application/vnd.geometry-explorer',
        ],
        'gre' =>
        [
            0 => 'application/vnd.geometry-explorer',
        ],
        'gxt' =>
        [
            0 => 'application/vnd.geonext',
        ],
        'g2w' =>
        [
            0 => 'application/vnd.geoplan',
        ],
        'g3w' =>
        [
            0 => 'application/vnd.geospace',
        ],
        'gmx' =>
        [
            0 => 'application/vnd.gmx',
        ],
        'kml' =>
        [
            0 => 'application/vnd.google-earth.kml+xml',
        ],
        'kmz' =>
        [
            0 => 'application/vnd.google-earth.kmz',
        ],
        'gqf' =>
        [
            0 => 'application/vnd.grafeq',
        ],
        'gqs' =>
        [
            0 => 'application/vnd.grafeq',
        ],
        'gac' =>
        [
            0 => 'application/vnd.groove-account',
        ],
        'ghf' =>
        [
            0 => 'application/vnd.groove-help',
        ],
        'gim' =>
        [
            0 => 'application/vnd.groove-identity-message',
        ],
        'grv' =>
        [
            0 => 'application/vnd.groove-injector',
        ],
        'gtm' =>
        [
            0 => 'application/vnd.groove-tool-message',
        ],
        'tpl' =>
        [
            0 => 'application/vnd.groove-tool-template',
        ],
        'vcg' =>
        [
            0 => 'application/vnd.groove-vcard',
        ],
        'hal' =>
        [
            0 => 'application/vnd.hal+xml',
        ],
        'zmm' =>
        [
            0 => 'application/vnd.handheld-entertainment+xml',
        ],
        'hbci' =>
        [
            0 => 'application/vnd.hbci',
        ],
        'les' =>
        [
            0 => 'application/vnd.hhe.lesson-player',
        ],
        'hpgl' =>
        [
            0 => 'application/vnd.hp-hpgl',
        ],
        'hpid' =>
        [
            0 => 'application/vnd.hp-hpid',
        ],
        'hps' =>
        [
            0 => 'application/vnd.hp-hps',
        ],
        'jlt' =>
        [
            0 => 'application/vnd.hp-jlyt',
        ],
        'pcl' =>
        [
            0 => 'application/vnd.hp-pcl',
        ],
        'pclxl' =>
        [
            0 => 'application/vnd.hp-pclxl',
        ],
        'sfd-hdstx' =>
        [
            0 => 'application/vnd.hydrostatix.sof-data',
        ],
        'mpy' =>
        [
            0 => 'application/vnd.ibm.minipay',
        ],
        'afp' =>
        [
            0 => 'application/vnd.ibm.modcap',
        ],
        'listafp' =>
        [
            0 => 'application/vnd.ibm.modcap',
        ],
        'list3820' =>
        [
            0 => 'application/vnd.ibm.modcap',
        ],
        'irm' =>
        [
            0 => 'application/vnd.ibm.rights-management',
        ],
        'sc' =>
        [
            0 => 'application/vnd.ibm.secure-container',
        ],
        'icc' =>
        [
            0 => 'application/vnd.iccprofile',
        ],
        'icm' =>
        [
            0 => 'application/vnd.iccprofile',
        ],
        'igl' =>
        [
            0 => 'application/vnd.igloader',
        ],
        'ivp' =>
        [
            0 => 'application/vnd.immervision-ivp',
        ],
        'ivu' =>
        [
            0 => 'application/vnd.immervision-ivu',
        ],
        'igm' =>
        [
            0 => 'application/vnd.insors.igm',
        ],
        'xpw' =>
        [
            0 => 'application/vnd.intercon.formnet',
        ],
        'xpx' =>
        [
            0 => 'application/vnd.intercon.formnet',
        ],
        'i2g' =>
        [
            0 => 'application/vnd.intergeo',
        ],
        'qbo' =>
        [
            0 => 'application/vnd.intu.qbo',
        ],
        'qfx' =>
        [
            0 => 'application/vnd.intu.qfx',
        ],
        'rcprofile' =>
        [
            0 => 'application/vnd.ipunplugged.rcprofile',
        ],
        'irp' =>
        [
            0 => 'application/vnd.irepository.package+xml',
        ],
        'xpr' =>
        [
            0 => 'application/vnd.is-xpr',
        ],
        'fcs' =>
        [
            0 => 'application/vnd.isac.fcs',
        ],
        'jam' =>
        [
            0 => 'application/vnd.jam',
        ],
        'rms' =>
        [
            0 => 'application/vnd.jcp.javame.midlet-rms',
        ],
        'jisp' =>
        [
            0 => 'application/vnd.jisp',
        ],
        'joda' =>
        [
            0 => 'application/vnd.joost.joda-archive',
        ],
        'ktz' =>
        [
            0 => 'application/vnd.kahootz',
        ],
        'ktr' =>
        [
            0 => 'application/vnd.kahootz',
        ],
        'karbon' =>
        [
            0 => 'application/vnd.kde.karbon',
        ],
        'chrt' =>
        [
            0 => 'application/vnd.kde.kchart',
        ],
        'kfo' =>
        [
            0 => 'application/vnd.kde.kformula',
        ],
        'flw' =>
        [
            0 => 'application/vnd.kde.kivio',
        ],
        'kon' =>
        [
            0 => 'application/vnd.kde.kontour',
        ],
        'kpr' =>
        [
            0 => 'application/vnd.kde.kpresenter',
        ],
        'kpt' =>
        [
            0 => 'application/vnd.kde.kpresenter',
        ],
        'ksp' =>
        [
            0 => 'application/vnd.kde.kspread',
        ],
        'kwd' =>
        [
            0 => 'application/vnd.kde.kword',
        ],
        'kwt' =>
        [
            0 => 'application/vnd.kde.kword',
        ],
        'htke' =>
        [
            0 => 'application/vnd.kenameaapp',
        ],
        'kia' =>
        [
            0 => 'application/vnd.kidspiration',
        ],
        'kne' =>
        [
            0 => 'application/vnd.kinar',
        ],
        'knp' =>
        [
            0 => 'application/vnd.kinar',
        ],
        'skp' =>
        [
            0 => 'application/vnd.koan',
        ],
        'skd' =>
        [
            0 => 'application/vnd.koan',
        ],
        'skt' =>
        [
            0 => 'application/vnd.koan',
        ],
        'skm' =>
        [
            0 => 'application/vnd.koan',
        ],
        'sse' =>
        [
            0 => 'application/vnd.kodak-descriptor',
        ],
        'lasxml' =>
        [
            0 => 'application/vnd.las.las+xml',
        ],
        'lbd' =>
        [
            0 => 'application/vnd.llamagraphics.life-balance.desktop',
        ],
        'lbe' =>
        [
            0 => 'application/vnd.llamagraphics.life-balance.exchange+xml',
        ],
        123 =>
        [
            0 => 'application/vnd.lotus-1-2-3',
        ],
        'apr' =>
        [
            0 => 'application/vnd.lotus-approach',
        ],
        'pre' =>
        [
            0 => 'application/vnd.lotus-freelance',
        ],
        'nsf' =>
        [
            0 => 'application/vnd.lotus-notes',
        ],
        'org' =>
        [
            0 => 'application/vnd.lotus-organizer',
        ],
        'scm' =>
        [
            0 => 'application/vnd.lotus-screencam',
        ],
        'lwp' =>
        [
            0 => 'application/vnd.lotus-wordpro',
        ],
        'portpkg' =>
        [
            0 => 'application/vnd.macports.portpkg',
        ],
        'mcd' =>
        [
            0 => 'application/vnd.mcd',
        ],
        'mc1' =>
        [
            0 => 'application/vnd.medcalcdata',
        ],
        'cdkey' =>
        [
            0 => 'application/vnd.mediastation.cdkey',
        ],
        'mwf' =>
        [
            0 => 'application/vnd.mfer',
        ],
        'mfm' =>
        [
            0 => 'application/vnd.mfmp',
        ],
        'flo' =>
        [
            0 => 'application/vnd.micrografx.flo',
        ],
        'igx' =>
        [
            0 => 'application/vnd.micrografx.igx',
        ],
        'mif' =>
        [
            0 => 'application/vnd.mif',
        ],
        'daf' =>
        [
            0 => 'application/vnd.mobius.daf',
        ],
        'dis' =>
        [
            0 => 'application/vnd.mobius.dis',
        ],
        'mbk' =>
        [
            0 => 'application/vnd.mobius.mbk',
        ],
        'mqy' =>
        [
            0 => 'application/vnd.mobius.mqy',
        ],
        'msl' =>
        [
            0 => 'application/vnd.mobius.msl',
        ],
        'plc' =>
        [
            0 => 'application/vnd.mobius.plc',
        ],
        'txf' =>
        [
            0 => 'application/vnd.mobius.txf',
        ],
        'mpn' =>
        [
            0 => 'application/vnd.mophun.application',
        ],
        'mpc' =>
        [
            0 => 'application/vnd.mophun.certificate',
        ],
        'xul' =>
        [
            0 => 'application/vnd.mozilla.xul+xml',
        ],
        'cil' =>
        [
            0 => 'application/vnd.ms-artgalry',
        ],
        'cab' =>
        [
            0 => 'application/vnd.ms-cab-compressed',
        ],
        'xls' =>
        [
            0 => 'application/vnd.ms-excel',
        ],
        'xlm' =>
        [
            0 => 'application/vnd.ms-excel',
        ],
        'xla' =>
        [
            0 => 'application/vnd.ms-excel',
        ],
        'xlc' =>
        [
            0 => 'application/vnd.ms-excel',
        ],
        'xlt' =>
        [
            0 => 'application/vnd.ms-excel',
        ],
        'xlw' =>
        [
            0 => 'application/vnd.ms-excel',
        ],
        'xlam' =>
        [
            0 => 'application/vnd.ms-excel.addin.macroenabled.12',
        ],
        'xlsb' =>
        [
            0 => 'application/vnd.ms-excel.sheet.binary.macroenabled.12',
        ],
        'xlsm' =>
        [
            0 => 'application/vnd.ms-excel.sheet.macroenabled.12',
        ],
        'xltm' =>
        [
            0 => 'application/vnd.ms-excel.template.macroenabled.12',
        ],
        'eot' =>
        [
            0 => 'application/vnd.ms-fontobject',
        ],
        'chm' =>
        [
            0 => 'application/vnd.ms-htmlhelp',
        ],
        'ims' =>
        [
            0 => 'application/vnd.ms-ims',
        ],
        'lrm' =>
        [
            0 => 'application/vnd.ms-lrm',
        ],
        'thmx' =>
        [
            0 => 'application/vnd.ms-officetheme',
        ],
        'cat' =>
        [
            0 => 'application/vnd.ms-pki.seccat',
        ],
        'stl' =>
        [
            0 => 'application/vnd.ms-pki.stl',
        ],
        'ppt' =>
        [
            0 => 'application/vnd.ms-powerpoint',
        ],
        'pps' =>
        [
            0 => 'application/vnd.ms-powerpoint',
        ],
        'pot' =>
        [
            0 => 'application/vnd.ms-powerpoint',
        ],
        'ppam' =>
        [
            0 => 'application/vnd.ms-powerpoint.addin.macroenabled.12',
        ],
        'pptm' =>
        [
            0 => 'application/vnd.ms-powerpoint.presentation.macroenabled.12',
        ],
        'sldm' =>
        [
            0 => 'application/vnd.ms-powerpoint.slide.macroenabled.12',
        ],
        'ppsm' =>
        [
            0 => 'application/vnd.ms-powerpoint.slideshow.macroenabled.12',
        ],
        'potm' =>
        [
            0 => 'application/vnd.ms-powerpoint.template.macroenabled.12',
        ],
        'mpp' =>
        [
            0 => 'application/vnd.ms-project',
        ],
        'mpt' =>
        [
            0 => 'application/vnd.ms-project',
        ],
        'docm' =>
        [
            0 => 'application/vnd.ms-word.document.macroenabled.12',
        ],
        'dotm' =>
        [
            0 => 'application/vnd.ms-word.template.macroenabled.12',
        ],
        'wps' =>
        [
            0 => 'application/vnd.ms-works',
        ],
        'wks' =>
        [
            0 => 'application/vnd.ms-works',
        ],
        'wcm' =>
        [
            0 => 'application/vnd.ms-works',
        ],
        'wdb' =>
        [
            0 => 'application/vnd.ms-works',
        ],
        'wpl' =>
        [
            0 => 'application/vnd.ms-wpl',
        ],
        'xps' =>
        [
            0 => 'application/vnd.ms-xpsdocument',
        ],
        'mseq' =>
        [
            0 => 'application/vnd.mseq',
        ],
        'mus' =>
        [
            0 => 'application/vnd.musician',
        ],
        'msty' =>
        [
            0 => 'application/vnd.muvee.style',
        ],
        'taglet' =>
        [
            0 => 'application/vnd.mynfc',
        ],
        'nlu' =>
        [
            0 => 'application/vnd.neurolanguage.nlu',
        ],
        'ntf' =>
        [
            0 => 'application/vnd.nitf',
        ],
        'nitf' =>
        [
            0 => 'application/vnd.nitf',
        ],
        'nnd' =>
        [
            0 => 'application/vnd.noblenet-directory',
        ],
        'nns' =>
        [
            0 => 'application/vnd.noblenet-sealer',
        ],
        'nnw' =>
        [
            0 => 'application/vnd.noblenet-web',
        ],
        'ngdat' =>
        [
            0 => 'application/vnd.nokia.n-gage.data',
        ],
        'n-gage' =>
        [
            0 => 'application/vnd.nokia.n-gage.symbian.install',
        ],
        'rpst' =>
        [
            0 => 'application/vnd.nokia.radio-preset',
        ],
        'rpss' =>
        [
            0 => 'application/vnd.nokia.radio-presets',
        ],
        'edm' =>
        [
            0 => 'application/vnd.novadigm.edm',
        ],
        'edx' =>
        [
            0 => 'application/vnd.novadigm.edx',
        ],
        'ext' =>
        [
            0 => 'application/vnd.novadigm.ext',
        ],
        'odc' =>
        [
            0 => 'application/vnd.oasis.opendocument.chart',
        ],
        'otc' =>
        [
            0 => 'application/vnd.oasis.opendocument.chart-template',
        ],
        'odb' =>
        [
            0 => 'application/vnd.oasis.opendocument.database',
        ],
        'odf' =>
        [
            0 => 'application/vnd.oasis.opendocument.formula',
        ],
        'odft' =>
        [
            0 => 'application/vnd.oasis.opendocument.formula-template',
        ],
        'odg' =>
        [
            0 => 'application/vnd.oasis.opendocument.graphics',
        ],
        'otg' =>
        [
            0 => 'application/vnd.oasis.opendocument.graphics-template',
        ],
        'odi' =>
        [
            0 => 'application/vnd.oasis.opendocument.image',
        ],
        'oti' =>
        [
            0 => 'application/vnd.oasis.opendocument.image-template',
        ],
        'odp' =>
        [
            0 => 'application/vnd.oasis.opendocument.presentation',
        ],
        'otp' =>
        [
            0 => 'application/vnd.oasis.opendocument.presentation-template',
        ],
        'ods' =>
        [
            0 => 'application/vnd.oasis.opendocument.spreadsheet',
        ],
        'ots' =>
        [
            0 => 'application/vnd.oasis.opendocument.spreadsheet-template',
        ],
        'odt' =>
        [
            0 => 'application/vnd.oasis.opendocument.text',
        ],
        'odm' =>
        [
            0 => 'application/vnd.oasis.opendocument.text-master',
        ],
        'ott' =>
        [
            0 => 'application/vnd.oasis.opendocument.text-template',
        ],
        'oth' =>
        [
            0 => 'application/vnd.oasis.opendocument.text-web',
        ],
        'xo' =>
        [
            0 => 'application/vnd.olpc-sugar',
        ],
        'dd2' =>
        [
            0 => 'application/vnd.oma.dd2+xml',
        ],
        'oxt' =>
        [
            0 => 'application/vnd.openofficeorg.extension',
        ],
        'pptx' =>
        [
            0 => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
        ],
        'sldx' =>
        [
            0 => 'application/vnd.openxmlformats-officedocument.presentationml.slide',
        ],
        'ppsx' =>
        [
            0 => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
        ],
        'potx' =>
        [
            0 => 'application/vnd.openxmlformats-officedocument.presentationml.template',
        ],
        'xlsx' =>
        [
            0 => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        ],
        'xltx' =>
        [
            0 => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
        ],
        'docx' =>
        [
            0 => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
        ],
        'dotx' =>
        [
            0 => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
        ],
        'mgp' =>
        [
            0 => 'application/vnd.osgeo.mapguide.package',
        ],
        'dp' =>
        [
            0 => 'application/vnd.osgi.dp',
        ],
        'esa' =>
        [
            0 => 'application/vnd.osgi.subsystem',
        ],
        'pdb' =>
        [
            0 => 'application/vnd.palm',
        ],
        'pqa' =>
        [
            0 => 'application/vnd.palm',
        ],
        'oprc' =>
        [
            0 => 'application/vnd.palm',
        ],
        'paw' =>
        [
            0 => 'application/vnd.pawaafile',
        ],
        'str' =>
        [
            0 => 'application/vnd.pg.format',
        ],
        'ei6' =>
        [
            0 => 'application/vnd.pg.osasli',
        ],
        'efif' =>
        [
            0 => 'application/vnd.picsel',
        ],
        'wg' =>
        [
            0 => 'application/vnd.pmi.widget',
        ],
        'plf' =>
        [
            0 => 'application/vnd.pocketlearn',
        ],
        'pbd' =>
        [
            0 => 'application/vnd.powerbuilder6',
        ],
        'box' =>
        [
            0 => 'application/vnd.previewsystems.box',
        ],
        'mgz' =>
        [
            0 => 'application/vnd.proteus.magazine',
        ],
        'qps' =>
        [
            0 => 'application/vnd.publishare-delta-tree',
        ],
        'ptid' =>
        [
            0 => 'application/vnd.pvi.ptid1',
        ],
        'qxd' =>
        [
            0 => 'application/vnd.quark.quarkxpress',
        ],
        'qxt' =>
        [
            0 => 'application/vnd.quark.quarkxpress',
        ],
        'qwd' =>
        [
            0 => 'application/vnd.quark.quarkxpress',
        ],
        'qwt' =>
        [
            0 => 'application/vnd.quark.quarkxpress',
        ],
        'qxl' =>
        [
            0 => 'application/vnd.quark.quarkxpress',
        ],
        'qxb' =>
        [
            0 => 'application/vnd.quark.quarkxpress',
        ],
        'bed' =>
        [
            0 => 'application/vnd.realvnc.bed',
        ],
        'mxl' =>
        [
            0 => 'application/vnd.recordare.musicxml',
        ],
        'musicxml' =>
        [
            0 => 'application/vnd.recordare.musicxml+xml',
        ],
        'cryptonote' =>
        [
            0 => 'application/vnd.rig.cryptonote',
        ],
        'cod' =>
        [
            0 => 'application/vnd.rim.cod',
        ],
        'rm' =>
        [
            0 => 'application/vnd.rn-realmedia',
        ],
        'rmvb' =>
        [
            0 => 'application/vnd.rn-realmedia-vbr',
        ],
        'link66' =>
        [
            0 => 'application/vnd.route66.link66+xml',
        ],
        'st' =>
        [
            0 => 'application/vnd.sailingtracker.track',
        ],
        'see' =>
        [
            0 => 'application/vnd.seemail',
        ],
        'sema' =>
        [
            0 => 'application/vnd.sema',
        ],
        'semd' =>
        [
            0 => 'application/vnd.semd',
        ],
        'semf' =>
        [
            0 => 'application/vnd.semf',
        ],
        'ifm' =>
        [
            0 => 'application/vnd.shana.informed.formdata',
        ],
        'itp' =>
        [
            0 => 'application/vnd.shana.informed.formtemplate',
        ],
        'iif' =>
        [
            0 => 'application/vnd.shana.informed.interchange',
        ],
        'ipk' =>
        [
            0 => 'application/vnd.shana.informed.package',
        ],
        'twd' =>
        [
            0 => 'application/vnd.simtech-mindmapper',
        ],
        'twds' =>
        [
            0 => 'application/vnd.simtech-mindmapper',
        ],
        'mmf' =>
        [
            0 => 'application/vnd.smaf',
        ],
        'teacher' =>
        [
            0 => 'application/vnd.smart.teacher',
        ],
        'sdkm' =>
        [
            0 => 'application/vnd.solent.sdkm+xml',
        ],
        'sdkd' =>
        [
            0 => 'application/vnd.solent.sdkm+xml',
        ],
        'dxp' =>
        [
            0 => 'application/vnd.spotfire.dxp',
        ],
        'sfs' =>
        [
            0 => 'application/vnd.spotfire.sfs',
        ],
        'sdc' =>
        [
            0 => 'application/vnd.stardivision.calc',
        ],
        'sda' =>
        [
            0 => 'application/vnd.stardivision.draw',
        ],
        'sdd' =>
        [
            0 => 'application/vnd.stardivision.impress',
        ],
        'smf' =>
        [
            0 => 'application/vnd.stardivision.math',
        ],
        'sdw' =>
        [
            0 => 'application/vnd.stardivision.writer',
        ],
        'vor' =>
        [
            0 => 'application/vnd.stardivision.writer',
        ],
        'sgl' =>
        [
            0 => 'application/vnd.stardivision.writer-global',
        ],
        'smzip' =>
        [
            0 => 'application/vnd.stepmania.package',
        ],
        'sm' =>
        [
            0 => 'application/vnd.stepmania.stepchart',
        ],
        'sxc' =>
        [
            0 => 'application/vnd.sun.xml.calc',
        ],
        'stc' =>
        [
            0 => 'application/vnd.sun.xml.calc.template',
        ],
        'sxd' =>
        [
            0 => 'application/vnd.sun.xml.draw',
        ],
        'std' =>
        [
            0 => 'application/vnd.sun.xml.draw.template',
        ],
        'sxi' =>
        [
            0 => 'application/vnd.sun.xml.impress',
        ],
        'sti' =>
        [
            0 => 'application/vnd.sun.xml.impress.template',
        ],
        'sxm' =>
        [
            0 => 'application/vnd.sun.xml.math',
        ],
        'sxw' =>
        [
            0 => 'application/vnd.sun.xml.writer',
        ],
        'sxg' =>
        [
            0 => 'application/vnd.sun.xml.writer.global',
        ],
        'stw' =>
        [
            0 => 'application/vnd.sun.xml.writer.template',
        ],
        'sus' =>
        [
            0 => 'application/vnd.sus-calendar',
        ],
        'susp' =>
        [
            0 => 'application/vnd.sus-calendar',
        ],
        'svd' =>
        [
            0 => 'application/vnd.svd',
        ],
        'sis' =>
        [
            0 => 'application/vnd.symbian.install',
        ],
        'sisx' =>
        [
            0 => 'application/vnd.symbian.install',
        ],
        'xsm' =>
        [
            0 => 'application/vnd.syncml+xml',
        ],
        'bdm' =>
        [
            0 => 'application/vnd.syncml.dm+wbxml',
        ],
        'xdm' =>
        [
            0 => 'application/vnd.syncml.dm+xml',
        ],
        'tao' =>
        [
            0 => 'application/vnd.tao.intent-module-archive',
        ],
        'pcap' =>
        [
            0 => 'application/vnd.tcpdump.pcap',
        ],
        'cap' =>
        [
            0 => 'application/vnd.tcpdump.pcap',
        ],
        'dmp' =>
        [
            0 => 'application/vnd.tcpdump.pcap',
        ],
        'tmo' =>
        [
            0 => 'application/vnd.tmobile-livetv',
        ],
        'tpt' =>
        [
            0 => 'application/vnd.trid.tpt',
        ],
        'mxs' =>
        [
            0 => 'application/vnd.triscape.mxs',
        ],
        'tra' =>
        [
            0 => 'application/vnd.trueapp',
        ],
        'ufd' =>
        [
            0 => 'application/vnd.ufdl',
        ],
        'ufdl' =>
        [
            0 => 'application/vnd.ufdl',
        ],
        'utz' =>
        [
            0 => 'application/vnd.uiq.theme',
        ],
        'umj' =>
        [
            0 => 'application/vnd.umajin',
        ],
        'unityweb' =>
        [
            0 => 'application/vnd.unity',
        ],
        'uoml' =>
        [
            0 => 'application/vnd.uoml+xml',
        ],
        'vcx' =>
        [
            0 => 'application/vnd.vcx',
        ],
        'vsd' =>
        [
            0 => 'application/vnd.visio',
        ],
        'vst' =>
        [
            0 => 'application/vnd.visio',
        ],
        'vss' =>
        [
            0 => 'application/vnd.visio',
        ],
        'vsw' =>
        [
            0 => 'application/vnd.visio',
        ],
        'vis' =>
        [
            0 => 'application/vnd.visionary',
        ],
        'vsf' =>
        [
            0 => 'application/vnd.vsf',
        ],
        'wbxml' =>
        [
            0 => 'application/vnd.wap.wbxml',
        ],
        'wmlc' =>
        [
            0 => 'application/vnd.wap.wmlc',
        ],
        'wmlsc' =>
        [
            0 => 'application/vnd.wap.wmlscriptc',
        ],
        'wtb' =>
        [
            0 => 'application/vnd.webturbo',
        ],
        'nbp' =>
        [
            0 => 'application/vnd.wolfram.player',
        ],
        'wpd' =>
        [
            0 => 'application/vnd.wordperfect',
        ],
        'wqd' =>
        [
            0 => 'application/vnd.wqd',
        ],
        'stf' =>
        [
            0 => 'application/vnd.wt.stf',
        ],
        'xar' =>
        [
            0 => 'application/vnd.xara',
        ],
        'xfdl' =>
        [
            0 => 'application/vnd.xfdl',
        ],
        'hvd' =>
        [
            0 => 'application/vnd.yamaha.hv-dic',
        ],
        'hvs' =>
        [
            0 => 'application/vnd.yamaha.hv-script',
        ],
        'hvp' =>
        [
            0 => 'application/vnd.yamaha.hv-voice',
        ],
        'osf' =>
        [
            0 => 'application/vnd.yamaha.openscoreformat',
        ],
        'osfpvg' =>
        [
            0 => 'application/vnd.yamaha.openscoreformat.osfpvg+xml',
        ],
        'saf' =>
        [
            0 => 'application/vnd.yamaha.smaf-audio',
        ],
        'spf' =>
        [
            0 => 'application/vnd.yamaha.smaf-phrase',
        ],
        'cmp' =>
        [
            0 => 'application/vnd.yellowriver-custom-menu',
        ],
        'zir' =>
        [
            0 => 'application/vnd.zul',
        ],
        'zirz' =>
        [
            0 => 'application/vnd.zul',
        ],
        'zaz' =>
        [
            0 => 'application/vnd.zzazz.deck+xml',
        ],
        'vxml' =>
        [
            0 => 'application/voicexml+xml',
        ],
        'wgt' =>
        [
            0 => 'application/widget',
        ],
        'hlp' =>
        [
            0 => 'application/winhlp',
        ],
        'wsdl' =>
        [
            0 => 'application/wsdl+xml',
        ],
        'wspolicy' =>
        [
            0 => 'application/wspolicy+xml',
        ],
        '7z' =>
        [
            0 => 'application/x-7z-compressed',
        ],
        'abw' =>
        [
            0 => 'application/x-abiword',
        ],
        'ace' =>
        [
            0 => 'application/x-ace-compressed',
        ],
        'dmg' =>
        [
            0 => 'application/x-apple-diskimage',
        ],
        'aab' =>
        [
            0 => 'application/x-authorware-bin',
        ],
        'x32' =>
        [
            0 => 'application/x-authorware-bin',
        ],
        'u32' =>
        [
            0 => 'application/x-authorware-bin',
        ],
        'vox' =>
        [
            0 => 'application/x-authorware-bin',
        ],
        'aam' =>
        [
            0 => 'application/x-authorware-map',
        ],
        'aas' =>
        [
            0 => 'application/x-authorware-seg',
        ],
        'bcpio' =>
        [
            0 => 'application/x-bcpio',
        ],
        'torrent' =>
        [
            0 => 'application/x-bittorrent',
        ],
        'blb' =>
        [
            0 => 'application/x-blorb',
        ],
        'blorb' =>
        [
            0 => 'application/x-blorb',
        ],
        'bz' =>
        [
            0 => 'application/x-bzip',
        ],
        'bz2' =>
        [
            0 => 'application/x-bzip2',
        ],
        'boz' =>
        [
            0 => 'application/x-bzip2',
        ],
        'cbr' =>
        [
            0 => 'application/x-cbr',
        ],
        'cba' =>
        [
            0 => 'application/x-cbr',
        ],
        'cbt' =>
        [
            0 => 'application/x-cbr',
        ],
        'cbz' =>
        [
            0 => 'application/x-cbr',
        ],
        'cb7' =>
        [
            0 => 'application/x-cbr',
        ],
        'vcd' =>
        [
            0 => 'application/x-cdlink',
        ],
        'cfs' =>
        [
            0 => 'application/x-cfs-compressed',
        ],
        'chat' =>
        [
            0 => 'application/x-chat',
        ],
        'pgn' =>
        [
            0 => 'application/x-chess-pgn',
        ],
        'nsc' =>
        [
            0 => 'application/x-conference',
        ],
        'cpio' =>
        [
            0 => 'application/x-cpio',
        ],
        'csh' =>
        [
            0 => 'application/x-csh',
        ],
        'deb' =>
        [
            0 => 'application/x-debian-package',
        ],
        'udeb' =>
        [
            0 => 'application/x-debian-package',
        ],
        'dgc' =>
        [
            0 => 'application/x-dgc-compressed',
        ],
        'dir' =>
        [
            0 => 'application/x-director',
        ],
        'dcr' =>
        [
            0 => 'application/x-director',
        ],
        'dxr' =>
        [
            0 => 'application/x-director',
        ],
        'cst' =>
        [
            0 => 'application/x-director',
        ],
        'cct' =>
        [
            0 => 'application/x-director',
        ],
        'cxt' =>
        [
            0 => 'application/x-director',
        ],
        'w3d' =>
        [
            0 => 'application/x-director',
        ],
        'fgd' =>
        [
            0 => 'application/x-director',
        ],
        'swa' =>
        [
            0 => 'application/x-director',
        ],
        'wad' =>
        [
            0 => 'application/x-doom',
        ],
        'ncx' =>
        [
            0 => 'application/x-dtbncx+xml',
        ],
        'dtb' =>
        [
            0 => 'application/x-dtbook+xml',
        ],
        'res' =>
        [
            0 => 'application/x-dtbresource+xml',
        ],
        'dvi' =>
        [
            0 => 'application/x-dvi',
        ],
        'evy' =>
        [
            0 => 'application/x-envoy',
        ],
        'eva' =>
        [
            0 => 'application/x-eva',
        ],
        'bdf' =>
        [
            0 => 'application/x-font-bdf',
        ],
        'gsf' =>
        [
            0 => 'application/x-font-ghostscript',
        ],
        'psf' =>
        [
            0 => 'application/x-font-linux-psf',
        ],
        'pcf' =>
        [
            0 => 'application/x-font-pcf',
        ],
        'snf' =>
        [
            0 => 'application/x-font-snf',
        ],
        'pfa' =>
        [
            0 => 'application/x-font-type1',
        ],
        'pfb' =>
        [
            0 => 'application/x-font-type1',
        ],
        'pfm' =>
        [
            0 => 'application/x-font-type1',
        ],
        'afm' =>
        [
            0 => 'application/x-font-type1',
        ],
        'arc' =>
        [
            0 => 'application/x-freearc',
        ],
        'spl' =>
        [
            0 => 'application/x-futuresplash',
        ],
        'gca' =>
        [
            0 => 'application/x-gca-compressed',
        ],
        'ulx' =>
        [
            0 => 'application/x-glulx',
        ],
        'gnumeric' =>
        [
            0 => 'application/x-gnumeric',
        ],
        'gramps' =>
        [
            0 => 'application/x-gramps-xml',
        ],
        'gtar' =>
        [
            0 => 'application/x-gtar',
        ],
        'hdf' =>
        [
            0 => 'application/x-hdf',
        ],
        'install' =>
        [
            0 => 'application/x-install-instructions',
        ],
        'iso' =>
        [
            0 => 'application/x-iso9660-image',
        ],
        'jnlp' =>
        [
            0 => 'application/x-java-jnlp-file',
        ],
        'latex' =>
        [
            0 => 'application/x-latex',
        ],
        'lzh' =>
        [
            0 => 'application/x-lzh-compressed',
        ],
        'lha' =>
        [
            0 => 'application/x-lzh-compressed',
        ],
        'mie' =>
        [
            0 => 'application/x-mie',
        ],
        'prc' =>
        [
            0 => 'application/x-mobipocket-ebook',
        ],
        'mobi' =>
        [
            0 => 'application/x-mobipocket-ebook',
        ],
        'application' =>
        [
            0 => 'application/x-ms-application',
        ],
        'lnk' =>
        [
            0 => 'application/x-ms-shortcut',
        ],
        'wmd' =>
        [
            0 => 'application/x-ms-wmd',
        ],
        'wmz' =>
        [
            0 => 'application/x-ms-wmz',
            1 => 'application/x-msmetafile',
        ],
        'xbap' =>
        [
            0 => 'application/x-ms-xbap',
        ],
        'mdb' =>
        [
            0 => 'application/x-msaccess',
        ],
        'obd' =>
        [
            0 => 'application/x-msbinder',
        ],
        'crd' =>
        [
            0 => 'application/x-mscardfile',
        ],
        'clp' =>
        [
            0 => 'application/x-msclip',
        ],
        'exe' =>
        [
            0 => 'application/x-msdownload',
        ],
        'dll' =>
        [
            0 => 'application/x-msdownload',
        ],
        'com' =>
        [
            0 => 'application/x-msdownload',
        ],
        'bat' =>
        [
            0 => 'application/x-msdownload',
        ],
        'msi' =>
        [
            0 => 'application/x-msdownload',
        ],
        'mvb' =>
        [
            0 => 'application/x-msmediaview',
        ],
        'm13' =>
        [
            0 => 'application/x-msmediaview',
        ],
        'm14' =>
        [
            0 => 'application/x-msmediaview',
        ],
        'wmf' =>
        [
            0 => 'application/x-msmetafile',
        ],
        'emf' =>
        [
            0 => 'application/x-msmetafile',
        ],
        'emz' =>
        [
            0 => 'application/x-msmetafile',
        ],
        'mny' =>
        [
            0 => 'application/x-msmoney',
        ],
        'pub' =>
        [
            0 => 'application/x-mspublisher',
        ],
        'scd' =>
        [
            0 => 'application/x-msschedule',
        ],
        'trm' =>
        [
            0 => 'application/x-msterminal',
        ],
        'wri' =>
        [
            0 => 'application/x-mswrite',
        ],
        'nc' =>
        [
            0 => 'application/x-netcdf',
        ],
        'cdf' =>
        [
            0 => 'application/x-netcdf',
        ],
        'nzb' =>
        [
            0 => 'application/x-nzb',
        ],
        'p12' =>
        [
            0 => 'application/x-pkcs12',
        ],
        'pfx' =>
        [
            0 => 'application/x-pkcs12',
        ],
        'p7b' =>
        [
            0 => 'application/x-pkcs7-certificates',
        ],
        'spc' =>
        [
            0 => 'application/x-pkcs7-certificates',
        ],
        'p7r' =>
        [
            0 => 'application/x-pkcs7-certreqresp',
        ],
        'rar' =>
        [
            0 => 'application/x-rar-compressed',
        ],
        'ris' =>
        [
            0 => 'application/x-research-info-systems',
        ],
        'sh' =>
        [
            0 => 'application/x-sh',
        ],
        'shar' =>
        [
            0 => 'application/x-shar',
        ],
        'swf' =>
        [
            0 => 'application/x-shockwave-flash',
        ],
        'xap' =>
        [
            0 => 'application/x-silverlight-app',
        ],
        'sql' =>
        [
            0 => 'application/x-sql',
        ],
        'sit' =>
        [
            0 => 'application/x-stuffit',
        ],
        'sitx' =>
        [
            0 => 'application/x-stuffitx',
        ],
        'srt' =>
        [
            0 => 'application/x-subrip',
        ],
        'sv4cpio' =>
        [
            0 => 'application/x-sv4cpio',
        ],
        'sv4crc' =>
        [
            0 => 'application/x-sv4crc',
        ],
        't3' =>
        [
            0 => 'application/x-t3vm-image',
        ],
        'gam' =>
        [
            0 => 'application/x-tads',
        ],
        'tar' =>
        [
            0 => 'application/x-tar',
        ],
        'tcl' =>
        [
            0 => 'application/x-tcl',
        ],
        'tex' =>
        [
            0 => 'application/x-tex',
        ],
        'tfm' =>
        [
            0 => 'application/x-tex-tfm',
        ],
        'texinfo' =>
        [
            0 => 'application/x-texinfo',
        ],
        'texi' =>
        [
            0 => 'application/x-texinfo',
        ],
        'obj' =>
        [
            0 => 'application/x-tgif',
        ],
        'ustar' =>
        [
            0 => 'application/x-ustar',
        ],
        'src' =>
        [
            0 => 'application/x-wais-source',
        ],
        'der' =>
        [
            0 => 'application/x-x509-ca-cert',
        ],
        'crt' =>
        [
            0 => 'application/x-x509-ca-cert',
        ],
        'fig' =>
        [
            0 => 'application/x-xfig',
        ],
        'xlf' =>
        [
            0 => 'application/x-xliff+xml',
        ],
        'xpi' =>
        [
            0 => 'application/x-xpinstall',
        ],
        'xz' =>
        [
            0 => 'application/x-xz',
        ],
        'z1' =>
        [
            0 => 'application/x-zmachine',
        ],
        'z2' =>
        [
            0 => 'application/x-zmachine',
        ],
        'z3' =>
        [
            0 => 'application/x-zmachine',
        ],
        'z4' =>
        [
            0 => 'application/x-zmachine',
        ],
        'z5' =>
        [
            0 => 'application/x-zmachine',
        ],
        'z6' =>
        [
            0 => 'application/x-zmachine',
        ],
        'z7' =>
        [
            0 => 'application/x-zmachine',
        ],
        'z8' =>
        [
            0 => 'application/x-zmachine',
        ],
        'xaml' =>
        [
            0 => 'application/xaml+xml',
        ],
        'xdf' =>
        [
            0 => 'application/xcap-diff+xml',
        ],
        'xenc' =>
        [
            0 => 'application/xenc+xml',
        ],
        'xhtml' =>
        [
            0 => 'application/xhtml+xml',
        ],
        'xht' =>
        [
            0 => 'application/xhtml+xml',
        ],
        'xml' =>
        [
            0 => 'application/xml',
        ],
        'xsl' =>
        [
            0 => 'application/xml',
        ],
        'dtd' =>
        [
            0 => 'application/xml-dtd',
        ],
        'xop' =>
        [
            0 => 'application/xop+xml',
        ],
        'xpl' =>
        [
            0 => 'application/xproc+xml',
        ],
        'xslt' =>
        [
            0 => 'application/xslt+xml',
        ],
        'xspf' =>
        [
            0 => 'application/xspf+xml',
        ],
        'mxml' =>
        [
            0 => 'application/xv+xml',
        ],
        'xhvml' =>
        [
            0 => 'application/xv+xml',
        ],
        'xvml' =>
        [
            0 => 'application/xv+xml',
        ],
        'xvm' =>
        [
            0 => 'application/xv+xml',
        ],
        'yang' =>
        [
            0 => 'application/yang',
        ],
        'yin' =>
        [
            0 => 'application/yin+xml',
        ],
        'adp' =>
        [
            0 => 'audio/adpcm',
        ],
        'au' =>
        [
            0 => 'audio/basic',
        ],
        'snd' =>
        [
            0 => 'audio/basic',
        ],
        'mid' =>
        [
            0 => 'audio/midi',
        ],
        'midi' =>
        [
            0 => 'audio/midi',
        ],
        'kar' =>
        [
            0 => 'audio/midi',
        ],
        'rmi' =>
        [
            0 => 'audio/midi',
        ],
        'm4a' =>
        [
            0 => 'audio/mp4',
        ],
        'mp4a' =>
        [
            0 => 'audio/mp4',
        ],
        'oga' =>
        [
            0 => 'audio/ogg',
        ],
        'ogg' =>
        [
            0 => 'audio/ogg',
        ],
        'spx' =>
        [
            0 => 'audio/ogg',
        ],
        's3m' =>
        [
            0 => 'audio/s3m',
        ],
        'sil' =>
        [
            0 => 'audio/silk',
        ],
        'uva' =>
        [
            0 => 'audio/vnd.dece.audio',
        ],
        'uvva' =>
        [
            0 => 'audio/vnd.dece.audio',
        ],
        'eol' =>
        [
            0 => 'audio/vnd.digital-winds',
        ],
        'dra' =>
        [
            0 => 'audio/vnd.dra',
        ],
        'dts' =>
        [
            0 => 'audio/vnd.dts',
        ],
        'dtshd' =>
        [
            0 => 'audio/vnd.dts.hd',
        ],
        'lvp' =>
        [
            0 => 'audio/vnd.lucent.voice',
        ],
        'pya' =>
        [
            0 => 'audio/vnd.ms-playready.media.pya',
        ],
        'ecelp4800' =>
        [
            0 => 'audio/vnd.nuera.ecelp4800',
        ],
        'ecelp7470' =>
        [
            0 => 'audio/vnd.nuera.ecelp7470',
        ],
        'ecelp9600' =>
        [
            0 => 'audio/vnd.nuera.ecelp9600',
        ],
        'rip' =>
        [
            0 => 'audio/vnd.rip',
        ],
        'weba' =>
        [
            0 => 'audio/webm',
        ],
        'aac' =>
        [
            0 => 'audio/x-aac',
        ],
        'aif' =>
        [
            0 => 'audio/x-aiff',
        ],
        'aiff' =>
        [
            0 => 'audio/x-aiff',
        ],
        'aifc' =>
        [
            0 => 'audio/x-aiff',
        ],
        'caf' =>
        [
            0 => 'audio/x-caf',
        ],
        'flac' =>
        [
            0 => 'audio/x-flac',
        ],
        'mka' =>
        [
            0 => 'audio/x-matroska',
        ],
        'm3u' =>
        [
            0 => 'audio/x-mpegurl',
        ],
        'wax' =>
        [
            0 => 'audio/x-ms-wax',
        ],
        'wma' =>
        [
            0 => 'audio/x-ms-wma',
        ],
        'ram' =>
        [
            0 => 'audio/x-pn-realaudio',
        ],
        'ra' =>
        [
            0 => 'audio/x-pn-realaudio',
        ],
        'rmp' =>
        [
            0 => 'audio/x-pn-realaudio-plugin',
        ],
        'wav' =>
        [
            0 => 'audio/x-wav',
        ],
        'xm' =>
        [
            0 => 'audio/xm',
        ],
        'cdx' =>
        [
            0 => 'chemical/x-cdx',
        ],
        'cif' =>
        [
            0 => 'chemical/x-cif',
        ],
        'cmdf' =>
        [
            0 => 'chemical/x-cmdf',
        ],
        'cml' =>
        [
            0 => 'chemical/x-cml',
        ],
        'csml' =>
        [
            0 => 'chemical/x-csml',
        ],
        'xyz' =>
        [
            0 => 'chemical/x-xyz',
        ],
        'woff' =>
        [
            0 => 'font/woff',
        ],
        'woff2' =>
        [
            0 => 'font/woff2',
        ],
        'cgm' =>
        [
            0 => 'image/cgm',
        ],
        'g3' =>
        [
            0 => 'image/g3fax',
        ],
        'gif' =>
        [
            0 => 'image/gif',
        ],
        'ief' =>
        [
            0 => 'image/ief',
        ],
        'ktx' =>
        [
            0 => 'image/ktx',
        ],
        'png' =>
        [
            0 => 'image/png',
        ],
        'btif' =>
        [
            0 => 'image/prs.btif',
        ],
        'sgi' =>
        [
            0 => 'image/sgi',
        ],
        'svg' =>
        [
            0 => 'image/svg+xml',
        ],
        'svgz' =>
        [
            0 => 'image/svg+xml',
        ],
        'tiff' =>
        [
            0 => 'image/tiff',
        ],
        'tif' =>
        [
            0 => 'image/tiff',
        ],
        'psd' =>
        [
            0 => 'image/vnd.adobe.photoshop',
        ],
        'uvi' =>
        [
            0 => 'image/vnd.dece.graphic',
        ],
        'uvvi' =>
        [
            0 => 'image/vnd.dece.graphic',
        ],
        'uvg' =>
        [
            0 => 'image/vnd.dece.graphic',
        ],
        'uvvg' =>
        [
            0 => 'image/vnd.dece.graphic',
        ],
        'djvu' =>
        [
            0 => 'image/vnd.djvu',
        ],
        'djv' =>
        [
            0 => 'image/vnd.djvu',
        ],
        'sub' =>
        [
            0 => 'image/vnd.dvb.subtitle',
            1 => 'text/vnd.dvb.subtitle',
        ],
        'dwg' =>
        [
            0 => 'image/vnd.dwg',
        ],
        'dxf' =>
        [
            0 => 'image/vnd.dxf',
        ],
        'fbs' =>
        [
            0 => 'image/vnd.fastbidsheet',
        ],
        'fpx' =>
        [
            0 => 'image/vnd.fpx',
        ],
        'fst' =>
        [
            0 => 'image/vnd.fst',
        ],
        'mmr' =>
        [
            0 => 'image/vnd.fujixerox.edmics-mmr',
        ],
        'rlc' =>
        [
            0 => 'image/vnd.fujixerox.edmics-rlc',
        ],
        'mdi' =>
        [
            0 => 'image/vnd.ms-modi',
        ],
        'wdp' =>
        [
            0 => 'image/vnd.ms-photo',
        ],
        'npx' =>
        [
            0 => 'image/vnd.net-fpx',
        ],
        'wbmp' =>
        [
            0 => 'image/vnd.wap.wbmp',
        ],
        'xif' =>
        [
            0 => 'image/vnd.xiff',
        ],
        'webp' =>
        [
            0 => 'image/webp',
        ],
        '3ds' =>
        [
            0 => 'image/x-3ds',
        ],
        'ras' =>
        [
            0 => 'image/x-cmu-raster',
        ],
        'cmx' =>
        [
            0 => 'image/x-cmx',
        ],
        'fh' =>
        [
            0 => 'image/x-freehand',
        ],
        'fhc' =>
        [
            0 => 'image/x-freehand',
        ],
        'fh4' =>
        [
            0 => 'image/x-freehand',
        ],
        'fh5' =>
        [
            0 => 'image/x-freehand',
        ],
        'fh7' =>
        [
            0 => 'image/x-freehand',
        ],
        'ico' =>
        [
            0 => 'image/x-icon',
        ],
        'sid' =>
        [
            0 => 'image/x-mrsid-image',
        ],
        'pcx' =>
        [
            0 => 'image/x-pcx',
        ],
        'pic' =>
        [
            0 => 'image/x-pict',
        ],
        'pct' =>
        [
            0 => 'image/x-pict',
        ],
        'pnm' =>
        [
            0 => 'image/x-portable-anymap',
        ],
        'pbm' =>
        [
            0 => 'image/x-portable-bitmap',
        ],
        'pgm' =>
        [
            0 => 'image/x-portable-graymap',
        ],
        'ppm' =>
        [
            0 => 'image/x-portable-pixmap',
        ],
        'rgb' =>
        [
            0 => 'image/x-rgb',
        ],
        'tga' =>
        [
            0 => 'image/x-tga',
        ],
        'xbm' =>
        [
            0 => 'image/x-xbitmap',
        ],
        'xpm' =>
        [
            0 => 'image/x-xpixmap',
        ],
        'xwd' =>
        [
            0 => 'image/x-xwindowdump',
        ],
        'eml' =>
        [
            0 => 'message/rfc822',
        ],
        'mime' =>
        [
            0 => 'message/rfc822',
        ],
        'igs' =>
        [
            0 => 'model/iges',
        ],
        'iges' =>
        [
            0 => 'model/iges',
        ],
        'msh' =>
        [
            0 => 'model/mesh',
        ],
        'mesh' =>
        [
            0 => 'model/mesh',
        ],
        'silo' =>
        [
            0 => 'model/mesh',
        ],
        'dae' =>
        [
            0 => 'model/vnd.collada+xml',
        ],
        'dwf' =>
        [
            0 => 'model/vnd.dwf',
        ],
        'gdl' =>
        [
            0 => 'model/vnd.gdl',
        ],
        'gtw' =>
        [
            0 => 'model/vnd.gtw',
        ],
        'mts' =>
        [
            0 => 'model/vnd.mts',
        ],
        'vtu' =>
        [
            0 => 'model/vnd.vtu',
        ],
        'wrl' =>
        [
            0 => 'model/vrml',
        ],
        'vrml' =>
        [
            0 => 'model/vrml',
        ],
        'x3db' =>
        [
            0 => 'model/x3d+binary',
        ],
        'x3dbz' =>
        [
            0 => 'model/x3d+binary',
        ],
        'x3dv' =>
        [
            0 => 'model/x3d+vrml',
        ],
        'x3dvz' =>
        [
            0 => 'model/x3d+vrml',
        ],
        'x3d' =>
        [
            0 => 'model/x3d+xml',
        ],
        'x3dz' =>
        [
            0 => 'model/x3d+xml',
        ],
        'appcache' =>
        [
            0 => 'text/cache-manifest',
        ],
        'ics' =>
        [
            0 => 'text/calendar',
        ],
        'ifb' =>
        [
            0 => 'text/calendar',
        ],
        'css' =>
        [
            0 => 'text/css',
        ],
        'csv' =>
        [
            0 => 'text/csv',
        ],
        'html' =>
        [
            0 => 'text/html',
        ],
        'htm' =>
        [
            0 => 'text/html',
        ],
        'n3' =>
        [
            0 => 'text/n3',
        ],
        'txt' =>
        [
            0 => 'text/plain',
        ],
        'text' =>
        [
            0 => 'text/plain',
        ],
        'conf' =>
        [
            0 => 'text/plain',
        ],
        'def' =>
        [
            0 => 'text/plain',
        ],
        'list' =>
        [
            0 => 'text/plain',
        ],
        'log' =>
        [
            0 => 'text/plain',
        ],
        'in' =>
        [
            0 => 'text/plain',
        ],
        'dsc' =>
        [
            0 => 'text/prs.lines.tag',
        ],
        'rtx' =>
        [
            0 => 'text/richtext',
        ],
        'sgml' =>
        [
            0 => 'text/sgml',
        ],
        'sgm' =>
        [
            0 => 'text/sgml',
        ],
        'tsv' =>
        [
            0 => 'text/tab-separated-values',
        ],
        't' =>
        [
            0 => 'text/troff',
        ],
        'tr' =>
        [
            0 => 'text/troff',
        ],
        'roff' =>
        [
            0 => 'text/troff',
        ],
        'man' =>
        [
            0 => 'text/troff',
        ],
        'me' =>
        [
            0 => 'text/troff',
        ],
        'ms' =>
        [
            0 => 'text/troff',
        ],
        'ttl' =>
        [
            0 => 'text/turtle',
        ],
        'uri' =>
        [
            0 => 'text/uri-list',
        ],
        'uris' =>
        [
            0 => 'text/uri-list',
        ],
        'urls' =>
        [
            0 => 'text/uri-list',
        ],
        'vcard' =>
        [
            0 => 'text/vcard',
        ],
        'curl' =>
        [
            0 => 'text/vnd.curl',
        ],
        'dcurl' =>
        [
            0 => 'text/vnd.curl.dcurl',
        ],
        'mcurl' =>
        [
            0 => 'text/vnd.curl.mcurl',
        ],
        'scurl' =>
        [
            0 => 'text/vnd.curl.scurl',
        ],
        'fly' =>
        [
            0 => 'text/vnd.fly',
        ],
        'flx' =>
        [
            0 => 'text/vnd.fmi.flexstor',
        ],
        'gv' =>
        [
            0 => 'text/vnd.graphviz',
        ],
        '3dml' =>
        [
            0 => 'text/vnd.in3d.3dml',
        ],
        'spot' =>
        [
            0 => 'text/vnd.in3d.spot',
        ],
        'jad' =>
        [
            0 => 'text/vnd.sun.j2me.app-descriptor',
        ],
        'wml' =>
        [
            0 => 'text/vnd.wap.wml',
        ],
        'wmls' =>
        [
            0 => 'text/vnd.wap.wmlscript',
        ],
        's' =>
        [
            0 => 'text/x-asm',
        ],
        'asm' =>
        [
            0 => 'text/x-asm',
        ],
        'c' =>
        [
            0 => 'text/x-c',
        ],
        'cc' =>
        [
            0 => 'text/x-c',
        ],
        'cxx' =>
        [
            0 => 'text/x-c',
        ],
        'cpp' =>
        [
            0 => 'text/x-c',
        ],
        'h' =>
        [
            0 => 'text/x-c',
        ],
        'hh' =>
        [
            0 => 'text/x-c',
        ],
        'dic' =>
        [
            0 => 'text/x-c',
        ],
        'f' =>
        [
            0 => 'text/x-fortran',
        ],
        'for' =>
        [
            0 => 'text/x-fortran',
        ],
        'f77' =>
        [
            0 => 'text/x-fortran',
        ],
        'f90' =>
        [
            0 => 'text/x-fortran',
        ],
        'java' =>
        [
            0 => 'text/x-java-source',
        ],
        'nfo' =>
        [
            0 => 'text/x-nfo',
        ],
        'opml' =>
        [
            0 => 'text/x-opml',
        ],
        'p' =>
        [
            0 => 'text/x-pascal',
        ],
        'pas' =>
        [
            0 => 'text/x-pascal',
        ],
        'etx' =>
        [
            0 => 'text/x-setext',
        ],
        'sfv' =>
        [
            0 => 'text/x-sfv',
        ],
        'uu' =>
        [
            0 => 'text/x-uuencode',
        ],
        'vcs' =>
        [
            0 => 'text/x-vcalendar',
        ],
        'vcf' =>
        [
            0 => 'text/x-vcard',
        ],
        '3gp' =>
        [
            0 => 'video/3gpp',
        ],
        '3g2' =>
        [
            0 => 'video/3gpp2',
        ],
        'h261' =>
        [
            0 => 'video/h261',
        ],
        'h263' =>
        [
            0 => 'video/h263',
        ],
        'h264' =>
        [
            0 => 'video/h264',
        ],
        'jpgv' =>
        [
            0 => 'video/jpeg',
        ],
        'jpm' =>
        [
            0 => 'video/jpm',
        ],
        'jpgm' =>
        [
            0 => 'video/jpm',
        ],
        'mj2' =>
        [
            0 => 'video/mj2',
        ],
        'mjp2' =>
        [
            0 => 'video/mj2',
        ],
        'mp4' =>
        [
            0 => 'video/mp4',
        ],
        'mp4v' =>
        [
            0 => 'video/mp4',
        ],
        'mpg4' =>
        [
            0 => 'video/mp4',
        ],
        'mpeg' =>
        [
            0 => 'video/mpeg',
        ],
        'mpg' =>
        [
            0 => 'video/mpeg',
        ],
        'mpe' =>
        [
            0 => 'video/mpeg',
        ],
        'm1v' =>
        [
            0 => 'video/mpeg',
        ],
        'm2v' =>
        [
            0 => 'video/mpeg',
        ],
        'ogv' =>
        [
            0 => 'video/ogg',
        ],
        'qt' =>
        [
            0 => 'video/quicktime',
        ],
        'mov' =>
        [
            0 => 'video/quicktime',
        ],
        'uvh' =>
        [
            0 => 'video/vnd.dece.hd',
        ],
        'uvvh' =>
        [
            0 => 'video/vnd.dece.hd',
        ],
        'uvm' =>
        [
            0 => 'video/vnd.dece.mobile',
        ],
        'uvvm' =>
        [
            0 => 'video/vnd.dece.mobile',
        ],
        'uvp' =>
        [
            0 => 'video/vnd.dece.pd',
        ],
        'uvvp' =>
        [
            0 => 'video/vnd.dece.pd',
        ],
        'uvs' =>
        [
            0 => 'video/vnd.dece.sd',
        ],
        'uvvs' =>
        [
            0 => 'video/vnd.dece.sd',
        ],
        'uvv' =>
        [
            0 => 'video/vnd.dece.video',
        ],
        'uvvv' =>
        [
            0 => 'video/vnd.dece.video',
        ],
        'dvb' =>
        [
            0 => 'video/vnd.dvb.file',
        ],
        'fvt' =>
        [
            0 => 'video/vnd.fvt',
        ],
        'mxu' =>
        [
            0 => 'video/vnd.mpegurl',
        ],
        'm4u' =>
        [
            0 => 'video/vnd.mpegurl',
        ],
        'pyv' =>
        [
            0 => 'video/vnd.ms-playready.media.pyv',
        ],
        'uvu' =>
        [
            0 => 'video/vnd.uvvu.mp4',
        ],
        'uvvu' =>
        [
            0 => 'video/vnd.uvvu.mp4',
        ],
        'viv' =>
        [
            0 => 'video/vnd.vivo',
        ],
        'webm' =>
        [
            0 => 'video/webm',
        ],
        'f4v' =>
        [
            0 => 'video/x-f4v',
        ],
        'fli' =>
        [
            0 => 'video/x-fli',
        ],
        'flv' =>
        [
            0 => 'video/x-flv',
        ],
        'm4v' =>
        [
            0 => 'video/x-m4v',
        ],
        'mkv' =>
        [
            0 => 'video/x-matroska',
        ],
        'mk3d' =>
        [
            0 => 'video/x-matroska',
        ],
        'mks' =>
        [
            0 => 'video/x-matroska',
        ],
        'mng' =>
        [
            0 => 'video/x-mng',
        ],
        'asf' =>
        [
            0 => 'video/x-ms-asf',
        ],
        'asx' =>
        [
            0 => 'video/x-ms-asf',
        ],
        'vob' =>
        [
            0 => 'video/x-ms-vob',
        ],
        'wm' =>
        [
            0 => 'video/x-ms-wm',
        ],
        'wmv' =>
        [
            0 => 'video/x-ms-wmv',
        ],
        'wmx' =>
        [
            0 => 'video/x-ms-wmx',
        ],
        'wvx' =>
        [
            0 => 'video/x-ms-wvx',
        ],
        'avi' =>
        [
            0 => 'video/x-msvideo',
        ],
        'movie' =>
        [
            0 => 'video/x-sgi-movie',
        ],
        'smv' =>
        [
            0 => 'video/x-smv',
        ],
        'ice' =>
        [
            0 => 'x-conference/x-cooltalk',
        ],
    ],

    /*
    
    /////////////////////////////////////////////////////
    
    
    
    
    
    
    
    /////////////////////////break for extensions
    
    
    
    
    
    
    
    /////////////////////////////////////////////////////
    
    */
    'extensions' =>
    [
        'application/font-woff' =>
        [
            0 => 'wof',
        ],
        'application/php' =>
        [
            0 => 'php',
        ],
        'application/x-font-otf' =>
        [
            0 => 'otf',
        ],
        'application/x-font-ttf' =>
        [
            0 => 'ttf',
            1 => 'ttc',
        ],
        'application/x-gzip' =>
        [
            0 => 'zip',
        ],
        'application/x-httpd-php' =>
        [
            0 => 'php',
        ],
        'application/x-httpd-php-source' =>
        [
            0 => 'php',
        ],
        'application/x-php' =>
        [
            0 => 'php',
        ],
        'audio/amr' =>
        [
            0 => 'amr',
        ],
        'audio/mpeg' =>
        [
            0 => 'mp3',
            1 => 'mpga',
            2 => 'mp2',
            3 => 'mp2a',
            4 => 'm2a',
            5 => 'm3a',
        ],
        'image/jpeg' =>
        [
            0 => 'jpg',
            1 => 'jpeg',
            2 => 'jpe',
        ],
        'image/x-ms-bmp' =>
        [
            0 => 'bmp',
        ],
        'text/php' =>
        [
            0 => 'php',
        ],
        'text/x-php' =>
        [
            0 => 'php',
        ],
        'application/andrew-inset' =>
        [
            0 => 'ez',
        ],
        'application/applixware' =>
        [
            0 => 'aw',
        ],
        'application/atom+xml' =>
        [
            0 => 'atom',
        ],
        'application/atomcat+xml' =>
        [
            0 => 'atomcat',
        ],
        'application/atomsvc+xml' =>
        [
            0 => 'atomsvc',
        ],
        'application/ccxml+xml' =>
        [
            0 => 'ccxml',
        ],
        'application/cdmi-capability' =>
        [
            0 => 'cdmia',
        ],
        'application/cdmi-container' =>
        [
            0 => 'cdmic',
        ],
        'application/cdmi-domain' =>
        [
            0 => 'cdmid',
        ],
        'application/cdmi-object' =>
        [
            0 => 'cdmio',
        ],
        'application/cdmi-queue' =>
        [
            0 => 'cdmiq',
        ],
        'application/cu-seeme' =>
        [
            0 => 'cu',
        ],
        'application/davmount+xml' =>
        [
            0 => 'davmount',
        ],
        'application/docbook+xml' =>
        [
            0 => 'dbk',
        ],
        'application/dssc+der' =>
        [
            0 => 'dssc',
        ],
        'application/dssc+xml' =>
        [
            0 => 'xdssc',
        ],
        'application/ecmascript' =>
        [
            0 => 'ecma',
        ],
        'application/emma+xml' =>
        [
            0 => 'emma',
        ],
        'application/epub+zip' =>
        [
            0 => 'epub',
        ],
        'application/exi' =>
        [
            0 => 'exi',
        ],
        'application/font-tdpfr' =>
        [
            0 => 'pfr',
        ],
        'application/gml+xml' =>
        [
            0 => 'gml',
        ],
        'application/gpx+xml' =>
        [
            0 => 'gpx',
        ],
        'application/gxf' =>
        [
            0 => 'gxf',
        ],
        'application/hyperstudio' =>
        [
            0 => 'stk',
        ],
        'application/inkml+xml' =>
        [
            0 => 'ink',
            1 => 'inkml',
        ],
        'application/ipfix' =>
        [
            0 => 'ipfix',
        ],
        'application/java-archive' =>
        [
            0 => 'jar',
        ],
        'application/java-serialized-object' =>
        [
            0 => 'ser',
        ],
        'application/java-vm' =>
        [
            0 => 'class',
        ],
        'application/javascript' =>
        [
            0 => 'js',
            0 => 'mjs',
        ],
        'application/json' =>
        [
            0 => 'json',
        ],
        'application/jsonml+json' =>
        [
            0 => 'jsonml',
        ],
        'application/lost+xml' =>
        [
            0 => 'lostxml',
        ],
        'application/mac-binhex40' =>
        [
            0 => 'hqx',
        ],
        'application/mac-compactpro' =>
        [
            0 => 'cpt',
        ],
        'application/mads+xml' =>
        [
            0 => 'mads',
        ],
        'application/marc' =>
        [
            0 => 'mrc',
        ],
        'application/marcxml+xml' =>
        [
            0 => 'mrcx',
        ],
        'application/mathematica' =>
        [
            0 => 'ma',
            1 => 'nb',
            2 => 'mb',
        ],
        'application/mathml+xml' =>
        [
            0 => 'mathml',
        ],
        'application/mbox' =>
        [
            0 => 'mbox',
        ],
        'application/mediaservercontrol+xml' =>
        [
            0 => 'mscml',
        ],
        'application/metalink+xml' =>
        [
            0 => 'metalink',
        ],
        'application/metalink4+xml' =>
        [
            0 => 'meta4',
        ],
        'application/mets+xml' =>
        [
            0 => 'mets',
        ],
        'application/mods+xml' =>
        [
            0 => 'mods',
        ],
        'application/mp21' =>
        [
            0 => 'm21',
            1 => 'mp21',
        ],
        'application/mp4' =>
        [
            0 => 'mp4s',
        ],
        'application/msword' =>
        [
            0 => 'doc',
            1 => 'dot',
        ],
        'application/mxf' =>
        [
            0 => 'mxf',
        ],
        'application/octet-stream' =>
        [
            0 => 'bin',
            1 => 'dms',
            2 => 'lrf',
            3 => 'mar',
            4 => 'so',
            5 => 'dist',
            6 => 'distz',
            7 => 'pkg',
            8 => 'bpk',
            9 => 'dump',
            10 => 'elc',
            11 => 'deploy',
        ],
        'application/oda' =>
        [
            0 => 'oda',
        ],
        'application/oebps-package+xml' =>
        [
            0 => 'opf',
        ],
        'application/ogg' =>
        [
            0 => 'ogx',
        ],
        'application/omdoc+xml' =>
        [
            0 => 'omdoc',
        ],
        'application/onenote' =>
        [
            0 => 'onetoc',
            1 => 'onetoc2',
            2 => 'onetmp',
            3 => 'onepkg',
        ],
        'application/oxps' =>
        [
            0 => 'oxps',
        ],
        'application/patch-ops-error+xml' =>
        [
            0 => 'xer',
        ],
        'application/pdf' =>
        [
            0 => 'pdf',
        ],
        'application/pgp-encrypted' =>
        [
            0 => 'pgp',
        ],
        'application/pgp-signature' =>
        [
            0 => 'asc',
            1 => 'sig',
        ],
        'application/pics-rules' =>
        [
            0 => 'prf',
        ],
        'application/pkcs10' =>
        [
            0 => 'p10',
        ],
        'application/pkcs7-mime' =>
        [
            0 => 'p7m',
            1 => 'p7c',
        ],
        'application/pkcs7-signature' =>
        [
            0 => 'p7s',
        ],
        'application/pkcs8' =>
        [
            0 => 'p8',
        ],
        'application/pkix-attr-cert' =>
        [
            0 => 'ac',
        ],
        'application/pkix-cert' =>
        [
            0 => 'cer',
        ],
        'application/pkix-crl' =>
        [
            0 => 'crl',
        ],
        'application/pkix-pkipath' =>
        [
            0 => 'pkipath',
        ],
        'application/pkixcmp' =>
        [
            0 => 'pki',
        ],
        'application/pls+xml' =>
        [
            0 => 'pls',
        ],
        'application/postscript' =>
        [
            0 => 'ai',
            1 => 'eps',
            2 => 'ps',
        ],
        'application/prs.cww' =>
        [
            0 => 'cww',
        ],
        'application/pskc+xml' =>
        [
            0 => 'pskcxml',
        ],
        'application/rdf+xml' =>
        [
            0 => 'rdf',
        ],
        'application/reginfo+xml' =>
        [
            0 => 'rif',
        ],
        'application/relax-ng-compact-syntax' =>
        [
            0 => 'rnc',
        ],
        'application/resource-lists+xml' =>
        [
            0 => 'rl',
        ],
        'application/resource-lists-diff+xml' =>
        [
            0 => 'rld',
        ],
        'application/rls-services+xml' =>
        [
            0 => 'rs',
        ],
        'application/rpki-ghostbusters' =>
        [
            0 => 'gbr',
        ],
        'application/rpki-manifest' =>
        [
            0 => 'mft',
        ],
        'application/rpki-roa' =>
        [
            0 => 'roa',
        ],
        'application/rsd+xml' =>
        [
            0 => 'rsd',
        ],
        'application/rss+xml' =>
        [
            0 => 'rss',
        ],
        'application/rtf' =>
        [
            0 => 'rtf',
        ],
        'application/sbml+xml' =>
        [
            0 => 'sbml',
        ],
        'application/scvp-cv-request' =>
        [
            0 => 'scq',
        ],
        'application/scvp-cv-response' =>
        [
            0 => 'scs',
        ],
        'application/scvp-vp-request' =>
        [
            0 => 'spq',
        ],
        'application/scvp-vp-response' =>
        [
            0 => 'spp',
        ],
        'application/sdp' =>
        [
            0 => 'sdp',
        ],
        'application/set-payment-initiation' =>
        [
            0 => 'setpay',
        ],
        'application/set-registration-initiation' =>
        [
            0 => 'setreg',
        ],
        'application/shf+xml' =>
        [
            0 => 'shf',
        ],
        'application/smil+xml' =>
        [
            0 => 'smi',
            1 => 'smil',
        ],
        'application/sparql-query' =>
        [
            0 => 'rq',
        ],
        'application/sparql-results+xml' =>
        [
            0 => 'srx',
        ],
        'application/srgs' =>
        [
            0 => 'gram',
        ],
        'application/srgs+xml' =>
        [
            0 => 'grxml',
        ],
        'application/sru+xml' =>
        [
            0 => 'sru',
        ],
        'application/ssdl+xml' =>
        [
            0 => 'ssdl',
        ],
        'application/ssml+xml' =>
        [
            0 => 'ssml',
        ],
        'application/tei+xml' =>
        [
            0 => 'tei',
            1 => 'teicorpus',
        ],
        'application/thraud+xml' =>
        [
            0 => 'tfi',
        ],
        'application/timestamped-data' =>
        [
            0 => 'tsd',
        ],
        'application/vnd.3gpp.pic-bw-large' =>
        [
            0 => 'plb',
        ],
        'application/vnd.3gpp.pic-bw-small' =>
        [
            0 => 'psb',
        ],
        'application/vnd.3gpp.pic-bw-var' =>
        [
            0 => 'pvb',
        ],
        'application/vnd.3gpp2.tcap' =>
        [
            0 => 'tcap',
        ],
        'application/vnd.3m.post-it-notes' =>
        [
            0 => 'pwn',
        ],
        'application/vnd.accpac.simply.aso' =>
        [
            0 => 'aso',
        ],
        'application/vnd.accpac.simply.imp' =>
        [
            0 => 'imp',
        ],
        'application/vnd.acucobol' =>
        [
            0 => 'acu',
        ],
        'application/vnd.acucorp' =>
        [
            0 => 'atc',
            1 => 'acutc',
        ],
        'application/vnd.adobe.air-application-installer-package+zip' =>
        [
            0 => 'air',
        ],
        'application/vnd.adobe.formscentral.fcdt' =>
        [
            0 => 'fcdt',
        ],
        'application/vnd.adobe.fxp' =>
        [
            0 => 'fxp',
            1 => 'fxpl',
        ],
        'application/vnd.adobe.xdp+xml' =>
        [
            0 => 'xdp',
        ],
        'application/vnd.adobe.xfdf' =>
        [
            0 => 'xfdf',
        ],
        'application/vnd.ahead.space' =>
        [
            0 => 'ahead',
        ],
        'application/vnd.airzip.filesecure.azf' =>
        [
            0 => 'azf',
        ],
        'application/vnd.airzip.filesecure.azs' =>
        [
            0 => 'azs',
        ],
        'application/vnd.amazon.ebook' =>
        [
            0 => 'azw',
        ],
        'application/vnd.americandynamics.acc' =>
        [
            0 => 'acc',
        ],
        'application/vnd.amiga.ami' =>
        [
            0 => 'ami',
        ],
        'application/vnd.android.package-archive' =>
        [
            0 => 'apk',
        ],
        'application/vnd.anser-web-certificate-issue-initiation' =>
        [
            0 => 'cii',
        ],
        'application/vnd.anser-web-funds-transfer-initiation' =>
        [
            0 => 'fti',
        ],
        'application/vnd.antix.game-component' =>
        [
            0 => 'atx',
        ],
        'application/vnd.apple.installer+xml' =>
        [
            0 => 'mpkg',
        ],
        'application/vnd.apple.mpegurl' =>
        [
            0 => 'm3u8',
        ],
        'application/vnd.aristanetworks.swi' =>
        [
            0 => 'swi',
        ],
        'application/vnd.astraea-software.iota' =>
        [
            0 => 'iota',
        ],
        'application/vnd.audiograph' =>
        [
            0 => 'aep',
        ],
        'application/vnd.blueice.multipass' =>
        [
            0 => 'mpm',
        ],
        'application/vnd.bmi' =>
        [
            0 => 'bmi',
        ],
        'application/vnd.businessobjects' =>
        [
            0 => 'rep',
        ],
        'application/vnd.chemdraw+xml' =>
        [
            0 => 'cdxml',
        ],
        'application/vnd.chipnuts.karaoke-mmd' =>
        [
            0 => 'mmd',
        ],
        'application/vnd.cinderella' =>
        [
            0 => 'cdy',
        ],
        'application/vnd.claymore' =>
        [
            0 => 'cla',
        ],
        'application/vnd.cloanto.rp9' =>
        [
            0 => 'rp9',
        ],
        'application/vnd.clonk.c4group' =>
        [
            0 => 'c4g',
            1 => 'c4d',
            2 => 'c4f',
            3 => 'c4p',
            4 => 'c4u',
        ],
        'application/vnd.cluetrust.cartomobile-config' =>
        [
            0 => 'c11amc',
        ],
        'application/vnd.cluetrust.cartomobile-config-pkg' =>
        [
            0 => 'c11amz',
        ],
        'application/vnd.commonspace' =>
        [
            0 => 'csp',
        ],
        'application/vnd.contact.cmsg' =>
        [
            0 => 'cdbcmsg',
        ],
        'application/vnd.cosmocaller' =>
        [
            0 => 'cmc',
        ],
        'application/vnd.crick.clicker' =>
        [
            0 => 'clkx',
        ],
        'application/vnd.crick.clicker.keyboard' =>
        [
            0 => 'clkk',
        ],
        'application/vnd.crick.clicker.palette' =>
        [
            0 => 'clkp',
        ],
        'application/vnd.crick.clicker.template' =>
        [
            0 => 'clkt',
        ],
        'application/vnd.crick.clicker.wordbank' =>
        [
            0 => 'clkw',
        ],
        'application/vnd.criticaltools.wbs+xml' =>
        [
            0 => 'wbs',
        ],
        'application/vnd.ctc-posml' =>
        [
            0 => 'pml',
        ],
        'application/vnd.cups-ppd' =>
        [
            0 => 'ppd',
        ],
        'application/vnd.curl.car' =>
        [
            0 => 'car',
        ],
        'application/vnd.curl.pcurl' =>
        [
            0 => 'pcurl',
        ],
        'application/vnd.dart' =>
        [
            0 => 'dart',
        ],
        'application/vnd.data-vision.rdz' =>
        [
            0 => 'rdz',
        ],
        'application/vnd.dece.data' =>
        [
            0 => 'uvf',
            1 => 'uvvf',
            2 => 'uvd',
            3 => 'uvvd',
        ],
        'application/vnd.dece.ttml+xml' =>
        [
            0 => 'uvt',
            1 => 'uvvt',
        ],
        'application/vnd.dece.unspecified' =>
        [
            0 => 'uvx',
            1 => 'uvvx',
        ],
        'application/vnd.dece.zip' =>
        [
            0 => 'uvz',
            1 => 'uvvz',
        ],
        'application/vnd.denovo.fcselayout-link' =>
        [
            0 => 'fe_launch',
        ],
        'application/vnd.dna' =>
        [
            0 => 'dna',
        ],
        'application/vnd.dolby.mlp' =>
        [
            0 => 'mlp',
        ],
        'application/vnd.dpgraph' =>
        [
            0 => 'dpg',
        ],
        'application/vnd.dreamfactory' =>
        [
            0 => 'dfac',
        ],
        'application/vnd.ds-keypoint' =>
        [
            0 => 'kpxx',
        ],
        'application/vnd.dvb.ait' =>
        [
            0 => 'ait',
        ],
        'application/vnd.dvb.service' =>
        [
            0 => 'svc',
        ],
        'application/vnd.dynageo' =>
        [
            0 => 'geo',
        ],
        'application/vnd.ecowin.chart' =>
        [
            0 => 'mag',
        ],
        'application/vnd.enliven' =>
        [
            0 => 'nml',
        ],
        'application/vnd.epson.esf' =>
        [
            0 => 'esf',
        ],
        'application/vnd.epson.msf' =>
        [
            0 => 'msf',
        ],
        'application/vnd.epson.quickanime' =>
        [
            0 => 'qam',
        ],
        'application/vnd.epson.salt' =>
        [
            0 => 'slt',
        ],
        'application/vnd.epson.ssf' =>
        [
            0 => 'ssf',
        ],
        'application/vnd.eszigno3+xml' =>
        [
            0 => 'es3',
            1 => 'et3',
        ],
        'application/vnd.ezpix-album' =>
        [
            0 => 'ez2',
        ],
        'application/vnd.ezpix-package' =>
        [
            0 => 'ez3',
        ],
        'application/vnd.fdf' =>
        [
            0 => 'fdf',
        ],
        'application/vnd.fdsn.mseed' =>
        [
            0 => 'mseed',
        ],
        'application/vnd.fdsn.seed' =>
        [
            0 => 'seed',
            1 => 'dataless',
        ],
        'application/vnd.flographit' =>
        [
            0 => 'gph',
        ],
        'application/vnd.fluxtime.clip' =>
        [
            0 => 'ftc',
        ],
        'application/vnd.framemaker' =>
        [
            0 => 'fm',
            1 => 'frame',
            2 => 'maker',
            3 => 'book',
        ],
        'application/vnd.frogans.fnc' =>
        [
            0 => 'fnc',
        ],
        'application/vnd.frogans.ltf' =>
        [
            0 => 'ltf',
        ],
        'application/vnd.fsc.weblaunch' =>
        [
            0 => 'fsc',
        ],
        'application/vnd.fujitsu.oasys' =>
        [
            0 => 'oas',
        ],
        'application/vnd.fujitsu.oasys2' =>
        [
            0 => 'oa2',
        ],
        'application/vnd.fujitsu.oasys3' =>
        [
            0 => 'oa3',
        ],
        'application/vnd.fujitsu.oasysgp' =>
        [
            0 => 'fg5',
        ],
        'application/vnd.fujitsu.oasysprs' =>
        [
            0 => 'bh2',
        ],
        'application/vnd.fujixerox.ddd' =>
        [
            0 => 'ddd',
        ],
        'application/vnd.fujixerox.docuworks' =>
        [
            0 => 'xdw',
        ],
        'application/vnd.fujixerox.docuworks.binder' =>
        [
            0 => 'xbd',
        ],
        'application/vnd.fuzzysheet' =>
        [
            0 => 'fzs',
        ],
        'application/vnd.genomatix.tuxedo' =>
        [
            0 => 'txd',
        ],
        'application/vnd.geogebra.file' =>
        [
            0 => 'ggb',
        ],
        'application/vnd.geogebra.tool' =>
        [
            0 => 'ggt',
        ],
        'application/vnd.geometry-explorer' =>
        [
            0 => 'gex',
            1 => 'gre',
        ],
        'application/vnd.geonext' =>
        [
            0 => 'gxt',
        ],
        'application/vnd.geoplan' =>
        [
            0 => 'g2w',
        ],
        'application/vnd.geospace' =>
        [
            0 => 'g3w',
        ],
        'application/vnd.gmx' =>
        [
            0 => 'gmx',
        ],
        'application/vnd.google-earth.kml+xml' =>
        [
            0 => 'kml',
        ],
        'application/vnd.google-earth.kmz' =>
        [
            0 => 'kmz',
        ],
        'application/vnd.grafeq' =>
        [
            0 => 'gqf',
            1 => 'gqs',
        ],
        'application/vnd.groove-account' =>
        [
            0 => 'gac',
        ],
        'application/vnd.groove-help' =>
        [
            0 => 'ghf',
        ],
        'application/vnd.groove-identity-message' =>
        [
            0 => 'gim',
        ],
        'application/vnd.groove-injector' =>
        [
            0 => 'grv',
        ],
        'application/vnd.groove-tool-message' =>
        [
            0 => 'gtm',
        ],
        'application/vnd.groove-tool-template' =>
        [
            0 => 'tpl',
        ],
        'application/vnd.groove-vcard' =>
        [
            0 => 'vcg',
        ],
        'application/vnd.hal+xml' =>
        [
            0 => 'hal',
        ],
        'application/vnd.handheld-entertainment+xml' =>
        [
            0 => 'zmm',
        ],
        'application/vnd.hbci' =>
        [
            0 => 'hbci',
        ],
        'application/vnd.hhe.lesson-player' =>
        [
            0 => 'les',
        ],
        'application/vnd.hp-hpgl' =>
        [
            0 => 'hpgl',
        ],
        'application/vnd.hp-hpid' =>
        [
            0 => 'hpid',
        ],
        'application/vnd.hp-hps' =>
        [
            0 => 'hps',
        ],
        'application/vnd.hp-jlyt' =>
        [
            0 => 'jlt',
        ],
        'application/vnd.hp-pcl' =>
        [
            0 => 'pcl',
        ],
        'application/vnd.hp-pclxl' =>
        [
            0 => 'pclxl',
        ],
        'application/vnd.hydrostatix.sof-data' =>
        [
            0 => 'sfd-hdstx',
        ],
        'application/vnd.ibm.minipay' =>
        [
            0 => 'mpy',
        ],
        'application/vnd.ibm.modcap' =>
        [
            0 => 'afp',
            1 => 'listafp',
            2 => 'list3820',
        ],
        'application/vnd.ibm.rights-management' =>
        [
            0 => 'irm',
        ],
        'application/vnd.ibm.secure-container' =>
        [
            0 => 'sc',
        ],
        'application/vnd.iccprofile' =>
        [
            0 => 'icc',
            1 => 'icm',
        ],
        'application/vnd.igloader' =>
        [
            0 => 'igl',
        ],
        'application/vnd.immervision-ivp' =>
        [
            0 => 'ivp',
        ],
        'application/vnd.immervision-ivu' =>
        [
            0 => 'ivu',
        ],
        'application/vnd.insors.igm' =>
        [
            0 => 'igm',
        ],
        'application/vnd.intercon.formnet' =>
        [
            0 => 'xpw',
            1 => 'xpx',
        ],
        'application/vnd.intergeo' =>
        [
            0 => 'i2g',
        ],
        'application/vnd.intu.qbo' =>
        [
            0 => 'qbo',
        ],
        'application/vnd.intu.qfx' =>
        [
            0 => 'qfx',
        ],
        'application/vnd.ipunplugged.rcprofile' =>
        [
            0 => 'rcprofile',
        ],
        'application/vnd.irepository.package+xml' =>
        [
            0 => 'irp',
        ],
        'application/vnd.is-xpr' =>
        [
            0 => 'xpr',
        ],
        'application/vnd.isac.fcs' =>
        [
            0 => 'fcs',
        ],
        'application/vnd.jam' =>
        [
            0 => 'jam',
        ],
        'application/vnd.jcp.javame.midlet-rms' =>
        [
            0 => 'rms',
        ],
        'application/vnd.jisp' =>
        [
            0 => 'jisp',
        ],
        'application/vnd.joost.joda-archive' =>
        [
            0 => 'joda',
        ],
        'application/vnd.kahootz' =>
        [
            0 => 'ktz',
            1 => 'ktr',
        ],
        'application/vnd.kde.karbon' =>
        [
            0 => 'karbon',
        ],
        'application/vnd.kde.kchart' =>
        [
            0 => 'chrt',
        ],
        'application/vnd.kde.kformula' =>
        [
            0 => 'kfo',
        ],
        'application/vnd.kde.kivio' =>
        [
            0 => 'flw',
        ],
        'application/vnd.kde.kontour' =>
        [
            0 => 'kon',
        ],
        'application/vnd.kde.kpresenter' =>
        [
            0 => 'kpr',
            1 => 'kpt',
        ],
        'application/vnd.kde.kspread' =>
        [
            0 => 'ksp',
        ],
        'application/vnd.kde.kword' =>
        [
            0 => 'kwd',
            1 => 'kwt',
        ],
        'application/vnd.kenameaapp' =>
        [
            0 => 'htke',
        ],
        'application/vnd.kidspiration' =>
        [
            0 => 'kia',
        ],
        'application/vnd.kinar' =>
        [
            0 => 'kne',
            1 => 'knp',
        ],
        'application/vnd.koan' =>
        [
            0 => 'skp',
            1 => 'skd',
            2 => 'skt',
            3 => 'skm',
        ],
        'application/vnd.kodak-descriptor' =>
        [
            0 => 'sse',
        ],
        'application/vnd.las.las+xml' =>
        [
            0 => 'lasxml',
        ],
        'application/vnd.llamagraphics.life-balance.desktop' =>
        [
            0 => 'lbd',
        ],
        'application/vnd.llamagraphics.life-balance.exchange+xml' =>
        [
            0 => 'lbe',
        ],
        'application/vnd.lotus-1-2-3' =>
        [
            0 => '123',
        ],
        'application/vnd.lotus-approach' =>
        [
            0 => 'apr',
        ],
        'application/vnd.lotus-freelance' =>
        [
            0 => 'pre',
        ],
        'application/vnd.lotus-notes' =>
        [
            0 => 'nsf',
        ],
        'application/vnd.lotus-organizer' =>
        [
            0 => 'org',
        ],
        'application/vnd.lotus-screencam' =>
        [
            0 => 'scm',
        ],
        'application/vnd.lotus-wordpro' =>
        [
            0 => 'lwp',
        ],
        'application/vnd.macports.portpkg' =>
        [
            0 => 'portpkg',
        ],
        'application/vnd.mcd' =>
        [
            0 => 'mcd',
        ],
        'application/vnd.medcalcdata' =>
        [
            0 => 'mc1',
        ],
        'application/vnd.mediastation.cdkey' =>
        [
            0 => 'cdkey',
        ],
        'application/vnd.mfer' =>
        [
            0 => 'mwf',
        ],
        'application/vnd.mfmp' =>
        [
            0 => 'mfm',
        ],
        'application/vnd.micrografx.flo' =>
        [
            0 => 'flo',
        ],
        'application/vnd.micrografx.igx' =>
        [
            0 => 'igx',
        ],
        'application/vnd.mif' =>
        [
            0 => 'mif',
        ],
        'application/vnd.mobius.daf' =>
        [
            0 => 'daf',
        ],
        'application/vnd.mobius.dis' =>
        [
            0 => 'dis',
        ],
        'application/vnd.mobius.mbk' =>
        [
            0 => 'mbk',
        ],
        'application/vnd.mobius.mqy' =>
        [
            0 => 'mqy',
        ],
        'application/vnd.mobius.msl' =>
        [
            0 => 'msl',
        ],
        'application/vnd.mobius.plc' =>
        [
            0 => 'plc',
        ],
        'application/vnd.mobius.txf' =>
        [
            0 => 'txf',
        ],
        'application/vnd.mophun.application' =>
        [
            0 => 'mpn',
        ],
        'application/vnd.mophun.certificate' =>
        [
            0 => 'mpc',
        ],
        'application/vnd.mozilla.xul+xml' =>
        [
            0 => 'xul',
        ],
        'application/vnd.ms-artgalry' =>
        [
            0 => 'cil',
        ],
        'application/vnd.ms-cab-compressed' =>
        [
            0 => 'cab',
        ],
        'application/vnd.ms-excel' =>
        [
            0 => 'xls',
            1 => 'xlm',
            2 => 'xla',
            3 => 'xlc',
            4 => 'xlt',
            5 => 'xlw',
        ],
        'application/vnd.ms-excel.addin.macroenabled.12' =>
        [
            0 => 'xlam',
        ],
        'application/vnd.ms-excel.sheet.binary.macroenabled.12' =>
        [
            0 => 'xlsb',
        ],
        'application/vnd.ms-excel.sheet.macroenabled.12' =>
        [
            0 => 'xlsm',
        ],
        'application/vnd.ms-excel.template.macroenabled.12' =>
        [
            0 => 'xltm',
        ],
        'application/vnd.ms-fontobject' =>
        [
            0 => 'eot',
        ],
        'application/vnd.ms-htmlhelp' =>
        [
            0 => 'chm',
        ],
        'application/vnd.ms-ims' =>
        [
            0 => 'ims',
        ],
        'application/vnd.ms-lrm' =>
        [
            0 => 'lrm',
        ],
        'application/vnd.ms-officetheme' =>
        [
            0 => 'thmx',
        ],
        'application/vnd.ms-pki.seccat' =>
        [
            0 => 'cat',
        ],
        'application/vnd.ms-pki.stl' =>
        [
            0 => 'stl',
        ],
        'application/vnd.ms-powerpoint' =>
        [
            0 => 'ppt',
            1 => 'pps',
            2 => 'pot',
        ],
        'application/vnd.ms-powerpoint.addin.macroenabled.12' =>
        [
            0 => 'ppam',
        ],
        'application/vnd.ms-powerpoint.presentation.macroenabled.12' =>
        [
            0 => 'pptm',
        ],
        'application/vnd.ms-powerpoint.slide.macroenabled.12' =>
        [
            0 => 'sldm',
        ],
        'application/vnd.ms-powerpoint.slideshow.macroenabled.12' =>
        [
            0 => 'ppsm',
        ],
        'application/vnd.ms-powerpoint.template.macroenabled.12' =>
        [
            0 => 'potm',
        ],
        'application/vnd.ms-project' =>
        [
            0 => 'mpp',
            1 => 'mpt',
        ],
        'application/vnd.ms-word.document.macroenabled.12' =>
        [
            0 => 'docm',
        ],
        'application/vnd.ms-word.template.macroenabled.12' =>
        [
            0 => 'dotm',
        ],
        'application/vnd.ms-works' =>
        [
            0 => 'wps',
            1 => 'wks',
            2 => 'wcm',
            3 => 'wdb',
        ],
        'application/vnd.ms-wpl' =>
        [
            0 => 'wpl',
        ],
        'application/vnd.ms-xpsdocument' =>
        [
            0 => 'xps',
        ],
        'application/vnd.mseq' =>
        [
            0 => 'mseq',
        ],
        'application/vnd.musician' =>
        [
            0 => 'mus',
        ],
        'application/vnd.muvee.style' =>
        [
            0 => 'msty',
        ],
        'application/vnd.mynfc' =>
        [
            0 => 'taglet',
        ],
        'application/vnd.neurolanguage.nlu' =>
        [
            0 => 'nlu',
        ],
        'application/vnd.nitf' =>
        [
            0 => 'ntf',
            1 => 'nitf',
        ],
        'application/vnd.noblenet-directory' =>
        [
            0 => 'nnd',
        ],
        'application/vnd.noblenet-sealer' =>
        [
            0 => 'nns',
        ],
        'application/vnd.noblenet-web' =>
        [
            0 => 'nnw',
        ],
        'application/vnd.nokia.n-gage.data' =>
        [
            0 => 'ngdat',
        ],
        'application/vnd.nokia.n-gage.symbian.install' =>
        [
            0 => 'n-gage',
        ],
        'application/vnd.nokia.radio-preset' =>
        [
            0 => 'rpst',
        ],
        'application/vnd.nokia.radio-presets' =>
        [
            0 => 'rpss',
        ],
        'application/vnd.novadigm.edm' =>
        [
            0 => 'edm',
        ],
        'application/vnd.novadigm.edx' =>
        [
            0 => 'edx',
        ],
        'application/vnd.novadigm.ext' =>
        [
            0 => 'ext',
        ],
        'application/vnd.oasis.opendocument.chart' =>
        [
            0 => 'odc',
        ],
        'application/vnd.oasis.opendocument.chart-template' =>
        [
            0 => 'otc',
        ],
        'application/vnd.oasis.opendocument.database' =>
        [
            0 => 'odb',
        ],
        'application/vnd.oasis.opendocument.formula' =>
        [
            0 => 'odf',
        ],
        'application/vnd.oasis.opendocument.formula-template' =>
        [
            0 => 'odft',
        ],
        'application/vnd.oasis.opendocument.graphics' =>
        [
            0 => 'odg',
        ],
        'application/vnd.oasis.opendocument.graphics-template' =>
        [
            0 => 'otg',
        ],
        'application/vnd.oasis.opendocument.image' =>
        [
            0 => 'odi',
        ],
        'application/vnd.oasis.opendocument.image-template' =>
        [
            0 => 'oti',
        ],
        'application/vnd.oasis.opendocument.presentation' =>
        [
            0 => 'odp',
        ],
        'application/vnd.oasis.opendocument.presentation-template' =>
        [
            0 => 'otp',
        ],
        'application/vnd.oasis.opendocument.spreadsheet' =>
        [
            0 => 'ods',
        ],
        'application/vnd.oasis.opendocument.spreadsheet-template' =>
        [
            0 => 'ots',
        ],
        'application/vnd.oasis.opendocument.text' =>
        [
            0 => 'odt',
        ],
        'application/vnd.oasis.opendocument.text-master' =>
        [
            0 => 'odm',
        ],
        'application/vnd.oasis.opendocument.text-template' =>
        [
            0 => 'ott',
        ],
        'application/vnd.oasis.opendocument.text-web' =>
        [
            0 => 'oth',
        ],
        'application/vnd.olpc-sugar' =>
        [
            0 => 'xo',
        ],
        'application/vnd.oma.dd2+xml' =>
        [
            0 => 'dd2',
        ],
        'application/vnd.openofficeorg.extension' =>
        [
            0 => 'oxt',
        ],
        'application/vnd.openxmlformats-officedocument.presentationml.presentation' =>
        [
            0 => 'pptx',
        ],
        'application/vnd.openxmlformats-officedocument.presentationml.slide' =>
        [
            0 => 'sldx',
        ],
        'application/vnd.openxmlformats-officedocument.presentationml.slideshow' =>
        [
            0 => 'ppsx',
        ],
        'application/vnd.openxmlformats-officedocument.presentationml.template' =>
        [
            0 => 'potx',
        ],
        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' =>
        [
            0 => 'xlsx',
        ],
        'application/vnd.openxmlformats-officedocument.spreadsheetml.template' =>
        [
            0 => 'xltx',
        ],
        'application/vnd.openxmlformats-officedocument.wordprocessingml.document' =>
        [
            0 => 'docx',
        ],
        'application/vnd.openxmlformats-officedocument.wordprocessingml.template' =>
        [
            0 => 'dotx',
        ],
        'application/vnd.osgeo.mapguide.package' =>
        [
            0 => 'mgp',
        ],
        'application/vnd.osgi.dp' =>
        [
            0 => 'dp',
        ],
        'application/vnd.osgi.subsystem' =>
        [
            0 => 'esa',
        ],
        'application/vnd.palm' =>
        [
            0 => 'pdb',
            1 => 'pqa',
            2 => 'oprc',
        ],
        'application/vnd.pawaafile' =>
        [
            0 => 'paw',
        ],
        'application/vnd.pg.format' =>
        [
            0 => 'str',
        ],
        'application/vnd.pg.osasli' =>
        [
            0 => 'ei6',
        ],
        'application/vnd.picsel' =>
        [
            0 => 'efif',
        ],
        'application/vnd.pmi.widget' =>
        [
            0 => 'wg',
        ],
        'application/vnd.pocketlearn' =>
        [
            0 => 'plf',
        ],
        'application/vnd.powerbuilder6' =>
        [
            0 => 'pbd',
        ],
        'application/vnd.previewsystems.box' =>
        [
            0 => 'box',
        ],
        'application/vnd.proteus.magazine' =>
        [
            0 => 'mgz',
        ],
        'application/vnd.publishare-delta-tree' =>
        [
            0 => 'qps',
        ],
        'application/vnd.pvi.ptid1' =>
        [
            0 => 'ptid',
        ],
        'application/vnd.quark.quarkxpress' =>
        [
            0 => 'qxd',
            1 => 'qxt',
            2 => 'qwd',
            3 => 'qwt',
            4 => 'qxl',
            5 => 'qxb',
        ],
        'application/vnd.realvnc.bed' =>
        [
            0 => 'bed',
        ],
        'application/vnd.recordare.musicxml' =>
        [
            0 => 'mxl',
        ],
        'application/vnd.recordare.musicxml+xml' =>
        [
            0 => 'musicxml',
        ],
        'application/vnd.rig.cryptonote' =>
        [
            0 => 'cryptonote',
        ],
        'application/vnd.rim.cod' =>
        [
            0 => 'cod',
        ],
        'application/vnd.rn-realmedia' =>
        [
            0 => 'rm',
        ],
        'application/vnd.rn-realmedia-vbr' =>
        [
            0 => 'rmvb',
        ],
        'application/vnd.route66.link66+xml' =>
        [
            0 => 'link66',
        ],
        'application/vnd.sailingtracker.track' =>
        [
            0 => 'st',
        ],
        'application/vnd.seemail' =>
        [
            0 => 'see',
        ],
        'application/vnd.sema' =>
        [
            0 => 'sema',
        ],
        'application/vnd.semd' =>
        [
            0 => 'semd',
        ],
        'application/vnd.semf' =>
        [
            0 => 'semf',
        ],
        'application/vnd.shana.informed.formdata' =>
        [
            0 => 'ifm',
        ],
        'application/vnd.shana.informed.formtemplate' =>
        [
            0 => 'itp',
        ],
        'application/vnd.shana.informed.interchange' =>
        [
            0 => 'iif',
        ],
        'application/vnd.shana.informed.package' =>
        [
            0 => 'ipk',
        ],
        'application/vnd.simtech-mindmapper' =>
        [
            0 => 'twd',
            1 => 'twds',
        ],
        'application/vnd.smaf' =>
        [
            0 => 'mmf',
        ],
        'application/vnd.smart.teacher' =>
        [
            0 => 'teacher',
        ],
        'application/vnd.solent.sdkm+xml' =>
        [
            0 => 'sdkm',
            1 => 'sdkd',
        ],
        'application/vnd.spotfire.dxp' =>
        [
            0 => 'dxp',
        ],
        'application/vnd.spotfire.sfs' =>
        [
            0 => 'sfs',
        ],
        'application/vnd.stardivision.calc' =>
        [
            0 => 'sdc',
        ],
        'application/vnd.stardivision.draw' =>
        [
            0 => 'sda',
        ],
        'application/vnd.stardivision.impress' =>
        [
            0 => 'sdd',
        ],
        'application/vnd.stardivision.math' =>
        [
            0 => 'smf',
        ],
        'application/vnd.stardivision.writer' =>
        [
            0 => 'sdw',
            1 => 'vor',
        ],
        'application/vnd.stardivision.writer-global' =>
        [
            0 => 'sgl',
        ],
        'application/vnd.stepmania.package' =>
        [
            0 => 'smzip',
        ],
        'application/vnd.stepmania.stepchart' =>
        [
            0 => 'sm',
        ],
        'application/vnd.sun.xml.calc' =>
        [
            0 => 'sxc',
        ],
        'application/vnd.sun.xml.calc.template' =>
        [
            0 => 'stc',
        ],
        'application/vnd.sun.xml.draw' =>
        [
            0 => 'sxd',
        ],
        'application/vnd.sun.xml.draw.template' =>
        [
            0 => 'std',
        ],
        'application/vnd.sun.xml.impress' =>
        [
            0 => 'sxi',
        ],
        'application/vnd.sun.xml.impress.template' =>
        [
            0 => 'sti',
        ],
        'application/vnd.sun.xml.math' =>
        [
            0 => 'sxm',
        ],
        'application/vnd.sun.xml.writer' =>
        [
            0 => 'sxw',
        ],
        'application/vnd.sun.xml.writer.global' =>
        [
            0 => 'sxg',
        ],
        'application/vnd.sun.xml.writer.template' =>
        [
            0 => 'stw',
        ],
        'application/vnd.sus-calendar' =>
        [
            0 => 'sus',
            1 => 'susp',
        ],
        'application/vnd.svd' =>
        [
            0 => 'svd',
        ],
        'application/vnd.symbian.install' =>
        [
            0 => 'sis',
            1 => 'sisx',
        ],
        'application/vnd.syncml+xml' =>
        [
            0 => 'xsm',
        ],
        'application/vnd.syncml.dm+wbxml' =>
        [
            0 => 'bdm',
        ],
        'application/vnd.syncml.dm+xml' =>
        [
            0 => 'xdm',
        ],
        'application/vnd.tao.intent-module-archive' =>
        [
            0 => 'tao',
        ],
        'application/vnd.tcpdump.pcap' =>
        [
            0 => 'pcap',
            1 => 'cap',
            2 => 'dmp',
        ],
        'application/vnd.tmobile-livetv' =>
        [
            0 => 'tmo',
        ],
        'application/vnd.trid.tpt' =>
        [
            0 => 'tpt',
        ],
        'application/vnd.triscape.mxs' =>
        [
            0 => 'mxs',
        ],
        'application/vnd.trueapp' =>
        [
            0 => 'tra',
        ],
        'application/vnd.ufdl' =>
        [
            0 => 'ufd',
            1 => 'ufdl',
        ],
        'application/vnd.uiq.theme' =>
        [
            0 => 'utz',
        ],
        'application/vnd.umajin' =>
        [
            0 => 'umj',
        ],
        'application/vnd.unity' =>
        [
            0 => 'unityweb',
        ],
        'application/vnd.uoml+xml' =>
        [
            0 => 'uoml',
        ],
        'application/vnd.vcx' =>
        [
            0 => 'vcx',
        ],
        'application/vnd.visio' =>
        [
            0 => 'vsd',
            1 => 'vst',
            2 => 'vss',
            3 => 'vsw',
        ],
        'application/vnd.visionary' =>
        [
            0 => 'vis',
        ],
        'application/vnd.vsf' =>
        [
            0 => 'vsf',
        ],
        'application/vnd.wap.wbxml' =>
        [
            0 => 'wbxml',
        ],
        'application/vnd.wap.wmlc' =>
        [
            0 => 'wmlc',
        ],
        'application/vnd.wap.wmlscriptc' =>
        [
            0 => 'wmlsc',
        ],
        'application/vnd.webturbo' =>
        [
            0 => 'wtb',
        ],
        'application/vnd.wolfram.player' =>
        [
            0 => 'nbp',
        ],
        'application/vnd.wordperfect' =>
        [
            0 => 'wpd',
        ],
        'application/vnd.wqd' =>
        [
            0 => 'wqd',
        ],
        'application/vnd.wt.stf' =>
        [
            0 => 'stf',
        ],
        'application/vnd.xara' =>
        [
            0 => 'xar',
        ],
        'application/vnd.xfdl' =>
        [
            0 => 'xfdl',
        ],
        'application/vnd.yamaha.hv-dic' =>
        [
            0 => 'hvd',
        ],
        'application/vnd.yamaha.hv-script' =>
        [
            0 => 'hvs',
        ],
        'application/vnd.yamaha.hv-voice' =>
        [
            0 => 'hvp',
        ],
        'application/vnd.yamaha.openscoreformat' =>
        [
            0 => 'osf',
        ],
        'application/vnd.yamaha.openscoreformat.osfpvg+xml' =>
        [
            0 => 'osfpvg',
        ],
        'application/vnd.yamaha.smaf-audio' =>
        [
            0 => 'saf',
        ],
        'application/vnd.yamaha.smaf-phrase' =>
        [
            0 => 'spf',
        ],
        'application/vnd.yellowriver-custom-menu' =>
        [
            0 => 'cmp',
        ],
        'application/vnd.zul' =>
        [
            0 => 'zir',
            1 => 'zirz',
        ],
        'application/vnd.zzazz.deck+xml' =>
        [
            0 => 'zaz',
        ],
        'application/voicexml+xml' =>
        [
            0 => 'vxml',
        ],
        'application/widget' =>
        [
            0 => 'wgt',
        ],
        'application/winhlp' =>
        [
            0 => 'hlp',
        ],
        'application/wsdl+xml' =>
        [
            0 => 'wsdl',
        ],
        'application/wspolicy+xml' =>
        [
            0 => 'wspolicy',
        ],
        'application/x-7z-compressed' =>
        [
            0 => '7z',
        ],
        'application/x-abiword' =>
        [
            0 => 'abw',
        ],
        'application/x-ace-compressed' =>
        [
            0 => 'ace',
        ],
        'application/x-apple-diskimage' =>
        [
            0 => 'dmg',
        ],
        'application/x-authorware-bin' =>
        [
            0 => 'aab',
            1 => 'x32',
            2 => 'u32',
            3 => 'vox',
        ],
        'application/x-authorware-map' =>
        [
            0 => 'aam',
        ],
        'application/x-authorware-seg' =>
        [
            0 => 'aas',
        ],
        'application/x-bcpio' =>
        [
            0 => 'bcpio',
        ],
        'application/x-bittorrent' =>
        [
            0 => 'torrent',
        ],
        'application/x-blorb' =>
        [
            0 => 'blb',
            1 => 'blorb',
        ],
        'application/x-bzip' =>
        [
            0 => 'bz',
        ],
        'application/x-bzip2' =>
        [
            0 => 'bz2',
            1 => 'boz',
        ],
        'application/x-cbr' =>
        [
            0 => 'cbr',
            1 => 'cba',
            2 => 'cbt',
            3 => 'cbz',
            4 => 'cb7',
        ],
        'application/x-cdlink' =>
        [
            0 => 'vcd',
        ],
        'application/x-cfs-compressed' =>
        [
            0 => 'cfs',
        ],
        'application/x-chat' =>
        [
            0 => 'chat',
        ],
        'application/x-chess-pgn' =>
        [
            0 => 'pgn',
        ],
        'application/x-conference' =>
        [
            0 => 'nsc',
        ],
        'application/x-cpio' =>
        [
            0 => 'cpio',
        ],
        'application/x-csh' =>
        [
            0 => 'csh',
        ],
        'application/x-debian-package' =>
        [
            0 => 'deb',
            1 => 'udeb',
        ],
        'application/x-dgc-compressed' =>
        [
            0 => 'dgc',
        ],
        'application/x-director' =>
        [
            0 => 'dir',
            1 => 'dcr',
            2 => 'dxr',
            3 => 'cst',
            4 => 'cct',
            5 => 'cxt',
            6 => 'w3d',
            7 => 'fgd',
            8 => 'swa',
        ],
        'application/x-doom' =>
        [
            0 => 'wad',
        ],
        'application/x-dtbncx+xml' =>
        [
            0 => 'ncx',
        ],
        'application/x-dtbook+xml' =>
        [
            0 => 'dtb',
        ],
        'application/x-dtbresource+xml' =>
        [
            0 => 'res',
        ],
        'application/x-dvi' =>
        [
            0 => 'dvi',
        ],
        'application/x-envoy' =>
        [
            0 => 'evy',
        ],
        'application/x-eva' =>
        [
            0 => 'eva',
        ],
        'application/x-font-bdf' =>
        [
            0 => 'bdf',
        ],
        'application/x-font-ghostscript' =>
        [
            0 => 'gsf',
        ],
        'application/x-font-linux-psf' =>
        [
            0 => 'psf',
        ],
        'application/x-font-pcf' =>
        [
            0 => 'pcf',
        ],
        'application/x-font-snf' =>
        [
            0 => 'snf',
        ],
        'application/x-font-type1' =>
        [
            0 => 'pfa',
            1 => 'pfb',
            2 => 'pfm',
            3 => 'afm',
        ],
        'application/x-freearc' =>
        [
            0 => 'arc',
        ],
        'application/x-futuresplash' =>
        [
            0 => 'spl',
        ],
        'application/x-gca-compressed' =>
        [
            0 => 'gca',
        ],
        'application/x-glulx' =>
        [
            0 => 'ulx',
        ],
        'application/x-gnumeric' =>
        [
            0 => 'gnumeric',
        ],
        'application/x-gramps-xml' =>
        [
            0 => 'gramps',
        ],
        'application/x-gtar' =>
        [
            0 => 'gtar',
        ],
        'application/x-hdf' =>
        [
            0 => 'hdf',
        ],
        'application/x-install-instructions' =>
        [
            0 => 'install',
        ],
        'application/x-iso9660-image' =>
        [
            0 => 'iso',
        ],
        'application/x-java-jnlp-file' =>
        [
            0 => 'jnlp',
        ],
        'application/x-latex' =>
        [
            0 => 'latex',
        ],
        'application/x-lzh-compressed' =>
        [
            0 => 'lzh',
            1 => 'lha',
        ],
        'application/x-mie' =>
        [
            0 => 'mie',
        ],
        'application/x-mobipocket-ebook' =>
        [
            0 => 'prc',
            1 => 'mobi',
        ],
        'application/x-ms-application' =>
        [
            0 => 'application',
        ],
        'application/x-ms-shortcut' =>
        [
            0 => 'lnk',
        ],
        'application/x-ms-wmd' =>
        [
            0 => 'wmd',
        ],
        'application/x-ms-wmz' =>
        [
            0 => 'wmz',
        ],
        'application/x-ms-xbap' =>
        [
            0 => 'xbap',
        ],
        'application/x-msaccess' =>
        [
            0 => 'mdb',
        ],
        'application/x-msbinder' =>
        [
            0 => 'obd',
        ],
        'application/x-mscardfile' =>
        [
            0 => 'crd',
        ],
        'application/x-msclip' =>
        [
            0 => 'clp',
        ],
        'application/x-msdownload' =>
        [
            0 => 'exe',
            1 => 'dll',
            2 => 'com',
            3 => 'bat',
            4 => 'msi',
        ],
        'application/x-msmediaview' =>
        [
            0 => 'mvb',
            1 => 'm13',
            2 => 'm14',
        ],
        'application/x-msmetafile' =>
        [
            0 => 'wmf',
            1 => 'wmz',
            2 => 'emf',
            3 => 'emz',
        ],
        'application/x-msmoney' =>
        [
            0 => 'mny',
        ],
        'application/x-mspublisher' =>
        [
            0 => 'pub',
        ],
        'application/x-msschedule' =>
        [
            0 => 'scd',
        ],
        'application/x-msterminal' =>
        [
            0 => 'trm',
        ],
        'application/x-mswrite' =>
        [
            0 => 'wri',
        ],
        'application/x-netcdf' =>
        [
            0 => 'nc',
            1 => 'cdf',
        ],
        'application/x-nzb' =>
        [
            0 => 'nzb',
        ],
        'application/x-pkcs12' =>
        [
            0 => 'p12',
            1 => 'pfx',
        ],
        'application/x-pkcs7-certificates' =>
        [
            0 => 'p7b',
            1 => 'spc',
        ],
        'application/x-pkcs7-certreqresp' =>
        [
            0 => 'p7r',
        ],
        'application/x-rar-compressed' =>
        [
            0 => 'rar',
        ],
        'application/x-research-info-systems' =>
        [
            0 => 'ris',
        ],
        'application/x-sh' =>
        [
            0 => 'sh',
        ],
        'application/x-shar' =>
        [
            0 => 'shar',
        ],
        'application/x-shockwave-flash' =>
        [
            0 => 'swf',
        ],
        'application/x-silverlight-app' =>
        [
            0 => 'xap',
        ],
        'application/x-sql' =>
        [
            0 => 'sql',
        ],
        'application/x-stuffit' =>
        [
            0 => 'sit',
        ],
        'application/x-stuffitx' =>
        [
            0 => 'sitx',
        ],
        'application/x-subrip' =>
        [
            0 => 'srt',
        ],
        'application/x-sv4cpio' =>
        [
            0 => 'sv4cpio',
        ],
        'application/x-sv4crc' =>
        [
            0 => 'sv4crc',
        ],
        'application/x-t3vm-image' =>
        [
            0 => 't3',
        ],
        'application/x-tads' =>
        [
            0 => 'gam',
        ],
        'application/x-tar' =>
        [
            0 => 'tar',
        ],
        'application/x-tcl' =>
        [
            0 => 'tcl',
        ],
        'application/x-tex' =>
        [
            0 => 'tex',
        ],
        'application/x-tex-tfm' =>
        [
            0 => 'tfm',
        ],
        'application/x-texinfo' =>
        [
            0 => 'texinfo',
            1 => 'texi',
        ],
        'application/x-tgif' =>
        [
            0 => 'obj',
        ],
        'application/x-ustar' =>
        [
            0 => 'ustar',
        ],
        'application/x-wais-source' =>
        [
            0 => 'src',
        ],
        'application/x-x509-ca-cert' =>
        [
            0 => 'der',
            1 => 'crt',
        ],
        'application/x-xfig' =>
        [
            0 => 'fig',
        ],
        'application/x-xliff+xml' =>
        [
            0 => 'xlf',
        ],
        'application/x-xpinstall' =>
        [
            0 => 'xpi',
        ],
        'application/x-xz' =>
        [
            0 => 'xz',
        ],
        'application/x-zmachine' =>
        [
            0 => 'z1',
            1 => 'z2',
            2 => 'z3',
            3 => 'z4',
            4 => 'z5',
            5 => 'z6',
            6 => 'z7',
            7 => 'z8',
        ],
        'application/xaml+xml' =>
        [
            0 => 'xaml',
        ],
        'application/xcap-diff+xml' =>
        [
            0 => 'xdf',
        ],
        'application/xenc+xml' =>
        [
            0 => 'xenc',
        ],
        'application/xhtml+xml' =>
        [
            0 => 'xhtml',
            1 => 'xht',
        ],
        'application/xml' =>
        [
            0 => 'xml',
            1 => 'xsl',
        ],
        'application/xml-dtd' =>
        [
            0 => 'dtd',
        ],
        'application/xop+xml' =>
        [
            0 => 'xop',
        ],
        'application/xproc+xml' =>
        [
            0 => 'xpl',
        ],
        'application/xslt+xml' =>
        [
            0 => 'xslt',
        ],
        'application/xspf+xml' =>
        [
            0 => 'xspf',
        ],
        'application/xv+xml' =>
        [
            0 => 'mxml',
            1 => 'xhvml',
            2 => 'xvml',
            3 => 'xvm',
        ],
        'application/yang' =>
        [
            0 => 'yang',
        ],
        'application/yin+xml' =>
        [
            0 => 'yin',
        ],
        'application/zip' =>
        [
            0 => 'zip',
        ],
        'audio/adpcm' =>
        [
            0 => 'adp',
        ],
        'audio/basic' =>
        [
            0 => 'au',
            1 => 'snd',
        ],
        'audio/midi' =>
        [
            0 => 'mid',
            1 => 'midi',
            2 => 'kar',
            3 => 'rmi',
        ],
        'audio/mp4' =>
        [
            0 => 'm4a',
            1 => 'mp4a',
        ],
        'audio/ogg' =>
        [
            0 => 'oga',
            1 => 'ogg',
            2 => 'spx',
        ],
        'audio/s3m' =>
        [
            0 => 's3m',
        ],
        'audio/silk' =>
        [
            0 => 'sil',
        ],
        'audio/vnd.dece.audio' =>
        [
            0 => 'uva',
            1 => 'uvva',
        ],
        'audio/vnd.digital-winds' =>
        [
            0 => 'eol',
        ],
        'audio/vnd.dra' =>
        [
            0 => 'dra',
        ],
        'audio/vnd.dts' =>
        [
            0 => 'dts',
        ],
        'audio/vnd.dts.hd' =>
        [
            0 => 'dtshd',
        ],
        'audio/vnd.lucent.voice' =>
        [
            0 => 'lvp',
        ],
        'audio/vnd.ms-playready.media.pya' =>
        [
            0 => 'pya',
        ],
        'audio/vnd.nuera.ecelp4800' =>
        [
            0 => 'ecelp4800',
        ],
        'audio/vnd.nuera.ecelp7470' =>
        [
            0 => 'ecelp7470',
        ],
        'audio/vnd.nuera.ecelp9600' =>
        [
            0 => 'ecelp9600',
        ],
        'audio/vnd.rip' =>
        [
            0 => 'rip',
        ],
        'audio/webm' =>
        [
            0 => 'weba',
        ],
        'audio/x-aac' =>
        [
            0 => 'aac',
        ],
        'audio/x-aiff' =>
        [
            0 => 'aif',
            1 => 'aiff',
            2 => 'aifc',
        ],
        'audio/x-caf' =>
        [
            0 => 'caf',
        ],
        'audio/x-flac' =>
        [
            0 => 'flac',
        ],
        'audio/x-matroska' =>
        [
            0 => 'mka',
        ],
        'audio/x-mpegurl' =>
        [
            0 => 'm3u',
        ],
        'audio/x-ms-wax' =>
        [
            0 => 'wax',
        ],
        'audio/x-ms-wma' =>
        [
            0 => 'wma',
        ],
        'audio/x-pn-realaudio' =>
        [
            0 => 'ram',
            1 => 'ra',
        ],
        'audio/x-pn-realaudio-plugin' =>
        [
            0 => 'rmp',
        ],
        'audio/x-wav' =>
        [
            0 => 'wav',
        ],
        'audio/xm' =>
        [
            0 => 'xm',
        ],
        'chemical/x-cdx' =>
        [
            0 => 'cdx',
        ],
        'chemical/x-cif' =>
        [
            0 => 'cif',
        ],
        'chemical/x-cmdf' =>
        [
            0 => 'cmdf',
        ],
        'chemical/x-cml' =>
        [
            0 => 'cml',
        ],
        'chemical/x-csml' =>
        [
            0 => 'csml',
        ],
        'chemical/x-xyz' =>
        [
            0 => 'xyz',
        ],
        'font/collection' =>
        [
            0 => 'ttc',
        ],
        'font/otf' =>
        [
            0 => 'otf',
        ],
        'font/ttf' =>
        [
            0 => 'ttf',
        ],
        'font/woff' =>
        [
            0 => 'woff',
        ],
        'font/woff2' =>
        [
            0 => 'woff2',
        ],
        'image/bmp' =>
        [
            0 => 'bmp',
        ],
        'image/cgm' =>
        [
            0 => 'cgm',
        ],
        'image/g3fax' =>
        [
            0 => 'g3',
        ],
        'image/gif' =>
        [
            0 => 'gif',
        ],
        'image/ief' =>
        [
            0 => 'ief',
        ],
        'image/ktx' =>
        [
            0 => 'ktx',
        ],
        'image/png' =>
        [
            0 => 'png',
        ],
        'image/prs.btif' =>
        [
            0 => 'btif',
        ],
        'image/sgi' =>
        [
            0 => 'sgi',
        ],
        'image/svg+xml' =>
        [
            0 => 'svg',
            1 => 'svgz',
        ],
        'image/tiff' =>
        [
            0 => 'tiff',
            1 => 'tif',
        ],
        'image/vnd.adobe.photoshop' =>
        [
            0 => 'psd',
        ],
        'image/vnd.dece.graphic' =>
        [
            0 => 'uvi',
            1 => 'uvvi',
            2 => 'uvg',
            3 => 'uvvg',
        ],
        'image/vnd.djvu' =>
        [
            0 => 'djvu',
            1 => 'djv',
        ],
        'image/vnd.dvb.subtitle' =>
        [
            0 => 'sub',
        ],
        'image/vnd.dwg' =>
        [
            0 => 'dwg',
        ],
        'image/vnd.dxf' =>
        [
            0 => 'dxf',
        ],
        'image/vnd.fastbidsheet' =>
        [
            0 => 'fbs',
        ],
        'image/vnd.fpx' =>
        [
            0 => 'fpx',
        ],
        'image/vnd.fst' =>
        [
            0 => 'fst',
        ],
        'image/vnd.fujixerox.edmics-mmr' =>
        [
            0 => 'mmr',
        ],
        'image/vnd.fujixerox.edmics-rlc' =>
        [
            0 => 'rlc',
        ],
        'image/vnd.ms-modi' =>
        [
            0 => 'mdi',
        ],
        'image/vnd.ms-photo' =>
        [
            0 => 'wdp',
        ],
        'image/vnd.net-fpx' =>
        [
            0 => 'npx',
        ],
        'image/vnd.wap.wbmp' =>
        [
            0 => 'wbmp',
        ],
        'image/vnd.xiff' =>
        [
            0 => 'xif',
        ],
        'image/webp' =>
        [
            0 => 'webp',
        ],
        'image/x-3ds' =>
        [
            0 => '3ds',
        ],
        'image/x-cmu-raster' =>
        [
            0 => 'ras',
        ],
        'image/x-cmx' =>
        [
            0 => 'cmx',
        ],
        'image/x-freehand' =>
        [
            0 => 'fh',
            1 => 'fhc',
            2 => 'fh4',
            3 => 'fh5',
            4 => 'fh7',
        ],
        'image/x-icon' =>
        [
            0 => 'ico',
        ],
        'image/x-mrsid-image' =>
        [
            0 => 'sid',
        ],
        'image/x-pcx' =>
        [
            0 => 'pcx',
        ],
        'image/x-pict' =>
        [
            0 => 'pic',
            1 => 'pct',
        ],
        'image/x-portable-anymap' =>
        [
            0 => 'pnm',
        ],
        'image/x-portable-bitmap' =>
        [
            0 => 'pbm',
        ],
        'image/x-portable-graymap' =>
        [
            0 => 'pgm',
        ],
        'image/x-portable-pixmap' =>
        [
            0 => 'ppm',
        ],
        'image/x-rgb' =>
        [
            0 => 'rgb',
        ],
        'image/x-tga' =>
        [
            0 => 'tga',
        ],
        'image/x-xbitmap' =>
        [
            0 => 'xbm',
        ],
        'image/x-xpixmap' =>
        [
            0 => 'xpm',
        ],
        'image/x-xwindowdump' =>
        [
            0 => 'xwd',
        ],
        'message/rfc822' =>
        [
            0 => 'eml',
            1 => 'mime',
        ],
        'model/iges' =>
        [
            0 => 'igs',
            1 => 'iges',
        ],
        'model/mesh' =>
        [
            0 => 'msh',
            1 => 'mesh',
            2 => 'silo',
        ],
        'model/vnd.collada+xml' =>
        [
            0 => 'dae',
        ],
        'model/vnd.dwf' =>
        [
            0 => 'dwf',
        ],
        'model/vnd.gdl' =>
        [
            0 => 'gdl',
        ],
        'model/vnd.gtw' =>
        [
            0 => 'gtw',
        ],
        'model/vnd.mts' =>
        [
            0 => 'mts',
        ],
        'model/vnd.vtu' =>
        [
            0 => 'vtu',
        ],
        'model/vrml' =>
        [
            0 => 'wrl',
            1 => 'vrml',
        ],
        'model/x3d+binary' =>
        [
            0 => 'x3db',
            1 => 'x3dbz',
        ],
        'model/x3d+vrml' =>
        [
            0 => 'x3dv',
            1 => 'x3dvz',
        ],
        'model/x3d+xml' =>
        [
            0 => 'x3d',
            1 => 'x3dz',
        ],
        'text/cache-manifest' =>
        [
            0 => 'appcache',
        ],
        'text/calendar' =>
        [
            0 => 'ics',
            1 => 'ifb',
        ],
        'text/css' =>
        [
            0 => 'css',
        ],
        'text/csv' =>
        [
            0 => 'csv',
        ],
        'text/html' =>
        [
            0 => 'html',
            1 => 'htm',
        ],
        'text/n3' =>
        [
            0 => 'n3',
        ],
        'text/plain' =>
        [
            0 => 'txt',
            1 => 'text',
            2 => 'conf',
            3 => 'def',
            4 => 'list',
            5 => 'log',
            6 => 'in',
            7 => 'md',
        ],
        'text/markdown' => 
        [
            0 => 'md',
        ],
        'text/prs.lines.tag' =>
        [
            0 => 'dsc',
        ],
        'text/richtext' =>
        [
            0 => 'rtx',
        ],
        'text/sgml' =>
        [
            0 => 'sgml',
            1 => 'sgm',
        ],
        'text/tab-separated-values' =>
        [
            0 => 'tsv',
        ],
        'text/troff' =>
        [
            0 => 't',
            1 => 'tr',
            2 => 'roff',
            3 => 'man',
            4 => 'me',
            5 => 'ms',
        ],
        'text/turtle' =>
        [
            0 => 'ttl',
        ],
        'text/uri-list' =>
        [
            0 => 'uri',
            1 => 'uris',
            2 => 'urls',
        ],
        'text/vcard' =>
        [
            0 => 'vcard',
        ],
        'text/vnd.curl' =>
        [
            0 => 'curl',
        ],
        'text/vnd.curl.dcurl' =>
        [
            0 => 'dcurl',
        ],
        'text/vnd.curl.mcurl' =>
        [
            0 => 'mcurl',
        ],
        'text/vnd.curl.scurl' =>
        [
            0 => 'scurl',
        ],
        'text/vnd.dvb.subtitle' =>
        [
            0 => 'sub',
        ],
        'text/vnd.fly' =>
        [
            0 => 'fly',
        ],
        'text/vnd.fmi.flexstor' =>
        [
            0 => 'flx',
        ],
        'text/vnd.graphviz' =>
        [
            0 => 'gv',
        ],
        'text/vnd.in3d.3dml' =>
        [
            0 => '3dml',
        ],
        'text/vnd.in3d.spot' =>
        [
            0 => 'spot',
        ],
        'text/vnd.sun.j2me.app-descriptor' =>
        [
            0 => 'jad',
        ],
        'text/vnd.wap.wml' =>
        [
            0 => 'wml',
        ],
        'text/vnd.wap.wmlscript' =>
        [
            0 => 'wmls',
        ],
        'text/x-asm' =>
        [
            0 => 's',
            1 => 'asm',
        ],
        'text/x-c' =>
        [
            0 => 'c',
            1 => 'cc',
            2 => 'cxx',
            3 => 'cpp',
            4 => 'h',
            5 => 'hh',
            6 => 'dic',
        ],
        'text/x-fortran' =>
        [
            0 => 'f',
            1 => 'for',
            2 => 'f77',
            3 => 'f90',
        ],
        'text/x-java-source' =>
        [
            0 => 'java',
        ],
        'text/x-nfo' =>
        [
            0 => 'nfo',
        ],
        'text/x-opml' =>
        [
            0 => 'opml',
        ],
        'text/x-pascal' =>
        [
            0 => 'p',
            1 => 'pas',
        ],
        'text/x-setext' =>
        [
            0 => 'etx',
        ],
        'text/x-sfv' =>
        [
            0 => 'sfv',
        ],
        'text/x-uuencode' =>
        [
            0 => 'uu',
        ],
        'text/x-vcalendar' =>
        [
            0 => 'vcs',
        ],
        'text/x-vcard' =>
        [
            0 => 'vcf',
        ],
        'video/3gpp' =>
        [
            0 => '3gp',
        ],
        'video/3gpp2' =>
        [
            0 => '3g2',
        ],
        'video/h261' =>
        [
            0 => 'h261',
        ],
        'video/h263' =>
        [
            0 => 'h263',
        ],
        'video/h264' =>
        [
            0 => 'h264',
        ],
        'video/jpeg' =>
        [
            0 => 'jpgv',
        ],
        'video/jpm' =>
        [
            0 => 'jpm',
            1 => 'jpgm',
        ],
        'video/mj2' =>
        [
            0 => 'mj2',
            1 => 'mjp2',
        ],
        'video/mp4' =>
        [
            0 => 'mp4',
            1 => 'mp4v',
            2 => 'mpg4',
        ],
        'video/mpeg' =>
        [
            0 => 'mpeg',
            1 => 'mpg',
            2 => 'mpe',
            3 => 'm1v',
            4 => 'm2v',
        ],
        'video/ogg' =>
        [
            0 => 'ogv',
        ],
        'video/quicktime' =>
        [
            0 => 'qt',
            1 => 'mov',
        ],
        'video/vnd.dece.hd' =>
        [
            0 => 'uvh',
            1 => 'uvvh',
        ],
        'video/vnd.dece.mobile' =>
        [
            0 => 'uvm',
            1 => 'uvvm',
        ],
        'video/vnd.dece.pd' =>
        [
            0 => 'uvp',
            1 => 'uvvp',
        ],
        'video/vnd.dece.sd' =>
        [
            0 => 'uvs',
            1 => 'uvvs',
        ],
        'video/vnd.dece.video' =>
        [
            0 => 'uvv',
            1 => 'uvvv',
        ],
        'video/vnd.dvb.file' =>
        [
            0 => 'dvb',
        ],
        'video/vnd.fvt' =>
        [
            0 => 'fvt',
        ],
        'video/vnd.mpegurl' =>
        [
            0 => 'mxu',
            1 => 'm4u',
        ],
        'video/vnd.ms-playready.media.pyv' =>
        [
            0 => 'pyv',
        ],
        'video/vnd.uvvu.mp4' =>
        [
            0 => 'uvu',
            1 => 'uvvu',
        ],
        'video/vnd.vivo' =>
        [
            0 => 'viv',
        ],
        'video/webm' =>
        [
            0 => 'webm',
        ],
        'video/x-f4v' =>
        [
            0 => 'f4v',
        ],
        'video/x-fli' =>
        [
            0 => 'fli',
        ],
        'video/x-flv' =>
        [
            0 => 'flv',
        ],
        'video/x-m4v' =>
        [
            0 => 'm4v',
        ],
        'video/x-matroska' =>
        [
            0 => 'mkv',
            1 => 'mk3d',
            2 => 'mks',
        ],
        'video/x-mng' =>
        [
            0 => 'mng',
        ],
        'video/x-ms-asf' =>
        [
            0 => 'asf',
            1 => 'asx',
        ],
        'video/x-ms-vob' =>
        [
            0 => 'vob',
        ],
        'video/x-ms-wm' =>
        [
            0 => 'wm',
        ],
        'video/x-ms-wmv' =>
        [
            0 => 'wmv',
        ],
        'video/x-ms-wmx' =>
        [
            0 => 'wmx',
        ],
        'video/x-ms-wvx' =>
        [
            0 => 'wvx',
        ],
        'video/x-msvideo' =>
        [
            0 => 'avi',
        ],
        'video/x-sgi-movie' =>
        [
            0 => 'movie',
        ],
        'video/x-smv' =>
        [
            0 => 'smv',
        ],
        'x-conference/x-cooltalk' =>
        [
            0 => 'ice',
        ],
    ],
];
<?php

///////
//
/// SERVER test routes
//
///////
$url = $_SERVER['REQUEST_URI'];
$parsed = parse_url($url);
$url = $parsed['path'];
if ($url=='/redirect/'){
    header("Location: /finished-redirect/");
    echo 'zeep';
    exit;
} else if ($url=='/finished-redirect/'){
    echo 'successful redirect';
} else if ($url=='/file-upload/'){

    echo 'File Content('.$_FILES['test_txt']['type'].'):'
        .file_get_contents($_FILES['test_txt']['tmp_name']);
} else if ($url=='/request-method/'){
    echo $_SERVER['REQUEST_METHOD'];
} else if ($url=='/') {
    echo "server-test";
}



/////////
//
//// BROWSER test routes
//
/////////
if ($url=='/browser/'){
    echo 'browser-test';
} else if ($url=='/go-home/'){
    header("Location: /browser/");
    exit;
} else if ($url=='/param/'){
    echo $_GET['param'];
} else if ($url=='/post/'){
    echo 'postme:'.$_POST['postme'];
} else if ($url=='/file/'){
    $file = $_FILES['file'];
    echo $file['name'].':'.file_get_contents($file['tmp_name']);
}
// else {
    // echo "failed at '$url'";
// }
<?php

echo "this is server 1";
<?php

echo "this is server 2";
<h1>Dir: test</h1>
    <section>        <h2>\Tlf\Tester\Test\Compare</h2><details>
    <summary><b>UnsortedArray:</b> <span style="color:green;">success</span>    </summary>
    <div style='padding-left:4ch;white-space:pre;'>
        
        
        +++pass+++
        Target:
        array ( 'a' =&gt; 'a', 'b' =&gt; 'b', )
        --
        Actual:
        array ( 'b' =&gt; 'b', 'a' =&gt; 'a', )
        --------
        
        
        +++pass+++
        is_false()
        
        +++pass+++ (inverted)
         strict comparisonTarget:
        array ( 'a' =&gt; 'a', 'b' =&gt; 'b', )
        --
        Actual:
        array ( 'b' =&gt; 'b', 'a' =&gt; 'a', )
        --------
        
    </div>
</details>
<details>
    <summary><b>ComparePHPFileToString:</b> <span style="color:green;">success</span> in 0.114ms   </summary>
    <div style='padding-left:4ch;white-space:pre;'>
        
        
        +++pass+++
        Target:
        I am php output
        --
        Actual:
        I am php output
        --------
        
        
        +++pass+++
        Target:
        I am php output
        --
        Actual:
        I am php output
        --------
        
    </div>
</details>
<details>
    <summary><b>CompareFileToStringStrict:</b> <span style="color:green;">success</span>    </summary>
    <div style='padding-left:4ch;white-space:pre;'>
        
        
        +++pass+++ (inverted)
         strict comparisonTarget:
        abcd
        I am a file
        
        I get tested against myself
        --
        Actual:
        file:///home/reed/data/owner/Reed/projects/php/unit-tester/test/extra/Compare/Compare.txt
        --------
        
        
        +++pass+++ (inverted)
         strict comparisonTarget:
        file:///home/reed/data/owner/Reed/projects/php/unit-tester/test/extra/Compare/Compare.txt
        --
        Actual:
        abcd
        I am a file
        
        I get tested against myself
        --------
        
    </div>
</details>
<details>
    <summary><b>CompareFileToStringLoose:</b> <span style="color:green;">success</span>    </summary>
    <div style='padding-left:4ch;white-space:pre;'>
        
        
        +++pass+++
        Target:
        abcd
        I am a file
        
        I get tested against myself
        --
        Actual:
        abcd
        I am a file
        
        I get tested against myself
        --------
        
        
        +++pass+++
        Target:
        abcd
        I am a file
        
        I get tested against myself
        --
        Actual:
        abcd
        I am a file
        
        I get tested against myself
        --------
        
    </div>
</details>
<details>
    <summary><b>ComparestringsWithDiffPad:</b> <span style="color:green;">success</span>    </summary>
    <div style='padding-left:4ch;white-space:pre;'>
        
        
        +++pass+++ (inverted)
         strict comparisonTarget:
           I am a string.
        --
        Actual:
        I am a string.
        --------
        
        
        +++pass+++
        Target:
        I am a string.
        --
        Actual:
        I am a string.
        --------
        
    </div>
</details>
<details>
    <summary><b>CompareStringsThatMatch:</b> <span style="color:green;">success</span>    </summary>
    <div style='padding-left:4ch;white-space:pre;'>
        
        
        +++pass+++
         strict comparisonTarget:
        Be good to others.
        --
        Actual:
        Be good to others.
        --------
        
    </div>
</details>
        <h2>\Tlf\Tester\Test\NewTests</h2><details>
    <summary><b>NewCliRunTest:</b> <strong style="color:blue;">error</strong> in 0.531ms   </summary>
    <div style='padding-left:4ch;white-space:pre;'>
        
        dir /home/reed/data/owner/Reed/projects/php/unit-tester/test/extra//test
        class \Tlf\Tester\Test\SubTest\Test
          + Anything
        
        Passing: 1 tests
        Failing: 0 tests
        
        See file:///home/reed/data/owner/Reed/projects/php/unit-tester/test/extra/test/TestResults.html for extended output
        
        
        
        
    </div>
    <br>
    <div style='color:red;padding-left:4ch;white-space:pre;'>
        ErrorException: Undefined index: \Taeluf\Tester\Test\SubTest\Test in /home/reed/data/owner/Reed/projects/php/unit-tester/test/all/New.php:14
        Stack trace:
        #0 /home/reed/data/owner/Reed/projects/php/unit-tester/test/all/New.php(14): Tlf\Tester->throwError()
        #1 /home/reed/data/owner/Reed/projects/php/unit-tester/code/Tester.php(129): Tlf\Tester\Test\NewTests->testNewCliRunTest()
        #2 /home/reed/data/owner/Reed/projects/php/unit-tester/code/NewCli.php(134): Tlf\Tester->run()
        #3 /home/reed/data/owner/Reed/projects/php/unit-tester/code/phptest(29): Tlf\Tester\NewCli->run()
        #4 /home/reed/data/owner/Reed/projects/php/cli/test/Cli.php(90): {closure}()
        #5 /home/reed/data/owner/Reed/projects/php/unit-tester/code/phptest(39): Tlf\Cli->execute()
        #6 {main}
    </div>
</details>
<details>
    <summary><b>NewCli:</b> <span style="color:green;">success</span> in 0.297ms   </summary>
    <div style='padding-left:4ch;white-space:pre;'>
        
        
        
        ****subtest: Inputs****
        
        +++pass+++
        Target:
        array ( 'file.config' =&gt; 'test/config.json', 'test' =&gt; '', 'config' =&gt; 'value', 'boolConfig' =&gt; '', 'anotherBoolConfig' =&gt; '1', 'key' =&gt; 'value2', )
        --
        Actual:
        array ( 'file.config' =&gt; 'test/config.json', 'test' =&gt; '', 'config' =&gt; 'value', 'boolConfig' =&gt; '', 'anotherBoolConfig' =&gt; '1', 'key' =&gt; 'value2', )
        --------
        
        
        ****subtest: Configs****
        
        +++pass+++
        Target:
        array ( 'dir.test' =&gt; 'test', 'dir.exclude' =&gt; array ( 0 =&gt; 'extra', ), 'file.autoloader' =&gt; '../../vendor/autoload.php', 'file.require' =&gt; array ( ), 'dir.require' =&gt; array ( ), 'results.writeHtml' =&gt; '1', )
        --
        Actual:
        array ( 'dir.test' =&gt; 'test', 'dir.exclude' =&gt; array ( 0 =&gt; 'extra', ), 'file.autoloader' =&gt; '../../vendor/autoload.php', 'file.require' =&gt; array ( ), 'dir.require' =&gt; array ( ), 'results.writeHtml' =&gt; '1', )
        --------
        
    </div>
</details>
        <h2>\Tlf\Tester\Test\SubTest\Test</h2><details>
    <summary><b>Anything:</b> <span style="color:green;">success</span>    </summary>
    <div style='padding-left:4ch;white-space:pre;'>
        
        
        +++pass+++
        Target:
        true
        --
        Actual:
        true
        --------
        
    </div>
</details>
    </section><?php

namespace Tlf\Tester\Test;

/** 
 * Base class for your test classes
 */
class Tester extends \Tlf\Tester {


}
<?php

// in case you need to do stuff before tests are run
{
    "dir.test":["test/run"],
    "dir.exclude":[],
    "file.require":["test/bootstrap.php"],

    "results.writeHtml":false,

    "server":{
        "main": { "dir":"test/Server" },
        "1": { "dir":"test/Server1" },
        "2": { "dir":"test/Server2" }
    },

    "bench.threshold": 0.0001,
    "test":[],
    "class":[]
}
this is text
<?php echo "I am php output"; ?>abcd
I am a file

I get tested against myself<h1>Dir: test</h1>
    <section>        <h2>\Tlf\Tester\Test\SubTest\Test</h2><details>
    <summary><b>Anything:</b> <span style="color:green;">success</span>    </summary>
    <div style='padding-left:4ch;white-space:pre;'>
        
        
        +++pass+++
        Target:
        true
        --
        Actual:
        true
        --------
        
    </div>
</details>
    </section>{
    "file.autoloader":"../../vendor/autoload.php"
}
<?php

namespace Tlf\Tester\Test\Runner;

class NestedTest extends \Tlf\Tester {

    /** called before tests are run */
    public function prepare(){}

    /** Test methods must prefix with `test` */
    public function testAnything(){
        $this->compare(true,true);
    }
}
this file is for testing uploads
<?php

namespace Tlf\Tester\Test;

class Browser extends \Tlf\Tester {

    public function testPostFile(){
        $browser = new \Tlf\Tester\CurlBrowser($this->get_server());
        $browser->post('/file/', ['postme'=>'fun'],[], ['file'=>$this->file('test/input/Browser/file.txt')]);

        $this->compare('file.txt:this is text', ''.$browser);
    }

    public function testBrowserPost(){
        $browser = new \Tlf\Tester\CurlBrowser($this->get_server());
        $browser->post('/post/', ['postme'=>'fun']);

        $this->compare('postme:fun', ''.$browser);
    }

    public function testBrowserFollow(){
        $browser = new \Tlf\Tester\CurlBrowser($this->get_server());
        $browser->get('/go-home/');
        $this->compare('', $browser.'');

        $browser->follow();
        
        $this->compare('browser-test', $browser.'');
    }

    public function testBrowserGetParam(){

        $browser = new \Tlf\Tester\CurlBrowser($this->get_server());
        $browser->get('/param/', ['param'=>'test']);

        $this->compare('test', $browser.'');
    }

    public function testBrowserGet(){

        $browser = new \Tlf\Tester\CurlBrowser($this->get_server());
        $browser->get('/browser/');

        $this->compare('browser-test', $browser.'');
    }
}
<?php

namespace Tlf\Tester\Test;

class Compare extends \Tlf\Tester {

    public function testCompareLines(){

        $this->compare_lines(
            "abc\ndef\nghi\n\n\n    jkl  \nmnop  \n\n",
            "  abc  \n def \n \n ghi \n\n\n jkl  \n\n mnop"
        );
    }


    public function testUnsortedArray(){

        $a = [
            'a'=>'a',
            'b'=>'b',
        ];
        $b = [
            'b'=>'b',
            'a'=>'a'
        ];

        $this->compare($a,$b);


        $this->is_false($a===$b);

        $this->invert();
        $this->compare($a,$b, true);

    }
    public function testComparePHPFileToString(){
        $file = dirname(__DIR__).'/input/Compare/Compare.php';
        ob_start();
        require($file);
        $target = ob_get_clean();
        if (substr($target,0,4)!='I am'){
            throw new \Exception("The source file for the test does not match /^I am.*/");
        }

        $this->compare($target,'file://'.$file);
            
        $this->compare('file://'.$file,$target);
    }
    public function testCompareFileToStringStrict(){
        $file = dirname(__DIR__).'/input/Compare/Compare.txt';
        $target = file_get_contents($file);
        if (substr($target,0,4)!='abcd'){
            throw new \Exception("The source file for the test does not match /^abcd.*/");
        }

        $this->invert();

        $this->compare($target, "file://{$file}",true);

        $this->compare("file://{$file}",$target,true);
    }

    public function testCompareFileToStringLoose(){
        $file = dirname(__DIR__).'/input/Compare/Compare.txt';
        $target = file_get_contents($file);
        if (substr($target,0,4)!='abcd'){
            throw new \Exception("The source file for the test does not match /^abcd.*/");
        }

        $this->compare($target, "file://{$file}");
        $this->compare("file://{$file}",$target);
    }
    public function testComparestringsWithDiffPad(){
        $actual = "I am a string.";
        $target = "   ".$actual;

        $this->invert();
        $this->compare($target,$actual,true);
        $this->invert();

        $this->compare($target,$actual);
    }

    public function testCompareStringsThatMatch(){
        $actual = "Be good to others.";
        $target = $actual;

        return $this->compare($target,$actual,true);
    }
}

<?php

namespace Tlf\Tester\Test;

class Exceptions extends \Tlf\Tester {

    public function testTriggerError(){

        if ($this->php_major_version()<8){
            $this->catch('Exception')
                 ->containing('Undefined index: cat')
             ;
        } else {
            $this->catch('Exception')
                 ->containing('Undefined array key "cat"')
             ;
        }
        $array = [];
        try {
            $cat = $array['cat'];
        } catch (\Exception $e){
            $this->throw($e);
        }
    }

    public function testThrowException(){
        $this->catch('Exception')
             ->containing('Undefined index: cat')
         ;
        try {
            throw new \Exception('Undefined index: cat');
        } catch (\Exception $e){
            $this->throw($e);
        }
    }

}
<?php

namespace Tlf\Tester\Test;

class Runner extends \Tlf\Tester {

    /**
     * @test SOME of the return value from running a directory of tests
     */
    public function testRunnerResults(){

        $cli = $runner = new \Tlf\Tester\Runner(dirname(__DIR__).'/input/Runner/',['phptest']);

        $cli->load_inputs(json_decode(file_get_contents(dirname(__DIR__,2).'/src/defaults.json'),true));

        $cli->load_inputs(['dir.test'=>['run/']]);

        $results = $runner->run_dir($cli, $cli->args);

        unset($results['class']);
        $this->compare(
            ['pass'=>1,
            'fail'=>0,
            'tests_run'=>1,
            'disabled'=>0,
            'assertions_pass'=>1,
            'assertions_fail'=>0
            ],
            $results
        );

    }
}

<?php

namespace Tlf\Tester\Test;

class Server extends \Tlf\Tester {

    public function testMultiServer1(){
        $response = $this->get('/',[], '1');

        $this->compare(
            $response,
            "this is server 1"
        );
    }

    public function testMultiServer2(){
        $response = $this->get('/',[], '2');

        $this->compare(
            $response,
            "this is server 2"
        );

    }

    public function testRequestMethod(){
        $response = $this->get('/request-method/');
        $this->compare('GET', $response);


        $response = $this->post('/request-method/');
        $this->compare('POST', $response);
    }

    public function testFileUpload(){
        $response = $this->post('/file-upload/',[], 
            [ 'test.txt' => $this->file('test/input/test-upload.txt') ]
        );

        echo $response;
        $this->compare('File Content(text/plain):this file is for testing uploads', $response);
    }

    public function testPostRedirect(){
        $response = $this->post('/redirect/');

        $this->compare('successful redirect', $response);
    }

    /**
     * @test that the phptest server works
     */
    public function testServer(){
        $response = $this->get('/');
        $this->compare('server-test', $response);
    }
}

<?php

namespace Tlf\Util;

/**
 * Prevent spam in forms
 */
class FormSpam {


    /** either POST or GET, depending which request method was used */
    public $data = [];

    /**
     *
     * @key the key_prefix
     * @value the actual key (with uniqid)
     */
    public array $latest_csrf = [];

    /** 
     * This should only be set after a session is validated
     * @key the csrf token name
     * @value true, always true
     */
    public array $valid_sessions = [];


    public function __construct(){
        if (count($_POST)>0)$this->data = $_POST;
        else $this->data = $_GET;
    }

    /**
     * Print all the spam controls into a form & send any cookies/headers
     *
     * @see enable_csrf() for description of args
     */
    public function print_spam_controls(string $key_prefix='',int $expiry_minutes=60, string $url_path=''){
        $this->enable_csrf($key_prefix, $expiry_minutes, $url_path);
        $this->enable_honey();
    }

    /**
     * Print the honeypot inputs
     */
    public function enable_honey(){
        require(__DIR__.'/HoneyForm.php');
    }

    /**
     * Check if the submission is valid or spam.
     *
     * @param $key_prefix @see is_valid_csrf()
     * @return true if the submission is valid, false if the submission is spam.
     */
    public function is_valid_submission(string $key_prefix=''){
        if ($this->is_valid_honey()
            && $this->is_valid_csrf($key_prefix))return true;

        return false;
    }

    /**
     * Verify the honeypot fields are correct.
     * @return true if honeypot fields are correctly filled. false means it is likely spam.
     */
    public function is_valid_honey(){
        if (!isset($this->data['honey']))return false;
        $honey = $this->data['honey'];
        $names = explode(',', $honey);
        if (count($names)!=3)return false;
        if (!isset($this->data[$names[0]])
            ||$this->data[$names[0]]!==''
            )return false;
        if (!isset($this->data[$names[1]])
            ||$this->data[$names[1]]!==''
            )return false;

        if (!isset($this->data[$names[2]])
            ||$this->data[$names[2]]==''
            )return false;

        if (!isset($this->data['honey_answer'])
            ||$this->data['honey_answer'] == ''
            )return false;
        // echo 'no';
        // exit;
        // var_dump($this->data['honey_answer']);
        // var_dump($this->data[$names[2]]);
        // var_dump(password_hash($this->data[$names[2]], PASSWORD_DEFAULT));

        // if (!password_verify($this->data[$names[2]], $this->data['honey_answer']))return false;
        if (md5($this->data[$names[2]]) != $this->data['honey_answer'])return false;

        return true;
    }

    /**
     * Checks `$_POST` for the csrf token
     *
     * @param $key_prefix the same key prefix you passed to `$this->enable_csrf()`
     * @return true if the csrf token is valid. false if it is spam.
     */
    public function is_valid_csrf(string $key_prefix=''): bool {
        // this attempts to do the checks listed on https://www.taeluf.com/blog/php/security/csrf-validation/

        $post_key = $this->get_csrf_post_key($key_prefix);
        if ($post_key=='')return false;
        $post_code = $_POST[$post_key];
        // because i unset from $_SESSION
        if (isset($this->valid_sessions[$post_key]))return true;

        if (session_status()==PHP_SESSION_NONE)session_start();
        if (session_status()!=PHP_SESSION_ACTIVE)throw new \Exception("Failed to start session. Cannot do csrf without session.");

        if (!isset($_SESSION[$post_key]))return false;
        $session_csrf = $_SESSION[$post_key];
        if ($session_csrf['code'] != $post_code) return false;
        if ($session_csrf['expires_at'] < time()) return false;
        $post_path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);

        if ($session_csrf['uri'] != ''
            &&$session_csrf['uri'] != $post_path
        )return false;
        if (!isset($_SERVER['HTTP_REFERER']))return false;
        $referer_domain = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST);
        // to remove the port (mainly bc of localhost testing)
        $server_host = parse_url($_SERVER['HTTP_HOST'], PHP_URL_HOST);
        if ($server_host==null)$server_host = $_SERVER['HTTP_HOST'];

        if ($referer_domain != $server_host)return false;

        unset($_SESSION[$post_key]);
        $this->valid_sessions[$post_key] = true;
        return true;
    }


    /**
     *
     *
     * @param $key_prefix string to help identify your csrf token.
     * @param $expiry_minutes number of minutes the token should be valid for
     * @param $url the url path the token should be validated on, like '/some/url/'. If not set, it works on any path
     *
     * @output a hidden input with the csrf value
     *
     * @return the csrf key. To load csrf data do `$_SESSION[$csrf_key]`. `$csrf_key` will be like `key_prefix-csrf-uniqid()`
     */
    public function enable_csrf(string $key_prefix='',int $expiry_minutes=60, string $url_path=''){
        $key = $key_prefix.'-csrf-'.uniqid();
        $code = $this->make_csrf_code(); 
        $data = [
            'code'=> $code,
            'expires_at' => time() + $expiry_minutes * 60,
            'uri' => $url_path,
        ];
        if (session_status()==PHP_SESSION_NONE)session_start();
        if (session_status()!=PHP_SESSION_ACTIVE)throw new \Exception("Failed to start session. Cannot do csrf without session.");
        $_SESSION[$key] = $data;
        $this->latest_csrf[$key_prefix] = $key;

        // var_dump($data);
        echo  "<input type=\"hidden\" name=\"$key\" value=\"$code\">";
        echo  "<input type=\"hidden\" name=\"csrf_key\" value=\"$key\">";
        // error_log('csrf key: '.$key);
        return $key;
    }


    public function make_csrf_code(){
        // this code from symfony csrf package: https://github.com/symfony/security-csrf/blob/5.4/TokenGenerator/UriSafeTokenGenerator.php
        $bytes = random_bytes(64);

        return rtrim(strtr(base64_encode($bytes), '+/', '-_'), '=');
    }

    /** 
     * get the key of the csrf data in `$_POST` for the given key
     * @param $key_prefix see csrf_is_valid
     */
    public function get_csrf_post_key(string $key_prefix=''): string {
        $len = strlen($key_prefix) + strlen('-csrf-');
        foreach ($_POST as $key=>$value){
            if (substr($key,0,$len)!=$key_prefix.'-csrf-')continue;
            $post_key = $key;
            // $post_code = $value;
            return $post_key;
            // break;
        }
        return '';
    }

    public function get_csrf_session_key(string $key_prefix=''): string {
        if (isset($this->latest_csrf[$key_prefix]))return $this->latest_csrf[$key_prefix];
        $len = strlen($key_prefix) + strlen('-csrf-');
        foreach ($_SESSION as $key=>$value){
            if (substr($key,0,$len)!=$key_prefix.'-csrf-')continue;
            return $key;
        }
        return '';
    }

    public function get_csrf_session_input(string $key_prefix=''): string {
        $key = $this->get_csrf_session_key($key_prefix);
        $code = $_SESSION[$key]['code'];
        return '<input type="hidden" name="'.$key.'" value="'.$code.'">';
    }

}
<?php

$names = [
    0=>uniqid(),
    1=>uniqid(),
    2=>'a'.uniqid().'b',
];

$answer = uniqid();
$hash = md5($answer);
// password_hash($answer, PASSWORD_DEFAULT)
?>
<input type="text" name="<?=$names[0]?>" style="display:none;" value="" />
<input type="hidden" name="<?=$names[1]?>" value="" />
<div class="<?=$names[2]?>">
<br>Please type <b><?=$answer?></b> into here, or enable javascript:<br>

    <input type="text" name="<?=$names[2]?>">
<br>
</div>
<script type="text/javascript">
(function(){
    const elem = document.querySelector('.<?=$names[2]?>');
    elem.style.display = 'none';
    const input = document.querySelector('.<?=$names[2]?> > input');
    input.setAttribute('value', '<?=$answer?>');
})();
</script>

<input type="hidden" name="honey" value="<?=implode(',', $names);?>">
<input type="hidden" name="honey_answer" value="<?=$hash?>">
<?php

namespace Tlf;

/**
 * A Utility class of convenience methods
 */
class Util  {

    /**
     * use `token_get_all()` to get a fully qualified class name from a file. Only gets the first defined class. Works with both php 7.4 and php 8.0
     *
     * @param $file an absolute file path
     *
     * @param $file an absolute path to a file
     * @return null if no class found or a string with the `Qualified\Clazz\Name`
     */
    static public function getClassFromFile($file){
        $DEBUG_MODE = false;
        if (is_dir($file)||!is_file($file)){
            return null;
            // throw new \Exception("'$file' is not a file");
        }


        $version = phpversion();
        $version_int = substr($version,0,1);
        $php_version = (int)$version_int;
 //echo "\n\n\n-----------\n\n";
        if ($DEBUG_MODE){
             //echo "VERSION: $version\nINT: $php_version";
             //exit;
        }

        $fp = fopen($file, 'r');
        $class = "";
        $class = $namespace = $buffer = '';
        $i = 0;
        $has_matched_class = false;

            ob_start();

        /**
         * Ensure buffer is long enough
         * An opening bracket is returned as a string, rather than an array detailing the token like every other token
         * So if there's a value that's JUST an opening bracket, there's a pretty good chance we've found our class.
         * This fails if there are opening brackets prior to the class's opening bracket, AND the class's opening bracket doesn't get loaded into the initial buffer. Bug is noted in the test class.
         */
        do {
            $buffer .= fread($fp, 512);
            $tokens = @token_get_all($buffer);
            //print_r($tokens);
        }
        while (array_search("{", $tokens) === false && !feof($fp));
        $err = ob_get_clean();

        //print_r($tokens);
        //exit;


            // loop over tokens
        $tcount = count($tokens);
        for (;$i<$tcount;$i++) {
            if ($php_version < 8 && $tokens[$i][0] === T_NAMESPACE) {
                if ($has_matched_class)continue;
                // for php < 8, if namespace token is namespace, loop over tokens and collect T_STRING tokens as the namespaces 
                for ($j=$i+1;$j<$tcount; $j++) {
                    if ($tokens[$j][0] === T_STRING) {

                        if ($DEBUG_MODE){
                            echo "\nPHP<8 NAMESPACE MATCH";
                            var_dump($tokens[$j]);
                        }
                        $namespace .= '\\'.$tokens[$j][1];
                    } else if ($tokens[$j] === '{' || $tokens[$j] === ';') {
                        if ($DEBUG_MODE){
                            echo "\nPHP<8 BREAK on '{' or ';'";
                            var_dump($tokens[$j]);
                        }
                        break;
                    }
                }
            } else if ($php_version >= 8 && $tokens[$i][0] == T_NAME_QUALIFIED && $namespace == null){//316){ // T_NAME_QUALIFIED === 316 
                if ($has_matched_class)continue;
                if ($DEBUG_MODE){
                    echo "\nPHP8+ NAMESPACE MATCH";
                    var_dump($tokens[$i]);
                }
                // for php >= 8, T_NAME_QUALIFIED token is the full namespace
                $namespace = '\\'.$tokens[$i][1];
                // var_dump($tokens[$i]);
            }
            
            // capture class name
            if ($tokens[$i][0] === T_CLASS) {
                if ($DEBUG_MODE){
                    echo "\nCLASS KEYWORD MATCH( i=$i)\n";
                    var_dump($tokens[$i]);
                }
                for ($j=$i+1;$j<count($tokens);$j++) {
                    $entry = is_array($tokens[$j]) ? 'array' : $tokens[$j];
                    if ($DEBUG_MODE){
                        echo "\nclass subloop: $j, ".$entry;
                        var_dump($tokens[$j]);
                    }
                    if ($tokens[$j] === '{') {
                        if ($DEBUG_MODE){
                            echo "\nOPEN BRACKET MATCHED";
                            var_dump($tokens[$j]);
                        }
                        if (isset($tokens[$i+2][1])){
                            $has_matched_class = true;

                            if ($DEBUG_MODE){
                                echo "\nCLASS NAME MATCH";
                                var_dump($tokens[$i+2]);
                            }
                            $class = $tokens[$i+2][1];
                        }
                    }
                }
            }
        }

        if ($class=='')return '';
        $full = $namespace.'\\'.$class;
        // var_dump("FULL CLASS: $full");
        return $namespace.'\\'.$class;
        
    }

    /**
     * Upload a file
     * @param $file an entry in `$_FILES[]`
     * @param $destinationFolder directory to upload to
     * @param $validExts array of extensions or an array containing just `*` to accept all file types.
     * @param $maxMB max size of file to allow
     *
     * Function comes from Util class of repo at https://gitlab.com/taeluf/php/php-utilities
     */
    static public function uploadFile($file, $destinationFolder, $validExts = ['jpg', 'png'], $maxMB = 15)
    {
        // print_r($file);
        // exit;
        if (!is_array($file) || $file == []
            || $file['size'] == 0
            || $file['name'] == ''
            || $file['tmp_name'] == ''
            || !is_int($file['error'])) {
            return false;
        }

        try {
            if (!isset($file['error']) ||
                is_array($file['error'])
            ) {
                throw new \RuntimeException('Invalid parameters.');
            }

            switch ($file['error']) {
                case UPLOAD_ERR_OK:
                    break;
                case UPLOAD_ERR_NO_FILE:
                    throw new \RuntimeException('No file sent.');
                case UPLOAD_ERR_INI_SIZE:
                case UPLOAD_ERR_FORM_SIZE:
                    throw new \RuntimeException('Exceeded filesize limit.');
                default:
                    throw new \RuntimeException('Unknown errors.');
            }

            // You should also check filesize here.
            if ($file['size'] > ($maxMB * 1024 * 1024)) {
                throw new \RuntimeException('Exceeded filesize limit.');
            }

            $ext = pathinfo($file['name'], PATHINFO_EXTENSION);
            $ext = strtolower($ext);

            // check file format
            if (!in_array('*', $validExts)&&!in_array($ext, $validExts)) {
                // var_dump($ext);
                // var_dump($validExts);
                // var_dump($file);
                // exit;
                throw new \RuntimeException('Invalid file format ('.$ext.').');
            }

            if (!file_exists($destinationFolder)) {
                mkdir($destinationFolder, 0775, true);
            }

            $fileName = sha1_file($file['tmp_name']) .'-'. uniqid() . '.' . $ext;
            if (!move_uploaded_file(
                $file['tmp_name'],
                $destinationFolder . '/' . $fileName
            )
            ) {
                throw new \RuntimeException('Failed to move uploaded file.');
            }

            return $fileName;

        } catch (\RuntimeException $e) {

            throw $e;

        }
    }

}
{
    "name": "taeluf/util",
    "description": "Utility methods",
    "type": "library",
    "autoload": {
        "classmap":["code"]
    },
    "bin": [
    ],
    "license": "MIT",
    "require-dev": {
        "taeluf/code-scrawl":"v0.8.x-dev",
        "taeluf/tester": "v0.3.x-dev",
        "taeluf/phtml": "v0.1.x-dev"
    },
    "minimum-stability":"dev"
}
{
    "_readme": [
        "This file locks the dependencies of your project to a known state",
        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
        "This file is @generated automatically"
    ],
    "content-hash": "0136ce6bca4e3e2b82eb15e43e401601",
    "packages": [],
    "packages-dev": [
        {
            "name": "taeluf/better-regex",
            "version": "v0.4.x-dev",
            "source": {
                "type": "git",
                "url": "git@gitlab.com:taeluf/php/better-regex.git",
                "reference": "3ee2ff3482d8903d6977fa1fd97a227f4457dc54"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Fbetter-regex/repository/archive.zip?sha=3ee2ff3482d8903d6977fa1fd97a227f4457dc54",
                "reference": "3ee2ff3482d8903d6977fa1fd97a227f4457dc54",
                "shasum": ""
            },
            "require-dev": {
                "taeluf/code-scrawl": "v0.7.x-dev",
                "taeluf/tester": "v0.3.x-dev"
            },
            "default-branch": true,
            "type": "library",
            "autoload": {
                "classmap": [
                    "code"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "time": "2022-03-28T20:55:32+00:00"
        },
        {
            "name": "taeluf/cli",
            "version": "v0.1.x-dev",
            "source": {
                "type": "git",
                "url": "git@gitlab.com:taeluf/php/cli.git",
                "reference": "ab3067f55db8d8592d5a7e3dfe072d3b00c50e80"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Fcli/repository/archive.zip?sha=ab3067f55db8d8592d5a7e3dfe072d3b00c50e80",
                "reference": "ab3067f55db8d8592d5a7e3dfe072d3b00c50e80",
                "shasum": ""
            },
            "require-dev": {
                "taeluf/code-scrawl": "v0.8.x-dev"
            },
            "default-branch": true,
            "type": "library",
            "autoload": {
                "files": [],
                "classmap": [
                    "code"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "time": "2022-12-08T20:29:22+00:00"
        },
        {
            "name": "taeluf/code-scrawl",
            "version": "v0.8.x-dev",
            "source": {
                "type": "git",
                "url": "git@gitlab.com:taeluf/php/CodeScrawl.git",
                "reference": "d79564b10cc16aa7811e31764b7e11cd14f5570c"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2FCodeScrawl/repository/archive.zip?sha=d79564b10cc16aa7811e31764b7e11cd14f5570c",
                "reference": "d79564b10cc16aa7811e31764b7e11cd14f5570c",
                "shasum": ""
            },
            "require": {
                "taeluf/better-regex": "v0.4.x-dev",
                "taeluf/cli": "v0.1.x-dev",
                "taeluf/lexer": "v0.8.x-dev"
            },
            "require-dev": {
                "taeluf/tester": "v0.3.x-dev"
            },
            "default-branch": true,
            "bin": [
                "bin/scrawl"
            ],
            "type": "library",
            "autoload": {
                "classmap": [
                    "code/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "description": "A documentation generation framework with some built-in extensions for exporting comments and code, and importing into markdown. ",
            "time": "2022-12-10T15:49:11+00:00"
        },
        {
            "name": "taeluf/lexer",
            "version": "v0.8.x-dev",
            "source": {
                "type": "git",
                "url": "git@gitlab.com:taeluf/php/lexer.git",
                "reference": "0f65bbfa4dde6b88affb87263a2be70b5cc8f0f0"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Flexer/repository/archive.zip?sha=0f65bbfa4dde6b88affb87263a2be70b5cc8f0f0",
                "reference": "0f65bbfa4dde6b88affb87263a2be70b5cc8f0f0",
                "shasum": ""
            },
            "require-dev": {
                "taeluf/tester": "v0.3.x-dev"
            },
            "default-branch": true,
            "type": "library",
            "autoload": {
                "classmap": [
                    "code"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "description": "A declarative lexer seamlessly hooking into php functions, building ASTs for multiple languages.",
            "time": "2022-12-10T15:36:14+00:00"
        },
        {
            "name": "taeluf/phtml",
            "version": "v0.1.x-dev",
            "source": {
                "type": "git",
                "url": "git@gitlab.com:taeluf/php/phtml-dom-document.git",
                "reference": "68fbcd60d9b0eafa61c281bcf384722d3bff3fa4"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Fphtml-dom-document/repository/archive.zip?sha=68fbcd60d9b0eafa61c281bcf384722d3bff3fa4",
                "reference": "68fbcd60d9b0eafa61c281bcf384722d3bff3fa4",
                "shasum": ""
            },
            "require-dev": {
                "taeluf/code-scrawl": "v0.6.x-dev",
                "taeluf/tester": "v0.3.x-dev"
            },
            "default-branch": true,
            "type": "library",
            "autoload": {
                "classmap": [
                    "code"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "time": "2022-12-08T21:17:59+00:00"
        },
        {
            "name": "taeluf/tester",
            "version": "v0.3.x-dev",
            "source": {
                "type": "git",
                "url": "git@gitlab.com:taeluf/php/php-tests.git",
                "reference": "8b4c907d3de2a0809fb35646f9117d3b917a2491"
            },
            "dist": {
                "type": "zip",
                "url": "https://gitlab.com/api/v4/projects/taeluf%2Fphp%2Fphp-tests/repository/archive.zip?sha=8b4c907d3de2a0809fb35646f9117d3b917a2491",
                "reference": "8b4c907d3de2a0809fb35646f9117d3b917a2491",
                "shasum": ""
            },
            "require": {
                "taeluf/cli": "v0.1.x-dev",
                "taeluf/util": "v0.1.x-dev"
            },
            "require-dev": {
                "taeluf/code-scrawl": "v0.6.x-dev"
            },
            "default-branch": true,
            "bin": [
                "code/phptest"
            ],
            "type": "library",
            "autoload": {
                "classmap": [
                    "code/"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "description": "A unit testing library for Php.",
            "time": "2022-12-14T19:08:13+00:00"
        }
    ],
    "aliases": [],
    "minimum-stability": "dev",
    "stability-flags": {
        "taeluf/code-scrawl": 20,
        "taeluf/tester": 20,
        "taeluf/phtml": 20
    },
    "prefer-stable": false,
    "prefer-lowest": false,
    "platform": [],
    "platform-dev": [],
    "plugin-api-version": "2.3.0"
}
<?php

require_once(dirname(__DIR__,2).'/vendor/autoload.php');

///////
//
/// SERVER test routes
//
///////
$url = $_SERVER['REQUEST_URI'];
$parsed = parse_url($url);
$url = $parsed['path'];




$file = __DIR__.'/public/'.$url;

require($file);



return;
// if ($url=='/redirect/'){
//     header("Location: /finished-redirect/");
//     echo 'zeep';
//     exit;
// } else if ($url=='/finished-redirect/'){
//     echo 'successful redirect';
// } else if ($url=='/file-upload/'){
//
//     echo 'File Content('.$_FILES['test_txt']['type'].'):'
//         .file_get_contents($_FILES['test_txt']['tmp_name']);
// } else if ($url=='/request-method/'){
//     echo $_SERVER['REQUEST_METHOD'];
// } else if ($url=='/') {
//     echo "server-test";
// }
//
//
//
// /////////
// //
// //// BROWSER test routes
// //
// /////////
// if ($url=='/browser/'){
//     echo 'browser-test';
// } else if ($url=='/go-home/'){
//     header("Location: /browser/");
//     exit;
// } else if ($url=='/param/'){
//     echo $_GET['param'];
// } else if ($url=='/post/'){
//     echo 'postme:'.$_POST['postme'];
// } else if ($url=='/file/'){
//     $file = $_FILES['file'];
//     echo $file['name'].':'.file_get_contents($file['tmp_name']);
// }
// // else {
//     // echo "failed at '$url'";
// // }
<?php


$fs = new \Tlf\Util\FormSpam();
if ($fs->is_valid_csrf('csrf-test')){
    echo 'csrf post test success';
    return;
}
echo 'csrf post test not valid';

<?php

$fs = new \Tlf\Util\FormSpam();
ob_start();
$key = $fs->enable_csrf('csrf-test', 10, '/csrf-test-post.php');
ob_end_clean();
$data = $_SESSION[$key];
$data['key'] = $key;

echo json_encode($data);
<form action="/honey-post.php" method="POST">
    <?php 
        $fs = new \Tlf\Util\FormSpam();
        $fs->enable_honey();
    ?>

    <input type="submit" value="Submit blank honey form">
</form>

<?php

$fs = new \Tlf\Util\FormSpam();
if ($fs->is_valid_honey()){
    echo 'honey post test success';
    return;
}
echo 'honey post test not valid';

<form action="/spam-post.php" method="POST">
<?php

$fs = new \Tlf\Util\FormSpam();
$key = $fs->print_spam_controls('spam-form', 10, '/spam-post.php');
// $data = $_SESSION[$key];
// $data['key'] = $key;

// echo json_encode($data);
//
?>

<input type="submit" value="Submit empty spam form">
</form>
<?php

$fs = new \Tlf\Util\FormSpam();
if ($fs->is_valid_submission('spam-form')){
    echo 'submission valid';
    return;
}
echo 'submission NOT valid';

#!/usr/bin/env php
<?php

$root = dirname(__DIR__,2);
require_once($root.'/code/Util.php');

/**
 * php tester relies upon the class finder method, SO this file tests that method
 */

$file = $root.'/test/input/SampleClass.php';

$actual_class = \Tlf\Util::getClassFromFile($file);

$target_class = '\\Tlf\\Util\\Test\\SampleClass';


echo "\nTarget Class: '$target_class'";
echo "\nClass Found: '$actual_class'";
<?php

// in case you need to do stuff before tests are run
{
    "dir.test":"test/run",
    "dir.exclude":[],
    "file.require":["test/bootstrap.php"],
    "dir.require":["test/src"],
    "results.writeHtml":false,
    "server.dir":"test/Server/",
    "server.router":"deliver.php",
    "servers":{
        "1":"test/Server1/deliver.php",
        "2":"test/Server2/deliver.php"
    },
    "host":{
        "production":"https://some-site-whatever.whatever",
        "test":"https://some-site-whatever.whatever"
    },

    "bench.threshold": 0.00001,
    "test":[],
    "class":[]
}
<?php

namespace Tlf\Util\Test;

class ClassExtends extends \ClassOnlyTest {

    public function do_nothing(){}
}
<?php

namespace Tlf\Util\Test;

class ClassExtendsAndImplements extends \ClassOnlyTest implements ClassImplementsInterface {

    public function do_nothing(){}
}
<?php

class ClassExtendsAndImplementsNoNamespace extends \ClassOnlyTest implements Tlf\Util\Test\ClassImplementsInterface {

    public function do_nothing(){}
}
<?php

namespace Tlf\Util\Test;

class ClassImplements implements ClassImplementsInterface {

    public function do_nothing(){}
}
<?php

namespace Tlf\Util\Test;

interface ClassImplementsInterface {

}
<?php

class ClassOnlyTest {

    public function do_nothing(){}
}
<?php

namespace Lia\Addon;

function abc(){
}

/**
 *
 * @see Router tests for good examples of output
 *
 * @note `$varDelim` is a string of characters used to separate dynamic portions of a url.
 * @note `$varDelim` is a global setting, but you can change it, add routes, change it, add routes, etc.
 * @note `pattern` refers to an unparsed url pattern like `/{category}/{blog_name}/`
 * @note added routers take a `\Lia\Obj\Request` object
 * @note route derivers accept `false` and return array of patterns or a `\Lia\Obj\Request` object
 * @note test patterns (or testReg) are simplified patterns with `?` in place of dynamic paramater names & are used internally
 * @note `$routeMap` contains all the info needed for selecting which route to use
 * @note optional paramaters (`/blog/{?optional}/`) only allow for one optional paramater
 *
 * @todo handleBlog(){} to respond to a request, routeBlog(){} to get an array of routes (which auto-point to handleBlog(){}))
 */
class Router extends \Lia\Addon implements \Lia\Http\ResponseInterface {

}
<?php

namespace Tlf\Util\Test;

class ClassWithNamespace {

    public function do_nothing(){}
}
<?php

namespace Tlf\Util\Test;

use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\Extension\CommonMark\Node\Block\FencedCode;
use League\CommonMark\Extension\CommonMark\Node\Block\IndentedCode;
use League\CommonMark\MarkdownConverter;
use Spatie\CommonMarkHighlighter\FencedCodeRenderer;
use Spatie\CommonMarkHighlighter\IndentedCodeRenderer;

class ClassWithUse {

    public function do_nothing(){}
}
<?php

namespace Lia\Addon;

/**
 *
 * @see Router tests for good examples of output
 *
 * @note `$varDelim` is a string of characters used to separate dynamic portions of a url.
 * @note `$varDelim` is a global setting, but you can change it, add routes, change it, add routes, etc.
 * @note `pattern` refers to an unparsed url pattern like `/{category}/{blog_name}/`
 * @note added routers take a `\Lia\Obj\Request` object
 * @note route derivers accept `false` and return array of patterns or a `\Lia\Obj\Request` object
 * @note test patterns (or testReg) are simplified patterns with `?` in place of dynamic paramater names & are used internally
 * @note `$routeMap` contains all the info needed for selecting which route to use
 * @note optional paramaters (`/blog/{?optional}/`) only allow for one optional paramater
 *
 * @todo handleBlog(){} to respond to a request, routeBlog(){} to get an array of routes (which auto-point to handleBlog(){}))
 */
class Router extends \Lia\Addon implements \Lia\Http\ResponseInterface {

}

<?php

namespace Lia\Addon;

/**
 *
 * @see Router tests for good examples of output
 *
 * @note `$routeMap` contains all the info needed for selecting which route to use
 * @note optional paramaters (`/blog/{?optional}/`) only allow for one optional paramater
 *
 * @todo handleBlog(){} to respond to a request, routeBlog(){} to get an array of routes (which auto-point to handleBlog(){}))
 */
class Router extends \Lia\Addon implements \Lia\Http\ResponseInterface {


    /**
     * Array of routers. Typically, one for each app
     */
    protected array $routers = [];

    /**
     * Setup routes for an app.
     *
     * @param $app
     * @param $value true to enable with default of 'public'. false to NOT enable. string to specify directory to use for route setup
     */
    public function onAppEnabled(\Lia\AppInterface $app, mixed $value){
        if ($value===true)$value = 'public';
        else if ($value===false)return;
        else if (!is_string($value)){
            $ns = $app->getNamespace();
            $class = get_class($app);
            $type = gettype($value);
            throw new \Exception("App '$ns' (class '$class') enabled addon 'lia:router', but provided an invalid value. The value MUST be a boolean or string, but a '$type' was provided. The value was '$value'");
        }

        // actually setup the routes

        $router = new \Lia\Src\Router();
        // @TODO configure params to pass to routes, on an app-by-app basis
        // @TODO configure varDelim, on an app-by-app basis
        $base_url = $app->hasConfig('router.base_url') ? $app->getConfig('router.base_url') : '/';
        $router->addDirectoryRoutes($app->getPath($value), $base_url);

        $this->routers[] = $router;
    }

    public function onGetHttpRoutes(\Lia\Http\Request $request): array {
        // @TODO consider hooking each Lia\Src\Router instance into GetHttpRoutes, instead of managing them within the addon.
    
        $route_list = [];
        /** @var $router \Lia\Src\Router */
        foreach ($this->routers as $router){
            $route_list[] = $router->getRoute($request);
        }

        return $route_list;
        
    }

    public function onAddonsLoaded(\Lia\AppInterface $app, array $addons){
        // @TODO maybe add a different callback for an addon to set itself up

        $app->getLia()->hook(\Lia\Events::GetHttpRoutes->value, [$this, 'onGetHttpRoutes']);
        $app->getLia()->hook(\Lia\Events::NoHttpRoutes->value, [$this, 'onNoHttpRoutes']);
        $app->getLia()->hook(\Lia\Events::NoHttpRoutes->value, [$this, 'onNoHttpRoutes']);
        $app->getLia()->hook(\Lia\Events::MultipleHttpRoutes->value, [$this, 'onNoSingleHttpRoute']);

    }

    /** do nothing */
    public function onRequestReady(\Lia\Http\Request $request){}

    /** Send a response */
    public function onNoHttpRoutes(\Lia\Http\Request $request){}

    /** 
     * Send a response 
     * @param $routes array<int index, \Lia\Http\Route $route> an array of Routes
     */
    public function onMultipleHttpRoutes(array $routes){

    }

    /**
     * Send a response
     * @param $route \Lia\Http\Route 
     */
    public function onSingleHttpRoute(\Lia\Http\Route $route){

    }

    /**
     * 
     * @param $request The request that is finished
     */
    public function onRequestFinished(\Lia\Http\Request $request){

    }


    /**
     * A string of characters that can be used as delimiters for dynamic url portions
     * @note this setting is global across all routes. You can circumvent this by using a second router addon
     */
    public $varDelim = '\\.\\/\\-\\:';
    // public $varDelim = '\\.\\/\\:';

    /**
     * @structure `['GET'=>['/test/?/pattern/'=>$decoded_pattern_array] ...]` 
     */
    public $routeMap = [];


    /**
     * Clean a url (without domain): replace space with '+', single quote with '%27', and replace multiple slashes with a single slash
     *
     * @param $dirty_url a url like `/some url///'with quotes'//`
     * @return a cleaned up url
     *
     * @example `/some url///'with quotes'//` returns `/some+url/%27with+quotes%27/`
     */
    public function clean_url($dirty_url){
        $dirty_url = str_replace(' ', '+', $dirty_url);
        $dirty_url = str_replace('\'', '%27', $dirty_url);
        $dirty_url = str_replace(['///','//'],'/',$dirty_url);
        return $dirty_url;
    }

    /**
     * This method is not tested at all. does not check dynamic routes.
     * @return true/false if the path has a route.
     */
    public function has_static_route(string $path,string $method="GET"):bool{
        return isset($this->routeMap[$method][$path]);
    }

    /**
     * Scan for files in the given directory & set each file up as a route.
     */
    public function addDirectoryRoutes(string $dir, string $base_url){

        $patterns = $this->dir_to_patterns($dir);
        foreach ($patterns as $file=>$pattern){
            $full_pattern = str_replace('//','/',$base_url.$pattern);


            // @TODO Setup router class to pass paramaters to routes (probably pass the same params to ALL routes within a given router)
            $this->addRoute($full_pattern,$dir.'/'.$file, null);
        }

    }


    /**
     * Add a route
     * 
     * @param $pattern A pattern. See decode_pattern()  documentation
     * @param $callbackOrFile a callback or a file path
     * @param $package (optional) A liaison package
     *
     */
    public function addRoute($pattern, $callbackOrFile,$package=null){
        $initialParsed = $this->decode_pattern($pattern);
        $list = $this->separate_optional_from_decoded_pattern($initialParsed);
        foreach ($list as $decoded){
            $decoded['target'] = $callbackOrFile;
            $decoded['package'] = $package;
            $testPattern = $decoded['parsedPattern'];
            $matches = [];
            foreach ($decoded['methods'] as $m){
                $this->routeMap[$m][$testPattern][] = $decoded;
            }            
        }
    }

    /**
     *  get a route for the given request
     *
     *  @todo write test for routing via added routers
     */
    public function getRoute(\Lia\HttpRequest $request){
        $url = $request->url();
        $method = $request->method();

        $testReg = $this->url_to_regex($url);
        $all = array_filter($this->routeMap[$method]??[],
            function($routeList,$decoded_pattern) use ($testReg) {
                if (preg_match('/'.$testReg.'/',$decoded_pattern))return true;
                return false;
            }
            ,ARRAY_FILTER_USE_BOTH);
        $routeList = [];
        sort($all);
        $all = array_merge(...$all);
        foreach ($all as $routeInfo){
            $active = [
                'url' => $url,
                'method'=>$method,
                'urlRegex'=>$testReg
            ];
            $paramaters = null;
            $paramaters = $this->extract_url_paramaters($routeInfo, $url);
            $optionalParamaters = $routeInfo['optionalParams']??[];
            $shared = [
                'paramaters'=>$paramaters,
                'optionalParamaters'=> $optionalParamaters,
            ];
            $static = [
                'allowedMethods'=>$routeInfo['methods'],
                'paramaterizedPattern'=>$routeInfo['pattern'],
                'placeholderPattern'=>$routeInfo['parsedPattern'],
                'target'=>$routeInfo['target'],
                'package'=>$routeInfo['package'],
            ];
            $route = new \Lia\Obj\Route(array_merge($active,$shared,$static));
            $routeList[] = $route;
        }
        return $routeList;
    }

    /**
     * Get an array of patterns from files in a directory.
     *
     * @return key=>value array, like `[rel_file_path=>pattern]` 
     */
    protected function dir_to_patterns($dir, $prefix=''){
        $files = \Lia\Utility\Files::all($dir,$dir);
        $patterns = [];
        foreach ($files as $f){
            $patterns[$f] = $prefix.$this->fileToPattern($f);
        }

        return $patterns;
    }

    /**
     * Convert a relative file path into a pattern
     *
     * @todo move file path => pattern conversion into router
     * @tag utility, routing
     */
    protected function fileToPattern($relFile){
        $pattern = $relFile;
        $ext = pathinfo($relFile,PATHINFO_EXTENSION);
        // $hidden = $this->props['route']['hidden_extensions'];
        $hidden = ['php'];
        if (in_array($ext,$hidden)){
            $pattern = substr($pattern,0,-(strlen($ext)+1));
            $ext = '';
        }

        // $indexNames = $this->props['route']['index_names'];
        $indexNames = ['index'];
        $base = basename($pattern);
        if (in_array($base,$indexNames)){
            $pattern = substr($pattern,0,-strlen($base));
        }

        // if ($ext==''
            // &&$this->config['route']['force_trail_slash'])$pattern .= '/';
        if ($ext==''
            &&true)$pattern .= '/';

        $pattern = str_replace(['///','//'], '/', $pattern);
        return $pattern;
    }



    /**
     * Facilitates optional paramaters
     *
     * Processes a parsed pattern into an array of valid parsed patterns where the original pattern may contain details for optional paramaters
     *
     * @return array of valid patterns (including the original)
     */
    protected function separate_optional_from_decoded_pattern($original_parsed){
        $clean_original = $original_parsed;
        unset($clean_original['extraParsedPattern']);
        unset($clean_original['optionalParams']);

        $list = [$clean_original];
        if (isset($original_parsed['extraParsedPattern'])){
            $next_parsed = $clean_original;
            $next_parsed['parsedPattern'] = $original_parsed['extraParsedPattern'];
            $params = $clean_original['params'];
            foreach ($original_parsed['optionalParams'] as $p){
                $index = array_search($p, $params);
                unset($params[$index]);
            }
            
            $params = array_values($params);
            $next_parsed['params'] = $params;
            $list[] = $next_parsed;
        }
        return $list;
    }

    /**
     *
     * Convert a pattern into a decoded array of information about that pattern
     *
    * The patterns apply both for the `public` dir and by adding routes via `$lia->addRoute()`. The file extension (for .php) is removed prior to calling decode_pattern()
    * The delimiters can be changed globally by setting $router->varDelims
    * 
    * ## Examples: 
    * - /blog/{category}/{post} is valid for url /blog/black-lives/matter
    * - /blog/{category}.{post}/ is valid for url /blog/environment.zero-waste/
    * - /blog/{category}{post}/ is valid for url /blog/{category}{post}/ and has NO dynamic paramaters
    * - /blog/{category}/@GET.{post}/ is valid for GET /blog/kindness/is-awesome/ but not for POST request
    * - /@POST.dir/sub/@GET.file/ is valid for both POST /dir/sub/file/ and GET /dir/sub/file/
    *
    * ## Methods: @POST, @GET, @PUT, @DELETE, @OPTIONS, @TRACE, @HEAD, @CONNECT
    * - We do not currently check the name of the method, just @ABCDEF for length 3-7
    * - These must appear after a `/` or after another '@METHOD.' or they will be taken literally
    * - lower case is not valid
    * - Each method MUST be followed by a period (.)
    * 
    * ## Paramaters:
    * - NEW: Dynamic portions may be separated by by (-) and/or (:) 
    * - {under_scoreCamel} specifies a named, dynamic paramater
    * - {param} must be surrounded by path delimiters (/) OR periods (.) which will be literal characters in the url
    * - {param} MAY be at the end of a pattern with no trailing delimiter
    *
    * ## TODO
    * - {paramName:regex} would specify a dynamic portion of a url that MUST match the given regex. 
    *     - Not currently implemented
    * - {?param} would specify a paramater that is optional
    *     - Not currently implemented
    *
    * @export(Router.PatternRules)
    */
    protected function decode_pattern($pattern){

        $dlm = $this->varDelim;

        $params = [];
        $optionalParams = [];
        $replace = 
        function($matches) use (&$params, &$optionalParams){
            if ($matches[1]=='?'){
                $params[] = $matches[2];
                $optionalParams[] = $matches[2];
                return '#';                
            }
            $params[] = $matches[2];
            return '?';
        };
        $pieces = explode('/',$pattern);
        $methods = [];
        $testUrl = '';
        $extraTestUrl = '';
        foreach ($pieces as $piece){
            $startPiece = $piece;
            // extract @METHODS.
            while (preg_match('/^\@([A-Z]{3,7})\./',$piece,$methodMatches)){
                $method = $methodMatches[1];
                $len = strlen($method);
                $piece = substr($piece,2+$len);
                $methods[$methodMatches[1]] = $methodMatches[1];
            } 
            while ($piece!=($piece = preg_replace_callback('/(?<=^|['.$dlm.'])\{(\??)([a-zA-Z\_]+)\}(?=['.$dlm.']|$)/',$replace,$piece))){
            }
            if ($piece=='#'&&$startPiece!=$piece){
                $extraTestUrl .= '';// don't add anything.
                $piece = '?';
            } else {
                $extraTestUrl .= '/'.$piece;
            }
            $testUrl .= '/'.$piece;
        }

        $testUrl = str_replace(['///','//'],'/',$testUrl);
        $extraTestUrl = str_replace(['///','//'],'/',$extraTestUrl);
        
        $decoded = [
            'pattern'=>$pattern,
            'parsedPattern'=>$testUrl,
            'params'=>$params,
            'methods'=>count($methods)>0 ? $methods : ['GET'=>'GET'],
        ];
        
        if ($testUrl!=$extraTestUrl){
            $decoded['extraParsedPattern']=$extraTestUrl;
            $decoded['optionalParams'] = $optionalParams;
        }
        return $decoded;
    }

    /**
     * Given a url and array of paramaters, 
     *
     * @param $decoded_pattern expects the array generated by decode_pattern(/url/pattern/)
     * @param $url 
     *
     * @return an array of paramaters expected by $decoded_pattern and found in $url
     */
    protected function extract_url_paramaters($decoded_pattern, $url){

        $phPattern = $decoded_pattern['parsedPattern'];
        $staticPieces = explode('?',$phPattern);
        $staticPieces = array_map(function($piece){return preg_quote($piece,'/');}, $staticPieces);
        $dlm = $this->varDelim;
        $reg = "([^{$dlm}].*)";
        $asReg = '/'.implode($reg, $staticPieces).'/';
        preg_match($asReg,$url,$matches);
        $params = [];
        $i=1;
        foreach ($decoded_pattern['params'] as $name){
            $params[$name] = $matches[$i++] ?? null;
            if ($params[$name]==null){
                echo "\n\nInternal Error. Please report a bug on https://github.com/Taeluf/Liaison/issues with the following:\n\n";
                echo "url: {$url}\nParsed Pattern:\n";
                print_r($decoded_pattern);
                echo "\n\n";
                throw new \Lia\Exception("Internal error. We were unable to perform routing for '{$url}'. ");
            }
        }

        return $params;
    }

    /**
     * convert an actual url into regex that can be used to match the test regs.
     *
     * @example `/one/two/` becomes `^\/(?:one|\?)\/(?:two|\?)\/$`
     */
    protected function url_to_regex($url){
        $url = str_replace('+', ' ',$url);
        $dlm = $this->varDelim;
        $pieces = preg_split('/['.$dlm.']/',$url);
        array_shift($pieces);
        $last = array_pop($pieces);
        if ($last!='')$pieces[] = $last;
        $reg = '';
        $pos = 0;

        $test = '';
        foreach ($pieces as $p){
            $len = strlen($p)+1;
            $startDelim = substr($url,$pos,1);
            if ($p==''){
                $test .= '\\'.$startDelim;
                $pos += $len;
                continue;
            }
            $pEsc = preg_quote($p,'/');
            $pReg = '\\'.$startDelim.'(?:'.$pEsc.'|\?)';

            $pos += $len;
            $test .= $pReg;
        }
        $finalDelim = substr($url,$pos);
        $test .= $finalDelim ? '\\'.$finalDelim : '';
        $test = '^'.$test.'$';
        return $test;
    }

    /** 
     * Get a url from a parsed pattern & array of values to fill
     *
     * @param $decoded see decode_pattern()
     * @param $withValues a `key=>value` array
     * @return the url with the paramaters inserted
     */ 
    protected function decoded_pattern_to_url(array $decoded, array $withValues): string{
        $sorted = [];
        foreach ($decoded['params'] as $index=>$param){
            $sorted[$index] = $withValues[$param];
        }
        $filledPattern = $decoded['parsedPattern'];
        $val = reset($sorted);
        while($pos = strpos($filledPattern,'?')){
            $filledPattern = substr($filledPattern,0,$pos)
                .$val
                .substr($filledPattern,$pos+1);
            $val = next($sorted);
        }
        
        return $filledPattern;
    }
}
<?php

namespace Tlf\Util\Test;

class ClassFinder extends \Tlf\Tester {

    public function testGetClassWithUse(){
        $file = $this->file('test/input/ClassWithUse.php');
        
        $actual_class = \Tlf\Util::getClassFromFile($file);

        $target_class = '\\Tlf\\Util\\Test\\ClassWithUse';

        $this->compare($target_class, $actual_class);

    }
    public function testClassOnly(){

        $file = $this->file('test/input/ClassOnlyTest.php');
        
        $actual_class = \Tlf\Util::getClassFromFile($file);

        $target_class = '\\ClassOnlyTest';

        $this->compare($target_class, $actual_class);
    }

    public function testClassWithNamespace(){

        $file = $this->file('test/input/ClassWithNamespace.php');
        
        $actual_class = \Tlf\Util::getClassFromFile($file);

        $target_class = '\\Tlf\\Util\\Test\\ClassWithNamespace';

        $this->compare($target_class, $actual_class);
    }

    public function testClassExtends(){

        $file = $this->file('test/input/ClassExtends.php');
        
        $actual_class = \Tlf\Util::getClassFromFile($file);

        $target_class = '\\Tlf\\Util\\Test\\ClassExtends';

        $this->compare($target_class, $actual_class);
    }


    public function testClassImplements(){
        $file = $this->file('test/input/ClassImplements.php');
        
        $actual_class = \Tlf\Util::getClassFromFile($file);

        $target_class = '\\Tlf\\Util\\Test\\ClassImplements';

        $this->compare($target_class, $actual_class);
    }
    
    public function testClassExtendsAndImplements(){
        $file = $this->file('test/input/ClassExtendsAndImplements.php');
        
        $actual_class = \Tlf\Util::getClassFromFile($file);

        $target_class = '\\Tlf\\Util\\Test\\ClassExtendsAndImplements';

        $this->compare($target_class, $actual_class);
    }

    public function testClassExtendsAndImplementsNoNamespace(){
        $file = $this->file('test/input/ClassExtendsAndImplementsNoNamespace.php');
        
        $actual_class = \Tlf\Util::getClassFromFile($file);

        $target_class = '\\ClassExtendsAndImplementsNoNamespace';

        $this->compare($target_class, $actual_class);
    }

    /**
     * A class in Liaison was failing. The docblock was very large, and the fread() approach was not getting enough of the file contents.
     * I tried debugging & fixing, but was unsuccessfull & switched to simple file_get_contents(), so the full file content is always loaded now, unfortunately.
     *
     * Either way, the bug is fixed.
     */
    public function testFailingClassOne(){
        $file = $this->file('test/input/FailingClassOne.php');
        
        $actual_class = \Tlf\Util::getClassFromFile($file);

        $target_class = '\\Lia\\Addon\\Router';

        $this->compare($target_class, $actual_class);
    }

    public function testVeryLargeClass(){
        $file = $this->file('test/input/VeryLargeClass.php');
        
        $actual_class = \Tlf\Util::getClassFromFile($file);

        $target_class = '\\Lia\\Addon\\Router';

        $this->compare($target_class, $actual_class);
    }

    /**
     *
     * @bug if there's a block defined before the class AND the class has a lot of text before the class is defined, it's very likely not enough of the file will be loaded into the buffer, so the class will not be detected. This will not be fixed until it's a problem for me personally, because I expect this to be very rare.
     */
    public function testClassWithFunctionBefore(){
        $this->disable();
        $file = $this->file('test/input/ClassWithFunctionBefore.php');
        
        $actual_class = \Tlf\Util::getClassFromFile($file);

        $target_class = '\\Lia\\Addon\\Router';

        $this->compare($target_class, $actual_class);
    }

    public function testFailingClassOneDebug(){
        $this->disable();
        return;
        echo "\n\nDEBUG WHAT THE HECK\n\n";
        $file = $this->file('test/input/FailingClassOne.php');


        $content = file_get_contents($file);
        $tokens = token_get_all($content);


        //print_r($tokens);
        
        //exit;
    }

}
<?php

namespace Tlf\Util\Test;

/**
 * Test CSRF Tokens
 */
class Csrf extends \Tlf\Tester {

    /**
     * Test that a POST fails if no CSRF token is passed.
     */
    public function testPostNoCsrf(){
        $bad_response = $this->post('/csrf-test-post.php', [],
        );
        echo $bad_response;

        $this->str_contains(
            $bad_response,
            'csrf post test not valid' 
        );

    }

    /**
     * @test that a request fails without a valid CSRF 
     * @test that a request succeeds with a valid CSRF
     */
    public function testValidateCsrf(){
        $response = $this->curl_post('/csrf-test.php');
        $content = $response['body'];
        $session_id = $response['cookies']['PHPSESSID']['value'];
        $csrf = json_decode($content, true);

        $bad_response = $this->curl_post('/csrf-test-post.php', [$csrf['key']=>null],
            $files=[],'backward_compat',
            [
               'REFERER: '.$this->cli->get_server_host(),
               'Cookie'=> 'PHPSESSID='.$session_id,
            ]
        );

        $this->str_contains(
            $bad_response['body'],
            'csrf post test not valid'
        );
        echo "\n\nInvalid Response:\n".$bad_response['body'];

        $good_response = $this->curl_post('/csrf-test-post.php', [$csrf['key']=>$csrf['code']],
            $files=[],'backward_compat',
            [
               'REFERER: '.$this->cli->get_server_host(),
               'Cookie'=> 'PHPSESSID='.$session_id,
            ]
        );

        $this->str_contains($good_response['body'],
            'csrf post test success'
        );

        echo "\n\nGood Response:\n".$good_response['body'];
    }

    /**
     * Test that a csrf code is successfully generated on the server
     */
    public function testGenCsrf(){
        $content = $this->get('/csrf-test.php');
        $csrf = json_decode($content, true);

        $this->is_string($csrf['code']);
        $this->is_true($csrf['expires_at'] > time());
        $this->is_true($csrf['expires_at'] < time() + 60 * 10 + 1);
        $this->compare($csrf['uri'], '/csrf-test-post.php');

    }

}
<?php

namespace Tlf\Util\Test;

/**
 * Test honeypots and full spam control
 */
class FormSpam extends \Tlf\Tester {

    public function testFormSpam(){
        $address = $this->get_server();
        $output = ob_end_clean();
        echo "\n\nVisit $address/spam-form.php";
        echo "\nWhen you submit the form, does it respond with 'submission valid'?";
        $answer = readline("Answer y/n/s-skip");


        ob_start();
        echo $output;


        if ($answer =='s'){
            $this->disable();
            return;
        } else if ($answer=='y')$this->handleDidPass(true);
        else $this->handleDidPass(false);

    }

    public function testSubmitWithCsrfOnly(){
        $response = $this->curl_post('/spam-form.php');
        $content = $response['body'];
        $session_id = $response['cookies']['PHPSESSID']['value'];
        // $csrf = json_decode($content, true);
//
        // var_dump($response);
        // exit;
        // $phtml = new \Taeluf\PHTML('<html>'.$content.'</html>');
        $phtml = new \Taeluf\PHTML($content);
        $key_node = $phtml->xpath('//input[@name="csrf_key"]')[0];
        $key = $key_node->value;
        $value_node = $phtml->xpath('//input[@name="'.$key.'"]')[0];
        $code = $value_node->value;
        

        $bad_response = $this->curl_post('/spam-post.php', [$key=>null],
            $files=[],'backward_compat',
            [
               'REFERER: '.$this->cli->get_server_host(),
               'Cookie'=> 'PHPSESSID='.$session_id,
            ]
        );

        $this->str_contains(
            $bad_response['body'],
            'submission NOT valid'
        );
        // echo "\n\nInvalid Response:\n".$bad_response['body'];

        $good_response = $this->curl_post('/spam-post.php', [$key=>$code],
            $files=[],'backward_compat',
            [
               'REFERER: '.$this->cli->get_server_host(),
               'Cookie'=> 'PHPSESSID='.$session_id,
            ]
        );

        $this->str_contains($good_response['body'],
            'submission NOT valid'
        );

        // echo "\n\nGood Response:\n".$good_response['body'];
    }

    public function testSubmitWithoutHoneyOrCsrf(){
        // $form = $this->get('/honey-form.php');
        $response = $this->post("/spam-post.php");
        $this->compare('submission NOT valid', $response);
    }
}
<?php

namespace Tlf\Util\Test;

/**
 * Test honeypots and full spam control
 */
class Honeypot extends \Tlf\Tester {

    public function testSubmitWithProperHoney(){
        $address = $this->get_server();
        $output = ob_end_clean();
        echo "\n\nVisit $address/honey-form.php";
        echo "\nWhen you submit the form, does it respond with 'honey post test success'?";
        $answer = readline("Answer y/n/s-skip");


        ob_start();
        echo $output;


        if ($answer =='s'){
            $this->disable();
            return;
        } else if ($answer=='y')$this->handleDidPass(true);
        else $this->handleDidPass(false);

    }

    public function testSubmitWithoutHoney(){
        // $form = $this->get('/honey-form.php');
        $response = $this->post("/honey-post.php");
        $this->compare('honey post test not valid', $response);
    }
    public function testGetHoney(){
        $content = $this->get('/honey-form.php');

        echo $content;

        $this->str_contains($content, 
            '<input type="text"',
            '<input type="hidden"',
            'Please type <b>',
            ' into here, or enable javascript:',
        );

    }

}
<?php

namespace Tlf\Tester;

class SampleTester extends \Tlf\Tester {

    // then your classes can extend from SampleTester if you want to share some convenience methods between different test classes 
}
�'�5����Rcq�����M��'����%OGBMB