HEX
Server: Apache/2.4.34 (Red Hat) OpenSSL/1.0.2k-fips
System: Linux WORDPRESS 3.10.0-1160.118.1.el7.x86_64 #1 SMP Thu Apr 4 03:33:23 EDT 2024 x86_64
User: digital (1020)
PHP: 7.2.24
Disabled: NONE
Upload Files
File: /datos/www/fabricas.colombiatrade.com.co/vendor2/consolidation/robo/src/Collection/CallableTask.php
<?php
namespace Robo\Collection;

use Robo\Result;
use Robo\Contract\TaskInterface;
use Robo\State\StateAwareInterface;
use Robo\State\Data;

/**
 * Creates a task wrapper that converts any Callable into an
 * object that can be used directly with a task collection.
 *
 * It is not necessary to use this class directly; Collection will
 * automatically wrap Callables when they are added.
 */
class CallableTask implements TaskInterface
{
    /**
     * @var callable
     */
    protected $fn;

    /**
     * @var \Robo\Contract\TaskInterface
     */
    protected $reference;

    public function __construct(callable $fn, TaskInterface $reference)
    {
        $this->fn = $fn;
        $this->reference = $reference;
    }

    /**
     * {@inheritdoc}
     */
    public function run()
    {
        $result = call_user_func($this->fn, $this->getState());
        // If the function returns no result, then count it
        // as a success.
        if (!isset($result)) {
            $result = Result::success($this->reference);
        }
        // If the function returns a result, it must either return
        // a \Robo\Result or an exit code.  In the later case, we
        // convert it to a \Robo\Result.
        if (!$result instanceof Result) {
            $result = new Result($this->reference, $result);
        }

        return $result;
    }

    /**
     * @return \Robo\State\Data
     */
    public function getState()
    {
        if ($this->reference instanceof StateAwareInterface) {
            return $this->reference->getState();
        }
        return new Data();
    }
}