Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
crazyfactory/jobs / src / JobConfig.php
Size: Mime:
<?php

namespace CrazyFactory\Jobs;

use Traversable;

/**
 * Class JobConfig
 *
 * @property string $name
 * @property string $cmd
 *
 * @property bool   $enabled
 * @property bool   $singleton
 *
 * @property bool   $logError
 * @property bool   $logSuccess
 * @property bool   $reportError
 * @property bool   $reportSuccess
 *
 * @property int    $processRuntimeEvery
 * @property int    $maxRuntime
 */
class JobConfig implements \ArrayAccess, \IteratorAggregate
{
    protected $_properties = [];

    /**
     * JobConfig constructor.
     *
     * @param string[] $data
     */
    public function __construct(array $data = [])
    {
        $this->fromArray($data);
    }

    /**
     * @param string[] $data
     */
    public function fromArray(array $data)
    {
        $this->_properties = array_merge($this->_properties, $data);
    }

    /**
     * @return JobConfig
     */
    public static function getDefault()
    {
        return new JobConfig([
            'enabled' => true,
            'singleton' => false,
            'logError' => true,
            'logSuccess' => true,
            'reportError' => true,
            'reportSuccess' => true,
            'processRuntimeEvery' => 10,
            'maxRuntime' => -1,
        ]);
    }

    /**
     * @param JobConfig $jobConfig
     *
     * @return JobConfig
     */
    public function merge(JobConfig $jobConfig)
    {
        return new JobConfig(array_merge($this->toArray(), $jobConfig->toArray()));
    }

    /**
     * @return string[]
     */
    public function toArray()
    {
        return array_slice($this->_properties, 0);
    }

    /**
     * Whether a offset exists
     *
     * @link  http://php.net/manual/en/arrayaccess.offsetexists.php
     *
     * @param mixed $offset <p>
     *                      An offset to check for.
     *                      </p>
     *
     * @return boolean true on success or false on failure.
     * </p>
     * <p>
     * The return value will be casted to boolean if non-boolean was returned.
     * @since 5.0.0
     */
    public function offsetExists($offset)
    {
        return isset($this->_properties[$offset]);
    }

    /**
     * Offset to retrieve
     *
     * @link  http://php.net/manual/en/arrayaccess.offsetget.php
     *
     * @param mixed $offset <p>
     *                      The offset to retrieve.
     *                      </p>
     *
     * @return mixed Can return all value types.
     * @since 5.0.0
     */
    public function offsetGet($offset)
    {
        return $this->_properties[$offset];
    }

    /**
     * Offset to set
     *
     * @link  http://php.net/manual/en/arrayaccess.offsetset.php
     *
     * @param mixed $offset <p>
     *                      The offset to assign the value to.
     *                      </p>
     * @param mixed $value  <p>
     *                      The value to set.
     *                      </p>
     *
     * @return void
     * @since 5.0.0
     */
    public function offsetSet($offset, $value)
    {
        $this->_properties[$offset] = $value;
    }

    /**
     * Offset to unset
     *
     * @link  http://php.net/manual/en/arrayaccess.offsetunset.php
     *
     * @param mixed $offset <p>
     *                      The offset to unset.
     *                      </p>
     *
     * @return void
     * @since 5.0.0
     */
    public function offsetUnset($offset)
    {
        unset($this->_properties[$offset]);
    }

    /**
     * @param string $name
     *
     * @return mixed|null
     */
    public function __get($name)
    {
        return isset($this->_properties[$name]) ? $this->_properties[$name] : null;
    }

    /**
     * @param string $name
     * @param $value
     *
     * @return mixed
     */
    public function __set($name, $value)
    {
        return $this->_properties[$name] = $value;
    }

    /**
     * @param string $name
     *
     * @return bool
     */
    public function __isset($name)
    {
        return isset($this->_properties[$name]);
    }

    /**
     * Retrieve an external iterator
     *
     * @link  http://php.net/manual/en/iteratoraggregate.getiterator.php
     * @return Traversable An instance of an object implementing <b>Iterator</b> or
     * <b>Traversable</b>
     * @since 5.0.0
     */
    public function getIterator()
    {
        return new \ArrayIterator($this->_properties);
    }
}