From 398aac21e75e33af3b3dab5dde798552dd262d56 Mon Sep 17 00:00:00 2001 From: Brady Miller Date: Fri, 18 Aug 2017 22:56:32 -0700 Subject: [PATCH] added knp-snappy package for Jerry's UB04 work --- build.xml | 1 + composer.json | 3 +- composer.lock | 116 +- vendor/composer/ClassLoader.php | 10 +- vendor/composer/LICENSE | 2 +- vendor/composer/autoload_classmap.php | 22 + vendor/composer/autoload_psr4.php | 2 + vendor/composer/autoload_static.php | 35 + vendor/composer/installed.json | 118 ++ vendor/knplabs/knp-snappy/CONTRIBUTING.md | 11 + vendor/{composer => knplabs/knp-snappy}/LICENSE | 6 +- vendor/knplabs/knp-snappy/README.md | 116 ++ vendor/knplabs/knp-snappy/composer.json | 42 + vendor/knplabs/knp-snappy/doc/faq.md | 68 + .../src/Knp/Snappy/AbstractGenerator.php | 644 ++++++++ .../Exception/FileAlreadyExistsException.php | 5 + .../src/Knp/Snappy/GeneratorInterface.php | 55 + vendor/knplabs/knp-snappy/src/Knp/Snappy/Image.php | 82 + vendor/knplabs/knp-snappy/src/Knp/Snappy/Pdf.php | 220 +++ vendor/symfony/process/CHANGELOG.md | 51 + .../process/Exception/ExceptionInterface.php | 21 + .../process/Exception/InvalidArgumentException.php | 21 + .../symfony/process/Exception/LogicException.php | 21 + .../process/Exception/ProcessFailedException.php | 54 + .../process/Exception/ProcessTimedOutException.php | 69 + .../symfony/process/Exception/RuntimeException.php | 21 + vendor/symfony/process/ExecutableFinder.php | 90 + vendor/symfony/process/InputStream.php | 90 + vendor/{composer => symfony/process}/LICENSE | 4 +- vendor/symfony/process/PhpExecutableFinder.php | 90 + vendor/symfony/process/PhpProcess.php | 78 + vendor/symfony/process/Pipes/AbstractPipes.php | 169 ++ vendor/symfony/process/Pipes/PipesInterface.php | 67 + vendor/symfony/process/Pipes/UnixPipes.php | 153 ++ vendor/symfony/process/Pipes/WindowsPipes.php | 200 +++ vendor/symfony/process/Process.php | 1735 ++++++++++++++++++++ vendor/symfony/process/ProcessBuilder.php | 288 ++++ vendor/symfony/process/ProcessUtils.php | 123 ++ vendor/symfony/process/README.md | 13 + vendor/symfony/process/composer.json | 33 + vendor/symfony/process/phpunit.xml.dist | 30 + 41 files changed, 4967 insertions(+), 12 deletions(-) create mode 100644 vendor/knplabs/knp-snappy/CONTRIBUTING.md copy vendor/{composer => knplabs/knp-snappy}/LICENSE (93%) create mode 100644 vendor/knplabs/knp-snappy/README.md create mode 100644 vendor/knplabs/knp-snappy/composer.json create mode 100644 vendor/knplabs/knp-snappy/doc/faq.md create mode 100644 vendor/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php create mode 100644 vendor/knplabs/knp-snappy/src/Knp/Snappy/Exception/FileAlreadyExistsException.php create mode 100644 vendor/knplabs/knp-snappy/src/Knp/Snappy/GeneratorInterface.php create mode 100644 vendor/knplabs/knp-snappy/src/Knp/Snappy/Image.php create mode 100644 vendor/knplabs/knp-snappy/src/Knp/Snappy/Pdf.php create mode 100644 vendor/symfony/process/CHANGELOG.md create mode 100644 vendor/symfony/process/Exception/ExceptionInterface.php create mode 100644 vendor/symfony/process/Exception/InvalidArgumentException.php create mode 100644 vendor/symfony/process/Exception/LogicException.php create mode 100644 vendor/symfony/process/Exception/ProcessFailedException.php create mode 100644 vendor/symfony/process/Exception/ProcessTimedOutException.php create mode 100644 vendor/symfony/process/Exception/RuntimeException.php create mode 100644 vendor/symfony/process/ExecutableFinder.php create mode 100644 vendor/symfony/process/InputStream.php copy vendor/{composer => symfony/process}/LICENSE (95%) create mode 100644 vendor/symfony/process/PhpExecutableFinder.php create mode 100644 vendor/symfony/process/PhpProcess.php create mode 100644 vendor/symfony/process/Pipes/AbstractPipes.php create mode 100644 vendor/symfony/process/Pipes/PipesInterface.php create mode 100644 vendor/symfony/process/Pipes/UnixPipes.php create mode 100644 vendor/symfony/process/Pipes/WindowsPipes.php create mode 100644 vendor/symfony/process/Process.php create mode 100644 vendor/symfony/process/ProcessBuilder.php create mode 100644 vendor/symfony/process/ProcessUtils.php create mode 100644 vendor/symfony/process/README.md create mode 100644 vendor/symfony/process/composer.json create mode 100644 vendor/symfony/process/phpunit.xml.dist diff --git a/build.xml b/build.xml index 9bb9e7b0a..b214720df 100644 --- a/build.xml +++ b/build.xml @@ -60,6 +60,7 @@ + diff --git a/composer.json b/composer.json index fe9ba1096..ae1850b6f 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,8 @@ "symfony/http-foundation": "2.8.*", "symfony/yaml": "2.8.*", "phpoffice/phpexcel": "1.8.1", - "ezyang/htmlpurifier": "4.9.3" + "ezyang/htmlpurifier": "4.9.3", + "knplabs/knp-snappy" : "^0.5.0" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 770c4717d..5b7d13724 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "9d131b3202760ebf0b9320b4782f9816", + "content-hash": "76ffa694ffb0b09b5f5d2c1b402d0e20", "packages": [ { "name": "adldap2/adldap2", @@ -1013,6 +1013,71 @@ "time": "2014-11-20T16:49:30+00:00" }, { + "name": "knplabs/knp-snappy", + "version": "v0.5.0", + "source": { + "type": "git", + "url": "https://github.com/KnpLabs/snappy.git", + "reference": "370da31fa92a8e583e34558c589e630647617a38" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/KnpLabs/snappy/zipball/370da31fa92a8e583e34558c589e630647617a38", + "reference": "370da31fa92a8e583e34558c589e630647617a38", + "shasum": "" + }, + "require": { + "php": ">=5.6", + "symfony/process": "~2.3|~3.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.7" + }, + "suggest": { + "h4cc/wkhtmltoimage-amd64": "Provides wkhtmltoimage-amd64 binary for Linux-compatible machines, use version `~0.12` as dependency", + "h4cc/wkhtmltoimage-i386": "Provides wkhtmltoimage-i386 binary for Linux-compatible machines, use version `~0.12` as dependency", + "h4cc/wkhtmltopdf-amd64": "Provides wkhtmltopdf-amd64 binary for Linux-compatible machines, use version `~0.12` as dependency", + "h4cc/wkhtmltopdf-i386": "Provides wkhtmltopdf-i386 binary for Linux-compatible machines, use version `~0.12` as dependency", + "wemersonjanuario/wkhtmltopdf-windows": "Provides wkhtmltopdf executable for Windows, use version `~0.12` as dependency" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.5.x-dev" + } + }, + "autoload": { + "psr-4": { + "Knp\\Snappy\\": "src/Knp/Snappy" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "KnpLabs Team", + "homepage": "http://knplabs.com" + }, + { + "name": "Symfony Community", + "homepage": "http://github.com/KnpLabs/snappy/contributors" + } + ], + "description": "PHP5 library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage.", + "homepage": "http://github.com/KnpLabs/snappy", + "keywords": [ + "knp", + "knplabs", + "pdf", + "snapshot", + "thumbnail", + "wkhtmltopdf" + ], + "time": "2017-06-16T07:50:40+00:00" + }, + { "name": "mpdf/mpdf", "version": "v6.1.3", "source": { @@ -2260,6 +2325,55 @@ "time": "2017-06-09T08:25:21+00:00" }, { + "name": "symfony/process", + "version": "v3.3.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/process.git", + "reference": "07432804942b9f6dd7b7377faf9920af5f95d70a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/process/zipball/07432804942b9f6dd7b7377faf9920af5f95d70a", + "reference": "07432804942b9f6dd7b7377faf9920af5f95d70a", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Process\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "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", + "time": "2017-07-13T13:05:09+00:00" + }, + { "name": "symfony/yaml", "version": "v2.8.24", "source": { diff --git a/vendor/composer/ClassLoader.php b/vendor/composer/ClassLoader.php index 4626994fd..2c72175e7 100644 --- a/vendor/composer/ClassLoader.php +++ b/vendor/composer/ClassLoader.php @@ -374,9 +374,13 @@ class ClassLoader $first = $class[0]; if (isset($this->prefixLengthsPsr4[$first])) { - foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { - if (0 === strpos($class, $prefix)) { - foreach ($this->prefixDirsPsr4[$prefix] as $dir) { + $subPath = $class; + while (false !== $lastPos = strrpos($subPath, '\\')) { + $subPath = substr($subPath, 0, $lastPos); + $search = $subPath.'\\'; + if (isset($this->prefixDirsPsr4[$search])) { + foreach ($this->prefixDirsPsr4[$search] as $dir) { + $length = $this->prefixLengthsPsr4[$first][$search]; if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { return $file; } diff --git a/vendor/composer/LICENSE b/vendor/composer/LICENSE index 1a2812488..f27399a04 100644 --- a/vendor/composer/LICENSE +++ b/vendor/composer/LICENSE @@ -1,5 +1,5 @@ -Copyright (c) 2016 Nils Adermann, Jordi Boggiano +Copyright (c) Nils Adermann, Jordi Boggiano Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index e50bd9357..f8b11fb12 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -1331,6 +1331,11 @@ return array( 'Installer' => $baseDir . '/library/classes/Installer.class.php', 'InsuranceCompany' => $baseDir . '/library/classes/InsuranceCompany.class.php', 'InsuranceNumbers' => $baseDir . '/library/classes/InsuranceNumbers.class.php', + 'Knp\\Snappy\\AbstractGenerator' => $vendorDir . '/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php', + 'Knp\\Snappy\\Exception\\FileAlreadyExistsException' => $vendorDir . '/knplabs/knp-snappy/src/Knp/Snappy/Exception/FileAlreadyExistsException.php', + 'Knp\\Snappy\\GeneratorInterface' => $vendorDir . '/knplabs/knp-snappy/src/Knp/Snappy/GeneratorInterface.php', + 'Knp\\Snappy\\Image' => $vendorDir . '/knplabs/knp-snappy/src/Knp/Snappy/Image.php', + 'Knp\\Snappy\\Pdf' => $vendorDir . '/knplabs/knp-snappy/src/Knp/Snappy/Pdf.php', 'MYANMAR' => $vendorDir . '/mpdf/mpdf/classes/myanmar.php', 'MyMailer' => $baseDir . '/library/classes/postmaster.php', 'Note' => $baseDir . '/library/classes/Note.class.php', @@ -1924,6 +1929,23 @@ return array( 'Symfony\\Component\\HttpFoundation\\Session\\Storage\\Proxy\\SessionHandlerProxy' => $vendorDir . '/symfony/http-foundation/Session/Storage/Proxy/SessionHandlerProxy.php', 'Symfony\\Component\\HttpFoundation\\Session\\Storage\\SessionStorageInterface' => $vendorDir . '/symfony/http-foundation/Session/Storage/SessionStorageInterface.php', 'Symfony\\Component\\HttpFoundation\\StreamedResponse' => $vendorDir . '/symfony/http-foundation/StreamedResponse.php', + 'Symfony\\Component\\Process\\Exception\\ExceptionInterface' => $vendorDir . '/symfony/process/Exception/ExceptionInterface.php', + 'Symfony\\Component\\Process\\Exception\\InvalidArgumentException' => $vendorDir . '/symfony/process/Exception/InvalidArgumentException.php', + 'Symfony\\Component\\Process\\Exception\\LogicException' => $vendorDir . '/symfony/process/Exception/LogicException.php', + 'Symfony\\Component\\Process\\Exception\\ProcessFailedException' => $vendorDir . '/symfony/process/Exception/ProcessFailedException.php', + 'Symfony\\Component\\Process\\Exception\\ProcessTimedOutException' => $vendorDir . '/symfony/process/Exception/ProcessTimedOutException.php', + 'Symfony\\Component\\Process\\Exception\\RuntimeException' => $vendorDir . '/symfony/process/Exception/RuntimeException.php', + 'Symfony\\Component\\Process\\ExecutableFinder' => $vendorDir . '/symfony/process/ExecutableFinder.php', + 'Symfony\\Component\\Process\\InputStream' => $vendorDir . '/symfony/process/InputStream.php', + 'Symfony\\Component\\Process\\PhpExecutableFinder' => $vendorDir . '/symfony/process/PhpExecutableFinder.php', + 'Symfony\\Component\\Process\\PhpProcess' => $vendorDir . '/symfony/process/PhpProcess.php', + 'Symfony\\Component\\Process\\Pipes\\AbstractPipes' => $vendorDir . '/symfony/process/Pipes/AbstractPipes.php', + 'Symfony\\Component\\Process\\Pipes\\PipesInterface' => $vendorDir . '/symfony/process/Pipes/PipesInterface.php', + 'Symfony\\Component\\Process\\Pipes\\UnixPipes' => $vendorDir . '/symfony/process/Pipes/UnixPipes.php', + 'Symfony\\Component\\Process\\Pipes\\WindowsPipes' => $vendorDir . '/symfony/process/Pipes/WindowsPipes.php', + 'Symfony\\Component\\Process\\Process' => $vendorDir . '/symfony/process/Process.php', + 'Symfony\\Component\\Process\\ProcessBuilder' => $vendorDir . '/symfony/process/ProcessBuilder.php', + 'Symfony\\Component\\Process\\ProcessUtils' => $vendorDir . '/symfony/process/ProcessUtils.php', 'Symfony\\Component\\Yaml\\Dumper' => $vendorDir . '/symfony/yaml/Dumper.php', 'Symfony\\Component\\Yaml\\Escaper' => $vendorDir . '/symfony/yaml/Escaper.php', 'Symfony\\Component\\Yaml\\Exception\\DumpException' => $vendorDir . '/symfony/yaml/Exception/DumpException.php', diff --git a/vendor/composer/autoload_psr4.php b/vendor/composer/autoload_psr4.php index d68617793..9ee43e9f1 100644 --- a/vendor/composer/autoload_psr4.php +++ b/vendor/composer/autoload_psr4.php @@ -20,6 +20,7 @@ return array( 'Symfony\\Polyfill\\Php54\\' => array($vendorDir . '/symfony/polyfill-php54'), 'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'), 'Symfony\\Component\\Yaml\\' => array($vendorDir . '/symfony/yaml'), + 'Symfony\\Component\\Process\\' => array($vendorDir . '/symfony/process'), 'Symfony\\Component\\HttpFoundation\\' => array($vendorDir . '/symfony/http-foundation'), 'Symfony\\Component\\Filesystem\\' => array($vendorDir . '/symfony/filesystem'), 'Symfony\\Component\\EventDispatcher\\' => array($vendorDir . '/symfony/event-dispatcher'), @@ -36,6 +37,7 @@ return array( 'OpenEMR\\Calendar\\' => array($baseDir . '/library/calendar/src'), 'OpenEMR\\Billing\\' => array($baseDir . '/library/billing/src'), 'OpenEMR\\Admin\\' => array($baseDir . '/library/admin/src'), + 'Knp\\Snappy\\' => array($vendorDir . '/knplabs/knp-snappy/src/Knp/Snappy'), 'Illuminate\\Support\\' => array($vendorDir . '/illuminate/support'), 'Illuminate\\Contracts\\' => array($vendorDir . '/illuminate/contracts'), 'Dotenv\\' => array($vendorDir . '/vlucas/phpdotenv/src'), diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 15b80008f..f84724cd2 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -62,6 +62,7 @@ class ComposerStaticInit22ddb69348c7ed922c96325249cef3d0 'Symfony\\Polyfill\\Php54\\' => 23, 'Symfony\\Polyfill\\Mbstring\\' => 26, 'Symfony\\Component\\Yaml\\' => 23, + 'Symfony\\Component\\Process\\' => 26, 'Symfony\\Component\\HttpFoundation\\' => 33, 'Symfony\\Component\\Filesystem\\' => 29, 'Symfony\\Component\\EventDispatcher\\' => 34, @@ -85,6 +86,10 @@ class ComposerStaticInit22ddb69348c7ed922c96325249cef3d0 'OpenEMR\\Billing\\' => 16, 'OpenEMR\\Admin\\' => 14, ), + 'K' => + array ( + 'Knp\\Snappy\\' => 11, + ), 'I' => array ( 'Illuminate\\Support\\' => 19, @@ -161,6 +166,10 @@ class ComposerStaticInit22ddb69348c7ed922c96325249cef3d0 array ( 0 => __DIR__ . '/..' . '/symfony/yaml', ), + 'Symfony\\Component\\Process\\' => + array ( + 0 => __DIR__ . '/..' . '/symfony/process', + ), 'Symfony\\Component\\HttpFoundation\\' => array ( 0 => __DIR__ . '/..' . '/symfony/http-foundation', @@ -225,6 +234,10 @@ class ComposerStaticInit22ddb69348c7ed922c96325249cef3d0 array ( 0 => __DIR__ . '/../..' . '/library/admin/src', ), + 'Knp\\Snappy\\' => + array ( + 0 => __DIR__ . '/..' . '/knplabs/knp-snappy/src/Knp/Snappy', + ), 'Illuminate\\Support\\' => array ( 0 => __DIR__ . '/..' . '/illuminate/support', @@ -1661,6 +1674,11 @@ class ComposerStaticInit22ddb69348c7ed922c96325249cef3d0 'Installer' => __DIR__ . '/../..' . '/library/classes/Installer.class.php', 'InsuranceCompany' => __DIR__ . '/../..' . '/library/classes/InsuranceCompany.class.php', 'InsuranceNumbers' => __DIR__ . '/../..' . '/library/classes/InsuranceNumbers.class.php', + 'Knp\\Snappy\\AbstractGenerator' => __DIR__ . '/..' . '/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php', + 'Knp\\Snappy\\Exception\\FileAlreadyExistsException' => __DIR__ . '/..' . '/knplabs/knp-snappy/src/Knp/Snappy/Exception/FileAlreadyExistsException.php', + 'Knp\\Snappy\\GeneratorInterface' => __DIR__ . '/..' . '/knplabs/knp-snappy/src/Knp/Snappy/GeneratorInterface.php', + 'Knp\\Snappy\\Image' => __DIR__ . '/..' . '/knplabs/knp-snappy/src/Knp/Snappy/Image.php', + 'Knp\\Snappy\\Pdf' => __DIR__ . '/..' . '/knplabs/knp-snappy/src/Knp/Snappy/Pdf.php', 'MYANMAR' => __DIR__ . '/..' . '/mpdf/mpdf/classes/myanmar.php', 'MyMailer' => __DIR__ . '/../..' . '/library/classes/postmaster.php', 'Note' => __DIR__ . '/../..' . '/library/classes/Note.class.php', @@ -2254,6 +2272,23 @@ class ComposerStaticInit22ddb69348c7ed922c96325249cef3d0 'Symfony\\Component\\HttpFoundation\\Session\\Storage\\Proxy\\SessionHandlerProxy' => __DIR__ . '/..' . '/symfony/http-foundation/Session/Storage/Proxy/SessionHandlerProxy.php', 'Symfony\\Component\\HttpFoundation\\Session\\Storage\\SessionStorageInterface' => __DIR__ . '/..' . '/symfony/http-foundation/Session/Storage/SessionStorageInterface.php', 'Symfony\\Component\\HttpFoundation\\StreamedResponse' => __DIR__ . '/..' . '/symfony/http-foundation/StreamedResponse.php', + 'Symfony\\Component\\Process\\Exception\\ExceptionInterface' => __DIR__ . '/..' . '/symfony/process/Exception/ExceptionInterface.php', + 'Symfony\\Component\\Process\\Exception\\InvalidArgumentException' => __DIR__ . '/..' . '/symfony/process/Exception/InvalidArgumentException.php', + 'Symfony\\Component\\Process\\Exception\\LogicException' => __DIR__ . '/..' . '/symfony/process/Exception/LogicException.php', + 'Symfony\\Component\\Process\\Exception\\ProcessFailedException' => __DIR__ . '/..' . '/symfony/process/Exception/ProcessFailedException.php', + 'Symfony\\Component\\Process\\Exception\\ProcessTimedOutException' => __DIR__ . '/..' . '/symfony/process/Exception/ProcessTimedOutException.php', + 'Symfony\\Component\\Process\\Exception\\RuntimeException' => __DIR__ . '/..' . '/symfony/process/Exception/RuntimeException.php', + 'Symfony\\Component\\Process\\ExecutableFinder' => __DIR__ . '/..' . '/symfony/process/ExecutableFinder.php', + 'Symfony\\Component\\Process\\InputStream' => __DIR__ . '/..' . '/symfony/process/InputStream.php', + 'Symfony\\Component\\Process\\PhpExecutableFinder' => __DIR__ . '/..' . '/symfony/process/PhpExecutableFinder.php', + 'Symfony\\Component\\Process\\PhpProcess' => __DIR__ . '/..' . '/symfony/process/PhpProcess.php', + 'Symfony\\Component\\Process\\Pipes\\AbstractPipes' => __DIR__ . '/..' . '/symfony/process/Pipes/AbstractPipes.php', + 'Symfony\\Component\\Process\\Pipes\\PipesInterface' => __DIR__ . '/..' . '/symfony/process/Pipes/PipesInterface.php', + 'Symfony\\Component\\Process\\Pipes\\UnixPipes' => __DIR__ . '/..' . '/symfony/process/Pipes/UnixPipes.php', + 'Symfony\\Component\\Process\\Pipes\\WindowsPipes' => __DIR__ . '/..' . '/symfony/process/Pipes/WindowsPipes.php', + 'Symfony\\Component\\Process\\Process' => __DIR__ . '/..' . '/symfony/process/Process.php', + 'Symfony\\Component\\Process\\ProcessBuilder' => __DIR__ . '/..' . '/symfony/process/ProcessBuilder.php', + 'Symfony\\Component\\Process\\ProcessUtils' => __DIR__ . '/..' . '/symfony/process/ProcessUtils.php', 'Symfony\\Component\\Yaml\\Dumper' => __DIR__ . '/..' . '/symfony/yaml/Dumper.php', 'Symfony\\Component\\Yaml\\Escaper' => __DIR__ . '/..' . '/symfony/yaml/Escaper.php', 'Symfony\\Component\\Yaml\\Exception\\DumpException' => __DIR__ . '/..' . '/symfony/yaml/Exception/DumpException.php', diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index ca2495b8e..19c11c578 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -2571,6 +2571,124 @@ ] }, { + "name": "symfony/process", + "version": "v3.3.6", + "version_normalized": "3.3.6.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/process.git", + "reference": "07432804942b9f6dd7b7377faf9920af5f95d70a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/process/zipball/07432804942b9f6dd7b7377faf9920af5f95d70a", + "reference": "07432804942b9f6dd7b7377faf9920af5f95d70a", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "time": "2017-07-13T13:05:09+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.3-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Symfony\\Component\\Process\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "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" + }, + { + "name": "knplabs/knp-snappy", + "version": "v0.5.0", + "version_normalized": "0.5.0.0", + "source": { + "type": "git", + "url": "https://github.com/KnpLabs/snappy.git", + "reference": "370da31fa92a8e583e34558c589e630647617a38" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/KnpLabs/snappy/zipball/370da31fa92a8e583e34558c589e630647617a38", + "reference": "370da31fa92a8e583e34558c589e630647617a38", + "shasum": "" + }, + "require": { + "php": ">=5.6", + "symfony/process": "~2.3|~3.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.7" + }, + "suggest": { + "h4cc/wkhtmltoimage-amd64": "Provides wkhtmltoimage-amd64 binary for Linux-compatible machines, use version `~0.12` as dependency", + "h4cc/wkhtmltoimage-i386": "Provides wkhtmltoimage-i386 binary for Linux-compatible machines, use version `~0.12` as dependency", + "h4cc/wkhtmltopdf-amd64": "Provides wkhtmltopdf-amd64 binary for Linux-compatible machines, use version `~0.12` as dependency", + "h4cc/wkhtmltopdf-i386": "Provides wkhtmltopdf-i386 binary for Linux-compatible machines, use version `~0.12` as dependency", + "wemersonjanuario/wkhtmltopdf-windows": "Provides wkhtmltopdf executable for Windows, use version `~0.12` as dependency" + }, + "time": "2017-06-16T07:50:40+00:00", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.5.x-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-4": { + "Knp\\Snappy\\": "src/Knp/Snappy" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "KnpLabs Team", + "homepage": "http://knplabs.com" + }, + { + "name": "Symfony Community", + "homepage": "http://github.com/KnpLabs/snappy/contributors" + } + ], + "description": "PHP5 library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage.", + "homepage": "http://github.com/KnpLabs/snappy", + "keywords": [ + "knp", + "knplabs", + "pdf", + "snapshot", + "thumbnail", + "wkhtmltopdf" + ] + }, + { "name": "phing/phing", "version": "2.14.0", "version_normalized": "2.14.0.0", diff --git a/vendor/knplabs/knp-snappy/CONTRIBUTING.md b/vendor/knplabs/knp-snappy/CONTRIBUTING.md new file mode 100644 index 000000000..2de5b2052 --- /dev/null +++ b/vendor/knplabs/knp-snappy/CONTRIBUTING.md @@ -0,0 +1,11 @@ + +# Thanks for contributing! + + +## Before adding issues + +Please verify the problem is actually a snappy problem and not a **wkhtmltopdf problem**. + +To do so, simply copy paste the command displayed in the error message in your command prompt. +If the same error appears on the command line, then it's a wkhtmltopdf problem, +and you'll have more chance to resolve your issue [there](https://github.com/wkhtmltopdf/wkhtmltopdf/issues). diff --git a/vendor/composer/LICENSE b/vendor/knplabs/knp-snappy/LICENSE similarity index 93% copy from vendor/composer/LICENSE copy to vendor/knplabs/knp-snappy/LICENSE index 1a2812488..cbdf8a91e 100644 --- a/vendor/composer/LICENSE +++ b/vendor/knplabs/knp-snappy/LICENSE @@ -1,5 +1,6 @@ +The MIT License -Copyright (c) 2016 Nils Adermann, Jordi Boggiano +Copyright (c) 2010 Matthieu Bontemps Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -17,5 +18,4 @@ 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. - +THE SOFTWARE. \ No newline at end of file diff --git a/vendor/knplabs/knp-snappy/README.md b/vendor/knplabs/knp-snappy/README.md new file mode 100644 index 000000000..d1a1b6cd0 --- /dev/null +++ b/vendor/knplabs/knp-snappy/README.md @@ -0,0 +1,116 @@ +# Snappy + +Snappy is a PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. +It uses the excellent webkit-based [wkhtmltopdf and wkhtmltoimage](http://wkhtmltopdf.org/) +available on OSX, linux, windows. + +You will have to download wkhtmltopdf `0.12.x` in order to use Snappy. + +Please, check [FAQ](doc/faq.md) before opening a new issue. Snappy is a tiny wrapper around wkhtmltox, so lots of issues are already answered, resolved or wkhtmltox ones. + +[![Build Status](https://secure.travis-ci.org/KnpLabs/snappy.png?branch=master)](http://travis-ci.org/KnpLabs/snappy) + +## Installation using [Composer](http://getcomposer.org/) + +```bash +$ composer require knplabs/knp-snappy +``` + +## Usage + +```php +setBinary('/usr/local/bin/wkhtmltopdf'); + +// Display the resulting pdf in the browser +// by setting the Content-type header to pdf +$snappy = new Pdf('/usr/local/bin/wkhtmltopdf'); +header('Content-Type: application/pdf'); +header('Content-Disposition: attachment; filename="file.pdf"'); +echo $snappy->getOutput('http://www.github.com'); + +// Merge multiple urls into one pdf +// by sending an array of urls to getOutput() +$snappy = new Pdf('/usr/local/bin/wkhtmltopdf'); +header('Content-Type: application/pdf'); +header('Content-Disposition: attachment; filename="file.pdf"'); +echo $snappy->getOutput(array('http://www.github.com','http://www.knplabs.com','http://www.php.net')); + +// .. or simply save the PDF to a file +$snappy = new Pdf('/usr/local/bin/wkhtmltopdf'); +$snappy->generateFromHtml('

