This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Process/ProcessUtils.php

70 lines
1.8 KiB
PHP
Raw Normal View History

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process;
use Symfony\Component\Process\Exception\InvalidArgumentException;
/**
* ProcessUtils is a bunch of utility methods.
*
* This class contains static methods only and is not meant to be instantiated.
*
* @author Martin Hasoň <martin.hason@gmail.com>
*/
class ProcessUtils
{
/**
2014-12-21 17:00:50 +00:00
* This class should not be instantiated.
*/
private function __construct()
{
}
/**
Merge branch '2.3' into 2.5 * 2.3: [2.3] CS And DocBlock Fixes [2.3] CS Fixes Conflicts: src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php src/Symfony/Bundle/FrameworkBundle/EventListener/TestSessionListener.php src/Symfony/Component/Config/Definition/ReferenceDumper.php src/Symfony/Component/Console/Application.php src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php src/Symfony/Component/Filesystem/Tests/FilesystemTest.php src/Symfony/Component/Form/Extension/Csrf/EventListener/CsrfValidationListener.php src/Symfony/Component/Form/FormError.php src/Symfony/Component/HttpFoundation/Request.php src/Symfony/Component/HttpFoundation/Response.php src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php src/Symfony/Component/Process/ProcessUtils.php src/Symfony/Component/PropertyAccess/PropertyAccessor.php src/Symfony/Component/PropertyAccess/PropertyAccessorInterface.php src/Symfony/Component/Serializer/Encoder/XmlEncoder.php src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php src/Symfony/Component/Validator/Constraints/GroupSequence.php src/Symfony/Component/Validator/Mapping/ClassMetadata.php src/Symfony/Component/Validator/Mapping/ClassMetadataFactory.php src/Symfony/Component/Validator/Mapping/MemberMetadata.php src/Symfony/Component/Validator/Tests/Fixtures/StubGlobalExecutionContext.php
2014-12-22 16:29:52 +00:00
* 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);
}
2016-03-29 15:14:08 +01:00
if ($input instanceof \Iterator) {
return $input;
}
if ($input instanceof \Traversable) {
return new \IteratorIterator($input);
}
2020-03-16 15:39:23 +00:00
throw new InvalidArgumentException(sprintf('"%s" only accepts strings, Traversable objects or stream resources.', $caller));
}
return $input;
}
}