Bill

You owe me money, dude.

', '/tmp/bill-123.pdf'); + +// Pass options to snappy +// Type wkhtmltopdf -H to see the list of options +$snappy = new Pdf('/usr/local/bin/wkhtmltopdf'); +$snappy->setOption('disable-javascript', true); +$snappy->setOption('no-background', true); +$snappy->setOption('allow', array('/path1', '/path2')); +$snappy->setOption('cookie', array('key' => 'value', 'key2' => 'value2')); +$snappy->setOption('post', array('key' => 'value')); +$snappy->setOption('cover', 'pathToCover.html'); +// .. or pass a cover as html +$snappy->setOption('cover', '

Bill cover

'); +$snappy->setOption('toc', true); +$snappy->setOption('cache-dir', '/path/to/cache/dir'); +``` + +## wkhtmltopdf binary as composer dependencies + +If you want to download wkhtmltopdf and wkhtmltoimage with composer you add to `composer.json`: + +```bash +$ composer require h4cc/wkhtmltopdf-i386 0.12.x +$ composer require h4cc/wkhtmltoimage-i386 0.12.x +``` + +or this if you are in 64 bit based system: + +```bash +$ composer require h4cc/wkhtmltopdf-amd64 0.12.x +$ composer require h4cc/wkhtmltoimage-amd64 0.12.x +``` + +And then you can use it + +```php +setOption('toc', true); +$snappy->setOption('xsl-style-sheet', 'http://path/to/stylesheet.xsl') //or local file; + +$snappy->generateFromHtml('

Some content

', 'test.pdf'); +``` + +## Credits + +Snappy has been originally developed by the [KnpLabs](http://knplabs.com) team. diff --git a/vendor/knplabs/knp-snappy/composer.json b/vendor/knplabs/knp-snappy/composer.json new file mode 100644 index 000000000..3ab72edf7 --- /dev/null +++ b/vendor/knplabs/knp-snappy/composer.json @@ -0,0 +1,42 @@ +{ + "name": "knplabs/knp-snappy", + "type": "library", + "description": "PHP5 library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage.", + "keywords": ["pdf", "thumbnail", "snapshot", "knplabs", "knp", "wkhtmltopdf"], + "homepage": "http://github.com/KnpLabs/snappy", + "license": "MIT", + "authors": [ + { + "name": "KnpLabs Team", + "homepage": "http://knplabs.com" + }, + { + "name": "Symfony Community", + "homepage": "http://github.com/KnpLabs/snappy/contributors" + } + ], + "require": { + "php": ">=5.6", + "symfony/process": "~2.3|~3.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.7" + }, + "suggest": { + "h4cc/wkhtmltopdf-amd64": "Provides wkhtmltopdf-amd64 binary for Linux-compatible machines, use version `~0.12` as dependency", + "h4cc/wkhtmltopdf-i386": "Provides wkhtmltopdf-i386 binary for Linux-compatible machines, use version `~0.12` as dependency", + "h4cc/wkhtmltoimage-amd64": "Provides wkhtmltoimage-amd64 binary for Linux-compatible machines, use version `~0.12` as dependency", + "h4cc/wkhtmltoimage-i386": "Provides wkhtmltoimage-i386 binary for Linux-compatible machines, use version `~0.12` as dependency", + "wemersonjanuario/wkhtmltopdf-windows": "Provides wkhtmltopdf executable for Windows, use version `~0.12` as dependency" + }, + "autoload": { + "psr-4": { + "Knp\\Snappy\\": "src/Knp/Snappy" + } + }, + "extra": { + "branch-alias": { + "dev-master": "0.5.x-dev" + } + } +} diff --git a/vendor/knplabs/knp-snappy/doc/faq.md b/vendor/knplabs/knp-snappy/doc/faq.md new file mode 100644 index 000000000..561c2a080 --- /dev/null +++ b/vendor/knplabs/knp-snappy/doc/faq.md @@ -0,0 +1,68 @@ +# Frequently asked questions + +###### *Q*: It does not work and everything is broken. + +*A*: Please, try to execute the command manually in your shell. Snappy is a thin PHP wrapper and most likely your issue is with wkhtmltopdf itself or is already described in this FAQ. If not, feel free to open the issue in Snappy issue tracker. + +How to get the command to execute - + +```php +var_dump($snappy->getCommand('http://google.com', 'test.pdf'), array('some' => 'option')); +``` + +Please, note that wkhtmltopdf takes only input url or file name as a source. + + +###### *Q*: My tables are broken when it is rendered on multiple pages with break. + +*A*: Add ```thead``` and ```tbody``` tags. Add the following css +```css +table, tr, td, th, tbody, thead, tfoot { + page-break-inside: avoid !important; +} +``` + + +###### *Q*: I have a PNG with a transparent background. When generating a PDF, the background turns black. + +*A*: It is wkhtmltopdf bug as described in https://github.com/wkhtmltopdf/wkhtmltopdf/issues/2214. You should update wkhtmltopdf to at least 0.12.3-dev + + +###### *Q*: Is there a way to secure the pdf so it can't be edited? + +*A*: There is no way to add a password via wkhtmltopdf, but there is a way via other linux tools like pdftk + + +###### *Q*: We are using wkhtmltopdf to export html to pdf. It breaks the HTML in two pages of pdf. Can we add a break? + +*A*: It is known problem of `wkhtmltopdf`. You can use css `page-break-after`, like: +```html + + +
+ new page +
+``` + + +###### *Q*: It says `wkhtmltopdf: cannot connect to X server` or `xvfb-run: error: Xvfb failed to start.` + +*A*: Please, check your `wkhtmltopdf` version. It is recommended to use at least `0.12.2.1` and what is important - starting from `wkhtmltopdf >= 0.12.2` it doesn't require X server or emulation anymore. You can download new version from http://wkhtmltopdf.org/downloads.html or install via composer for Linux servers as stated in [README](https://github.com/KnpLabs/snappy#wkhtmltopdf-binary-as-composer-dependencies). If there is no possibility to update `wkhtmltopdf`, please check http://stackoverflow.com/questions/9604625/wkhtmltopdf-cannot-connect-to-x-server + + +###### *Q*: My PDF is always generated for a small screen resolution\I always receive a mobile version. + +*A*: It is well-known issue of wkhtmltopdf, you can check https://github.com/wkhtmltopdf/wkhtmltopdf/issues/1508. One of solutions is to use xvbf and to setup xvbf resolution to desired one though a simple bit of css such as `zoom: .75;` would be sufficient in most cases. + +###### *Q*: My chars with accents in HTML document are not correctly rendered. + +*A*: Make sure that you have set `` + +###### *Q*: My document text is not correctly rendered, it is just black squares + +*A*: Make sure you have installed `xfonts-base`, `xfonts-75dpi` and `urw-fonts` diff --git a/vendor/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php b/vendor/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php new file mode 100644 index 000000000..fec44b15c --- /dev/null +++ b/vendor/knplabs/knp-snappy/src/Knp/Snappy/AbstractGenerator.php @@ -0,0 +1,644 @@ + + * @author Antoine Hérault + */ +abstract class AbstractGenerator implements GeneratorInterface +{ + private $binary; + private $options = array(); + private $env; + private $timeout = false; + private $defaultExtension; + + /** + * @var string + */ + protected $temporaryFolder; + + /** + * @var array + */ + public $temporaryFiles = array(); + + /** + * Constructor + * + * @param string $binary + * @param array $options + * @param array $env + */ + public function __construct($binary, array $options = array(), array $env = null) + { + $this->configure(); + + $this->setBinary($binary); + $this->setOptions($options); + $this->env = empty($env) ? null : $env; + + register_shutdown_function(array($this, 'removeTemporaryFiles')); + } + + public function __destruct() + { + $this->removeTemporaryFiles(); + } + + /** + * This method must configure the media options + * + * @see AbstractGenerator::addOption() + */ + abstract protected function configure(); + + /** + * Sets the default extension. + * Useful when letting Snappy deal with file creation + * + * @param string $defaultExtension + */ + public function setDefaultExtension($defaultExtension) + { + $this->defaultExtension = $defaultExtension; + } + + /** + * Gets the default extension + * + * @return $string + */ + public function getDefaultExtension() + { + return $this->defaultExtension; + } + + /** + * Sets an option. Be aware that option values are NOT validated and that + * it is your responsibility to validate user inputs + * + * @param string $name The option to set + * @param mixed $value The value (NULL to unset) + * + * @throws \InvalidArgumentException + */ + public function setOption($name, $value) + { + if (!array_key_exists($name, $this->options)) { + throw new \InvalidArgumentException(sprintf('The option \'%s\' does not exist.', $name)); + } + + $this->options[$name] = $value; + } + + /** + * Sets the timeout. Be aware that option only works with symfony + * + * @param integer $timeout The timeout to set + */ + public function setTimeout($timeout) + { + $this->timeout = $timeout; + } + + /** + * Sets an array of options + * + * @param array $options An associative array of options as name/value + */ + public function setOptions(array $options) + { + foreach ($options as $name => $value) { + $this->setOption($name, $value); + } + } + + /** + * Returns all the options + * + * @return array + */ + public function getOptions() + { + return $this->options; + } + + /** + * {@inheritDoc} + */ + public function generate($input, $output, array $options = array(), $overwrite = false) + { + if (null === $this->binary) { + throw new \LogicException( + 'You must define a binary prior to conversion.' + ); + } + + $this->prepareOutput($output, $overwrite); + + $command = $this->getCommand($input, $output, $options); + + list($status, $stdout, $stderr) = $this->executeCommand($command); + $this->checkProcessStatus($status, $stdout, $stderr, $command); + + $this->checkOutput($output, $command); + } + + /** + * {@inheritDoc} + */ + public function generateFromHtml($html, $output, array $options = array(), $overwrite = false) + { + $fileNames = array(); + if (is_array($html)) { + foreach ($html as $htmlInput) { + $fileNames[] = $this->createTemporaryFile($htmlInput, 'html'); + } + } else { + $fileNames[] = $this->createTemporaryFile($html, 'html'); + } + + $this->generate($fileNames, $output, $options, $overwrite); + } + + /** + * {@inheritDoc} + */ + public function getOutput($input, array $options = array()) + { + $filename = $this->createTemporaryFile(null, $this->getDefaultExtension()); + + $this->generate($input, $filename, $options); + + $result = $this->getFileContents($filename); + + return $result; + } + + /** + * {@inheritDoc} + */ + public function getOutputFromHtml($html, array $options = array()) + { + $fileNames = array(); + if (is_array($html)) { + foreach ($html as $htmlInput) { + $fileNames[] = $this->createTemporaryFile($htmlInput, 'html'); + } + } else { + $fileNames[] = $this->createTemporaryFile($html, 'html'); + } + + $result = $this->getOutput($fileNames, $options); + + return $result; + } + + /** + * Defines the binary + * + * @param string $binary The path/name of the binary + */ + public function setBinary($binary) + { + $this->binary = $binary; + } + + /** + * Returns the binary + * + * @return string + */ + public function getBinary() + { + return $this->binary; + } + + /** + * Returns the command for the given input and output files + * + * @param array|string $input The input file + * @param string $output The ouput file + * @param array $options An optional array of options that will be used + * only for this command + * + * @return string + */ + public function getCommand($input, $output, array $options = array()) + { + $options = $this->mergeOptions($options); + + return $this->buildCommand($this->binary, $input, $output, $options); + } + + /** + * Adds an option + * + * @param string $name The name + * @param mixed $default An optional default value + * + * @throws \InvalidArgumentException + */ + protected function addOption($name, $default = null) + { + if (array_key_exists($name, $this->options)) { + throw new \InvalidArgumentException(sprintf('The option \'%s\' already exists.', $name)); + } + + $this->options[$name] = $default; + } + + /** + * Adds an array of options + * + * @param array $options + */ + protected function addOptions(array $options) + { + foreach ($options as $name => $default) { + $this->addOption($name, $default); + } + } + + /** + * Merges the given array of options to the instance options and returns + * the result options array. It does NOT change the instance options. + * + * @param array $options + * @throws \InvalidArgumentException + * + * @return array + */ + protected function mergeOptions(array $options) + { + $mergedOptions = $this->options; + + foreach ($options as $name => $value) { + if (!array_key_exists($name, $mergedOptions)) { + throw new \InvalidArgumentException(sprintf('The option \'%s\' does not exist.', $name)); + } + + $mergedOptions[$name] = $value; + } + + return $mergedOptions; + } + + /** + * Checks the specified output + * + * @param string $output The output filename + * @param string $command The generation command + * + * @throws \RuntimeException if the output file generation failed + */ + protected function checkOutput($output, $command) + { + // the output file must exist + if (!$this->fileExists($output)) { + throw new \RuntimeException(sprintf( + 'The file \'%s\' was not created (command: %s).', + $output, $command + )); + } + + // the output file must not be empty + if (0 === $this->filesize($output)) { + throw new \RuntimeException(sprintf( + 'The file \'%s\' was created but is empty (command: %s).', + $output, $command + )); + } + } + + /** + * Checks the process return status + * + * @param int $status The exit status code + * @param string $stdout The stdout content + * @param string $stderr The stderr content + * @param string $command The run command + * + * @throws \RuntimeException if the output file generation failed + */ + protected function checkProcessStatus($status, $stdout, $stderr, $command) + { + if (0 !== $status and '' !== $stderr) { + throw new \RuntimeException(sprintf( + 'The exit status code \'%s\' says something went wrong:'."\n" + .'stderr: "%s"'."\n" + .'stdout: "%s"'."\n" + .'command: %s.', + $status, $stderr, $stdout, $command + )); + } + } + + /** + * Creates a temporary file. + * The file is not created if the $content argument is null + * + * @param string $content Optional content for the temporary file + * @param string $extension An optional extension for the filename + * + * @return string The filename + */ + protected function createTemporaryFile($content = null, $extension = null) + { + $dir = rtrim($this->getTemporaryFolder(), DIRECTORY_SEPARATOR); + + if (!is_dir($dir)) { + if (false === @mkdir($dir, 0777, true) && !is_dir($dir)) { + throw new \RuntimeException(sprintf("Unable to create directory: %s\n", $dir)); + } + } elseif (!is_writable($dir)) { + throw new \RuntimeException(sprintf("Unable to write in directory: %s\n", $dir)); + } + + $filename = $dir . DIRECTORY_SEPARATOR . uniqid('knp_snappy', true); + + if (null !== $extension) { + $filename .= '.'.$extension; + } + + if (null !== $content) { + file_put_contents($filename, $content); + } + + $this->temporaryFiles[] = $filename; + + return $filename; + } + + /** + * Removes all temporary files + */ + public function removeTemporaryFiles() + { + foreach ($this->temporaryFiles as $file) { + $this->unlink($file); + } + } + + /** + * Builds the command string + * + * @param string $binary The binary path/name + * @param string/array $input Url(s) or file location(s) of the page(s) to process + * @param string $output File location to the image-to-be + * @param array $options An array of options + * + * @return string + */ + protected function buildCommand($binary, $input, $output, array $options = array()) + { + $command = $binary; + $escapedBinary = escapeshellarg($binary); + if (is_executable($escapedBinary)) { + $command = $escapedBinary; + } + + foreach ($options as $key => $option) { + if (null !== $option && false !== $option) { + + if (true === $option) { + // Dont't put '--' if option is 'toc'. + if ($key == 'toc') { + $command .= ' '.$key; + } else { + $command .= ' --'.$key; + } + + } elseif (is_array($option)) { + if ($this->isAssociativeArray($option)) { + foreach ($option as $k => $v) { + $command .= ' --'.$key.' '.escapeshellarg($k).' '.escapeshellarg($v); + } + } else { + foreach ($option as $v) { + $command .= ' --'.$key.' '.escapeshellarg($v); + } + } + + } else { + // Dont't add '--' if option is "cover" or "toc". + if (in_array($key, array('toc', 'cover'))) { + $command .= ' '.$key.' '.escapeshellarg($option); + } else { + $command .= ' --'.$key.' '.escapeshellarg($option); + } + } + } + } + + if (is_array($input)) { + foreach ($input as $i) { + $command .= ' '.escapeshellarg($i).' '; + } + $command .= escapeshellarg($output); + } else { + $command .= ' '.escapeshellarg($input).' '.escapeshellarg($output); + } + + return $command; + } + + /** + * Return true if the array is an associative array + * and not an indexed array + * + * @param array $array + * + * @return boolean + */ + protected function isAssociativeArray(array $array) + { + return (bool) count(array_filter(array_keys($array), 'is_string')); + } + + /** + * Executes the given command via shell and returns the complete output as + * a string + * + * @param string $command + * + * @return array(status, stdout, stderr) + */ + protected function executeCommand($command) + { + $process = new Process($command, null, $this->env); + + if (false !== $this->timeout) { + $process->setTimeout($this->timeout); + } + + $process->run(); + + return array( + $process->getExitCode(), + $process->getOutput(), + $process->getErrorOutput(), + ); + } + + /** + * Prepares the specified output + * + * @param string $filename The output filename + * @param boolean $overwrite Whether to overwrite the file if it already + * exist + * + * @throws Exception\FileAlreadyExistsException + * @throws \RuntimeException + * @throws \InvalidArgumentException + */ + protected function prepareOutput($filename, $overwrite) + { + $directory = dirname($filename); + + if ($this->fileExists($filename)) { + if (!$this->isFile($filename)) { + throw new \InvalidArgumentException(sprintf( + 'The output file \'%s\' already exists and it is a %s.', + $filename, $this->isDir($filename) ? 'directory' : 'link' + )); + } elseif (false === $overwrite) { + throw new Exceptions\FileAlreadyExistsException(sprintf( + 'The output file \'%s\' already exists.', + $filename + )); + } elseif (!$this->unlink($filename)) { + throw new \RuntimeException(sprintf( + 'Could not delete already existing output file \'%s\'.', + $filename + )); + } + } elseif (!$this->isDir($directory) && !$this->mkdir($directory)) { + throw new \RuntimeException(sprintf( + 'The output file\'s directory \'%s\' could not be created.', + $directory + )); + } + } + + /** + * Get TemporaryFolder + * + * @return string + */ + public function getTemporaryFolder() + { + if ($this->temporaryFolder === null) { + return sys_get_temp_dir(); + } + + return $this->temporaryFolder; + } + + /** + * Set temporaryFolder + * + * @param string $temporaryFolder + * + * @return $this + */ + public function setTemporaryFolder($temporaryFolder) + { + $this->temporaryFolder = $temporaryFolder; + + return $this; + } + + /** + * Wrapper for the "file_get_contents" function + * + * @param string $filename + * + * @return string + */ + protected function getFileContents($filename) + { + return file_get_contents($filename); + } + + /** + * Wrapper for the "file_exists" function + * + * @param string $filename + * + * @return boolean + */ + protected function fileExists($filename) + { + return file_exists($filename); + } + + /** + * Wrapper for the "is_file" method + * + * @param string $filename + * + * @return boolean + */ + protected function isFile($filename) + { + return is_file($filename); + } + + /** + * Wrapper for the "filesize" function + * + * @param string $filename + * + * @return integer or FALSE on failure + */ + protected function filesize($filename) + { + return filesize($filename); + } + + /** + * Wrapper for the "unlink" function + * + * @param string $filename + * + * @return boolean + */ + protected function unlink($filename) + { + return $this->fileExists($filename) ? unlink($filename) : false; + } + + /** + * Wrapper for the "is_dir" function + * + * @param string $filename + * + * @return boolean + */ + protected function isDir($filename) + { + return is_dir($filename); + } + + /** + * Wrapper for the mkdir function + * + * @param string $pathname + * + * @return boolean + */ + protected function mkdir($pathname) + { + return mkdir($pathname, 0777, true); + } +} diff --git a/vendor/knplabs/knp-snappy/src/Knp/Snappy/Exception/FileAlreadyExistsException.php b/vendor/knplabs/knp-snappy/src/Knp/Snappy/Exception/FileAlreadyExistsException.php new file mode 100644 index 000000000..d20f3c97f --- /dev/null +++ b/vendor/knplabs/knp-snappy/src/Knp/Snappy/Exception/FileAlreadyExistsException.php @@ -0,0 +1,5 @@ + + * @author Antoine Hérault * + */ +interface GeneratorInterface +{ + /** + * Generates the output media file from the specified input HTML file + * + * @param array|string $input The input HTML filename or URL + * @param string $output The output media filename + * @param array $options An array of options for this generation only + * @param bool $overwrite Overwrite the file if it exists. If not, throw a FileAlreadyExistsException + */ + public function generate($input, $output, array $options = array(), $overwrite = false); + + /** + * Generates the output media file from the given HTML + * + * @param array|string $html The HTML to be converted + * @param string $output The output media filename + * @param array $options An array of options for this generation only + * @param bool $overwrite Overwrite the file if it exists. If not, throw a FileAlreadyExistsException + */ + public function generateFromHtml($html, $output, array $options = array(), $overwrite = false); + + /** + * Returns the output of the media generated from the specified input HTML + * file + * + * @param array|string $input The input HTML filename or URL + * @param array $options An array of options for this output only + * + * @return string + */ + public function getOutput($input, array $options = array()); + + /** + * Returns the output of the media generated from the given HTML + * + * @param array|string $html The HTML to be converted + * @param array $options An array of options for this output only + * + * @return string + */ + public function getOutputFromHtml($html, array $options = array()); +} diff --git a/vendor/knplabs/knp-snappy/src/Knp/Snappy/Image.php b/vendor/knplabs/knp-snappy/src/Knp/Snappy/Image.php new file mode 100644 index 000000000..c2de065cc --- /dev/null +++ b/vendor/knplabs/knp-snappy/src/Knp/Snappy/Image.php @@ -0,0 +1,82 @@ + + * @author Antoine Hérault + */ +class Image extends AbstractGenerator +{ + /** + * {@inheritDoc} + */ + public function __construct($binary = null, array $options = array(), array $env = null) + { + $this->setDefaultExtension('jpg'); + + parent::__construct($binary, $options, $env); + } + + /** + * {@inheritDoc} + */ + protected function configure() + { + $this->addOptions(array( + 'allow' => null, // Allow the file or files from the specified folder to be loaded (repeatable) + 'checkbox-checked-svg' => null, // Use this SVG file when rendering checked checkboxes + 'checked-svg' => null, // Use this SVG file when rendering unchecked checkboxes + 'cookie' => array(), // Set an additional cookie (repeatable) + 'cookie-jar' => null, // Read and write cookies from and to the supplied cookie jar file + 'crop-h' => null, // Set height for cropping + 'crop-w' => null, // Set width for cropping + 'crop-x' => null, // Set x coordinate for cropping (default 0) + 'crop-y' => null, // Set y coordinate for cropping (default 0) + 'custom-header' => array(), // Set an additional HTTP header (repeatable) + 'custom-header-propagation' => null, // Add HTTP headers specified by --custom-header for each resource request. + 'no-custom-header-propagation' => null, // Do not add HTTP headers specified by --custom-header for each resource request. + 'debug-javascript' => null, // Show javascript debugging output + 'no-debug-javascript' => null, // Do not show javascript debugging output (default) + 'encoding' => null, // Set the default text encoding, for input + 'format' => $this->getDefaultExtension(), // Output format + 'height' => null, // Set screen height (default is calculated from page content) (default 0) + 'images' => null, // Do load or print images (default) + 'no-images' => null, // Do not load or print images + 'disable-javascript' => null, // Do not allow web pages to run javascript + 'enable-javascript' => null, // Do allow web pages to run javascript (default) + 'javascript-delay' => null, // Wait some milliseconds for javascript finish (default 200) + 'load-error-handling' => null, // Specify how to handle pages that fail to load: abort, ignore or skip (default abort) + 'load-media-error-handling' => null, // Specify how to handle media files that fail to load: abort, ignore or skip (default ignore) + 'disable-local-file-access' => null, // Do not allowed conversion of a local file to read in other local files, unless explicitly allowed with allow + 'enable-local-file-access' => null, // Allowed conversion of a local file to read in other local files. (default) + 'minimum-font-size' => null, // Minimum font size + 'password' => null, // HTTP Authentication password + 'disable-plugins' => null, // Disable installed plugins (default) + 'enable-plugins' => null, // Enable installed plugins (plugins will likely not work) + 'post' => array(), // Add an additional post field + 'post-file' => array(), // Post an additional file + 'proxy' => null, // Use a proxy + 'quality' => null, // Output image quality (between 0 and 100) (default 94) + 'radiobutton-checked-svg' => null, // Use this SVG file when rendering checked radio-buttons + 'radiobutton-svg' => null, // Use this SVG file when rendering unchecked radio-buttons + 'run-script' => null, // Run this additional javascript after the page is done loading (repeatable) + 'disable-smart-width' => null, // Use the specified width even if it is not large enough for the content + 'enable-smart-width' => null, // Extend --width to fit unbreakable content (default) + 'stop-slow-scripts' => null, // Stop slow running javascript + 'no-stop-slow-scripts' => null, // Do not stop slow running javascript (default) + 'transparent' => null, // Make the background transparent in pngs * + 'use-xserver' => null, // Use the X server (some plugins and other stuff might not work without X11) + 'user-style-sheet' => null, // Specify a user style sheet, to load with every page + 'username' => null, // HTTP Authentication username + 'width' => null, // Set screen width (default is 1024) + 'window-status' => null, // Wait until window.status is equal to this string before rendering page + 'zoom' => null, // Use this zoom factor (default 1) + 'quiet' => null, // Be less verbose + )); + } +} diff --git a/vendor/knplabs/knp-snappy/src/Knp/Snappy/Pdf.php b/vendor/knplabs/knp-snappy/src/Knp/Snappy/Pdf.php new file mode 100644 index 000000000..04bcaf80a --- /dev/null +++ b/vendor/knplabs/knp-snappy/src/Knp/Snappy/Pdf.php @@ -0,0 +1,220 @@ + + * @author Antoine Hérault + */ +class Pdf extends AbstractGenerator +{ + protected $optionsWithContentCheck = array(); + + /** + * {@inheritDoc} + */ + public function __construct($binary = null, array $options = array(), array $env = null) + { + $this->setDefaultExtension('pdf'); + $this->setOptionsWithContentCheck(); + + parent::__construct($binary, $options, $env); + } + + /** + * Handle options to transform HTML strings into temporary files containing HTML + * @param array $options + * @return array $options Transformed options + */ + protected function handleOptions(array $options = array()) + { + foreach ($options as $option => $value) { + if (null === $value) { + unset($options[$option]); + continue; + } + + if (!empty($value) && array_key_exists($option, $this->optionsWithContentCheck)) { + $saveToTempFile = !$this->isFile($value) && !$this->isOptionUrl($value); + $fetchUrlContent = $option === 'xsl-style-sheet' && $this->isOptionUrl($value); + + if ($saveToTempFile || $fetchUrlContent) { + $fileContent = $fetchUrlContent ? file_get_contents($value) : $value; + $options[$option] = $this->createTemporaryFile($fileContent, $this->optionsWithContentCheck[$option]); + } + } + } + + return $options; + } + + /** + * {@inheritDoc} + */ + public function generate($input, $output, array $options = array(), $overwrite = false) + { + $options = $this->handleOptions($this->mergeOptions($options)); + + parent::generate($input, $output, $options, $overwrite); + } + + /** + * Convert option content or url to file if it is needed + * @param $option + * @return bool + */ + protected function isOptionUrl($option) + { + return (bool)filter_var($option, FILTER_VALIDATE_URL); + } + + /** + * {@inheritDoc} + */ + protected function configure() + { + $this->addOptions(array( + 'ignore-load-errors' => null, // old v0.9 + 'lowquality' => true, + 'collate' => null, + 'no-collate' => null, + 'cookie-jar' => null, + 'copies' => null, + 'dpi' => null, + 'extended-help' => null, + 'grayscale' => null, + 'help' => null, + 'htmldoc' => null, + 'image-dpi' => null, + 'image-quality' => null, + 'manpage' => null, + 'margin-bottom' => null, + 'margin-left' => null, + 'margin-right' => null, + 'margin-top' => null, + 'orientation' => null, + 'output-format' => null, + 'page-height' => null, + 'page-size' => null, + 'page-width' => null, + 'no-pdf-compression' => null, + 'quiet' => null, + 'read-args-from-stdin' => null, + 'title' => null, + 'use-xserver' => null, + 'version' => null, + 'dump-default-toc-xsl' => null, + 'dump-outline' => null, + 'outline' => null, + 'no-outline' => null, + 'outline-depth' => null, + 'allow' => null, + 'background' => null, + 'no-background' => null, + 'checkbox-checked-svg' => null, + 'checkbox-svg' => null, + 'cookie' => null, + 'custom-header' => null, + 'custom-header-propagation' => null, + 'no-custom-header-propagation' => null, + 'debug-javascript' => null, + 'no-debug-javascript' => null, + 'default-header' => null, + 'encoding' => null, + 'disable-external-links' => null, + 'enable-external-links' => null, + 'disable-forms' => null, + 'enable-forms' => null, + 'images' => null, + 'no-images' => null, + 'disable-internal-links' => null, + 'enable-internal-links' => null, + 'disable-javascript' => null, + 'enable-javascript' => null, + 'javascript-delay' => null, + 'load-error-handling' => null, + 'load-media-error-handling' => null, + 'disable-local-file-access' => null, + 'enable-local-file-access' => null, + 'minimum-font-size' => null, + 'exclude-from-outline' => null, + 'include-in-outline' => null, + 'page-offset' => null, + 'password' => null, + 'disable-plugins' => null, + 'enable-plugins' => null, + 'post' => null, + 'post-file' => null, + 'print-media-type' => null, + 'no-print-media-type' => null, + 'proxy' => null, + 'radiobutton-checked-svg' => null, + 'radiobutton-svg' => null, + 'run-script' => null, + 'disable-smart-shrinking' => null, + 'enable-smart-shrinking' => null, + 'stop-slow-scripts' => null, + 'no-stop-slow-scripts' => null, + 'disable-toc-back-links' => null, + 'enable-toc-back-links' => null, + 'user-style-sheet' => null, + 'username' => null, + 'window-status' => null, + 'zoom' => null, + 'footer-center' => null, + 'footer-font-name' => null, + 'footer-font-size' => null, + 'footer-html' => null, + 'footer-left' => null, + 'footer-line' => null, + 'no-footer-line' => null, + 'footer-right' => null, + 'footer-spacing' => null, + 'header-center' => null, + 'header-font-name' => null, + 'header-font-size' => null, + 'header-html' => null, + 'header-left' => null, + 'header-line' => null, + 'no-header-line' => null, + 'header-right' => null, + 'header-spacing' => null, + 'replace' => null, + 'disable-dotted-lines' => null, + 'cover' => null, + 'toc' => null, + 'toc-depth' => null, + 'toc-font-name' => null, + 'toc-l1-font-size' => null, + 'toc-header-text' => null, + 'toc-header-font-name' => null, + 'toc-header-font-size' => null, + 'toc-level-indentation' => null, + 'disable-toc-links' => null, + 'toc-text-size-shrink' => null, + 'xsl-style-sheet' => null, + 'viewport-size' => null, + 'redirect-delay' => null, // old v0.9 + 'cache-dir' => null, + 'keep-relative-links' => null, + 'resolve-relative-links' => null, + )); + } + + /** + * Array with options which require to store the content of the option before passing it to wkhtmltopdf + */ + protected function setOptionsWithContentCheck() + { + $this->optionsWithContentCheck = array( + 'header-html' => 'html', + 'footer-html' => 'html', + 'cover' => 'html', + 'xsl-style-sheet'=> 'xsl', + ); + } +} diff --git a/vendor/symfony/process/CHANGELOG.md b/vendor/symfony/process/CHANGELOG.md new file mode 100644 index 000000000..bb719be71 --- /dev/null +++ b/vendor/symfony/process/CHANGELOG.md @@ -0,0 +1,51 @@ +CHANGELOG +========= + +3.3.0 +----- + + * added command line arrays in the `Process` class + * added `$env` argument to `Process::start()`, `run()`, `mustRun()` and `restart()` methods + * deprecated the `ProcessUtils::escapeArgument()` method + * deprecated not inheriting environment variables + * deprecated configuring `proc_open()` options + * deprecated configuring enhanced Windows compatibility + * deprecated configuring enhanced sigchild compatibility + +2.5.0 +----- + + * added support for PTY mode + * added the convenience method "mustRun" + * deprecation: Process::setStdin() is deprecated in favor of Process::setInput() + * deprecation: Process::getStdin() is deprecated in favor of Process::getInput() + * deprecation: Process::setInput() and ProcessBuilder::setInput() do not accept non-scalar types + +2.4.0 +----- + + * added the ability to define an idle timeout + +2.3.0 +----- + + * added ProcessUtils::escapeArgument() to fix the bug in escapeshellarg() function on Windows + * added Process::signal() + * added Process::getPid() + * added support for a TTY mode + +2.2.0 +----- + + * added ProcessBuilder::setArguments() to reset the arguments on a builder + * added a way to retrieve the standard and error output incrementally + * added Process:restart() + +2.1.0 +----- + + * added support for non-blocking processes (start(), wait(), isRunning(), stop()) + * enhanced Windows compatibility + * added Process::getExitCodeText() that returns a string representation for + the exit code returned by the process + * added ProcessBuilder diff --git a/vendor/symfony/process/Exception/ExceptionInterface.php b/vendor/symfony/process/Exception/ExceptionInterface.php new file mode 100644 index 000000000..75c1c9e5d --- /dev/null +++ b/vendor/symfony/process/Exception/ExceptionInterface.php @@ -0,0 +1,21 @@ + + * + * 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 + */ +interface ExceptionInterface +{ +} diff --git a/vendor/symfony/process/Exception/InvalidArgumentException.php b/vendor/symfony/process/Exception/InvalidArgumentException.php new file mode 100644 index 000000000..926ee2118 --- /dev/null +++ b/vendor/symfony/process/Exception/InvalidArgumentException.php @@ -0,0 +1,21 @@ + + * + * 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 + */ +class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface +{ +} diff --git a/vendor/symfony/process/Exception/LogicException.php b/vendor/symfony/process/Exception/LogicException.php new file mode 100644 index 000000000..be3d490dd --- /dev/null +++ b/vendor/symfony/process/Exception/LogicException.php @@ -0,0 +1,21 @@ + + * + * 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 + */ +class LogicException extends \LogicException implements ExceptionInterface +{ +} diff --git a/vendor/symfony/process/Exception/ProcessFailedException.php b/vendor/symfony/process/Exception/ProcessFailedException.php new file mode 100644 index 000000000..328acfde5 --- /dev/null +++ b/vendor/symfony/process/Exception/ProcessFailedException.php @@ -0,0 +1,54 @@ + + * + * 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 + */ +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.'."\n\nExit Code: %s(%s)\n\nWorking directory: %s", + $process->getCommandLine(), + $process->getExitCode(), + $process->getExitCodeText(), + $process->getWorkingDirectory() + ); + + 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; + } +} diff --git a/vendor/symfony/process/Exception/ProcessTimedOutException.php b/vendor/symfony/process/Exception/ProcessTimedOutException.php new file mode 100644 index 000000000..d45114696 --- /dev/null +++ b/vendor/symfony/process/Exception/ProcessTimedOutException.php @@ -0,0 +1,69 @@ + + * + * 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 + */ +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)); + } + } +} diff --git a/vendor/symfony/process/Exception/RuntimeException.php b/vendor/symfony/process/Exception/RuntimeException.php new file mode 100644 index 000000000..adead2536 --- /dev/null +++ b/vendor/symfony/process/Exception/RuntimeException.php @@ -0,0 +1,21 @@ + + * + * 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 + */ +class RuntimeException extends \RuntimeException implements ExceptionInterface +{ +} diff --git a/vendor/symfony/process/ExecutableFinder.php b/vendor/symfony/process/ExecutableFinder.php new file mode 100644 index 000000000..d8e689622 --- /dev/null +++ b/vendor/symfony/process/ExecutableFinder.php @@ -0,0 +1,90 @@ + + * + * 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 + * @author Johannes M. Schmitt + */ +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) { + // Silencing against https://bugs.php.net/69240 + 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 = array_merge($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; + } +} diff --git a/vendor/symfony/process/InputStream.php b/vendor/symfony/process/InputStream.php new file mode 100644 index 000000000..831b10932 --- /dev/null +++ b/vendor/symfony/process/InputStream.php @@ -0,0 +1,90 @@ + + * + * 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; + +/** + * Provides a way to continuously write to the input of a Process until the InputStream is closed. + * + * @author Nicolas Grekas + */ +class InputStream implements \IteratorAggregate +{ + private $onEmpty = null; + private $input = array(); + private $open = true; + + /** + * Sets a callback that is called when the write buffer becomes empty. + */ + public function onEmpty(callable $onEmpty = null) + { + $this->onEmpty = $onEmpty; + } + + /** + * Appends an input to the write buffer. + * + * @param resource|scalar|\Traversable|null The input to append as stream resource, scalar or \Traversable + */ + public function write($input) + { + if (null === $input) { + return; + } + if ($this->isClosed()) { + throw new RuntimeException(sprintf('%s is closed', static::class)); + } + $this->input[] = ProcessUtils::validateInput(__METHOD__, $input); + } + + /** + * Closes the write buffer. + */ + public function close() + { + $this->open = false; + } + + /** + * Tells whether the write buffer is closed or not. + */ + public function isClosed() + { + return !$this->open; + } + + public function getIterator() + { + $this->open = true; + + while ($this->open || $this->input) { + if (!$this->input) { + yield ''; + continue; + } + $current = array_shift($this->input); + + if ($current instanceof \Iterator) { + foreach ($current as $cur) { + yield $cur; + } + } else { + yield $current; + } + if (!$this->input && $this->open && null !== $onEmpty = $this->onEmpty) { + $this->write($onEmpty($this)); + } + } + } +} diff --git a/vendor/composer/LICENSE b/vendor/symfony/process/LICENSE similarity index 95% copy from vendor/composer/LICENSE copy to vendor/symfony/process/LICENSE index 1a2812488..17d16a133 100644 --- a/vendor/composer/LICENSE +++ b/vendor/symfony/process/LICENSE @@ -1,5 +1,4 @@ - -Copyright (c) 2016 Nils Adermann, Jordi Boggiano +Copyright (c) 2004-2017 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 @@ -18,4 +17,3 @@ 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. - diff --git a/vendor/symfony/process/PhpExecutableFinder.php b/vendor/symfony/process/PhpExecutableFinder.php new file mode 100644 index 000000000..db31cc1b3 --- /dev/null +++ b/vendor/symfony/process/PhpExecutableFinder.php @@ -0,0 +1,90 @@ + + * + * 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 + * @author Johannes M. Schmitt + */ +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) + { + $args = $this->findArguments(); + $args = $includeArgs && $args ? ' '.implode(' ', $args) : ''; + + // HHVM support + if (defined('HHVM_VERSION')) { + return (getenv('PHP_BINARY') ?: PHP_BINARY).$args; + } + + // PHP_BINARY return the current sapi executable + if (PHP_BINARY && in_array(PHP_SAPI, array('cli', 'cli-server', 'phpdbg')) && is_file(PHP_BINARY)) { + return PHP_BINARY.$args; + } + + 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(); + + if (defined('HHVM_VERSION')) { + $arguments[] = '--php'; + } elseif ('phpdbg' === PHP_SAPI) { + $arguments[] = '-qrr'; + } + + return $arguments; + } +} diff --git a/vendor/symfony/process/PhpProcess.php b/vendor/symfony/process/PhpProcess.php new file mode 100644 index 000000000..7afd182f5 --- /dev/null +++ b/vendor/symfony/process/PhpProcess.php @@ -0,0 +1,78 @@ + + * + * 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(''); + * $p->run(); + * print $p->getOutput()."\n"; + * + * @author Fabien Potencier + */ +class PhpProcess extends Process +{ + /** + * Constructor. + * + * @param string $script The PHP script to run (as a string) + * @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 use the same environment as the current PHP process + * @param int $timeout The timeout in seconds + * @param array $options An array of options for proc_open + */ + public function __construct($script, $cwd = null, array $env = null, $timeout = 60, array $options = null) + { + $executableFinder = new PhpExecutableFinder(); + if (false === $php = $executableFinder->find(false)) { + $php = null; + } else { + $php = array_merge(array($php), $executableFinder->findArguments()); + } + if ('phpdbg' === PHP_SAPI) { + $file = tempnam(sys_get_temp_dir(), 'dbg'); + file_put_contents($file, $script); + register_shutdown_function('unlink', $file); + $php[] = $file; + $script = null; + } + if (null !== $options) { + @trigger_error(sprintf('The $options parameter of the %s constructor is deprecated since version 3.3 and will be removed in 4.0.', __CLASS__), E_USER_DEPRECATED); + } + + parent::__construct($php, $cwd, $env, $script, $timeout, $options); + } + + /** + * Sets the path to the PHP binary to use. + */ + public function setPhpBinary($php) + { + $this->setCommandLine($php); + } + + /** + * {@inheritdoc} + */ + public function start(callable $callback = null/*, array $env = array()*/) + { + if (null === $this->getCommandLine()) { + throw new RuntimeException('Unable to find the PHP executable.'); + } + $env = 1 < func_num_args() ? func_get_arg(1) : null; + + parent::start($callback, $env); + } +} diff --git a/vendor/symfony/process/Pipes/AbstractPipes.php b/vendor/symfony/process/Pipes/AbstractPipes.php new file mode 100644 index 000000000..4c67d5b82 --- /dev/null +++ b/vendor/symfony/process/Pipes/AbstractPipes.php @@ -0,0 +1,169 @@ + + * + * 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\Exception\InvalidArgumentException; + +/** + * @author Romain Neutron + * + * @internal + */ +abstract class AbstractPipes implements PipesInterface +{ + /** @var array */ + public $pipes = array(); + + /** @var string */ + private $inputBuffer = ''; + /** @var resource|scalar|\Iterator|null */ + private $input; + /** @var bool */ + private $blocked = true; + + public function __construct($input) + { + if (is_resource($input) || $input instanceof \Iterator) { + $this->input = $input; + } elseif (is_string($input)) { + $this->inputBuffer = $input; + } else { + $this->inputBuffer = (string) $input; + } + } + + /** + * {@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 (is_resource($this->input)) { + stream_set_blocking($this->input, 0); + } + + $this->blocked = false; + } + + /** + * Writes input to stdin. + * + * @throws InvalidArgumentException When an input iterator yields a non supported value + */ + protected function write() + { + if (!isset($this->pipes[0])) { + return; + } + $input = $this->input; + + if ($input instanceof \Iterator) { + if (!$input->valid()) { + $input = null; + } elseif (is_resource($input = $input->current())) { + stream_set_blocking($input, 0); + } elseif (!isset($this->inputBuffer[0])) { + if (!is_string($input)) { + if (!is_scalar($input)) { + throw new InvalidArgumentException(sprintf('%s yielded a value of type "%s", but only scalars and stream resources are supported', get_class($this->input), gettype($input))); + } + $input = (string) $input; + } + $this->inputBuffer = $input; + $this->input->next(); + $input = null; + } else { + $input = null; + } + } + + $r = $e = array(); + $w = array($this->pipes[0]); + + // let's have a look if something changed in streams + if (false === $n = @stream_select($r, $w, $e, 0, 0)) { + return; + } + + foreach ($w as $stdin) { + if (isset($this->inputBuffer[0])) { + $written = fwrite($stdin, $this->inputBuffer); + $this->inputBuffer = substr($this->inputBuffer, $written); + if (isset($this->inputBuffer[0])) { + return array($this->pipes[0]); + } + } + + if ($input) { + for (;;) { + $data = fread($input, self::CHUNK_SIZE); + if (!isset($data[0])) { + break; + } + $written = fwrite($stdin, $data); + $data = substr($data, $written); + if (isset($data[0])) { + $this->inputBuffer = $data; + + return array($this->pipes[0]); + } + } + if (feof($input)) { + if ($this->input instanceof \Iterator) { + $this->input->next(); + } else { + $this->input = null; + } + } + } + } + + // no input to read on resource, buffer is empty + if (!isset($this->inputBuffer[0]) && !($this->input instanceof \Iterator ? $this->input->valid() : $this->input)) { + $this->input = null; + fclose($this->pipes[0]); + unset($this->pipes[0]); + } elseif (!$w) { + return array($this->pipes[0]); + } + } +} diff --git a/vendor/symfony/process/Pipes/PipesInterface.php b/vendor/symfony/process/Pipes/PipesInterface.php new file mode 100644 index 000000000..52bbe76b8 --- /dev/null +++ b/vendor/symfony/process/Pipes/PipesInterface.php @@ -0,0 +1,67 @@ + + * + * 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 + * + * @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(); + + /** + * Returns if pipes are able to read output. + * + * @return bool + */ + public function haveReadSupport(); + + /** + * Closes file handles and pipes. + */ + public function close(); +} diff --git a/vendor/symfony/process/Pipes/UnixPipes.php b/vendor/symfony/process/Pipes/UnixPipes.php new file mode 100644 index 000000000..3185fe76e --- /dev/null +++ b/vendor/symfony/process/Pipes/UnixPipes.php @@ -0,0 +1,153 @@ + + * + * 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 + * + * @internal + */ +class UnixPipes extends AbstractPipes +{ + /** @var bool */ + private $ttyMode; + /** @var bool */ + private $ptyMode; + /** @var bool */ + private $haveReadSupport; + + public function __construct($ttyMode, $ptyMode, $input, $haveReadSupport) + { + $this->ttyMode = (bool) $ttyMode; + $this->ptyMode = (bool) $ptyMode; + $this->haveReadSupport = (bool) $haveReadSupport; + + parent::__construct($input); + } + + public function __destruct() + { + $this->close(); + } + + /** + * {@inheritdoc} + */ + public function getDescriptors() + { + if (!$this->haveReadSupport) { + $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) + { + $this->unblock(); + $w = $this->write(); + + $read = $e = array(); + $r = $this->pipes; + unset($r[0]); + + // let's have a look if something changed in streams + if (($r || $w) && 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; + } + + 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 + $read[$type = array_search($pipe, $this->pipes, true)] = ''; + + do { + $data = fread($pipe, self::CHUNK_SIZE); + $read[$type] .= $data; + } while (isset($data[0]) && ($close || isset($data[self::CHUNK_SIZE - 1]))); + + if (!isset($read[$type][0])) { + unset($read[$type]); + } + + if ($close && feof($pipe)) { + fclose($pipe); + unset($this->pipes[$type]); + } + } + + return $read; + } + + /** + * {@inheritdoc} + */ + public function haveReadSupport() + { + return $this->haveReadSupport; + } + + /** + * {@inheritdoc} + */ + public function areOpen() + { + return (bool) $this->pipes; + } +} diff --git a/vendor/symfony/process/Pipes/WindowsPipes.php b/vendor/symfony/process/Pipes/WindowsPipes.php new file mode 100644 index 000000000..a1e311551 --- /dev/null +++ b/vendor/symfony/process/Pipes/WindowsPipes.php @@ -0,0 +1,200 @@ + + * + * 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 + * + * @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 $haveReadSupport; + + public function __construct($input, $haveReadSupport) + { + $this->haveReadSupport = (bool) $haveReadSupport; + + if ($this->haveReadSupport) { + // 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 + $pipes = array( + Process::STDOUT => Process::OUT, + Process::STDERR => Process::ERR, + ); + $tmpCheck = false; + $tmpDir = sys_get_temp_dir(); + $lastError = 'unknown reason'; + set_error_handler(function ($type, $msg) use (&$lastError) { $lastError = $msg; }); + for ($i = 0;; ++$i) { + foreach ($pipes as $pipe => $name) { + $file = sprintf('%s\\sf_proc_%02X.%s', $tmpDir, $i, $name); + if (file_exists($file) && !unlink($file)) { + continue 2; + } + $h = fopen($file, 'xb'); + if (!$h) { + $error = $lastError; + if ($tmpCheck || $tmpCheck = unlink(tempnam(false, 'sf_check_'))) { + continue; + } + restore_error_handler(); + throw new RuntimeException(sprintf('A temporary file could not be opened to write the process output: %s', $error)); + } + if (!$h || !$this->fileHandles[$pipe] = fopen($file, 'rb')) { + continue 2; + } + if (isset($this->files[$pipe])) { + unlink($this->files[$pipe]); + } + $this->files[$pipe] = $file; + } + break; + } + restore_error_handler(); + } + + parent::__construct($input); + } + + public function __destruct() + { + $this->close(); + $this->removeFiles(); + } + + /** + * {@inheritdoc} + */ + public function getDescriptors() + { + if (!$this->haveReadSupport) { + $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->unblock(); + $w = $this->write(); + $read = $r = $e = array(); + + if ($blocking) { + if ($w) { + @stream_select($r, $w, $e, 0, Process::TIMEOUT_PRECISION * 1E6); + } elseif ($this->fileHandles) { + usleep(Process::TIMEOUT_PRECISION * 1E6); + } + } + foreach ($this->fileHandles as $type => $fileHandle) { + $data = stream_get_contents($fileHandle, -1, $this->readBytes[$type]); + + if (isset($data[0])) { + $this->readBytes[$type] += strlen($data); + $read[$type] = $data; + } + if ($close) { + fclose($fileHandle); + unset($this->fileHandles[$type]); + } + } + + return $read; + } + + /** + * {@inheritdoc} + */ + public function haveReadSupport() + { + return $this->haveReadSupport; + } + + /** + * {@inheritdoc} + */ + public function areOpen() + { + return $this->pipes && $this->fileHandles; + } + + /** + * {@inheritdoc} + */ + public function close() + { + parent::close(); + foreach ($this->fileHandles as $handle) { + fclose($handle); + } + $this->fileHandles = array(); + } + + /** + * Removes temporary files. + */ + private function removeFiles() + { + foreach ($this->files as $filename) { + if (file_exists($filename)) { + @unlink($filename); + } + } + $this->files = array(); + } +} diff --git a/vendor/symfony/process/Process.php b/vendor/symfony/process/Process.php new file mode 100644 index 000000000..05f88d2d1 --- /dev/null +++ b/vendor/symfony/process/Process.php @@ -0,0 +1,1735 @@ + + * + * 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 + * @author Romain Neutron + */ +class Process implements \IteratorAggregate +{ + 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; + + const ITER_NON_BLOCKING = 1; // By default, iterating over outputs is a blocking call, use this flag to make it non-blocking + const ITER_KEEP_OUTPUT = 2; // By default, outputs are cleared while iterating, use this flag to keep them in memory + const ITER_SKIP_OUT = 4; // Use this flag to skip STDOUT while iterating + const ITER_SKIP_ERR = 8; // Use this flag to skip STDERR while iterating + + private $callback; + private $hasCallback = false; + private $commandline; + private $cwd; + private $env; + private $input; + private $starttime; + private $lastOutputTime; + private $timeout; + private $idleTimeout; + private $options = array('suppress_errors' => true); + private $exitcode; + private $fallbackStatus = array(); + 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 $inheritEnv = false; + + 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|array $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 use the same environment as the current PHP process + * @param mixed|null $input The input as stream resource, scalar or \Traversable, or null for no 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 + */ + public function __construct($commandline, $cwd = null, array $env = null, $input = null, $timeout = 60, array $options = null) + { + 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->setInput($input); + $this->setTimeout($timeout); + $this->useFileHandles = '\\' === DIRECTORY_SEPARATOR; + $this->pty = false; + $this->enhanceSigchildCompatibility = '\\' !== DIRECTORY_SEPARATOR && $this->isSigchildEnabled(); + if (null !== $options) { + @trigger_error(sprintf('The $options parameter of the %s constructor is deprecated since version 3.3 and will be removed in 4.0.', __CLASS__), E_USER_DEPRECATED); + $this->options = array_replace($this->options, $options); + } + } + + public function __destruct() + { + $this->stop(0); + } + + 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 + * @param array $env An array of additional env vars to set when running the process + * + * @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 + * + * @final since version 3.3 + */ + public function run($callback = null/*, array $env = array()*/) + { + $env = 1 < func_num_args() ? func_get_arg(1) : null; + $this->start($callback, $env); + + 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 + * @param array $env An array of additional env vars to set when running the process + * + * @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 + * + * @final since version 3.3 + */ + public function mustRun(callable $callback = null/*, array $env = array()*/) + { + if (!$this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) { + throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.'); + } + $env = 1 < func_num_args() ? func_get_arg(1) : null; + + if (0 !== $this->run($callback, $env)) { + 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. + * + * @param callable|null $callback A PHP callback to run whenever there is some + * output available on STDOUT or STDERR + * @param array $env An array of additional env vars to set when running the process + * + * @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(callable $callback = null/*, array $env = array()*/) + { + if ($this->isRunning()) { + throw new RuntimeException('Process is already running'); + } + if (2 <= func_num_args()) { + $env = func_get_arg(1); + } else { + if (__CLASS__ !== static::class) { + $r = new \ReflectionMethod($this, __FUNCTION__); + if (__CLASS__ !== $r->getDeclaringClass()->getName() && (2 > $r->getNumberOfParameters() || 'env' !== $r->getParameters()[0]->name)) { + @trigger_error(sprintf('The %s::start() method expects a second "$env" argument since version 3.3. It will be made mandatory in 4.0.', static::class), E_USER_DEPRECATED); + } + } + $env = null; + } + + $this->resetProcessData(); + $this->starttime = $this->lastOutputTime = microtime(true); + $this->callback = $this->buildCallback($callback); + $this->hasCallback = null !== $callback; + $descriptors = $this->getDescriptors(); + $inheritEnv = $this->inheritEnv; + + if (is_array($commandline = $this->commandline)) { + $commandline = implode(' ', array_map(array($this, 'escapeArgument'), $commandline)); + + if ('\\' !== DIRECTORY_SEPARATOR) { + // exec is mandatory to deal with sending a signal to the process + $commandline = 'exec '.$commandline; + } + } + + if (null === $env) { + $env = $this->env; + } else { + if ($this->env) { + $env += $this->env; + } + $inheritEnv = true; + } + + $envBackup = array(); + if (null !== $env && $inheritEnv) { + foreach ($env as $k => $v) { + $envBackup[$k] = getenv($k); + putenv(false === $v || null === $v ? $k : "$k=$v"); + } + $env = null; + } elseif (null !== $env) { + @trigger_error('Not inheriting environment variables is deprecated since Symfony 3.3 and will always happen in 4.0. Set "Process::inheritEnvironmentVariables()" to true instead.', E_USER_DEPRECATED); + } + if ('\\' === DIRECTORY_SEPARATOR && $this->enhanceWindowsCompatibility) { + $this->options['bypass_shell'] = true; + $commandline = $this->prepareWindowsCommandLine($commandline, $envBackup, $env); + } elseif (!$this->useFileHandles && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) { + // last exit code is output on the fourth pipe and caught to work around --enable-sigchild + $descriptors[3] = array('pipe', 'w'); + + // See https://unix.stackexchange.com/questions/71205/background-process-pipe-input + $commandline = '{ ('.$commandline.') <&3 3<&- 3>/dev/null & } 3<&0;'; + $commandline .= 'pid=$!; echo $pid >&3; wait $pid; code=$?; echo $code >&3; exit $code'; + + // Workaround for the bug, when PTS functionality is enabled. + // @see : https://bugs.php.net/69442 + $ptsWorkaround = fopen(__FILE__, 'r'); + } + + $this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $env, $this->options); + + foreach ($envBackup as $k => $v) { + putenv(false === $v ? $k : "$k=$v"); + } + + if (!is_resource($this->process)) { + throw new RuntimeException('Unable to launch a new process.'); + } + $this->status = self::STATUS_STARTED; + + if (isset($descriptors[3])) { + $this->fallbackStatus['pid'] = (int) fgets($this->processPipes->pipes[3]); + } + + 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 + * @param array $env An array of additional env vars to set when running the process + * + * @return $this + * + * @throws RuntimeException When process can't be launched + * @throws RuntimeException When process is already running + * + * @see start() + * + * @final since version 3.3 + */ + public function restart(callable $callback = null/*, array $env = array()*/) + { + if ($this->isRunning()) { + throw new RuntimeException('Process is already running'); + } + $env = 1 < func_num_args() ? func_get_arg(1) : null; + + $process = clone $this; + $process->start($callback, $env); + + 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(callable $callback = null) + { + $this->requireProcessIsStarted(__FUNCTION__); + + $this->updateStatus(false); + + if (null !== $callback) { + if (!$this->processPipes->haveReadSupport()) { + $this->stop(0); + throw new \LogicException('Pass the callback to the Process::start method or enableOutput to use a callback with Process::wait'); + } + $this->callback = $this->buildCallback($callback); + } + + do { + $this->checkTimeout(); + $running = '\\' === DIRECTORY_SEPARATOR ? $this->isRunning() : $this->processPipes->areOpen(); + $this->readPipes($running, '\\' !== DIRECTORY_SEPARATOR || !$running); + } 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 + */ + public function getPid() + { + 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 $this + * + * @throws LogicException In case the process is not running + * @throws RuntimeException In case --enable-sigchild is activated and the process can't be killed + * @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 $this + * + * @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 $this + * + * @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 + */ + public function getOutput() + { + $this->readPipesForOutput(__FUNCTION__); + + if (false === $ret = stream_get_contents($this->stdout, -1, 0)) { + return ''; + } + + return $ret; + } + + /** + * 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. + * + * @return string The process output since the last call + * + * @throws LogicException in case the output has been disabled + * @throws LogicException In case the process is not started + */ + public function getIncrementalOutput() + { + $this->readPipesForOutput(__FUNCTION__); + + $latest = stream_get_contents($this->stdout, -1, $this->incrementalOutputOffset); + $this->incrementalOutputOffset = ftell($this->stdout); + + if (false === $latest) { + return ''; + } + + return $latest; + } + + /** + * Returns an iterator to the output of the process, with the output type as keys (Process::OUT/ERR). + * + * @param int $flags A bit field of Process::ITER_* flags + * + * @throws LogicException in case the output has been disabled + * @throws LogicException In case the process is not started + * + * @return \Generator + */ + public function getIterator($flags = 0) + { + $this->readPipesForOutput(__FUNCTION__, false); + + $clearOutput = !(self::ITER_KEEP_OUTPUT & $flags); + $blocking = !(self::ITER_NON_BLOCKING & $flags); + $yieldOut = !(self::ITER_SKIP_OUT & $flags); + $yieldErr = !(self::ITER_SKIP_ERR & $flags); + + while (null !== $this->callback || ($yieldOut && !feof($this->stdout)) || ($yieldErr && !feof($this->stderr))) { + if ($yieldOut) { + $out = stream_get_contents($this->stdout, -1, $this->incrementalOutputOffset); + + if (isset($out[0])) { + if ($clearOutput) { + $this->clearOutput(); + } else { + $this->incrementalOutputOffset = ftell($this->stdout); + } + + yield self::OUT => $out; + } + } + + if ($yieldErr) { + $err = stream_get_contents($this->stderr, -1, $this->incrementalErrorOutputOffset); + + if (isset($err[0])) { + if ($clearOutput) { + $this->clearErrorOutput(); + } else { + $this->incrementalErrorOutputOffset = ftell($this->stderr); + } + + yield self::ERR => $err; + } + } + + if (!$blocking && !isset($out[0]) && !isset($err[0])) { + yield self::OUT => ''; + } + + $this->checkTimeout(); + $this->readPipesForOutput(__FUNCTION__, $blocking); + } + } + + /** + * Clears the process output. + * + * @return $this + */ + public function clearOutput() + { + ftruncate($this->stdout, 0); + fseek($this->stdout, 0); + $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 + */ + public function getErrorOutput() + { + $this->readPipesForOutput(__FUNCTION__); + + if (false === $ret = stream_get_contents($this->stderr, -1, 0)) { + return ''; + } + + return $ret; + } + + /** + * 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. + * + * @return string The process error output since the last call + * + * @throws LogicException in case the output has been disabled + * @throws LogicException In case the process is not started + */ + public function getIncrementalErrorOutput() + { + $this->readPipesForOutput(__FUNCTION__); + + $latest = stream_get_contents($this->stderr, -1, $this->incrementalErrorOutputOffset); + $this->incrementalErrorOutputOffset = ftell($this->stderr); + + if (false === $latest) { + return ''; + } + + return $latest; + } + + /** + * Clears the process output. + * + * @return $this + */ + public function clearErrorOutput() + { + ftruncate($this->stderr, 0); + fseek($this->stderr, 0); + $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 + */ + public function getExitCode() + { + if (!$this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) { + 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 + * + * @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 + */ + 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 + */ + public function hasBeenSignaled() + { + $this->requireProcessIsTerminated(__FUNCTION__); + + if (!$this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) { + throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.'); + } + + 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 + */ + public function getTermSignal() + { + $this->requireProcessIsTerminated(__FUNCTION__); + + if ($this->isSigchildEnabled() && (!$this->enhanceSigchildCompatibility || -1 === $this->processInformation['termsig'])) { + throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.'); + } + + 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 + */ + public function hasBeenStopped() + { + $this->requireProcessIsTerminated(__FUNCTION__); + + 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 + */ + public function getStopSignal() + { + $this->requireProcessIsTerminated(__FUNCTION__); + + 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 (9) + * + * @return int The exit-code of the process + */ + public function stop($timeout = 10, $signal = null) + { + $timeoutMicro = microtime(true) + $timeout; + if ($this->isRunning()) { + // 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()) { + // Avoid exception here: process is supposed to be running, but it might have stopped just + // after this line. In any case, let's silently discard the error, we cannot do anything. + $this->doSignal($signal ?: 9, false); + } + } + + if ($this->isRunning()) { + if (isset($this->fallbackStatus['pid'])) { + unset($this->fallbackStatus['pid']); + + return $this->stop(0, $signal); + } + $this->close(); + } + + return $this->exitcode; + } + + /** + * Adds a line to the STDOUT stream. + * + * @internal + * + * @param string $line The line to append + */ + public function addOutput($line) + { + $this->lastOutputTime = microtime(true); + + fseek($this->stdout, 0, SEEK_END); + fwrite($this->stdout, $line); + fseek($this->stdout, $this->incrementalOutputOffset); + } + + /** + * Adds a line to the STDERR stream. + * + * @internal + * + * @param string $line The line to append + */ + public function addErrorOutput($line) + { + $this->lastOutputTime = microtime(true); + + fseek($this->stderr, 0, SEEK_END); + fwrite($this->stderr, $line); + fseek($this->stderr, $this->incrementalErrorOutputOffset); + } + + /** + * Gets the command line to be executed. + * + * @return string The command to execute + */ + public function getCommandLine() + { + return is_array($this->commandline) ? implode(' ', array_map(array($this, 'escapeArgument'), $this->commandline)) : $this->commandline; + } + + /** + * Sets the command line to be executed. + * + * @param string|array $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) { + static $isTtySupported; + + if (null === $isTtySupported) { + $isTtySupported = (bool) @proc_open('echo 1 >/dev/null', array(array('file', '/dev/tty', 'r'), array('file', '/dev/tty', 'w'), array('file', '/dev/tty', 'w')), $pipes); + } + + if (!$isTtySupported) { + throw new RuntimeException('TTY mode requires /dev/tty to be read/writable.'); + } + } + + $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. + * If it is false or null, it will be removed when + * env vars are otherwise inherited. + * + * 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 = $env; + + return $this; + } + + /** + * Gets the Process input. + * + * @return resource|string|\Iterator|null The Process input + */ + public function getInput() + { + return $this->input; + } + + /** + * Sets the input. + * + * This content will be passed to the underlying process standard input. + * + * @param resource|scalar|\Traversable|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(__METHOD__, $input); + + return $this; + } + + /** + * Gets the options for proc_open. + * + * @return array The current options + * + * @deprecated since version 3.3, to be removed in 4.0. + */ + public function getOptions() + { + @trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED); + + return $this->options; + } + + /** + * Sets the options for proc_open. + * + * @param array $options The new options + * + * @return self The current Process instance + * + * @deprecated since version 3.3, to be removed in 4.0. + */ + public function setOptions(array $options) + { + @trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED); + + $this->options = $options; + + return $this; + } + + /** + * Gets whether or not Windows compatibility is enabled. + * + * This is true by default. + * + * @return bool + * + * @deprecated since version 3.3, to be removed in 4.0. Enhanced Windows compatibility will always be enabled. + */ + public function getEnhanceWindowsCompatibility() + { + @trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Enhanced Windows compatibility will always be enabled.', __METHOD__), E_USER_DEPRECATED); + + return $this->enhanceWindowsCompatibility; + } + + /** + * Sets whether or not Windows compatibility is enabled. + * + * @param bool $enhance + * + * @return self The current Process instance + * + * @deprecated since version 3.3, to be removed in 4.0. Enhanced Windows compatibility will always be enabled. + */ + public function setEnhanceWindowsCompatibility($enhance) + { + @trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Enhanced Windows compatibility will always be enabled.', __METHOD__), E_USER_DEPRECATED); + + $this->enhanceWindowsCompatibility = (bool) $enhance; + + return $this; + } + + /** + * Returns whether sigchild compatibility mode is activated or not. + * + * @return bool + * + * @deprecated since version 3.3, to be removed in 4.0. Sigchild compatibility will always be enabled. + */ + public function getEnhanceSigchildCompatibility() + { + @trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Sigchild compatibility will always be enabled.', __METHOD__), E_USER_DEPRECATED); + + 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 + * + * @deprecated since version 3.3, to be removed in 4.0. + */ + public function setEnhanceSigchildCompatibility($enhance) + { + @trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Sigchild compatibility will always be enabled.', __METHOD__), E_USER_DEPRECATED); + + $this->enhanceSigchildCompatibility = (bool) $enhance; + + return $this; + } + + /** + * Sets whether environment variables will be inherited or not. + * + * @param bool $inheritEnv + * + * @return self The current Process instance + */ + public function inheritEnvironmentVariables($inheritEnv = true) + { + if (!$inheritEnv) { + @trigger_error('Not inheriting environment variables is deprecated since Symfony 3.3 and will always happen in 4.0. Set "Process::inheritEnvironmentVariables()" to true instead.', E_USER_DEPRECATED); + } + + $this->inheritEnv = (bool) $inheritEnv; + + return $this; + } + + /** + * Returns whether environment variables will be inherited or not. + * + * @return bool + * + * @deprecated since version 3.3, to be removed in 4.0. Environment variables will always be inherited. + */ + public function areEnvironmentVariablesInherited() + { + @trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0. Environment variables will always be inherited.', __METHOD__), E_USER_DEPRECATED); + + return $this->inheritEnv; + } + + /** + * 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; + } + + return $result = (bool) @proc_open('echo 1 >/dev/null', array(array('pty'), array('pty'), array('pty')), $pipes); + } + + /** + * Creates the descriptors needed by the proc_open. + * + * @return array + */ + private function getDescriptors() + { + if ($this->input instanceof \Iterator) { + $this->input->rewind(); + } + if ('\\' === DIRECTORY_SEPARATOR) { + $this->processPipes = new WindowsPipes($this->input, !$this->outputDisabled || $this->hasCallback); + } else { + $this->processPipes = new UnixPipes($this->isTty(), $this->isPty(), $this->input, !$this->outputDisabled || $this->hasCallback); + } + + return $this->processPipes->getDescriptors(); + } + + /** + * 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 \Closure A PHP closure + */ + protected function buildCallback(callable $callback = null) + { + if ($this->outputDisabled) { + return function ($type, $data) use ($callback) { + if (null !== $callback) { + call_user_func($callback, $type, $data); + } + }; + } + + $out = self::OUT; + + return function ($type, $data) use ($callback, $out) { + if ($out == $type) { + $this->addOutput($data); + } else { + $this->addErrorOutput($data); + } + + if (null !== $callback) { + call_user_func($callback, $type, $data); + } + }; + } + + /** + * 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); + $running = $this->processInformation['running']; + + $this->readPipes($running && $blocking, '\\' !== DIRECTORY_SEPARATOR || !$running); + + if ($this->fallbackStatus && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) { + $this->processInformation = $this->fallbackStatus + $this->processInformation; + } + + if (!$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') || defined('HHVM_VERSION')) { + return self::$sigchild = false; + } + + ob_start(); + phpinfo(INFO_GENERAL); + + return self::$sigchild = false !== strpos(ob_get_clean(), '--enable-sigchild'); + } + + /** + * Reads pipes for the freshest output. + * + * @param string $caller The name of the method that needs fresh outputs + * @param bool $blocking Whether to use blocking calls or not + * + * @throws LogicException in case output has been disabled or process is not started + */ + private function readPipesForOutput($caller, $blocking = false) + { + if ($this->outputDisabled) { + throw new LogicException('Output has been disabled.'); + } + + $this->requireProcessIsStarted($caller); + + $this->updateStatus($blocking); + } + + /** + * 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) { + $callback($type === self::STDOUT ? self::OUT : self::ERR, $data); + } elseif (!isset($this->fallbackStatus['signaled'])) { + $this->fallbackStatus['exitcode'] = (int) $data; + } + } + } + + /** + * Closes process resource, closes file handles, sets the exitcode. + * + * @return int The exitcode + */ + private function close() + { + $this->processPipes->close(); + if (is_resource($this->process)) { + proc_close($this->process); + } + $this->exitcode = $this->processInformation['exitcode']; + $this->status = self::STATUS_TERMINATED; + + if (-1 === $this->exitcode) { + if ($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']; + } elseif ($this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) { + $this->processInformation['signaled'] = true; + $this->processInformation['termsig'] = -1; + } + } + + // Free memory from self-reference callback created by buildCallback + // Doing so in other contexts like __destruct or by garbage collector is ineffective + // Now pipes are closed, so the callback is no longer necessary + $this->callback = null; + + 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->fallbackStatus = array(); + $this->processInformation = null; + $this->stdout = fopen('php://temp/maxmemory:'.(1024 * 1024), 'wb+'); + $this->stderr = fopen('php://temp/maxmemory:'.(1024 * 1024), 'wb+'); + $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 and the process can't be killed + * @throws RuntimeException In case of failure + */ + private function doSignal($signal, $throwException) + { + if (null === $pid = $this->getPid()) { + if ($throwException) { + throw new LogicException('Can not send signal on a non running process.'); + } + + return false; + } + + if ('\\' === DIRECTORY_SEPARATOR) { + exec(sprintf('taskkill /F /T /PID %d 2>&1', $pid), $output, $exitCode); + if ($exitCode && $this->isRunning()) { + if ($throwException) { + throw new RuntimeException(sprintf('Unable to kill the process (%s).', implode(' ', $output))); + } + + return false; + } + } else { + if (!$this->enhanceSigchildCompatibility || !$this->isSigchildEnabled()) { + $ok = @proc_terminate($this->process, $signal); + } elseif (function_exists('posix_kill')) { + $ok = @posix_kill($pid, $signal); + } elseif ($ok = proc_open(sprintf('kill -%d %d', $signal, $pid), array(2 => array('pipe', 'w')), $pipes)) { + $ok = false === fgets($pipes[2]); + } + if (!$ok) { + if ($throwException) { + throw new RuntimeException(sprintf('Error while sending signal `%s`.', $signal)); + } + + return false; + } + } + + $this->latestSignal = (int) $signal; + $this->fallbackStatus['signaled'] = true; + $this->fallbackStatus['exitcode'] = -1; + $this->fallbackStatus['termsig'] = $this->latestSignal; + + return true; + } + + private function prepareWindowsCommandLine($cmd, array &$envBackup, array &$env = null) + { + $uid = uniqid('', true); + $varCount = 0; + $varCache = array(); + $cmd = preg_replace_callback( + '/"(?:( + [^"%!^]*+ + (?: + (?: !LF! | "(?:\^[%!^])?+" ) + [^"%!^]*+ + )++ + ) | [^"]*+ )"/x', + function ($m) use (&$envBackup, &$env, &$varCache, &$varCount, $uid) { + if (!isset($m[1])) { + return $m[0]; + } + if (isset($varCache[$m[0]])) { + return $varCache[$m[0]]; + } + if (false !== strpos($value = $m[1], "\0")) { + $value = str_replace("\0", '?', $value); + } + if (false === strpbrk($value, "\"%!\n")) { + return '"'.$value.'"'; + } + + $value = str_replace(array('!LF!', '"^!"', '"^%"', '"^^"', '""'), array("\n", '!', '%', '^', '"'), $value); + $value = '"'.preg_replace('/(\\\\*)"/', '$1$1\\"', $value).'"'; + $var = $uid.++$varCount; + + if (null === $env) { + putenv("$var=$value"); + } else { + $env[$var] = $value; + } + + $envBackup[$var] = false; + + return $varCache[$m[0]] = '!'.$var.'!'; + }, + $cmd + ); + + $cmd = 'cmd /V:ON /E:ON /D /C ('.str_replace("\n", ' ', $cmd).')'; + foreach ($this->processPipes->getFiles() as $offset => $filename) { + $cmd .= ' '.$offset.'>"'.$filename.'"'; + } + + return $cmd; + } + + /** + * 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)); + } + } + + /** + * Escapes a string to be used as a shell argument. + * + * @param string $argument The argument that will be escaped + * + * @return string The escaped argument + */ + private function escapeArgument($argument) + { + if ('\\' !== DIRECTORY_SEPARATOR) { + return "'".str_replace("'", "'\\''", $argument)."'"; + } + if ('' === $argument = (string) $argument) { + return '""'; + } + if (false !== strpos($argument, "\0")) { + $argument = str_replace("\0", '?', $argument); + } + if (!preg_match('/[\/()%!^"<>&|\s]/', $argument)) { + return $argument; + } + $argument = preg_replace('/(\\\\+)$/', '$1$1', $argument); + + return '"'.str_replace(array('"', '^', '%', '!', "\n"), array('""', '"^^"', '"^%"', '"^!"', '!LF!'), $argument).'"'; + } +} diff --git a/vendor/symfony/process/ProcessBuilder.php b/vendor/symfony/process/ProcessBuilder.php new file mode 100644 index 000000000..36db35edb --- /dev/null +++ b/vendor/symfony/process/ProcessBuilder.php @@ -0,0 +1,288 @@ + + * + * 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 + */ +class ProcessBuilder +{ + private $arguments; + private $cwd; + private $env = array(); + private $input; + private $timeout = 60; + private $options; + 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 static + */ + 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 $this + */ + 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 $this + */ + 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 $this + */ + public function setArguments(array $arguments) + { + $this->arguments = $arguments; + + return $this; + } + + /** + * Sets the working directory. + * + * @param null|string $cwd The working directory + * + * @return $this + */ + public function setWorkingDirectory($cwd) + { + $this->cwd = $cwd; + + return $this; + } + + /** + * Sets whether environment variables will be inherited or not. + * + * @param bool $inheritEnv + * + * @return $this + * + * @deprecated since version 3.3, to be removed in 4.0. + */ + public function inheritEnvironmentVariables($inheritEnv = true) + { + @trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED); + + $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 $this + */ + 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 $this + */ + public function addEnvironmentVariables(array $variables) + { + $this->env = array_replace($this->env, $variables); + + return $this; + } + + /** + * Sets the input of the process. + * + * @param resource|scalar|\Traversable|null $input The input content + * + * @return $this + * + * @throws InvalidArgumentException In case the argument is invalid + */ + public function setInput($input) + { + $this->input = ProcessUtils::validateInput(__METHOD__, $input); + + return $this; + } + + /** + * Sets the process timeout. + * + * To disable the timeout, set this value to null. + * + * @param float|null $timeout + * + * @return $this + * + * @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 $this + * + * @deprecated since version 3.3, to be removed in 4.0. + */ + public function setOption($name, $value) + { + @trigger_error(sprintf('The %s() method is deprecated since version 3.3 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED); + + $this->options[$name] = $value; + + return $this; + } + + /** + * Disables fetching output and error output from the underlying process. + * + * @return $this + */ + public function disableOutput() + { + $this->outputDisabled = true; + + return $this; + } + + /** + * Enables fetching output and error output from the underlying process. + * + * @return $this + */ + 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().'); + } + + $arguments = array_merge($this->prefix, $this->arguments); + $process = new Process($arguments, $this->cwd, $this->env, $this->input, $this->timeout, $this->options); + // to preserve the BC with symfony <3.3, we convert the array structure + // to a string structure to avoid the prefixing with the exec command + $process->setCommandLine($process->getCommandLine()); + + if ($this->inheritEnv) { + $process->inheritEnvironmentVariables(); + } + if ($this->outputDisabled) { + $process->disableOutput(); + } + + return $process; + } +} diff --git a/vendor/symfony/process/ProcessUtils.php b/vendor/symfony/process/ProcessUtils.php new file mode 100644 index 000000000..24438d985 --- /dev/null +++ b/vendor/symfony/process/ProcessUtils.php @@ -0,0 +1,123 @@ + + * + * 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ň + */ +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 + * + * @deprecated since version 3.3, to be removed in 4.0. Use a command line array or give env vars to the `Process::start/run()` method instead. + */ + public static function escapeArgument($argument) + { + @trigger_error('The '.__METHOD__.'() method is deprecated since version 3.3 and will be removed in 4.0. Use a command line array or give env vars to the Process::start/run() method instead.', E_USER_DEPRECATED); + + //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 "'".str_replace("'", "'\\''", $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 mixed 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_string($input)) { + return $input; + } + if (is_scalar($input)) { + return (string) $input; + } + if ($input instanceof Process) { + return $input->getIterator($input::ITER_SKIP_ERR); + } + if ($input instanceof \Iterator) { + return $input; + } + if ($input instanceof \Traversable) { + return new \IteratorIterator($input); + } + + throw new InvalidArgumentException(sprintf('%s only accepts strings, Traversable objects or stream resources.', $caller)); + } + + return $input; + } + + private static function isSurroundedBy($arg, $char) + { + return 2 < strlen($arg) && $char === $arg[0] && $char === $arg[strlen($arg) - 1]; + } +} diff --git a/vendor/symfony/process/README.md b/vendor/symfony/process/README.md new file mode 100644 index 000000000..b7ca5b425 --- /dev/null +++ b/vendor/symfony/process/README.md @@ -0,0 +1,13 @@ +Process Component +================= + +The Process component executes commands in sub-processes. + +Resources +--------- + + * [Documentation](https://symfony.com/doc/current/components/process.html) + * [Contributing](https://symfony.com/doc/current/contributing/index.html) + * [Report issues](https://github.com/symfony/symfony/issues) and + [send Pull Requests](https://github.com/symfony/symfony/pulls) + in the [main Symfony repository](https://github.com/symfony/symfony) diff --git a/vendor/symfony/process/composer.json b/vendor/symfony/process/composer.json new file mode 100644 index 000000000..f899c52b2 --- /dev/null +++ b/vendor/symfony/process/composer.json @@ -0,0 +1,33 @@ +{ + "name": "symfony/process", + "type": "library", + "description": "Symfony Process Component", + "keywords": [], + "homepage": "https://symfony.com", + "license": "MIT", + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "require": { + "php": ">=5.5.9" + }, + "autoload": { + "psr-4": { "Symfony\\Component\\Process\\": "" }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "minimum-stability": "dev", + "extra": { + "branch-alias": { + "dev-master": "3.3-dev" + } + } +} diff --git a/vendor/symfony/process/phpunit.xml.dist b/vendor/symfony/process/phpunit.xml.dist new file mode 100644 index 000000000..d38846730 --- /dev/null +++ b/vendor/symfony/process/phpunit.xml.dist @@ -0,0 +1,30 @@ + + + + + + + + + + ./Tests/ + + + + + + ./ + + ./Tests + ./vendor + + + + -- 2.11.4.GIT